Ghidra is a software reverse engineering (SRE) framework
GP-6130 Correct pointer offsets for buildStore and buildLoad
caheckman35ac4cf37cd1
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.ccindex d7aef4dca3..c47293afb9 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc@@ -3715,13 +3715,11 @@ bool LaneDivide::buildStore(PcodeOp *op,int4 numLanes,int4 skipLanes)}TransformVar *basePtr = getPreexistingVarnode(origPtr);int4 ptrSize = origPtr->getSize();- Varnode *valueVn = op->getIn(2);- for(int4 i=0;i<numLanes;++i) {+ // Order lanes by pointer offset. Least significant to most for little endian, or most significant to least for big endian.+ int8 bytePos = 0; // Smallest pointer offset+ for(int4 count=0;count<numLanes;++count) {+ int4 i = spc->isBigEndian() ? numLanes -1 - count: count; // little = least to most, big = most to leastTransformOp *ropStore = newOpReplace(3, CPUI_STORE, op);- int4 bytePos = description.getPosition(skipLanes + i);- int4 sz = description.getSize(skipLanes + i);- if (spc->isBigEndian())- bytePos = valueVn->getSize() - (bytePos + sz); // Convert position to address order// Construct the pointerTransformVar *ptrVn;@@ -3738,6 +3736,7 @@ bool LaneDivide::buildStore(PcodeOp *op,int4 numLanes,int4 skipLanes)opSetInput(ropStore,newConstant(spaceConstSize,0,spaceConst),0);opSetInput(ropStore,ptrVn,1);opSetInput(ropStore,inVars+i,2);+ bytePos += description.getSize(skipLanes + i);}return true;}@@ -3763,13 +3762,11 @@ bool LaneDivide::buildLoad(PcodeOp *op,TransformVar *outVars,int4 numLanes,int4}TransformVar *basePtr = getPreexistingVarnode(origPtr);int4 ptrSize = origPtr->getSize();- int4 outSize = op->getOut()->getSize();- for(int4 i=0;i<numLanes;++i) {+ // Order lanes by pointer offset. Least significant to most for little endian, or most significant to least for big endian.+ int8 bytePos = 0; // Smallest pointer offset+ for(int4 count=0;count<numLanes;++count) {TransformOp *ropLoad = newOpReplace(2, CPUI_LOAD, op);- int4 bytePos = description.getPosition(skipLanes + i);- int4 sz = description.getSize(skipLanes + i);- if (spc->isBigEndian())- bytePos = outSize - (bytePos + sz); // Convert position to address order+ int4 i = spc->isBigEndian() ? numLanes - 1 - count : count; // little = least to most, big = most to least// Construct the pointerTransformVar *ptrVn;@@ -3786,6 +3783,7 @@ bool LaneDivide::buildLoad(PcodeOp *op,TransformVar *outVars,int4 numLanes,int4opSetInput(ropLoad,newConstant(spaceConstSize,0,spaceConst),0);opSetInput(ropLoad,ptrVn,1);opSetOutput(ropLoad,outVars+i);+ bytePos += description.getSize(skipLanes + i);}return true;}