* Added anal.prelude to specify an hexpair to find

* Added search/prelude API into RCore and Vapi
This commit is contained in:
pancake 2011-07-06 01:40:14 +02:00
parent 840190602c
commit 77816183a0
4 changed files with 22 additions and 14 deletions

View File

@ -2129,13 +2129,13 @@ static int preludecnt = 0;
static int __prelude_cb_hit(RSearchKeyword *kw, void *user, ut64 addr) {
RCore *core = (RCore *)user;
int depth = r_config_get_i (core->config, "anal.depth");
eprintf ("ap: Found function prelude at 0x%08llx\n", addr);
eprintf ("ap: Found function prelude %d at 0x%08"PFMT64x"\n", preludecnt, addr);
r_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth);
preludecnt++;
return R_TRUE;
}
static void search_preludes(RCore *core, const ut8 *buf, int blen, const ut8 *mask, int mlen) {
R_API int r_core_search_prelude(RCore *core, const ut8 *buf, int blen, const ut8 *mask, int mlen) {
int ret;
ut64 at, from, to;
ut8 *b = (ut8 *)malloc (core->blocksize);
@ -2161,33 +2161,35 @@ static void search_preludes(RCore *core, const ut8 *buf, int blen, const ut8 *ma
}
eprintf ("Analized %d functions based on preludes\n", preludecnt);
free (b);
return preludecnt;
}
R_API r_core_search_preludes(RCore *core) {
R_API int r_core_search_preludes(RCore *core) {
int ret = -1;
const char *prelude = r_config_get (core->config, "anal.prelude");
const char *arch = r_config_get (core->config, "asm.arch");
int bits = r_config_get_i (core->config, "asm.bits");
// TODO: this is x86 only
// TODO: allow interruptible search
char *o = strdup (r_config_get (core->config, "search.prefix"));
r_config_set (core->config, "search.prefix", "pre.");
r_flag_space_set (core->flags, "preludes");
if (prelude && *prelude) {
char *kw = malloc (strlen (prelude));
int kwlen = r_hex_str2bin (prelude, kw);
ret = r_core_search_prelude (core, kw, kwlen, NULL, 0);
free (kw);
} else
if (strstr (arch, "x86")) {
switch (bits) {
case 32:
search_preludes (core, "\x55\x89\xe5", 3, NULL, 0);
ret = r_core_search_prelude (core, "\x55\x89\xe5", 3, NULL, 0);
break;
case 64:
search_preludes (core, "\x55\x48\x89\xe5", 3, NULL, 0);
ret = r_core_search_prelude (core, "\x55\x48\x89\xe5", 3, NULL, 0);
//r_core_cmd0 (core, "./x 554989e5");
break;
default:
eprintf ("ap: Unsupported bits: %d\n", bits);
}
} else {
eprintf ("ap: Unsupported asm.arch and asm.bits\n");
}
r_config_set (core->config, "search.prefix", o);
free (o);
} else eprintf ("ap: Unsupported asm.arch and asm.bits\n");
return ret;
}
static int cmd_anal(void *data, const char *input) {

View File

@ -354,6 +354,7 @@ R_API int r_core_config_init(RCore *core) {
r_config_set (cfg, "dir.source", "");
r_config_set (cfg, "dir.plugins", LIBDIR"/radare2/"R2_VERSION"/");
/* anal */
r_config_set (cfg, "anal.prelude", "");
r_config_set_i (cfg, "anal.depth", 50); // XXX: warn if depth is > 50 .. can be problematic
r_config_set_i (cfg, "anal.ptrdepth", 3);
r_config_set_cb (cfg, "anal.split", "true", &config_analsplit_callback);

View File

@ -224,6 +224,8 @@ R_API void r_core_seek_previous (RCore *core, const char *type);
R_API void r_core_visual_define (RCore *core);
R_API int r_core_visual_trackflags(RCore *core);
R_API void r_core_visual_prompt (RCore *core);
R_API int r_core_search_preludes(RCore *core);
R_API int r_core_search_prelude(RCore *core, const ut8 *buf, int blen, const ut8 *mask, int mlen);
#endif

View File

@ -50,6 +50,9 @@ public class RCore {
public unowned string disassemble_instr(uint64 addr, int l);
public unowned string disassemble_bytes(uint64 addr, int b);
public int anal_search_preludes();
public int anal_search_prelude(uint8 *k, int ksz, uint8 *m, int msz);
public bool anal_all();
public int anal_search (uint64 from, uint64 to, uint64 ref);
public void anal_refs(uint64 addr, int gv);