* Set variable direction during function analysis
* Add argument "dir" to r_anal_var_add() * Fix reg handling in x86im plugin * Fix variable analysis in r_anal * Use plugin "x86" in ranal2 by default
This commit is contained in:
parent
f0d2279a0e
commit
eb88fa40fc
|
@ -148,7 +148,7 @@ int main(int argc, char **argv) {
|
|||
eprintf ("Invalid plugin\n");
|
||||
return 1;
|
||||
}
|
||||
} else r_anal_use (anal, "x86_x86im");
|
||||
} else r_anal_use (anal, "x86");
|
||||
if (!r_anal_set_bits (anal, bits))
|
||||
r_anal_set_bits (anal, 32);
|
||||
/* Get input & convert to bin if necessary */
|
||||
|
|
|
@ -72,11 +72,11 @@ R_API int r_anal_fcn(RAnal *anal, RAnalFcn *fcn, ut64 addr, ut8 *buf, ut64 len,
|
|||
if (aop.ref > 0) {
|
||||
varname = r_str_dup_printf ("arg_%x", aop.ref);
|
||||
r_anal_var_add (anal, fcn, aop.addr, aop.ref, R_ANAL_VAR_TYPE_ARG,
|
||||
NULL, varname, 1);
|
||||
R_ANAL_VAR_DIR_IN, NULL, varname, 1);
|
||||
} else {
|
||||
varname = r_str_dup_printf ("local_%x", -aop.ref);
|
||||
r_anal_var_add (anal, fcn, aop.addr, -aop.ref, R_ANAL_VAR_TYPE_LOCAL,
|
||||
NULL, varname, 1);
|
||||
R_ANAL_VAR_DIR_NONE, NULL, varname, 1);
|
||||
}
|
||||
free (varname);
|
||||
break;
|
||||
|
@ -84,11 +84,11 @@ R_API int r_anal_fcn(RAnal *anal, RAnalFcn *fcn, ut64 addr, ut8 *buf, ut64 len,
|
|||
if (aop.ref > 0) {
|
||||
varname = r_str_dup_printf ("arg_%x", aop.ref);
|
||||
r_anal_var_add (anal, fcn, aop.addr, aop.ref, R_ANAL_VAR_TYPE_ARG,
|
||||
NULL, varname, 0);
|
||||
R_ANAL_VAR_DIR_IN, NULL, varname, 0);
|
||||
} else {
|
||||
varname = r_str_dup_printf ("local_%x", -aop.ref);
|
||||
r_anal_var_add (anal, fcn, aop.addr, -aop.ref, R_ANAL_VAR_TYPE_LOCAL,
|
||||
NULL, varname, 0);
|
||||
R_ANAL_VAR_DIR_NONE, NULL, varname, 0);
|
||||
}
|
||||
free (varname);
|
||||
break;
|
||||
|
@ -238,7 +238,8 @@ R_API int r_anal_fcn_from_string(RAnal *a, RAnalFcn *f, const char *_str) {
|
|||
f->name = strdup (q+1);
|
||||
/* set return value */
|
||||
// TODO: simplify this complex api usage
|
||||
r_anal_var_add (a, f, 0LL, 0, R_ANAL_VAR_TYPE_RET, str, "ret", 1);
|
||||
r_anal_var_add (a, f, 0LL, 0, R_ANAL_VAR_TYPE_RET,
|
||||
R_ANAL_VAR_DIR_OUT, str, "ret", 1);
|
||||
|
||||
/* parse arguments */
|
||||
for (arg=0,p++;;) {
|
||||
|
@ -255,7 +256,8 @@ R_API int r_anal_fcn_from_string(RAnal *a, RAnalFcn *f, const char *_str) {
|
|||
r = r_str_chop (r+1);
|
||||
printf ("VAR %d=(%s)(%s)\n", arg, p, r);
|
||||
// TODO : increment arg by var size
|
||||
r_anal_var_add (a, f, 0LL, arg, R_ANAL_VAR_TYPE_RET, p, r, 1);
|
||||
r_anal_var_add (a, f, 0LL, arg, R_ANAL_VAR_TYPE_ARG,
|
||||
R_ANAL_VAR_DIR_IN, p, r, 1);
|
||||
arg++;
|
||||
p=q+1;
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@ static void anal_mov(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
if (io.mem_base == 0) { /* mov [0x0ff], reg */
|
||||
aop->ref = disp;
|
||||
} else
|
||||
if ((io.mem_base & X86IM_IO_ROP_ID_EBP) &&
|
||||
if ((X86IM_IO_ROP_GET_ID (io.mem_base) == X86IM_IO_ROP_ID_EBP) &&
|
||||
io.mem_index == 0) { /* mov [ebp+0x0ff], reg */
|
||||
aop->stackop = R_ANAL_STACK_SET;
|
||||
aop->ref = disp;
|
||||
|
@ -249,7 +249,7 @@ static void anal_mov(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
if (io.mem_base == 0) { /* mov reg, [0x0ff] */
|
||||
aop->ref = disp;
|
||||
} else
|
||||
if ((io.mem_base & X86IM_IO_ROP_ID_EBP) &&
|
||||
if ((X86IM_IO_ROP_GET_ID (io.mem_base) == X86IM_IO_ROP_ID_EBP) &&
|
||||
io.mem_index == 0) { /* mov reg, [ebp+0x0ff] */
|
||||
aop->stackop = R_ANAL_STACK_GET;
|
||||
aop->ref = disp;
|
||||
|
@ -262,7 +262,7 @@ static void anal_mov(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
if (io.mem_base == 0) { /* [0x0ff], 0x1 */
|
||||
aop->ref = disp;
|
||||
} else
|
||||
if ((io.mem_base & X86IM_IO_ROP_ID_EBP) &&
|
||||
if ((X86IM_IO_ROP_GET_ID (io.mem_base) == X86IM_IO_ROP_ID_EBP) &&
|
||||
io.mem_index == 0) { /* mov [ebp+0x0ff], 0x1 */
|
||||
aop->stackop = R_ANAL_STACK_SET;
|
||||
aop->ref = disp;
|
||||
|
@ -340,7 +340,7 @@ static void anal_cmp(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
if (io.mem_base == 0) { /* cmp [0x0ff], 0x1 */
|
||||
aop->ref = disp;
|
||||
} else
|
||||
if ((io.mem_base & X86IM_IO_ROP_ID_EBP) &&
|
||||
if ((X86IM_IO_ROP_GET_ID (io.mem_base) == X86IM_IO_ROP_ID_EBP) &&
|
||||
io.mem_index == 0) { /* cmp [ebp+0x0ff], 0x1*/
|
||||
aop->stackop = R_ANAL_STACK_GET;
|
||||
aop->ref = disp;
|
||||
|
@ -368,7 +368,7 @@ static void anal_push(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
if (io.mem_base == 0) { /* push [0x0ff] */
|
||||
aop->ref = disp;
|
||||
} else
|
||||
if ((io.mem_base & X86IM_IO_ROP_ID_EBP) &&
|
||||
if ((X86IM_IO_ROP_GET_ID (io.mem_base) == X86IM_IO_ROP_ID_EBP) &&
|
||||
io.mem_index == 0) { /* push [ebp+0x0ff] */
|
||||
aop->stackop = R_ANAL_STACK_GET;
|
||||
aop->ref = disp;
|
||||
|
@ -379,11 +379,11 @@ static void anal_push(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
aop->type = R_ANAL_OP_TYPE_UPUSH;
|
||||
aop->src[0] = anal_fill_ai_rg (anal, io, 0);
|
||||
/* TODO: Deprecate */
|
||||
if ((io.rop[0] & X86IM_IO_ROP_SGR_GPR_16))
|
||||
if (X86IM_IO_ROP_IS_GPR16(io.rop[0]))
|
||||
aop->stackptr = 2;
|
||||
else if ((io.rop[0] & X86IM_IO_ROP_SGR_GPR_32))
|
||||
else if (X86IM_IO_ROP_IS_GPR32(io.rop[0]))
|
||||
aop->stackptr = 4;
|
||||
else if ((io.rop[0] & X86IM_IO_ROP_SGR_GPR_64))
|
||||
else if (X86IM_IO_ROP_IS_GPR64(io.rop[0]))
|
||||
aop->stackptr = 8;
|
||||
break;
|
||||
case X86IM_IO_ID_PUSH_IM: /* push 0x1 */
|
||||
|
@ -424,13 +424,13 @@ static void anal_pop(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
case X86IM_IO_ID_POP_RG2:
|
||||
aop->dst = anal_fill_ai_rg (anal, io, 0);
|
||||
/* TODO: Deprecate */
|
||||
if ((io.rop[0] & X86IM_IO_ROP_SGR_GPR_16))
|
||||
if (X86IM_IO_ROP_IS_GPR16 (io.rop[0]))
|
||||
aop->stackptr = -2;
|
||||
else
|
||||
if ((io.rop[0] & X86IM_IO_ROP_SGR_GPR_32))
|
||||
if (X86IM_IO_ROP_IS_GPR32 (io.rop[0]))
|
||||
aop->stackptr = -4;
|
||||
else
|
||||
if ((io.rop[0] & X86IM_IO_ROP_SGR_GPR_64))
|
||||
if (X86IM_IO_ROP_IS_GPR64 (io.rop[0]))
|
||||
aop->stackptr = -8;
|
||||
break;
|
||||
case X86IM_IO_ID_POP_SR2: /* pop sr */
|
||||
|
@ -457,7 +457,7 @@ static void anal_add(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
if (io.mem_base == 0) { /* add [0x0ff], reg */
|
||||
aop->ref = disp;
|
||||
} else
|
||||
if ((io.mem_base & X86IM_IO_ROP_ID_EBP) &&
|
||||
if ((X86IM_IO_ROP_GET_ID (io.mem_base) == X86IM_IO_ROP_ID_EBP) &&
|
||||
io.mem_index == 0) { /* add [ebp+0x0ff], reg*/
|
||||
aop->stackop = R_ANAL_STACK_SET;
|
||||
aop->ref = disp;
|
||||
|
@ -470,7 +470,7 @@ static void anal_add(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
if (io.mem_base == 0) { /* add reg, [0x0ff] */
|
||||
aop->ref = disp;
|
||||
} else
|
||||
if ((io.mem_base & X86IM_IO_ROP_ID_EBP) &&
|
||||
if ((X86IM_IO_ROP_GET_ID (io.mem_base) == X86IM_IO_ROP_ID_EBP) &&
|
||||
io.mem_index == 0) { /* add reg, [ebp+0x0ff] */
|
||||
aop->stackop = R_ANAL_STACK_GET;
|
||||
aop->ref = disp;
|
||||
|
@ -494,7 +494,7 @@ static void anal_add(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
aop->dst = anal_fill_ai_rg (anal, io, 0);
|
||||
aop->src[0] = anal_fill_im (anal, io);
|
||||
/* TODO: Deprecate */
|
||||
if (io.rop[0] & X86IM_IO_ROP_ID_ESP) { /* add esp, 0x1 */
|
||||
if (X86IM_IO_ROP_GET_ID (io.rop[0]) == X86IM_IO_ROP_ID_ESP) { /* add esp, 0x1 */
|
||||
aop->stackop = R_ANAL_STACK_INCSTACK;
|
||||
aop->value = imm;
|
||||
aop->stackptr = -imm;
|
||||
|
@ -544,7 +544,7 @@ static void anal_sub(RAnal *anal, RAnalOp *aop, x86im_instr_object io) {
|
|||
aop->dst = anal_fill_ai_rg (anal, io, 0);
|
||||
aop->src[0] = anal_fill_im (anal, io);
|
||||
/* TODO: Deprecate */
|
||||
if (io.rop[0] & X86IM_IO_ROP_ID_ESP) { /* sub esp, 0x1*/
|
||||
if (X86IM_IO_ROP_GET_ID (io.rop[0]) == X86IM_IO_ROP_ID_ESP) { /* sub esp, 0x1*/
|
||||
aop->stackop = R_ANAL_STACK_INCSTACK;
|
||||
aop->value = imm;
|
||||
aop->stackptr = imm;
|
||||
|
|
|
@ -111,7 +111,7 @@ static int cmpdelta(RAnalVar *a, RAnalVar *b) {
|
|||
return (a->delta - b->delta);
|
||||
}
|
||||
|
||||
R_API int r_anal_var_add(RAnal *anal, RAnalFcn *fcn, ut64 from, int delta, int type, const char *vartype, const char *name, int set) {
|
||||
R_API int r_anal_var_add(RAnal *anal, RAnalFcn *fcn, ut64 from, int delta, int type, int dir, const char *vartype, const char *name, int set) {
|
||||
RAnalVar *var, *vari;
|
||||
RListIter *iter;
|
||||
if (from != 0LL)
|
||||
|
@ -125,6 +125,7 @@ R_API int r_anal_var_add(RAnal *anal, RAnalFcn *fcn, ut64 from, int delta, int t
|
|||
if (vartype)
|
||||
var->vartype = strdup (vartype);
|
||||
var->type = type;
|
||||
var->dir = dir;
|
||||
var->delta = delta;
|
||||
if (from != 0LL)
|
||||
r_anal_var_access_add (anal, var, from, set);
|
||||
|
|
|
@ -360,7 +360,7 @@ R_API int r_anal_var_type_add(RAnal *anal, const char *name, int size, const cha
|
|||
R_API int r_anal_var_type_del(RAnal *anal, const char *name);
|
||||
R_API RAnalVarType *r_anal_var_type_get(RAnal *anal, const char *name);
|
||||
R_API int r_anal_var_add(RAnal *anal, RAnalFcn *fcn, ut64 from, int delta, int type,
|
||||
const char *vartype, const char *name, int set);
|
||||
int dir, const char *vartype, const char *name, int set);
|
||||
R_API int r_anal_var_del(RAnal *anal, RAnalFcn *fcn, int delta, int type);
|
||||
R_API RAnalVar *r_anal_var_get(RAnal *anal, RAnalFcn *fcn, int delta, int type);
|
||||
R_API const char *r_anal_var_type_to_str (RAnal *anal, int type);
|
||||
|
|
Loading…
Reference in New Issue