partial ARM support
[ia32rtools.git] / tools / cmpmrg_text.c
index 5a0d296..015db89 100644 (file)
@@ -287,11 +287,11 @@ static int handle_pad(uint8_t *d_obj, uint8_t *d_exe, int maxlen)
 {
        static const uint8_t p7[7] = { 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00 };
        static const uint8_t p6[6] = { 0x8d, 0x9b, 0x00, 0x00, 0x00, 0x00 };
-       static const uint8_t p5[5] = { 0x05, 0x00, 0x00, 0x00, 0x00 };
-       static const uint8_t p4[4] = { 0x8d, 0x64, 0x24, 0x00 };
-       static const uint8_t p3[3] = { 0x8d, 0x49, 0x00 };
-       static const uint8_t p2[2] = { 0x8b, 0xff };
-       static const uint8_t p1[1] = { 0x90 };
+       static const uint8_t p5[5] = { 0x05, 0x00, 0x00, 0x00, 0x00 }; // add eax, 0
+       static const uint8_t p4[4] = { 0x8d, 0x64, 0x24, 0x00 }; // lea
+       static const uint8_t p3[3] = { 0x8d, 0x49, 0x00 }; // lea ecx, [ecx]
+       static const uint8_t p2[2] = { 0x8b, 0xff }; // mov edi, edi
+       static const uint8_t p1[1] = { 0x90 }; // nop
        int len;
        int i;
 
@@ -474,7 +474,7 @@ static void fill_int3(unsigned char *d, int len)
 
 int main(int argc, char *argv[])
 {
-       unsigned int base = 0, addr, addr2, end, sym, *t;
+       unsigned int base = 0, addr, end, sym, *t;
        struct my_sect_info s_text_obj, s_text_exe;
        struct my_symtab *raw_syms_obj = NULL;
        struct my_symtab *syms_obj = NULL;
@@ -482,26 +482,35 @@ int main(int argc, char *argv[])
        FILE *f_obj, *f_exe;
        SCNHDR tmphdr;
        long sztext_cmn;
+       int do_cmp = 1;
        int retval = 1;
        int left;
+       int arg;
        int ret;
        int i;
 
-       if (argc != 3) {
-               printf("usage:\n%s <a_obj> <exe>\n", argv[0]);
+       for (arg = 1; arg < argc; arg++) {
+               if (!strcmp(argv[arg], "-n"))
+                       do_cmp = 0;
+               else
+                       break;
+       }
+
+       if (argc != arg + 2) {
+               printf("usage:\n%s [-n] <a_obj> <exe>\n", argv[0]);
                return 1;
        }
 
-       f_obj = fopen(argv[1], "r+b");
+       f_obj = fopen(argv[arg++], "r+b");
        if (f_obj == NULL) {
-               fprintf(stderr, "%s", argv[1]);
+               fprintf(stderr, "%s", argv[1]);
                perror("");
                return 1;
        }
 
-       f_exe = fopen(argv[2], "r");
+       f_exe = fopen(argv[arg++], "r");
        if (f_exe == NULL) {
-               fprintf(stderr, "%s", argv[2]);
+               fprintf(stderr, "%s", argv[2]);
                perror("");
                return 1;
        }
@@ -539,6 +548,7 @@ int main(int argc, char *argv[])
                }
        }
 
+       if (do_cmp)
        for (i = 0; i < sztext_cmn; i++)
        {
                if (s_text_obj.data[i] == s_text_exe.data[i])
@@ -608,10 +618,12 @@ int main(int argc, char *argv[])
                        i--;
                        s_text_obj.reloc_cnt--;
                }
+#if 0
                // note: branches/calls already linked,
                // so only useful for dd refs
+               // XXX: rm'd because of switch tables
                else if (raw_syms_obj[sym].is_text) {
-                       addr2 = raw_syms_obj[sym].addr;
+                       unsigned int addr2 = raw_syms_obj[sym].addr;
                        if (s_text_obj.data[addr2] == 0xcc) {
                                printf("warning: reloc %08x -> %08x "
                                        "points to rm'd target '%s'\n",
@@ -619,6 +631,7 @@ int main(int argc, char *argv[])
                                        raw_syms_obj[sym].name);
                        }
                }
+#endif
        }
 
        // patch .text