diff --git a/include/interfaces/irdb/STARSProgram.h b/include/interfaces/irdb/STARSProgram.h index a34b35658a6214f6cdd6b0d5d4231b502ac171db..eee21452fd1caa9f3a634bed0b1703977e9e19a8 100644 --- a/include/interfaces/irdb/STARSProgram.h +++ b/include/interfaces/irdb/STARSProgram.h @@ -32,7 +32,7 @@ public: void InitStaticDataTable(SMPProgram *CurrProg); virtual void PrintAllCodeToCodeXrefs(STARS_ea_t, std::size_t) {} - virtual void GetBlockSuccessorTargets(bool, STARS_InstructionID_t, std::size_t, std::list<STARS_InstructionID_t>&) {} + virtual void GetBlockSuccessorTargets(bool, STARS_InstructionID_t, std::size_t, std::list<STARS_InstructionID_t>&); private: diff --git a/src/interfaces/irdb/STARSIRDBProgram.cpp b/src/interfaces/irdb/STARSIRDBProgram.cpp index 681c5d5da0403053875892d21da6ac2c396e43f4..f79e98c359714c62c762d5abc5563b1306d98ff8 100644 --- a/src/interfaces/irdb/STARSIRDBProgram.cpp +++ b/src/interfaces/irdb/STARSIRDBProgram.cpp @@ -6,6 +6,7 @@ #include "interfaces/STARSTypes.h" #include "interfaces/SMPDBInterface.h" #include "interfaces/irdb/STARSProgram.h" +#include "interfaces/irdb/STARSInstruction.h" #include "base/SMPProgram.h" @@ -45,6 +46,7 @@ void STARS_IRDB_Program_t::CloseFiles(void) { } // end of STARS_IRDB_Program_t::CloseFiles() void STARS_IRDB_Program_t::DetermineRootFileName(void) { + this->SetRootFileName("b.ncexe"); #if 0 SMP_msg("INFO: Reached DetermineRootFileName method.\n"); // Get the root file name from IDA Pro, e.g. "foo" when analyzing "foo.exe" @@ -56,59 +58,7 @@ void STARS_IRDB_Program_t::DetermineRootFileName(void) { #endif } -#if 0 -void STARS_IRDB_Program_t::MDInitializeCallerSavedRegs(void) { - this->STARS_MDCallerSavedRegs.clear(); - bool x86_64_ISA_flag = false; -#ifdef __EA64__ - x86_64_ISA_flag = (this->GetSTARS_ISA_Bitwidth() == 64); -#endif - if (!x86_64_ISA_flag) { - // 32-bit x86 uses EAX, ECX, EDX as caller-saved. - this->STARS_MDCallerSavedRegs.push_back(R_ax); - this->STARS_MDCallerSavedRegs.push_back(R_cx); - this->STARS_MDCallerSavedRegs.push_back(R_dx); - } - else { - // 64-bit x86 uses EDI, ESI, EDX, ECX, R8 and R9 - // in that order. After six arguments that fit into - // these regs, arguments are passed on the stack. - // In addition, registers EAX, R10 and R11 are caller-saved - // but are not used to pass arguments. - this->STARS_MDCallerSavedRegs.push_back(R_ax); - this->STARS_MDCallerSavedRegs.push_back(R_cx); - this->STARS_MDCallerSavedRegs.push_back(R_dx); - this->STARS_MDCallerSavedRegs.push_back(R_si); - this->STARS_MDCallerSavedRegs.push_back(R_di); - this->STARS_MDCallerSavedRegs.push_back(R_r8); - this->STARS_MDCallerSavedRegs.push_back(R_r9); - this->STARS_MDCallerSavedRegs.push_back(R_r10); - this->STARS_MDCallerSavedRegs.push_back(R_r11); - } - return; -} // end of STARS_IRDB_Program_t::MDInitializeCallerSavedRegs() -#endif -#if 0 -void STARS_IRDB_Program_t::MDInitializeArgumentRegs(void) { - bool x86_64_ISA_flag = false; -#ifdef __EA64__ - x86_64_ISA_flag = (this->GetSTARS_ISA_Bitwidth() == 64); -#endif - if (x86_64_ISA_flag) { - this->STARS_MDArgumentRegs.push_back(R_di); - this->STARS_MDArgumentRegs.push_back(R_si); - this->STARS_MDArgumentRegs.push_back(R_dx); - this->STARS_MDArgumentRegs.push_back(R_cx); - this->STARS_MDArgumentRegs.push_back(R_r8); - this->STARS_MDArgumentRegs.push_back(R_r9); - } - else { - this->STARS_MDArgumentRegs.clear(); - } - return; -} // end of STARS_IRDB_Program_t::MDInitializeArgumentRegs() -#endif // Does the instruction at InstAddr access the global data offset in GlobalAddr // using an index register? @@ -335,56 +285,26 @@ void STARS_IRDB_Program_t::InitStaticDataTable(SMPProgram *CurrProg) { return; } // end of STARS_IDA_Program_t::InitStaticDataTable() -// Find the direct and indexed accesses to offsets within each static data table entry. -// Record the offset and kind of access (indexed or not) and conservatively mark the -// field boundaries based on the unindexed accesses. -#if 0 -void STARS_IRDB_Program_t::ComputeGlobalFieldOffsets(struct GlobalVar &CurrGlobal) { - SMP_xref_t xb; - STARS_ea_t addr; - std::size_t offset; - bool DebugFlag = false; - DebugFlag |= (0 == strcmp("spec_fd", CurrGlobal.name)); - for (addr = CurrGlobal.addr; addr < CurrGlobal.addr + CurrGlobal.size; ++addr) { - bool Referenced = false; - offset = addr - CurrGlobal.addr; - pair<std::size_t, bool> TempOffset(offset, false); // false ==> No indexed accesses seen yet - for (bool ok = xb.SMP_first_to(addr, XREF_ALL); ok; ok = xb.SMP_next_to()) { - uchar XrefType = xb.GetType() & XREF_MASK; - if (xb.GetIscode()) { -#if SMP_DEBUG_GLOBAL_GRANULARITY - SMP_msg("WARNING: code xref to global data at %x\n", addr); -#endif - ; - } - else { - STARS_ea_t FromAddr = xb.GetFrom(); - if ((XrefType == dr_O) || (XrefType == dr_W) || (XrefType == dr_R)) { -#if SMP_DEBUG_GLOBAL_GRANULARITY - SMPInstr TempInstr(FromAddr); - TempInstr.Analyze(); - SMP_msg("Data xref to global data %s at %x from code at %x %s\n", - CurrGlobal.name, addr, FromAddr, TempInstr.GetDisasm()); -#endif - Referenced = true; - TempOffset.second |= MDIsIndexedAccess(FromAddr, addr); - } - else { -#if SMP_DEBUG_GLOBAL_GRANULARITY - SMP_msg("WARNING: Weird data xref type %d at %x\n", XrefType, FromAddr); -#endif - ; - } - } - } // end for (bool ok = iterate through xrefs ...) - if (Referenced) { - CurrGlobal.FieldOffsets.insert(TempOffset); - } - } // end for all addrs in current global +// Get successors for LastBlockInst, omitting call targets +void STARS_IRDB_Program_t::GetBlockSuccessorTargets + (bool CallFlag, + STARS_InstructionID_t LastBlockInst, + std::size_t InstSize, + std::list<STARS_InstructionID_t> &SuccList) +{ + const STARS_Instruction_t* interface_insn=LastBlockInst.GetInstruction(); + assert(interface_insn); + const STARS_IRDB_Instruction_t* irdb_interface_insn=dynamic_cast<const STARS_IRDB_Instruction_t*>(interface_insn); + assert(irdb_interface_insn); + const libIRDB::Instruction_t* irdb_insn=irdb_interface_insn->GetIRDBInstruction(); + + + if(irdb_insn->GetFallthrough()) + SuccList.push_back(STARS_InstructionID_t(irdb_insn->GetFallthrough()->GetBaseID())); + if(irdb_insn->GetTarget()) + SuccList.push_back(STARS_InstructionID_t(irdb_insn->GetTarget()->GetBaseID())); + return; -} // end of STARS_IDA_Program_t::ComputeGlobalFieldOffsets() -#endif -// No need for IRDB version for fine-grained global static data, as all fine-grained info computed in ComputeGlobalFieldOffsets() will -// be written to the annotations file, read by the IRDB builder process, and then read back in -// the IRDB version of InitStaticDataTable(). +} +