Skip to content

Ghidra is a software reverse engineering (SRE) framework

Fix allowing decompiler to simplify some forms of division/remainder constructions

caheckman4e3d6552bd99
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
index d91ecb870d..31eef80eb3 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
@@ -3192,7 +3192,13 @@ int4 RuleShiftPiece::applyOp(PcodeOp *op,Funcdata &data)
(zexthiop->code()!= CPUI_INT_SEXT))
return 0;
vn1 = zexthiop->getIn(0);
- if (vn1->isFree()) return 0;
+ if (vn1->isConstant()) {
+ if (vn1->getSize() < sizeof(uintb))
+ return 0; // Normally we let ZEXT of a constant collapse naturally
+ // But if the ZEXTed constant is too big, this won't happen
+ }
+ else if (vn1->isFree())
+ return 0;
int4 sa = shiftop->getIn(1)->getOffset();
int4 concatsize = sa + 8*vn1->getSize();
if (op->getOut()->getSize() * 8 < concatsize) return 0;