Skip to content

Commit

Permalink
RulePullsubMulti adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
caheckman committed Mar 2, 2020
1 parent 47290cc commit 921eb9c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -945,11 +945,24 @@ int4 RulePullsubMulti::applyOp(PcodeOp *op,Funcdata &data)
Varnode *outvn = op->getOut();
if (outvn->isPrecisLo()||outvn->isPrecisHi()) return 0; // Don't pull apart a double precision object

// Make sure we don't new add SUBPIECE ops that aren't going to cancel in some way
int4 branches = mult->numInput();
uintb consume = calc_mask(newSize) << 8*minByte;
consume = ~consume;
consume = ~consume; // Check for use of bits outside of what gets truncated later
for(int4 i=0;i<branches;++i) {
if ((consume & mult->getIn(i)->getConsume()) != 0) return 0;
Varnode *inVn = mult->getIn(i);
if ((consume & inVn->getConsume()) != 0) { // Check if bits not truncated are still used
// Check if there's an extension that matches the truncation
if (minByte == 0 && inVn->isWritten()) {
PcodeOp *defOp = inVn->getDef();
OpCode opc = defOp->code();
if (opc == CPUI_INT_ZEXT || opc == CPUI_INT_SEXT) {
if (newSize == defOp->getIn(0)->getSize())
continue; // We have matching extension, so new SUBPIECE will cancel anyway
}
}
return 0;
}
}

Address smalladdr2;
Expand Down

0 comments on commit 921eb9c

Please sign in to comment.