Added val op hints to let the user define jmptbl sizes ##anal

This commit is contained in:
radare 2019-07-07 18:51:21 +02:00 committed by GitHub
parent 0d1c3c4f33
commit 56cdeee666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 3 deletions

View File

@ -11,7 +11,7 @@ include ../../libr/main/deps.mk
include ../../shlr/zip/deps.mk
include ../../shlr/gdb/deps.mk
include ../../shlr/java/deps.mk
include ../../shlr/grub/deps.mk
#include ../../shlr/grub/deps.mk
include ../../shlr/bochs/deps.mk
include ../../shlr/qnx/deps.mk
include ../../shlr/ar/deps.mk

View File

@ -848,6 +848,16 @@ static bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAna
anal->iob.read_at (anal->iob.io, prev_bb->addr, (ut8 *) bb_buf, prev_bb->size);
isValid = false;
RAnalHint *hint = r_anal_hint_get (anal, addr);
if (hint) {
if (hint->val != UT64_MAX) {
*table_size = hint->val;
}
eprintf ("TMPAPVAL %llx, %llx\n", addr, tmp_aop.val);
r_anal_hint_free (hint);
return true;
}
for (i = 0; i < prev_bb->op_pos_size; i++) {
ut64 prev_pos = prev_bb->op_pos[i];
ut64 op_addr = prev_bb->addr + prev_pos;
@ -857,7 +867,7 @@ static bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAna
int buflen = prev_bb->size - prev_pos;
int len = r_anal_op (anal, &tmp_aop, op_addr,
bb_buf + prev_pos, buflen,
R_ANAL_OP_MASK_BASIC);
R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT);
ut32 type = tmp_aop.type & R_ANAL_OP_TYPE_MASK;
if (len < 1 || type != R_ANAL_OP_TYPE_CMP) {
r_anal_op_fini (&tmp_aop);

View File

@ -130,6 +130,10 @@ R_API void r_anal_hint_set_stackframe(RAnal *a, ut64 addr, ut64 size) {
setHint (a, "Frame:", addr, NULL, size);
}
R_API void r_anal_hint_set_val(RAnal *a, ut64 addr, ut64 v) {
setHint (a, "val:", addr, NULL, v);
}
R_API void r_anal_hint_unset_size(RAnal *a, ut64 addr) {
unsetHint(a, "size:", addr);
}
@ -186,6 +190,10 @@ R_API void r_anal_hint_unset_fail(RAnal *a, ut64 addr) {
unsetHint (a, "fail:", addr);
}
R_API void r_anal_hint_unset_val (RAnal *a, ut64 v) {
unsetHint (a, "val:", v);
}
R_API void r_anal_hint_unset_type (RAnal *a, ut64 addr) {
unsetHint (a, "type:", addr);
}
@ -249,6 +257,7 @@ R_API RAnalHint *r_anal_hint_from_string(RAnal *a, ut64 addr, const char *str) {
hint->jump = UT64_MAX;
hint->fail = UT64_MAX;
hint->ret = UT64_MAX;
hint->val = UT64_MAX;
hint->stackframe = UT64_MAX;
char *s = strdup (str);
if (!s) {
@ -282,6 +291,7 @@ R_API RAnalHint *r_anal_hint_from_string(RAnal *a, ut64 addr, const char *str) {
case 'e': hint->esil = (char*)sdb_decode (nxt, 0); break;
case 'a': hint->arch = (char*)sdb_decode (nxt, 0); break;
case 'h': hint->high = sdb_atoi (nxt); break;
case 'v': hint->val = sdb_atoi (nxt); break;
}
}
if (!nxt || !nxt2) {

View File

@ -743,6 +743,10 @@ R_API int r_anal_op_family_from_string(const char *f) {
R_API int r_anal_op_hint(RAnalOp *op, RAnalHint *hint) {
int changes = 0;
if (hint) {
if (hint->val != UT64_MAX) {
op->val = hint->val;
changes++;
}
if (hint->type > 0) {
op->type = hint->type;
changes++;

View File

@ -970,6 +970,9 @@ static void print_hint_h_format(RAnalHint* hint) {
HINTCMD (hint, immbase, " immbase=%d");
HINTCMD (hint, esil, " esil='%s'");
HINTCMD (hint, ptr, " ptr=0x%"PFMT64x);
if (hint->val != UT64_MAX) {
r_cons_printf (" val=0x%08"PFMT64x, hint->val);
}
if (hint->jump != UT64_MAX) {
r_cons_printf (" jump=0x%08"PFMT64x, hint->jump);
}

View File

@ -555,6 +555,7 @@ static const char *help_msg_ah[] = {
"ahs", " 4", "set opcode size=4",
"ahS", " jz", "set asm.syntax=jz for this opcode",
"aht", " call", "change opcode type (see aht?)",
"ahv", " val", "change opcode's val field (useful to set jmptbl sizes in jmp rax)",
NULL
};
@ -1642,7 +1643,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
pj_j (pj, opexstr);
pj_kn (pj, "addr", core->offset + idx);
pj_ks (pj, "bytes", r_hex_bin2strdup (buf, ret));
if (op.ptr != UT64_MAX) {
if (op.val != UT64_MAX) {
pj_kn (pj, "val", op.val);
}
if (op.ptr != UT64_MAX) {
@ -6967,6 +6968,15 @@ static void cmd_anal_hint(RCore *core, const char *input) {
r_core_anal_hint_list (core->anal, input[0]);
}
break;
case 'v': // "ahv"
if (input[1] == ' ') {
r_anal_hint_set_val (
core->anal, core->offset,
r_num_math (core->num, input + 1));
} else if (input[1] == '-') {
r_anal_hint_unset_val (core->anal, core->offset);
}
break;
case '-': // "ah-"
if (input[1]) {
if (input[1] == '*') {

View File

@ -724,6 +724,7 @@ typedef struct r_anal_t {
typedef struct r_anal_hint_t {
ut64 addr;
ut64 ptr;
ut64 val; // used to hint jmp rax
ut64 jump;
ut64 fail;
ut64 ret; // hint for function ret values
@ -1739,6 +1740,8 @@ R_API void r_anal_hint_set_pointer (RAnal *a, ut64 addr, ut64 jump);
R_API void r_anal_hint_set_ret(RAnal *a, ut64 addr, ut64 val);
R_API void r_anal_hint_set_high(RAnal *a, ut64 addr);
R_API void r_anal_hint_set_stackframe(RAnal *a, ut64 addr, ut64 size);
R_API void r_anal_hint_set_val (RAnal *a, ut64 addr, ut64 v);
R_API void r_anal_hint_unset_val (RAnal *a, ut64 addr);
R_API void r_anal_hint_unset_high(RAnal *a, ut64 addr);
R_API void r_anal_hint_unset_size(RAnal *a, ut64 addr);
R_API void r_anal_hint_unset_bits(RAnal *a, ut64 addr);