Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 1st, 2015  |  syntax: C++  |  size: 1.25 KB  |  views: 240  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print  |  QR code  |  clone
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #define UNLOADED_FILE   1
  2. #include <idc.idc>
  3.  
  4. static main(void) {
  5.         auto addr;
  6.         auto val;
  7.  
  8.         // Start from the first piece of code found...
  9.         addr = FindCode(0x00000000, SEARCH_DOWN);
  10.         // ... and keep going until we run out of code to process
  11.         while (addr != BADADDR) {
  12.                 // Get opcode and check it
  13.                 val = Word(addr);
  14.                 if ((val & 0xFFBF) == 0x4EB8) {
  15.                         // (jmp|jsr) (XXX).w
  16.                         FixupIns(addr, "(%s).w");
  17.                 } else if ((val & 0xFFBF) == 0x4EB9) {
  18.                         // (jmp|jsr) (XXX).l
  19.                         FixupIns(addr, "(%s).l");
  20.                 } else if ((val & 0xF1FF) == 0x41FA || (val & 0xFFBF) == 0x4EBA || val == 0x487A) {
  21.                         // (jmp|jsr|lea|pea) XXX(pc)
  22.                         FixupIns(addr, "%s(pc)");
  23.                 }
  24.                 addr = FindCode(addr, SEARCH_DOWN);
  25.         }
  26. }
  27.  
  28. static FixupIns(addr, fmt) {
  29.         auto mnem;
  30.         auto opnd;
  31.         auto name;
  32.         // Get current disassembly line for comparison
  33.         mnem = GetDisasm(addr);
  34.         // Reset offset (fixes an issue with pc-relative addresses)
  35.         OpOff(addr, 0, 0);
  36.         // Get value of operand (the instructions we are looking for only have one)
  37.         opnd = GetOpnd(addr, 0);
  38.         // Generate new representation
  39.         name = sprintf(fmt, opnd);
  40.         // Set manual operand representation
  41.         OpAlt(addr, 0, name);
  42.         // Log what we did
  43.         Message("%s:%08X: %-60s\t%-60s\n", SegName(addr), addr, mnem, GetDisasm(addr));
  44. }
clone this paste RAW Paste Data