Skip to content

Fix #4974 - Print binary Cd data in value order ##disasm - #27348

Merged
trufae merged 1 commit into
radareorg:masterfrom
Thanatos9404:cd-binary-value-order
Nov 5, 2026
Merged

trufae merged 1 commit into
radareorg:masterfrom
Thanatos9404:cd-binary-value-order

Conversation

@Thanatos9404

Copy link
Copy Markdown
Contributor
  • Mark this if you consider it ready to merge
  • I've added tests (optional)
  • I wrote some lines in the book (optional)

Description

Fixes #4974. With a binary immbase (ahi 1), a Cd data item printed its bits in memory order, while every other base prints the value read with the configured endianness. A little endian dword 03 00 00 00 showed as 00000011000000000000000000000000b, so ? on that text, as in the issue, gave a different number, and e cfg.bigendian made no difference.

data_type_tostring now writes the value most significant byte first before printing the bits, so the binary text is the same value as the hex and decimal text, and cfg.bigendian changes it the way it changes hex.

When the value fits the directive, the text now assembles back to the same bytes (rasm2 round-trips .int16, .int32 and .int64 with a b suffix on x86, arm and mips). So data_type_assembles treats binary like decimal: pdj puts it in opcode, and keeps .hex there for a single byte or a 16/32-bit value above the signed maximum. This drops the "binary digits follow memory order" exception from #27320.

Something I left alone: for Cd data, immbase 1 is binary and 2 falls back to hex, while for instructions ahi s (1) is string and ahi b (2) is binary, as ahi? says. So ahi b on a Cd item prints hex. I can change that here or in a separate PR if you want.

Testing

  • New test in test/db/cmd/metadata: the same dword printed with both endiannesses.
  • Extended the cmd_pdj Cd test with a dword that has the top bit set (.hex in opcode, binary in disasm) and a word (binary in opcode).
  • Updated the expected binary output in three existing tests (two in metadata, one in cmd_pdj).
  • The changed tests fail on master. db/cmd/metadata (231), db/cmd/cmd_pdj (178), db/cmd/cmd_ahi and db/cmd/cmd_pd pass. sys/lint.py --all is clean.

With a binary immbase, Cd data printed the bits in memory order, while
every other base prints the value, so a little endian dword 3 showed as
00000011000000000000000000000000b. Print the most significant byte
first. When the value fits the directive, the text now assembles back
to the same bytes, so pdj puts it in opcode, as it does for decimal.

trufae commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Good to merge. No blockers found.

The endian conversion is right, and the .hex fallback still covers bytes and 16/32-bit values above the signed limit. No meaningful perf concern here.

Built b43b3ba. Both changed r2r files pass. Also checked 120 pdj → rasm2 round trips across all four data sizes, both byte orders and x86/arm/mips, including the sign-bit boundaries and UINT64_MAX.

  • Separate follow-up: fix the ahi b/ahi s mismatch you noted. Cd should honor the same hint mapping as instructions. Add a small regression for the letter forms too.

trufae commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Looks good to merge. The binary text now matches the value and endianness. The .hex fallback still covers bytes and 16/32-bit values that the signed directives reject. No merge blocker or meaningful perf regression found; the extra work is bounded to 8 bytes and only happens for binary output.

Small follow-ups:

  • You can reuse buf for r_write_ble (buf, n, true, size * 8) and pass it to r_str_bits. That drops msb and the extra case scope.
  • Let's fix the ahi b / ahi s mismatch separately. Cd should honor the same base IDs as instructions. Keep a regression for the old ahi 1 behavior so the compatibility choice is explicit.

@trufae
trufae merged commit 39dcc1c into radareorg:master Nov 5, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eval command ignoring endianess when converting from binary

2 participants