+/*
+ * 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 <ida.hpp>
#include <idp.hpp>
#include <name.hpp>
#include <frame.hpp>
#include <struct.hpp>
+#include <offset.hpp>
#include <auto.hpp>
#include <intel.hpp>
"offset",
"aam",
"text",
+ "size",
+ "c",
};
static int is_name_reserved(const char *name)
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);
}
}
}
- // 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)
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
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);
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, 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;
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
}
}
- 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");
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)