Fix glitch + tests asm.bytes.{align,space} ##disasm

This commit is contained in:
pancake 2023-07-04 10:49:38 +02:00
parent 2446852fff
commit 3bc3d3daf7
7 changed files with 103 additions and 19 deletions

View File

@ -3523,6 +3523,7 @@ static void ds_print_bytes(RDisasmState *ds) {
if (ds->show_flag_in_bytes) { if (ds->show_flag_in_bytes) {
flagstr = r_flag_get_liststr (core->flags, ds->at); flagstr = r_flag_get_liststr (core->flags, ds->at);
} }
bool off = false;
int nb = R_MIN (100, ds->nb); int nb = R_MIN (100, ds->nb);
if (flagstr) { if (flagstr) {
if (nb > 3 && strlen (flagstr) >= nb) { if (nb > 3 && strlen (flagstr) >= nb) {
@ -3582,20 +3583,27 @@ static void ds_print_bytes(RDisasmState *ds) {
} }
} }
#endif #endif
if (r_str_ansi_len (str) > nb) {
char *p = (char *)r_str_ansi_chrn (str, nb);
if (p) {
p[0] = '.';
p[1] = '\0';
}
}
ds->print->cur_enabled = (ds->cursor != -1); ds->print->cur_enabled = (ds->cursor != -1);
if (ds->show_bytes_opcolor) { if (ds->show_bytes_opcolor) {
ds->print->nbcolor = (ds->analop.nopcode > 1)? ds->analop.nopcode: 1; ds->print->nbcolor = (ds->analop.nopcode > 1)? ds->analop.nopcode: 1;
} else { } else {
ds->print->nbcolor = 0; ds->print->nbcolor = 0;
} }
// R2R db/cmd/cmd_disassembly
nstr = r_print_hexpair (ds->print, str, n); nstr = r_print_hexpair (ds->print, str, n);
if (r_str_ansi_len (nstr) > nb) {
char *p = (char *)r_str_ansi_chrn (nstr, nb);
if (p) {
off = true;
p[0] = '.';
if (core->print->bytespace) {
p[1] = '.';
p[2] = '\0';
} else {
p[1] = '\0';
}
}
}
ds->print->nbcolor = 0; ds->print->nbcolor = 0;
if (ds->print->bytespace) { if (ds->print->bytespace) {
k = (nb + (nb / 2)) - r_str_ansi_len (nstr) + 2; k = (nb + (nb / 2)) - r_str_ansi_len (nstr) + 2;
@ -3624,7 +3632,13 @@ static void ds_print_bytes(RDisasmState *ds) {
} }
} }
if (ds->show_bytes_align) { if (ds->show_bytes_align) {
r_cons_printf ("%s%s%s ", (*extra)? extra + 1: extra, str, pad); if (core->print->bytespace) {
const int d = off? 2: 1;
const char *air = off? " ":"";
r_cons_printf ("%s%s%s %s", (extra[0] && extra[1])? extra + d: extra, str, pad, air);
} else {
r_cons_printf ("%s%s%s ", (extra[0])? extra + 1: extra, str, pad);
}
} else { } else {
r_cons_printf ("%s%s %s", pad, str, extra); r_cons_printf ("%s%s %s", pad, str, extra);
} }

View File

@ -107,6 +107,7 @@ if not capstone_dep.found() or not get_option('use_sys_capstone')
'arch/XCore/XCoreInstPrinter.c', 'arch/XCore/XCoreInstPrinter.c',
'arch/XCore/XCoreMapping.c', 'arch/XCore/XCoreMapping.c',
'arch/XCore/XCoreModule.c', 'arch/XCore/XCoreModule.c',
'Mapping.c',
'cs.c', 'cs.c',
'MCInst.c', 'MCInst.c',
'MCInstrDesc.c', 'MCInstrDesc.c',

View File

@ -58,8 +58,8 @@ ahi 10
pd 1 pd 1
EOF EOF
EXPECT=<<EOF EXPECT=<<EOF
0x00000000 4881ec480600. sub rsp, 0x648 0x00000000 4881ec480600. sub rsp, 0x648
0x00000000 4881ec480600. sub rsp, 1608 0x00000000 4881ec480600. sub rsp, 1608
EOF EOF
RUN RUN

View File

@ -258,3 +258,72 @@ EXPECT=<<EOF
3 3
EOF EOF
RUN RUN
NAME=byte spacing and align in disasm
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=32
e scr.utf8=0
e asm.lines.jmp=1
e asm.comments=0
wx 803d1ca0040833740ceb1c83c004a318a0088ffd2a118a00408b1085d275eb
e asm.bytes.space=0
e asm.bytes.align=0
pd 10
?e --
e asm.bytes.align = true
pd 10
?e --
e asm.bytes.space = true
pd 10
?e --
e asm.bytes.align = true
pd 10
EOF
EXPECT=<<EOF
0x00000000 803d1ca00408. cmp byte [0x804a01c], 0x33
,=< 0x00000007 740c je 0x15
,==< 0x00000009 eb1c jmp 0x27
|| 0x0000000b 83c004 add eax, 4
|| 0x0000000e a318a0088f mov dword [0x8f08a018], eax
|| 0x00000013 fd std
|| 0x00000014 2a11 sub dl, byte [ecx]
| 0x00000016 8a00 mov al, byte [eax]
| 0x00000018 40 inc eax
| 0x00000019 8b10 mov edx, dword [eax]
--
0x00000000 803d1ca00408. cmp byte [0x804a01c], 0x33
,=< 0x00000007 740c je 0x15
,==< 0x00000009 eb1c jmp 0x27
|| 0x0000000b 83c004 add eax, 4
|| 0x0000000e a318a0088f mov dword [0x8f08a018], eax
|| 0x00000013 fd std
|| 0x00000014 2a11 sub dl, byte [ecx]
| 0x00000016 8a00 mov al, byte [eax]
| 0x00000018 40 inc eax
| 0x00000019 8b10 mov edx, dword [eax]
--
0x00000000 80 3d 1c a0 .. cmp byte [0x804a01c], 0x33
,=< 0x00000007 74 0c je 0x15
,==< 0x00000009 eb 1c jmp 0x27
|| 0x0000000b 83 c0 04 add eax, 4
|| 0x0000000e a3 18 a0 08 .. mov dword [0x8f08a018], eax
|| 0x00000013 fd std
|| 0x00000014 2a 11 sub dl, byte [ecx]
| 0x00000016 8a 00 mov al, byte [eax]
| 0x00000018 40 inc eax
| 0x00000019 8b 10 mov edx, dword [eax]
--
0x00000000 80 3d 1c a0 .. cmp byte [0x804a01c], 0x33
,=< 0x00000007 74 0c je 0x15
,==< 0x00000009 eb 1c jmp 0x27
|| 0x0000000b 83 c0 04 add eax, 4
|| 0x0000000e a3 18 a0 08 .. mov dword [0x8f08a018], eax
|| 0x00000013 fd std
|| 0x00000014 2a 11 sub dl, byte [ecx]
| 0x00000016 8a 00 mov al, byte [eax]
| 0x00000018 40 inc eax
| 0x00000019 8b 10 mov edx, dword [eax]
EOF
RUN

View File

@ -806,7 +806,7 @@ pd 1
EOF EOF
EXPECT=<<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 0x00005e6e 488d3d339b01. lea rdi, section..fini_array ; 0x1f9a8
EOF EOF
RUN RUN

View File

@ -63,9 +63,9 @@ EXPECT=<<EOF
| entry0+0x9 4883e4f0 and rsp, 0xfffffffffffffff0 | entry0+0x9 4883e4f0 and rsp, 0xfffffffffffffff0
| entry0+0xd 50 push rax | entry0+0xd 50 push rax
| entry0+0xe 54 push rsp | entry0+0xe 54 push rsp
| entry0+0xf 4c8b05e69301. mov r8, qword [section..got] ; [0x1f220:8]=0x16ee0 | entry0+0xf 4c8b05e69301. mov r8, qword [section..got] ; [0x1f220:8]=0x16ee0
| entry0+0x16 488b0de79301. mov rcx, qword [0x0001f228] ; [0x1f228:8]=0x16e60 | entry0+0x16 488b0de79301. mov rcx, qword [0x0001f228] ; [0x1f228:8]=0x16e60
| entry0+0x1d 488b3de89301. mov rdi, qword [0x0001f230] ; [0x1f230:8]=0x3bd0 main | entry0+0x1d 488b3de89301. mov rdi, qword [0x0001f230] ; [0x1f230:8]=0x3bd0 main
EOF EOF
RUN RUN

View File

@ -397,17 +397,17 @@ EXPECT=<<EOF
| 0x00005aed 4883e4f0 and rsp, 0xfffffffffffffff0 | 0x00005aed 4883e4f0 and rsp, 0xfffffffffffffff0
| 0x00005af1 50 push rax | 0x00005af1 50 push rax
| 0x00005af2 54 push rsp | 0x00005af2 54 push rsp
| 0x00005af3 4c8d05660c01. lea r8, [fcn.00016760] ; 0x16760 | 0x00005af3 4c8d05660c01. lea r8, [fcn.00016760] ; 0x16760
| 0x00005afa 488d0def0b01. lea rcx, [fcn.000166f0] ; 0x166f0 | 0x00005afa 488d0def0b01. lea rcx, [fcn.000166f0] ; 0x166f0
| 0x00005b01 488d3d68e5ff. lea rdi, main ; 0x4070 ; "AWAVAUATU\x89\xfdSH\x89\xf3H\x83\xecXH\x8b>dH\x8b\x04%(" | 0x00005b01 488d3d68e5ff. lea rdi, main ; 0x4070 ; "AWAVAUATU\x89\xfdSH\x89\xf3H\x83\xecXH\x8b>dH\x8b\x04%("
\ 0x00005b08 ff150ac30100 call qword [reloc.__libc_start_main] ; [0x21e18:8]=0 \ 0x00005b08 ff150ac30100 call qword [reloc.__libc_start_main] ; [0x21e18:8]=0
0x00005b0e f4 hlt 0x00005b0e f4 hlt
0x00005b0f 90 nop 0x00005b0f 90 nop
; CALL XREF from entry.fini0 @ 0x5ba8(x) ; CALL XREF from entry.fini0 @ 0x5ba8(x)
/ 34: fcn.00005b0e (); / 34: fcn.00005b0e ();
| 0x00005b10 488d3d51c701. lea rdi, loc._edata ; loc.__bss_start | 0x00005b10 488d3d51c701. lea rdi, loc._edata ; loc.__bss_start
|  ; 0x22268 |  ; 0x22268
| 0x00005b17 488d054ac701. lea rax, loc._edata ; loc.__bss_start | 0x00005b17 488d054ac701. lea rax, loc._edata ; loc.__bss_start
|  ; 0x22268 |  ; 0x22268
| 0x00005b1e 4839f8 cmp rax, rdi | 0x00005b1e 4839f8 cmp rax, rdi
EOF EOF