diff --git a/include/interfaces/abstract/STARSProgram.h b/include/interfaces/abstract/STARSProgram.h index 5522672a702c257b560f5a69985fccf79d89684a..406ffeac931e36d6dc9c50c335a901f810232abf 100644 --- a/include/interfaces/abstract/STARSProgram.h +++ b/include/interfaces/abstract/STARSProgram.h @@ -85,7 +85,8 @@ class STARS_Program_t void PrintCodeToCodeXref(STARS_ea_t FromAddr, STARS_ea_t ToAddr, std::size_t InstrSize); void PrintDataToCodeXref(STARS_ea_t FromDataAddr, STARS_ea_t ToCodeAddr, std::size_t InstrSize); void PrintUnknownCodeXref(STARS_ea_t ToAddr, std::size_t InstrSize); - virtual void PrintAllCodeToCodeXrefs(STARS_ea_t InstAddr, std::size_t InstSize) = 0; + void PrintCodeToCodeXrefComplete(STARS_ea_t FromAddr, std::size_t InstrSize, std::size_t IBTCount); + virtual void PrintAllCodeToCodeXrefs(STARS_ea_t InstAddr, std::size_t InstSize, bool CallFlag) = 0; // Analysis methods virtual bool IsImmedCodeAddress(STARS_ea_t ImmedValue) { return false; }; // Is ImmedValue a code address? diff --git a/include/interfaces/idapro/STARSProgram.h b/include/interfaces/idapro/STARSProgram.h index 73f686d437890412e777f37c482458442ae400b0..d0bf5ec6803603d5947585987493f8e6b9bda528 100644 --- a/include/interfaces/idapro/STARSProgram.h +++ b/include/interfaces/idapro/STARSProgram.h @@ -31,7 +31,7 @@ public: // Query methods // Printing methods - virtual void PrintAllCodeToCodeXrefs(STARS_ea_t InstAddr, std::size_t InstSize); + virtual void PrintAllCodeToCodeXrefs(STARS_ea_t InstAddr, std::size_t InstSize, bool CallFlag); // Analysis methods diff --git a/include/interfaces/irdb/STARSProgram.h b/include/interfaces/irdb/STARSProgram.h index eee21452fd1caa9f3a634bed0b1703977e9e19a8..fa44b6957201640c5e5d26e893781cb86f9fde47 100644 --- a/include/interfaces/irdb/STARSProgram.h +++ b/include/interfaces/irdb/STARSProgram.h @@ -31,7 +31,7 @@ public: void ReportTotalCodeSize(unsigned long long TotalCodeSize); void InitStaticDataTable(SMPProgram *CurrProg); - virtual void PrintAllCodeToCodeXrefs(STARS_ea_t, std::size_t) {} + virtual void PrintAllCodeToCodeXrefs(STARS_ea_t, std::size_t, bool CallFlag) {} virtual void GetBlockSuccessorTargets(bool, STARS_InstructionID_t, std::size_t, std::list<STARS_InstructionID_t>&); diff --git a/src/base/SMPFunction.cpp b/src/base/SMPFunction.cpp index ff944b2432efd29e054a3bf555080008d340bf32..1bf43ed97183badcd5e07a3493a5d03a3a9854b5 100644 --- a/src/base/SMPFunction.cpp +++ b/src/base/SMPFunction.cpp @@ -9057,8 +9057,9 @@ void SMPFunction::EmitAnnotations(FILE *AnnotFile, FILE *InfoAnnotFile) { SMP_fprintf(AnnotFile, "%18llx %6zu INSTR BELONGTO %llx \n", (unsigned long long) addr, CurrInst->GetSize(), (unsigned long long) GetStartAddr()); SMPitype CurrDataFlow = CurrInst->GetDataFlowType(); - if ((CurrDataFlow == INDIR_JUMP) || (CurrDataFlow == INDIR_CALL)) { - global_STARS_program->PrintAllCodeToCodeXrefs(addr, CurrInst->GetSize()); + bool IndirCallFlag = (CurrDataFlow == INDIR_CALL); + if ((CurrDataFlow == INDIR_JUMP) || IndirCallFlag) { + global_STARS_program->PrintAllCodeToCodeXrefs(addr, CurrInst->GetSize(), IndirCallFlag); } if (this->LocalVarsAllocInstr == addr) { diff --git a/src/interfaces/abstract/STARSProgram.cpp b/src/interfaces/abstract/STARSProgram.cpp index 490e33766bc6dfd8ae41d3e999161f6d039b49b6..973190ba9e43d683a83889623afaa11cfb993687 100644 --- a/src/interfaces/abstract/STARSProgram.cpp +++ b/src/interfaces/abstract/STARSProgram.cpp @@ -421,6 +421,15 @@ void STARS_Program_t::PrintUnknownCodeXref(STARS_ea_t ToAddr, std::size_t InstrS return; } +// Utility functions to signify code xrefs are complete in STARS_XrefsFile for FromAddr +void STARS_Program_t::PrintCodeToCodeXrefComplete(STARS_ea_t FromAddr, std::size_t InstrSize, std::size_t IBTCount) { + if (IsAddressInCodeRange(FromAddr)) { + SMP_fprintf(this->GetXrefsFile(), "%18llx %6zu INSTR XREF FROMIB COMPLETE %6zu \n", + (unsigned long long) FromAddr, InstrSize, IBTCount); + } + return; +} + // Read the foo.exe.policy file to initialize our security policies for system calls. void STARS_Program_t::ZST_InitPolicies(void) { string ZSTPolicyFileName(this->GetRootFileName()); diff --git a/src/interfaces/idapro/STARSIDAProgram.cpp b/src/interfaces/idapro/STARSIDAProgram.cpp index 19412aadae6e19810cc0e710a4059b4a6031a226..fcbfdaa2054db18c68c2bd5de19f1d3aad3f6b3c 100644 --- a/src/interfaces/idapro/STARSIDAProgram.cpp +++ b/src/interfaces/idapro/STARSIDAProgram.cpp @@ -408,17 +408,23 @@ void STARS_IDA_Program_t::ComputeGlobalFieldOffsets(struct GlobalVar &CurrGlobal // be written to the annotations file, read by the IRDB builder process, and then read back in // the IRDB version of InitStaticDataTable(). -void STARS_IDA_Program_t::PrintAllCodeToCodeXrefs(STARS_ea_t InstAddr, std::size_t InstSize) { +void STARS_IDA_Program_t::PrintAllCodeToCodeXrefs(STARS_ea_t InstAddr, std::size_t InstSize, bool CallFlag) { SMP_xref_t xrefs; + std::size_t IBTCount = 0; for (bool ok = xrefs.SMP_first_from(InstAddr, XREF_ALL); ok; ok = xrefs.SMP_next_from()) { if (xrefs.GetTo() != 0) { // Exclude the ordinary fall-through control flow type, fl_F if (xrefs.GetIscode() && (xrefs.GetType() != fl_F)) { // Found a code target, with its address in xrefs.to global_STARS_program->PrintCodeToCodeXref(InstAddr, xrefs.GetTo(), InstSize); + ++IBTCount; } } } + if ((IBTCount > 0) && (!CallFlag)) { + // IDA Pro does not list xrefs for INDIR_JUMPs if it has not analyzed the xrefs completely for the IB. + global_STARS_program->PrintCodeToCodeXrefComplete(InstAddr, InstSize, IBTCount); + } return; }