TypePointerRel adjustments

This commit is contained in:
caheckman 2021-11-24 15:22:17 -05:00
parent 6cc2eae322
commit 64534bc774
7 changed files with 98 additions and 12 deletions

View file

@ -785,16 +785,18 @@ void PrintC::opPtrsub(const PcodeOp *op)
TypePointerRel *ptrel;
Datatype *ct;
const Varnode *in0;
uintb in1const;
bool valueon,flex,arrayvalue;
uint4 m;
in0 = op->getIn(0);
in1const = op->getIn(1)->getOffset();
ptype = (TypePointer *)in0->getHigh()->getType();
if (ptype->getMetatype() != TYPE_PTR) {
clear();
throw LowlevelError("PTRSUB off of non-pointer type");
}
if (ptype->isFormalPointerRel()) {
if (ptype->isFormalPointerRel() && ((TypePointerRel *)ptype)->evaluateThruParent(in1const)) {
ptrel = (TypePointerRel *)ptype;
ct = ptrel->getParent();
}
@ -807,10 +809,19 @@ void PrintC::opPtrsub(const PcodeOp *op)
flex = isValueFlexible(in0);
if (ct->getMetatype() == TYPE_STRUCT) {
uintb suboff = op->getIn(1)->getOffset(); // How far into container
uintb suboff = in1const; // How far into container
if (ptrel != (TypePointerRel *)0) {
suboff += ptrel->getPointerOffset();
suboff &= calc_mask(ptype->getSize());
if (suboff == 0) {
// Special case where we do not print a field
pushTypePointerRel(op);
if (flex)
pushVnImplied(in0,op,m | print_load_value);
else
pushVnImplied(in0,op,m);
return;
}
}
suboff = AddrSpace::addressToByte(suboff,ptype->getWordSize());
string fieldname;
@ -904,7 +915,7 @@ void PrintC::opPtrsub(const PcodeOp *op)
}
if (symbol == (Symbol *)0) {
TypeSpacebase *sb = (TypeSpacebase *)ct;
Address addr = sb->getAddress(op->getIn(1)->getOffset(),in0->getSize(),op->getAddr());
Address addr = sb->getAddress(in1const,in0->getSize(),op->getAddr());
pushUnnamedLocation(addr,(Varnode *)0,op);
}
else {
@ -923,7 +934,7 @@ void PrintC::opPtrsub(const PcodeOp *op)
push_integer(0,4,false,(Varnode *)0,op);
}
else if (ct->getMetatype() == TYPE_ARRAY) {
if (op->getIn(1)->getOffset() != 0) {
if (in1const != 0) {
clear();
throw LowlevelError("PTRSUB with non-zero offset into array type");
}