Fix #18427 - Sort flags by [sections,formats][other][regs] ##disasm (#18770)

This commit is contained in:
pancake 2021-05-28 02:27:17 +02:00 committed by GitHub
parent 1b27c79e7b
commit 4ade590c47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 7 deletions

View File

@ -2246,6 +2246,59 @@ static void __preline_flag(RDisasmState *ds, RFlagItem *flag) {
}
}
static bool is_first (const char *fs) {
if (fs) {
if (strstr (fs, "segment")) {
return true;
}
if (strstr (fs, "section")) {
return true;
}
if (strstr (fs, "format")) {
return true;
}
if (strstr (fs, "class")) {
return true;
}
}
return false;
}
static RList *custom_sorted_flags(const RList *flaglist) {
RListIter *iter;
RFlagItem *flag;
if (!flaglist) {
return NULL;
}
RList *list = r_list_uniq (flaglist, flagCmp);
RList *res = r_list_newf (NULL);
RList *rest = r_list_newf (NULL);
RList *tail = r_list_newf (NULL);
r_list_foreach (list, iter, flag) {
const char *fs = flag->space? flag->space->name: NULL;
if (is_first (fs)) {
r_list_append (res, flag);
} else {
r_list_append (rest, flag);
}
}
r_list_foreach (rest, iter, flag) {
const char *fs = flag->space? flag->space->name: NULL;
if (fs && !strcmp (fs, "registers")) {
r_list_append (tail, flag);
} else {
r_list_append (res, flag);
}
}
r_list_foreach (tail, iter, flag) {
r_list_append (res, flag);
}
r_list_free (tail);
r_list_free (rest);
list->free = NULL;
r_list_free (list);
return res;
}
#define printPre (outline || !*comma)
static void ds_show_flags(RDisasmState *ds, bool overlapped) {
//const char *beginch;
@ -2261,13 +2314,18 @@ static void ds_show_flags(RDisasmState *ds, bool overlapped) {
int case_start = -1, case_prev = 0, case_current = 0;
f = r_anal_get_function_at (ds->core->anal, ds->at);
const RList *flaglist = r_flag_get_list (core->flags, ds->at);
RList *uniqlist = flaglist? r_list_uniq (flaglist, flagCmp): NULL;
RList *uniqlist = custom_sorted_flags (flaglist);
int count = 0;
bool outline = !ds->flags_inline;
const char *comma = "";
bool keep_lib = r_config_get_i (core->config, "bin.demangle.libs");
bool docolon = true;
int nth = 0;
#if 0
r_list_foreach (uniqlist, iter, flag) {
r_cons_printf ("(%s)(at:%s),", flag->name, flag->space->name);
}
#endif
r_list_foreach (uniqlist, iter, flag) {
if (!overlapped && f && f->addr == flag->offset && !strcmp (flag->name, f->name)) {
// do not show non-overlapped flags that have the same name as the function

View File

@ -1,3 +1,18 @@
NAME=flags order by space
FILE=bins/elf/hello_world
CMDS=<<EOF
e asm.flags.inline=false
pd 1
EOF
EXPECT=<<EOF
;-- section..text:
;-- .text:
;-- entry0:
;-- _start:
0x000006a0 31ed xor ebp, ebp ; [14] -r-x section size 546 named .text
EOF
RUN
NAME=pD@x:90
FILE=-
CMDS=<<EOF

View File

@ -386,8 +386,8 @@ pd 10
EOF
EXPECT=<<EOF
; [14] -r-x section size 2466 named .text
;-- entry0:
;-- section..text:
;-- entry0:
xor ebp, ebp
mov r9, rdx
pop rsi

View File

@ -164,9 +164,9 @@ pd 2
pi 2
EOF
EXPECT=<<EOF
;-- entry0:
;-- section..text:
;-- .text:
;-- entry0:
;-- _start:
0x004005c0 31ed xor ebp, ebp ; [14] -r-x section size 584 named .text
0x004005c2 4989d1 mov r9, rdx

View File

@ -104,9 +104,9 @@ e asm.bytes = false
pde
EOF
EXPECT=<<EOF
;-- entry0:
;-- section..text:
;-- .text:
;-- entry0:
;-- _start:
;-- pc:
0x10000308 mr r9, r1 ; start.S:62

View File

@ -295,8 +295,8 @@ aaa
pdf @ dbg.init
EOF
EXPECT=<<EOF
;-- Grid::init():
;-- method.Grid.init__:
;-- Grid::init():
; CALL XREF from dbg.main @ 0x10001ae8
/ 64: dbg.init (Grid * const this);
| ; arg Grid * const this @ r3

View File

@ -559,13 +559,13 @@ EOF
EXPECT=<<EOF
"\tANSI\\esc: \x1b[33m\r\n"
ascii[19] "\tANSI\\esc: \x1b[33m\r\n"
;-- str._tANSIesc:_e_33m_r_n:
;-- section..data:
;-- str._tANSIesc:_e_33m_r_n:
0x140016000 .string "\tANSI\\esc: \x1b[33m\r\n" ; len=19 ; [02] -rw- section size 8192 named .data
"\tANSI\esc: \x1b[33m\r\n"
ascii[19] "\tANSI\esc: \x1b[33m\r\n"
;-- str._tANSIesc:_e_33m_r_n:
;-- section..data:
;-- str._tANSIesc:_e_33m_r_n:
0x140016000 .string "\tANSI\esc: \x1b[33m\r\n" ; len=19 ; [02] -rw- section size 8192 named .data
EOF
RUN