Ghidra is a software reverse engineering (SRE) framework
GP-6310 Apply extension patch if consumption is beyond small variable
caheckman123bd5cbe6d5
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.ccindex c47293afb9..260313c576 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc@@ -417,7 +417,7 @@ bool SubvariableFlow::traceForward(ReplaceVarnode *rvn)}// Is the small variable getting zero padded into something that is fully consumedif ((!aggressive)&&((outvn->getConsume() & rvn->mask) != outvn->getConsume())) {- addSuggestedPatch(rvn,op,-1);+ addExtensionPatch(rvn,op,-1);hcount += 1; // Dealt with this descendantbreak;}@@ -477,10 +477,10 @@ bool SubvariableFlow::traceForward(ReplaceVarnode *rvn)newmask = (rvn->mask << sa) & calc_mask( outvn->getSize() );if (newmask == 0) break; // Subvar is cleared, truncate flowif (rvn->mask != (newmask >> sa)) return false; // subvar is clipped- // Is the small variable getting zero padded into something that is fully consumed+ // Is the small variable getting zero padded into something that is consumed beyond the variableif (((rvn->mask & 1)!=0)&&(sa + bitsize == 8*outvn->getSize())- &&(calc_mask(outvn->getSize()) == outvn->getConsume())) {- addSuggestedPatch(rvn,op,sa);+ &&((outvn->getConsume() & ~newmask) != 0)) {+ addExtensionPatch(rvn,op,sa);hcount += 1;break;}@@ -514,10 +514,10 @@ bool SubvariableFlow::traceForward(ReplaceVarnode *rvn)hcount += 1; // Dealt with this descendantbreak;}- // Is the small variable getting zero padded into something that is fully consumed+ // Is the small variable getting zero padded into something that is consumed beyond the variableif (((newmask&1)==1)&&(sa + bitsize == 8*outvn->getSize())- &&(calc_mask(outvn->getSize()) == outvn->getConsume())) {- addSuggestedPatch(rvn,op,0);+ &&((outvn->getConsume() & ~newmask) != 0)) {+ addExtensionPatch(rvn,op,0);hcount += 1;break;}@@ -1211,14 +1211,14 @@ void SubvariableFlow::addBooleanPatch(PcodeOp *pullop,ReplaceVarnode *rvn,int4 s// this is not a true modification}-/// \brief Mark a subgraph variable flowing to an operation that expands it by padding with zero bits.+/// \brief Mark a subgraph variable flowing to an operation that extends it by padding with zero bits.////// Data-flow along the specified edge within the logical subgraph is terminated by added a PatchRecord./// This doesn't count as a logical value that needs to be patched (by itself)./// \param rvn is the given subgraph variable/// \param pushop is the operation that pads the variable/// \param sa is the amount the logical value is shifted to the left-void SubvariableFlow::addSuggestedPatch(ReplaceVarnode *rvn,PcodeOp *pushop,int4 sa)+void SubvariableFlow::addExtensionPatch(ReplaceVarnode *rvn,PcodeOp *pushop,int4 sa){patchlist.emplace_back();diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hhindex d389e8979d..6843eb77d8 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh@@ -114,7 +114,7 @@ class SubvariableFlow {void addTerminalPatch(PcodeOp *pullop,ReplaceVarnode *rvn);void addTerminalPatchSameOp(PcodeOp *pullop,ReplaceVarnode *rvn,int4 slot);void addBooleanPatch(PcodeOp *pullop,ReplaceVarnode *rvn,int4 slot);- void addSuggestedPatch(ReplaceVarnode *rvn,PcodeOp *pushop,int4 sa);+ void addExtensionPatch(ReplaceVarnode *rvn,PcodeOp *pushop,int4 sa);void addComparePatch(ReplaceVarnode *in1,ReplaceVarnode *in2,PcodeOp *op);ReplaceVarnode *addConstant(ReplaceOp *rop,uintb mask,uint4 slot,Varnode *constvn);ReplaceVarnode *addNewConstant(ReplaceOp *rop,uint4 slot,uintb val);