X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=plugin%2Fsaveasm.cpp;h=3622cc8e0c893f7d4a60d65a4b98b726f141b659;hb=4741fdfeb90852f33f8954f67aaf9c32f2969c7d;hp=ba660767f4f05d5e3fe8452adff8bfeff07818c6;hpb=1caf86bb1f7a1eee66ee364dd96624fd55e2d487;p=ia32rtools.git diff --git a/plugin/saveasm.cpp b/plugin/saveasm.cpp index ba66076..3622cc8 100644 --- a/plugin/saveasm.cpp +++ b/plugin/saveasm.cpp @@ -42,6 +42,7 @@ static const char *reserved_names[] = { "type", "offset", "aam", + "text", }; static int is_name_reserved(const char *name) @@ -80,10 +81,11 @@ static int is_insn_jmp(uint16 itype) return itype == NN_jmp || (NN_ja <= itype && itype <= NN_jz); } -static void do_def_line(char *buf, size_t buf_size, const char *line) +static void do_def_line(char *buf, size_t buf_size, const char *line, + ea_t ea) { - char *endp = NULL; - ea_t ea, *ea_ret; + ea_t *ea_ret; + char *p; int len; tag_remove(line, buf, buf_size); // remove color codes @@ -94,17 +96,17 @@ static void do_def_line(char *buf, size_t buf_size, const char *line) } memmove(buf, buf + 9, len - 9 + 1); // rm address - if (IS_START(buf, "loc_")) { - ea = strtoul(buf + 4, &endp, 16); - if (ea != 0 && *endp == ':') { - ea_ret = (ea_t *)bsearch(&ea, nonlocal_bt, nonlocal_bt_cnt, - sizeof(nonlocal_bt[0]), nonlocal_bt_cmp); - if (ea_ret != 0) { - if (endp[1] != ' ') - msg("no trailing blank in '%s'\n", buf); - else - endp[1] = ':'; - } + p = buf; + while (*p && *p != ' ' && *p != ':') + p++; + if (*p == ':') { + ea_ret = (ea_t *)bsearch(&ea, nonlocal_bt, nonlocal_bt_cnt, + sizeof(nonlocal_bt[0]), nonlocal_bt_cmp); + if (ea_ret != 0) { + if (p[1] != ' ') + msg("no trailing blank in '%s'\n", buf); + else + p[1] = ':'; } } } @@ -331,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); } } @@ -364,9 +383,14 @@ static void idaapi run(int /*arg*/) ln.set_place(&pl); n = ln.get_linecnt(); for (i = 0; i < n - 1; i++) { - do_def_line(buf, sizeof(buf), ln.down()); + do_def_line(buf, sizeof(buf), ln.down(), ea); if (strstr(buf, "include")) continue; + p = strstr(buf, "assume cs"); + if (p != NULL) { + memmove(p + 1, p, strlen(p) + 1); + *p = ';'; + } fout_line++; qfprintf(fout, "%s\n", buf); @@ -375,6 +399,14 @@ static void idaapi run(int /*arg*/) memcpy(p, ".xmm", 4); fout_line++; qfprintf(fout, "%s\n", buf); + continue; + } + p = strstr(buf, ".model"); + if (p != NULL) { + qstrncpy(p, "include imports.inc", sizeof(buf) - (p - buf)); + fout_line++; + qfprintf(fout, "\n%s\n", buf); + continue; } } pl.lnnum = i; @@ -450,22 +482,26 @@ static void idaapi run(int /*arg*/) pass: n = ln.get_linecnt(); for (i = pl.lnnum; i < n; i++) { - do_def_line(buf, sizeof(buf), ln.down()); + do_def_line(buf, sizeof(buf), ln.down(), ea); + + char *fw; + for (fw = buf; *fw != 0 && *fw == ' '; ) + fw++; // patches.. if (drop_large) { - p = strstr(buf, "large "); + p = strstr(fw, "large "); if (p != NULL) memmove(p, p + 6, strlen(p + 6) + 1); } while (drop_rva) { - p = strstr(buf, " rva "); + p = strstr(fw, " rva "); if (p == NULL) break; memmove(p, p + 4, strlen(p + 4) + 1); } if (set_scale) { - p = strchr(buf, '['); + p = strchr(fw, '['); if (p != NULL) p = strchr(p, '+'); if (p != NULL && p[1] == 'e') { @@ -477,7 +513,7 @@ pass: } } else if (jmp_near) { - p = strchr(buf, 'j'); + p = strchr(fw, 'j'); while (p && *p != ' ') p++; while (p && *p == ' ') @@ -488,7 +524,7 @@ pass: } } if (word_imm) { - p = strstr(buf, ", "); + p = strstr(fw, ", "); if (p != NULL && '0' <= p[2] && p[2] <= '9') { p += 2; memmove(p + 9, p, strlen(p) + 1); @@ -496,7 +532,7 @@ pass: } } else if (dword_imm) { - p = strstr(buf, ", "); + p = strstr(fw, ", "); if (p != NULL && '0' <= p[2] && p[2] <= '9') { p += 2; memmove(p + 10, p, strlen(p) + 1); @@ -504,9 +540,9 @@ pass: } } else if (do_pushf) { - p = strstr(buf, "pushf"); + p = strstr(fw, "pushf"); if (p == NULL) - p = strstr(buf, "popf"); + p = strstr(fw, "popf"); if (p != NULL) { p = strchr(p, 'f') + 1; memmove(p + 1, p, strlen(p) + 1); @@ -514,6 +550,14 @@ pass: } } + if (fw[0] == 'e' && IS_START(fw, "end") && fw[3] == ' ') { + fout_line++; + qfprintf(fout, "include public.inc\n\n"); + + // kill entry point + fw[3] = 0; + } + fout_line++; qfprintf(fout, "%s\n", buf); }