Skip to content

Decompiler: Add support for INT_REM in jumptable recovery.#6070

Closed
LukeSerne wants to merge 3 commits into
NationalSecurityAgency:masterfrom
LukeSerne:decomp-jumptable-recovery-add-int-rem
Closed

Decompiler: Add support for INT_REM in jumptable recovery.#6070
LukeSerne wants to merge 3 commits into
NationalSecurityAgency:masterfrom
LukeSerne:decomp-jumptable-recovery-add-int-rem

Conversation

@LukeSerne

Copy link
Copy Markdown
Contributor

This commit adds INT_REM handling to the JumpBasic class, which allows switch statements depending on expressions like x % 10 to be properly recovered. Previously, a warning was emitted about there being "too many branches". This slightly improves the third problem mentioned in #2628 (comment).

Screenshots
These screenshots show the main function of the switch example from GhidraDocs/GhidraClass/Advanced/Examples after auto-analysis.

Before applying the patch
image

After applying the patch
image

Comment thread Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc Outdated
@LukeSerne LukeSerne force-pushed the decomp-jumptable-recovery-add-int-rem branch from 7da9f4f to 1cae319 Compare December 31, 2023 17:32
@ryanmkurtz ryanmkurtz added Feature: Decompiler Status: Triage Information is being gathered labels Jan 2, 2024
@Nemoumbra

Copy link
Copy Markdown

image

This won't help with my case... sniff

@LukeSerne

Copy link
Copy Markdown
Contributor Author

@Nemoumbra could you share the bytes / instructions corresponding to the function containing that segment? I tried reproducing this, but even when the assembly clearly did a comparison of the switch variable before the lookup, the decompiler still properly decompiled the switch. It might be that there is more in your function that contributes to the problem. Either way, I think it's better to continue discussion in issue #2628.

@ryanmkurtz is there anything I can do to help get this PR out of triage, and closer to being merged?

@Nemoumbra

Copy link
Copy Markdown

@LukeSerne I have no clue which program I was studying back then.😭
And I have not tried it with latest Ghidra either, maybe it'd be fine there.

Comment thread Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc Outdated
This commit adds INT_REM handling to JumpBasic, which allows switch statements
depending on expressions like "x % 10" to be properly recovered. Previously, a
warning was emitted about there being "too many branches".
This commit adds a fallback to use the non-zero mask to determine the
maximum value a varnode can take. It also slightly improves the case
where a varnode is defined by a MULTIEQUAL by recursively calling the
getMaxValue function.
By keeping track of how deep in the recursive chain we are, we can avoid
infinite recursion.
@LukeSerne LukeSerne force-pushed the decomp-jumptable-recovery-add-int-rem branch from 632a0d0 to 6572c4a Compare June 19, 2026 18:18
@ryanmkurtz ryanmkurtz added Status: Internal This is being tracked internally by the Ghidra team and removed Status: Triage Information is being gathered labels Jul 6, 2026
@ryanmkurtz ryanmkurtz added this to the 12.2 milestone Jul 6, 2026
@ryanmkurtz ryanmkurtz added the Reason: Internal effort This will be solved internally label Jul 6, 2026
@ryanmkurtz ryanmkurtz closed this in db03910 Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature: Decompiler Reason: Internal effort This will be solved internally Status: Internal This is being tracked internally by the Ghidra team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants