From 67e20135ccbbbe36a90371cf2f970eaeee19d775 Mon Sep 17 00:00:00 2001 From: Nibble Date: Tue, 1 Mar 2011 19:16:29 +0100 Subject: [PATCH] * Add support for more opcodes in anal_x86 - lea, leave... * Update asm.decode with these changes * Add var $o for core->io->offset * Fix "function"|"loc" comments in disasm * Fix p% --- libr/anal/op.c | 9 +++++++++ libr/anal/p/anal_x86.c | 17 +++++++++++++++++ libr/core/cmd.c | 6 ++++-- libr/core/core.c | 1 + libr/include/r_anal.h | 2 ++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/libr/anal/op.c b/libr/anal/op.c index d58aea2658..90daf8c15f 100644 --- a/libr/anal/op.c +++ b/libr/anal/op.c @@ -88,6 +88,9 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { case R_ANAL_OP_TYPE_JMP: snprintf (ret, retsz, "goto 0x%"PFMT64x, op->jump); break; + case R_ANAL_OP_TYPE_UJMP: + snprintf (ret, retsz, "goto %s", r0); + break; case R_ANAL_OP_TYPE_PUSH: case R_ANAL_OP_TYPE_UPUSH: snprintf (ret, retsz, "push %s", a0); @@ -138,6 +141,9 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { snprintf (ret, retsz, "%s ^= %s", r0, a0); else snprintf (ret, retsz, "%s = %s ^ %s", r0, a0, a1); break; + case R_ANAL_OP_TYPE_LEA: + snprintf (ret, retsz, "%s -> %s", r0, a0); + break; case R_ANAL_OP_TYPE_CMP: ret[0] = '\0'; break; @@ -147,6 +153,9 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { case R_ANAL_OP_TYPE_RET: sprintf (ret, "ret"); break; + case R_ANAL_OP_TYPE_LEAVE: + sprintf (ret, "leave"); + break; default: sprintf (ret, "// ?"); break; diff --git a/libr/anal/p/anal_x86.c b/libr/anal/p/anal_x86.c index 388383afaa..b113e12c9b 100644 --- a/libr/anal/p/anal_x86.c +++ b/libr/anal/p/anal_x86.c @@ -753,6 +753,17 @@ static void anal_xor(RAnal *anal, RAnalOp *op, x86im_instr_object io) { } } +static void anal_lea(RAnal *anal, RAnalOp *op, x86im_instr_object io) { + st64 imm, disp; + imm = r_hex_bin_truncate (io.imm, io.imm_size); + disp = r_hex_bin_truncate (io.disp, io.disp_size); + + op->type = R_ANAL_OP_TYPE_LEA; + /* lea reg, [0x0ff | reg1+reg2+0x0ff] */ + op->dst = anal_fill_ai_rg (anal, io, 0); + op->src[0] = anal_fill_ai_mm (anal, io); +} + static void anal_int(RAnal *anal, RAnalOp *op, x86im_instr_object io) { op->type = R_ANAL_OP_TYPE_SWI; switch (io.id) { @@ -860,6 +871,12 @@ static int x86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) } else if (io.id == X86IM_IO_ID_NOP) /* nop */ op->type = R_ANAL_OP_TYPE_NOP; + else + if (io.id == X86IM_IO_ID_LEA) /* lea */ + anal_lea (anal, op, io); + else + if (io.id == X86IM_IO_ID_LEAVE) /* leave */ + op->type = R_ANAL_OP_TYPE_LEAVE; op->length = io.len; op->nopcode = io.opcode_count; } diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 7809e3aa49..4a7536604f 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -278,7 +278,8 @@ if (core->inc == 0) if (f->addr == at) { char *sign = r_anal_fcn_to_string (core->anal, f); r_cons_printf ("/ %s: %s (%d)\n| ", - f->type == R_ANAL_FCN_TYPE_FCN?"function":"loc", f->name, f->size); + (f->type==R_ANAL_FCN_TYPE_FCN||f->type==R_ANAL_FCN_TYPE_SYM)?"function":"loc", + f->name, f->size); if (sign) r_cons_printf ("// %s\n", sign); free (sign); pre = "| "; @@ -1550,6 +1551,7 @@ static int cmd_help(void *data, const char *input) { " ??? ; show this help\n" "$variables:\n" " $$ = here (current seek)\n" + " $o = here (current io offset)\n" " $s = file size\n" " $b = block size\n" " $j = jump address\n" @@ -1877,7 +1879,7 @@ static int cmd_print(void *data, const char *input) { switch (input[0]) { case '%': { - ut64 off = core->offset; + ut64 off = core->io->off; ut64 s = core->file?core->file->size:0; ut64 piece = 0; int w = core->print->cols * 4; diff --git a/libr/core/core.c b/libr/core/core.c index 997bac7d51..47467bc822 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -38,6 +38,7 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { case 's': return core->file->size; case '?': return core->num->value; case '$': return core->offset; + case 'o': return core->io->off; } } if (str[0]>'A') { diff --git a/libr/include/r_anal.h b/libr/include/r_anal.h index 1e26cb0a84..59b1a5fcb1 100644 --- a/libr/include/r_anal.h +++ b/libr/include/r_anal.h @@ -53,6 +53,8 @@ enum { R_ANAL_OP_TYPE_NOT = 0x8000000, R_ANAL_OP_TYPE_STORE = 0x10000000, /* store from register to memory */ R_ANAL_OP_TYPE_LOAD = 0x20000000, /* load from memory to register */ + R_ANAL_OP_TYPE_LEA = 0x40000000, + R_ANAL_OP_TYPE_LEAVE = 0x80000000, }; /* TODO: what to do with signed/unsigned conditionals? */