Skip to content

Commit 56002b7

Browse files
committed
Merge remote-tracking branch
'origin/GP-7063_caheckman_DetectSymbolConflict' (Closes #9217)
2 parents ae7432b + 6740b89 commit 56002b7

25 files changed

Lines changed: 828 additions & 638 deletions

File tree

Ghidra/Features/Decompiler/src/decompile/cpp/constseq.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ uint4 ArraySequence::selectStringCopyFunction(int4 &index)
185185
/// \param ent is the given Symbol
186186
/// \param root is the COPY holding the constant
187187
/// \param addr is the Address being COPYed into
188-
StringSequence::StringSequence(Funcdata &fdata,Datatype *ct,SymbolEntry *ent,PcodeOp *root,const Address &addr)
188+
StringSequence::StringSequence(Funcdata &fdata,Datatype *ct,MapEntry *ent,PcodeOp *root,const Address &addr)
189189
: ArraySequence(fdata,ct,root)
190190
{
191191
rootAddr = addr;
@@ -987,8 +987,8 @@ int4 RuleStringCopy::applyOp(PcodeOp *op,Funcdata &data)
987987
if (!ct->isCharPrint()) return 0; // Copied to a "char" data-type Varnode
988988
if (ct->isOpaqueString()) return 0;
989989
if (!outvn->isAddrTied()) return 0;
990-
SymbolEntry *entry = data.getScopeLocal()->queryContainer(outvn->getAddr(), outvn->getSize(), op->getAddr());
991-
if (entry == (SymbolEntry *)0)
990+
MapEntry *entry = data.getScopeLocal()->queryContainer(outvn->getAddr(), outvn->getSize(), op->getAddr());
991+
if (entry == (MapEntry *)0)
992992
return 0;
993993
StringSequence sequence(data,ct,entry,op,outvn->getAddr());
994994
if (!sequence.isValid())

Ghidra/Features/Decompiler/src/decompile/cpp/constseq.hh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
namespace ghidra {
2424

25+
class MapEntry;
26+
2527
/// \brief A sequence of PcodeOps that move data in-to/out-of an array data-type.
2628
///
2729
/// A container for a sequence of PcodeOps within a basic block where we are trying to determine if the sequence
@@ -66,15 +68,15 @@ public:
6668
class StringSequence : public ArraySequence {
6769
Address rootAddr; ///< Address within the memory region associated with the root PcodeOp
6870
Address startAddr; ///< Starting address of the memory region
69-
SymbolEntry *entry; ///< Symbol at the root Address
71+
MapEntry *entry; ///< Symbol at the root Address
7072
bool collectCopyOps(int size); ///< Collect ops COPYing constants into the memory region
7173
PcodeOp *buildStringCopy(void); ///< Build the strncpy,wcsncpy, or memcpy function with string as input
7274
static void removeForward(const WriteNode &curNode,map<PcodeOp *,list<WriteNode>::iterator> &xref,
7375
list<WriteNode> &points,vector<WriteNode> &deadOps);
7476
void removeCopyOps(PcodeOp *replaceOp); ///< Remove all the COPY ops from the basic block
7577
Varnode *constructTypedPointer(PcodeOp *insertPoint);
7678
public:
77-
StringSequence(Funcdata &fdata,Datatype *ct,SymbolEntry *ent,PcodeOp *root,const Address &addr);
79+
StringSequence(Funcdata &fdata,Datatype *ct,MapEntry *ent,PcodeOp *root,const Address &addr);
7880
bool transform(void); ///< Transform COPYs into a single memcpy user-op
7981
};
8082

Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,9 +1071,8 @@ bool ActionConstantPtr::checkCopy(PcodeOp *op,Funcdata &data)
10711071
/// \param fullEncoding will hold the full pointer encoding being passed back
10721072
/// \param data is the function being analyzed
10731073
/// \return the recovered symbol or NULL
1074-
SymbolEntry *ActionConstantPtr::isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op,int4 slot,
1075-
Address &rampoint,uintb &fullEncoding,Funcdata &data)
1076-
1074+
MapEntry *ActionConstantPtr::isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op,int4 slot,
1075+
Address &rampoint,uintb &fullEncoding,Funcdata &data)
10771076
{
10781077
bool needexacthit;
10791078
vn->setSymbolCheck(Varnode::symcheck_complete);
@@ -1084,7 +1083,7 @@ SymbolEntry *ActionConstantPtr::isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op
10841083
needexacthit = false;
10851084
}
10861085
else {
1087-
if (vn->isTypeLock()) return (SymbolEntry *)0; // Locked as NOT a pointer
1086+
if (vn->isTypeLock()) return (MapEntry *)0; // Locked as NOT a pointer
10881087
needexacthit = true;
10891088
// Check if the constant is involved in a potential pointer expression
10901089
// as the base
@@ -1093,22 +1092,22 @@ SymbolEntry *ActionConstantPtr::isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op
10931092
case CPUI_CALLIND:
10941093
{
10951094
if (slot==0)
1096-
return (SymbolEntry *)0;
1095+
return (MapEntry *)0;
10971096
// A constant parameter could be a pointer
10981097
FuncCallSpecs *fc = data.getCallSpecs(op);
10991098
if (fc != (FuncCallSpecs *)0 && fc->isInputLocked() && fc->numParams() > slot-1) {
11001099
type_metatype meta = fc->getParam(slot-1)->getType()->getMetatype();
11011100
if (meta != TYPE_PTR && meta != TYPE_UNKNOWN) {
1102-
return (SymbolEntry *)0; // Definitely not passing a pointer
1101+
return (MapEntry *)0; // Definitely not passing a pointer
11031102
}
11041103
}
11051104
else if (!glb->infer_pointers)
1106-
return (SymbolEntry *)0;
1105+
return (MapEntry *)0;
11071106
break;
11081107
}
11091108
case CPUI_COPY:
11101109
if (!checkCopy(op, data))
1111-
return (SymbolEntry *)0;
1110+
return (MapEntry *)0;
11121111
break;
11131112
case CPUI_PIECE:
11141113
// Pointers get concatenated in structures
@@ -1118,43 +1117,43 @@ SymbolEntry *ActionConstantPtr::isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op
11181117
case CPUI_INT_LESSEQUAL:
11191118
// A comparison with a constant could be a pointer
11201119
if (!glb->infer_pointers)
1121-
return (SymbolEntry *)0;
1120+
return (MapEntry *)0;
11221121
break;
11231122
case CPUI_INT_ADD:
11241123
outvn = op->getOut();
11251124
if (outvn->getTypeDefFacing()->getMetatype()==TYPE_PTR) {
11261125
// Is there another pointer base in this expression
11271126
if (op->getIn(1-slot)->getTypeReadFacing(op)->getMetatype()==TYPE_PTR)
1128-
return (SymbolEntry *)0; // If so, we are not a pointer
1127+
return (MapEntry *)0; // If so, we are not a pointer
11291128
// FIXME: need to fully explore additive tree
11301129
needexacthit = false;
11311130
}
11321131
else if (!glb->infer_pointers)
1133-
return (SymbolEntry *)0;
1132+
return (MapEntry *)0;
11341133
break;
11351134
case CPUI_STORE:
11361135
if (slot != 2)
1137-
return (SymbolEntry *)0;
1136+
return (MapEntry *)0;
11381137
break;
11391138
default:
1140-
return (SymbolEntry *)0;
1139+
return (MapEntry *)0;
11411140
}
11421141
// Make sure the constant is in the expected range for a pointer
11431142
if (spc->getPointerLowerBound() > vn->getOffset())
1144-
return (SymbolEntry *)0;
1143+
return (MapEntry *)0;
11451144
if (spc->getPointerUpperBound() < vn->getOffset())
1146-
return (SymbolEntry *)0;
1145+
return (MapEntry *)0;
11471146
// Check if the constant looks like a single bit or mask
11481147
if (bit_transitions(vn->getOffset(),vn->getSize()) < 3)
1149-
return (SymbolEntry *)0;
1148+
return (MapEntry *)0;
11501149
rampoint = glb->resolveConstant(spc,vn->getOffset(),vn->getSize(),op->getAddr(),fullEncoding);
11511150
}
11521151

1153-
if (rampoint.isInvalid()) return (SymbolEntry *)0;
1152+
if (rampoint.isInvalid()) return (MapEntry *)0;
11541153
// Since we are looking for a global address
11551154
// Assume it is address tied and use empty usepoint
1156-
SymbolEntry *entry = data.getScopeLocal()->getParent()->queryContainer(rampoint,1,Address());
1157-
if (entry != (SymbolEntry *)0) {
1155+
MapEntry *entry = data.getScopeLocal()->getParent()->queryContainer(rampoint,1,Address());
1156+
if (entry != (MapEntry *)0) {
11581157
Datatype *ptrType = entry->getSymbol()->getType();
11591158
if (ptrType->getMetatype() == TYPE_ARRAY) {
11601159
Datatype *ct = ((TypeArray *)ptrType)->getBase();
@@ -1165,7 +1164,7 @@ SymbolEntry *ActionConstantPtr::isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op
11651164
}
11661165
if (needexacthit && entry->getAddr() != rampoint) {
11671166
vn->setSymbolCheck(Varnode::symcheck_incomplete); // May need to retest if we later discover vn is a pointer
1168-
return (SymbolEntry *)0;
1167+
return (MapEntry *)0;
11691168
}
11701169
}
11711170
return entry;
@@ -1183,7 +1182,7 @@ int4 ActionConstantPtr::apply(Funcdata &data)
11831182
VarnodeLocSet::const_iterator begiter,enditer;
11841183
Architecture *glb = data.getArch();
11851184
AddrSpace *cspc = glb->getConstantSpace();
1186-
SymbolEntry *entry;
1185+
MapEntry *entry;
11871186
Varnode *vn;
11881187

11891188
begiter = data.beginLoc(cspc);
@@ -1214,7 +1213,7 @@ int4 ActionConstantPtr::apply(Funcdata &data)
12141213
Address rampoint;
12151214
uintb fullEncoding;
12161215
entry = isPointer(rspc,vn,op,slot,rampoint,fullEncoding,data);
1217-
if (entry != (SymbolEntry *)0) {
1216+
if (entry != (MapEntry *)0) {
12181217
data.spacebaseConstant(op,slot,entry,rampoint,fullEncoding,vn->getSize());
12191218
if ((opc == CPUI_INT_ADD)&&(slot==1))
12201219
data.opSwapInput(op,0,1);
@@ -5066,12 +5065,12 @@ int4 ActionDynamicMapping::apply(Funcdata &data)
50665065

50675066
{
50685067
ScopeLocal *localmap = data.getScopeLocal();
5069-
list<SymbolEntry>::iterator iter,enditer;
5068+
list<DynamicEntry *>::iterator iter,enditer;
50705069
iter = localmap->beginDynamic();
50715070
enditer = localmap->endDynamic();
50725071
DynamicHash dhash;
50735072
while(iter != enditer) {
5074-
SymbolEntry *entry = &(*iter);
5073+
DynamicEntry *entry = *iter;
50755074
++iter;
50765075
if (data.attemptDynamicMapping(entry,dhash))
50775076
count += 1;
@@ -5083,12 +5082,12 @@ int4 ActionDynamicSymbols::apply(Funcdata &data)
50835082

50845083
{
50855084
ScopeLocal *localmap = data.getScopeLocal();
5086-
list<SymbolEntry>::iterator iter,enditer;
5085+
list<DynamicEntry *>::iterator iter,enditer;
50875086
iter = localmap->beginDynamic();
50885087
enditer = localmap->endDynamic();
50895088
DynamicHash dhash;
50905089
while(iter != enditer) {
5091-
SymbolEntry *entry = &(*iter);
5090+
DynamicEntry *entry = *iter;
50925091
++iter;
50935092
if (data.attemptDynamicMappingLate(entry, dhash))
50945093
count += 1;
@@ -5233,7 +5232,9 @@ void ActionInferTypes::buildLocaltypes(Funcdata &data)
52335232
bool needsBlock = false;
52345233
SymbolEntry *entry = vn->getSymbolEntry();
52355234
if (entry != (SymbolEntry *)0 && !vn->isTypeLock() && entry->getSymbol()->isTypeLocked()) {
5236-
int4 curOff = (vn->getAddr().getOffset() - entry->getAddr().getOffset()) + entry->getOffset();
5235+
int4 curOff = entry->getOffset();
5236+
if (!entry->isDynamic())
5237+
curOff += (vn->getAddr().getOffset() - ((MapEntry *)entry)->getAddr().getOffset());
52375238
ct = typegrp->getExactPiece(entry->getSymbol()->getType(), curOff, vn->getSize());
52385239
if (ct == (Datatype *)0 || ct->getMetatype() == TYPE_UNKNOWN) // If we can't resolve, or resolve to UNKNOWN
52395240
ct = vn->getLocalType(needsBlock); // Let data-type float, even though parent symbol is type-locked

Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ class ActionConstantPtr : public Action {
190190
static AddrSpace *searchForSpaceAttribute(Varnode *vn,PcodeOp *op);
191191
static AddrSpace *selectInferSpace(Varnode *vn,PcodeOp *op,const vector<AddrSpace *> &spaceList);
192192
static bool checkCopy(PcodeOp *op,Funcdata &data);
193-
static SymbolEntry *isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op,int4 slot,
194-
Address &rampoint,uintb &fullEncoding,Funcdata &data);
193+
static MapEntry *isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op,int4 slot,
194+
Address &rampoint,uintb &fullEncoding,Funcdata &data);
195195
public:
196196
ActionConstantPtr(const string &g) : Action(0,"constantptr",g) {} ///< Constructor
197197
virtual void reset(Funcdata &data) { localcount = 0; }

0 commit comments

Comments
 (0)