Skip to content

Ghidra is a software reverse engineering (SRE) framework

Suggestions from github issue #382

caheckman933e16f751fe
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh
index f41b4557da..a0943c9243 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh
@@ -116,8 +116,6 @@ public:
class Architecture : public AddrSpaceManager {
public:
string archid; ///< ID string uniquely describing this architecture
- string description; ///< Description of architecture
- string version; ///< Configuration version
// Configuration data
int4 trim_recurse_max; ///< How many levels to let parameter trims recurse
@@ -178,6 +176,8 @@ public:
void restoreFlowOverride(const Element *el); ///< Set flow overrides from XML
virtual ~Architecture(void); ///< Destructor
+ virtual string getDescription(void) const { return archid; } ///< Get a string describing \b this architecture
+
/// \brief Print an error message to console
///
/// Write the given message to whatever the registered error stream is
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc
index 84b23c0ce7..fa726c2571 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc
@@ -100,7 +100,7 @@ void IfcLoadFile::execute(istream &s)
#ifdef OPACTION_DEBUG
dcp->conf->setDebugStream(status->optr);
#endif
- *status->optr << filename << " successfully loaded: " << dcp->conf->description << endl;
+ *status->optr << filename << " successfully loaded: " << dcp->conf->getDescription() << endl;
}
void IfcAddpath::execute(istream &s)
@@ -162,7 +162,7 @@ void IfcRestore::execute(istream &s)
#ifdef OPACTION_DEBUG
dcp->conf->setDebugStream(status->optr);
#endif
- *status->optr << savefile << " successfully loaded: " << dcp->conf->description << endl;
+ *status->optr << savefile << " successfully loaded: " << dcp->conf->getDescription() << endl;
}
int main(int argc,char **argv)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
index 06a05287fb..c38d6859ee 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
@@ -2282,7 +2282,7 @@ ProtoStoreSymbol::ProtoStoreSymbol(Scope *sc,const Address &usepoint)
ParameterPieces pieces;
pieces.type = scope->getArch()->types->getTypeVoid();
pieces.flags = 0;
- setOutput(pieces);
+ ProtoStoreSymbol::setOutput(pieces);
}
ProtoStoreSymbol::~ProtoStoreSymbol(void)
@@ -2465,7 +2465,7 @@ ProtoStoreInternal::ProtoStoreInternal(Datatype *vt)
ParameterPieces pieces;
pieces.type = voidtype;
pieces.flags = 0;
- setOutput(pieces);
+ ProtoStoreInternal::setOutput(pieces);
}
ProtoStoreInternal::~ProtoStoreInternal(void)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc
index dbb04c7d6f..4a1e44dbf8 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc
@@ -281,9 +281,8 @@ void InjectPayloadDynamic::inject(InjectContext &context,PcodeEmit &emit) const
PcodeInjectLibrarySleigh::PcodeInjectLibrarySleigh(Architecture *g,uintb tmpbase)
: PcodeInjectLibrary(g,tmpbase)
{
- glb = g;
- slgh = (const SleighBase *)glb->translate;
- contextCache.glb = glb;
+ slgh = (const SleighBase *)g->translate;
+ contextCache.glb = g;
}
int4 PcodeInjectLibrarySleigh::registerDynamicInject(InjectPayload *payload)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.hh
index dac98dd6e5..ad6f44bff2 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.hh
@@ -87,7 +87,6 @@ public:
};
class PcodeInjectLibrarySleigh : public PcodeInjectLibrary {
- Architecture *glb;
const SleighBase *slgh;
vector<OpBehavior *> inst;
InjectContextSleigh contextCache;
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.cc
index b7075b885b..1742e61a23 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.cc
@@ -125,6 +125,12 @@ SleighArchitecture::~SleighArchitecture(void)
translate = (const Translate *)0;
}
+string SleighArchitecture::getDescription(void) const
+
+{
+ return description[languageindex].getDescription();
+}
+
/// If the current \b languageindex matches the \b last_languageindex,
/// try to reuse the previous Sleigh object, so we don't reload
/// the .sla file.
@@ -198,8 +204,6 @@ void SleighArchitecture::buildSpecFile(DocumentStorage &store)
{ // Given a specific language, make sure relevant spec files are loaded
bool language_reuse = isTranslateReused();
const LanguageDescription &language(description[languageindex]);
- Architecture::description = language.getDescription();
- version = language.getVersion();
string compiler = archid.substr(archid.rfind(':')+1);
const CompilerTag &compilertag( language.getCompiler(compiler));
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.hh
index d7788a2da4..01d41fe077 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.hh
@@ -112,6 +112,7 @@ public:
void restoreXmlHeader(const Element *el); ///< Restore from XML basic attributes of an executable
virtual void printMessage(const string &message) const { *errorstream << message << endl; }
virtual ~SleighArchitecture(void);
+ virtual string getDescription(void) const;
static string normalizeProcessor(const string &nm); ///< Try to recover a \e language \e id processor field
static string normalizeEndian(const string &nm); ///< Try to recover a \e language \e id endianess field
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
index 6f75e63ad7..dbeba71e14 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
@@ -2062,10 +2062,10 @@ int4 DecisionNode::getNumFixed(int4 low,int4 size,bool context)
double DecisionNode::getScore(int4 low,int4 size,bool context)
{
- int4 numBins = 1 << size;
+ int4 numBins = 1 << size; // size is between 1 and 8
int4 i;
uintm val,mask;
- uintm m = (size==8*sizeof(uintm)) ? 0 : (((uintm)1)<<size);
+ uintm m = ((uintm)1)<<size;
m = m-1;
int4 total = 0;
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc
index 7ef29d23e1..0537c9da8f 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/subflow.cc
@@ -1986,8 +1986,7 @@ Varnode *SubfloatFlow::getReplaceVarnode(ReplaceVarnode *rvn)
// Here we artificially truncate the location, which isn't realistic
if (addr.isBigEndian())
addr = addr + (rvn->vn->getSize() - precision);
- if (isinput)
- replaceInput(rvn); // Replace input to avoid overlap errors
+ replaceInput(rvn); // Replace input to avoid overlap errors
rvn->replacement = fd->newVarnode(precision,addr);
}
else
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/unify.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/unify.cc
index 6edc35a505..d848cfc7dd 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/unify.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/unify.cc
@@ -91,7 +91,7 @@ UnifyDatatype::~UnifyDatatype(void)
delete storespot.cn;
break;
default:
- throw LowlevelError("Bad unify datatype");
+ break;
}
}