diff --git a/include/interfaces/abstract/STARSProgram.h b/include/interfaces/abstract/STARSProgram.h index eaf68937e3f50b730f4f501f9a46c3dcfcadb2b7..d13481e4a2cc3b3e2ee162d9718cbc041a1a1ac7 100644 --- a/include/interfaces/abstract/STARSProgram.h +++ b/include/interfaces/abstract/STARSProgram.h @@ -27,6 +27,7 @@ class STARS_Program_t virtual void DetermineRootFileName(void) = 0; virtual bool OpenFiles(void); virtual void CloseFiles(void); + virtual bool ReopenAnnotFile(const char *mode); void ZST_InitPolicies(void); // Get (accessor) methods diff --git a/include/interfaces/idapro/STARSInterface.h b/include/interfaces/idapro/STARSInterface.h index 490d00155e16528c2edaa64588a88f2546e0d966..0dba26fa37f3170955e8d78600c655e6b171d339 100644 --- a/include/interfaces/idapro/STARSInterface.h +++ b/include/interfaces/idapro/STARSInterface.h @@ -45,10 +45,10 @@ public: // Function accessors - // find out how many functions there are + // find out how many functions there are virtual std::size_t get_func_qty() { return ::get_func_qty(); }; - // get the index-th function + // get the index-th function virtual STARS_Function_t *getn_func(int index) { func_t* Func = ::getn_func(index); return func2Func(Func); @@ -105,7 +105,7 @@ public: // Miscellaneous IDA-only methods. virtual void AuditTailChunkOwnership(void); - virtual void AuditCodeTargets(void); + virtual void AuditCodeTargets(void); virtual bool STARS_patch_byte(STARS_ea_t InstAddr, uint32_t ByteValue); // Patch IDA Pro database. diff --git a/src/base/ProfilerInformation.cpp b/src/base/ProfilerInformation.cpp index b571653c51d988d13ab45f1bc53dd6f8f6be303b..461be192ba177ccc58bc66abdd8e92bdfc74b7e4 100644 --- a/src/base/ProfilerInformation.cpp +++ b/src/base/ProfilerInformation.cpp @@ -116,7 +116,6 @@ ProfilerInformation::ProfilerInformation(const char* fn, SMPProgram *CurrProg) return; fin = SMP_fopen(fn, "r"); - if (!fin) { SMP_msg("WARNING: Cannot open strata annotation file %s\n", fn); @@ -258,9 +257,11 @@ ProfilerInformation::ProfilerInformation(const char* fn, SMPProgram *CurrProg) } while ((TempChar != '\n') && (TempChar != EOF)); line++; } while (!SMP_feof(fin)); + int ReturnCode = SMP_fclose(fin); if (0 != ReturnCode) { - SMP_msg("ERROR: Failed to close annotation file %s ReturnCode: %d\n", fn, ReturnCode); + SMP_msg("FATAL ERROR: Failed to close annotation file %s in ProfilerInformation. ReturnCode: %d\n", fn, ReturnCode); + assert(0 == ReturnCode); } SMP_msg("Successfully loaded annotation file %s\n", fn); diff --git a/src/base/SMPInstr.cpp b/src/base/SMPInstr.cpp index 9423951e9e9ddb5bd3728b66e0ab4b180e779cd9..e8d251a48aaf09071e06bdf47f703f5330096f2f 100644 --- a/src/base/SMPInstr.cpp +++ b/src/base/SMPInstr.cpp @@ -2813,6 +2813,9 @@ int SMPInstr::operator<=(const SMPInstr &rhs) const { // Is this instruction one that allocates space on the // stack for the local variables? bool SMPInstr::MDIsFrameAllocInstr(void) { + if (this->IsAllocaCall()) + return true; + // The frame allocating instruction should look like: // sub esp,48 or add esp,-64 etc. STARSOpndTypePtr ESPOp = this->STARSInstPtr->MakeRegOpnd(STARS_x86_R_sp); diff --git a/src/drivers/idapro/SMPStaticAnalyzer.cpp b/src/drivers/idapro/SMPStaticAnalyzer.cpp index 77cc9c65f6140ea2ca51fccf6f83f3b6cc871c10..a79c5559b40eb406b36a562123bc614938e3c725 100644 --- a/src/drivers/idapro/SMPStaticAnalyzer.cpp +++ b/src/drivers/idapro/SMPStaticAnalyzer.cpp @@ -348,8 +348,11 @@ void IDAP_run(int arg) { // read the Profiler generated information into a new prof_info class CurrProg = new SMPProgram(); + + CurrProg->AnalyzeData(); // Analyze static data in the executable + + // Note: ProfilerInformation must come after the call above to AnalyzeData(). ProfilerInformation *prof_info = new ProfilerInformation(global_STARS_program->GetAnnotFileName().c_str(), CurrProg); - // NOTE: ProfilerInformation fopen's the AnnotFile, reads it, then closes it. Then we re-open for writing below. if (!(global_STARS_program->OpenFiles())) { SMP_msg("FATAL ERROR: At least one file could not be opened.\n"); @@ -390,8 +393,6 @@ void IDAP_run(int arg) { } #endif - CurrProg->AnalyzeData(); // Analyze static data in the executable - // Read the Zephyr Security Toolkit system call security policies, if available. global_STARS_program->ZST_InitPolicies(); diff --git a/src/interfaces/abstract/STARSProgram.cpp b/src/interfaces/abstract/STARSProgram.cpp index 3c2f433358b6c6a04571d1d04b480152f2f233ff..4d6f5fd7fdcc8cdf9f156900b806a9a766324430 100644 --- a/src/interfaces/abstract/STARSProgram.cpp +++ b/src/interfaces/abstract/STARSProgram.cpp @@ -167,6 +167,16 @@ void STARS_Program_t::CloseFiles(void) { return; } // end of STARS_Program_t::CloseFiles() +// Apply new mode to the AnnotFile. +bool STARS_Program_t::ReopenAnnotFile(const char *mode) { + FILE *TempHandle = freopen(NULL, mode, this->GetAnnotFile()); + bool success = (NULL != TempHandle); + if (success) { + this->STARS_AnnotFile = TempHandle; + } + return success; +} + void STARS_Program_t::InitData(void) { this->CurrentFileNumber = 0; this->ZST_AlarmFile = NULL;