From 98411b4dbfa84bdf7a5bde58da8f39193ca55c09 Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Wed, 22 Dec 2021 09:57:58 +0100 Subject: [PATCH] Update Rizin to dev and use CMake config files (#2855) API usage has been adjusted. There are now also cmake config files directly installed by Rizin itself, so we don't need to keep a custom FindRizin.cmake file in Cutter. This remove that file and just uses `find_package(Rizin COMPONENTS Core)`, which will use the cmake files installed on the system. --- CMakeLists.txt | 4 +- cmake/BundledRizin.cmake | 4 +- cmake/FindRizin.cmake | 117 ------------------------------ dist/CMakeLists.txt | 8 +- dist/MacOSSetupBundle.cmake.in | 1 - dist/bundle_jsdec.ps1 | 4 +- scripts/jsdec.sh | 4 +- src/common/ColorThemeWorker.cpp | 9 ++- src/common/Configuration.cpp | 2 +- src/core/Cutter.cpp | 25 ++++--- src/dialogs/BreakpointsDialog.cpp | 12 +-- src/widgets/BreakpointWidget.cpp | 6 +- 12 files changed, 40 insertions(+), 156 deletions(-) delete mode 100644 cmake/FindRizin.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index bbbba86b..92b49af4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,8 +48,8 @@ if(CUTTER_USE_BUNDLED_RIZIN) include(BundledRizin) set(RIZIN_TARGET Rizin) else() - find_package(Rizin REQUIRED) - set(RIZIN_TARGET Rizin::librz) + find_package(Rizin COMPONENTS Core REQUIRED) + set(RIZIN_TARGET Rizin::Core) endif() set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/cmake/BundledRizin.cmake b/cmake/BundledRizin.cmake index a042f807..ba6813e3 100644 --- a/cmake/BundledRizin.cmake +++ b/cmake/BundledRizin.cmake @@ -47,8 +47,8 @@ else() endif() set (RZ_LIBS rz_core rz_config rz_cons rz_io rz_util rz_flag rz_asm rz_debug - rz_hash rz_bin rz_lang rz_io rz_analysis rz_parse rz_bp rz_egg rz_reg - rz_search rz_syscall rz_socket rz_magic rz_crypto rz_type rz_diff) + rz_hash rz_bin rz_lang rz_il rz_analysis rz_parse rz_bp rz_egg rz_reg + rz_search rz_syscall rz_socket rz_magic rz_crypto rz_type rz_diff rz_sign) set (RZ_EXTRA_LIBS rz_main) set (RZ_BIN rz-agent rz-bin rizin rz-diff rz-find rz-gg rz-hash rz-run rz-asm rz-ax) diff --git a/cmake/FindRizin.cmake b/cmake/FindRizin.cmake deleted file mode 100644 index 924e112a..00000000 --- a/cmake/FindRizin.cmake +++ /dev/null @@ -1,117 +0,0 @@ -# - Find Rizin (librz) -# -# This module provides the following imported targets, if found: -# -# Rizin::librz -# -# This will define the following variables: -# (but don't use them if you don't know what you are doing, use Rizin::librz) -# -# Rizin_FOUND - True if librz has been found. -# Rizin_INCLUDE_DIRS - librz include directory -# Rizin_LIBRARIES - List of libraries when using librz. -# Rizin_LIBRARY_DIRS - librz library directories -# -# If librz was found using find_library and not pkg-config, the following variables will also be set: -# Rizin_LIBRARY_ - Path to library rz_ - -if(WIN32) - find_path(Rizin_INCLUDE_DIRS - NAMES rz_core.h rz_bin.h rz_util.h - HINTS - "$ENV{HOME}/bin/prefix/rizin/include/librz" - /usr/local/include/libr - /usr/include/librz) - find_path(SDB_INCLUDE_DIR - NAMES sdb.h sdbht.h sdb_version.h - HINTS - "$ENV{HOME}/bin/prefix/rizin/include/librz/sdb" - /usr/local/include/librz/sdb - /usr/include/librz/sdb) - - list(APPEND Rizin_INCLUDE_DIRS ${SDB_INCLUDE_DIR}) - - set(Rizin_LIBRARY_NAMES - core - config - cons - io - util - flag - asm - debug - hash - bin - lang - io - analysis - parse - bp - egg - reg - search - syscall - socket - magic - crypto - type) - - set(Rizin_LIBRARIES "") - set(Rizin_LIBRARIES_VARS "") - foreach(libname ${Rizin_LIBRARY_NAMES}) - find_library(Rizin_LIBRARY_${libname} - rz_${libname} - HINTS - "$ENV{HOME}/bin/prefix/rizin/lib" - /usr/local/lib - /usr/lib) - - list(APPEND Rizin_LIBRARIES ${Rizin_LIBRARY_${libname}}) - list(APPEND Rizin_LIBRARIES_VARS "Rizin_LIBRARY_${libname}") - endforeach() - - set(Rizin_LIBRARY_DIRS "") - - add_library(Rizin::librz UNKNOWN IMPORTED) - set_target_properties(Rizin::librz PROPERTIES - IMPORTED_LOCATION "${Rizin_LIBRARY_core}" - IMPORTED_LINK_INTERFACE_LIBRARIES "${Rizin_LIBRARIES}" - INTERFACE_LINK_DIRECTORIES "${Rizin_LIBRARY_DIRS}" - INTERFACE_INCLUDE_DIRECTORIES "${Rizin_INCLUDE_DIRS}") - set(Rizin_TARGET Rizin::librz) -else() - # support installation locations used by rizin scripts like sys/user.sh and sys/install.sh - if(CUTTER_USE_ADDITIONAL_RIZIN_PATHS) - set(Rizin_CMAKE_PREFIX_PATH_TEMP ${CMAKE_PREFIX_PATH}) - list(APPEND CMAKE_PREFIX_PATH "$ENV{HOME}/bin/prefix/rizin") # sys/user.sh - list(APPEND CMAKE_PREFIX_PATH "/usr/local") # sys/install.sh - endif() - - find_package(PkgConfig REQUIRED) - if(CMAKE_VERSION VERSION_LESS "3.6") - pkg_search_module(Rizin REQUIRED rz_core) - else() - pkg_search_module(Rizin IMPORTED_TARGET REQUIRED rz_core) - endif() - - # reset CMAKE_PREFIX_PATH - if(CUTTER_USE_ADDITIONAL_RIZIN_PATHS) - set(CMAKE_PREFIX_PATH ${Rizin_CMAKE_PREFIX_PATH_TEMP}) - endif() - - if((TARGET PkgConfig::Rizin) AND (NOT CMAKE_VERSION VERSION_LESS "3.11.0")) - set_target_properties(PkgConfig::Rizin PROPERTIES IMPORTED_GLOBAL ON) - add_library(Rizin::librz ALIAS PkgConfig::Rizin) - set(Rizin_TARGET Rizin::librz) - elseif(Rizin_FOUND) - add_library(Rizin::librz INTERFACE IMPORTED) - set_target_properties(Rizin::librz PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${Rizin_INCLUDE_DIRS}") - set_target_properties(Rizin::librz PROPERTIES - INTERFACE_LINK_LIBRARIES "${Rizin_LIBRARIES}") - set(Rizin_TARGET Rizin::librz) - endif() -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Rizin REQUIRED_VARS Rizin_TARGET Rizin_LIBRARIES Rizin_INCLUDE_DIRS) diff --git a/dist/CMakeLists.txt b/dist/CMakeLists.txt index 5dec4c46..cf57cc66 100644 --- a/dist/CMakeLists.txt +++ b/dist/CMakeLists.txt @@ -84,9 +84,7 @@ if(APPLE) if (CUTTER_PACKAGE_JSDEC AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) install(CODE " - execute_process(COMMAND \"${CMAKE_CURRENT_SOURCE_DIR}/../scripts/jsdec.sh\" --prefix=\${CMAKE_INSTALL_PREFIX} - \"-Drizin_incdir=\${CMAKE_INSTALL_PREFIX}/include/librz\" - \"-Drizin_libdir=\${CMAKE_INSTALL_PREFIX}/lib\" + execute_process(COMMAND \"${CMAKE_CURRENT_SOURCE_DIR}/../scripts/jsdec.sh\" --pkg-config-path=\${CMAKE_INSTALL_PREFIX}/lib/pkgconfig --prefix=\${CMAKE_INSTALL_PREFIX} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE SCRIPT_RESULT) if (SCRIPT_RESULT) @@ -109,9 +107,9 @@ if(CUTTER_PACKAGE_RZ_GHIDRA) # installed Cutter. ExternalProject_Add(rz-ghidra GIT_REPOSITORY https://github.com/rizinorg/rz-ghidra - GIT_TAG v0.3.0 + #GIT_TAG v0.3.0 #GIT_TAG c7a50a2e7c0a95cd52b167c9ee0fa1805223f08e - #GIT_TAG dev + GIT_TAG dev #GIT_SHALLOW ON # disable this line when using commit hash CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/dist/MacOSSetupBundle.cmake.in b/dist/MacOSSetupBundle.cmake.in index 3666bae7..88bd6fd8 100644 --- a/dist/MacOSSetupBundle.cmake.in +++ b/dist/MacOSSetupBundle.cmake.in @@ -25,7 +25,6 @@ file(COPY "${INFO_PLIST_PATH}" DESTINATION "${BUNDLE_PATH}/Contents") # replace absolute path from build directory in rizin pkgconfig files with relative ones file(GLOB RZ_PCFILES "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig/rz_*.pc") -list(APPEND RZ_PCFILES "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig/librz.pc") foreach (_pcfile ${RZ_PCFILES}) file(READ "${_pcfile}" _text) string(REGEX REPLACE "^prefix=[^\n]*\n" "prefix=\${pcfiledir}/../..\n" _text "${_text}") diff --git a/dist/bundle_jsdec.ps1 b/dist/bundle_jsdec.ps1 index fe3ded97..762d7b11 100644 --- a/dist/bundle_jsdec.ps1 +++ b/dist/bundle_jsdec.ps1 @@ -2,10 +2,10 @@ $dist = $args[0] $python = Split-Path((Get-Command python.exe).Path) if (-not (Test-Path -Path 'jsdec' -PathType Container)) { - git clone https://github.com/rizinorg/jsdec.git --depth 1 --branch v0.3.1 + git clone https://github.com/rizinorg/jsdec.git --depth 1 --branch master } cd jsdec -& meson.exe --buildtype=release -Dc_args=-DDUK_USE_DATE_NOW_WINDOWS -Djsc_folder=".." -Drizin_plugdir=lib\plugins --prefix=$dist --libdir=lib\plugins --datadir=lib\plugins p build +& meson.exe --buildtype=release -Dc_args=-DDUK_USE_DATE_NOW_WINDOWS -Djsc_folder=".." --prefix=$dist p build ninja -C build install $ErrorActionPreference = 'Stop' $pathdll = "$dist\lib\plugins\core_pdd.dll" diff --git a/scripts/jsdec.sh b/scripts/jsdec.sh index 571ecb80..caee0759 100755 --- a/scripts/jsdec.sh +++ b/scripts/jsdec.sh @@ -7,13 +7,13 @@ SCRIPTPATH=$(realpath "$(dirname "${BASH_SOURCE[0]}")") cd "$SCRIPTPATH/.." if [[ ! -d jsdec ]]; then - git clone https://github.com/rizinorg/jsdec.git --depth 1 --branch v0.3.1 + git clone https://github.com/rizinorg/jsdec.git --depth 2 --branch master fi cd jsdec rm -rf build mkdir build && cd build -meson --buildtype=release -Drizin_plugdir=share/rizin/plugins -Djsc_folder="../" --libdir=share/rizin/plugins --datadir=share/rizin/plugins "$@" ../p +meson --buildtype=release -Djsc_folder="../" "$@" ../p ninja ninja install diff --git a/src/common/ColorThemeWorker.cpp b/src/common/ColorThemeWorker.cpp index 34851920..a7ca2bc8 100644 --- a/src/common/ColorThemeWorker.cpp +++ b/src/common/ColorThemeWorker.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "common/Configuration.h" @@ -29,7 +30,7 @@ const QStringList ColorThemeWorker::rizinUnusedOptions = { ColorThemeWorker::ColorThemeWorker(QObject *parent) : QObject(parent) { - char *szThemes = rz_str_home(RZ_HOME_THEMES); + char *szThemes = rz_path_home_prefix(RZ_THEMES); customRzThemesLocationPath = szThemes; rz_mem_free(szThemes); if (!QDir(customRzThemesLocationPath).exists()) { @@ -37,7 +38,7 @@ ColorThemeWorker::ColorThemeWorker(QObject *parent) : QObject(parent) } QDir currDir { - QStringLiteral("%1%2%3").arg(rz_sys_prefix(nullptr)).arg(RZ_SYS_DIR).arg(RZ_THEMES) + QStringLiteral("%1%2%3").arg(rz_path_prefix(nullptr)).arg(RZ_SYS_DIR).arg(RZ_THEMES) }; if (currDir.exists()) { standardRzThemesLocationPath = currDir.absolutePath(); @@ -132,9 +133,9 @@ QJsonDocument ColorThemeWorker::getTheme(const QString &themeName) const if (themeName != curr) { RzCoreLocked core(Core()); - rz_core_load_theme(core, themeName.toUtf8().constData()); + rz_core_theme_load(core, themeName.toUtf8().constData()); theme = Core()->cmdj("ecj").object().toVariantMap(); - rz_core_load_theme(core, curr.toUtf8().constData()); + rz_core_theme_load(core, curr.toUtf8().constData()); } else { theme = Core()->cmdj("ecj").object().toVariantMap(); } diff --git a/src/common/Configuration.cpp b/src/common/Configuration.cpp index 3c309e83..5bb7a7ef 100644 --- a/src/common/Configuration.cpp +++ b/src/common/Configuration.cpp @@ -530,7 +530,7 @@ void Configuration::setColorTheme(const QString &theme) Core()->cmdRaw("ecd"); s.setValue("theme", "default"); } else { - rz_core_load_theme(Core()->core(), theme.toUtf8().constData()); + rz_core_theme_load(Core()->core(), theme.toUtf8().constData()); s.setValue("theme", theme); } diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 92cf4acb..fbcff262 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -187,7 +187,7 @@ void CutterCore::initialize(bool loadPlugins) #if defined(CUTTER_ENABLE_PACKAGING) && defined(Q_OS_WIN) auto prefixBytes = prefix.absolutePath().toUtf8(); - rz_sys_prefix(prefixBytes.constData()); + rz_path_prefix(prefixBytes.constData()); #endif rz_cons_new(); // initialize console @@ -225,7 +225,7 @@ void CutterCore::initialize(bool loadPlugins) setConfig("cfg.plugins", 0); } if (getConfigi("cfg.plugins")) { - rz_core_loadlibs(this->core_, RZ_CORE_LOADLIBS_ALL, nullptr); + rz_core_loadlibs(this->core_, RZ_CORE_LOADLIBS_ALL); } // IMPLICIT rz_bin_iobind (core_->bin, core_->io); @@ -2416,7 +2416,7 @@ void CutterCore::addBreakpoint(const BreakpointDescription &config) RzBreakpointItem *breakpoint = nullptr; int watchpoint_prot = 0; if (config.hw) { - watchpoint_prot = config.permission & ~(RZ_BP_PROT_EXEC); + watchpoint_prot = config.permission & ~(RZ_PERM_X); } auto address = config.addr; @@ -3003,7 +3003,7 @@ QList CutterCore::getAllComments(const QString &filterType) CORE_LOCK(); QList ret; - QJsonArray commentsArray = cmdj("CCj").array(); + QJsonArray commentsArray = cmdj("CClj").array(); for (const QJsonValue &value : commentsArray) { QJsonObject commentObject = value.toObject(); @@ -3153,13 +3153,16 @@ QList CutterCore::getAllSections() section.paddr = sect->paddr; section.size = sect->size; section.perm = rz_str_rwx_i(sect->perm); - HtPP *digests = rz_core_bin_section_digests(core, sect, hashnames); - if (!digests) { - continue; + if (sect->size > 0) { + HtPP *digests = rz_core_bin_create_digests(core, sect->paddr, sect->size, hashnames); + if (!digests) { + continue; + } + const char *entropy = (const char *)ht_pp_find(digests, "entropy", NULL); + section.entropy = rz_str_get(entropy); + ht_pp_free(digests); } - const char *entropy = (const char *)ht_pp_find(digests, "entropy", NULL); - section.entropy = rz_str_get(entropy); - ht_pp_free(digests); + section.entropy = ""; sections << section; } @@ -3834,7 +3837,7 @@ QString CutterCore::listFlagsAsStringAt(RVA addr) QString CutterCore::nearestFlag(RVA offset, RVA *flagOffsetOut) { - auto r = cmdj(QString("fdj @") + QString::number(offset)).object(); + auto r = cmdj(QString("fdj @ ") + QString::number(offset)).object(); QString name = r.value("name").toString(); if (flagOffsetOut) { auto offsetValue = r.value("offset"); diff --git a/src/dialogs/BreakpointsDialog.cpp b/src/dialogs/BreakpointsDialog.cpp index 75c5f8b4..c4c3108a 100644 --- a/src/dialogs/BreakpointsDialog.cpp +++ b/src/dialogs/BreakpointsDialog.cpp @@ -86,9 +86,9 @@ BreakpointsDialog::BreakpointsDialog(const BreakpointDescription &breakpoint, QW ui->breakpointCondition->setEditText(breakpoint.condition); if (breakpoint.hw) { ui->radioHardware->setChecked(true); - ui->hwRead->setChecked(breakpoint.permission & RZ_BP_PROT_READ); - ui->hwWrite->setChecked(breakpoint.permission & RZ_BP_PROT_WRITE); - ui->hwExecute->setChecked(breakpoint.permission & RZ_BP_PROT_EXEC); + ui->hwRead->setChecked(breakpoint.permission & RZ_PERM_R); + ui->hwWrite->setChecked(breakpoint.permission & RZ_PERM_W); + ui->hwExecute->setChecked(breakpoint.permission & RZ_PERM_X); ui->breakpointSize->setCurrentText(QString::number(breakpoint.size)); } else { ui->radioSoftware->setChecked(true); @@ -204,13 +204,13 @@ int BreakpointsDialog::getHwPermissions() { int result = 0; if (ui->hwRead->isChecked()) { - result |= RZ_BP_PROT_READ; + result |= RZ_PERM_R; } if (ui->hwWrite->isChecked()) { - result |= RZ_BP_PROT_WRITE; + result |= RZ_PERM_W; } if (ui->hwExecute->isChecked()) { - result |= RZ_BP_PROT_EXEC; + result |= RZ_PERM_X; } return result; } diff --git a/src/widgets/BreakpointWidget.cpp b/src/widgets/BreakpointWidget.cpp index ceb5636d..967e13a8 100644 --- a/src/widgets/BreakpointWidget.cpp +++ b/src/widgets/BreakpointWidget.cpp @@ -32,13 +32,13 @@ int BreakpointModel::columnCount(const QModelIndex &) const static QString formatHwBreakpoint(int permission) { char data[] = "rwx"; - if ((permission & (RZ_BP_PROT_READ | RZ_BP_PROT_ACCESS)) == 0) { + if ((permission & (RZ_PERM_R | RZ_PERM_RW)) == 0) { data[0] = '-'; } - if ((permission & (RZ_BP_PROT_WRITE | RZ_BP_PROT_ACCESS)) == 0) { + if ((permission & (RZ_PERM_W | RZ_PERM_RW)) == 0) { data[1] = '-'; } - if ((permission & RZ_BP_PROT_EXEC) == 0) { + if ((permission & RZ_PERM_X) == 0) { data[2] = '-'; } return data;