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 768d4bf33ea2a0a2cdd89838ace21798b50daa33..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. diff --git a/include/interfaces/idapro/STARSInterface.h b/include/interfaces/idapro/STARSInterface.h index 261d88cc946c569c3cc8b4841656b0862c5bc3ca..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. diff --git a/include/interfaces/irdb/STARSInterface.h b/include/interfaces/irdb/STARSInterface.h index 11f55e159e61b02b85e873f3a473629488806565..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" @@ -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) diff --git a/src/base/SMPInstr.cpp b/src/base/SMPInstr.cpp index d887959816961daa8c31ef13739134fcea2ece8f..1a18ffc58d23def85a9ed3ce857ecdb68d2f40da 100644 --- a/src/base/SMPInstr.cpp +++ b/src/base/SMPInstr.cpp @@ -4933,6 +4933,7 @@ SMPInstr::~SMPInstr() { this->Uses.clear(); } +#if 0 if (global_STARS_program->IsIDAProDriverMode() && (nullptr != this->STARSInstPtr)) { delete this->STARSInstPtr; this->STARSInstPtr = nullptr; @@ -4942,6 +4943,7 @@ SMPInstr::~SMPInstr() { delete this->STARSInstPtr; this->STARSInstPtr = nullptr; } +#endif return; } diff --git a/src/interfaces/irdb/STARS_IRDB_Function.cpp b/src/interfaces/irdb/STARS_IRDB_Function.cpp index 1c4aea07fb509a2e0e8e9a50a47232e281a1d931..14a6293601eabed29ad22039c1cba80ac1f77735 100644 --- a/src/interfaces/irdb/STARS_IRDB_Function.cpp +++ b/src/interfaces/irdb/STARS_IRDB_Function.cpp @@ -231,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_Interface.cpp b/src/interfaces/irdb/STARS_IRDB_Interface.cpp index faf9eadd143777da1c90f220aa0fd3663e6d7366..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,27 +15,27 @@ #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); + 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 = nullptr; + if (InstID.HasCorrespondingInstructionIR()) { - insn = (STARS_Instruction_t*) InstID.GetInstruction(); + 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. - insn = (STARS_Instruction_t*) new STARS_IRDB_Instruction_t(this->instr_id_to_irdb_insn_map[(IRDB_SDK::DatabaseID_t) InstID.GetIDWithinFile()]); + 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()])}; } - assert(insn != nullptr); - return insn; };