}
// unlike pushes after sub esp,
- // IDA treats pushed like this as part of var area
+ // IDA treats pushes like this as part of var area
*fsz += seq_len * 4;
}
for (; i < opcnt; i++) {
if (i > 0 && g_labels[i] != NULL)
break;
- if (ops[i].op == OP_PUSH || (ops[i].flags & (OPF_JMP|OPF_TAIL)))
+ if (ops[i].flags & (OPF_JMP|OPF_TAIL))
+ break;
+ if (ops[i].flags & OPF_DONE)
+ continue;
+ if (ops[i].op == OP_PUSH)
break;
if (ops[i].op == OP_SUB && ops[i].operand[0].reg == xSP
&& ops[i].operand[1].type == OPT_CONST)
ops[j].flags |= OPF_RMD | OPF_DONE | OPF_NOREGS;
i = j + 1;
*esp_sub = 1;
+ break;
}
- break;
}
}
for (; j >= 0; j--) {
if (ops[j].op != OP_MOV)
break;
- if (ops[j].operand[0].type != OPT_REGMEM)
- break;
- if (strstr(ops[j].operand[0].name, "arg_") == NULL)
- break;
+ if (ops[j].operand[0].type == OPT_REGMEM
+ && strstr(ops[j].operand[0].name, "arg_") != NULL)
+ continue;
+ if (ops[j].operand[0].type == OPT_REG)
+ continue; // assume arg-reg mov
+ break;
}
}
if (ret < 0)
return ret;
+ if (pp->is_unresolved) {
+ pp->argc += ret;
+ pp->argc_stack += ret;
+ for (a = 0; a < pp->argc; a++)
+ if (pp->arg[a].type.name == NULL)
+ pp->arg[a].type.name = strdup("int");
+ }
+
if (arg_grp != 0) {
// propagate arg_grp
for (a = 0; a < pp->argc; a++) {
}
}
- if (pp->is_unresolved) {
- pp->argc += ret;
- pp->argc_stack += ret;
- for (a = 0; a < pp->argc; a++)
- if (pp->arg[a].type.name == NULL)
- pp->arg[a].type.name = strdup("int");
- }
-
return ret;
}
regmask_stack |= 1 << tmp_op->operand[0].reg;
}
- if (!((regmask_stack & (1 << xCX))
- && (regmask_stack & (1 << xDX))))
+ // quick dumb check for potential reg-args
+ for (j = i - 1; j >= 0 && ops[j].op == OP_MOV; j--)
+ if (ops[j].operand[0].type == OPT_REG)
+ regmask_stack &= ~(1 << ops[j].operand[0].reg);
+
+ if ((regmask_stack & (mxCX|mxDX)) != (mxCX|mxDX)
+ && ((regmask | regmask_arg) & (mxCX|mxDX)))
{
if (pp->argc_stack != 0
- || ((regmask | regmask_arg) & ((1 << xCX)|(1 << xDX))))
+ || ((regmask | regmask_arg) & (mxCX|mxDX)))
{
pp_insert_reg_arg(pp, "ecx");
pp->is_fastcall = 1;
regmask |= 1 << xCX;
}
if (pp->argc_stack != 0
- || ((regmask | regmask_arg) & (1 << xDX)))
+ || ((regmask | regmask_arg) & mxDX))
{
pp_insert_reg_arg(pp, "edx");
regmask_init |= 1 << xDX;
default:
break;
}
+ }
+
+ // pass8: final adjustments
+ for (i = 0; i < opcnt; i++)
+ {
+ po = &ops[i];
+ if (po->flags & (OPF_RMD|OPF_DONE))
+ continue;
- // this might need it's own pass...
if (po->op != OP_FST && po->p_argnum > 0)
save_arg_vars[po->p_arggrp] |= 1 << (po->p_argnum - 1);