X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=plugin%2Fsaveasm.cpp;h=0732e092c0148d2bccb134ce710caeee0cef3a33;hb=fc1c61f5af4e34ed1a813cfdcbe4b9f1b585763c;hp=3622cc8e0c893f7d4a60d65a4b98b726f141b659;hpb=b25f320a4cbf26d2b28d9f74ff7c495516a710d0;p=ia32rtools.git diff --git a/plugin/saveasm.cpp b/plugin/saveasm.cpp index 3622cc8..0732e09 100644 --- a/plugin/saveasm.cpp +++ b/plugin/saveasm.cpp @@ -1,3 +1,11 @@ +/* + * ia32rtools + * (C) notaz, 2013,2014 + * + * This work is licensed under the terms of 3-clause BSD license. + * See COPYING file in the top-level directory. + */ + #define NO_OBSOLETE_FUNCS #include #include @@ -8,6 +16,7 @@ #include #include #include +#include #include #include @@ -43,6 +52,8 @@ static const char *reserved_names[] = { "offset", "aam", "text", + "size", + "c", }; static int is_name_reserved(const char *name) @@ -246,8 +257,8 @@ static void idaapi run(int /*arg*/) } } } - // detect code alignment else if (cmd.itype == NN_lea) { + // detect code alignment if (cmd.Operands[0].reg == cmd.Operands[1].reg && cmd.Operands[1].type == o_displ && cmd.Operands[1].addr == 0) @@ -262,6 +273,24 @@ static void idaapi run(int /*arg*/) doAlign(ea, tmp_ea - ea, n); } } + else if (!isDefArg1(ea_flags) + && cmd.Operands[1].type == o_mem // why o_mem? + && cmd.Operands[1].dtyp == dt_dword) + { + if (inf.minEA <= cmd.Operands[1].addr + && cmd.Operands[1].addr < inf.maxEA) + { + // lea to segments, like ds:58D6A8h[edx*8] + msg("%x: lea offset to %x\n", ea, cmd.Operands[1].addr); + op_offset(ea, 1, REF_OFF32); + } + else + { + // ds:0[eax*8] -> [eax*8+0] + msg("%x: dropping ds: for %x\n", ea, cmd.Operands[1].addr); + op_hex(ea, 1); + } + } } // find non-local branches @@ -386,11 +415,6 @@ static void idaapi run(int /*arg*/) 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); @@ -406,14 +430,15 @@ static void idaapi run(int /*arg*/) qstrncpy(p, "include imports.inc", sizeof(buf) - (p - buf)); fout_line++; qfprintf(fout, "\n%s\n", buf); - continue; + i++; + break; } } pl.lnnum = i; 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) { @@ -476,7 +501,7 @@ static void idaapi run(int /*arg*/) } else { // not code if (isOff0(ea_flags)) - drop_rva = 1; + do_rva = 1; } pass: @@ -494,11 +519,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, '['); @@ -550,7 +576,12 @@ pass: } } - if (fw[0] == 'e' && IS_START(fw, "end") && fw[3] == ' ') { + if (fw[0] == 'a' && IS_START(fw, "assume cs")) { + // "assume cs" causes problems with ext syms + memmove(fw + 1, fw, strlen(fw) + 1); + *fw = ';'; + } + else if (fw[0] == 'e' && IS_START(fw, "end") && fw[3] == ' ') { fout_line++; qfprintf(fout, "include public.inc\n\n");