Skip to content

Commit

Permalink
Merge 'dev' branch into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed Feb 24, 2024
2 parents dbddcf1 + 3733b13 commit 018dfee
Show file tree
Hide file tree
Showing 39 changed files with 811 additions and 772 deletions.
2 changes: 1 addition & 1 deletion .builds/freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ environment:
CC: clang
HOST_CC: clang
sources:
- https://github.com/rizinorg/rizin#stable
- https://github.com/rizinorg/rizin
- https://github.com/rizinorg/rz-ghidra
- https://github.com/rizinorg/rizin-testbins
hottub_trigger: '.*'
Expand Down
2 changes: 1 addition & 1 deletion .builds/openbsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
CXX: clang++
CC: clang
sources:
- https://github.com/rizinorg/rizin#stable
- https://github.com/rizinorg/rizin
- https://github.com/rizinorg/rz-ghidra
- https://github.com/rizinorg/rizin-testbins
hottub_trigger: '.*'
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
with:
repository: rizinorg/rizin
path: rizin
ref: stable
- name: Extract rizin version
shell: pwsh
run: echo "branch=$(python sys/version.py)" >> $Env:GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
pip install meson
- name: Prepare Rizin and Cutter
run: |
git clone --recursive --depth 1 -b stable https://github.com/rizinorg/rizin
git clone --recursive --depth 1 https://github.com/rizinorg/rizin
cd rizin
meson build
ninja -C build
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ env:

install:
- pip3 install meson
- git clone --depth 1 -b stable https://github.com/rizinorg/rizin
- git clone --depth 1 https://github.com/rizinorg/rizin
- cd rizin && mkdir build && cd build
- meson --prefix="$INSTALL_PREFIX" ..
- ninja
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<!--[![Build Status](https://travis-ci.com/rizinorg/rz-ghidra-dec.svg?token=JDmXp2pDhXxtPErySVHM&branch=master)](https://travis-ci.com/rizinorg/rz-ghidra)-->

This is an integration of the Ghidra decompiler and Sleigh Disassembler for [rizin](https://github.com/rizinorg/rizin).
This is an integration of the Ghidra decompiler and Sleigh Disassembler for [Rizin](https://github.com/rizinorg/rizin).
It is solely based on the decompiler part of Ghidra, which is written entirely in
C++, so Ghidra itself is not required at all and the plugin can be built self-contained.
This project was presented, initially for radare2, at r2con 2019 as part of the Cutter talk: [https://youtu.be/eHtMiezr7l8?t=950](https://youtu.be/eHtMiezr7l8?t=950)
Expand Down Expand Up @@ -48,7 +48,7 @@ git submodule init
git submodule update
```

Then, the rizin plugin can be built and installed as follows:
Then, the Rizin plugin can be built and installed as follows:

```
mkdir build && cd build
Expand All @@ -57,8 +57,9 @@ make
make install
```

Here, set the `CMAKE_INSTALL_PREFIX` to a location where rizin can load the plugin from.
Here, set the `CMAKE_INSTALL_PREFIX` to a location where Rizin can load the plugin from.
The install step is necessary for the plugin to work because it includes installing the necessary Sleigh files.
If you are using Rizin from git, also set `CMAKE_PREFIX_PATH` to the Rizin installation directory.

To also build the Cutter plugin, you must have Cutter installed from source under some prefix,
which can be optionally specified with `-DCMAKE_PREFIX_PATH=<path>`, then pass `-DBUILD_CUTTER_PLUGIN=ON` to cmake
Expand Down
5 changes: 0 additions & 5 deletions ghidra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ if(GENERATE_PARSERS)
else()
set(yacc_prefix "${yacc_name}")
endif()
if(BISON_VERSION VERSION_LESS 2.6)
set(BISON_COMPILE_FLAGS "--name-prefix=${yacc_prefix}")
else()
set(BISON_COMPILE_FLAGS "-Dapi.prefix={${yacc_prefix}}")
endif()
BISON_TARGET(${yacc_name}
"${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_DIR}/${yacc_file}"
"${CMAKE_CURRENT_BINARY_DIR}/bison/${yacc_name}.cpp"
Expand Down
2 changes: 1 addition & 1 deletion ghidra/ghidra
Submodule ghidra updated 5123 files
2 changes: 1 addition & 1 deletion scripts/Dockerfile.arch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN pacman --noconfirm -Syu
RUN pacman --noconfirm -S git gcc make cmake pkg-config flex bison meson ninja qt5-base qt5-svg qt5-tools

RUN cd /root && \
git clone --depth 1 -b stable https://github.com/rizinorg/rizin && \
git clone --depth 1 https://github.com/rizinorg/rizin && \
cd rizin && \
meson build --prefix=/usr && \
ninja -C build && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/Dockerfile.buster
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get -y install git g++ cmake pkg-config flex bison python3 python3-pip n
pip3 install meson

RUN cd /root && \
git clone --depth 1 -b stable https://github.com/rizinorg/rizin && \
git clone --depth 1 https://github.com/rizinorg/rizin && \
cd rizin && \
meson build --prefix=/usr && \
ninja -C build && \
Expand Down
2 changes: 2 additions & 0 deletions src/ArchMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <map>
#include <functional>

using namespace ghidra;

std::string CompilerFromCore(RzCore *core);

template<typename T>
Expand Down
2 changes: 1 addition & 1 deletion src/ArchMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -16,6 +16,8 @@
#include <sstream>
#include <string>

using namespace ghidra;

struct ParseCodeXMLContext
{
Funcdata *func;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/CodeXMLParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -3,6 +3,8 @@

#include "PrettyXmlEncode.h"

using namespace ghidra;

void PrettyXmlEncode::indent()
{
for(int i = 0; i < depth; i++)
Expand Down
6 changes: 3 additions & 3 deletions src/PrettyXmlEncode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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" },
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 13 additions & 12 deletions src/RizinArchitecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
};


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

#include "RizinUtils.h"

using namespace ghidra;

RizinCommentDatabase::RizinCommentDatabase(RizinArchitecture *arch)
: arch(arch),
cache_filled(false)
Expand Down
22 changes: 11 additions & 11 deletions src/RizinCommentDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions src/RizinLoadImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -42,12 +44,13 @@ void RizinLoadImage::getReadonly(RangeList &list) const
rz_pvector_foreach_cpp<RzBinFile>(&info->cf->binfiles, [&](RzBinFile *bf) {
if(!bf->o || !bf->o->sections)
return true;
rz_list_foreach_cpp<RzBinSection>(bf->o->sections, [&](RzBinSection *sec) {
rz_pvector_foreach_cpp<RzBinSection>(bf->o->sections, [&](RzBinSection *sec) {
if(!sec->name || !sec->vsize)
return;
return true;
if(strstr(sec->name, "__objc_data") || strstr(sec->name, "__objc_classrefs") || strstr(sec->name, "__objc_msgrefs") ||
strstr(sec->name, "__objc_selrefs") || strstr(sec->name, "__objc_superrefs") || strstr(sec->name, "__objc_protorefs"))
list.insertRange(space, sec->vaddr, sec->vaddr + sec->vsize - 1);
return true;
});
return true;
});
Expand Down
12 changes: 6 additions & 6 deletions src/RizinLoadImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Loading

0 comments on commit 018dfee

Please sign in to comment.