Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Ghidra
Browse files Browse the repository at this point in the history
Notable changes: New ghidra namespace, removed using namespace std from
headers, different handling of case values.
Fix #284
thestr4ng3r committed Oct 22, 2023
1 parent 454eba1 commit 1754b6b
Showing 29 changed files with 543 additions and 594 deletions.
2 changes: 1 addition & 1 deletion ghidra/ghidra
Submodule ghidra updated 5123 files
2 changes: 2 additions & 0 deletions src/ArchMap.cpp
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@
#include <map>
#include <functional>

using namespace ghidra;

std::string CompilerFromCore(RzCore *core);

template<typename T>
2 changes: 1 addition & 1 deletion src/ArchMap.h
Original file line number Diff line number Diff line change
@@ -21,6 +21,6 @@ RZ_API std::string SleighIdFromCore(RzCore *core);
/**
* Match sleigh id from sleigh-plugin specific settings (asm.cpu)
*/
RZ_API std::string SleighIdFromSleighAsmConfig(const char *cpu, int bits, bool bigendian, const vector<LanguageDescription> &langs);
RZ_API std::string SleighIdFromSleighAsmConfig(const char *cpu, int bits, bool bigendian, const std::vector<ghidra::LanguageDescription> &langs);

#endif
5 changes: 4 additions & 1 deletion src/CodeXMLParse.cpp
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
#include <sstream>
#include <string>

using namespace ghidra;

struct ParseCodeXMLContext
{
Funcdata *func;
@@ -262,7 +264,8 @@ static const std::map<std::string, std::vector <void (*)(ANNOTATOR_PARAMS)> > an
{ "variable", { AnnotateVariable, AnnotateColor } },
{ "funcname", { AnnotateFunctionName, AnnotateColor } },
{ "type", { AnnotateColor } },
{ "syntax", { AnnotateColor } }
{ "syntax", { AnnotateColor } },
{ "value", { AnnotateColor } }
};

//#define TEST_UNKNOWN_NODES
4 changes: 3 additions & 1 deletion src/CodeXMLParse.h
Original file line number Diff line number Diff line change
@@ -6,8 +6,10 @@

#include <rz_util/rz_annotated_code.h>

namespace ghidra {
class Funcdata;
};

RZ_API RzAnnotatedCode *ParseCodeXML(Funcdata *func, const char *xml);
RZ_API RzAnnotatedCode *ParseCodeXML(ghidra::Funcdata *func, const char *xml);

#endif //RZ_GHIDRA_CODEXMLPARSE_H
2 changes: 2 additions & 0 deletions src/PrettyXmlEncode.cpp
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@

#include "PrettyXmlEncode.h"

using namespace ghidra;

void PrettyXmlEncode::indent()
{
for(int i = 0; i < depth; i++)
6 changes: 3 additions & 3 deletions src/PrettyXmlEncode.h
Original file line number Diff line number Diff line change
@@ -6,16 +6,16 @@

#include <marshal.hh>

class PrettyXmlEncode: public XmlEncode
class PrettyXmlEncode: public ghidra::XmlEncode
{
private:
int depth = 0;
void indent();

public:
PrettyXmlEncode(std::ostream &s) : XmlEncode(s) {}
void openElement(const ElementId &elemId) override;
void closeElement(const ElementId &elemId) override;
void openElement(const ghidra::ElementId &elemId) override;
void closeElement(const ghidra::ElementId &elemId) override;
};

#endif
5 changes: 5 additions & 0 deletions src/RizinArchitecture.cpp
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
#include <iostream>
#include <cassert>

using namespace ghidra;

// maps rizin calling conventions to decompiler proto models
static const std::map<std::string, std::string> cc_map = {
{ "cdecl", "__cdecl" },
@@ -153,7 +155,10 @@ Scope *RizinArchitecture::buildDatabase(DocumentStorage &store)
void RizinArchitecture::buildTypegrp(DocumentStorage &store)
{
types = rizinTypeFactory = new RizinTypeFactory(this);
}

void RizinArchitecture::buildCoreTypes(DocumentStorage &store)
{
// TODO: load from rizin?
types->setCoreType("void", 1, TYPE_VOID, false);
types->setCoreType("bool", 1, TYPE_BOOL, false);
25 changes: 13 additions & 12 deletions src/RizinArchitecture.h
Original file line number Diff line number Diff line change
@@ -12,18 +12,18 @@
class RizinTypeFactory;
typedef struct rz_core_t RzCore;

class RizinArchitecture : public SleighArchitecture
class RizinArchitecture : public ghidra::SleighArchitecture
{
private:
RzCoreMutex coreMutex;

RizinTypeFactory *rizinTypeFactory = nullptr;
std::map<std::string, VarnodeData> registers;
std::map<std::string, ghidra::VarnodeData> registers;
std::vector<std::string> warnings;

bool rawptr = false;

void loadRegisters(const Translate *translate);
void loadRegisters(const ghidra::Translate *translate);

public:
explicit RizinArchitecture(RzCore *core, const std::string &sleigh_id);
@@ -32,23 +32,24 @@ class RizinArchitecture : public SleighArchitecture

RizinTypeFactory *getTypeFactory() const { return rizinTypeFactory; }

ProtoModel *protoModelFromRizinCC(const char *cc);
Address registerAddressFromRizinReg(const char *regname);
ghidra::ProtoModel *protoModelFromRizinCC(const char *cc);
ghidra::Address registerAddressFromRizinReg(const char *regname);

void addWarning(const std::string &warning) { warnings.push_back(warning); }
const std::vector<std::string> getWarnings() const { return warnings; }
ContextDatabase *getContextDatabase();
ghidra::ContextDatabase *getContextDatabase();

void setRawPtr(bool rawptr) { this->rawptr = rawptr; }

protected:
Translate *buildTranslator(DocumentStorage &store) override;
void buildLoader(DocumentStorage &store) override;
Scope *buildDatabase(DocumentStorage &store) override;
void buildTypegrp(DocumentStorage &store) override;
void buildCommentDB(DocumentStorage &store) override;
ghidra::Translate *buildTranslator(ghidra::DocumentStorage &store) override;
void buildLoader(ghidra::DocumentStorage &store) override;
ghidra::Scope *buildDatabase(ghidra::DocumentStorage &store) override;
void buildTypegrp(ghidra::DocumentStorage &store) override;
void buildCoreTypes(ghidra::DocumentStorage &store) override;
void buildCommentDB(ghidra::DocumentStorage &store) override;
void postSpecFile() override;
void buildAction(DocumentStorage &store) override;
void buildAction(ghidra::DocumentStorage &store) override;
};


2 changes: 2 additions & 0 deletions src/RizinCommentDatabase.cpp
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@

#include "RizinUtils.h"

using namespace ghidra;

RizinCommentDatabase::RizinCommentDatabase(RizinArchitecture *arch)
: arch(arch),
cache_filled(false)
22 changes: 11 additions & 11 deletions src/RizinCommentDatabase.h
Original file line number Diff line number Diff line change
@@ -8,29 +8,29 @@

class RizinArchitecture;

class RizinCommentDatabase : public CommentDatabase
class RizinCommentDatabase : public ghidra::CommentDatabase
{
RizinArchitecture *arch;
mutable CommentDatabaseInternal cache;
mutable ghidra::CommentDatabaseInternal cache;
mutable bool cache_filled;
void fillCache(const Address &fad) const;
void fillCache(const ghidra::Address &fad) const;

public:
RizinCommentDatabase(RizinArchitecture *arch);

void clear() override;
void clearType(const Address &fad, uint4 tp) override;
void clearType(const ghidra::Address &fad, ghidra::uint4 tp) override;

void addComment(uint4 tp, const Address &fad, const Address &ad, const string &txt) override;
bool addCommentNoDuplicate(uint4 tp, const Address &fad, const Address &ad, const string &txt) override;
void addComment(ghidra::uint4 tp, const ghidra::Address &fad, const ghidra::Address &ad, const std::string &txt) override;
bool addCommentNoDuplicate(ghidra::uint4 tp, const ghidra::Address &fad, const ghidra::Address &ad, const std::string &txt) override;

void deleteComment(Comment *com) override { throw LowlevelError("deleteComment unimplemented"); }
void deleteComment(ghidra::Comment *com) override { throw ghidra::LowlevelError("deleteComment unimplemented"); }

CommentSet::const_iterator beginComment(const Address &fad) const override;
CommentSet::const_iterator endComment(const Address &fad) const override;
ghidra::CommentSet::const_iterator beginComment(const ghidra::Address &fad) const override;
ghidra::CommentSet::const_iterator endComment(const ghidra::Address &fad) const override;

void encode(Encoder &encoder) const override { cache.encode(encoder); }
void decode(Decoder &decoder) override { throw LowlevelError("CommentDatabaseGhidra::decode unimplemented"); }
void encode(ghidra::Encoder &encoder) const override { cache.encode(encoder); }
void decode(ghidra::Decoder &decoder) override { throw ghidra::LowlevelError("CommentDatabaseGhidra::decode unimplemented"); }
};

#endif //RZ_GHIDRA_RizinCOMMENTDATABASE_H
2 changes: 2 additions & 0 deletions src/RizinLoadImage.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
#include "RizinArchitecture.h"
#include "RizinUtils.h"

using namespace ghidra;

RizinLoadImage::RizinLoadImage(RzCoreMutex *core_mutex, AddrSpaceManager *addr_space_manager)
: LoadImage("rizin_program"),
core_mutex(core_mutex),
12 changes: 6 additions & 6 deletions src/RizinLoadImage.h
Original file line number Diff line number Diff line change
@@ -15,18 +15,18 @@

class RzCoreMutex;

class RizinLoadImage : public LoadImage
class RizinLoadImage : public ghidra::LoadImage
{
private:
RzCoreMutex *const core_mutex;
AddrSpaceManager *addr_space_manager;
ghidra::AddrSpaceManager *addr_space_manager;

public:
explicit RizinLoadImage(RzCoreMutex *core_mutex, AddrSpaceManager *addr_space_manager);
explicit RizinLoadImage(RzCoreMutex *core_mutex, ghidra::AddrSpaceManager *addr_space_manager);

void loadFill(uint1 *ptr, int4 size, const Address &addr) override;
void getReadonly(RangeList &list) const override;
string getArchType() const override;
void loadFill(ghidra::uint1 *ptr, ghidra::int4 size, const ghidra::Address &addr) override;
void getReadonly(ghidra::RangeList &list) const override;
std::string getArchType() const override;
void adjustVma(long adjust) override;
};

4 changes: 3 additions & 1 deletion src/RizinPrintC.cpp
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@
#include <varnode.hh>
#include <architecture.hh>

using namespace ghidra;

// Constructing this registers the capability
RizinPrintCCapability RizinPrintCCapability::inst;

@@ -33,7 +35,7 @@ void RizinPrintC::pushUnnamedLocation(const Address &addr, const Varnode *vn, co
{
pushOp(&dereference, op);
auto type = glb->types->getTypePointer(space->getAddrSize(), vn->getType(), space->getWordSize());
pushConstant(addr.getOffset(), type, vn, op);
pushConstant(addr.getOffset(), type, vartoken, vn, op);
}
else
{
10 changes: 5 additions & 5 deletions src/RizinPrintC.h
Original file line number Diff line number Diff line change
@@ -6,24 +6,24 @@

#include <printc.hh>

class RizinPrintC : public PrintC
class RizinPrintC : public ghidra::PrintC
{
protected:
void pushUnnamedLocation(const Address &addr, const Varnode *vn,const PcodeOp *op) override;
void pushUnnamedLocation(const ghidra::Address &addr, const ghidra::Varnode *vn,const ghidra::PcodeOp *op) override;

public:
explicit RizinPrintC(Architecture *g, const string &nm = "c-language");
explicit RizinPrintC(ghidra::Architecture *g, const std::string &nm = "c-language");

};

class RizinPrintCCapability : public PrintLanguageCapability
class RizinPrintCCapability : public ghidra::PrintLanguageCapability
{
private:
static RizinPrintCCapability inst;
RizinPrintCCapability();

public:
PrintLanguage *buildLanguage(Architecture *glb) override;
ghidra::PrintLanguage *buildLanguage(ghidra::Architecture *glb) override;
};

#endif //RZ_GHIDRA_RizinPRINTC_H
2 changes: 2 additions & 0 deletions src/RizinScope.cpp
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@

#include "RizinUtils.h"

using namespace ghidra;

RizinScope::RizinScope(RizinArchitecture *arch)
: Scope(0, "", arch, this),
arch(arch),
Loading

0 comments on commit 1754b6b

Please sign in to comment.