mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
Restrict distribution producing non-multiples if no sub-components
This commit is contained in:
parent
40bb05d8ed
commit
4f1adfcfc0
2 changed files with 16 additions and 9 deletions
|
@ -5626,7 +5626,8 @@ AddTreeState::AddTreeState(Funcdata &d,PcodeOp *op,int4 slot)
|
||||||
ct = (const TypePointer *)ptr->getType();
|
ct = (const TypePointer *)ptr->getType();
|
||||||
ptrsize = ptr->getSize();
|
ptrsize = ptr->getSize();
|
||||||
ptrmask = calc_mask(ptrsize);
|
ptrmask = calc_mask(ptrsize);
|
||||||
size = AddrSpace::byteToAddressInt(ct->getPtrTo()->getSize(),ct->getWordSize());
|
baseType = ct->getPtrTo();
|
||||||
|
size = AddrSpace::byteToAddressInt(baseType->getSize(),ct->getWordSize());
|
||||||
multsum = 0; // Sums start out as zero
|
multsum = 0; // Sums start out as zero
|
||||||
nonmultsum = 0;
|
nonmultsum = 0;
|
||||||
correct = 0;
|
correct = 0;
|
||||||
|
@ -5701,16 +5702,21 @@ bool AddTreeState::checkTerm(Varnode *vn,uintb treeCoeff)
|
||||||
|
|
||||||
if (vn == ptr) return false;
|
if (vn == ptr) return false;
|
||||||
if (vn->isConstant()) {
|
if (vn->isConstant()) {
|
||||||
if (treeCoeff != 1)
|
|
||||||
isDistributeUsed = true;
|
|
||||||
val = vn->getOffset() * treeCoeff;
|
val = vn->getOffset() * treeCoeff;
|
||||||
intb sval = (intb)val;
|
intb sval = (intb)val;
|
||||||
sign_extend(sval,vn->getSize()*8-1);
|
sign_extend(sval,vn->getSize()*8-1);
|
||||||
intb rem = (size == 0) ? sval : (sval % size);
|
intb rem = (size == 0) ? sval : (sval % size);
|
||||||
if (rem!=0) { // constant is not multiple of size
|
if (rem!=0) { // constant is not multiple of size
|
||||||
|
if (treeCoeff != 1) {
|
||||||
|
// An offset "into" the base data-type makes little sense unless is has subcomponents
|
||||||
|
if (baseType->getMetatype() == TYPE_ARRAY || baseType->getMetatype() == TYPE_STRUCT)
|
||||||
|
isDistributeUsed = true;
|
||||||
|
}
|
||||||
nonmultsum += val;
|
nonmultsum += val;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (treeCoeff != 1)
|
||||||
|
isDistributeUsed = true;
|
||||||
multsum += val; // Add multiples of size into multsum
|
multsum += val; // Add multiples of size into multsum
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5786,11 +5792,11 @@ void AddTreeState::calcSubtype(void)
|
||||||
}
|
}
|
||||||
isSubtype = false; // There are no offsets INTO the pointer
|
isSubtype = false; // There are no offsets INTO the pointer
|
||||||
}
|
}
|
||||||
else if (ct->getPtrTo()->getMetatype() == TYPE_SPACEBASE) {
|
else if (baseType->getMetatype() == TYPE_SPACEBASE) {
|
||||||
uintb nonmultbytes = AddrSpace::addressToByte(nonmultsum,ct->getWordSize()); // Convert to bytes
|
uintb nonmultbytes = AddrSpace::addressToByte(nonmultsum,ct->getWordSize()); // Convert to bytes
|
||||||
uintb extra;
|
uintb extra;
|
||||||
// Get offset into mapped variable
|
// Get offset into mapped variable
|
||||||
if (ct->getPtrTo()->getSubType(nonmultbytes, &extra) == (Datatype*)0) {
|
if (baseType->getSubType(nonmultbytes, &extra) == (Datatype*)0) {
|
||||||
valid = false; // Cannot find mapped variable but nonmult is non-empty
|
valid = false; // Cannot find mapped variable but nonmult is non-empty
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5798,12 +5804,12 @@ void AddTreeState::calcSubtype(void)
|
||||||
offset = (nonmultsum - extra) & ptrmask;
|
offset = (nonmultsum - extra) & ptrmask;
|
||||||
isSubtype = true;
|
isSubtype = true;
|
||||||
}
|
}
|
||||||
else if (ct->getPtrTo()->getMetatype() == TYPE_STRUCT) {
|
else if (baseType->getMetatype() == TYPE_STRUCT) {
|
||||||
uintb nonmultbytes = AddrSpace::addressToByte(nonmultsum,ct->getWordSize()); // Convert to bytes
|
uintb nonmultbytes = AddrSpace::addressToByte(nonmultsum,ct->getWordSize()); // Convert to bytes
|
||||||
uintb extra;
|
uintb extra;
|
||||||
// Get offset into field in structure
|
// Get offset into field in structure
|
||||||
if (ct->getPtrTo()->getSubType(nonmultbytes, &extra) == (Datatype*) 0) {
|
if (baseType->getSubType(nonmultbytes, &extra) == (Datatype*) 0) {
|
||||||
if (nonmultbytes >= ct->getPtrTo()->getSize()) {
|
if (nonmultbytes >= size) {
|
||||||
valid = false; // Out of structure's bounds
|
valid = false; // Out of structure's bounds
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5813,7 +5819,7 @@ void AddTreeState::calcSubtype(void)
|
||||||
offset = (nonmultsum - extra) & ptrmask;
|
offset = (nonmultsum - extra) & ptrmask;
|
||||||
isSubtype = true;
|
isSubtype = true;
|
||||||
}
|
}
|
||||||
else if (ct->getPtrTo()->getMetatype() == TYPE_ARRAY) {
|
else if (baseType->getMetatype() == TYPE_ARRAY) {
|
||||||
isSubtype = true;
|
isSubtype = true;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ class AddTreeState {
|
||||||
PcodeOp *baseOp; ///< Base of the ADD tree
|
PcodeOp *baseOp; ///< Base of the ADD tree
|
||||||
Varnode *ptr; ///< The pointer varnode
|
Varnode *ptr; ///< The pointer varnode
|
||||||
const TypePointer *ct; ///< The pointer data-type
|
const TypePointer *ct; ///< The pointer data-type
|
||||||
|
const Datatype *baseType; ///< The base data-type being pointed at
|
||||||
int4 ptrsize; ///< Size of the pointer
|
int4 ptrsize; ///< Size of the pointer
|
||||||
int4 size; ///< Size of data-type being pointed to
|
int4 size; ///< Size of data-type being pointed to
|
||||||
uintb ptrmask; ///< Mask for modulo calculations in ptr space
|
uintb ptrmask; ///< Mask for modulo calculations in ptr space
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue