Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-2859 Clearing symbols from HighVariable must set symboldirty

caheckman9424fdf208b8
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh
index 892883c0d6..3b9ebb4981 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh
@@ -408,7 +408,6 @@ public:
void clearDeadVarnodes(void); ///< Delete any dead Varnodes
void calcNZMask(void); ///< Calculate \e non-zero masks for all Varnodes
void clearDeadOps(void) { obank.destroyDead(); } ///< Delete any dead PcodeOps
- void clearSymbolLinks(HighVariable *high); ///< Clear Symbols attached to Varnodes in the given HighVariable
void remapVarnode(Varnode *vn,Symbol *sym,const Address &usepoint);
void remapDynamicVarnode(Varnode *vn,Symbol *sym,const Address &usepoint,uint8 hash);
Symbol *linkSymbol(Varnode *vn); ///< Find or create Symbol associated with given Varnode
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
index 0c4275f15f..63784131dd 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
@@ -1002,18 +1002,6 @@ bool Funcdata::syncVarnodesWithSymbol(VarnodeLocSet::const_iterator &iter,uint4
return updateoccurred;
}
-/// For each instance Varnode, remove any SymbolEntry reference and associated properties.
-/// \param high is the given HighVariable to clear
-void Funcdata::clearSymbolLinks(HighVariable *high)
-
-{
- for(int4 i=0;i<high->numInstances();++i) {
- Varnode *vn = high->getInstance(i);
- vn->mapentry = (SymbolEntry *)0;
- vn->clearFlags(Varnode::namelock | Varnode::typelock | Varnode::mapped);
- }
-}
-
/// \brief Remap a Symbol to a given Varnode using a static mapping
///
/// Any previous links between the Symbol, the Varnode, and the associate HighVariable are
@@ -1024,7 +1012,7 @@ void Funcdata::clearSymbolLinks(HighVariable *high)
void Funcdata::remapVarnode(Varnode *vn,Symbol *sym,const Address &usepoint)
{
- clearSymbolLinks(vn->getHigh());
+ vn->clearSymbolLinks();
SymbolEntry *entry = localmap->remapSymbol(sym, vn->getAddr(), usepoint);
vn->setSymbolEntry(entry);
}
@@ -1040,7 +1028,7 @@ void Funcdata::remapVarnode(Varnode *vn,Symbol *sym,const Address &usepoint)
void Funcdata::remapDynamicVarnode(Varnode *vn,Symbol *sym,const Address &usepoint,uint8 hash)
{
- clearSymbolLinks(vn->getHigh());
+ vn->clearSymbolLinks();
SymbolEntry *entry = localmap->remapSymbolDynamic(sym, hash, usepoint);
vn->setSymbolEntry(entry);
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc
index ff5678c042..b8fdd62c94 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc
@@ -175,15 +175,14 @@ void HighVariable::updateSymbol(void) const
highflags &= ~((uint4)symboldirty);
vector<Varnode *>::const_iterator iter;
symbol = (Symbol *)0;
- Varnode *vn = (Varnode *)0;
for(iter=inst.begin();iter!=inst.end();++iter) {
- Varnode *tmpvn = *iter;
- if (tmpvn->getSymbolEntry() != (SymbolEntry *)0)
- vn = tmpvn;
+ Varnode *vn = *iter;
+ if (vn->getSymbolEntry() != (SymbolEntry *)0) {
+ setSymbol(vn);
+ return;
+ }
}
- if (vn != (Varnode *)0)
- setSymbol(vn);
}
/// Compare two Varnode objects based just on their storage address
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh
index 25f6f83619..21e5479190 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh
@@ -88,6 +88,7 @@ private:
void flagsDirty(void) const { highflags |= flagsdirty | namerepdirty; } ///< Mark the boolean properties as \e dirty
void coverDirty(void) const { highflags |= coverdirty; } ///< Mark the cover as \e dirty
void typeDirty(void) const { highflags |= typedirty; } ///< Mark the data-type as \e dirty
+ void symbolDirty(void) const { highflags |= symboldirty; } ///< Mark the symbol as \e dirty
void setUnmerged(void) const { highflags |= unmerged; } ///< Mark \b this as having merge problems
public:
HighVariable(Varnode *vn); ///< Construct a HighVariable with a single member Varnode
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.cc
index 4675e9ee8d..36203c8d62 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.cc
@@ -352,6 +352,22 @@ void Varnode::clearFlags(uint4 fl) const
}
}
+/// For \b this Varnode and any others attached to the same HighVariable,
+/// remove any SymbolEntry reference and associated properties.
+void Varnode::clearSymbolLinks(void)
+
+{
+ bool foundEntry = false;
+ for(int4 i=0;i<high->numInstances();++i) {
+ Varnode *vn = high->getInstance(i);
+ foundEntry = foundEntry || (vn->mapentry != (SymbolEntry *)0);
+ vn->mapentry = (SymbolEntry *)0;
+ vn->clearFlags(Varnode::namelock | Varnode::typelock | Varnode::mapped);
+ }
+ if (foundEntry)
+ high->symbolDirty();
+}
+
/// Directly change the defining PcodeOp and set appropriate dirty bits
/// \param op is the pointer to the new PcodeOp, which can be \b null
void Varnode::setDef(PcodeOp *op)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh
index c6f656478b..30a49cb754 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh
@@ -159,6 +159,7 @@ private:
void clearCover(void) const; ///< Turn off any coverage information
void setFlags(uint4 fl) const; ///< Internal method for setting boolean attributes
void clearFlags(uint4 fl) const; ///< Internal method for clearing boolean attributes
+ void clearSymbolLinks(void); ///< Clear any Symbol attached to \b this Varnode
void setUnaffected(void) { setFlags(Varnode::unaffected); } ///< Mark Varnode as \e unaffected
// These functions should be only private things used by VarnodeBank
void setInput(void) { setFlags(Varnode::input|Varnode::coverdirty); } ///< Mark Varnode as \e input