Skip to content

Feature: Highlight conditional gadgets in all modes#6324

Open
MrQuantum1915 wants to merge 1 commit into
rizinorg:devfrom
MrQuantum1915:feat/highlight-cond-gadget
Open

Feature: Highlight conditional gadgets in all modes#6324
MrQuantum1915 wants to merge 1 commit into
rizinorg:devfrom
MrQuantum1915:feat/highlight-cond-gadget

Conversation

@MrQuantum1915
Copy link
Copy Markdown
Contributor

@MrQuantum1915 MrQuantum1915 commented May 7, 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.

Detailed description

As discussed with @notxvilka in mattermost, implemented highlighting of conditional gadgets in all modes (non-color mode too)

This applies when e gadget.conditional=true is set
Please let me know if you mean to highlight conditional terminator instruction in the output no matter what is the state of config : gadget.conditional

Just to be clear is_conditional is set by using a trick actually. We get to know if teminator is conditional or not, by the function in gadget_[rjc]op.c so what i did is :

  • if gadget_is_valid_terminator return true for allow_conditional is passed as true
  • &&
  • return false when allow_conditional is passed as false
  • = the gadget is conditional terminator.

I did this hack so that it is same code for ROP/COP/JOP.

UI/UX and color choices may be slightly questionable, i may be bad at that :)
suggestions welcome...

Here are some ss (arm32)
image
image
image
image
image

I also injected is_conditional key in JSON output when it is, otherwise the key is not injected
an exerpt:

    {
        "opcodes": [
            {
                "offset": 0,
                "size": 4,
                "opcode": "str lr, [sp, -4]!",
                "type": "store"
            },
            {
                "offset": 4,
                "size": 4,
                "opcode": "mov r0, r0",
                "type": "mov"
            },
            {
                "offset": 8,
                "size": 4,
                "opcode": "mov r1, r1",
                "type": "mov"
            },
            {
                "offset": 12,
                "size": 4,
                "opcode": "ldmeq sp!, {pc}",
                "type": "cret"
            }
        ],
        "retaddr": 12,
        "size": 16,
        "is_conditional": true
    },

Test plan

Added (updated) new tests for conditonal gadgets

Closing issues

@MrQuantum1915 MrQuantum1915 force-pushed the feat/highlight-cond-gadget branch 2 times, most recently from 070b71f to 89dfa94 Compare May 11, 2026 10:13
@MrQuantum1915 MrQuantum1915 force-pushed the feat/highlight-cond-gadget branch from 89dfa94 to bed2a85 Compare May 11, 2026 10:15
Copy link
Copy Markdown
Contributor

@notxvilka notxvilka left a comment

Choose a reason for hiding this comment

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

Ideally we would need to follow the colorscheme rather than hardcoding colors, especially important for terminals with white background (see #6338). But it's better done in a separate PR. Currently it's good as is.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 62.06897% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.45%. Comparing base (b4f2c39) to head (bed2a85).

Files with missing lines Patch % Lines
librz/core/gadget.c 62.06% 9 Missing and 13 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
librz/core/gadget.c 63.27% <62.06%> (+1.85%) ⬆️

... and 11 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 b4f2c39...bed2a85. 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.

@MrQuantum1915
Copy link
Copy Markdown
Contributor Author

Ideally we would need to follow the colorscheme rather than hardcoding colors, especially important for terminals with white background (see #6338). But it's better done in a separate PR. Currently it's good as is.

yeah, we'd probably need help from someone better with UI/colors, I am pretty bad at that 😂

Comment thread librz/core/gadget.c
const char *highlight_color = colorize ? Color_CYAN : "";
const char *reset_color = colorize ? Color_RESET : "";
if (is_conditional) {
rz_cons_printf("%sGadget 0x%" PFMT64x " [Conditional Gadget]%s\n", highlight_color, gadget_info->address, reset_color);
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.

Suggested change
rz_cons_printf("%sGadget 0x%" PFMT64x " [Conditional Gadget]%s\n", highlight_color, gadget_info->address, reset_color);
rz_cons_printf("%sGadget 0x%" PFMT64x " [Conditional]%s\n", highlight_color, gadget_info->address, reset_color);

Comment thread librz/core/gadget.c
const char *highlight_color = colorize ? Color_CYAN : "";
const char *reset_color = colorize ? Color_RESET : "";
if (is_conditional) {
rz_cons_printf("%sGadget 0x%" PFMT64x " (size %d bytes) [Conditional Gadget]%s\n", highlight_color, addr, size, reset_color);
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.

Suggested change
rz_cons_printf("%sGadget 0x%" PFMT64x " (size %d bytes) [Conditional Gadget]%s\n", highlight_color, addr, size, reset_color);
rz_cons_printf("%sGadget 0x%" PFMT64x " (size %d bytes) [Conditional]%s\n", highlight_color, addr, size, reset_color);

Comment thread test/db/cmd/cmd_rop
Comment on lines +4146 to +4154
0x00000000 04e02de50000a0e10110a0e10080bd08 [Conditional Gadget] str lr, [sp, -4]!; ; mov r0, r0; ; mov r1, r1; ; ldmeq sp!, {pc};
0x00000004 0000a0e10110a0e10080bd08 [Conditional Gadget] mov r0, r0; ; mov r1, r1; ; ldmeq sp!, {pc};
0x00000008 0110a0e10080bd08 [Conditional Gadget] mov r1, r1; ; ldmeq sp!, {pc};
0x0000000c 0080bd08 [Conditional Gadget] ldmeq sp!, {pc};
0x00000000 04e02de50000a0e10110a0e10080bd081eff2fe1 str lr, [sp, -4]!; ; mov r0, r0; ; mov r1, r1; ; ldmeq sp!, {pc}; ; bx lr;
0x00000004 0000a0e10110a0e10080bd081eff2fe1 mov r0, r0; ; mov r1, r1; ; ldmeq sp!, {pc}; ; bx lr;
0x00000008 0110a0e10080bd081eff2fe1 mov r1, r1; ; ldmeq sp!, {pc}; ; bx lr;
0x0000000c 0080bd081eff2fe1 ldmeq sp!, {pc}; ; bx lr;
0x00000010 1eff2fe1 bx lr;
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.

the bytes length should be limited by an evar.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants