Skip to content

Commit

Permalink
Use anal.x86.udis86 when asm.bits=16 from anal.x86
Browse files Browse the repository at this point in the history
Fixes in the anal.x86.udis86 analysis
Add pcj command to show bytes of current block in json
  • Loading branch information
radare committed Nov 22, 2012
1 parent 70af249 commit 514dd14
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
5 changes: 5 additions & 0 deletions libr/anal/p/anal_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ static void anal_int(RAnal *anal, RAnalOp *op, x86im_instr_object io) {
}
}

extern int x86_udis86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len);
static int x86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {
x86im_instr_object io;
st64 imm;
Expand All @@ -807,6 +808,10 @@ static int x86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len)
if (data == NULL)
return 0;

if (anal->bits == 16) {
return x86_udis86_op (anal, op, addr, data, len);
}

memset (op, '\0', sizeof (RAnalOp));
op->type = R_ANAL_OP_TYPE_UNK;
op->addr = addr;
Expand Down
36 changes: 29 additions & 7 deletions libr/anal/p/anal_x86_udis86.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
#include "udis86/types.h"
#include "udis86/extern.h"

static ut64 getval(int bits, ud_operand_t *op) {
static st64 getval(ud_operand_t *op) {
int bits = op->size;
switch (bits) {
case 8: return op->lval.sbyte;
case 16: return op->lval.uword;
case 8: return (char)op->lval.sbyte;
case 16: return (short) op->lval.uword;
case 32: return op->lval.udword;
case 64: return op->lval.uqword;
}
return 0LL;
}
static int x86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {

int x86_udis86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {
int oplen;
struct ud u;
ud_init (&u);
Expand All @@ -34,11 +36,31 @@ static int x86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len)
switch (u.mnemonic) {
case UD_Ijmp:
op->type = R_ANAL_OP_TYPE_JMP;
op->jump = oplen + getval (anal->bits, &u.operand[0]);
op->jump = addr + oplen + getval (&u.operand[0]);
break;
case UD_Ijz:
case UD_Ijnz:
case UD_Ijb:
case UD_Ijbe:
case UD_Ija:
case UD_Ijs:
case UD_Ijns:
case UD_Ijo:
case UD_Ijno:
case UD_Ijp:
case UD_Ijnp:
case UD_Ijl:
case UD_Ijge:
case UD_Ijle:
case UD_Ijg:
case UD_Ijcxz:
op->type = R_ANAL_OP_TYPE_CJMP;
op->jump = addr + oplen + getval (&u.operand[0]);
op->fail = addr+oplen;
break;
case UD_Icall:
op->type = R_ANAL_OP_TYPE_CALL;
op->jump = oplen + getval (anal->bits, &u.operand[0]);
op->jump = oplen + getval (&u.operand[0]);
op->fail = addr+oplen;
break;
case UD_Iret:
Expand Down Expand Up @@ -216,7 +238,7 @@ struct r_anal_plugin_t r_anal_plugin_x86_udis86 = {
.bits = 16|32|64,
.init = NULL,
.fini = NULL,
.op = &x86_op,
.op = &x86_udis86_op,
.set_reg_profile = &set_reg_profile,
.fingerprint_bb = NULL,
.fingerprint_fcn = NULL,
Expand Down
11 changes: 10 additions & 1 deletion libr/print/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,16 @@ R_API void r_print_code(RPrint *p, ut64 addr, ut8 *buf, int len, char lang) {
int i, w = p->cols*0.7;
switch (lang) {
case '?':
eprintf ("Valid print code formats are: C and Python\n");
eprintf ("Valid print code formats are: JSON, C and Python (pcj, pc, pcp) \n");
break;
case 'j':
p->printf ("[");
for (i=0; !p->interrupt && i<len; i++) {
r_print_cursor (p, i, 1);
p->printf ("0x%02x%s", buf[i], (i+1<len)?",":"");
r_print_cursor (p, i, 0);
}
p->printf ("]\n");
break;
case 'P':
case 'p':
Expand Down

0 comments on commit 514dd14

Please sign in to comment.