Skip to content

Ghidra is a software reverse engineering (SRE) framework

convert splitVarnode to transferVarnodeProperties

caheckmanbb0feb3d6230
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh
index 1cae9fae15..b29c96f8bb 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh
@@ -352,7 +352,7 @@ public:
bool onlyOpUse(const Varnode *invn,const PcodeOp *opmatch,const ParamTrial &trial) const;
bool ancestorOpUse(int4 maxlevel,const Varnode *invn,const PcodeOp *op,ParamTrial &trial) const;
bool syncVarnodesWithSymbols(const ScopeLocal *lm,bool typesyes);
- void splitVarnode(Varnode *vn,int4 lowsize,Varnode *&vnlo,Varnode *& vnhi);
+ void transferVarnodeProperties(Varnode *vn,Varnode *newVn,int4 lsbOffset);
bool fillinReadOnly(Varnode *vn); ///< Replace the given Varnode with its (constant) value in the load image
bool replaceVolatile(Varnode *vn); ///< Replace accesses of the given Varnode with \e volatile operations
void markIndirectOnly(void); ///< Mark \e illegal \e input Varnodes used only in INDIRECTs
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
index 17341e4d49..4582e0e2e7 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
@@ -479,34 +479,22 @@ void Funcdata::setHighLevel(void)
assignHigh(*iter);
}
-/// \brief Create two new Varnodes which split the given Varnode
+/// \brief Copy properties from an existing Varnode to a new Varnode
///
-/// Attributes are copied from the original into the split pieces if appropriate
-/// \param vn is the given Varnode
-/// \param lowsize is the desired size in bytes of the least significant portion
-/// \param vnlo will hold the least significant portion
-/// \param vnhi will hold the most significant portion
-void Funcdata::splitVarnode(Varnode *vn,int4 lowsize,Varnode *& vnlo,Varnode *& vnhi)
+/// The new Varnode is assumed to overlap the storage of the existing Varnode.
+/// Properties like boolean flags and \e consume bits are copied as appropriate.
+/// \param vn is the existing Varnode
+/// \param newVn is the new Varnode that has its properties set
+/// \param lsbOffset is the significance offset of the new Varnode within the exising
+void Funcdata::transferVarnodeProperties(Varnode *vn,Varnode *newVn,int4 lsbOffset)
{
- int4 highsize = vn->getSize() - lowsize;
- Address addrhi = vn->getAddr();
- Address addrlo = addrhi;
- uintb consumehi = vn->getConsume() >> 8*lowsize;
- uintb consumelo = vn->getConsume() & calc_mask(lowsize);
- if (vn->getSpace()->isBigEndian())
- addrlo = addrhi + highsize;
- else
- addrhi = addrhi + lowsize;
+ uintb newConsume = (vn->getConsume() >> 8*lsbOffset) & calc_mask(newVn->getSize());
- uint4 vnflags = vn->getFlags() & (Varnode::directwrite|Varnode::addrforce|Varnode::auto_live);
- vnhi = newVarnode(highsize,addrhi);
- vnlo = newVarnode(lowsize,addrlo);
+ uint4 vnFlags = vn->getFlags() & (Varnode::directwrite|Varnode::addrforce|Varnode::auto_live);
- vnhi->setFlags(vnflags); // Preserve addrforce setting
- vnlo->setFlags(vnflags);
- vnhi->setConsume(consumehi);
- vnlo->setConsume(consumelo);
+ newVn->setFlags(vnFlags); // Preserve addrforce setting
+ newVn->setConsume(newConsume);
}
/// Treat the given Varnode as read-only, look up its value in LoadImage