diff --git a/include/interfaces/abstract/STARSInterface.h b/include/interfaces/abstract/STARSInterface.h index 2cd28cf465ff64a4b0e9eedda5aca45eb267cca1..768d4bf33ea2a0a2cdd89838ace21798b50daa33 100644 --- a/include/interfaces/abstract/STARSInterface.h +++ b/include/interfaces/abstract/STARSInterface.h @@ -82,8 +82,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..261d88cc946c569c3cc8b4841656b0862c5bc3ca 100644 --- a/include/interfaces/idapro/STARSInterface.h +++ b/include/interfaces/idapro/STARSInterface.h @@ -135,8 +135,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 0b06a2cd5c5f7cd68a3c1e3b5eaf267ef3e18a36..11f55e159e61b02b85e873f3a473629488806565 100644 --- a/include/interfaces/irdb/STARSInterface.h +++ b/include/interfaces/irdb/STARSInterface.h @@ -189,10 +189,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 { 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_Interface.cpp b/src/interfaces/irdb/STARS_IRDB_Interface.cpp index 0dbe8a3bd92b2924a219785ddaa4233c88a43471..faf9eadd143777da1c90f220aa0fd3663e6d7366 100644 --- a/src/interfaces/irdb/STARS_IRDB_Interface.cpp +++ b/src/interfaces/irdb/STARS_IRDB_Interface.cpp @@ -41,12 +41,12 @@ STARS_Instruction_t * STARS_IRDB_Interface_t::CreateInst(STARS_InstructionID_t I 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; } @@ -59,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. @@ -99,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 @@ -108,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());