plugin: replace rva with offset, don't rm
[ia32rtools.git] / plugin / saveasm.cpp
index efe8e9d..2d07728 100644 (file)
@@ -333,9 +333,26 @@ static void idaapi run(int /*arg*/)
       continue;
     }
 
-    if (is_name_reserved(name)) {
+    // rename vars with '?@' (funcs are ok)
+    int change_qat = 0;
+    ea_flags = get_flags_novalue(ea);
+    if (!isCode(ea_flags) && strpbrk(name, "?@"))
+      change_qat = 1;
+
+    if (change_qat || is_name_reserved(name)) {
       msg("%x: renaming name '%s'\n", ea, name);
       qsnprintf(buf, sizeof(buf), "%s_g", name);
+
+      if (change_qat) {
+        for (p = buf; *p != 0; p++) {
+          if (*p == '?' || *p == '@') {
+            qsnprintf(buf2, sizeof(buf2), "%02x", (unsigned char)*p);
+            memmove(p + 1, p, strlen(p) + 1);
+            memcpy(p, buf2, 2);
+          }
+        }
+      }
+
       set_name(ea, buf);
     }
   }
@@ -396,7 +413,7 @@ static void idaapi run(int /*arg*/)
 
   for (;;)
   {
-    int drop_large = 0, drop_rva = 0, set_scale = 0, jmp_near = 0;
+    int drop_large = 0, do_rva = 0, set_scale = 0, jmp_near = 0;
     int word_imm = 0, dword_imm = 0, do_pushf = 0;
 
     if ((ea >> 14) != ui_ea_block) {
@@ -459,7 +476,7 @@ static void idaapi run(int /*arg*/)
     }
     else { // not code
       if (isOff0(ea_flags))
-        drop_rva = 1;
+        do_rva = 1;
     }
 
 pass:
@@ -477,11 +494,12 @@ pass:
         if (p != NULL)
           memmove(p, p + 6, strlen(p + 6) + 1);
       }
-      while (drop_rva) {
+      while (do_rva) {
         p = strstr(fw, " rva ");
         if (p == NULL)
           break;
-        memmove(p, p + 4, strlen(p + 4) + 1);
+        memmove(p + 4 + 3, p + 4, strlen(p + 4) + 1);
+        memcpy(p + 1, "offset", 6);
       }
       if (set_scale) {
         p = strchr(fw, '[');