Support multiline comments in px ##print

This commit is contained in:
pancake 2021-05-28 01:34:21 +02:00 committed by pancake
parent fd715556c9
commit 1b27c79e7b
5 changed files with 60 additions and 31 deletions

View File

@ -477,7 +477,7 @@ static void _ds_comment_align_(RDisasmState *ds, bool up, bool nl) {
}
const char *sn = ds->show_section ? r_core_get_section_name (ds->core, ds->at) : "";
ds_align_comment (ds);
ds_align_comment (ds);
// ds_align_comment (ds);
r_cons_print (COLOR_RESET (ds));
ds_print_pre (ds, true);
r_cons_printf ("%s%s", nl? "\n": "", sn);
@ -501,7 +501,7 @@ static void ds_comment_(RDisasmState *ds, bool align, bool nl, const char *forma
*nl = 0;
}
if (ds->show_comments) {
if (ds->show_comment_right ) { // && align) {
if (ds->show_comment_right && align) {
ds_align_comment (ds);
}
}

View File

@ -1314,6 +1314,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
free (rstr);
}
}
bool first = true;
if (!eol && p && p->use_comments) {
for (; j < i + inc; j++) {
print (" ");
@ -1340,7 +1341,33 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
} else {
a = "";
}
printfmt ("%s ; %s", a, comment);
if (strchr (comment, '\n')) {
char *s = strdup (comment);
char *q = s;
while (true) {
char *nl = strchr (q, '\n');
if (nl) {
*nl = 0;
}
if (first) {
printfmt ("%s 2; %s", a, q);
first = false;
} else {
const char *a = r_str_pad (' ', 8 + (p->cols * 4));
printfmt ("%s; %s", a, q);
}
p->cb_printf ("\n");
if (!nl) {
break;
}
q = nl + 1;
}
free (s);
} else {
printfmt ("%s ; %s", a, comment);
p->cb_printf ("\n");
}
free (comment);
}
}

View File

@ -1261,7 +1261,7 @@ EOF
EXPECT=<<EOF
[{"offset":0,"text":" 0x00000000 90 nop ; test"}]
[{"offset":0,"text":" 0x00000000 90 nop ; test \"with quotes\""}]
[{"offset":0,"text":" ; test \"with quotes\"\n"},{"offset":0,"text":" 0x00000000 90 nop"}]
[{"offset":0,"text":{"offset":0,"text":" ; test \"with quotes\"\n ; "},{"offset":0,"text":" 0x00000000 90 nop"}}
EOF
RUN
@ -1733,8 +1733,8 @@ e emu.str.inv=false
pd 1 @ 0x161d
EOF
EXPECT=<<EOF
0x0000161d lea eax, [esi - abcdefghi] ; 0x21f7 ; "abcdefghi" ; "\n Blue Pill" str._n__Blue_Pill
0x0000161d lea eax, [esi - abcdefghi] ; 0x21f7 ; "abcdefghi" ; "\n Blue Pill" str._n__Blue_Pill
0x0000161d lea eax, [esi - abcdefghi] ; 0x21f7 ; "abcdefghi" ; "\n Blue Pill" str._n__Blue_Pill
0x0000161d lea eax, [esi - abcdefghi] ; 0x21f7 ; "abcdefghi" ; "\n Blue Pill" str._n__Blue_Pill
; 0x21f7
; "abcdefghi"

View File

@ -679,13 +679,13 @@ EXPECT=<<EOF
|| 0x0000420f xor edi, edi
|| 0x00004211 mov esi, dword [rdx + rax*4]
|| 0x00004214 call 0x13c50
|`-> 0x0000421a mov qword [0x000232b0], 0x50 ; 'P'
|  ; [0x232b0:8]=0
| 0x00004225 lea rdi, str.COLUMNS ; 0x18a22 ; "COLUMNS"
|`-> 0x0000421a mov qword [0x000232b0], 0x50 ; 'P'
|  ; [0x232b0:8]=0
| 0x00004225 lea rdi, str.COLUMNS ; 0x18a22 ; "COLUMNS"
0x000041ee lea rsi, [rip + 0x1d84b] ; 0x21a40
0x00004225 lea rdi, [rip + 0x147f6] ; str.COLUMNS
 ; 0x18a22 ; "COLUMNS"
0x000041ee lea rsi, [rip + 0x1d84b] ; 0x21a40
0x00004225 lea rdi, [rip + 0x147f6] ; str.COLUMNS
 ; 0x18a22 ; "COLUMNS"
,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
@ -710,8 +710,8 @@ EXPECT=<<EOF
,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
| 0x000041e7 mov rax, qword [0x0001b980] ; [0x1b980:8]=0x100000000
| 0x000041ee mov rax, qword [0x00021a40] ; [0x21a40:8]=0x18d31 str.literal
| 0x000041e7 mov rax, qword [0x0001b980] ; [0x1b980:8]=0x100000000
| 0x000041ee mov rax, qword [0x00021a40] ; [0x21a40:8]=0x18d31 str.literal
| 0x000041f5 mov rdi, rax
| 0x000041f8 call 0xc660
| 0x000041fe test eax, eax
@ -721,13 +721,13 @@ EXPECT=<<EOF
|| 0x0000420f xor edi, edi
|| 0x00004211 mov esi, dword [rdx + rax*4]
|| 0x00004214 call 0x13c50
|`-> 0x0000421a mov qword [0x000232b0], 0x50 ; 'P'
|  ; [0x232b0:8]=0
| 0x00004225 mov rax, qword [str.COLUMNS] ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"
|`-> 0x0000421a mov qword [0x000232b0], 0x50 ; 'P'
|  ; [0x232b0:8]=0
| 0x00004225 mov rax, qword [str.COLUMNS] ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"
0x000041ee mov rax, qword [rip + 0x1d84b] ; [0x21a40:8]=0x18d31 str.literal
0x00004225 mov rax, qword [rip + 0x147f6] ; str.COLUMNS
 ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"
0x000041ee mov rax, qword [rip + 0x1d84b] ; [0x21a40:8]=0x18d31 str.literal
0x00004225 mov rax, qword [rip + 0x147f6] ; str.COLUMNS
 ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"
,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
@ -752,8 +752,8 @@ EXPECT=<<EOF
,=< 0x000041e0 je 0x421a
| 0x000041e2 mov ecx, 4
| 0x000041e7 cmp rdx, qword [0x0001b980] ; [0x1b980:8]=0x100000000
| 0x000041ee cmp rsi, qword [0x00021a40] ; [0x21a40:8]=0x18d31 str.literal
| 0x000041e7 cmp rdx, qword [0x0001b980] ; [0x1b980:8]=0x100000000
| 0x000041ee cmp rsi, qword [0x00021a40] ; [0x21a40:8]=0x18d31 str.literal
| 0x000041f5 mov rdi, rax
| 0x000041f8 call 0xc660
| 0x000041fe test eax, eax
@ -763,13 +763,13 @@ EXPECT=<<EOF
|| 0x0000420f xor edi, edi
|| 0x00004211 mov esi, dword [rdx + rax*4]
|| 0x00004214 call 0x13c50
|`-> 0x0000421a mov qword [0x000232b0], 0x50 ; 'P'
|  ; [0x232b0:8]=0
| 0x00004225 cmp rdi, qword [str.COLUMNS] ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"
|`-> 0x0000421a mov qword [0x000232b0], 0x50 ; 'P'
|  ; [0x232b0:8]=0
| 0x00004225 cmp rdi, qword [str.COLUMNS] ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"
0x000041ee cmp rsi, qword [rip + 0x1d84b] ; [0x21a40:8]=0x18d31 str.literal
0x00004225 cmp rdi, qword [rip + 0x147f6] ; str.COLUMNS
 ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"
0x000041ee cmp rsi, qword [rip + 0x1d84b] ; [0x21a40:8]=0x18d31 str.literal
0x00004225 cmp rdi, qword [rip + 0x147f6] ; str.COLUMNS
 ; [0x18a22:8]=0x534e4d554c4f43 ; "COLUMNS"
EOF
RUN
@ -784,7 +784,7 @@ pd 1
EOF
EXPECT=<<EOF
0x00005e6e 488d3d339b01. lea rdi, section..fini_array ; 0x1f9a8
0x00005e6e 488d3d339b01. lea rdi, section..fini_array ; 0x1f9a8
0x00005e6e 488d3d339b01. lea rdi, section..fini_array ; 0x1f9a8
EOF
RUN

View File

@ -135,7 +135,8 @@ EXPECT=<<EOF
0x0000ffca .... .... .... .... .... .... .... ....                 
0x0000ffda .... .... .... .... .... .... .... ....                 
0x0000ffea .... .... .... .... .... .... .... ....                 
0x0000fffa .... .... .... 7f45 4c46 0100 0000 0000       .ELF...... ; segment.ehdr ; [01] -rw- segment size 45 named ehdr
0x0000fffa .... .... .... 7f45 4c46 0100 0000 0000       .ELF...... ; segment.ehdr ; [01] -rw- segment size 45 named ehdr
0x0001000a 0000 0000 0100 0200 0300 2000 0100 2000 .......... ... .
0x0001001a 0100 0400 0000 b32a 31c0 40cd 8000 3400 .......*1.@...4. ; entry0
0x0001002a 2000 0100 0000 0000 0000 0000 0000 0000  ...............
@ -146,7 +147,8 @@ EXPECT=<<EOF
0x0000ffca .... .... .... .... .... .... .... ....
0x0000ffda .... .... .... .... .... .... .... ....
0x0000ffea .... .... .... .... .... .... .... ....
0x0000fffa .... .... .... 7f45 4c46 0100 0000 0000 .ELF...... ; segment.ehdr ; [01] -rw- segment size 45 named ehdr
0x0000fffa .... .... .... 7f45 4c46 0100 0000 0000 .ELF...... ; segment.ehdr ; [01] -rw- segment size 45 named ehdr
0x0001000a 0000 0000 0100 0200 0300 2000 0100 2000 .......... ... .
0x0001001a 0100 0400 0000 b32a 31c0 40cd 8000 3400 .......*1.@...4. ; entry0
0x0001002a 2000 0100 0000 0000 0000 0000 0000 0000 ...............