Skip to content

Comments

decompiler: fix bit extractions with RuleShiftAnd and RuleShiftCompare#8718

Merged
ryanmkurtz merged 1 commit intoNationalSecurityAgency:masterfrom
fkil:ghidra_issue_8717
Jan 13, 2026
Merged

decompiler: fix bit extractions with RuleShiftAnd and RuleShiftCompare#8718
ryanmkurtz merged 1 commit intoNationalSecurityAgency:masterfrom
fkil:ghidra_issue_8717

Conversation

@fkil
Copy link
Contributor

@fkil fkil commented Dec 2, 2025

Fixes #8717

RuleShiftAnd previously replaced the AND opcode with COPY. This, however doesn't update the NZMask of the Varnode. As a result, following rules may assume the NZMask after the AND operation also applies to the Varnode being copied.

In combination with RuleShiftCompare, an expression of the form (a & bitmask) >> const != 0, wrongfully is reduced to a != 0. Instead of replacing the AND with COPY, we now replace the input of the shift operation instead. This way, future rules will see the correct NZMask.

Fixes NationalSecurityAgency#8717

RuleShiftAnd previously replaced the AND opcode with COPY. This,
however doesn't update the NZMask of the Varnode. As a result, following
rules may assume the NZMask after the AND operation also applies to the
Varnode being copied.

In combination with RuleShiftCompare, an expression of the form
(a & bitmask) >> const != 0, wrongfully is reduced to a != 0.
Instead of replacing the AND with COPY, we now replace the input
of the shift operation instead. This way, future rules will see
the correct NZMask.
@ryanmkurtz ryanmkurtz added Feature: Decompiler Status: Triage Information is being gathered labels Dec 3, 2025
@ryanmkurtz ryanmkurtz added Status: Internal This is being tracked internally by the Ghidra team and removed Status: Triage Information is being gathered labels Jan 13, 2026
@ryanmkurtz ryanmkurtz added this to the 12.1 milestone Jan 13, 2026
@ryanmkurtz ryanmkurtz merged commit 92091a7 into NationalSecurityAgency:master Jan 13, 2026
ryanmkurtz added a commit that referenced this pull request Jan 13, 2026
'origin/GP-6318_caheckman_PR-8718_fkil_ghidra_issue_8717' (Closes #8717,
Closes #8718)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature: Decompiler Status: Internal This is being tracked internally by the Ghidra team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decompiler: Ghidra sometimes incorrectly optimizes bit extractions that use AND and RSHIFT

3 participants