Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3609 Split based on endianess of output AddrSpace

caheckman0b13fc710955
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc
index f5074f6cf1..befa26c1e8 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc
@@ -2085,11 +2085,11 @@ bool SplitDatatype::generateConstants(Varnode *vn,vector<Varnode *> &inVarnodes)
/// based on the input offsets in \b dataTypePieces.
/// \param rootVn is the given root constant
/// \param inVarnodes is the container for the new Varnodes
-void SplitDatatype::buildInConstants(Varnode *rootVn,vector<Varnode *> &inVarnodes)
+/// \param bigEndian is \b true if the output address space is big endian
+void SplitDatatype::buildInConstants(Varnode *rootVn,vector<Varnode *> &inVarnodes,bool bigEndian)
{
uintb baseVal = rootVn->getOffset();
- bool bigEndian = rootVn->getSpace()->isBigEndian();
for(int4 i=0;i<dataTypePieces.size();++i) {
Datatype *dt = dataTypePieces[i].inType;
int4 off = dataTypePieces[i].offset;
@@ -2346,7 +2346,7 @@ bool SplitDatatype::splitCopy(PcodeOp *copyOp,Datatype *inType,Datatype *outType
vector<Varnode *> inVarnodes;
vector<Varnode *> outVarnodes;
if (inVn->isConstant())
- buildInConstants(inVn,inVarnodes);
+ buildInConstants(inVn,inVarnodes,outVn->getSpace()->isBigEndian());
else
buildInSubpieces(inVn,copyOp,inVarnodes);
buildOutVarnodes(outVn,outVarnodes);
@@ -2461,9 +2461,10 @@ bool SplitDatatype::splitStore(PcodeOp *storeOp,Datatype *outType)
return false;
}
+ AddrSpace *storeSpace = storeOp->getIn(0)->getSpaceFromConst();
vector<Varnode *> inVarnodes;
if (inVn->isConstant())
- buildInConstants(inVn,inVarnodes);
+ buildInConstants(inVn,inVarnodes,storeSpace->isBigEndian());
else if (loadOp != (PcodeOp *)0) {
vector<Varnode *> loadPtrs;
buildPointers(loadRoot.pointer, loadRoot.ptrType, loadRoot.baseOffset, loadOp, loadPtrs, true);
@@ -2485,7 +2486,6 @@ bool SplitDatatype::splitStore(PcodeOp *storeOp,Datatype *outType)
vector<Varnode *> storePtrs;
buildPointers(storeRoot.pointer, storeRoot.ptrType, storeRoot.baseOffset, storeOp, storePtrs, false);
- AddrSpace *storeSpace = storeOp->getIn(0)->getSpaceFromConst();
// Preserve original STORE object, so that INDIRECT references are still valid
// but convert it into the first of the smaller STOREs
data.opSetInput(storeOp,storePtrs[0],1);
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh
index 83460c4497..17353af49a 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.hh
@@ -188,7 +188,7 @@ class SplitDatatype {
bool testDatatypeCompatibility(Datatype *inBase,Datatype *outBase,bool inConstant);
bool testCopyConstraints(PcodeOp *copyOp);
bool generateConstants(Varnode *vn,vector<Varnode *> &inVarnodes);
- void buildInConstants(Varnode *rootVn,vector<Varnode *> &inVarnodes);
+ void buildInConstants(Varnode *rootVn,vector<Varnode *> &inVarnodes,bool bigEndian);
void buildInSubpieces(Varnode *rootVn,PcodeOp *followOp,vector<Varnode *> &inVarnodes);
void buildOutVarnodes(Varnode *rootVn,vector<Varnode *> &outVarnodes);
void buildOutConcats(Varnode *rootVn,PcodeOp *previousOp,vector<Varnode *> &outVarnodes);