Skip to content

Commit

Permalink
Add support for globbing flags for search.in ##search
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Nov 7, 2023
1 parent 367e290 commit bb27a51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libr/core/cconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,8 @@ static bool cb_searchin(void *user, void *data) {
if (strlen (node->value) > 1 && node->value[1] == '?') {
r_cons_printf ("Valid values for search.in (depends on .from/.to and io.va):\n"
"range search between .from/.to boundaries\n"
"flag find boundaries on flag in current offset bigger than 1 byte\n"
"flag find boundaries in ranges defined by flags larger than 1 byte\n"
"flag:[glob] find boundaries in flags matching given glob and larger than 1 byte\n"
"block search in the current block\n"
"io.map search in current map\n"
"io.maps search in all maps\n"
Expand Down Expand Up @@ -4357,7 +4358,7 @@ R_API int r_core_config_init(RCore *core) {
SETI ("search.from", -1, "search start address");
n = NODECB ("search.in", "io.maps", &cb_searchin);
SETDESC (n, "specify search boundaries");
SETOPTIONS (n, "raw", "flag", "block",
SETOPTIONS (n, "raw", "flag", "flag:", "block",
"bin.section", "bin.sections", "bin.sections.rwx", "bin.sections.r", "bin.sections.rw", "bin.sections.rx", "bin.sections.wx", "bin.sections.x",
"io.map", "io.maps", "io.maps.rwx", "io.maps.r", "io.maps.rw", "io.maps.rx", "io.maps.wx", "io.maps.x",
"dbg.stack", "dbg.heap",
Expand Down
10 changes: 10 additions & 0 deletions libr/core/cmd_search.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,16 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, R_UNUSED int perm, const ch
append_bound (list, core->io, search_itv, fi->offset, fi->size, 7);
}
}
} else if (r_str_startswith (mode, "flag:")) {
const char *match = mode + 5;
const RList *ls = r_flag_get_list (core->flags, core->offset);
RFlagItem *fi;
RListIter *iter;
r_list_foreach (ls, iter, fi) {
if (fi->size > 1 && r_str_glob (fi->name, match)) {
append_bound (list, core->io, search_itv, fi->offset, fi->size, 7);
}
}
} else if (!r_config_get_b (core->config, "cfg.debug") && !core->io->va) {
append_bound (list, core->io, search_itv, 0, r_io_size (core->io), 7);
} else if (!strcmp (mode, "file")) {
Expand Down

0 comments on commit bb27a51

Please sign in to comment.