From 6a97387ebcc462f7526ad25ea9c238b756b03ef5 Mon Sep 17 00:00:00 2001 From: clc5q <clc5q@git.zephyr-software.com> Date: Thu, 13 Dec 2007 19:42:44 +0000 Subject: [PATCH] Fix code to reflect that EBP can be a base register in an opcode SIB byte. --- SMPDataFlowAnalysis.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/SMPDataFlowAnalysis.cpp b/SMPDataFlowAnalysis.cpp index 0ae9fb54..b2a49ee9 100644 --- a/SMPDataFlowAnalysis.cpp +++ b/SMPDataFlowAnalysis.cpp @@ -29,7 +29,7 @@ #define SMP_DEBUG_CONTROLFLOW 0 // tells what processing stage is entered #define SMP_DEBUG_XOR 0 #define SMP_DEBUG_CHUNKS 1 // tracking down tail chunks for functions -#define SMP_DEBUG_FRAMEFIXUP 1 +#define SMP_DEBUG_FRAMEFIXUP 0 // Used for binary search by function number in SMPStaticAnalyzer.cpp // to trigger debugging output and find which instruction in which @@ -214,9 +214,11 @@ void PrintSIB(op_t Opnd) { #define NAME_LEN 5 char BaseName[NAME_LEN] = {'N', 'o', 'n', 'e', '\0'}; char IndexName[NAME_LEN] = {'N', 'o', 'n', 'e', '\0'}; - if (BaseReg != R_bp) { // SIB code for NO BASE REG +#if 0 + if (BaseReg != R_bp) // SIB code for NO BASE REG +#endif qstrncpy(BaseName, RegNames[BaseReg], NAME_LEN - 1); - } + if (IndexReg != R_sp) { // SIB code for NO INDEX REG qstrncpy(IndexName, RegNames[IndexReg], NAME_LEN -1); } @@ -275,10 +277,12 @@ void SMPInstr::PrintOperands() const { } else if (Opnd.type == o_far) { msg(" Operand %d : FarPtrImmed", i); + msg(" addr: %x", Opnd.addr); PrintDefUse(features, i); } else if (Opnd.type == o_near) { msg(" Operand %d : NearPtrImmed", i); + msg(" addr: %x", Opnd.addr); PrintDefUse(features, i); } else { @@ -546,8 +550,8 @@ void SMPInstr::MDFixupDefUseLists(void) { // offsets if EBP is being used as a frame pointer (UseFP == true). void SMPInstr::AnnotateStackConstants(bool UseFP, FILE *AnnotFile) { op_t Opnd; -#if 0 - if ((this->address == 0x8048409) || (this->address == 0x81488a1)) { +#if 1 + if (this->address == 0x80ffe32) { msg("PROBLEM INSTRUCTION: \n"); this->PrintOperands(); } @@ -559,13 +563,16 @@ void SMPInstr::AnnotateStackConstants(bool UseFP, FILE *AnnotFile) { if (Opnd.hasSIB) { int BaseReg = sib_base(Opnd); short IndexReg = sib_index(Opnd); - if (BaseReg == R_sp) { // EBP cannot be BaseReg in SIB + if (BaseReg == R_none) { + msg("BaseReg of R_none at %x\n", this->address); + } + if (BaseReg == R_sp) { // EBP cannot be BaseReg in SIB ?? // ESP-relative constant offset qfprintf(AnnotFile, "%x %d PTRIMMEDESP STACK %d %s\n", SMPcmd.ea, SMPcmd.size, offset, disasm); } - else if (UseFP && (IndexReg == R_bp)) { // ESP cannot be IndexReg + else if (UseFP && ((IndexReg == R_bp) || (BaseReg == R_bp))) { // ESP cannot be IndexReg // EBP-relative constant offset qfprintf(AnnotFile, "%x %d PTRIMMEDEBP STACK %d %s\n", @@ -1159,7 +1166,7 @@ bool SMPFunction::MDFixFrameInfo(void) { return Changed; } // end of SMPFunction::MDFixFrameInfo() -// IDA Pro is often confused by a function that uses the frame pointer +// IDA Pro is sometimes confused by a function that uses the frame pointer // register for other purposes. For the x86, a function that uses EBP // as a frame pointer would begin with: push ebp; mov ebp,esp to save // the old value of EBP and give it a new value as a frame pointer. The @@ -1244,7 +1251,7 @@ void SMPFunction::Analyze(void) { ++ChunkCounter; #if SMP_DEBUG_CHUNKS if (1 < ChunkCounter) - msg("Found tail chunk for %s\n", this->FuncName); + msg("Found tail chunk for %s at %x\n", this->FuncName, CurrChunk.startEA); #endif // Build the instruction and block lists for the function. for (ea_t addr = CurrChunk.startEA; addr < CurrChunk.endEA; -- GitLab