Advertisement
encoree1996

Untitled

May 1st, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <idc.idc>
  2.  
  3. static main()
  4. {
  5.     auto pAddress, iIndex;
  6.     auto szFilePath, hFile;
  7.     auto skipAmt;
  8.  
  9.     SetStatus(IDA_STATUS_WORK);
  10.  
  11.     // User selected vtable block
  12.     pAddress = ScreenEA();
  13.    
  14.     if (pAddress == BADADDR)
  15.     {  
  16.         Message("** No vtable selected! Aborted **");
  17.         Warning("No vtable selected!\nSelect vtable block first.");                        
  18.         SetStatus(IDA_STATUS_READY);
  19.         return;
  20.     }
  21.  
  22.     skipAmt = AskLong(1, "Number of vtable entries to ignore for indexing:");
  23.  
  24.     // Request output header file
  25.     SetStatus(IDA_STATUS_WAITING);
  26.     if ((szFilePath = AskFile(1, "*.txt", "Select output dump file:")) == 0)
  27.     {      
  28.         Message("Aborted.");
  29.         SetStatus(IDA_STATUS_READY);
  30.         return;
  31.     }
  32.    
  33.     // And create it..
  34.     if ((hFile = fopen(szFilePath, "wb")) != 0)
  35.     {
  36.         auto szFuncName, szFullName, BadHits;
  37.        
  38.         BadHits = 0;
  39.  
  40.         // Create the header
  41.         fprintf(hFile, "// Auto reconstructed from vtable block @ 0x%08X\n// from \"%s\", by ida_vtables.idc\n", pAddress, GetInputFile());
  42.        
  43.         /* For linux, skip the first entry */
  44.         if (Dword(pAddress) == 0)
  45.         {
  46.             pAddress = pAddress + 8;
  47.         }
  48.        
  49.         pAddress = pAddress + (skipAmt * 4);
  50.  
  51.         // Loop through the vtable block
  52.         while (pAddress != BADADDR)
  53.         {
  54.             auto real_addr;
  55.             real_addr = Dword(pAddress);
  56.                
  57.             szFuncName = Name(real_addr);
  58.             if (strlen(szFuncName) == 0)
  59.             {
  60.                 break;
  61.             }
  62.             szFullName = Demangle(szFuncName, INF_LONG_DN);
  63.             if (szFullName == "")
  64.             {
  65.                 szFullName = szFuncName;
  66.             }
  67.             if (strstr(szFullName, "_ZN") != -1)
  68.             {
  69.                 fclose(hFile);
  70.                 Warning("You must toggle GCC v3.x demangled names!\n");
  71.                 break;
  72.             }
  73.             fprintf(hFile, "%d\t%s\n", iIndex, szFullName);
  74.                        
  75.             pAddress = pAddress + 4;
  76.             iIndex++;
  77.         };
  78.  
  79.         fclose(hFile);
  80.         Message("Successfully wrote %d vtable entries.\n", iIndex);
  81.     }
  82.     else
  83.     {      
  84.         Message("** Error opening \"%s\"! Aborted **\n", szFilePath);
  85.         Warning("Error creating \"%s\"!\n", szFilePath);
  86.     }
  87.  
  88.     Message("\nDone.\n\n");
  89.     SetStatus(IDA_STATUS_READY);
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement