Ghidra is a software reverse engineering (SRE) framework
GP-7356 Add register name check in pushUnnamedLocation
caheckman9de219978d7e
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printc.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/printc.ccindex 9c6db91521..c3da7329d2 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/printc.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printc.cc@@ -1097,7 +1097,7 @@ void PrintC::opPtrsub(const PcodeOp *op)if (symbol == (Symbol *)0) {TypeSpacebase *sb = (TypeSpacebase *)ct;Address addr = sb->getAddress(in1const,in0->getSize(),op->getAddr());- pushUnnamedLocation(addr,(Varnode *)0,op);+ pushUnnamedLocation(addr,1,(Varnode *)0,op);}else {int4 off = high->getSymbolOffset();@@ -2008,12 +2008,17 @@ void PrintC::pushSymbol(const Symbol *sym,const Varnode *vn,const PcodeOp *op)pushAtom(Atom(sym->getDisplayName(),vartoken,tokenColor,op,vn));}-void PrintC::pushUnnamedLocation(const Address &addr,- const Varnode *vn,const PcodeOp *op)+void PrintC::pushUnnamedLocation(const Address &addr,int4 size,const Varnode *vn,const PcodeOp *op)+{ostringstream s;- s << addr.getSpace()->getName();- addr.printRaw(s);+ AddrSpace *spc = addr.getSpace();+ s << spc->getName();+ string nm = spc->getTrans()->getExactRegisterName(spc, addr.getOffset(), size);+ if (nm.size() != 0)+ s << '_' << nm;+ else+ addr.printRaw(s);pushAtom(Atom(s.str(),vartoken,EmitMarkup::var_color,op,vn));}@@ -2155,7 +2160,7 @@ void PrintC::pushMismatchSymbol(const Symbol *sym,int4 off,int4 sz,pushAtom(Atom(nm,vartoken,tokenColor,op,vn));}else- pushUnnamedLocation(vn->getAddr(),vn,op);+ pushUnnamedLocation(vn->getAddr(),vn->getSize(),vn,op);}void PrintC::pushImpliedField(const Varnode *vn,const PcodeOp *op)diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printc.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/printc.hhindex 2f5b722c4e..45fff8f445 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/printc.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printc.hh@@ -210,8 +210,7 @@ protected:const Varnode *vn,const PcodeOp *op);virtual void pushAnnotation(const Varnode *vn,const PcodeOp *op);virtual void pushSymbol(const Symbol *sym,const Varnode *vn,const PcodeOp *op);- virtual void pushUnnamedLocation(const Address &addr,- const Varnode *vn,const PcodeOp *op);+ virtual void pushUnnamedLocation(const Address &addr,int4 size,const Varnode *vn,const PcodeOp *op);virtual void pushPartialSymbol(const Symbol *sym,int4 off,int4 sz,const Varnode *vn,const PcodeOp *op,int4 slot,bool allowCast);virtual void pushMismatchSymbol(const Symbol *sym,int4 off,int4 sz,diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.ccindex b96e226e74..ace245acbe 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc@@ -242,7 +242,7 @@ void PrintLanguage::pushSymbolDetail(const Varnode *vn,const PcodeOp *op,bool isHighVariable *high = vn->getHigh();Symbol *sym = high->getSymbol();if (sym == (Symbol *)0) {- pushUnnamedLocation(high->getNameRepresentative()->getAddr(),vn,op);+ pushUnnamedLocation(high->getNameRepresentative()->getAddr(),vn->getSize(),vn,op);}else {int4 symboloff = high->getSymbolOffset();diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hhindex dab66c71a2..a1443cd088 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh@@ -360,9 +360,10 @@ protected:/// If there is no Symbol or other name source for an explicit variable,/// this method is used to print something to represent the variable based on its storage address./// \param addr is the storage address+ /// \param size is the number of storage bytes/// \param vn is the Varnode representing the variable (if present)/// \param op is a PcodeOp associated with the variable- virtual void pushUnnamedLocation(const Address &addr,const Varnode *vn,const PcodeOp *op)=0;+ virtual void pushUnnamedLocation(const Address &addr,int4 size,const Varnode *vn,const PcodeOp *op)=0;/// \brief Push a variable that represents only part of a symbol onto the RPN stack///