Skip to content

Commit

Permalink
Merge branch 'dev' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
thestr4ng3r committed Sep 24, 2021
2 parents 8df3bf7 + c7a50a2 commit cf557ff
Show file tree
Hide file tree
Showing 24 changed files with 1,039 additions and 560 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
tasks:
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
tasks:
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 "##[set-output name=branch;]$( python sys\\version.py )"
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 @@ -47,7 +47,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
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ endif()
add_subdirectory(ghidra)
add_subdirectory(third-party)

set(PUBLIC_HEADERS
src/rz_ghidra.h)

set(CORE_SOURCE
src/core_ghidra.cpp
src/RizinArchitecture.cpp
Expand Down Expand Up @@ -78,6 +81,10 @@ set_target_properties(core_ghidra PROPERTIES
OUTPUT_NAME core_ghidra
PREFIX "")

configure_file(
${PROJECT_SOURCE_DIR}/rz_ghidra.pc.in
${PROJECT_BINARY_DIR}/rz_ghidra.pc
@ONLY)

if(BUILD_CUTTER_PLUGIN)
add_subdirectory(cutter-plugin)
Expand Down Expand Up @@ -116,8 +123,14 @@ if(SLEIGHHOME_DEFAULT)
endif()
endif()

if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries.")
endif()

install(TARGETS core_ghidra DESTINATION "${RIZIN_INSTALL_PLUGDIR}")
if(BUILD_SLEIGH_PLUGIN)
install(TARGETS asm_ghidra DESTINATION "${RIZIN_INSTALL_PLUGDIR}")
install(TARGETS analysis_ghidra DESTINATION "${RIZIN_INSTALL_PLUGDIR}")
endif()
install(FILES ${PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rz_ghidra.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
3 changes: 2 additions & 1 deletion cmake/FindRizin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

if(WIN32)
find_path(Rizin_INCLUDE_DIRS
NAMES rz_core.h rz_bin.h rz_util.h
NAMES rz_core.h rz_bin.h rz_util.h rz_type.h
HINTS
"$ENV{HOME}/bin/prefix/rizin/include/librz"
/usr/local/include/librz
Expand Down Expand Up @@ -53,6 +53,7 @@ if(WIN32)
syscall
socket
magic
type
crypto)

set(Rizin_LIBRARIES "")
Expand Down
1 change: 1 addition & 0 deletions ghidra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ set(SOURCE_CONSOLE_CXX
consolemain.cc
interface.cc
ifacedecomp.cc
testfunction.cc
ifaceterm.cc
callgraph.cc
raw_arch.cc)
Expand Down
2 changes: 1 addition & 1 deletion ghidra/ghidra
Submodule ghidra updated 4172 files
13 changes: 13 additions & 0 deletions rz_ghidra.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix="${prefix}"
includedir="${prefix}/include"

Name: RzGhidra
Description: RzGhidra Rizin plugin library
URL: https://github.com/rizinorg/rz-ghidra
Version: @PROJECT_VERSION@
Requires: rz_core
Requires.private: rz_core
Cflags: -I"${includedir}"
Libs: -L"${prefix}/@RIZIN_INSTALL_PLUGDIR@" -l:core_ghidra@CMAKE_SHARED_LIBRARY_SUFFIX@
Libs.private: -L"${prefix}/@RIZIN_INSTALL_PLUGDIR@" -l:core_ghidra@CMAKE_SHARED_LIBRARY_SUFFIX@
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

RUN cd /root && \
git clone --recurse-submodules --depth 1 -b stable https://github.com/rizinorg/rizin && \
git clone --recurse-submodules --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 --recurse-submodules --depth 1 https://github.com/rizinorg/rizin -b stable && \
git clone --recurse-submodules --depth 1 https://github.com/rizinorg/rizin && \
cd rizin && \
meson build --prefix=/usr && \
ninja -C build && \
Expand Down
41 changes: 37 additions & 4 deletions src/RizinScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,12 @@ FunctionSymbol *RizinScope::registerFunction(RzAnalysisFunction *fcn) const
{
rz_list_foreach_cpp<RzAnalysisVar>(vars, [&](RzAnalysisVar *var) {
std::string typeError;
Datatype *type = var->type ? arch->getTypeFactory()->fromCString(var->type, &typeError) : nullptr;
Datatype *type = var->type ? arch->getTypeFactory()->fromRzType(var->type, &typeError) : nullptr;
if(!type)
{
arch->addWarning("Failed to match type " + to_string(var->type) + " for variable " + to_string(var->name) + " to Decompiler type: " + typeError);
char *tstr = rz_type_as_string(core->analysis->typedb, var->type);
arch->addWarning("Failed to match type " + to_string(tstr ? tstr : "?") + " for variable " + to_string(var->name) + " to Decompiler type: " + typeError);
rz_mem_free(tstr);
type = arch->types->getBase(core->analysis->bits / 8, TYPE_UNKNOWN);
if(!type)
return;
Expand Down Expand Up @@ -459,10 +461,12 @@ Symbol *RizinScope::registerFlag(RzFlagItem *flag) const
{
switch(str->type)
{
case RZ_STRING_TYPE_WIDE:
case RZ_STRING_TYPE_WIDE_LE:
case RZ_STRING_TYPE_WIDE_BE:
tn = "char16_t";
break;
case RZ_STRING_TYPE_WIDE32:
case RZ_STRING_TYPE_WIDE32_LE:
case RZ_STRING_TYPE_WIDE32_BE:
tn = "char32_t";
break;
}
Expand Down Expand Up @@ -492,6 +496,27 @@ Symbol *RizinScope::registerFlag(RzFlagItem *flag) const
return symbol;
}

Symbol *RizinScope::registerGlobalVar(RzAnalysisVarGlobal *glob) const
{
RzCoreLock core(arch->getCore());
uint4 attr = Varnode::namelock | Varnode::typelock;
if (!glob->type)
return nullptr;
std::string terr;
Datatype *type = arch->getTypeFactory()->fromRzType(glob->type, &terr);
if(!type)
{
arch->addWarning(std::string("Failed to create type for global variable ") + glob->name + ": " + terr);
return nullptr;
}
SymbolEntry *entry = cache->addSymbol(glob->name, type, Address(arch->getDefaultCodeSpace(), glob->addr), Address());
if(!entry)
return nullptr;
auto symbol = entry->getSymbol();
cache->setAttribute(symbol, attr);
return symbol;
}

Symbol *RizinScope::queryRizinAbsolute(ut64 addr, bool contain) const
{
RzCoreLock core(arch->getCore());
Expand All @@ -510,6 +535,14 @@ Symbol *RizinScope::queryRizinAbsolute(ut64 addr, bool contain) const
if(fcn)
return registerFunction(fcn);

RzAnalysisVarGlobal *glob;
if(contain)
glob = rz_analysis_var_global_get_byaddr_in(core->analysis, addr);
else
glob = rz_analysis_var_global_get_byaddr_at(core->analysis, addr);
if(glob)
return registerGlobalVar(glob);

// TODO: register more things

// TODO: correctly handle contain for flags
Expand Down
8 changes: 5 additions & 3 deletions src/RizinScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class RizinArchitecture;
typedef struct rz_analysis_function_t RzAnalysisFunction;
typedef struct rz_flag_item_t RzFlagItem;
typedef struct rz_analysis_var_global_t RzAnalysisVarGlobal;

class RizinScope : public Scope
{
Expand All @@ -27,6 +28,7 @@ class RizinScope : public Scope

FunctionSymbol *registerFunction(RzAnalysisFunction *fcn) 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;
Expand Down Expand Up @@ -54,17 +56,17 @@ class RizinScope : public Scope
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 { throw LowlevelError("findClosestFit unimplemented"); }
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;

SymbolEntry *findOverlap(const Address &addr,int4 size) const { throw LowlevelError("findOverlap unimplemented"); }
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<Symbol *> &res) const { throw LowlevelError("findByName unimplemented"); }
void findByName(const string &name,vector<Symbol *> &res) const override { throw LowlevelError("findByName unimplemented"); }
MapIterator begin() const override { throw LowlevelError("begin unimplemented"); }
MapIterator end() const override { throw LowlevelError("end unimplemented"); }
list<SymbolEntry>::const_iterator beginDynamic() const override { throw LowlevelError("beginDynamic unimplemented"); }
Expand Down
Loading

0 comments on commit cf557ff

Please sign in to comment.