Fix /V hitnames and add aav command

This commit is contained in:
pancake 2016-04-11 00:02:58 +02:00
parent 67030c2137
commit f42e69bb3e
2 changed files with 50 additions and 9 deletions

View File

@ -3691,6 +3691,34 @@ static void r_core_anal_info (RCore *core, const char *input) {
}
}
extern int cmd_search_value_in_range(RCore *core, ut64 from, ut64 to, ut64 vmin, ut64 vmax, int vsize);
static void cmd_anal_aav(RCore *core, const char *input) {
#define set(x,y) r_config_set(core->config, x, y);
#define seti(x,y) r_config_set_i(core->config, x, y);
#define geti(x) r_config_get_i(core->config, x);
RIOSection *s = r_io_section_vget (core->io, core->offset);
ut64 o_align = geti ("search.align");
ut64 from = s->vaddr;
ut64 to = s->vaddr + s->size;
seti ("search.align", 4);
char *arg = strchr (input, ' ');
if (arg) {
ut64 ptr = r_num_math (core->num, arg + 1);
s = r_io_section_vget (core->io, ptr);
}
ut64 vmin = s->vaddr;
ut64 vmax = s->vaddr + s->size;
//eprintf ("from to %llx %llx\n", from, to);
//eprintf ("from to %llx %llx\n", vmin, vmax);
int vsize = 4; // 32bit dword
(void)cmd_search_value_in_range (core,
from, to, vmin, vmax, vsize);
// TODO: for each hit . must set flag, xref and metadata Cd 4
seti ("search.align", o_align);
}
static int cmd_anal_all(RCore *core, const char *input) {
const char *help_msg_aa[] = {
"Usage:", "aa[0*?]", " # see also 'af' and 'afna'",
@ -3705,6 +3733,7 @@ static int cmd_anal_all(RCore *core, const char *input) {
"aas", " [len]", "analyze symbols (af @@= `isq~[0]`)",
"aat", " [len]", "analyze all consecutive functions in section",
"aap", "", "find and analyze function preludes",
"aav", "", "find values referencing a specific section or map",
NULL };
switch (*input) {
@ -3715,6 +3744,9 @@ static int cmd_anal_all(RCore *core, const char *input) {
r_core_cmd0 (core, "af @@ sym.*");
r_core_cmd0 (core, "af @ entry0");
break;
case 'v': // "aav"
cmd_anal_aav(core, input);
break;
case 'i': // "aai"
r_core_anal_info (core, input + 1);
break;

View File

@ -12,6 +12,7 @@ static const char *cmdhit = NULL;
static const char *searchprefix = NULL;
static unsigned int searchcount = 0;
struct search_parameters {
RList *boundaries;
const char *mode;
@ -134,14 +135,13 @@ static void cmd_search_bin(RCore *core, ut64 from, ut64 to) {
r_cons_break_end ();
}
static int cmd_search_value_in_range(RCore *core, ut64 from, ut64 to, ut64 vmin, ut64 vmax, int vsize) {
R_API int cmd_search_value_in_range(RCore *core, ut64 from, ut64 to, ut64 vmin, ut64 vmax, int vsize) {
int i, match, align = core->search->align, hitctr = 0;
ut8 buf[4096];
const int sz = sizeof (buf);
ut64 v64;
ut64 v64, v = 0;
ut32 v32;
ut16 v16;
#define cbhit(y) r_cons_printf ("f hit0_%d = 0x%"PFMT64x"\n", hitctr, y); hitctr++
if (vmin >= vmax) {
eprintf ("Error: vmin must be lower than vmax\n");
return -1;
@ -156,13 +156,21 @@ static int cmd_search_value_in_range(RCore *core, ut64 from, ut64 to, ut64 vmin,
match = false;
switch (vsize) {
case 1: match = (buf[i]>=vmin && buf[i]<=vmax); break;
case 2: v16 = *((ut16*)(v)); match = (v16>=vmin && v16<=vmax); break;
case 4: v32 = *((ut32 *)(v)); match = (v32>=vmin && v32<=vmax); break;
case 8: v64 = *((ut64 *)(v)); match = (v64>=vmin && v64<=vmax); break;
case 2: v = v16 = *((ut16*)(v)); match = (v16>=vmin && v16<=vmax); v = v16; break;
case 4: v = v32 = *((ut32 *)(v)); match = (v32>=vmin && v32<=vmax); v = v32; break;
case 8: v = v64 = *((ut64 *)(v)); match = (v64>=vmin && v64<=vmax); v = v64; break;
default: eprintf ("Unknown vsize\n"); return -1;
}
if (match)
cbhit (from+i);
if (match) {
r_cons_printf ("ax 0x%"PFMT64x" 0x%"PFMT64x"\n",
v, from + i);
r_cons_printf ("Cd %d @ 0x%"PFMT64x"\n", vsize,
from + i);
r_cons_printf ("f hit0_%d = 0x%"PFMT64x
" # from 0x%"PFMT64x"\n",
hitctr, from +i, v);
hitctr++;
}
}
from += sz;
}
@ -1933,7 +1941,7 @@ reread:
case 'V':
// TODO: add support for json
{
int err = 1, vsize = atoi (input+1);
int err = 1, vsize = atoi (input + 1);
if (vsize && input[2] && input[3]) {
char *w = strchr (input + 3, ' ');
if (w) {
@ -1944,6 +1952,7 @@ reread:
err = 0;
(void)cmd_search_value_in_range (core,
param.from, param.to, vmin, vmax, vsize);
r_cons_printf ("f-hit*\n");
}
}
}