Advertisement
Guest User

Fixed-AddrFixup.idc

a guest
Feb 24th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  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.     OpAlt(addr, 0, "");
  36.     OpOff(addr, 0, 0);
  37.     // Get value of operand (the instructions we are looking for only have one)
  38.     opnd = GetOpnd(addr, 0);
  39.     // Generate new representation
  40.     if (strstr(opnd, "(") == 0) {
  41.         name = sprintf(fmt, substr(opnd, 1, strlen(opnd)-3));
  42.         if (strstr(name, opnd) != -1) {
  43.             return;
  44.         }
  45.     } else if (strstr(opnd, "(pc)") > -1) {
  46.         name = sprintf(fmt, substr(opnd, 0, strlen(opnd)-4));
  47.         if (strstr(name, opnd) != -1) {
  48.             return;
  49.         }
  50.     }
  51.     name = sprintf(fmt, opnd);
  52.     // Set manual operand representation
  53.     OpAlt(addr, 0, name);
  54.     // Log what we did
  55.     Message("%s:%08X: %-60s\t%-60s\n", SegName(addr), addr, mnem, GetDisasm(addr));
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement