Skip to content

Ghidra is a software reverse engineering (SRE) framework

Added getSplit based on lane subset

caheckman2f3415de8c5a
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc
index 2cc374f1c2..f2139d79e3 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/transform.cc
@@ -373,8 +373,9 @@ TransformVar *TransformManager::newSplit(Varnode *vn,const LaneDescription &desc
{
TransformVar *res = new TransformVar[numLanes];
pieceMap[vn->getCreateIndex()] = res;
+ int4 baseBitPos = description.getPosition(startLane) * 8;
for(int4 i=0;i<numLanes;++i) {
- int4 bitpos = description.getPosition(startLane + i) * 8;
+ int4 bitpos = description.getPosition(startLane + i) * 8 - baseBitPos;
int4 byteSize = description.getSize(startLane + i);
TransformVar *newVar = &res[i];
if (vn->isConstant())
@@ -511,6 +512,26 @@ TransformVar *TransformManager::getSplit(Varnode *vn,const LaneDescription &desc
return newSplit(vn,description);
}
+/// \brief Find (or create) placeholder nodes splitting a Varnode into a subset of lanes from a description
+///
+/// Given a big Varnode and a specific subset of a lane description, look up placeholders
+/// for all the explicit pieces. If they don't exist, create them.
+/// \param vn is the big Varnode to split
+/// \param description describes all the possible lanes
+/// \param numLanes is the number of lanes in the subset
+/// \param startLane is the starting (least significant) lane in the subset
+/// \return an array of the TransformVar placeholders from least to most significant
+TransformVar *TransformManager::getSplit(Varnode *vn,const LaneDescription &description,int4 numLanes,int4 startLane)
+
+{
+ map<int4,TransformVar *>::const_iterator iter;
+ iter = pieceMap.find(vn->getCreateIndex());
+ if (iter != pieceMap.end()) {
+ return (*iter).second;
+ }
+ return newSplit(vn,description,numLanes,startLane);
+}
+
/// \brief Handle some special PcodeOp marking
/// If a PcodeOp is an INDIRECT creation, we need to do special marking of the op and Varnodes
/// \param rop is the placeholder op with the special requirement
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/transform.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/transform.hh
index 2f5a13a946..a388b3d811 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/transform.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/transform.hh
@@ -143,6 +143,7 @@ public:
TransformVar *getPreexistingVarnode(Varnode *vn); ///< Get (or create) placeholder for preexisting Varnode
TransformVar *getPiece(Varnode *vn,int4 bitSize,int4 lsbOffset); ///< Get (or create) placeholder piece
TransformVar *getSplit(Varnode *vn,const LaneDescription &description);
+ TransformVar *getSplit(Varnode *vn,const LaneDescription &description,int4 numLanes,int4 startLane);
void opSetInput(TransformOp *rop,TransformVar *rvn,int4 slot); ///< Mark given variable as input to given op
void opSetOutput(TransformOp *rop,TransformVar *rvn); ///< Mark given variable as output of given op