Skip to content

gadget: add gadget.bytes_maxlen to truncate /Rt bytes column#6409

Open
clmoon2 wants to merge 1 commit into
rizinorg:devfrom
clmoon2:fix-6359-gadget-bytes-maxlen
Open

gadget: add gadget.bytes_maxlen to truncate /Rt bytes column#6409
clmoon2 wants to merge 1 commit into
rizinorg:devfrom
clmoon2:fix-6359-gadget-bytes-maxlen

Conversation

@clmoon2
Copy link
Copy Markdown

@clmoon2 clmoon2 commented May 26, 2026

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository.
  • I made sure to follow the project's coding style.
  • I've documented every RZ_API function and struct this PR changes.
  • I've added tests that prove my changes are effective (required for changes to RZ_API).
  • I've updated the Rizin book with the relevant information (if needed).
  • I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.

Closes #6359.

The bytes column in /Rt table mode shows the full concatenated hex of every instruction in the gadget, which gets visually unmanageable once gadgets are more than a handful of instructions long. The issue asks for a config var to cap that with an ellipsis when it overflows.

Added gadget.bytes_maxlen. Default is 0 so nothing changes for existing users. When set to N, each row's bytes column is capped at 2*N hex chars and a trailing ... is appended.

Scoped to RZ_OUTPUT_MODE_TABLE only. JSON, quiet, and standard modes need the full bytes for downstream consumption, so left alone.

This config option could use a line in the Rizin book; left box 5 unchecked since the book is a separate repo. No test in this PR: the existing /Rt fixture (bins/elf/varsub) has short gadgets that don't exercise the truncation.

…ggh-6359)

The /Rt gadget search table prints the full hex of every gadget in
the bytes column, which gets visually unmanageable once gadgets are
more than a handful of instructions long.

Add gadget.bytes_maxlen (default 0 = no truncation, preserves current
behavior). When set to N, the bytes column for each row is capped at
N bytes (2*N hex chars) with a trailing ... so the table stays
readable even with long gadgets.

Only affects table mode (/Rt); JSON, quiet, and standard modes are
unchanged.
Comment thread librz/core/gadget.c
Comment on lines +1316 to +1318
// gh-6359: optionally cap the bytes column. The hex string
// has two characters per byte, so a byte limit of N maps to
// 2*N hex chars before the truncation marker.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is not needed

Comment thread librz/core/cconfig.c
SETBPREF("gadget.subchains", "false", "Display every length gadget from gadget.len=X to 2");
SETBPREF("gadget.conditional", "false", "Include conditional jump, calls and returns in gadget search");
SETBPREF("gadget.comments", "false", "Display comments in gadget search output");
SETI("gadget.bytes_maxlen", 0, "Truncate the bytes column in /Rt table output to N bytes (0 = no truncation, append ... when truncated)");
Copy link
Copy Markdown
Member

@wargio wargio May 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SETI("gadget.bytes_maxlen", 0, "Truncate the bytes column in /Rt table output to N bytes (0 = no truncation, append ... when truncated)");
SETI("gadget.bytes_maxlen", 0, "Truncate the bytes column in the gadget output table to N bytes (0 = disabled)");

@wargio
Copy link
Copy Markdown
Member

wargio commented May 26, 2026

It's forbidden to remove the checklist. i have added it back. fill it up

@clmoon2
Copy link
Copy Markdown
Author

clmoon2 commented May 28, 2026

filled in the checklist, sorry for stripping it out. let me know if anything else is needed.

@wargio
Copy link
Copy Markdown
Member

wargio commented May 29, 2026

@MrQuantum1915 have a look.

@wargio wargio changed the title gadget: add gadget.bytes_maxlen to truncate /Rt bytes column (gh-6359) gadget: add gadget.bytes_maxlen to truncate /Rt bytes column May 29, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.81%. Comparing base (0b74a61) to head (5d63ee5).
⚠️ Report is 22 commits behind head on dev.

Files with missing lines Patch % Lines
librz/core/gadget.c 14.28% 5 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
librz/core/cconfig.c 80.26% <100.00%> (+<0.01%) ⬆️
librz/core/gadget.c 64.47% <14.28%> (-0.24%) ⬇️

... and 15 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b74a61...5d63ee5. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@MrQuantum1915 MrQuantum1915 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See one suggestion below

Also I think we should add 1 related test in test/db/cmd/cmd_rop.

otherwise LGTM

Comment thread librz/core/cconfig.c
SETBPREF("gadget.subchains", "false", "Display every length gadget from gadget.len=X to 2");
SETBPREF("gadget.conditional", "false", "Include conditional jump, calls and returns in gadget search");
SETBPREF("gadget.comments", "false", "Display comments in gadget search output");
SETI("gadget.bytes_maxlen", 0, "Truncate the bytes column in /Rt table output to N bytes (0 = no truncation, append ... when truncated)");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this config is restricted to only table mode, it would be better to use something like gadget.table.maxbytes

@wargio WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gadget Search: The printed bytes length should be limited by an evar

3 participants