Honor search.maxhits in /m (#11609)

This commit is contained in:
radare 2018-09-21 16:32:25 +02:00 committed by GitHub
parent b56c4862eb
commit 6e65b5d02a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -12,12 +12,16 @@ static void r_core_magic_reset(RCore *core) {
kw_count = 0;
}
static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, int v, bool json) {
static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, int v, bool json, int *hits) {
const char *fmt;
char *q, *p;
const char *str;
int found = 0, delta = 0, adelta = 0, ret;
ut64 curoffset = core->offset;
int maxHits = r_config_get_i (core->config, "search.maxhits");
if (maxHits > 0 && *hits >= maxHits) {
return 0;
}
#define NAH 32
if (--depth<0) {
@ -113,6 +117,7 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
strcpy (q + 1, q + ((q[2] == ' ')? 3: 2));
}
}
(*hits)++;
cmdhit = r_config_get (core->config, "cmd.hit");
if (cmdhit && *cmdhit) {
r_core_cmd0 (core, cmdhit);
@ -152,7 +157,7 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
if (!fmt || !*fmt) {
fmt = file;
}
r_core_magic_at (core, fmt, addr, depth, 1, json);
r_core_magic_at (core, fmt, addr, depth, 1, json, hits);
*q = '@';
}
break;
@ -191,8 +196,9 @@ seek_exit:
static void r_core_magic(RCore *core, const char *file, int v) {
ut64 addr = core->offset;
int hits = 0;
magicdepth = r_config_get_i (core->config, "magic.depth"); // TODO: do not use global var here
r_core_magic_at (core, file, addr, magicdepth, v, false);
r_core_magic_at (core, file, addr, magicdepth, v, false, &hits);
if (addr != core->offset) {
r_core_seek (core, addr, true);
}

View File

@ -3003,6 +3003,8 @@ reread:
r_cons_printf ("[");
}
r_core_magic_reset (core);
int maxHits = r_config_get_i (core->config, "search.maxhits");
int hits = 0;
r_list_foreach (param.boundaries, iter, map) {
if (!json) {
eprintf ("-- %llx %llx\n", map->itv.addr, r_itv_end (map->itv));
@ -3012,11 +3014,14 @@ reread:
if (r_cons_is_breaked ()) {
break;
}
ret = r_core_magic_at (core, file, addr, 99, false, json);
ret = r_core_magic_at (core, file, addr, 99, false, json, &hits);
if (ret == -1) {
// something went terribly wrong.
break;
}
if (maxHits && hits >= maxHits) {
break;
}
addr += ret - 1;
}
r_cons_clear_line (1);