X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=plugin%2Fsaveasm.cpp;h=aee282f7581fefde4c6077f88cf10dd8357c282b;hb=feb0ee5dc9eb3ab94bf488b4f4c5a07999f6b1bb;hp=5f704ef31b2aab7a6eb5c50e578e439cdf01d39f;hpb=de8a204c7581e428a387640fc9131ff3ee9e2823;p=ia32rtools.git diff --git a/plugin/saveasm.cpp b/plugin/saveasm.cpp index 5f704ef..aee282f 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 @@ -239,7 +248,10 @@ static void idaapi run(int /*arg*/) if (cmd.Operands[o].type == o_mem) { tmp_ea = cmd.Operands[o].addr; flags_t tmp_ea_flags = get_flags_novalue(tmp_ea); - if (!isUnknown(tmp_ea_flags)) { + // ..but base float is ok.. + int is_flt = isDwrd(tmp_ea_flags) || isFloat(tmp_ea_flags); + if (!is_flt && !isUnknown(tmp_ea_flags)) + { buf[0] = 0; get_name(ea, tmp_ea, buf, sizeof(buf)); msg("%x: undefining %x '%s'\n", ea, tmp_ea, buf); @@ -248,8 +260,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) @@ -264,6 +276,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 @@ -412,7 +442,7 @@ static void idaapi run(int /*arg*/) for (;;) { int drop_large = 0, do_rva = 0, set_scale = 0, jmp_near = 0; - int word_imm = 0, dword_imm = 0, do_pushf = 0; + int word_imm = 0, dword_imm = 0, do_pushf = 0, do_nops = 0; if ((ea >> 14) != ui_ea_block) { ui_ea_block = ea >> 14; @@ -470,6 +500,12 @@ static void idaapi run(int /*arg*/) if (get_word(ea + opr.offb) == (ushort)opr.value) word_imm = 1; } + else if (opr.type == o_displ && opr.addr == 0 + && opr.offb != 0 && opr.hasSIB && opr.sib == 0x24) + { + // uses [esp+0] with 0 encoded into op + do_nops++; + } } } else { // not code @@ -566,6 +602,9 @@ pass: qfprintf(fout, "%s\n", buf); } + while (do_nops-- > 0) + qfprintf(fout, " nop ; adj\n"); + // note: next_head skips some undefined stuff ea = next_not_tail(ea); // correct? if (ea == BADADDR)