]> git.feebdaed.xyz Git - 0xmirror/radare2.git/commitdiff
Sperm bit handled in the helper ##util
authorpancake <pancake@nopcode.org>
Tue, 23 Dec 2025 12:41:58 +0000 (13:41 +0100)
committerpancake <pancake@nowsecure.com>
Tue, 23 Dec 2025 15:34:01 +0000 (16:34 +0100)
libr/cons/pal.c
libr/core/cbin.c
libr/util/str.c

index 14ffbbffb58bb4c60bf467b7cafa66c37bac6144..ed6c7b9ad18e608505bfc91661dae82f31afc44d 100644 (file)
@@ -200,7 +200,7 @@ static void pal_refresh(RCons *cons, bool rain) {
 
 R_API void r_cons_permstr(RCons *cons, int perm, bool color_enabled, char *buf, size_t buf_sz) {
        const char *perm_str = r_str_rwx_i (perm);
-       if (!color_enabled || !cons || !(perm & R_PERM_RWX)) {
+       if (!color_enabled || !cons || !(perm & (R_PERM_RWX | R_PERM_SHAR))) {
                strncpy (buf, perm_str, buf_sz - 1);
                buf[buf_sz - 1] = 0;
                return;
index 78d4f827ede9f5480517d00e5b78c6d581ae9b0e..ed1a0e0df9231b1ffc4971a6107e81c080cae445 100644 (file)
@@ -3392,7 +3392,7 @@ static bool bin_sections(RCore *core, PJ *pj, int mode, ut64 laddr, int va, ut64
        int plimit = filesize? R_MIN (filesize, bin_hashlimit): bin_hashlimit;
        const bool use_color = r_config_get_i (core->config, "scr.color") > 0;
        r_list_foreach (sections, iter, section) {
-               char perms[] = "----";
+               const char *perms = r_str_rwx_i (section->perm);
                int va_sect = va;
 
                if (va && ! (section->perm & R_PERM_R)) {
@@ -3415,19 +3415,6 @@ static bool bin_sections(RCore *core, PJ *pj, int mode, ut64 laddr, int va, ut64
                if (section->is_segment != print_segments) {
                        continue;
                }
-               // XXX use r_str_perm instead of doing it here imho
-               if (section->perm & R_PERM_SHAR) {
-                       perms[0] = 's';
-               }
-               if (section->perm & R_PERM_R) {
-                       perms[1] = 'r';
-               }
-               if (section->perm & R_PERM_W) {
-                       perms[2] = 'w';
-               }
-               if (section->perm & R_PERM_X) {
-                       perms[3] = 'x';
-               }
                const char *arch = NULL;
                int bits = 0;
                if (section->arch || section->bits) {
index c8c355591b11974896dd7b77c36c505f8283bbf1..5b245216437b2e1134a6d10309e26a8684f54464 100644 (file)
@@ -6,23 +6,23 @@
 
 /* stable code */
 static const char *const rwxstr[] = {
-       [0] = "---",
-       [1] = "--x",
-       [2] = "-w-",
-       [3] = "-wx",
-       [4] = "r--",
-       [5] = "r-x",
-       [6] = "rw-",
-       [7] = "rwx",
-
-       [8] = "---",
-       [9] = "--x",
-       [10] = "-w-",
-       [11] = "-wx",
-       [12] = "r--",
-       [13] = "r-x",
-       [14] = "rw-",
-       [15] = "rwx",
+       [0] = "----",
+       [1] = "---x",
+       [2] = "-w--",
+       [3] = "-w-x",
+       [4] = "-r--",
+       [5] = "-r-x",
+       [6] = "-rw-",
+       [7] = "-rwx",
+
+       [8] = "s---",
+       [9] = "s--x",
+       [10] = "sw--",
+       [11] = "sw-x",
+       [12] = "sr--",
+       [13] = "sr-x",
+       [14] = "srw-",
+       [15] = "srwx",
 };
 
 // equal string, same case
@@ -223,10 +223,11 @@ R_API int r_str_rwx(const char *str) {
 
 // Returns the string representation of the permission of the inputted integer.
 R_API const char *r_str_rwx_i(int rwx) {
-       if (rwx < 0 || rwx >= R_ARRAY_SIZE (rwxstr)) {
-               rwx = 0;
+       int idx = (rwx & R_PERM_RWX) | ((rwx & R_PERM_SHAR) ? 8 : 0);
+       if (idx < 0 || idx >= (int)R_ARRAY_SIZE (rwxstr)) {
+               idx = 0;
        }
-       return rwxstr[rwx % 24]; // 15 for srwx
+       return rwxstr[idx];
 }
 
 // If up is true, upcase all characters in the string, otherwise downcase all