Fix #6308 - Fix crash in /P and enhance the output

This commit is contained in:
pancake 2016-12-10 23:29:19 +01:00
parent 74ea0907f2
commit 1ebc5e29ec
6 changed files with 62 additions and 24 deletions

View File

@ -1,7 +1,7 @@
-include config-user.mk -include config-user.mk
include global.mk include global.mk
PREVIOUS_RELEASE=0.10.4 PREVIOUS_RELEASE=1.0.2
R2R=radare2-regressions R2R=radare2-regressions
R2R_URL=$(shell doc/repo REGRESSIONS) R2R_URL=$(shell doc/repo REGRESSIONS)

View File

@ -495,6 +495,14 @@ static inline void print_search_progress(ut64 at, ut64 to, int n) {
R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char *mode, ut64 *from, ut64 *to) { R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char *mode, ut64 *from, ut64 *to) {
RList *list = NULL; RList *list = NULL;
ut64 _from, _to;
if (!from) {
from = &_from;
}
if (!to) {
to = &_to;
}
if (!strcmp (mode, "block")) { if (!strcmp (mode, "block")) {
*from = core->offset; *from = core->offset;
*to = core->offset + core->blocksize; *to = core->offset + core->blocksize;
@ -534,12 +542,14 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
*to = s->vaddr+s->vsize; *to = s->vaddr+s->vsize;
continue; continue;
} }
if (((s->vaddr) < *from) && s->vaddr) if (((s->vaddr) < *from) && s->vaddr) {
*from = s->vaddr; *from = s->vaddr;
if ((s->vaddr+s->vsize) > *to) }
if ((s->vaddr+s->vsize) > *to) {
*to = s->vaddr+s->vsize; *to = s->vaddr+s->vsize;
} }
} }
}
if (!*to || *to == UT64_MAX || *to == UT32_MAX) { if (!*to || *to == UT64_MAX || *to == UT32_MAX) {
RIOMap *map = r_io_map_get (core->io, core->offset); RIOMap *map = r_io_map_get (core->io, core->offset);
*from = core->offset; *from = core->offset;
@ -548,6 +558,18 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int protection, const char
*from = 0; *from = 0;
} }
} }
#if 0
RIOMap *map = R_NEW0 (RIOMap);
if (map) {
map->fd = core->io->raised;
map->from = *from;
map->to = *to;
map->flags = 6;
map->delta = 0;
list = r_list_newf (free);
r_list_append (list, map);
}
#endif
} else if (!strcmp (mode, "io.section")) { } else if (!strcmp (mode, "io.section")) {
if (core->io->va) { if (core->io->va) {
RListIter *iter; RListIter *iter;
@ -1210,7 +1232,9 @@ static int r_core_search_rop(RCore *core, ut64 from, ut64 to, int opt, const cha
|| !strncmp (smode, "io.sections", 11) \ || !strncmp (smode, "io.sections", 11) \
|| prot & R_IO_EXEC) { || prot & R_IO_EXEC) {
list = r_core_get_boundaries_prot (core, prot, smode, &from, &to); list = r_core_get_boundaries_prot (core, prot, smode, &from, &to);
} else list = NULL; } else {
list = NULL;
}
if (!list) { if (!list) {
map = R_NEW0 (RIOMap); map = R_NEW0 (RIOMap);
@ -2050,17 +2074,10 @@ static int memcmpdiff(const ut8 *a, const ut8 *b, int len) {
return diff; return diff;
} }
static void search_similar_pattern(RCore *core, int count) { static void search_similar_pattern_in(RCore *core, int count, ut64 from, ut64 to) {
RIOMap *p; ut64 addr = from;
RListIter *iter;
ut8 *block = calloc (core->blocksize, 1); ut8 *block = calloc (core->blocksize, 1);
const char *where = r_config_get (core->config, "search.in"); while (addr < to) {
r_cons_break_push (NULL, NULL);
RList *list = r_core_get_boundaries_prot (core, R_IO_EXEC, where, NULL, NULL);
r_list_foreach (list, iter, p) {
ut64 addr = p->from;
while (addr < p->to) {
(void)r_io_read_at (core->io, addr, block, core->blocksize); (void)r_io_read_at (core->io, addr, block, core->blocksize);
if (r_cons_is_breaked ()) { if (r_cons_is_breaked ()) {
break; break;
@ -2068,13 +2085,32 @@ static void search_similar_pattern(RCore *core, int count) {
int diff = memcmpdiff (core->block, block, core->blocksize); int diff = memcmpdiff (core->block, block, core->blocksize);
int equal = core->blocksize - diff; int equal = core->blocksize - diff;
if (equal >= count) { if (equal >= count) {
r_cons_printf ("0x%08"PFMT64x" %d/%d\n", addr, equal, core->blocksize); int pc = (equal * 100 )/core->blocksize;
r_cons_printf ("0x%08"PFMT64x" %4d/%d %3d%% ", addr, equal, core->blocksize, pc);
ut8 ptr[2] = { pc * 2.5, 0 };
r_print_fill (core->print, ptr, 1, UT64_MAX, core->blocksize);
} }
addr += core->blocksize; addr += core->blocksize;
} }
free (block);
}
static void search_similar_pattern(RCore *core, int count) {
RIOMap *p;
ut64 from, to;
RListIter *iter;
const char *where = r_config_get (core->config, "search.in");
r_cons_break_push (NULL, NULL);
RList *list = r_core_get_boundaries_prot (core, R_IO_EXEC, where, &from, &to);
if (list) {
r_list_foreach (list, iter, p) {
search_similar_pattern_in (core, count, p->from, p->to);
}
} else {
search_similar_pattern_in (core, count, from, to);
} }
r_cons_break_pop (); r_cons_break_pop ();
free (block);
} }
static int cmd_search(void *data, const char *input) { static int cmd_search(void *data, const char *input) {

View File

@ -1219,8 +1219,10 @@ R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step
int base = 0; int base = 0;
if (addr != UT64_MAX && step > 0) { if (addr != UT64_MAX && step > 0) {
p->cb_printf ("0x%08"PFMT64x" ", addr + (i * step)); p->cb_printf ("0x%08"PFMT64x" ", addr + (i * step));
}
p->cb_printf ("%02x %04x |", i, arr[i]); p->cb_printf ("%02x %04x |", i, arr[i]);
} else {
p->cb_printf ("|");
}
if (show_colors) { if (show_colors) {
int idx = (int)(arr[i] * 5 / 255); int idx = (int)(arr[i] * 5 / 255);
const char *k = firebow[idx]; const char *k = firebow[idx];

View File

@ -1,4 +1,4 @@
PACKAGE=radare2-dev PACKAGE?=radare2-dev
ARCH=iphoneos-arm ARCH=iphoneos-arm
SECTION=user/shell SECTION=user/shell
DEPENDS=radare2 DEPENDS=radare2

View File

@ -1,4 +1,4 @@
PACKAGE=radare2 PACKAGE?=radare2
ARCH=iphoneos-arm ARCH=iphoneos-arm
SECTION=user/shell SECTION=user/shell
PRIORITY=optional PRIORITY=optional