mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 02:09:44 +02:00
GP-3873 Data-type alignment support in decompiler
This commit is contained in:
parent
6508088623
commit
64a58bdeab
29 changed files with 456 additions and 149 deletions
|
@ -3324,9 +3324,23 @@ int4 RuleDoubleLoad::applyOp(PcodeOp *op,Funcdata &data)
|
|||
Varnode *piece1 = op->getIn(1);
|
||||
if (!piece0->isWritten()) return 0;
|
||||
if (!piece1->isWritten()) return 0;
|
||||
if (piece0->getDef()->code() != CPUI_LOAD) return false;
|
||||
if (piece1->getDef()->code() != CPUI_LOAD) return false;
|
||||
if (!SplitVarnode::testContiguousPointers(piece0->getDef(),piece1->getDef(),loadlo,loadhi,spc))
|
||||
PcodeOp *load1 = piece1->getDef();
|
||||
if (load1->code() != CPUI_LOAD) return false;
|
||||
PcodeOp *load0 = piece0->getDef();
|
||||
OpCode opc = load0->code();
|
||||
int4 offset = 0;
|
||||
if (opc == CPUI_SUBPIECE) {
|
||||
// Check for 2 LOADs but most significant part of most significant LOAD is discarded
|
||||
if (load0->getIn(1)->getOffset() != 0) return false;
|
||||
Varnode *vn0 = load0->getIn(0);
|
||||
if (!vn0->isWritten()) return false;
|
||||
offset = vn0->getSize() - piece0->getSize();
|
||||
load0 = vn0->getDef();
|
||||
opc = load0->code();
|
||||
}
|
||||
if (opc != CPUI_LOAD)
|
||||
return false;
|
||||
if (!SplitVarnode::testContiguousPointers(load0,load1,loadlo,loadhi,spc))
|
||||
return 0;
|
||||
|
||||
size = piece0->getSize() + piece1->getSize();
|
||||
|
@ -3340,8 +3354,17 @@ int4 RuleDoubleLoad::applyOp(PcodeOp *op,Funcdata &data)
|
|||
data.opSetOpcode(newload,CPUI_LOAD);
|
||||
data.opSetInput(newload,spcvn,0);
|
||||
Varnode *addrvn = loadlo->getIn(1);
|
||||
if (addrvn->isConstant())
|
||||
addrvn = data.newConstant(addrvn->getSize(),addrvn->getOffset());
|
||||
if (spc->isBigEndian() && offset != 0) {
|
||||
// If the most significant part of LOAD is discarded, we need to add discard amount to pointer
|
||||
PcodeOp *newadd = data.newOp(2,latest->getAddr());
|
||||
Varnode *addout = data.newUniqueOut(addrvn->getSize(),newadd);
|
||||
data.opSetOpcode(newadd,CPUI_INT_ADD);
|
||||
data.opSetInput(newadd,addrvn,0);
|
||||
data.opSetInput(newadd,data.newConstant(addrvn->getSize(), offset),1);
|
||||
data.opInsertAfter(newadd,latest);
|
||||
addrvn = addout;
|
||||
latest = newadd;
|
||||
}
|
||||
data.opSetInput(newload,addrvn,1);
|
||||
// We need to guarantee that -newload- reads -addrvn- after
|
||||
// it has been defined. So insert it after the latest.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue