From 1d76b1c6e84530adf4f359437c1dc14bf21f2de2 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 22 Dec 2025 16:37:34 +0100 Subject: [PATCH] Implement the @@@m:perm foreach operator ##shell --- libr/core/cmd.c | 20 +++++++++++++++++++- libr/core/cmd_help.inc.c | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 7b481595de..4deab8010b 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -5610,7 +5610,25 @@ static RList *foreach3list(RCore *core, char type, const char *glob) { } break; case 'm': // "@@@m" - { + if (R_STR_ISNOTEMPTY (glob)) { + // filter io maps by permission string (e.g., @@@m:x, @@@m:rw, @@@m:rwx) + int perm = r_str_rwx (glob); + if (perm < 1) { + R_LOG_WARN ("Invalid permissions string '%s'", glob); + } else { + RIOBank *bank = r_io_bank_get (core->io, core->io->bank); + if (bank) { + RListIter *iter; + RIOMapRef *mapref; + r_list_foreach_prev (bank->maprefs, iter, mapref) { + RIOMap *map = r_io_map_get (core->io, mapref->id); + if (map && (map->perm & perm) == perm) { + append_item (list, NULL, r_io_map_begin (map), r_io_map_size (map)); + } + } + } + } + } else { int fd = r_io_fd_get_current (core->io); // only iterate maps of current fd RList *maps = r_io_map_get_by_fd (core->io, fd); diff --git a/libr/core/cmd_help.inc.c b/libr/core/cmd_help.inc.c index 4733e6b889..5194b52167 100644 --- a/libr/core/cmd_help.inc.c +++ b/libr/core/cmd_help.inc.c @@ -117,7 +117,7 @@ static RCoreHelpMessage help_msg_at_at_at = { "x", " @@@f:hit*", "flags matching glob expression", "x", " @@@i", "imports", "x", " @@@M", "dbg.maps (See ?$?~size)", - "x", " @@@m", "io.maps", + "x", " @@@m[:rwx]", "io.maps (all of the ones matching perm mask)", "x", " @@@r", "registers", "x", " @@@R", "relocs", "x", " @@@S", "sections", -- 2.43.0