Add R_ANAL_OP_MASK_OPEX ##anal

This commit is contained in:
Florian Märkl 2019-03-16 21:07:29 +01:00 committed by radare
parent c5d09f32e8
commit eae7e73230
14 changed files with 37 additions and 17 deletions

View File

@ -1064,7 +1064,7 @@ repeat:
return R_ANAL_RET_ERROR;
}
r_anal_op_fini (&op);
if ((oplen = r_anal_op (anal, &op, at, buf, bytes_read, R_ANAL_OP_MASK_ALL)) < 1) {
if ((oplen = r_anal_op (anal, &op, at, buf, bytes_read, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT)) < 1) {
RCore *core = anal->coreb.core;
if (!core || !core->bin || !core->bin->is_debugger) { // HACK
ut8 v = 0;

View File

@ -882,7 +882,6 @@ static void arm64math(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len,
static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) {
const char *postfix = NULL;
opex64 (&op->opex, *handle, insn);
r_strbuf_init (&op->esil);
r_strbuf_set (&op->esil, "");
@ -1515,8 +1514,6 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len
int pcdelta = (thumb ? 4 : 8);
ut32 mask = UT32_MAX;
opex (&op->opex, *handle, insn);
r_strbuf_init (&op->esil);
r_strbuf_set (&op->esil, "");
postfix = arm_prefix_cond (op, insn->detail->arm.cc);
@ -3083,11 +3080,17 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
op->id = insn->id;
if (a->bits == 64) {
anop64 (handle, op, insn);
if (mask & R_ANAL_OP_MASK_OPEX) {
opex64 (&op->opex, handle, insn);
}
if (mask & R_ANAL_OP_MASK_ESIL) {
analop64_esil (a, op, addr, buf, len, &handle, insn);
}
} else {
anop32 (a, handle, op, insn, thumb, (ut8*)buf, len);
if (mask & R_ANAL_OP_MASK_OPEX) {
opex (&op->opex, handle, insn);
}
if (mask & R_ANAL_OP_MASK_ESIL) {
analop_esil (a, op, addr, buf, len, &handle, insn, thumb);
}

View File

@ -190,7 +190,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
op->delay = 0;
op->id = insn->id;
opsize = op->size = insn->size;
opex (&op->opex, handle, insn);
if (mask & R_ANAL_OP_MASK_OPEX) {
opex (&op->opex, handle, insn);
}
switch (insn->id) {
case M68K_INS_INVALID:
op->type = R_ANAL_OP_TYPE_ILL;

View File

@ -182,7 +182,6 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len
r_strbuf_set (&op->esil, "");
if (insn) {
opex (&op->opex, *handle, insn);
// caching operands
for (i = 0; i < insn->detail->mips.op_count && i < 8; i++) {
*str[i] = 0;
@ -1034,6 +1033,9 @@ static int analop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len,
}
beach:
set_opdir (op);
if (insn && mask & R_ANAL_OP_MASK_OPEX) {
opex (&op->opex, hndl, insn);
}
if (mask & R_ANAL_OP_MASK_ESIL) {
if (analop_esil (anal, op, addr, buf, len, &hndl, insn) != 0) {
r_strbuf_fini (&op->esil);

View File

@ -581,7 +581,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
if (n < 1) {
op->type = R_ANAL_OP_TYPE_ILL;
} else {
opex (&op->opex, handle, insn);
if (mask & R_ANAL_OP_MASK_OPEX) {
opex (&op->opex, handle, insn);
}
struct Getarg gop = {
.handle = handle,
.insn = insn,

View File

@ -133,7 +133,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
if (n < 1) {
op->type = R_ANAL_OP_TYPE_ILL;
} else {
opex (&op->opex, handle, insn);
if (mask & R_ANAL_OP_MASK_OPEX) {
opex (&op->opex, handle, insn);
}
op->size = insn->size;
op->id = insn->id;
switch (insn->id) {

View File

@ -67,7 +67,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
if (n < 1) {
op->type = R_ANAL_OP_TYPE_ILL;
} else {
opex (&op->opex, handle, insn);
if (mask & R_ANAL_OP_MASK_OPEX) {
opex (&op->opex, handle, insn);
}
op->size = insn->size;
switch (insn->id) {
case SYSZ_INS_BRCL:

View File

@ -85,7 +85,7 @@ int tms320_op(RAnal * anal, RAnalOp * op, ut64 addr, const ut8 * buf, int len, R
if (anal->cpu && r_str_casecmp(anal->cpu, "c64x") == 0) {
#ifdef CAPSTONE_TMS320C64X_H
return tms320c64x_analop (anal, op, addr, buf, len);
return tms320c64x_analop (anal, op, addr, buf, len, mask);
#else
return -1;
#endif

View File

@ -59,7 +59,7 @@ static void opex(RStrBuf *buf, csh handle, cs_insn *insn) {
r_strbuf_append (buf, "]}");
}
static int tms320c64x_analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
static int tms320c64x_analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
static csh handle = 0;
static int omode;
cs_insn *insn;
@ -90,7 +90,9 @@ static int tms320c64x_analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, i
if (n < 1) {
op->type = R_ANAL_OP_TYPE_ILL;
} else {
opex (&op->opex, handle, insn);
if (mask & R_ANAL_OP_MASK_OPEX) {
opex (&op->opex, handle, insn);
}
op->size = insn->size;
op->id = insn->id;
switch (insn->id) {

View File

@ -355,7 +355,6 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len,
if (op->prefix & R_ANAL_OP_PREFIX_REP) {
esilprintf (op, "%s,!,?{,BREAK,},", counter);
}
opex (&op->opex, *handle, insn);
switch (insn->id) {
case X86_INS_FNOP:
@ -2807,6 +2806,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
if (mask & R_ANAL_OP_MASK_ESIL) {
anop_esil (a, op, addr, buf, len, &handle, insn);
}
if (mask & R_ANAL_OP_MASK_OPEX) {
opex (&op->opex, handle, insn);
}
if (mask & R_ANAL_OP_MASK_VAL) {
op_fillval (a, op, &handle, insn);
}

View File

@ -82,7 +82,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
if (n < 1) {
op->type = R_ANAL_OP_TYPE_ILL;
} else {
opex (&op->opex, handle, insn);
if (mask & R_ANAL_OP_MASK_OPEX) {
opex (&op->opex, handle, insn);
}
op->size = insn->size;
op->id = insn->id;
switch (insn->id) {

View File

@ -2928,7 +2928,7 @@ R_API void r_core_recover_vars(RCore *core, RAnalFunction *fcn, bool argonly) {
if (r_cons_is_breaked ()) {
break;
}
op = r_core_anal_op (core, pos, R_ANAL_OP_MASK_ALL);
op = r_core_anal_op (core, pos, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT);
if (!op) {
//eprintf ("Cannot get op\n");
break;
@ -4428,7 +4428,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) {
}
r_anal_op_fini (&op);
r_asm_set_pc (core->assembler, cur);
if (!r_anal_op (core->anal, &op, cur, buf + i, iend - i, R_ANAL_OP_MASK_ALL)) {
if (!r_anal_op (core->anal, &op, cur, buf + i, iend - i, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT)) {
i += minopsize - 1; // XXX dupe in op.size below
}
// if (op.type & 0x80000000 || op.type == 0) {

View File

@ -1452,7 +1452,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
r_asm_set_pc (core->assembler, addr);
(void)r_asm_disassemble (core->assembler, &asmop, buf + idx, len - idx);
ret = r_anal_op (core->anal, &op, core->offset + idx, buf + idx, len - idx,
R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT);
R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_OPEX | R_ANAL_OP_MASK_HINT);
esilstr = R_STRBUF_SAFEGET (&op.esil);
opexstr = R_STRBUF_SAFEGET (&op.opex);
char *mnem = strdup (r_asm_op_get_asm (&asmop));

View File

@ -468,6 +468,7 @@ typedef enum {
R_ANAL_OP_MASK_ESIL = 1, // It fills RAnalop->esil info
R_ANAL_OP_MASK_VAL = 2, // It fills RAnalop->dst/src info
R_ANAL_OP_MASK_HINT = 4, // It calls r_anal_op_hint to override anal options
R_ANAL_OP_MASK_OPEX = 8, // It fills RAnalop->opex info
R_ANAL_OP_MASK_ALL = R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT
} RAnalOpMask;