1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/editor/ida/linux_vtable_dump.idc Sun Jul 08 01:36:16 2007 +0000
1.3 @@ -0,0 +1,102 @@
1.4 +
1.5 +// *****************************************************************************
1.6 +// - IDA Pro script -
1.7 +// Name: ida_vtables.idc
1.8 +// Desc: Recreates the methods of a class from a vtable
1.9 +//
1.10 +// Ver: 1.0b - July 20, 2006 - By Sirmabus
1.11 +// Ver: 2.0 - July 7, 2006 by BAILOPAN
1.12 +// �������������������������������������������������������������������������-��-
1.13 +//
1.14 +// -----------------------------------------------------------------------------
1.15 +
1.16 +#include <idc.idc>
1.17 +
1.18 +static main()
1.19 +{
1.20 + auto pAddress, iIndex;
1.21 + auto szFilePath, hFile;
1.22 + auto skipAmt;
1.23 +
1.24 + SetStatus(IDA_STATUS_WORK);
1.25 +
1.26 + // User selected vtable block
1.27 + pAddress = ScreenEA();
1.28 +
1.29 + if (pAddress == BADADDR)
1.30 + {
1.31 + Message("** No vtable selected! Aborted **");
1.32 + Warning("No vtable selected!\nSelect vtable block first.");
1.33 + SetStatus(IDA_STATUS_READY);
1.34 + return;
1.35 + }
1.36 +
1.37 + skipAmt = AskLong(1, "Number of vtable entries to ignore for indexing:");
1.38 +
1.39 + // Request output header file
1.40 + SetStatus(IDA_STATUS_WAITING);
1.41 + if ((szFilePath = AskFile(1, "*.txt", "Select output dump file:")) == 0)
1.42 + {
1.43 + Message("Aborted.");
1.44 + SetStatus(IDA_STATUS_READY);
1.45 + return;
1.46 + }
1.47 +
1.48 + // And create it..
1.49 + if ((hFile = fopen(szFilePath, "wb")) != 0)
1.50 + {
1.51 + auto szFuncName, szFullName, BadHits;
1.52 +
1.53 + BadHits = 0;
1.54 +
1.55 + // Create the header
1.56 + fprintf(hFile, "// Auto reconstructed from vtable block @ 0x%08X\n// from \"%s\", by ida_vtables.idc\n", pAddress, GetInputFile());
1.57 +
1.58 + /* For linux, skip the first entry */
1.59 + if (Dword(pAddress) == 0)
1.60 + {
1.61 + pAddress = pAddress + 8;
1.62 + }
1.63 +
1.64 + pAddress = pAddress + (skipAmt * 4);
1.65 +
1.66 + // Loop through the vtable block
1.67 + while (pAddress != BADADDR)
1.68 + {
1.69 + auto real_addr;
1.70 + real_addr = Dword(pAddress);
1.71 +
1.72 + szFuncName = GetFunctionName(real_addr);
1.73 + if (strlen(szFuncName) == 0)
1.74 + {
1.75 + break;
1.76 + }
1.77 + szFullName = Demangle(szFuncName, INF_LONG_DN);
1.78 + if (szFullName == "")
1.79 + {
1.80 + szFullName = szFuncName;
1.81 + }
1.82 + if (strstr(szFullName, "_ZN") != -1)
1.83 + {
1.84 + fclose(hFile);
1.85 + Warning("You must toggle GCC v3.x demangled names!\n");
1.86 + break;
1.87 + }
1.88 + fprintf(hFile, "%d\t%s\n", iIndex, szFullName);
1.89 +
1.90 + pAddress = pAddress + 4;
1.91 + iIndex++;
1.92 + };
1.93 +
1.94 + fclose(hFile);
1.95 + Message("Successfully wrote %d vtable entries.\n", iIndex);
1.96 + }
1.97 + else
1.98 + {
1.99 + Message("** Error opening \"%s\"! Aborted **\n", szFilePath);
1.100 + Warning("Error creating \"%s\"!\n", szFilePath);
1.101 + }
1.102 +
1.103 + Message("\nDone.\n\n");
1.104 + SetStatus(IDA_STATUS_READY);
1.105 +}