diff --git a/binr/rabin2/Makefile b/binr/rabin2/Makefile index c859ca054c..a392223711 100644 --- a/binr/rabin2/Makefile +++ b/binr/rabin2/Makefile @@ -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 diff --git a/libr/anal/fcn.c b/libr/anal/fcn.c index 9942c3394b..6a0f802797 100644 --- a/libr/anal/fcn.c +++ b/libr/anal/fcn.c @@ -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); diff --git a/libr/anal/hint.c b/libr/anal/hint.c index 27d1a491f1..91307043a9 100644 --- a/libr/anal/hint.c +++ b/libr/anal/hint.c @@ -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) { diff --git a/libr/anal/op.c b/libr/anal/op.c index 20a4d26015..4c8842e2bc 100644 --- a/libr/anal/op.c +++ b/libr/anal/op.c @@ -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++; diff --git a/libr/core/canal.c b/libr/core/canal.c index 2f23817670..436cacdeee 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -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); } diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index f47df38b5e..847c810749 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -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] == '*') { diff --git a/libr/include/r_anal.h b/libr/include/r_anal.h index eb22436296..9508b6aa68 100644 --- a/libr/include/r_anal.h +++ b/libr/include/r_anal.h @@ -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);