Skip to content

Commit

Permalink
Ugliest commit ever, but passing all px tests on big endian
Browse files Browse the repository at this point in the history
* My future self will fix that, doing baby steps here for now
  • Loading branch information
trufae committed Apr 26, 2024
1 parent 26edf29 commit fab3348
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
48 changes: 33 additions & 15 deletions libr/util/print.c
Expand Up @@ -1101,7 +1101,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
print ((col == 1)? "|": " ");
}
for (j = i; j < i + inc; j++) {
if (j!=i && use_align && rowbytes == inc) {
if (j != i && use_align && rowbytes == inc) {
int sz = (p && p->offsize)? p->offsize (p->user, addr + j): -1;
if (sz >= 0) {
rowbytes = bytes;
Expand Down Expand Up @@ -1151,15 +1151,36 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
#if R_SYS_ENDIAN
if (base == 32) {
// only needed for big endian
ut32 n32;
ut32 n32 = 0;
r_mem_swaporcopy ((ut8 *)&n32, buf + j, 4, be);
if (sz_n == 2) {
switch (sz_n) {
case 1:
n = n32 & 0xff;
break;
case 2:
n = n32 & 0xffff;
} else {
break;
case 4:
n = n32;
break;
}
} else {
r_mem_swaporcopy ((ut8 *) &n, buf + j, sz_n, be);
ut64 n64 = 0;
r_mem_swaporcopy ((ut8 *) &n64, buf + j, 8, be);
switch (sz_n) {
case 1:
n = n64 & 0xff;
break;
case 2:
n = n64 & 0xffff;
break;
case 4:
n = n64 & 0xffffffff;
break;
default:
n = n64;
break;
}
}
#else
r_mem_swaporcopy ((ut8 *) &n, buf + j, sz_n, be);
Expand Down Expand Up @@ -1278,26 +1299,23 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
} else {
r_print_byte (p, addr + j, bytefmt, j, buf[j]);
}
bool mustspace = false;
if (pairs && !compact && (inc & 1)) {
bool mustspace = (rows % 2) ? !(j&1) : (j&1);
if (mustspace) {
print (" ");
}
mustspace = (rows % 2) ? !(j&1) : (j&1);
} else if (bytes % 2 || !pairs) {
if (col == 1) {
if (j + 1 < inc + i) {
if (!compact) {
print (" ");
}
mustspace = !compact;
} else {
print ("|");
}
} else {
if (!compact) {
print (" ");
}
mustspace = !compact;
}
}
if (mustspace) {
print (" ");
}
}
if (hl) {
print (Color_RESET);
Expand Down
8 changes: 8 additions & 0 deletions test/db/cmd/cmd_px
Expand Up @@ -5,29 +5,34 @@ e asm.arch=x86
e asm.bits=64
woe 1 255
s+11
?e vuit
b 8
pxr8
pxr4
pxr2
pxr1
?e quatre
b 4
pxr8
pxr4
pxr2
pxr1
?e dos
b 2
pxr8
pxr4
pxr2
pxr1
pxr2
?e u
b 1
pxr8
pxr4
pxr2
pxr1
EOF
EXPECT=<<EOF
vuit
0x0000000b 0x0101010101010101 ........
0x0000000b 0x01010101 .... 16843009
0x0000000f 0x01010101 .... 16843009
Expand All @@ -44,6 +49,7 @@ EXPECT=<<EOF
0x00000010 001 .
0x00000011 001 .
0x00000012 001 .
quatre
0x0000000b 0x0000000001010101 ....
0x0000000b 0x01010101 .... 16843009
0x0000000b 0101 .. 257 R W X 'add byte [rax], al'
Expand All @@ -53,13 +59,15 @@ EXPECT=<<EOF
0x0000000c 001 .
0x0000000d 001 .
0x0000000e 001 .
dos
0x0000000b 0x0000000000000101 ..
0x0000000b 0x00000101 ..
0x0000000b 0101 .. 257 R W X 'add byte [rax], al'
- offset - B B
0x0000000b 001 .
0x0000000c 001 .
0x0000000b 0101 .. 257 R W X 'add byte [rax], al'
u
0x0000000b 0x0000000000000001 .
0x0000000b 0x00000001 .
0x0000000b 01 .
Expand Down

0 comments on commit fab3348

Please sign in to comment.