Fix #2536 - Implement `ahS` and fix `ah` in `pd`
This commit is contained in:
parent
bb76bb1794
commit
0697103f7d
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2013-2014 - pancake */
|
||||
/* radare - LGPL - Copyright 2013-2015 - pancake */
|
||||
|
||||
#include <r_anal.h>
|
||||
|
||||
|
@ -24,7 +24,7 @@ static void setHint (RAnal *a, const char *type, ut64 addr, const char *s, ut64
|
|||
char key[128], val[128], *nval = NULL;
|
||||
setf (key, "hint.0x%"PFMT64x, addr);
|
||||
idx = sdb_array_indexof (DB, key, type, 0);
|
||||
if (s) nval = sdb_encode ((const ut8*)s, 0);
|
||||
if (s) nval = sdb_encode ((const ut8*)s, -1);
|
||||
else nval = sdb_itoa (ptr, val, 16);
|
||||
if (idx != -1) {
|
||||
if (!s) nval = sdb_itoa (ptr, val, 16);
|
||||
|
@ -52,6 +52,10 @@ R_API void r_anal_hint_set_arch (RAnal *a, ut64 addr, const char *arch) {
|
|||
setHint (a, "arch:", addr, r_str_trim_const (arch), 0);
|
||||
}
|
||||
|
||||
R_API void r_anal_hint_set_syntax (RAnal *a, ut64 addr, const char *syn) {
|
||||
setHint (a, "Syntax:", addr, syn, 0);
|
||||
}
|
||||
|
||||
R_API void r_anal_hint_set_opcode (RAnal *a, ut64 addr, const char *opcode) {
|
||||
setHint (a, "opcode:", addr, r_str_trim_const (opcode), 0);
|
||||
}
|
||||
|
@ -73,6 +77,7 @@ R_API void r_anal_hint_free (RAnalHint *h) {
|
|||
free (h->arch);
|
||||
free (h->esil);
|
||||
free (h->opcode);
|
||||
free (h->syntax);
|
||||
free (h);
|
||||
}
|
||||
|
||||
|
@ -91,6 +96,7 @@ R_API RAnalHint *r_anal_hint_from_string(RAnal *a, ut64 addr, const char *str) {
|
|||
case 'p': hint->ptr = sdb_atoi (r); break;
|
||||
case 'b': hint->bits = sdb_atoi (r); break;
|
||||
case 's': hint->size = sdb_atoi (r); break;
|
||||
case 'S': hint->syntax = (char*)sdb_decode (r, 0); break;
|
||||
case 'o': hint->opcode = (char*)sdb_decode (r, 0); break;
|
||||
case 'e': hint->esil = (char*)sdb_decode (r, 0); break;
|
||||
case 'a': hint->arch = (char*)sdb_decode (r, 0); break;
|
||||
|
|
|
@ -51,6 +51,8 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
}
|
||||
if (a->syntax == R_ASM_SYNTAX_ATT) {
|
||||
cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT);
|
||||
} else {
|
||||
cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_INTEL);
|
||||
}
|
||||
op->size = 1;
|
||||
#if USE_ITER_API
|
||||
|
|
|
@ -63,6 +63,13 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|||
if (opsize<1 || strstr (op->buf_asm, "invalid"))
|
||||
opsize = 0;
|
||||
op->size = opsize;
|
||||
if (a->syntax == R_ASM_SYNTAX_JZ) {
|
||||
if (!strncmp (op->buf_asm, "je ", 3)) {
|
||||
memcpy (op->buf_asm, "jz", 2);
|
||||
} else if (!strncmp (op->buf_asm, "jne ", 4)) {
|
||||
memcpy (op->buf_asm, "jnz", 3);
|
||||
}
|
||||
}
|
||||
return opsize;
|
||||
}
|
||||
|
||||
|
|
|
@ -580,7 +580,6 @@ static int cmd_anal_fcn(RCore *core, const char *input) {
|
|||
ut64 size = 0LL;
|
||||
RAnalDiff *diff = NULL;
|
||||
int type = R_ANAL_FCN_TYPE_FCN;
|
||||
|
||||
if (n > 2) {
|
||||
switch(n) {
|
||||
case 5:
|
||||
|
@ -2046,6 +2045,7 @@ static void cmd_anal_hint(RCore *core, const char *input) {
|
|||
"ahc", " 0x804804", "override call/jump address",
|
||||
"ahf", " 0x804840", "override fallback address for call",
|
||||
"ahs", " 4", "set opcode size=4",
|
||||
"ahS", " jz", "set asm.syntax=jz for this opcode",
|
||||
"aho", " foo a0,33", "replace opcode string",
|
||||
"ahe", " eax+=3", "set vm analysis string",
|
||||
NULL };
|
||||
|
@ -2089,13 +2089,24 @@ static void cmd_anal_hint(RCore *core, const char *input) {
|
|||
r_num_math (core->num, input+1));
|
||||
break;
|
||||
case 's': // set size (opcode length)
|
||||
r_anal_hint_set_size (core->anal, core->offset, atoi (input+1));
|
||||
if (input[1]) {
|
||||
r_anal_hint_set_size (core->anal, core->offset, atoi (input+1));
|
||||
} else eprintf ("Usage: ahs 16\n");
|
||||
break;
|
||||
case 'S': // set size (opcode length)
|
||||
if (input[1]==' ') {
|
||||
r_anal_hint_set_syntax (core->anal, core->offset, input+2);
|
||||
} else eprintf ("Usage: ahS att\n");
|
||||
break;
|
||||
case 'o': // set opcode string
|
||||
r_anal_hint_set_opcode (core->anal, core->offset, input+1);
|
||||
if (input[1]==' ') {
|
||||
r_anal_hint_set_opcode (core->anal, core->offset, input+2);
|
||||
} else eprintf ("Usage: aho popall\n");
|
||||
break;
|
||||
case 'e': // set ESIL string
|
||||
r_anal_hint_set_esil (core->anal, core->offset, input+1);
|
||||
if (input[1]==' ') {
|
||||
r_anal_hint_set_esil (core->anal, core->offset, input+2);
|
||||
} else eprintf ("Usage: ahe r0,pc,=\n");
|
||||
break;
|
||||
#if TODO
|
||||
case 'e': // set endian
|
||||
|
|
|
@ -507,6 +507,7 @@ static void handle_build_op_str (RCore *core, RDisasmState *ds) {
|
|||
R_API RAnalHint *r_core_hint_begin (RCore *core, RAnalHint* hint, ut64 at) {
|
||||
// XXX not here
|
||||
static char *hint_arch = NULL;
|
||||
static char *hint_syntax = NULL;
|
||||
static int hint_bits = 0;
|
||||
if (hint) {
|
||||
r_anal_hint_free (hint);
|
||||
|
@ -517,6 +518,10 @@ R_API RAnalHint *r_core_hint_begin (RCore *core, RAnalHint* hint, ut64 at) {
|
|||
r_config_set (core->config, "asm.arch", hint_arch);
|
||||
hint_arch = NULL;
|
||||
}
|
||||
if (hint_syntax) {
|
||||
r_config_set (core->config, "asm.syntax", hint_syntax);
|
||||
hint_syntax = NULL;
|
||||
}
|
||||
if (hint_bits) {
|
||||
r_config_set_i (core->config, "asm.bits", hint_bits);
|
||||
hint_bits = 0;
|
||||
|
@ -528,6 +533,12 @@ R_API RAnalHint *r_core_hint_begin (RCore *core, RAnalHint* hint, ut64 at) {
|
|||
r_config_get (core->config, "asm.arch"));
|
||||
r_config_set (core->config, "asm.arch", hint->arch);
|
||||
}
|
||||
/* arch */
|
||||
if (hint->syntax) {
|
||||
if (!hint_syntax) hint_syntax = strdup (
|
||||
r_config_get (core->config, "asm.syntax"));
|
||||
r_config_set (core->config, "asm.syntax", hint->syntax);
|
||||
}
|
||||
/* bits */
|
||||
if (hint->bits) {
|
||||
if (!hint_bits) hint_bits =
|
||||
|
|
|
@ -613,6 +613,7 @@ typedef struct r_anal_hint_t {
|
|||
ut64 fail;
|
||||
char *arch;
|
||||
char *opcode;
|
||||
char *syntax;
|
||||
char *esil;
|
||||
int size;
|
||||
int bits;
|
||||
|
@ -1361,6 +1362,7 @@ R_API RAnalHint *r_anal_hint_at (RAnal *a, ut64 from);
|
|||
R_API RAnalHint *r_anal_hint_add (RAnal *a, ut64 from, int size);
|
||||
R_API void r_anal_hint_free (RAnalHint *h);
|
||||
R_API RAnalHint *r_anal_hint_get(RAnal *anal, ut64 addr);
|
||||
R_API void r_anal_hint_set_syntax (RAnal *a, ut64 addr, const char *syn);
|
||||
R_API void r_anal_hint_set_jump (RAnal *a, ut64 addr, ut64 ptr);
|
||||
R_API void r_anal_hint_set_fail (RAnal *a, ut64 addr, ut64 ptr);
|
||||
R_API void r_anal_hint_set_length (RAnal *a, ut64 addr, int length);
|
||||
|
|
Loading…
Reference in New Issue