]> git.feebdaed.xyz Git - 0xmirror/radare2.git/commitdiff
Implement the @@@m:perm foreach operator ##shell
authorpancake <pancake@nowsecure.com>
Mon, 22 Dec 2025 15:37:34 +0000 (16:37 +0100)
committerGitHub <noreply@github.com>
Mon, 22 Dec 2025 15:37:34 +0000 (16:37 +0100)
libr/core/cmd.c
libr/core/cmd_help.inc.c

index 7b481595de84b3529e34a7e3b4ca81c3e61bde0a..4deab8010bafe895fbfa576ca824ca17ff21bf37 100644 (file)
@@ -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);
index 4733e6b889d5f617a24f2ed800fb0e228dc47ac7..5194b521674711dabe619fdecf82e779b7ecf741 100644 (file)
@@ -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",