From c88f59a5eddad302ac0a7aee4cbc7796954280c0 Mon Sep 17 00:00:00 2001
From: caheckman <48068198+caheckman@users.noreply.github.com>
Date: Thu, 12 May 2022 17:53:10 -0400
Subject: [PATCH] GP-2024 Fix for formatting test
---
Ghidra/Features/Decompiler/src/decompile/cpp/database.cc | 9 +++++----
Ghidra/Features/Decompiler/src/decompile/cpp/database.hh | 2 +-
.../Decompiler/src/decompile/cpp/funcdata_varnode.cc | 6 +++++-
.../Features/Decompiler/src/decompile/cpp/ifacedecomp.cc | 2 +-
.../Decompiler/src/decompile/datatests/displayformat.xml | 2 +-
5 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc
index c71e554be6..8ba62b9e74 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc
@@ -1699,19 +1699,20 @@ Symbol *Scope::addDynamicSymbol(const string &nm,Datatype *ct,const Address &cad
return sym;
}
-/// \brief Create a symbol that forces a constant display conversion
+/// \brief Create a symbol that forces display conversion on a constant
///
-/// \param format is the type of conversion (Symbol::force_hex, Symbol::force_dec, etc.)
+/// \param nm is the equate name to display, which may be empty for an integer conversion
+/// \param format is the type of integer conversion (Symbol::force_hex, Symbol::force_dec, etc.)
/// \param value is the constant value being converted
/// \param addr is the address of the p-code op reading the constant
/// \param hash is the dynamic hash identifying the constant
/// \return the new EquateSymbol
-Symbol *Scope::addConvertSymbol(uint4 format,uintb value,Address &addr,uint8 hash)
+Symbol *Scope::addEquateSymbol(const string &nm,uint4 format,uintb value,const Address &addr,uint8 hash)
{
Symbol *sym;
- sym = new EquateSymbol(owner,"",format,value);
+ sym = new EquateSymbol(owner,nm,format,value);
addSymbolInternal(sym);
RangeList rnglist;
if (!addr.isInvalid())
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/database.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/database.hh
index 6dff61a8c6..77df585871 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/database.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/database.hh
@@ -727,7 +727,7 @@ public:
ExternRefSymbol *addExternalRef(const Address &addr,const Address &refaddr,const string &nm);
LabSymbol *addCodeLabel(const Address &addr,const string &nm);
Symbol *addDynamicSymbol(const string &nm,Datatype *ct,const Address &caddr,uint8 hash);
- Symbol *addConvertSymbol(uint4 format,uintb value,Address &addr,uint8 hash);
+ Symbol *addEquateSymbol(const string &nm,uint4 format,uintb value,const Address &addr,uint8 hash);
string buildDefaultName(Symbol *sym,int4 &base,Varnode *vn) const; ///< Create a default name for the given Symbol
bool isReadOnly(const Address &addr,int4 size,const Address &usepoint) const;
void printBounds(ostream &s) const { rangetree.printBounds(s); } ///< Print a description of \b this Scope's \e owned memory ranges
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
index a8e761ea19..4c22cbd42c 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
@@ -1198,7 +1198,11 @@ void Funcdata::buildDynamicSymbol(Varnode *vn)
if (dhash.getHash() == 0)
throw RecovError("Unable to find unique hash for varnode");
- Symbol *sym = localmap->addDynamicSymbol("",high->getType(),dhash.getAddress(),dhash.getHash());
+ Symbol *sym;
+ if (vn->isConstant())
+ sym = localmap->addEquateSymbol("",Symbol::force_hex, vn->getOffset(), dhash.getAddress(), dhash.getHash());
+ else
+ sym = localmap->addDynamicSymbol("",high->getType(),dhash.getAddress(),dhash.getHash());
vn->setSymbolEntry(sym->getFirstWholeMap());
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc
index 5b1d265771..f2994e1fcb 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc
@@ -708,7 +708,7 @@ void IfcMapconvert::execute(istream &s)
s >> hex >> hash; // Parse the hash value
- dcp->fd->getScopeLocal()->addConvertSymbol(format, value, addr, hash);
+ dcp->fd->getScopeLocal()->addEquateSymbol("", format, value, addr, hash);
}
/// \class IfcPrintdisasm
diff --git a/Ghidra/Features/Decompiler/src/decompile/datatests/displayformat.xml b/Ghidra/Features/Decompiler/src/decompile/datatests/displayformat.xml
index b1dd5661d5..9ddb3a6db4 100644
--- a/Ghidra/Features/Decompiler/src/decompile/datatests/displayformat.xml
+++ b/Ghidra/Features/Decompiler/src/decompile/datatests/displayformat.xml
@@ -25,7 +25,7 @@
map addr r0x301020 octint4 globalbin
lo fu setglobals
decompile
- force varnode #0xaa(0x100625:0x12) bin
+ force varnode #0xaa(0x100619:7) bin
print C
quit