From 3bc3d3daf7361eabbd8887e7885424d0e9a57e2c Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 4 Jul 2023 10:49:38 +0200 Subject: [PATCH] Fix glitch + tests asm.bytes.{align,space} ##disasm --- libr/core/disasm.c | 30 +++++++++++----- shlr/meson.build | 1 + test/db/cmd/cmd_ahi | 4 +-- test/db/cmd/cmd_disassembly | 69 +++++++++++++++++++++++++++++++++++++ test/db/cmd/cmd_pd2 | 2 +- test/db/cmd/cmd_pd_bugs | 6 ++-- test/db/cmd/cmd_px | 10 +++--- 7 files changed, 103 insertions(+), 19 deletions(-) diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 4352cd00a4..aa888f6cc0 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -3523,6 +3523,7 @@ static void ds_print_bytes(RDisasmState *ds) { if (ds->show_flag_in_bytes) { flagstr = r_flag_get_liststr (core->flags, ds->at); } + bool off = false; int nb = R_MIN (100, ds->nb); if (flagstr) { if (nb > 3 && strlen (flagstr) >= nb) { @@ -3582,20 +3583,27 @@ static void ds_print_bytes(RDisasmState *ds) { } } #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); if (ds->show_bytes_opcolor) { ds->print->nbcolor = (ds->analop.nopcode > 1)? ds->analop.nopcode: 1; } else { ds->print->nbcolor = 0; } + // R2R db/cmd/cmd_disassembly 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; if (ds->print->bytespace) { 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) { - 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 { r_cons_printf ("%s%s %s", pad, str, extra); } diff --git a/shlr/meson.build b/shlr/meson.build index 8a1274f841..41ba0cefd0 100644 --- a/shlr/meson.build +++ b/shlr/meson.build @@ -107,6 +107,7 @@ if not capstone_dep.found() or not get_option('use_sys_capstone') 'arch/XCore/XCoreInstPrinter.c', 'arch/XCore/XCoreMapping.c', 'arch/XCore/XCoreModule.c', + 'Mapping.c', 'cs.c', 'MCInst.c', 'MCInstrDesc.c', diff --git a/test/db/cmd/cmd_ahi b/test/db/cmd/cmd_ahi index 4a6edc6ee2..a847b9999e 100644 --- a/test/db/cmd/cmd_ahi +++ b/test/db/cmd/cmd_ahi @@ -58,8 +58,8 @@ ahi 10 pd 1 EOF EXPECT=<dH\x8b\x04%(" +| 0x00005af3 4c8d05660c01. lea r8, [fcn.00016760] ; 0x16760 +| 0x00005afa 488d0def0b01. lea rcx, [fcn.000166f0] ; 0x166f0 +| 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 0x00005b0e f4 hlt 0x00005b0f 90 nop ; CALL XREF from entry.fini0 @ 0x5ba8(x) / 34: fcn.00005b0e (); -| 0x00005b10 488d3d51c701. lea rdi, loc._edata ; loc.__bss_start +| 0x00005b10 488d3d51c701. lea rdi, loc._edata ; loc.__bss_start |  ; 0x22268 -| 0x00005b17 488d054ac701. lea rax, loc._edata ; loc.__bss_start +| 0x00005b17 488d054ac701. lea rax, loc._edata ; loc.__bss_start |  ; 0x22268 | 0x00005b1e 4839f8 cmp rax, rdi EOF