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;
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)) {
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) {
/* 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
// 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