From 247ab94b71b271ca8dfa76ff66a78374a37e9951 Mon Sep 17 00:00:00 2001 From: Giovanni <561184+wargio@users.noreply.github.com> Date: Mon, 6 Jun 2022 11:27:13 +0200 Subject: [PATCH] Download and install sigdb option (#2949) * Download and install sigdb option and disable swift demangler when libswift is installed * Remove dir.prefix and use rz_core_analysis_sigdb_list for sigdb * Use a different color for flirts * Updated to rizin dev * Use rz_path_set_prefix to set the prefix path on OSX bundle --- .github/workflows/ccpp.yml | 3 ++ CMakeLists.txt | 4 ++ cmake/BundledRizin.cmake | 8 ++++ dist/CMakeLists.txt | 8 +--- rizin | 2 +- src/CutterApplication.cpp | 4 +- src/common/ColorThemeWorker.cpp | 4 +- src/common/Configuration.cpp | 2 + src/core/Cutter.cpp | 73 ++++++++------------------------- src/widgets/FunctionsWidget.cpp | 2 + 10 files changed, 45 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 64a3f7f6..a1aec8cb 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -120,6 +120,7 @@ jobs: -DCUTTER_USE_BUNDLED_RIZIN=ON \ -DCUTTER_APPIMAGE_BUILD=ON \ -DCUTTER_ENABLE_PACKAGING=ON \ + -DCUTTER_ENABLE_SIGDB=ON \ -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON \ -DCUTTER_PACKAGE_RZ_GHIDRA=ON \ -DCUTTER_PACKAGE_RZ_LIBSWIFT=ON \ @@ -185,6 +186,7 @@ jobs: -DCUTTER_ENABLE_CRASH_REPORTS=ON \ -DCUTTER_USE_BUNDLED_RIZIN=ON \ -DCUTTER_ENABLE_PACKAGING=ON \ + -DCUTTER_ENABLE_SIGDB=ON \ -DCUTTER_PACKAGE_DEPENDENCIES=ON \ -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON \ -DCUTTER_PACKAGE_RZ_GHIDRA=ON \ @@ -225,6 +227,7 @@ jobs: -DCUTTER_ENABLE_PYTHON=ON ^ -DCUTTER_ENABLE_PYTHON_BINDINGS=ON ^ -DCUTTER_ENABLE_PACKAGING=ON ^ + -DCUTTER_ENABLE_SIGDB=ON ^ -DCUTTER_PACKAGE_DEPENDENCIES=ON ^ -DCUTTER_PACKAGE_RZ_GHIDRA=ON ^ -DCUTTER_PACKAGE_RZ_LIBSWIFT=ON ^ diff --git a/CMakeLists.txt b/CMakeLists.txt index 991368ec..9498c796 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ set(SHIBOKEN_EXTRA_OPTIONS "" CACHE STRING "Extra options for shiboken generator set(CUTTER_EXTRA_PLUGIN_DIRS "" CACHE STRING "List of addition plugin locations") option(CUTTER_ENABLE_DEPENDENCY_DOWNLOADS "Enable downloading of dependencies. Setting to OFF doesn't affect any downloads done by rizin build." OFF) option(CUTTER_ENABLE_PACKAGING "Enable building platform-specific packages for distributing" OFF) +option(CUTTER_ENABLE_SIGDB "Downloads and installs sigdb (only available when CUTTER_USE_BUNDLED_RIZIN=ON)." OFF) option(CUTTER_PACKAGE_DEPENDENCIES "During install step include the third party dependencies." OFF) option(CUTTER_PACKAGE_RZ_GHIDRA "Compile and install rz-ghidra during install step." OFF) option(CUTTER_PACKAGE_RZ_LIBSWIFT, "Compile and install rz-libswift demangler during the install step." OFF) @@ -123,6 +124,9 @@ message(STATUS "") message(STATUS "Building Cutter version ${CUTTER_VERSION_FULL}") message(STATUS "Options:") message(STATUS "- Bundled rizin: ${CUTTER_USE_BUNDLED_RIZIN}") +if(CUTTER_USE_BUNDLED_RIZIN) + message(STATUS "- Bundled sigdb: ${CUTTER_ENABLE_SIGDB}") +endif() message(STATUS "- Python: ${CUTTER_ENABLE_PYTHON}") message(STATUS "- Python Bindings: ${CUTTER_ENABLE_PYTHON_BINDINGS}") message(STATUS "- Crash Handling: ${CUTTER_ENABLE_CRASH_REPORTS}") diff --git a/cmake/BundledRizin.cmake b/cmake/BundledRizin.cmake index 83e4c128..7955c279 100644 --- a/cmake/BundledRizin.cmake +++ b/cmake/BundledRizin.cmake @@ -18,6 +18,14 @@ if (CUTTER_ENABLE_PACKAGING) list(APPEND MESON_OPTIONS "-Dportable=true") endif() +if (CUTTER_ENABLE_SIGDB) + list(APPEND MESON_OPTIONS "-Dinstall_sigdb=true") +endif() + +if (CUTTER_PACKAGE_RZ_LIBSWIFT AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) + list(APPEND MESON_OPTIONS "-Duse_swift_demangler=false") +endif() + find_program(MESON meson) if(NOT MESON) message(FATAL_ERROR "Failed to find meson, which is required to build bundled rizin") diff --git a/dist/CMakeLists.txt b/dist/CMakeLists.txt index 6ce64463..fa4b80e5 100644 --- a/dist/CMakeLists.txt +++ b/dist/CMakeLists.txt @@ -92,7 +92,7 @@ if(APPLE) get_filename_component(QT_PREFIX "${MACDEPLOYQT_PATH}/../.." ABSOLUTE) list(APPEND RZ_GHIDRA_PREFIX_PATH "${QT_PREFIX}") - set(RIZIN_INSTALL_PLUGDIR "share/rizin/plugins") # escaped backslash on purpose, should be evaluated later + set(RIZIN_INSTALL_PLUGDIR "lib/rizin/plugins") # escaped backslash on purpose, should be evaluated later if (CUTTER_PACKAGE_JSDEC AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) install(CODE " @@ -139,11 +139,7 @@ if(CUTTER_PACKAGE_RZ_GHIDRA) INSTALL_COMMAND "" ) endif() - if (WIN32) - set (GHIDRA_OPTIONS " - \"-DRIZIN_INSTALL_PLUGDIR=\${CMAKE_INSTALL_PREFIX}/${RIZIN_INSTALL_PLUGDIR}\" - -DCUTTER_INSTALL_PLUGDIR=plugins/native") - elseif (APPLE) + if (WIN32 OR APPLE) set (GHIDRA_OPTIONS " \"-DRIZIN_INSTALL_PLUGDIR=\${CMAKE_INSTALL_PREFIX}/${RIZIN_INSTALL_PLUGDIR}\" -DCUTTER_INSTALL_PLUGDIR=plugins/native") diff --git a/rizin b/rizin index 0950e823..7665d0f3 160000 --- a/rizin +++ b/rizin @@ -1 +1 @@ -Subproject commit 0950e823a4502677cbf77cfd0266e8de64875fc0 +Subproject commit 7665d0f30ef7771b305329502d94842ec4a97a62 diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index 2dccd156..bfd7679a 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -177,11 +177,11 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc { auto rzprefix = QDir(QCoreApplication::applicationDirPath()); // Contents/MacOS rzprefix.cdUp(); // Contents - rzprefix.cd("Resources"); // Contents/Resources/rz + rzprefix.cd("Resources"); // Contents/Resources/ auto sleighHome = rzprefix; sleighHome.cd( - "share/rizin/plugins/rz_ghidra_sleigh"); // Contents/Resources/rz/share/rizin/plugins/rz_ghidra_sleigh + "lib/rizin/plugins/rz_ghidra_sleigh"); // Contents/Resources/lib/rizin/plugins/rz_ghidra_sleigh Core()->setConfig("ghidra.sleighhome", sleighHome.absolutePath()); } #endif diff --git a/src/common/ColorThemeWorker.cpp b/src/common/ColorThemeWorker.cpp index c4abfd5c..a9e592ba 100644 --- a/src/common/ColorThemeWorker.cpp +++ b/src/common/ColorThemeWorker.cpp @@ -37,7 +37,8 @@ ColorThemeWorker::ColorThemeWorker(QObject *parent) : QObject(parent) QDir().mkpath(customRzThemesLocationPath); } - QDir currDir { QStringLiteral("%1%2%3").arg(rz_path_prefix(nullptr), RZ_SYS_DIR, RZ_THEMES) }; + char *theme_dir = rz_path_prefix(RZ_THEMES); + QDir currDir { theme_dir }; if (currDir.exists()) { standardRzThemesLocationPath = currDir.absolutePath(); } else { @@ -46,6 +47,7 @@ ColorThemeWorker::ColorThemeWorker(QObject *parent) : QObject(parent) "Most likely, Rizin is not properly installed.") .arg(currDir.path())); } + free(theme_dir); } QColor ColorThemeWorker::mergeColors(const QColor &upper, const QColor &lower) const diff --git a/src/common/Configuration.cpp b/src/common/Configuration.cpp index 5239ad6b..25d5907a 100644 --- a/src/common/Configuration.cpp +++ b/src/common/Configuration.cpp @@ -46,6 +46,8 @@ const QHash> Configuration::cutterOptionColor { { DarkFlag, QColor(0x9b, 0x9b, 0x9b) }, { LightFlag, QColor(0x9b, 0x9b, 0x9b) } } }, { "gui.main", { { DarkFlag, QColor(0x21, 0xd8, 0x93) }, { LightFlag, QColor(0x00, 0x80, 0x00) } } }, + { "gui.flirt", + { { DarkFlag, QColor(0xd8, 0xbb, 0x21) }, { LightFlag, QColor(0xf1, 0xc4, 0x0f) } } }, { "gui.item_unsafe", { { DarkFlag, QColor(0xff, 0x81, 0x7b) }, { LightFlag, QColor(0xff, 0x81, 0x7b) } } }, { "gui.navbar.seek", diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 0f31eddd..161916cd 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -188,11 +188,13 @@ CutterCore *CutterCore::instance() void CutterCore::initialize(bool loadPlugins) { - auto prefix = QDir(QCoreApplication::applicationDirPath()); - -#if defined(CUTTER_ENABLE_PACKAGING) && defined(Q_OS_WIN) - auto prefixBytes = prefix.absolutePath().toUtf8(); - rz_path_prefix(prefixBytes.constData()); +#if defined(MACOS_RZ_BUNDLED) + auto app_path = QDir(QCoreApplication::applicationDirPath()); + app_path.cdUp(); + app_path.cd("Resources"); + qInfo() << "Setting Rizin prefix =" << app_path.absolutePath() + << " for macOS Application Bundle."; + rz_path_set_prefix(app_path.absolutePath().toUtf8().constData()); #endif rz_cons_new(); // initialize console @@ -203,34 +205,11 @@ void CutterCore::initialize(bool loadPlugins) rz_event_hook(core_->analysis->ev, RZ_EVENT_ALL, cutterREventCallback, this); -#if defined(APPIMAGE) || defined(MACOS_RZ_BUNDLED) -# ifdef APPIMAGE - // Executable is in appdir/bin - prefix.cdUp(); - qInfo() << "Setting Rizin prefix =" << prefix.absolutePath() << " for AppImage."; -# else // MACOS_RZ_BUNDLED - // Executable is in Contents/MacOS, prefix is Contents/Resources/rz - prefix.cdUp(); - prefix.cd("Resources"); - qInfo() << "Setting Rizin prefix =" << prefix.absolutePath() - << " for macOS Application Bundle."; - setConfig("dir.prefix", prefix.absolutePath()); -# endif - - auto pluginsDir = prefix; - if (pluginsDir.cd("share/rizin/plugins")) { - qInfo() << "Setting Rizin plugins dir =" << pluginsDir.absolutePath(); - setConfig("dir.plugins", pluginsDir.absolutePath()); - } else { - qInfo() << "Rizin plugins dir under" << pluginsDir.absolutePath() << "does not exist!"; - } -#endif - - if (!loadPlugins) { - setConfig("cfg.plugins", 0); - } - if (getConfigi("cfg.plugins")) { + if (loadPlugins) { + setConfig("cfg.plugins", true); rz_core_loadlibs(this->core_, RZ_CORE_LOADLIBS_ALL); + } else { + setConfig("cfg.plugins", false); } // IMPLICIT rz_bin_iobind (core_->bin, core_->io); @@ -3166,10 +3145,16 @@ QList CutterCore::getAllHeaders() return ret; } -static void sigdb_insert_element_into_qlist(RzList *list, QList &sigdb) +QList CutterCore::getSignaturesDB() { + CORE_LOCK(); + void *ptr = NULL; RzListIter *iter = NULL; + QList sigdb; + + RzList *list = rz_core_analysis_sigdb_list(core, true); + rz_list_foreach(list, iter, ptr) { RzSigDBEntry *sig = static_cast(ptr); @@ -3185,28 +3170,6 @@ static void sigdb_insert_element_into_qlist(RzList *list, QList CutterCore::getSignaturesDB() -{ - CORE_LOCK(); - QList sigdb; - RzList *list = nullptr; - - char *system_sigdb = rz_path_system(RZ_SIGDB); - if (RZ_STR_ISNOTEMPTY(system_sigdb) && rz_file_is_directory(system_sigdb)) { - list = rz_sign_sigdb_load_database(system_sigdb, true); - sigdb_insert_element_into_qlist(list, sigdb); - } - free(system_sigdb); - - const char *sigdb_path = rz_config_get(core->config, "flirt.sigdb.path"); - if (RZ_STR_ISEMPTY(sigdb_path)) { - return sigdb; - } - - list = rz_sign_sigdb_load_database(sigdb_path, true); - sigdb_insert_element_into_qlist(list, sigdb); return sigdb; } diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index ab92ecd9..6324467b 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -274,6 +274,8 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const return QVariant(ConfigColor("gui.imports")); } else if (functionIsMain(function.offset)) { return QVariant(ConfigColor("gui.main")); + } else if (function.name.startsWith("flirt.")) { + return QVariant(ConfigColor("gui.flirt")); } return QVariant(this->property("color"));