diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index a7974eec49..6716d38b8e 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -3829,18 +3829,26 @@ 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); + RIOSection *s; ut64 o_align = geti ("search.align"); ut64 from, to, ptr; ut64 vmin, vmax; bool asterisk = false; - if (s) { - from = s->vaddr; - to = s->vaddr + s->size; + bool is_debug = r_config_get_i (core->config, "cfg.debug"); + + if (is_debug) { + // + r_list_free (r_core_get_boundaries_prot (core, 0, "dbg.map", &from, &to)); } else { - eprintf ("aav: Cannot find section at this address\n"); - // TODO: look in debug maps - return; + s = r_io_section_vget (core->io, core->offset); + if (s) { + from = s->vaddr; + to = s->vaddr + s->size; + } else { + eprintf ("aav: Cannot find section at this address\n"); + // TODO: look in debug maps + return; + } } seti ("search.align", 4); @@ -3848,29 +3856,26 @@ static void cmd_anal_aav(RCore *core, const char *input) { if (arg) { ptr = r_num_math (core->num, arg + 1); s = r_io_section_vget (core->io, ptr); - } else { - eprintf ("aav: using from to %llx %llx\n", from, to); - from = r_config_get_i (core->config, "bin.baddr"); - to = from + ((core->file)? r_io_desc_size (core->io, core->file->desc): 0); - } - if (!s) { - eprintf ("aav: Cannot find section at 0x%"PFMT64d"\n", ptr); - return; // WTF! } { RList *ret; - if (r_config_get_i (core->config, "cfg.debug")) { - ret = r_core_get_boundaries_prot (core, 0, "dbg.maps", &vmin, &vmax); + if (is_debug) { + ret = r_core_get_boundaries_prot (core, 0, "dbg.map", &vmin, &vmax); } else { + from = r_config_get_i (core->config, "bin.baddr"); + to = from + ((core->file)? r_io_desc_size (core->io, core->file->desc): 0); + if (!s) { + eprintf ("aav: Cannot find section at 0x%"PFMT64d"\n", ptr); + return; // WTF! + } ret = r_core_get_boundaries_prot (core, 0, "io.sections", &vmin, &vmax); } r_list_free (ret); } -//eprintf ("from to %llx %llx\n", from, to); -//eprintf ("from to %llx %llx\n", vmin, vmax); + eprintf ("aav: using from to 0x%"PFMT64x" 0x%"PFMT64x"\n", from, to); + eprintf ("Using vmin 0x%"PFMT64x" and vmax 0x%"PFMT64x"\n", vmin, vmax); int vsize = 4; // 32bit dword - (void)cmd_search_value_in_range (core, - from, to, vmin, vmax, vsize); + (void)cmd_search_value_in_range (core, from, to, vmin, vmax, vsize); // TODO: for each hit . must set flag, xref and metadata Cd 4 if (asterisk) { r_cons_printf ("f-hit*\n"); diff --git a/libr/core/cmd_search.c b/libr/core/cmd_search.c index f65dcf9985..5a9f16500e 100644 --- a/libr/core/cmd_search.c +++ b/libr/core/cmd_search.c @@ -137,22 +137,32 @@ static void cmd_search_bin(RCore *core, ut64 from, ut64 to) { 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; - bool asterisk = false; ut8 buf[4096]; - const int sz = sizeof (buf); + bool asterisk = false; ut64 v64, n = 0; ut32 v32; ut16 v16; + if (from >= to) { + eprintf ("Error: from must be lower than to\n"); + return -1; + } if (vmin >= vmax) { eprintf ("Error: vmin must be lower than vmax\n"); return -1; } while (from < to) { - memset (buf, 0, sz); // probably unnecessary - (void)r_io_read_at (core->io, from, buf, sz); - for (i=0; iio, from, buf, sizeof (buf)); + if (r_cons_is_breaked ()) { + goto beach; + } + for (i=0; i < sizeof (buf) - vsize; i++) { + void *v = (buf + i); + if (r_cons_is_breaked ()) { + eprintf ("BEACH\n"); + goto beach; + } + if (align && (from + i) % align) continue; match = false; switch (vsize) { @@ -176,8 +186,10 @@ R_API int cmd_search_value_in_range(RCore *core, ut64 from, ut64 to, ut64 vmin, hitctr++; } } - from += sz; + from += sizeof (buf); } +beach: + r_cons_break_end (); return hitctr; } @@ -590,6 +602,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char *from = map->addr; *to = map->addr_end; perm = map->perm; + break; } } if (perm) { @@ -631,7 +644,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char if (nmap->from < *from) { *from = nmap->from; } - if (nmap->to < *to) { + if (nmap->to > *to) { *to = nmap->to; } }