Skip to content

Commit

Permalink
Fix glitch when asm.bytes.space+asm.bytes.align+asm.nbytes%2 ##disasm
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored Oct 23, 2023
1 parent 3078b9f commit 24d497b
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 212 deletions.
20 changes: 15 additions & 5 deletions libr/core/disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3736,15 +3736,25 @@ static void ds_print_bytes(RDisasmState *ds) {
// R2R db/cmd/cmd_disassembly
nstr = r_print_hexpair (ds->print, str, n);
if (r_str_ansi_len (nstr) > nb) {
if (nb % 2) {
nb--;
if (ds->show_bytes_align) {
r_cons_printf (" ");
}
}
char *p = (char *)r_str_ansi_chrn (nstr, nb);
if (p) {
if (p) {
off = true;
if (!core->print->bytespace) {
p--;
}
p[0] = '.';
if (core->print->bytespace) {
p[1] = '.';
p[1] = '.';
if (ds->show_bytes_align) {
p[2] = '\0';
} else {
p[1] = '\0';
p[2] = ' ';
p[3] = '\0';
}
}
}
Expand Down Expand Up @@ -3779,7 +3789,7 @@ static void ds_print_bytes(RDisasmState *ds) {
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);
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);
}
Expand Down
10 changes: 5 additions & 5 deletions test/db/anal/bpf_64
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ CMDS=pd 5
EXPECT=<<EOF
;-- entry0:
;-- entrypoint:
0x000009b8 bf1200000000. mov64 r2, r1
0x000009c0 bfa100000000. mov64 r1, r10
0x000009c8 07010000d0ff. add64 r1, 0xffffffd0
0x000009d0 851000000502. call 0x205
0x000009d8 79a6d0ff0000. ldxdw r6, [r10+0xffd0]
0x000009b8 bf12000000.. mov64 r2, r1
0x000009c0 bfa1000000.. mov64 r1, r10
0x000009c8 07010000d0.. add64 r1, 0xffffffd0
0x000009d0 8510000005.. call 0x205
0x000009d8 79a6d0ff00.. ldxdw r6, [r10+0xffd0]
EOF
RUN

Expand Down
6 changes: 3 additions & 3 deletions test/db/anal/calls
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ EXPECT=<<EOF
| 0x00400419 4883e4f0 and rsp, 0xfffffffffffffff0
| 0x0040041d 50 push rax
| 0x0040041e 54 push rsp
| 0x0040041f 49c7c0000640. mov r8, sym.__libc_csu_fini ; 0x400600
| 0x00400426 48c7c1900540. mov rcx, sym.__libc_csu_init ; 0x400590 ; "AWA\x89\xffAVI\x89\xf6AUI\x89\xd5ATL\x8d%p\x01 "
| 0x0040042d 48c7c7740540. mov rdi, main ; 0x400574 ; "U\xff\x14%X\t`"
| 0x0040041f 49c7c00006.. mov r8, sym.__libc_csu_fini ; 0x400600
| 0x00400426 48c7c19005.. mov rcx, sym.__libc_csu_init ; 0x400590 ; "AWA\x89\xffAVI\x89\xf6AUI\x89\xd5ATL\x8d%p\x01 "
| 0x0040042d 48c7c77405.. mov rdi, main ; 0x400574 ; "U\xff\x14%X\t`"
\ 0x00400434 e8b7ffffff call sym.imp.__libc_start_main ; int __libc_start_main(func main, int argc, char **ubp_av, func init, func fini, func rtld_fini, void *stack_end)
EOF
RUN
2 changes: 1 addition & 1 deletion test/db/anal/evm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ wx 7c030000000000000000000000000000000000000000000000000000000f9004
pd 3
EOF
EXPECT=<<EOF
0x00000000 7c0300000000. push29 0x030000000000000000000000000000000000000000000000000000000f
0x00000000 7c03000000.. push29 0x030000000000000000000000000000000000000000000000000000000f
0x0000001e 90 swap1
0x0000001f 04 div
EOF
Expand Down
44 changes: 22 additions & 22 deletions test/db/anal/x86_64
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,15 @@ EOF
EXPECT=<<EOF
/ 114: fcn.00487350 ();
| 0x00487350 8b8710030000 mov eax, dword [rdi + 0x310]
| 0x00487356 48b900000000. movabs rcx, 0x200000000
| 0x00487356 48b9000000.. movabs rcx, 0x200000000
| 0x00487360 8d50ff lea edx, [rax - 1]
| 0x00487363 48b8ffffffff. movabs rax, 0x3ffffffff
| 0x00487363 48b8ffffff.. movabs rax, 0x3ffffffff
| 0x0048736d 899710030000 mov dword [rdi + 0x310], edx
| 0x00487373 482387100300. and rax, qword [rdi + 0x310]
| 0x00487373 4823871003.. and rax, qword [rdi + 0x310]
| 0x0048737a 4839c8 cmp rax, rcx
| 0x0048737d 7411 je 0x487390
| // true: 0x00487390 false: 0x0048737f
| 0x0048737f f605d2542300. test byte [0x006bc858], 0x40
| 0x0048737f f605d25423.. test byte [0x006bc858], 0x40
| 0x00487386 7525 jne 0x4873ad
| // true: 0x004873ad false: 0x00487388
| 0x00487388 f3c3 repz ret
Expand All @@ -539,12 +539,12 @@ EXPECT=<<EOF
| 0x00487396 85c0 test eax, eax
| 0x00487398 7426 je 0x4873c0
| // true: 0x004873c0 false: 0x0048739a
| 0x0048739a f605b7542300. test byte [0x006bc858], 0x40
| 0x004873a1 c705d54d2300. mov dword [0x006bc180], 2
| 0x0048739a f605b75423.. test byte [0x006bc858], 0x40
| 0x004873a1 c705d54d23.. mov dword [0x006bc180], 2
| 0x004873ab 74db je 0x487388
| // true: 0x00487388 false: 0x004873ad
| 0x004873ad 488b7708 mov rsi, qword [rdi + 8]
| 0x004873b1 488d3dd03502. lea rdi, str._nclosing_file_s__direct_opencount_u_n
| 0x004873b1 488d3dd035.. lea rdi, str._nclosing_file_s__direct_opencount_u_n
| 0x004873b8 31c0 xor eax, eax
| 0x004873ba e9b16cffff jmp fcn.0047e070

Expand Down Expand Up @@ -3535,29 +3535,29 @@ EXPECT=<<EOF
0x140001012 0f871a010000 ja case.0x140001034.3
0x140001034 ffe1 jmp rcx ; switch table (99 cases) at 0x140001148
;-- case 1: ; from 0x140001034
0x140001036 488d0dd31100. lea rcx, str.case_1 ; 0x140002210 ; "case 1"
0x140001036 488d0dd311.. lea rcx, str.case_1 ; 0x140002210 ; "case 1"
;-- case 2: ; from 0x140001034
0x14000104b 488d0dc61100. lea rcx, str.case_2 ; 0x140002218 ; "case 2"
0x14000104b 488d0dc611.. lea rcx, str.case_2 ; 0x140002218 ; "case 2"
;-- case 11: ; from 0x140001034
0x140001060 488d0db91100. lea rcx, str.case_11 ; 0x140002220 ; "case 11"
0x140001060 488d0db911.. lea rcx, str.case_11 ; 0x140002220 ; "case 11"
;-- case 13: ; from 0x140001034
0x140001075 488d0dac1100. lea rcx, str.case_13 ; 0x140002228 ; "case 13"
0x140001075 488d0dac11.. lea rcx, str.case_13 ; 0x140002228 ; "case 13"
;-- case 15...16: ; from 0x140001034
0x14000108a 488d0d9f1100. lea rcx, str.case_15_and_16 ; 0x140002230 ; "case 15 and 16"
0x14000108a 488d0d9f11.. lea rcx, str.case_15_and_16 ; 0x140002230 ; "case 15 and 16"
;-- case 19: ; from 0x140001034
0x14000109f 488d0d9a1100. lea rcx, str.case_19 ; 0x140002240 ; "case 19"
0x14000109f 488d0d9a11.. lea rcx, str.case_19 ; 0x140002240 ; "case 19"
;-- case 50: ; from 0x140001034
0x1400010b4 488d0d8d1100. lea rcx, str.case_50 ; 0x140002248 ; "case 50"
0x1400010b4 488d0d8d11.. lea rcx, str.case_50 ; 0x140002248 ; "case 50"
;-- case 30: ; from 0x140001034
0x1400010c9 488d0d801100. lea rcx, str.case_30 ; 0x140002250 ; "case 30"
0x1400010c9 488d0d8011.. lea rcx, str.case_30 ; 0x140002250 ; "case 30"
;-- case 20: ; from 0x140001034
0x1400010de 488d0d731100. lea rcx, str.case_20 ; 0x140002258 ; "case 20"
0x1400010de 488d0d7311.. lea rcx, str.case_20 ; 0x140002258 ; "case 20"
;-- case 10: ; from 0x140001034
0x1400010f3 488d0d661100. lea rcx, str.case_10 ; 0x140002260 ; "case 10"
0x1400010f3 488d0d6611.. lea rcx, str.case_10 ; 0x140002260 ; "case 10"
;-- case 99: ; from 0x140001034
0x140001108 488d0d591100. lea rcx, str.case_99 ; 0x140002268 ; "case 99"
0x140001108 488d0d5911.. lea rcx, str.case_99 ; 0x140002268 ; "case 99"
;-- case 97: ; from 0x140001034
0x14000111d 488d0d4c1100. lea rcx, str.case_97 ; 0x140002270 ; "case 97"
0x14000111d 488d0d4c11.. lea rcx, str.case_97 ; 0x140002270 ; "case 97"
;-- case 3...9: ; from 0x140001034
;-- case 12: ; from 0x140001034
;-- case 14: ; from 0x140001034
Expand Down Expand Up @@ -3847,7 +3847,7 @@ EXPECT=<<EOF
| 0x00000004 b402 mov ah, 2
| 0x00000006 66b83333 mov ax, 0x3333
| 0x0000000a b855554444 mov eax, 0x44445555
| 0x0000000f 48b8bebafeca. movabs rax, 0xdeadbeefcafebabe
| 0x0000000f 48b8bebafe.. movabs rax, 0xdeadbeefcafebabe
| 0x00000019 4889d8 mov rax, rbx
| 0x0000001c 488d03 lea rax, [rbx]
| 0x0000001f 488b4308 mov rax, qword [rbx + 8]
Expand Down Expand Up @@ -3888,7 +3888,7 @@ EXPECT=<<EOF
| 0x00000004 b402 ah = 2
| 0x00000006 66b83333 ax = 0x3333
| 0x0000000a b855554444 eax = 0x44445555
| 0x0000000f 48b8bebafeca. rax = 0xdeadbeefcafebabe
| 0x0000000f 48b8bebafe.. rax = 0xdeadbeefcafebabe
| 0x00000019 4889d8 rax = rbx
| 0x0000001c 488d03 rax = rbx
| 0x0000001f 488b4308 rax = qword [rbx + 8]
Expand Down Expand Up @@ -4036,7 +4036,7 @@ scale: 1
esil: 0x1fce0,rip,+,[16],xmm0,=
direction: read
family: vec
0x140001358 660f6f05e0fc. movdqa xmm0, xmmword [str._n_2.__1__a] ; [0x140021040:16]=-1 ; "\n*,2.)%#1%#)a~\x7f"
0x140001358 660f6f05e0.. movdqa xmm0, xmmword [str._n_2.__1__a] ; [0x140021040:16]=-1 ; "\n*,2.)%#1%#)a~\x7f"
;-- str._n_2.__1__a:
; DATA XREF from main @ +0x38(r)
0x140021040 .string "\n*,2.)%#1%#)a~" ; len=15
Expand Down
20 changes: 10 additions & 10 deletions test/db/cmd/cmd_ahi
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ ahi 10
pd 1
EOF
EXPECT=<<EOF
0x00000000 4881ec480600. sub rsp, 0x648
0x00000000 4881ec480600. sub rsp, 1608
0x00000000 4881ec4806.. sub rsp, 0x648
0x00000000 4881ec4806.. sub rsp, 1608
EOF
RUN

Expand Down Expand Up @@ -123,7 +123,7 @@ wx 4881ec48060000
pd 1
EOF
EXPECT=<<EOF
0x00000000 4881ec480600. sub rsp, 0x648
0x00000000 4881ec4806.. sub rsp, 0x648
EOF
RUN

Expand All @@ -137,7 +137,7 @@ wx 4881ec48060000
pd 1
EOF
EXPECT=<<EOF
0x00000000 4881ec480600. sub rsp, 0x648
0x00000000 4881ec4806.. sub rsp, 0x648
EOF
RUN

Expand All @@ -151,7 +151,7 @@ ahi 10
pd 1
EOF
EXPECT=<<EOF
0x00000000 4881ec480600. sub rsp, 1608
0x00000000 4881ec4806.. sub rsp, 1608
EOF
RUN

Expand All @@ -165,7 +165,7 @@ ahi 8
pd 1
EOF
EXPECT=<<EOF
0x00000000 4881ec480600. sub rsp, 03110
0x00000000 4881ec4806.. sub rsp, 03110
EOF
RUN

Expand All @@ -179,7 +179,7 @@ ahi 2
pd 1
EOF
EXPECT=<<EOF
0x00000000 4881ec480600. sub rsp, 11001001000b
0x00000000 4881ec4806.. sub rsp, 11001001000b
EOF
RUN

Expand Down Expand Up @@ -282,9 +282,9 @@ ahi 10; pd 1
EOF
EXPECT=<<EOF
true
0x100001000 c7055f440000. mov dword [rip + 0x445f], 0 ; [0x100005469:4]=-1
0x100001000 c7055f440000. mov dword [0x100005469], 0 ; [0x100005469:4]=-1
0x100001000 c7055f440000. mov dword [4294988905], 0 ; [0x100005469:4]=-1
0x100001000 c7055f4400.. mov dword [rip + 0x445f], 0 ; [0x100005469:4]=-1
0x100001000 c7055f4400.. mov dword [0x100005469], 0 ; [0x100005469:4]=-1
0x100001000 c7055f4400.. mov dword [4294988905], 0 ; [0x100005469:4]=-1
EOF
RUN

Expand Down
44 changes: 22 additions & 22 deletions test/db/cmd/cmd_disassembly
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ e asm.bytes.align = true
pd 10
EOF
EXPECT=<<EOF
0x00000000 803d1ca00408. cmp byte [0x804a01c], 0x33
0x00000000 803d1ca004.. cmp byte [0x804a01c], 0x33
,=< 0x00000007 740c je 0x15
,==< 0x00000009 eb1c jmp 0x27
|| 0x0000000b 83c004 add eax, 4
Expand All @@ -293,7 +293,7 @@ EXPECT=<<EOF
| 0x00000018 40 inc eax
| 0x00000019 8b10 mov edx, dword [eax]
--
0x00000000 803d1ca00408. cmp byte [0x804a01c], 0x33
0x00000000 803d1ca004.. cmp byte [0x804a01c], 0x33
,=< 0x00000007 740c je 0x15
,==< 0x00000009 eb1c jmp 0x27
|| 0x0000000b 83c004 add eax, 4
Expand All @@ -304,26 +304,26 @@ EXPECT=<<EOF
| 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]
--
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
Loading

0 comments on commit 24d497b

Please sign in to comment.