diff --git a/include/base/SMPInstr.h b/include/base/SMPInstr.h index c15c7b951917a540399a810511b1356c24523510..39a739ef6410b2b53b2e51b61e626f9bc545f1b2 100644 --- a/include/base/SMPInstr.h +++ b/include/base/SMPInstr.h @@ -34,6 +34,7 @@ #include <string> #include <bitset> +#include <memory> #include <cstddef> #include <cstdint> @@ -789,6 +790,7 @@ public: bool IsBasicBlockTerminator(void) const; // kind of inst that ALWAYS terminates a block inline bool IsLastInBlock(void) const { return (booleans1 & INSTR_SET_BLOCK_TERM); }; // does terminate its block inline bool IsJumpTarget(void) { return (booleans1 & INSTR_SET_JUMP_TARGET); }; + inline bool IsJumpFromFixedCall(void) const { return this->STARSInstPtr->IsJumpFromFixedCall(); }; bool IsBranchToFarChunk(void); // instr jumps outside current chunk bool IsBranchToOtherFunc(void); // instr branches or jumps to another function inline bool IsTailCall(void) const { return (booleans1 & INSTR_SET_TAIL_CALL); }; @@ -1018,7 +1020,7 @@ public: bool IsLoopExitStatement(bool &InvertedExit); // true => jump is used to exit a loop inline bool AnalyzeSwitchInfo(struct SwitchTableInfo &TableInfo) { return STARSInstPtr->AnalyzeSwitchStatement(this, TableInfo); }; - inline STARS_Instruction_t* GetSTARSInstPtr() { return STARSInstPtr; } // pointer to either STARS_IDA_Instruction_t or STARS_IRDB_Instruction_t + // inline std::unique_ptr<STARS_Instruction_t> GetSTARSInstPtr() { return STARSInstPtr; } // pointer to either STARS_IDA_Instruction_t or STARS_IRDB_Instruction_t private: // Data @@ -1028,7 +1030,7 @@ private: uint32 features; // Canonical features for SMPcmd #endif STARS_InstructionID_t STARS_ID; // instruction ID; could be IDA Pro address or IRDB inst ID - STARS_Instruction_t *STARSInstPtr; // pointer to either STARS_IDA_Instruction_t or STARS_IRDB_Instruction_t + std::unique_ptr<STARS_Instruction_t> STARSInstPtr; // pointer to either STARS_IDA_Instruction_t or STARS_IRDB_Instruction_t SMPitype type; // Data flow analysis category #if 0 // Get this dynamically to save memory diff --git a/include/interfaces/abstract/STARSInterface.h b/include/interfaces/abstract/STARSInterface.h index 2cd28cf465ff64a4b0e9eedda5aca45eb267cca1..f9fc3713576677a559e90888e48a0c430cbb2f27 100644 --- a/include/interfaces/abstract/STARSInterface.h +++ b/include/interfaces/abstract/STARSInterface.h @@ -2,6 +2,7 @@ #define STARSInterface_h #include <cstdio> +#include <memory> #if __unix__ #include <sys/time.h> @@ -51,7 +52,7 @@ class STARS_Interface_t virtual void get_func_name(const STARS_ea_t &ea, char* name, const std::size_t &len) = 0; // Instruction creation. - virtual STARS_Instruction_t *CreateInst(STARS_InstructionID_t InstID) = 0; + virtual std::unique_ptr<STARS_Instruction_t> CreateInst(STARS_InstructionID_t InstID) = 0; // IDA Pro does not permit direct usage of common file and string library calls, so we // have to do them differently in the IDA Pro and IRDB interfaces. @@ -82,8 +83,8 @@ class STARS_Interface_t virtual void SetCGCBinary(void) = 0; virtual bool IsCGCBinary(void) const = 0; virtual bool InstHasNoCodeXrefs(STARS_InstructionID_t InstID) const = 0; - virtual bool IsInstJumpTarget(STARS_InstructionID_t InstID) const = 0; - virtual STARS_InstructionID_t FindFirstCallTarget(STARS_InstructionID_t CallInstID) const = 0; // Find call target; first one, if any, for indirect call + virtual bool IsInstJumpTarget(STARS_InstructionID_t InstID) = 0; + virtual STARS_InstructionID_t FindFirstCallTarget(STARS_InstructionID_t CallInstID) = 0; // Find call target; first one, if any, for indirect call #if __unix__ virtual long GetMemoryInUse(void) const { // return max resident size in MB struct rusage *usage = (struct rusage *) malloc(sizeof(struct rusage) + 8); diff --git a/include/interfaces/idapro/STARSInterface.h b/include/interfaces/idapro/STARSInterface.h index 6d81e3951261543c75b489aa646e3ef07d31a686..87f227ff9c0aee2c310105464abc85f047831e0f 100644 --- a/include/interfaces/idapro/STARSInterface.h +++ b/include/interfaces/idapro/STARSInterface.h @@ -3,6 +3,7 @@ #include <cstdio> +#include <memory> #include <map> #include <pro.h> @@ -78,8 +79,8 @@ public: } // Instruction creation. - virtual STARS_Instruction_t *CreateInst(STARS_InstructionID_t InstID) { - return new STARS_IDA_Instruction_t(InstID); + virtual std::unique_ptr<STARS_Instruction_t> CreateInst(STARS_InstructionID_t InstID) { + return std::unique_ptr<STARS_Instruction_t>{(STARS_Instruction_t *) new STARS_IDA_Instruction_t(InstID)}; } // File methods. @@ -135,8 +136,8 @@ public: virtual void SetCGCBinary(void) { CGCBinary = true; }; virtual bool IsCGCBinary(void) const { return CGCBinary; }; virtual bool InstHasNoCodeXrefs(STARS_InstructionID_t InstID) const; - virtual bool IsInstJumpTarget(STARS_InstructionID_t InstID) const; - virtual STARS_InstructionID_t FindFirstCallTarget(STARS_InstructionID_t CallInstID) const; // Find call target; first one, if any, for indirect call + virtual bool IsInstJumpTarget(STARS_InstructionID_t InstID); + virtual STARS_InstructionID_t FindFirstCallTarget(STARS_InstructionID_t CallInstID); // Find call target; first one, if any, for indirect call // Miscellaneous IDA-only methods. virtual void AuditTailChunkOwnership(void); diff --git a/include/interfaces/irdb/STARSInterface.h b/include/interfaces/irdb/STARSInterface.h index be4c0424ff7379edad58944c87d4f3c66a7e6ba0..49c208e7048ab8e65db77819b341f8021908631e 100644 --- a/include/interfaces/irdb/STARSInterface.h +++ b/include/interfaces/irdb/STARSInterface.h @@ -1,6 +1,7 @@ #ifndef STARS_irdb_Interface_h #define STARS_irdb_Interface_h +#include <memory> #include "interfaces/abstract/STARSInterface.h" #include "interfaces/abstract/STARSInstructionID.h" @@ -48,7 +49,7 @@ public: { InitSegments(); InitFunctions(); - InitIBTAMaps(); + InitIBTAandIDMaps(); } // Destructors @@ -140,7 +141,7 @@ public: } // Instruction creation. - virtual STARS_Instruction_t *CreateInst(STARS_InstructionID_t InstID) ; + virtual std::unique_ptr<STARS_Instruction_t> CreateInst(STARS_InstructionID_t InstID) ; // File methods. virtual FILE *STARS_fopen(const char *file, const char *mode) @@ -189,10 +190,10 @@ public: virtual bool InstHasNoCodeXrefs(STARS_InstructionID_t InstID) const { assert(0); return 0; } // not implemented, shouldn't be called. - virtual bool IsInstJumpTarget(STARS_InstructionID_t InstID) const; + virtual bool IsInstJumpTarget(STARS_InstructionID_t InstID); // Find call target; first one, if any, for indirect call - virtual STARS_InstructionID_t FindFirstCallTarget(STARS_InstructionID_t CallInstID) const; + virtual STARS_InstructionID_t FindFirstCallTarget(STARS_InstructionID_t CallInstID); #if 0 { @@ -303,14 +304,13 @@ private: } } - void InitIBTAMaps() + void InitIBTAandIDMaps() { - for(IRDB_SDK::InstructionSet_t::iterator it=firp->getInstructions().begin(); - it!=firp->getInstructions().end(); - ++it) + for (IRDB_SDK::Instruction_t* insn : this->firp->getInstructions()) { - IRDB_SDK::Instruction_t* insn=*it; assert(insn); + this->instr_id_to_irdb_insn_map[insn->getBaseID()] = insn; + if(insn->getIndirectBranchTargetAddress()) { ibta_to_id_map [ AddressIDPlaceholder_t(insn->getIndirectBranchTargetAddress()) ] = insn; @@ -321,6 +321,7 @@ private: std::vector<STARS_IRDB_Segment_t*> segments; std::map<STARS_ea_t, STARS_IRDB_Function_t*> instr_id_to_func_map; + std::map<IRDB_SDK::DatabaseID_t, IRDB_SDK::Instruction_t*> instr_id_to_irdb_insn_map; std::map<AddressIDPlaceholder_t, IRDB_SDK::Instruction_t*> ibta_to_id_map; std::vector<STARS_IRDB_Function_t*> functions; ELFIO::elfio* elfiop; diff --git a/src/base/SMPInstr.cpp b/src/base/SMPInstr.cpp index 5098e2e5c8a88a2f579dfbeae3cb0cdda56a688b..cafbb1e2b70abbf0ff4fdf1d6a48350265253a1b 100644 --- a/src/base/SMPInstr.cpp +++ b/src/base/SMPInstr.cpp @@ -4932,12 +4932,19 @@ SMPInstr::~SMPInstr() { this->Defs.clear(); this->Uses.clear(); } -#if 1 // fix crashes before enabling this + +#if 0 if (global_STARS_program->IsIDAProDriverMode() && (nullptr != this->STARSInstPtr)) { delete this->STARSInstPtr; this->STARSInstPtr = nullptr; } + else if ((nullptr != this->STARSInstPtr) && (nullptr != this->GetBlock())) { // IRDB instruction, not orphan + SMP_msg("DEBUG: Destroying IRDB STARSInstPtr for inst ID %llx\n", (uint64_t) this->GetAddr()); + delete this->STARSInstPtr; + this->STARSInstPtr = nullptr; + } #endif + return; } diff --git a/src/drivers/library/stars_irdb.cpp b/src/drivers/library/stars_irdb.cpp index 79ba5676f0bfcd9caceee1a7108d0f1bb74f8f7d..567be4f2958e21628eb4be05c297e0597bf3304d 100644 --- a/src/drivers/library/stars_irdb.cpp +++ b/src/drivers/library/stars_irdb.cpp @@ -86,29 +86,22 @@ SMPProgram* InitSMPProgram() void ProcessOrphanedInstrs(SMPProgram* cur_pgm, FileIR_t* firp) { - set<STARS_IRDB_Instruction_t*> orphans; - STARS_Program_t* gsp=global_STARS_program; + STARS_Program_t* gsp = global_STARS_program; // for each orphan instruction (i.e., instruction that's not part of a function - for(auto it=firp->getInstructions().begin(); - it!=firp->getInstructions().end(); + for (auto it = firp->getInstructions().begin(); + it != firp->getInstructions().end(); ++it) { - Instruction_t* instr=*it; + Instruction_t* instr = *it; assert(instr); assert(instr->getBaseID() != BaseObj_t::NOT_IN_DATABASE); - if(instr->getFunction()!=NULL) - continue; - - // create the IRDB instruction - STARS_IRDB_Instruction_t *foo= new STARS_IRDB_Instruction_t(instr); - orphans.insert(foo); - - + if (instr->getFunction() != nullptr) + continue; // skip if inside a function // instr is "orphaned", that is, not part of a function. - // create the SMPInstr analyze it. + // create the SMPInstr and analyze it. SMPInstr CurrInst(instr->getBaseID()); CurrInst.Analyze(); @@ -116,7 +109,7 @@ void ProcessOrphanedInstrs(SMPProgram* cur_pgm, FileIR_t* firp) // The fixes can help produce better annotations. CurrInst.MDFixupDefUseLists(); - // If instruction is still not included in a code chunk, + // As instruction is not included in a function, // emit annotations for it in isolation. if (CurrInst.IsAnalyzeable()) { @@ -127,13 +120,8 @@ void ProcessOrphanedInstrs(SMPProgram* cur_pgm, FileIR_t* firp) } - // delete the insn here? - delete foo; } - // or process orphans and delete here? - // for ( each item orphan) delete item; - } diff --git a/src/interfaces/idapro/STARSInterface.cpp b/src/interfaces/idapro/STARSInterface.cpp index 8b6620663214e0278c73f249e09b3fdd5c3772e0..46d588ea3edb164f59e6297ff36fa740dc3c26b5 100644 --- a/src/interfaces/idapro/STARSInterface.cpp +++ b/src/interfaces/idapro/STARSInterface.cpp @@ -260,7 +260,7 @@ bool STARS_IDA_Interface_t::InstHasNoCodeXrefs(STARS_InstructionID_t InstID) con return (!FoundCodeXref); } // end of STARS_IDA_Interface_t::InstHasNoCodeXrefs() -bool STARS_IDA_Interface_t::IsInstJumpTarget(STARS_InstructionID_t InstID) const { +bool STARS_IDA_Interface_t::IsInstJumpTarget(STARS_InstructionID_t InstID) { // Determine whether the instruction is a jump target by looking // at its cross references and seeing if it has "TO" code xrefs. bool InstIsJumpTarget = false; @@ -275,7 +275,7 @@ bool STARS_IDA_Interface_t::IsInstJumpTarget(STARS_InstructionID_t InstID) const return InstIsJumpTarget; } -STARS_InstructionID_t STARS_IDA_Interface_t::FindFirstCallTarget(STARS_InstructionID_t CallInstID) const { +STARS_InstructionID_t STARS_IDA_Interface_t::FindFirstCallTarget(STARS_InstructionID_t CallInstID) { SMP_xref_t xrefs; STARS_ea_t CallTarget = STARS_BADADDR; STARS_ea_t CallInstAddr = CallInstID.GetIDWithinFile(); diff --git a/src/interfaces/irdb/STARS_IRDB_Function.cpp b/src/interfaces/irdb/STARS_IRDB_Function.cpp index 84df4eb8ff2a1c29fddcc2bb23def3104960d5f3..14a6293601eabed29ad22039c1cba80ac1f77735 100644 --- a/src/interfaces/irdb/STARS_IRDB_Function.cpp +++ b/src/interfaces/irdb/STARS_IRDB_Function.cpp @@ -111,22 +111,22 @@ void STARS_IRDB_Function_t::BuildFuncIR(SMPFunction *func) bool first_in_func=true; - for(auto block_it=sorted_blocks.begin(); block_it!=sorted_blocks.end(); ++block_it) + for (const BasicBlock_t* block : sorted_blocks) { list<SMPInstr*> block_id_map; block_id_map.clear(); - auto block=*block_it; - for(auto insn_it=block->getInstructions().begin(); insn_it!=block->getInstructions().end(); ++insn_it) + + for (const Instruction_t* irdb_insn : block->getInstructions()) { - auto irdb_insn=*insn_it; // cout<<"Building IR for instruction "<<dec<<irdb_insn->getBaseID()<<":"<<irdb_insn->getDisassembly()<<endl; - STARS_IRDB_Instruction_t* interface_insn=new STARS_IRDB_Instruction_t(irdb_insn); - STARS_InstructionID_t instruction_id=interface_insn->GetID(); + // STARS_IRDB_Instruction_t* interface_insn=new STARS_IRDB_Instruction_t(irdb_insn); + // STARS_InstructionID_t instruction_id=interface_insn->GetID(); + // create instruction - SMPInstr *CurrInst = new SMPInstr(interface_insn->GetID().GetIDWithinFile()); + SMPInstr *CurrInst = new SMPInstr(irdb_insn->getBaseID()); CurrInst->Analyze(); - if(first_in_func) + if (first_in_func) { first_in_func=false; @@ -152,10 +152,9 @@ void STARS_IRDB_Function_t::BuildFuncIR(SMPFunction *func) (global_stars_interface); assert(sGi); Instruction_t* entry=the_func->getEntryPoint(); - for(InstructionSet_t::iterator tmp_it=sGi->instruction_preds[entry].begin(); - tmp_it!=sGi->instruction_preds[entry].end(); ++tmp_it) + for (Instruction_t* tmp : sGi->instruction_preds[entry]) { - Instruction_t* tmp=*tmp_it; + ; if(tmp->getFunction()!=the_func && tmp->getFallthrough()!=entry) // tell stars about the jump func->AddCallSource(tmp->getBaseID()); @@ -178,7 +177,7 @@ void STARS_IRDB_Function_t::BuildFuncIR(SMPFunction *func) // Insert instruction at end of list. func->Instrs.push_back(CurrInst); - } + } // end for all instructions in block // find start/end of block @@ -232,7 +231,7 @@ void STARS_IRDB_Function_t::FindFixedCalls(SMPFunction *CurrFunc) { SMPInstr *CurrInst = (*InstIter); #if 1 - if (CurrInst->GetSTARSInstPtr()->IsJumpFromFixedCall()) + if (CurrInst->IsJumpFromFixedCall()) { CurrInst->SetFixedCallJump(); #if 0 diff --git a/src/interfaces/irdb/STARS_IRDB_Instruction.cpp b/src/interfaces/irdb/STARS_IRDB_Instruction.cpp index 06dc1c5eca55f4fad9da96c706bc59c7d88828a4..5d0ef5bd997edb9c602f0a65578e281ed0cdbf5a 100644 --- a/src/interfaces/irdb/STARS_IRDB_Instruction.cpp +++ b/src/interfaces/irdb/STARS_IRDB_Instruction.cpp @@ -2438,8 +2438,6 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void) { if(my_disasm.hasOperand(i)) Operands[i+1]=(std::make_shared<STARS_IRDB_op_t>(my_disasm,0,my_disasm.getOperand(i),length)); - else - Operands[i+1] = this->MakeVoidOpnd(); } features=GetInitialInstFeatures(true,my_disasm) | (STARS_CF_CHG1 | STARS_CF_USE1); } @@ -2506,8 +2504,6 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void) { if (my_disasm.hasOperand(i)) Operands[i + 1] = (std::make_shared<STARS_IRDB_op_t>(my_disasm, 0, my_disasm.getOperand(i),length)); - else - Operands[i + 1] = this->MakeVoidOpnd(); } if (FloatingStackLoad) features = GetInitialInstFeatures(true,my_disasm) | (STARS_CF_CHG1 | STARS_CF_USE2); @@ -2539,8 +2535,6 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void) { if(my_disasm.hasOperand(i)) Operands[i+1]=(std::make_shared<STARS_IRDB_op_t>(my_disasm,0,my_disasm.getOperand(i),length)); - else - Operands[i+1] = this->MakeVoidOpnd(); } features=GetInitialInstFeatures(true,my_disasm) | (STARS_CF_USE1); @@ -2617,8 +2611,6 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void) { if(my_disasm.hasOperand(i)) Operands[i+1]=(std::make_shared<STARS_IRDB_op_t>(my_disasm,0,my_disasm.getOperand(i),length)); - else - Operands[i+1] = this->MakeVoidOpnd(); } features=GetInitialInstFeatures(true,my_disasm) | (STARS_CF_CHG1 | STARS_CF_USE1); } @@ -2739,8 +2731,6 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void) { if(my_disasm.hasOperand(i)) Operands[i]=(std::make_shared<STARS_IRDB_op_t>(my_disasm,0,my_disasm.getOperand(i),length)); - else - Operands[i] = this->MakeVoidOpnd(); } features=GetInitialInstFeatures(false,my_disasm); } diff --git a/src/interfaces/irdb/STARS_IRDB_Interface.cpp b/src/interfaces/irdb/STARS_IRDB_Interface.cpp index ef04b6ddfa6550e3963e03c6290b971062f341a0..fdbe4b8767c91b72468a19cf523b7871f9e813d3 100644 --- a/src/interfaces/irdb/STARS_IRDB_Interface.cpp +++ b/src/interfaces/irdb/STARS_IRDB_Interface.cpp @@ -1,4 +1,4 @@ - +#include <memory> #include "interfaces/abstract/STARSInterface.h" #include "interfaces/irdb/STARSSegment.h" @@ -15,28 +15,38 @@ #include <stdio.h> #include <pqxx/pqxx> +using namespace std; - -STARS_Instruction_t * STARS_IRDB_Interface_t::CreateInst(STARS_InstructionID_t InstID) +unique_ptr<STARS_Instruction_t> STARS_IRDB_Interface_t::CreateInst(STARS_InstructionID_t InstID) { // check for pseudo-instructions - if(STARS_IsSSAMarkerPseudoID(InstID.GetIDWithinFile())) - return new STARS_IRDB_Instruction_t(InstID); + if (STARS_IsSSAMarkerPseudoID(InstID.GetIDWithinFile())) + return unique_ptr<STARS_Instruction_t>{(STARS_Instruction_t *) new STARS_IRDB_Instruction_t(InstID)}; + // already created, just return what we need. - STARS_Instruction_t* insn=(STARS_Instruction_t*)InstID.GetInstruction(); - assert(insn); - return insn; + STARS_Instruction_t* insn = nullptr; + + if (InstID.HasCorrespondingInstructionIR()) + { + return unique_ptr<STARS_Instruction_t>{(STARS_Instruction_t*)InstID.GetInstruction()}; + } + else + { + // Look it up in the private map, create STARS_IRDB_Instruction_t with it. + return unique_ptr<STARS_Instruction_t>{(STARS_Instruction_t*) new STARS_IRDB_Instruction_t(this->instr_id_to_irdb_insn_map[(IRDB_SDK::DatabaseID_t) InstID.GetIDWithinFile()])}; + } + }; bool STARS_IRDB_Interface_t::STARS_generate_disasm_line(STARS_ea_t addr, char *buf, std::size_t bufsize, int flags) { - STARS_InstructionID_t id(addr); - const STARS_Instruction_t* insn=id.GetInstruction(); - if (nullptr == insn) - return false; - const STARS_IRDB_Instruction_t* irdb_insn=dynamic_cast<const STARS_IRDB_Instruction_t*>(insn); - strncpy(buf,irdb_insn->GetIRDBInstruction()->getDisassembly().c_str(), bufsize); + STARS_InstructionID_t InstID(addr); + + IRDB_SDK::DatabaseID_t IRDBInstID = (IRDB_SDK::DatabaseID_t) InstID.GetIDWithinFile(); + IRDB_SDK::Instruction_t* irdb_insn = this->instr_id_to_irdb_insn_map[IRDBInstID]; + + strncpy(buf, irdb_insn->getDisassembly().c_str(), bufsize); return true; } @@ -49,33 +59,37 @@ bool STARS_IRDB_Interface_t::STARS_getenv(const char *varname, char varvalue[STA }; -bool STARS_IRDB_Interface_t::IsInstJumpTarget(STARS_InstructionID_t InstID) const +bool STARS_IRDB_Interface_t::IsInstJumpTarget(STARS_InstructionID_t InstID) { - const STARS_IRDB_Instruction_t* interface_insn=dynamic_cast<const STARS_IRDB_Instruction_t*>(InstID.GetInstruction()); - assert(interface_insn); +#if 0 + const STARS_IRDB_Instruction_t* interface_insn=dynamic_cast<const STARS_IRDB_Instruction_t*>(InstID.GetInstruction()); + assert(interface_insn); IRDB_SDK::Instruction_t* insn=(IRDB_SDK::Instruction_t*)interface_insn->GetIRDBInstruction(); +#else + IRDB_SDK::DatabaseID_t IRDBInstID = (IRDB_SDK::DatabaseID_t) InstID.GetIDWithinFile(); + IRDB_SDK::Instruction_t* insn = this->instr_id_to_irdb_insn_map[IRDBInstID]; +#endif - // return true if - // jumped to indirectly (jmp instruction) - // called indirectly (call instruction) - // Using the IBT provs guarantees we don't count jumped to by a ret - // (which includes push-rets), even with unpinned IBTs - if(IBT_provs[insn].hasIndirectJump() || IBT_provs[insn].hasIndirectCall()) + // return true if + // jumped to indirectly (jmp instruction) + // called indirectly (call instruction) + // Using the IBT provs guarantees we don't count jumped to by a ret + // (which includes push-rets), even with unpinned IBTs + if (IBT_provs[insn].hasIndirectJump() || IBT_provs[insn].hasIndirectCall()) { return true; } - // jumped to directly (jmp or jcc instruction) - // called directly (call instruction) + // jumped to directly (jmp or jcc instruction) + // called directly (call instruction) - for(IRDB_SDK::InstructionSet_t::iterator it=instruction_preds[insn].begin(); - it!=instruction_preds[insn].end(); ++it) - { - if(insn->getTarget()==insn) - return true; - } + for (auto pred : instruction_preds[insn]) + { + if (pred->getTarget() == insn) + return true; + } - return false; + return false; // jumped to via a return doesn't count. @@ -89,7 +103,7 @@ bool STARS_IRDB_Interface_t::IsInstJumpTarget(STARS_InstructionID_t InstID) cons assert(0); return 0; } -STARS_InstructionID_t STARS_IRDB_Interface_t::FindFirstCallTarget(STARS_InstructionID_t CallInstID) const +STARS_InstructionID_t STARS_IRDB_Interface_t::FindFirstCallTarget(STARS_InstructionID_t CallInstID) #if 0 // direct call: if no target -- return STARS_BADADDR // direct call: if target, return target @@ -98,11 +112,16 @@ STARS_InstructionID_t STARS_IRDB_Interface_t::FindFirstCallTarget(STARS_Instruc assert(0); return 0; #endif { - const STARS_Instruction_t* interface_insn=CallInstID.GetInstruction(); +#if 0 + const STARS_Instruction_t* interface_insn = CallInstID.GetInstruction(); assert(interface_insn); - const STARS_IRDB_Instruction_t* irdb_interface_insn=dynamic_cast<const STARS_IRDB_Instruction_t*>(interface_insn); + const STARS_IRDB_Instruction_t* irdb_interface_insn = dynamic_cast<const STARS_IRDB_Instruction_t*>(interface_insn); assert(irdb_interface_insn); const IRDB_SDK::Instruction_t* irdb_insn=irdb_interface_insn->GetIRDBInstruction(); +#else + IRDB_SDK::DatabaseID_t InstID = (IRDB_SDK::DatabaseID_t) CallInstID.GetIDWithinFile(); + IRDB_SDK::Instruction_t* irdb_insn = this->instr_id_to_irdb_insn_map[InstID]; +#endif if(irdb_insn->getTarget()) return STARS_InstructionID_t(irdb_insn->getTarget()->getBaseID());