This commit is contained in:
David Anderson 2008-11-11 01:37:24 -08:00
commit c880919466

View File

@ -5,8 +5,15 @@
// Desc: Add references for strings, variables, and other data that seem mangled // Desc: Add references for strings, variables, and other data that seem mangled
// due to GCC's -fPIC option and the .got section of an x86 ELF binary. // due to GCC's -fPIC option and the .got section of an x86 ELF binary.
// //
// Version 1.0 - November 22, 2007 // Version History
// Version 1.1 - May 02, 2008 - Now works with GCC 4.x compiled binaries // 1.0 [2007-11-22]
// - Initial Version
// 1.1 [2008-05-02]
// - Now works with GCC 4.x compiled binaries
// 1.2 [2008-11-06]
// - Now works with GCC 4.3 compiled binaries
// - Fixed: Redefining alignment blocks as data caused IDA to pop up
// an annoying warning
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <idc.idc> #include <idc.idc>
@ -123,7 +130,7 @@ static main()
} }
/* Get current PIC register */ /* Get current PIC register */
reg = GetPICRegister(addr, reg); reg = GetPICRegister(addr, reg, funcend);
if (reg != REG_NONE) if (reg != REG_NONE)
{ {
@ -173,6 +180,10 @@ static main()
{ {
/* Create a name based on the address */ /* Create a name based on the address */
opstr = form("unk_%X", dataAddr); opstr = form("unk_%X", dataAddr);
if (strstr(GetDisasm(dataAddr), "align") != -1)
{
MakeUnkn(dataAddr, DOUNK_SIMPLE);
}
MakeNameEx(dataAddr, opstr, SN_NOCHECK|SN_NOLIST|SN_NOWARN); MakeNameEx(dataAddr, opstr, SN_NOCHECK|SN_NOLIST|SN_NOWARN);
opformat = OPFORMAT_DEREF; opformat = OPFORMAT_DEREF;
} }
@ -188,6 +199,10 @@ static main()
{ {
/* If name doesn't exist for that, then create name based on address */ /* If name doesn't exist for that, then create name based on address */
opstr = form("unk_%X", dataAddr); opstr = form("unk_%X", dataAddr);
if (strstr(GetDisasm(dataAddr), "align") != -1)
{
MakeUnkn(dataAddr, DOUNK_SIMPLE);
}
MakeNameEx(dataAddr, opstr, SN_NOCHECK|SN_NOLIST|SN_NOWARN); MakeNameEx(dataAddr, opstr, SN_NOCHECK|SN_NOLIST|SN_NOWARN);
opformat = OPFORMAT_DEREF; opformat = OPFORMAT_DEREF;
} }
@ -255,15 +270,21 @@ static main()
* Tries to determine the current PIC register given the current address being processed * Tries to determine the current PIC register given the current address being processed
* and the previous PIC register. * and the previous PIC register.
*/ */
static GetPICRegister(addr, previous) static GetPICRegister(addr, previous, funcend)
{ {
auto assemblyStr, idx, reg; auto assemblyStr, idx, reg, ab;
assemblyStr = GetDisasm(addr); assemblyStr = GetDisasm(addr);
if ((idx = strstr(assemblyStr, "call __i686_get_pc_thunk_")) != -1) if ((idx = strstr(assemblyStr, "call __i686_get_pc_thunk_")) != -1)
{ {
/* 28 is the length of the above string */ /* 28 is the length of the above string */
reg = substr(assemblyStr, idx + 28, 30); reg = substr(assemblyStr, idx + 28, 30);
}
else if (strstr(assemblyStr, "call $+5") != -1)
{
assemblyStr = GetDisasm(NextHead(addr, funcend));
reg = substr(assemblyStr, 9, 11);
}
if (reg == "ax") if (reg == "ax")
{ {
@ -281,7 +302,6 @@ static GetPICRegister(addr, previous)
{ {
return REG_EDX; return REG_EDX;
} }
}
return previous; return previous;
} }