diff --git a/ghidra/ghidra b/ghidra/ghidra index d89dd09b..b82c65ac 160000 --- a/ghidra/ghidra +++ b/ghidra/ghidra @@ -1 +1 @@ -Subproject commit d89dd09b18645ba62fc202f962fdb73fb60145a7 +Subproject commit b82c65ac80271e45dd78c24fe9d06730052c77ff diff --git a/src/ArchMap.cpp b/src/ArchMap.cpp index 45ccf899..1d8d8588 100644 --- a/src/ArchMap.cpp +++ b/src/ArchMap.cpp @@ -7,6 +7,8 @@ #include #include +using namespace ghidra; + std::string CompilerFromCore(RzCore *core); template diff --git a/src/ArchMap.h b/src/ArchMap.h index 37481f02..56f61bfe 100644 --- a/src/ArchMap.h +++ b/src/ArchMap.h @@ -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 &langs); +RZ_API std::string SleighIdFromSleighAsmConfig(const char *cpu, int bits, bool bigendian, const std::vector &langs); #endif diff --git a/src/CodeXMLParse.cpp b/src/CodeXMLParse.cpp index 1452e8c1..d8f95b44 100644 --- a/src/CodeXMLParse.cpp +++ b/src/CodeXMLParse.cpp @@ -16,6 +16,8 @@ #include #include +using namespace ghidra; + struct ParseCodeXMLContext { Funcdata *func; @@ -262,7 +264,8 @@ static const std::map > an { "variable", { AnnotateVariable, AnnotateColor } }, { "funcname", { AnnotateFunctionName, AnnotateColor } }, { "type", { AnnotateColor } }, - { "syntax", { AnnotateColor } } + { "syntax", { AnnotateColor } }, + { "value", { AnnotateColor } } }; //#define TEST_UNKNOWN_NODES diff --git a/src/CodeXMLParse.h b/src/CodeXMLParse.h index 2264d4e7..dc4594e5 100644 --- a/src/CodeXMLParse.h +++ b/src/CodeXMLParse.h @@ -6,8 +6,10 @@ #include +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 diff --git a/src/PrettyXmlEncode.cpp b/src/PrettyXmlEncode.cpp index a1fdb777..4fff908c 100644 --- a/src/PrettyXmlEncode.cpp +++ b/src/PrettyXmlEncode.cpp @@ -3,6 +3,8 @@ #include "PrettyXmlEncode.h" +using namespace ghidra; + void PrettyXmlEncode::indent() { for(int i = 0; i < depth; i++) diff --git a/src/PrettyXmlEncode.h b/src/PrettyXmlEncode.h index a0d90535..9b5d9c63 100644 --- a/src/PrettyXmlEncode.h +++ b/src/PrettyXmlEncode.h @@ -6,7 +6,7 @@ #include -class PrettyXmlEncode: public XmlEncode +class PrettyXmlEncode: public ghidra::XmlEncode { private: int depth = 0; @@ -14,8 +14,8 @@ class PrettyXmlEncode: public XmlEncode 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 diff --git a/src/RizinArchitecture.cpp b/src/RizinArchitecture.cpp index 883604f1..e912aafc 100644 --- a/src/RizinArchitecture.cpp +++ b/src/RizinArchitecture.cpp @@ -15,6 +15,8 @@ #include #include +using namespace ghidra; + // maps rizin calling conventions to decompiler proto models static const std::map 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); diff --git a/src/RizinArchitecture.h b/src/RizinArchitecture.h index c7f10e83..6bd0b73b 100644 --- a/src/RizinArchitecture.h +++ b/src/RizinArchitecture.h @@ -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 registers; + std::map registers; std::vector 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 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; }; diff --git a/src/RizinCommentDatabase.cpp b/src/RizinCommentDatabase.cpp index 04df9a5b..503328d4 100644 --- a/src/RizinCommentDatabase.cpp +++ b/src/RizinCommentDatabase.cpp @@ -8,6 +8,8 @@ #include "RizinUtils.h" +using namespace ghidra; + RizinCommentDatabase::RizinCommentDatabase(RizinArchitecture *arch) : arch(arch), cache_filled(false) diff --git a/src/RizinCommentDatabase.h b/src/RizinCommentDatabase.h index e2bd6254..ca8cc0a5 100644 --- a/src/RizinCommentDatabase.h +++ b/src/RizinCommentDatabase.h @@ -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 diff --git a/src/RizinLoadImage.cpp b/src/RizinLoadImage.cpp index d2912e70..cb9535a1 100644 --- a/src/RizinLoadImage.cpp +++ b/src/RizinLoadImage.cpp @@ -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), diff --git a/src/RizinLoadImage.h b/src/RizinLoadImage.h index 86051e1c..6253b714 100644 --- a/src/RizinLoadImage.h +++ b/src/RizinLoadImage.h @@ -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; }; diff --git a/src/RizinPrintC.cpp b/src/RizinPrintC.cpp index 42256af2..74e98ec0 100644 --- a/src/RizinPrintC.cpp +++ b/src/RizinPrintC.cpp @@ -6,6 +6,8 @@ #include #include +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 { diff --git a/src/RizinPrintC.h b/src/RizinPrintC.h index 9c8ba3ae..6f280a9a 100644 --- a/src/RizinPrintC.h +++ b/src/RizinPrintC.h @@ -6,24 +6,24 @@ #include -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 diff --git a/src/RizinScope.cpp b/src/RizinScope.cpp index cf5882d6..178e8b58 100644 --- a/src/RizinScope.cpp +++ b/src/RizinScope.cpp @@ -11,6 +11,8 @@ #include "RizinUtils.h" +using namespace ghidra; + RizinScope::RizinScope(RizinArchitecture *arch) : Scope(0, "", arch, this), arch(arch), diff --git a/src/RizinScope.h b/src/RizinScope.h index b9173a8e..4e6e2d52 100644 --- a/src/RizinScope.h +++ b/src/RizinScope.h @@ -21,78 +21,78 @@ typedef struct rz_flag_item_t RzFlagItem; typedef struct rz_analysis_var_global_t RzAnalysisVarGlobal; typedef struct rz_bin_reloc_t RzBinReloc; -class RizinScope : public Scope +class RizinScope : public ghidra::Scope { private: RizinArchitecture *arch; - ScopeInternal *cache; - std::unique_ptr next_id; + ghidra::ScopeInternal *cache; + std::unique_ptr next_id; - uint8 makeId() const { return (*next_id)++; } + ghidra::uint8 makeId() const { return (*next_id)++; } - FunctionSymbol *registerFunction(RzAnalysisFunction *fcn) const; - FunctionSymbol *registerRelocTarget(RzBinReloc *reloc) const; - Symbol *registerFlag(RzFlagItem *flag) const; - Symbol *registerGlobalVar(RzAnalysisVarGlobal *glob) const; - Symbol *queryRizinAbsolute(ut64 addr, bool contain) const; - Symbol *queryRizin(const Address &addr, bool contain) const; - LabSymbol *queryRizinFunctionLabel(const Address &addr) const; + ghidra::FunctionSymbol *registerFunction(RzAnalysisFunction *fcn) const; + ghidra::FunctionSymbol *registerRelocTarget(RzBinReloc *reloc) const; + ghidra::Symbol *registerFlag(RzFlagItem *flag) const; + ghidra::Symbol *registerGlobalVar(RzAnalysisVarGlobal *glob) const; + ghidra::Symbol *queryRizinAbsolute(ut64 addr, bool contain) const; + ghidra::Symbol *queryRizin(const ghidra::Address &addr, bool contain) const; + ghidra::LabSymbol *queryRizinFunctionLabel(const ghidra::Address &addr) const; protected: // TODO? void addRange(AddrSpace *spc,uintb first,uintb last) override; - void removeRange(AddrSpace *spc,uintb first,uintb last) override { throw LowlevelError("remove_range should not be performed on rizin scope"); } - void addSymbolInternal(Symbol *sym) override { throw LowlevelError("addSymbolInternal unimplemented"); } - SymbolEntry *addMapInternal(Symbol *sym, uint4 exfl, const Address &addr, int4 off, int4 sz, const RangeList &uselim) override { throw LowlevelError("addMapInternal unimplemented"); } - SymbolEntry *addDynamicMapInternal(Symbol *sym, uint4 exfl, uint8 hash, int4 off, int4 sz, const RangeList &uselim) override { throw LowlevelError("addMap unimplemented"); } + void removeRange(ghidra::AddrSpace *spc, ghidra::uintb first, ghidra::uintb last) override { throw ghidra::LowlevelError("remove_range should not be performed on rizin scope"); } + void addSymbolInternal(ghidra::Symbol *sym) override { throw ghidra::LowlevelError("addSymbolInternal unimplemented"); } + ghidra::SymbolEntry *addMapInternal(ghidra::Symbol *sym, ghidra::uint4 exfl, const ghidra::Address &addr, ghidra::int4 off, ghidra::int4 sz, const ghidra::RangeList &uselim) override { throw ghidra::LowlevelError("addMapInternal unimplemented"); } + ghidra::SymbolEntry *addDynamicMapInternal(ghidra::Symbol *sym, ghidra::uint4 exfl, ghidra::uint8 hash, ghidra::int4 off, ghidra::int4 sz, const ghidra::RangeList &uselim) override { throw ghidra::LowlevelError("addMap unimplemented"); } public: explicit RizinScope(RizinArchitecture *arch); ~RizinScope() override; - Scope *buildSubScope(uint8 id, const string &nm) override; + Scope *buildSubScope(ghidra::uint8 id, const std::string &nm) override; void clear(void) override { cache->clear(); } - SymbolEntry *addSymbol(const string &name, Datatype *ct, const Address &addr, const Address &usepoint) override { return cache->addSymbol(name, ct, addr, usepoint); } - string buildVariableName(const Address &addr, const Address &pc, Datatype *ct,int4 &index,uint4 flags) const override { return cache->buildVariableName(addr,pc,ct,index,flags); } - string buildUndefinedName(void) const override { return cache->buildUndefinedName(); } - void setAttribute(Symbol *sym,uint4 attr) override { cache->setAttribute(sym,attr); } - void clearAttribute(Symbol *sym,uint4 attr) override { cache->clearAttribute(sym,attr); } - void setDisplayFormat(Symbol *sym,uint4 attr) override { cache->setDisplayFormat(sym,attr); } + ghidra::SymbolEntry *addSymbol(const std::string &name, ghidra::Datatype *ct, const ghidra::Address &addr, const ghidra::Address &usepoint) override { return cache->addSymbol(name, ct, addr, usepoint); } + std::string buildVariableName(const ghidra::Address &addr, const ghidra::Address &pc, ghidra::Datatype *ct, ghidra::int4 &index, ghidra::uint4 flags) const override { return cache->buildVariableName(addr,pc,ct,index,flags); } + std::string buildUndefinedName(void) const override { return cache->buildUndefinedName(); } + void setAttribute(ghidra::Symbol *sym, ghidra::uint4 attr) override { cache->setAttribute(sym,attr); } + void clearAttribute(ghidra::Symbol *sym, ghidra::uint4 attr) override { cache->clearAttribute(sym,attr); } + void setDisplayFormat(ghidra::Symbol *sym,ghidra::uint4 attr) override { cache->setDisplayFormat(sym,attr); } void adjustCaches(void) override { cache->adjustCaches(); } - SymbolEntry *findAddr(const Address &addr,const Address &usepoint) const override; - SymbolEntry *findContainer(const Address &addr,int4 size, const Address &usepoint) const override; - SymbolEntry *findClosestFit(const Address &addr,int4 size, const Address &usepoint) const override { throw LowlevelError("findClosestFit unimplemented"); } - Funcdata *findFunction(const Address &addr) const override; - ExternRefSymbol *findExternalRef(const Address &addr) const override; - LabSymbol *findCodeLabel(const Address &addr) const override; - bool isNameUsed(const string &name, const Scope *op2) const override { throw LowlevelError("isNameUsed unimplemented"); } - Funcdata *resolveExternalRefFunction(ExternRefSymbol *sym) const override; + ghidra::SymbolEntry *findAddr(const ghidra::Address &addr, const ghidra::Address &usepoint) const override; + ghidra::SymbolEntry *findContainer(const ghidra::Address &addr, ghidra::int4 size, const ghidra::Address &usepoint) const override; + ghidra::SymbolEntry *findClosestFit(const ghidra::Address &addr, ghidra::int4 size, const ghidra::Address &usepoint) const override { throw ghidra::LowlevelError("findClosestFit unimplemented"); } + ghidra::Funcdata *findFunction(const ghidra::Address &addr) const override; + ghidra::ExternRefSymbol *findExternalRef(const ghidra::Address &addr) const override; + ghidra::LabSymbol *findCodeLabel(const ghidra::Address &addr) const override; + bool isNameUsed(const std::string &name, const Scope *op2) const override { throw ghidra::LowlevelError("isNameUsed unimplemented"); } + ghidra::Funcdata *resolveExternalRefFunction(ghidra::ExternRefSymbol *sym) const override; - SymbolEntry *findOverlap(const Address &addr,int4 size) const override { throw LowlevelError("findOverlap unimplemented"); } - SymbolEntry *findBefore(const Address &addr) const { throw LowlevelError("findBefore unimplemented"); } - SymbolEntry *findAfter(const Address &addr) const { throw LowlevelError("findAfter unimplemented"); } - void findByName(const string &name,vector &res) const override { throw LowlevelError("findByName unimplemented"); } - MapIterator begin() const override { throw LowlevelError("begin unimplemented"); } - MapIterator end() const override { throw LowlevelError("end unimplemented"); } - list::const_iterator beginDynamic() const override { throw LowlevelError("beginDynamic unimplemented"); } - list::const_iterator endDynamic() const override { throw LowlevelError("endDynamic unimplemented"); } - list::iterator beginDynamic() override { throw LowlevelError("beginDynamic unimplemented"); } - list::iterator endDynamic() override { throw LowlevelError("endDynamic unimplemented"); } - void clearCategory(int4 cat) override { throw LowlevelError("clearCategory unimplemented"); } - void clearUnlockedCategory(int4 cat) override { throw LowlevelError("clearUnlockedCategory unimplemented"); } - void clearUnlocked() override { throw LowlevelError("clearUnlocked unimplemented"); } - void restrictScope(Funcdata *f) override { throw LowlevelError("restrictScope unimplemented"); } - void removeSymbolMappings(Symbol *symbol) override { throw LowlevelError("removeSymbolMappings unimplemented"); } - void removeSymbol(Symbol *symbol) override { throw LowlevelError("removeSymbol unimplemented"); } - void renameSymbol(Symbol *sym,const string &newname) override { throw LowlevelError("renameSymbol unimplemented"); } - void retypeSymbol(Symbol *sym,Datatype *ct) override { throw LowlevelError("retypeSymbol unimplemented"); } - string makeNameUnique(const string &nm) const override { throw LowlevelError("makeNameUnique unimplemented"); } - void encode(Encoder &encoder) const override { cache->encode(encoder); } - void decode(Decoder &decoder) override { throw LowlevelError("decode unimplemented"); } - void printEntries(ostream &s) const override { throw LowlevelError("printEntries unimplemented"); } - int4 getCategorySize(int4 cat) const override { throw LowlevelError("getCategorySize unimplemented"); } - Symbol *getCategorySymbol(int4 cat,int4 ind) const override { throw LowlevelError("getCategorySymbol unimplemented"); } - void setCategory(Symbol *sym,int4 cat,int4 ind) override { throw LowlevelError("setCategory unimplemented"); } + ghidra::SymbolEntry *findOverlap(const ghidra::Address &addr, ghidra::int4 size) const override { throw ghidra::LowlevelError("findOverlap unimplemented"); } + ghidra::SymbolEntry *findBefore(const ghidra::Address &addr) const { throw ghidra::LowlevelError("findBefore unimplemented"); } + ghidra::SymbolEntry *findAfter(const ghidra::Address &addr) const { throw ghidra::LowlevelError("findAfter unimplemented"); } + void findByName(const std::string &name, std::vector &res) const override { throw ghidra::LowlevelError("findByName unimplemented"); } + ghidra::MapIterator begin() const override { throw ghidra::LowlevelError("begin unimplemented"); } + ghidra::MapIterator end() const override { throw ghidra::LowlevelError("end unimplemented"); } + std::list::const_iterator beginDynamic() const override { throw ghidra::LowlevelError("beginDynamic unimplemented"); } + std::list::const_iterator endDynamic() const override { throw ghidra::LowlevelError("endDynamic unimplemented"); } + std::list::iterator beginDynamic() override { throw ghidra::LowlevelError("beginDynamic unimplemented"); } + std::list::iterator endDynamic() override { throw ghidra::LowlevelError("endDynamic unimplemented"); } + void clearCategory(ghidra::int4 cat) override { throw ghidra::LowlevelError("clearCategory unimplemented"); } + void clearUnlockedCategory(ghidra::int4 cat) override { throw ghidra::LowlevelError("clearUnlockedCategory unimplemented"); } + void clearUnlocked() override { throw ghidra::LowlevelError("clearUnlocked unimplemented"); } + void restrictScope(ghidra::Funcdata *f) override { throw ghidra::LowlevelError("restrictScope unimplemented"); } + void removeSymbolMappings(ghidra::Symbol *symbol) override { throw ghidra::LowlevelError("removeSymbolMappings unimplemented"); } + void removeSymbol(ghidra::Symbol *symbol) override { throw ghidra::LowlevelError("removeSymbol unimplemented"); } + void renameSymbol(ghidra::Symbol *sym, const std::string &newname) override { throw ghidra::LowlevelError("renameSymbol unimplemented"); } + void retypeSymbol(ghidra::Symbol *sym, ghidra::Datatype *ct) override { throw ghidra::LowlevelError("retypeSymbol unimplemented"); } + std::string makeNameUnique(const std::string &nm) const override { throw ghidra::LowlevelError("makeNameUnique unimplemented"); } + void encode(ghidra::Encoder &encoder) const override { cache->encode(encoder); } + void decode(ghidra::Decoder &decoder) override { throw ghidra::LowlevelError("decode unimplemented"); } + void printEntries(std::ostream &s) const override { throw ghidra::LowlevelError("printEntries unimplemented"); } + ghidra::int4 getCategorySize(ghidra::int4 cat) const override { throw ghidra::LowlevelError("getCategorySize unimplemented"); } + ghidra::Symbol *getCategorySymbol(ghidra::int4 cat, ghidra::int4 ind) const override { throw ghidra::LowlevelError("getCategorySymbol unimplemented"); } + void setCategory(ghidra::Symbol *sym, ghidra::int4 cat, ghidra::int4 ind) override { throw ghidra::LowlevelError("setCategory unimplemented"); } }; #endif //RZ_GHIDRA_RizinSCOPE_H diff --git a/src/RizinTypeFactory.cpp b/src/RizinTypeFactory.cpp index cf07587e..e7478dd5 100644 --- a/src/RizinTypeFactory.cpp +++ b/src/RizinTypeFactory.cpp @@ -9,6 +9,8 @@ #include "RizinUtils.h" +using namespace ghidra; + RizinTypeFactory::RizinTypeFactory(RizinArchitecture *arch) : TypeFactory(arch), arch(arch) diff --git a/src/RizinTypeFactory.h b/src/RizinTypeFactory.h index ac455dcd..ea6aa34e 100644 --- a/src/RizinTypeFactory.h +++ b/src/RizinTypeFactory.h @@ -12,33 +12,33 @@ typedef struct rz_base_type_t RzBaseType; class RizinArchitecture; -class RizinTypeFactory : public TypeFactory +class RizinTypeFactory : public ghidra::TypeFactory { public: using StackTypes = std::set; private: RizinArchitecture *arch; - std::set prototypes; // set of types that have not been created fully yet + std::set prototypes; // set of types that have not been created fully yet - Datatype *addRizinStruct(RzBaseType *type, StackTypes &stack_types, bool prototype); - Datatype *addRizinEnum(RzBaseType *type); - Datatype *addRizinTypedef(RzBaseType *type, StackTypes &stack_types); - Datatype *addRizinAtomicType(RzBaseType *type, StackTypes &stack_types); - Datatype *queryRizin(const string &n, StackTypes &stack_types, bool prototype); + ghidra::Datatype *addRizinStruct(RzBaseType *type, StackTypes &stack_types, bool prototype); + ghidra::Datatype *addRizinEnum(RzBaseType *type); + ghidra::Datatype *addRizinTypedef(RzBaseType *type, StackTypes &stack_types); + ghidra::Datatype *addRizinAtomicType(RzBaseType *type, StackTypes &stack_types); + ghidra::Datatype *queryRizin(const std::string &n, StackTypes &stack_types, bool prototype); protected: - Datatype *findById(const string &n, uint8 id, int4 sz) override; - Datatype *findById(const string &n, uint8 id, int4 sz, StackTypes &stack_types, bool prototype); + ghidra::Datatype *findById(const std::string &n, ghidra::uint8 id, ghidra::int4 sz) override; + ghidra::Datatype *findById(const std::string &n, ghidra::uint8 id, ghidra::int4 sz, StackTypes &stack_types, bool prototype); using TypeFactory::findByName; - Datatype *findByName(const string &n, StackTypes &stack_types, bool prototype) { return findById(n, 0, 0, stack_types, prototype); } - Datatype *fromRzTypeInternal(const RzType *ctype, string *error, StackTypes *stack_types, bool prototype, bool refd); + ghidra::Datatype *findByName(const std::string &n, StackTypes &stack_types, bool prototype) { return findById(n, 0, 0, stack_types, prototype); } + ghidra::Datatype *fromRzTypeInternal(const RzType *ctype, std::string *error, StackTypes *stack_types, bool prototype, bool refd); public: RizinTypeFactory(RizinArchitecture *arch); ~RizinTypeFactory() override; - Datatype *fromRzType(const RzType *ctype, string *error = nullptr, StackTypes *stack_types = nullptr); + ghidra::Datatype *fromRzType(const RzType *ctype, std::string *error = nullptr, StackTypes *stack_types = nullptr); }; #endif //RZ_GHIDRA_RizinTYPEFACTORY_H diff --git a/src/SleighAnalysisValue.cpp b/src/SleighAnalysisValue.cpp index 06fa26ef..ef604a27 100644 --- a/src/SleighAnalysisValue.cpp +++ b/src/SleighAnalysisValue.cpp @@ -3,6 +3,8 @@ #include "SleighAnalysisValue.h" +using namespace ghidra; + RzAnalysisValueType SleighAnalysisValue::type_from_values(const SleighAnalysisValue &in0, const SleighAnalysisValue &in1) { RzAnalysisValueType res; diff --git a/src/SleighAnalysisValue.h b/src/SleighAnalysisValue.h index 896dc332..231239d5 100644 --- a/src/SleighAnalysisValue.h +++ b/src/SleighAnalysisValue.h @@ -29,7 +29,7 @@ struct SleighAnalysisValue: public RzAnalysisValue bool is_mem() const { return type == RZ_ANALYSIS_VAL_MEM; } void invalid() { absolute = -1; } - void mem(uint4 size); + void mem(ghidra::uint4 size); RzAnalysisValue *dup() const; private: diff --git a/src/SleighAsm.cpp b/src/SleighAsm.cpp index 74176d23..104c71c9 100644 --- a/src/SleighAsm.cpp +++ b/src/SleighAsm.cpp @@ -5,6 +5,8 @@ #include "SleighAsm.h" #include "ArchMap.h" +using namespace ghidra; + AsmLoadImage::AsmLoadImage() : LoadImage("rizin_asm"), buf(rz_buf_new_sparse(0xff), rz_buf_free) { diff --git a/src/SleighAsm.h b/src/SleighAsm.h index ffcd125e..f8de0056 100644 --- a/src/SleighAsm.h +++ b/src/SleighAsm.h @@ -22,22 +22,22 @@ #include "sleigh_arch.hh" #include "SleighInstruction.h" -class AsmLoadImage : public LoadImage +class AsmLoadImage : public ghidra::LoadImage { private: std::unique_ptr buf; public: AsmLoadImage(); - void loadFill(uint1 *ptr, int4 size, const Address &addr) override; - string getArchType(void) const override { return "rizin"; } - void adjustVma(long adjust) override { throw LowlevelError("Cannot adjust rizin virtual memory"); } + void loadFill(ghidra::uint1 *ptr, ghidra::int4 size, const ghidra::Address &addr) override; + std::string getArchType(void) const override { return "rizin"; } + void adjustVma(long adjust) override { throw ghidra::LowlevelError("Cannot adjust rizin virtual memory"); } void resetBuffer(ut64 offset, const ut8 *data, size_t size); }; class SleighAsm; -class AssemblySlg : public AssemblyEmit +class AssemblySlg : public ghidra::AssemblyEmit { private: SleighAsm *sasm = nullptr; @@ -47,7 +47,7 @@ class AssemblySlg : public AssemblyEmit AssemblySlg(SleighAsm *s): sasm(s) {} - void dump(const Address &addr, const string &mnem, const string &body) override; + void dump(const ghidra::Address &addr, const std::string &mnem, const std::string &body) override; ~AssemblySlg() { @@ -58,11 +58,12 @@ class AssemblySlg : public AssemblyEmit struct PcodeOperand { - PcodeOperand(uintb offset, uint4 size): type(RAM), offset(offset), size(size) {} - PcodeOperand(uintb number): type(CONST), number(number), size(0) {} - PcodeOperand(const std::string &name, uint4 size): type(REGISTER), name(name), size(size) {} + PcodeOperand(ghidra::uintb offset, ghidra::uint4 size): type(RAM), offset(offset), size(size) {} + PcodeOperand(ghidra::uintb number): type(CONST), number(number), size(0) {} + PcodeOperand(const std::string &name, ghidra::uint4 size): type(REGISTER), name(name), size(size) {} virtual ~PcodeOperand() { + using namespace std; if(type == REGISTER) name.~string(); } @@ -70,10 +71,10 @@ struct PcodeOperand union { std::string name; - uintb offset; - uintb number; + ghidra::uintb offset; + ghidra::uintb number; }; - uint4 size; + ghidra::uint4 size; enum { @@ -94,7 +95,7 @@ struct PcodeOperand case UNIQUE: /* Same as RAM */ case RAM: offset = rhs.offset; break; case CONST: number = rhs.number; break; - default: throw LowlevelError("Unexpected type of PcodeOperand found in operator==."); + default: throw ghidra::LowlevelError("Unexpected type of PcodeOperand found in operator==."); } } @@ -109,7 +110,7 @@ struct PcodeOperand case UNIQUE: /* Same as RAM */ case RAM: return offset == rhs.offset && size == rhs.size; case CONST: return number == rhs.number; - default: throw LowlevelError("Unexpected type of PcodeOperand found in operator==."); + default: throw ghidra::LowlevelError("Unexpected type of PcodeOperand found in operator==."); } } @@ -122,9 +123,9 @@ struct PcodeOperand bool is_reg() const { return type == REGISTER; } }; -ostream &operator<<(ostream &s, const PcodeOperand &arg); +std::ostream &operator<<(std::ostream &s, const PcodeOperand &arg); -typedef OpCode PcodeOpType; +typedef ghidra::OpCode PcodeOpType; struct Pcodeop { @@ -151,7 +152,7 @@ struct Pcodeop } }; -ostream &operator<<(ostream &s, const Pcodeop &op); +std::ostream &operator<<(std::ostream &s, const Pcodeop &op); struct UniquePcodeOperand: public PcodeOperand { @@ -160,24 +161,24 @@ struct UniquePcodeOperand: public PcodeOperand ~UniquePcodeOperand() = default; }; -class PcodeSlg : public PcodeEmit +class PcodeSlg : public ghidra::PcodeEmit { private: SleighAsm *sanalysis = nullptr; - PcodeOperand *parse_vardata(VarnodeData &data); + PcodeOperand *parse_vardata(ghidra::VarnodeData &data); public: std::vector pcodes; PcodeSlg(SleighAsm *s): sanalysis(s) {} - void dump(const Address &addr, OpCode opc, VarnodeData *outvar, VarnodeData *vars, - int4 isize) override + void dump(const ghidra::Address &addr, ghidra::OpCode opc, ghidra::VarnodeData *outvar, ghidra::VarnodeData *vars, + ghidra::int4 isize) override { PcodeOperand *out = nullptr, *in0 = nullptr, *in1 = nullptr; - if(opc == CPUI_CALLOTHER) + if(opc == ghidra::CPUI_CALLOTHER) isize = isize > 2? 2: isize; switch(isize) @@ -186,7 +187,7 @@ class PcodeSlg : public PcodeEmit case 2: in1 = parse_vardata(vars[1]); case 1: in0 = parse_vardata(vars[0]); case 0: break; - default: throw LowlevelError("Unexpexted isize in PcodeSlg::dump()"); + default: throw ghidra::LowlevelError("Unexpexted isize in PcodeSlg::dump()"); } if(outvar) @@ -218,22 +219,22 @@ class SleighAsm { private: AsmLoadImage loader; - ContextInternal context; - DocumentStorage docstorage; - FileManage specpaths; - std::vector description; + ghidra::ContextInternal context; + ghidra::DocumentStorage docstorage; + ghidra::FileManage specpaths; + std::vector description; int languageindex; void initInner(std::string sleigh_id); void initRegMapping(void); std::string getSleighHome(RzConfig *cfg); void collectSpecfiles(void); - void scanSleigh(const string &rootpath); - void resolveArch(const string &archid); - void buildSpecfile(DocumentStorage &store); - void parseProcConfig(DocumentStorage &store); - void parseCompConfig(DocumentStorage &store); - void loadLanguageDescription(const string &specfile); + void scanSleigh(const std::string &rootpath); + void resolveArch(const std::string &archid); + void buildSpecfile(ghidra::DocumentStorage &store); + void parseProcConfig(ghidra::DocumentStorage &store); + void parseCompConfig(ghidra::DocumentStorage &store); + void loadLanguageDescription(const std::string &specfile); void resetBuffer(ut64 offset, const ut8 *buf, size_t size); public: @@ -250,7 +251,7 @@ class SleighAsm SleighAsm(): trans(nullptr, nullptr) {} void init(const char *cpu, int bits, bool bigendian, RzConfig *cfg); int disassemble(RzAsmOp *op, ut64 offset, const ut8 *buf, size_t size); - int genOpcode(PcodeSlg &pcode_slg, Address &addr, const ut8 *buf, size_t size); + int genOpcode(PcodeSlg &pcode_slg, ghidra::Address &addr, const ut8 *buf, size_t size); std::vector getRegs(void); static RzConfig *getConfig(RzAsm *a); static RzConfig *getConfig(RzAnalysis *a); diff --git a/src/SleighInstruction.cpp b/src/SleighInstruction.cpp index f5146f40..8d7c88e4 100644 --- a/src/SleighInstruction.cpp +++ b/src/SleighInstruction.cpp @@ -4,6 +4,8 @@ #include "SleighInstruction.h" +using namespace ghidra; + SleighInstructionPrototype *RizinSleigh::getPrototype(SleighInstruction *context) { SleighInstructionPrototype *new_proto = new SleighInstructionPrototype(this, context); diff --git a/src/SleighInstruction.h b/src/SleighInstruction.h index bd047f55..a60e79f5 100644 --- a/src/SleighInstruction.h +++ b/src/SleighInstruction.h @@ -118,16 +118,16 @@ static bool flowTypeHasFallthrough(FlowType t) } } -static uint4 hashConstructState(ConstructState *cs, uint4 hashCode) +static ghidra::uint4 hashConstructState(ghidra::ConstructState *cs, ghidra::uint4 hashCode) { if(cs->ct == nullptr) return hashCode; - uint4 id = cs->ct->getId(); - hashCode = crc_update(hashCode, id >> 8); - hashCode = crc_update(hashCode, id); + ghidra::uint4 id = cs->ct->getId(); + hashCode = ghidra::crc_update(hashCode, id >> 8); + hashCode = ghidra::crc_update(hashCode, id); - for(ConstructState *p: cs->resolve) + for(ghidra::ConstructState *p: cs->resolve) if(p != nullptr) hashCode = hashConstructState(p, hashCode); @@ -142,10 +142,10 @@ static uint4 hashConstructState(ConstructState *cs, uint4 hashCode) class OpTplWalker { private: - ConstructState *point = nullptr; // The current node being visited - const vector *oparray = nullptr; // current array of ops being traversed - int4 depth; // Depth of current node within the tree - int4 breadcrumb[64]; // Path of operands from the root + ghidra::ConstructState *point = nullptr; // The current node being visited + const std::vector *oparray = nullptr; // current array of ops being traversed + ghidra::int4 depth; // Depth of current node within the tree + ghidra::int4 breadcrumb[64]; // Path of operands from the root int maxsize; // Maximum number of directives for this point int sectionnum; @@ -153,10 +153,10 @@ class OpTplWalker { maxsize = 0; oparray = nullptr; - Constructor *ct = point->ct; + ghidra::Constructor *ct = point->ct; if(ct == nullptr) return; - const ConstructTpl *tpl; + const ghidra::ConstructTpl *tpl; if(sectionnum < 0) { tpl = ct->getTempl(); @@ -182,7 +182,7 @@ class OpTplWalker * @param root is the root ConstructState of the tree * @param sectionnum is the named section to traverse (or -1 for main section) */ - OpTplWalker(ConstructState *root, int sectionnum): point(root), sectionnum(sectionnum) + OpTplWalker(ghidra::ConstructState *root, int sectionnum): point(root), sectionnum(sectionnum) { // NOTE: breadcrumb array size limits depth of parse depth = 0; @@ -194,7 +194,7 @@ class OpTplWalker * Constructor for walking a single template * @param tpl */ - OpTplWalker(ConstructTpl *tpl) + OpTplWalker(ghidra::ConstructTpl *tpl) { depth = 0; breadcrumb[0] = 0; @@ -202,7 +202,7 @@ class OpTplWalker maxsize = oparray->size(); } - ConstructState *getState() { return point; } + ghidra::ConstructState *getState() { return point; } bool isState() { @@ -246,7 +246,7 @@ class OpTplWalker } } - int nextOpTpl(OpTpl *(&lastop)) + int nextOpTpl(ghidra::OpTpl *(&lastop)) { int curind = breadcrumb[depth]++; if(curind >= maxsize) @@ -254,8 +254,8 @@ class OpTplWalker if(oparray == nullptr) // Plus one to avoid overlay when zero appear, which means return truly lastop return curind + 1; // Virtual build directive - OpTpl *op = (*oparray)[curind]; - if(op->getOpcode() != OpCode::CPUI_MULTIEQUAL) + ghidra::OpTpl *op = (*oparray)[curind]; + if(op->getOpcode() != ghidra::OpCode::CPUI_MULTIEQUAL) { // if NOT a build directive lastop = op; return 0; // return ordinary OpTpl @@ -268,51 +268,51 @@ class OpTplWalker }; class SleighInstructionPrototype; -class SleighParserContext : public ParserContext +class SleighParserContext : public ghidra::ParserContext { private: SleighInstructionPrototype *prototype = nullptr; public: - SleighParserContext(ContextCache *ccache, Translate *trans): ParserContext(ccache, trans) {} + SleighParserContext(ghidra::ContextCache *ccache, ghidra::Translate *trans): ParserContext(ccache, trans) {} SleighInstructionPrototype *getPrototype() { return prototype; } void setPrototype(SleighInstructionPrototype *p); }; class SleighInstruction; class SleighInstructionPrototype; -class RizinSleigh : public Sleigh +class RizinSleigh : public ghidra::Sleigh { // To export protected member functions to SleighInstructionPrototype friend SleighInstructionPrototype; private: - LoadImage *rizin_loader = nullptr; - mutable LRUCache ins_cache; - mutable unordered_map proto_cache; + ghidra::LoadImage *rizin_loader = nullptr; + mutable LRUCache ins_cache; + mutable std::unordered_map proto_cache; - void generateLocation(const VarnodeTpl *vntpl, VarnodeData &vn, ParserWalker &walker); - void generatePointer(const VarnodeTpl *vntpl, VarnodeData &vn, ParserWalker &walker); + void generateLocation(const ghidra::VarnodeTpl *vntpl, ghidra::VarnodeData &vn, ghidra::ParserWalker &walker); + void generatePointer(const ghidra::VarnodeTpl *vntpl, ghidra::VarnodeData &vn, ghidra::ParserWalker &walker); public: - RizinSleigh(LoadImage *ld, ContextDatabase *c_db): rizin_loader(ld), Sleigh(ld, c_db) {} + RizinSleigh(ghidra::LoadImage *ld, ghidra::ContextDatabase *c_db): rizin_loader(ld), Sleigh(ld, c_db) {} ~RizinSleigh() { clearCache(); } - void reset(LoadImage *ld,ContextDatabase *c_db) { rizin_loader = ld; Sleigh::reset(ld, c_db); } - void reconstructContext(ParserContext &protoContext); - SleighParserContext *newSleighParserContext(Address &addr, SleighInstructionPrototype *proto); - SleighParserContext *getParserContext(Address &addr, SleighInstructionPrototype *proto); + void reset(ghidra::LoadImage *ld, ghidra::ContextDatabase *c_db) { rizin_loader = ld; Sleigh::reset(ld, c_db); } + void reconstructContext(ghidra::ParserContext &protoContext); + SleighParserContext *newSleighParserContext(ghidra::Address &addr, SleighInstructionPrototype *proto); + SleighParserContext *getParserContext(ghidra::Address &addr, SleighInstructionPrototype *proto); SleighInstructionPrototype *getPrototype(SleighInstruction *context); - SleighInstruction *getInstruction(Address &addr); + SleighInstruction *getInstruction(ghidra::Address &addr); - VarnodeData dumpInvar(OpTpl *op, Address &addr); + ghidra::VarnodeData dumpInvar(ghidra::OpTpl *op, ghidra::Address &addr); void resolve(SleighParserContext &pos) const; void clearCache(); - LRUCache *getInsCache() { return &ins_cache; } + LRUCache *getInsCache() { return &ins_cache; } - ParserContext *getContext(const Address &addr,int4 state) const + ghidra::ParserContext *getContext(const ghidra::Address &addr, ghidra::int4 state) const { return obtainContext(addr, state); } @@ -320,17 +320,17 @@ class RizinSleigh : public Sleigh struct SleighInstruction { - Address baseaddr; + ghidra::Address baseaddr; SleighInstructionPrototype *proto = nullptr; - SleighInstruction(Address &addr): baseaddr(addr) {} + SleighInstruction(ghidra::Address &addr): baseaddr(addr) {} FlowType getFlowType(); - std::vector
getFlows(); + std::vector getFlows(); SleighParserContext *getParserContext(); - SleighParserContext *getParserContext(Address &addr); - Address getFallThrough(); - VarnodeData getIndirectInvar(); + SleighParserContext *getParserContext(ghidra::Address &addr); + ghidra::Address getFallThrough(); + ghidra::VarnodeData getIndirectInvar(); }; class SleighInstructionPrototype @@ -356,9 +356,9 @@ class SleighInstructionPrototype struct FlowRecord { - ConstructState *addressnode = + ghidra::ConstructState *addressnode = nullptr; // Constructor state containing destination address of flow - OpTpl *op = nullptr; // The pcode template producing the flow + ghidra::OpTpl *op = nullptr; // The pcode template producing the flow FlowFlags flowFlags = FlowFlags(0); // flags associated with this flow }; @@ -367,47 +367,47 @@ class SleighInstructionPrototype int delay = 0; bool hasCrossBuilds = false; std::vector flowState; - OpTpl *lastop = nullptr; + ghidra::OpTpl *lastop = nullptr; }; FlowType flowType = FlowType::INVALID; int delaySlotByteCnt = 0; - int4 length = 0; + ghidra::int4 length = 0; bool hasCrossBuilds = false; std::vector flowStateList; std::vector> flowStateListNamed; RizinSleigh *sleigh = nullptr; FlowFlags gatherFlags(FlowFlags curflags, SleighInstruction *inst, int secnum); - void gatherFlows(std::vector
&res, SleighInstruction *inst, int secnum); - Address getHandleAddr(FixedHandle &hand, AddrSpace *curSpace); + void gatherFlows(std::vector &res, SleighInstruction *inst, int secnum); + ghidra::Address getHandleAddr(ghidra::FixedHandle &hand, ghidra::AddrSpace *curSpace); static FlowType convertFlowFlags(FlowFlags flags); static FlowType flowListToFlowType(std::vector &flowstate); - static bool handleIsInvalid(FixedHandle &hand); + static bool handleIsInvalid(ghidra::FixedHandle &hand); static FlowSummary walkTemplates(OpTplWalker &walker); - static void addExplicitFlow(ConstructState *state, OpTpl *op, FlowFlags flags, + static void addExplicitFlow(ghidra::ConstructState *state, ghidra::OpTpl *op, FlowFlags flags, FlowSummary &summary); public: SleighInstruction *inst = nullptr; - ConstructState rootState; - uint4 hashCode = 0; + ghidra::ConstructState rootState; + ghidra::uint4 hashCode = 0; FlowType getFlowType(SleighInstruction *inst); - std::vector
getFlows(SleighInstruction *inst); + std::vector getFlows(SleighInstruction *inst); static const char *printFlowType(FlowType t); int getLength() { return length; } - Address getFallThrough(SleighInstruction *inst); + ghidra::Address getFallThrough(SleighInstruction *inst); int getFallThroughOffset(SleighInstruction *inst); // bool isFallthrough() { return flowTypeHasFallthrough(getFlowType()); } - SleighParserContext *getParserContext(Address &addr) { return sleigh->getParserContext(addr, this); } + SleighParserContext *getParserContext(ghidra::Address &addr) { return sleigh->getParserContext(addr, this); } void cacheTreeInfo(); // It could be renamed to parse(), but keep original name to ease update - VarnodeData getIndirectInvar(SleighInstruction *ins); + ghidra::VarnodeData getIndirectInvar(SleighInstruction *ins); SleighInstructionPrototype(RizinSleigh *s, SleighInstruction *i): sleigh(s), inst(i) { if(sleigh == nullptr) - throw LowlevelError("Null pointer in SleighInstructionPrototype ctor"); + throw ghidra::LowlevelError("Null pointer in SleighInstructionPrototype ctor"); rootState.parent = nullptr; // rootState = new ConstructState(null); rootState.ct = nullptr; @@ -434,7 +434,7 @@ class SleighInstructionPrototype clearRootState(&rootState); } - void clearRootState(ConstructState *curr) + void clearRootState(ghidra::ConstructState *curr) { // Classic DFS if(curr) @@ -449,21 +449,21 @@ class SleighInstructionPrototype } }; -class SleighParserWalker : public ParserWalkerChange +class SleighParserWalker : public ghidra::ParserWalkerChange { public: - SleighParserWalker(ParserContext *c): ParserWalkerChange(c) {} + SleighParserWalker(ghidra::ParserContext *c): ParserWalkerChange(c) {} - void subTreeState(ConstructState *subtree) + void subTreeState(ghidra::ConstructState *subtree) { point = subtree; depth = 0; breadcrumb[0] = 0; } - void allocateOperand(int4 i) + void allocateOperand(ghidra::int4 i) { - ConstructState *opstate = new ConstructState; + ghidra::ConstructState *opstate = new ghidra::ConstructState; opstate->ct = nullptr; opstate->parent = point; opstate->length = opstate->offset = 0; diff --git a/src/analysis_ghidra.cpp b/src/analysis_ghidra.cpp index 2016e85f..ba468046 100644 --- a/src/analysis_ghidra.cpp +++ b/src/analysis_ghidra.cpp @@ -13,6 +13,8 @@ #include "SleighAsm.h" #include "SleighAnalysisValue.h" +using namespace ghidra; + static SleighAsm sanalysis; static int archinfo(RzAnalysis *analysis, RzAnalysisInfoType query) diff --git a/src/asm_ghidra.cpp b/src/asm_ghidra.cpp index 86a5472c..e99a6d2e 100644 --- a/src/asm_ghidra.cpp +++ b/src/asm_ghidra.cpp @@ -6,6 +6,8 @@ #include "SleighAsm.h" #include "rz_ghidra_internal.h" +using namespace ghidra; + static SleighAsm sasm; static RzIO *rio = nullptr; diff --git a/src/core_ghidra.cpp b/src/core_ghidra.cpp index a426a06e..00d50860 100644 --- a/src/core_ghidra.cpp +++ b/src/core_ghidra.cpp @@ -24,6 +24,8 @@ #include #include +using namespace ghidra; + #define CMD_PREFIX "pdg" #define CFG_PREFIX "ghidra" diff --git a/test/db/extras/ghidra b/test/db/extras/ghidra index 7f48cf94..101a7245 100644 --- a/test/db/extras/ghidra +++ b/test/db/extras/ghidra @@ -94,7 +94,6 @@ EXPECT=< - + - + - + - + - + @@ -2444,19 +2346,19 @@ CCu base64:Jg== @ 0x804858a - + - + - + - + - + @@ -2466,15 +2368,15 @@ CCu base64:Jg== @ 0x804858a - + - + - + @@ -2492,7 +2394,7 @@ CCu base64:Jg== @ 0x804858a -- - + @@ -2641,6 +2543,7 @@ CCu base64:Jg== @ 0x804858a + @@ -2651,6 +2554,7 @@ CCu base64:Jg== @ 0x804858a + @@ -2661,12 +2565,15 @@ CCu base64:Jg== @ 0x804858a + + + @@ -2677,6 +2584,7 @@ CCu base64:Jg== @ 0x804858a + @@ -2687,6 +2595,8 @@ CCu base64:Jg== @ 0x804858a + + @@ -2964,6 +2874,7 @@ x86:LE:16:Protected Mode x86:LE:16:Real Mode x86:LE:32:System Management Mode x86:LE:32:default +x86:LE:64:compat32 x86:LE:64:default z180:LE:16:default z182:LE:16:default @@ -2988,7 +2899,7 @@ add eax, 0xf shr eax, 4 ----- 0x08048540: PUSH EBP - (unique,0x9b00,4) = COPY EBP + (unique,0x9b80,4) = COPY EBP ESP = INT_SUB ESP, 0x4 0x08048541: MOV EBP,ESP EBP = COPY ESP @@ -2998,20 +2909,20 @@ shr eax, 4 ESP = INT_SUB ESP, 0x88 SF = INT_SLESS ESP, 0x0 ZF = INT_EQUAL ESP, 0x0 - (unique,0xdc80,4) = INT_AND ESP, 0xff - (unique,0xdd00,1) = POPCOUNT (unique,0xdc80,4) - (unique,0xdd80,1) = INT_AND (unique,0xdd00,1), 0x1 - PF = INT_EQUAL (unique,0xdd80,1), 0x0 + (unique,0xdd00,4) = INT_AND ESP, 0xff + (unique,0xdd80,1) = POPCOUNT (unique,0xdd00,4) + (unique,0xde00,1) = INT_AND (unique,0xdd80,1), 0x1 + PF = INT_EQUAL (unique,0xde00,1), 0x0 0x08048549: AND ESP,0xfffffff0 CF = COPY 0x0 OF = COPY 0x0 ESP = INT_AND ESP, 0xfffffff0 SF = INT_SLESS ESP, 0x0 ZF = INT_EQUAL ESP, 0x0 - (unique,0xdc80,4) = INT_AND ESP, 0xff - (unique,0xdd00,1) = POPCOUNT (unique,0xdc80,4) - (unique,0xdd80,1) = INT_AND (unique,0xdd00,1), 0x1 - PF = INT_EQUAL (unique,0xdd80,1), 0x0 + (unique,0xdd00,4) = INT_AND ESP, 0xff + (unique,0xdd80,1) = POPCOUNT (unique,0xdd00,4) + (unique,0xde00,1) = INT_AND (unique,0xdd80,1), 0x1 + PF = INT_EQUAL (unique,0xde00,1), 0x0 0x0804854c: MOV EAX,0x0 EAX = COPY 0x0 0x08048551: ADD EAX,0xf @@ -3020,58 +2931,58 @@ shr eax, 4 EAX = INT_ADD EAX, 0xf SF = INT_SLESS EAX, 0x0 ZF = INT_EQUAL EAX, 0x0 - (unique,0xdc80,4) = INT_AND EAX, 0xff - (unique,0xdd00,1) = POPCOUNT (unique,0xdc80,4) - (unique,0xdd80,1) = INT_AND (unique,0xdd00,1), 0x1 - PF = INT_EQUAL (unique,0xdd80,1), 0x0 + (unique,0xdd00,4) = INT_AND EAX, 0xff + (unique,0xdd80,1) = POPCOUNT (unique,0xdd00,4) + (unique,0xde00,1) = INT_AND (unique,0xdd80,1), 0x1 + PF = INT_EQUAL (unique,0xde00,1), 0x0 0x08048554: ADD EAX,0xf CF = INT_CARRY EAX, 0xf OF = INT_SCARRY EAX, 0xf EAX = INT_ADD EAX, 0xf SF = INT_SLESS EAX, 0x0 ZF = INT_EQUAL EAX, 0x0 - (unique,0xdc80,4) = INT_AND EAX, 0xff - (unique,0xdd00,1) = POPCOUNT (unique,0xdc80,4) - (unique,0xdd80,1) = INT_AND (unique,0xdd00,1), 0x1 - PF = INT_EQUAL (unique,0xdd80,1), 0x0 + (unique,0xdd00,4) = INT_AND EAX, 0xff + (unique,0xdd80,1) = POPCOUNT (unique,0xdd00,4) + (unique,0xde00,1) = INT_AND (unique,0xdd80,1), 0x1 + PF = INT_EQUAL (unique,0xde00,1), 0x0 0x08048557: SHR EAX,0x4 - (unique,0x41900,4) = INT_AND 0x4, 0x1f - (unique,0x41980,4) = COPY EAX - EAX = INT_RIGHT EAX, (unique,0x41900,4) - (unique,0x11180,1) = INT_NOTEQUAL (unique,0x41900,4), 0x0 - (unique,0x11200,4) = INT_SUB (unique,0x41900,4), 0x1 - (unique,0x11280,4) = INT_RIGHT (unique,0x41980,4), (unique,0x11200,4) - (unique,0x11300,4) = INT_AND (unique,0x11280,4), 0x1 - (unique,0x11400,1) = INT_NOTEQUAL (unique,0x11300,4), 0x0 - (unique,0x11480,1) = BOOL_NEGATE (unique,0x11180,1) - (unique,0x11500,1) = INT_AND (unique,0x11480,1), CF - (unique,0x11580,1) = INT_AND (unique,0x11180,1), (unique,0x11400,1) - CF = INT_OR (unique,0x11500,1), (unique,0x11580,1) - (unique,0x11700,1) = INT_EQUAL (unique,0x41900,4), 0x1 - (unique,0x11800,1) = INT_SLESS (unique,0x41980,4), 0x0 - (unique,0x11880,1) = BOOL_NEGATE (unique,0x11700,1) - (unique,0x11900,1) = INT_AND (unique,0x11880,1), OF - (unique,0x11980,1) = INT_AND (unique,0x11700,1), (unique,0x11800,1) - OF = INT_OR (unique,0x11900,1), (unique,0x11980,1) - (unique,0xdf00,1) = INT_NOTEQUAL (unique,0x41900,4), 0x0 - (unique,0xe000,1) = INT_SLESS EAX, 0x0 - (unique,0xe080,1) = BOOL_NEGATE (unique,0xdf00,1) - (unique,0xe100,1) = INT_AND (unique,0xe080,1), SF - (unique,0xe180,1) = INT_AND (unique,0xdf00,1), (unique,0xe000,1) - SF = INT_OR (unique,0xe100,1), (unique,0xe180,1) - (unique,0xe300,1) = INT_EQUAL EAX, 0x0 - (unique,0xe380,1) = BOOL_NEGATE (unique,0xdf00,1) - (unique,0xe400,1) = INT_AND (unique,0xe380,1), ZF - (unique,0xe480,1) = INT_AND (unique,0xdf00,1), (unique,0xe300,1) - ZF = INT_OR (unique,0xe400,1), (unique,0xe480,1) - (unique,0xe580,4) = INT_AND EAX, 0xff - (unique,0xe600,1) = POPCOUNT (unique,0xe580,4) - (unique,0xe680,1) = INT_AND (unique,0xe600,1), 0x1 - (unique,0xe780,1) = INT_EQUAL (unique,0xe680,1), 0x0 - (unique,0xe800,1) = BOOL_NEGATE (unique,0xdf00,1) - (unique,0xe880,1) = INT_AND (unique,0xe800,1), PF - (unique,0xe900,1) = INT_AND (unique,0xdf00,1), (unique,0xe780,1) - PF = INT_OR (unique,0xe880,1), (unique,0xe900,1) + (unique,0x3e780,4) = INT_AND 0x4, 0x1f + (unique,0x3e800,4) = COPY EAX + EAX = INT_RIGHT EAX, (unique,0x3e780,4) + (unique,0x11200,1) = INT_NOTEQUAL (unique,0x3e780,4), 0x0 + (unique,0x11280,4) = INT_SUB (unique,0x3e780,4), 0x1 + (unique,0x11300,4) = INT_RIGHT (unique,0x3e800,4), (unique,0x11280,4) + (unique,0x11380,4) = INT_AND (unique,0x11300,4), 0x1 + (unique,0x11480,1) = INT_NOTEQUAL (unique,0x11380,4), 0x0 + (unique,0x11500,1) = BOOL_NEGATE (unique,0x11200,1) + (unique,0x11580,1) = INT_AND (unique,0x11500,1), CF + (unique,0x11600,1) = INT_AND (unique,0x11200,1), (unique,0x11480,1) + CF = INT_OR (unique,0x11580,1), (unique,0x11600,1) + (unique,0x11780,1) = INT_EQUAL (unique,0x3e780,4), 0x1 + (unique,0x11880,1) = INT_SLESS (unique,0x3e800,4), 0x0 + (unique,0x11900,1) = BOOL_NEGATE (unique,0x11780,1) + (unique,0x11980,1) = INT_AND (unique,0x11900,1), OF + (unique,0x11a00,1) = INT_AND (unique,0x11780,1), (unique,0x11880,1) + OF = INT_OR (unique,0x11980,1), (unique,0x11a00,1) + (unique,0xdf80,1) = INT_NOTEQUAL (unique,0x3e780,4), 0x0 + (unique,0xe080,1) = INT_SLESS EAX, 0x0 + (unique,0xe100,1) = BOOL_NEGATE (unique,0xdf80,1) + (unique,0xe180,1) = INT_AND (unique,0xe100,1), SF + (unique,0xe200,1) = INT_AND (unique,0xdf80,1), (unique,0xe080,1) + SF = INT_OR (unique,0xe180,1), (unique,0xe200,1) + (unique,0xe380,1) = INT_EQUAL EAX, 0x0 + (unique,0xe400,1) = BOOL_NEGATE (unique,0xdf80,1) + (unique,0xe480,1) = INT_AND (unique,0xe400,1), ZF + (unique,0xe500,1) = INT_AND (unique,0xdf80,1), (unique,0xe380,1) + ZF = INT_OR (unique,0xe480,1), (unique,0xe500,1) + (unique,0xe600,4) = INT_AND EAX, 0xff + (unique,0xe680,1) = POPCOUNT (unique,0xe600,4) + (unique,0xe700,1) = INT_AND (unique,0xe680,1), 0x1 + (unique,0xe800,1) = INT_EQUAL (unique,0xe700,1), 0x0 + (unique,0xe880,1) = BOOL_NEGATE (unique,0xdf80,1) + (unique,0xe900,1) = INT_AND (unique,0xe880,1), PF + (unique,0xe980,1) = INT_AND (unique,0xdf80,1), (unique,0xe800,1) + PF = INT_OR (unique,0xe900,1), (unique,0xe980,1) EOF CMDS=<