From 90608117c999150e14a2ff41213eda271b7e6787 Mon Sep 17 00:00:00 2001 From: Giovanni <561184+wargio@users.noreply.github.com> Date: Wed, 8 Jun 2022 01:18:43 +0200 Subject: [PATCH] Yara plugin + fix linuxdeployqt plugins (#2924) --- .github/workflows/ccpp.yml | 9 +++-- CMakeLists.txt | 9 +++++ dist/CMakeLists.txt | 64 +++++++++++++++++++++++++++------- dist/MacOSSetupBundle.cmake.in | 3 ++ dist/bundle_rz_libswift.ps1 | 2 +- dist/bundle_rz_libyara.ps1 | 26 ++++++++++++++ rizin | 2 +- scripts/rz-libyara.sh | 25 +++++++++++++ src/CutterApplication.cpp | 7 +--- src/plugins/PluginManager.cpp | 2 ++ 10 files changed, 123 insertions(+), 26 deletions(-) create mode 100644 dist/bundle_rz_libyara.ps1 create mode 100755 scripts/rz-libyara.sh diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index a1aec8cb..a1c8e0c5 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -124,6 +124,7 @@ jobs: -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON \ -DCUTTER_PACKAGE_RZ_GHIDRA=ON \ -DCUTTER_PACKAGE_RZ_LIBSWIFT=ON \ + -DCUTTER_PACKAGE_RZ_LIBYARA=ON \ -DCMAKE_INSTALL_PREFIX=appdir/usr \ -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \ .. @@ -142,20 +143,16 @@ jobs: ninja install "../scripts/appimage_embed_python.sh" appdir APP_PREFIX=`pwd`/appdir/usr - # export LD_LIBRARY_PATH=${APP_PREFIX}/lib:$Shiboken2_ROOT/lib + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$APP_PREFIX/lib/rizin/plugins" export PATH=$PATH:${APP_PREFIX}/bin - "../scripts/jsdec.sh" --prefix=`pwd`/appdir/usr wget -c "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage" chmod a+x linuxdeployqt*.AppImage rm -fv "../cutter-deps/qt/plugins/imageformats/libqjp2.so" - # ./linuxdeployqt*.AppImage ./appdir/usr/share/applications/*.desktop -executable=./appdir/usr/bin/python3 -bundle-non-qt-libs -no-strip -exclude-libs=libnss3.so,libnssutil3.so,libqjp2.so -ignore-glob=usr/lib/python3.9/**/* -verbose=2 - # exclude librzghidra cutter plugin because cutter and rz plugin is loaded manuallly as they are plugins linuxdeployqt doesn't know this ./linuxdeployqt*.AppImage ./appdir/usr/share/applications/*.desktop \ -executable=./appdir/usr/bin/python3 \ -appimage \ -no-strip -exclude-libs=libnss3.so,libnssutil3.so,libqjp2.so \ -ignore-glob=usr/lib/python3.9/**/* \ - -ignore-glob=usr/share/rizin/cutter/plugins/native/librz_ghidra_cutter.so \ -verbose=2 find ./appdir -executable -type f -exec ldd {} \; | grep " => /usr" | cut -d " " -f 2-3 | sort | uniq export APPIMAGE_FILE="Cutter-${PACKAGE_ID}-x64.Linux.AppImage" @@ -192,6 +189,7 @@ jobs: -DCUTTER_PACKAGE_RZ_GHIDRA=ON \ -DCUTTER_PACKAGE_JSDEC=ON \ -DCUTTER_PACKAGE_RZ_LIBSWIFT=ON \ + -DCUTTER_PACKAGE_RZ_LIBYARA=ON \ -DCPACK_PACKAGE_FILE_NAME="$PACKAGE_NAME" \ -DCMAKE_FRAMEWORK_PATH="$BREAKPAD_FRAMEWORK_DIR" \ -DCPACK_BUNDLE_APPLE_CERT_APP="-" \ @@ -231,6 +229,7 @@ jobs: -DCUTTER_PACKAGE_DEPENDENCIES=ON ^ -DCUTTER_PACKAGE_RZ_GHIDRA=ON ^ -DCUTTER_PACKAGE_RZ_LIBSWIFT=ON ^ + -DCUTTER_PACKAGE_RZ_LIBYARA=ON ^ -DCUTTER_PACKAGE_JSDEC=ON ^ -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON ^ -DCUTTER_ENABLE_CRASH_REPORTS=ON ^ diff --git a/CMakeLists.txt b/CMakeLists.txt index 9498c796..034478ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ option(CUTTER_ENABLE_SIGDB "Downloads and installs sigdb (only available when CU 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) +option(CUTTER_PACKAGE_RZ_LIBYARA, "Compile and install rz-libyara during the install step." OFF) option(CUTTER_PACKAGE_JSDEC "Compile and install jsdec during install step." OFF) OPTION(CUTTER_QT6 "Use QT6" OFF) @@ -132,6 +133,14 @@ message(STATUS "- Python Bindings: ${CUTTER_ENABLE_PYTHON_BINDINGS}") message(STATUS "- Crash Handling: ${CUTTER_ENABLE_CRASH_REPORTS}") message(STATUS "- KSyntaxHighlighting: ${KSYNTAXHIGHLIGHTING_STATUS}") message(STATUS "- Graphviz: ${CUTTER_ENABLE_GRAPHVIZ}") +message(STATUS "- Downloads dependencies: ${CUTTER_ENABLE_DEPENDENCY_DOWNLOADS}") +message(STATUS "- Enable Packaging: ${CUTTER_ENABLE_PACKAGING}") +message(STATUS "- Package Dependencies: ${CUTTER_PACKAGE_DEPENDENCIES}") +message(STATUS "- Package RzGhidra: ${CUTTER_PACKAGE_RZ_GHIDRA}") +message(STATUS "- Package RzLibSwift: ${CUTTER_PACKAGE_RZ_LIBSWIFT}") +message(STATUS "- Package RzLibYara: ${CUTTER_PACKAGE_RZ_LIBYARA}") +message(STATUS "- Package JSDec: ${CUTTER_PACKAGE_JSDEC}") +message(STATUS "- QT6: ${CUTTER_QT6}") message(STATUS "") add_subdirectory(src) diff --git a/dist/CMakeLists.txt b/dist/CMakeLists.txt index fa4b80e5..ee962d2e 100644 --- a/dist/CMakeLists.txt +++ b/dist/CMakeLists.txt @@ -28,7 +28,7 @@ if(WIN32) WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE SCRIPT_RESULT) if (SCRIPT_RESULT) - message(FATAL_ERROR \"Failed to package jsdec\") + message(FATAL_ERROR \"Failed to package jsdec (returned \${SCRIPT_RESULT})\") endif() ") endif() @@ -40,7 +40,22 @@ if(WIN32) WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE SCRIPT_RESULT) if (SCRIPT_RESULT) - message(FATAL_ERROR \"Failed to package rz-libswift\") + message(FATAL_ERROR \"Failed to package rz-libswift (returned \${SCRIPT_RESULT})\") + endif() + ") + endif() + if (CUTTER_PACKAGE_RZ_LIBYARA AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) + install(CODE " + set(ENV{RZ_PREFIX} \"\${CMAKE_INSTALL_PREFIX}\") + set(ENV{PATH} \"\${CMAKE_INSTALL_PREFIX};\$ENV{PATH}\") + execute_process(COMMAND powershell + \"${CMAKE_CURRENT_SOURCE_DIR}/bundle_rz_libyara.ps1\" + \"\${CMAKE_INSTALL_PREFIX}\" + \"-DCUTTER_INSTALL_PLUGDIR=plugins/native\" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE SCRIPT_RESULT) + if (SCRIPT_RESULT) + message(FATAL_ERROR \"Failed to package rz_libyara (returned \${SCRIPT_RESULT})\") endif() ") endif() @@ -93,29 +108,52 @@ if(APPLE) get_filename_component(QT_PREFIX "${MACDEPLOYQT_PATH}/../.." ABSOLUTE) list(APPEND RZ_GHIDRA_PREFIX_PATH "${QT_PREFIX}") set(RIZIN_INSTALL_PLUGDIR "lib/rizin/plugins") # escaped backslash on purpose, should be evaluated later +endif() - if (CUTTER_PACKAGE_JSDEC AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) +################################################ +# macOS + Linux +################################################ + +if(CUTTER_ENABLE_DEPENDENCY_DOWNLOADS AND (NOT WIN32)) + if (CUTTER_PACKAGE_JSDEC) install(CODE " - execute_process(COMMAND \"${CMAKE_CURRENT_SOURCE_DIR}/../scripts/jsdec.sh\" --pkg-config-path=\${CMAKE_INSTALL_PREFIX}/lib/pkgconfig --prefix=\${CMAKE_INSTALL_PREFIX} + 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) - message(FATAL_ERROR \"Failed to package jsdec\") + message(FATAL_ERROR \"Failed to package jsdec (returned \${SCRIPT_RESULT})\") endif() ") endif() - - if (CUTTER_PACKAGE_RZ_LIBSWIFT AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) + if (CUTTER_PACKAGE_RZ_LIBSWIFT) install(CODE " - execute_process(COMMAND \"${CMAKE_CURRENT_SOURCE_DIR}/../scripts/rz-libswift.sh\" --pkg-config-path=\${CMAKE_INSTALL_PREFIX}/lib/pkgconfig --prefix=\${CMAKE_INSTALL_PREFIX} + execute_process(COMMAND \"${CMAKE_CURRENT_SOURCE_DIR}/../scripts/rz-libswift.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) - message(FATAL_ERROR \"Failed to package rz-libswift\") + message(FATAL_ERROR \"Failed to package rz-libswift (returned \${SCRIPT_RESULT})\") + endif() + ") + endif() + if (CUTTER_PACKAGE_RZ_LIBYARA) + if(APPLE) + set (YARA_PLUGIN_OPTIONS "-DCUTTER_INSTALL_PLUGDIR=plugins/native") + else() + set (YARA_PLUGIN_OPTIONS "") + endif() + install(CODE " + execute_process(COMMAND + \"${CMAKE_CURRENT_SOURCE_DIR}/../scripts/rz-libyara.sh\" + \"\${CMAKE_INSTALL_PREFIX}\" \"${YARA_PLUGIN_OPTIONS}\" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE SCRIPT_RESULT) + if (SCRIPT_RESULT) + message(FATAL_ERROR \"Failed to package rz-libyara (returned \${SCRIPT_RESULT})\") endif() ") endif() - endif() ################################################ @@ -144,7 +182,7 @@ if(CUTTER_PACKAGE_RZ_GHIDRA) \"-DRIZIN_INSTALL_PLUGDIR=\${CMAKE_INSTALL_PREFIX}/${RIZIN_INSTALL_PLUGDIR}\" -DCUTTER_INSTALL_PLUGDIR=plugins/native") else() - set (GHIDRA_OPTIONS "") + set (GHIDRA_OPTIONS "-DCUTTER_INSTALL_PLUGDIR=\${CMAKE_INSTALL_PREFIX}/share/rizin/cutter/plugins/native") endif() install(CODE " execute_process( @@ -161,14 +199,14 @@ if(CUTTER_PACKAGE_RZ_GHIDRA) -G Ninja ) if (SCRIPT_RESULT) - message(FATAL_ERROR \"Failed to configure rz-ghidra\") + message(FATAL_ERROR \"Failed to configure rz-ghidra (returned \${SCRIPT_RESULT})\") endif() execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/rz-ghidra-prefix/src/rz-ghidra-build RESULT_VARIABLE SCRIPT_RESULT COMMAND \${CMAKE_COMMAND} --build . --target install ) if (SCRIPT_RESULT) - message(FATAL_ERROR \"Failed to install rz-ghidra plugin\") + message(FATAL_ERROR \"Failed to install rz-ghidra plugin (returned \${SCRIPT_RESULT})\") endif() ") endif() diff --git a/dist/MacOSSetupBundle.cmake.in b/dist/MacOSSetupBundle.cmake.in index 88bd6fd8..ff8bdb35 100644 --- a/dist/MacOSSetupBundle.cmake.in +++ b/dist/MacOSSetupBundle.cmake.in @@ -60,6 +60,9 @@ run_or_die(COMMAND install_name_tool run_or_die(COMMAND install_name_tool -add_rpath "@executable_path/../Resources/lib" "${EXECUTABLE_DIR}/cutter") +run_or_die(COMMAND install_name_tool + -add_rpath "@executable_path/../Resources/lib/rizin/plugins" + "${EXECUTABLE_DIR}/cutter") set(MACDEPLOYQT_COMMAND "${MACDEPLOYQT_PATH}" "${BUNDLE_PATH}" "-verbose=2" "-libpath=${CMAKE_INSTALL_PREFIX}/lib") message("Running macdeployqt \"${MACDEPLOYQT_COMMAND}\"") diff --git a/dist/bundle_rz_libswift.ps1 b/dist/bundle_rz_libswift.ps1 index 12928c93..9fec607c 100644 --- a/dist/bundle_rz_libswift.ps1 +++ b/dist/bundle_rz_libswift.ps1 @@ -13,4 +13,4 @@ if(![System.IO.File]::Exists($pathdll)) { ls "$dist/lib/plugins/" throw (New-Object System.IO.FileNotFoundException("File not found: $pathdll", $pathdll)) } -Remove-Item -Recurse -Force $dist/lib/plugins/libswift.lib +Remove-Item -Recurse -Force $dist/lib/plugins/swift.lib diff --git a/dist/bundle_rz_libyara.ps1 b/dist/bundle_rz_libyara.ps1 new file mode 100644 index 00000000..c3309b94 --- /dev/null +++ b/dist/bundle_rz_libyara.ps1 @@ -0,0 +1,26 @@ +$dist = $args[0] +$cmake_opts = $args[1] +$python = Split-Path((Get-Command python.exe).Path) + +if (-not (Test-Path -Path 'rz_libyara' -PathType Container)) { + git clone https://github.com/rizinorg/rz-libyara.git --depth 1 rz_libyara + git -C rz_libyara submodule init + git -C rz_libyara submodule update +} +cd rz_libyara +& meson.exe --buildtype=release --prefix=$dist build +ninja -C build install +$pathdll = "$dist/lib/plugins/rz_yara.dll" +if(![System.IO.File]::Exists($pathdll)) { + type build/meson-logs/meson-log.txt + ls "$dist/lib/plugins/" + throw (New-Object System.IO.FileNotFoundException("File not found: $pathdll", $pathdll)) +} +Remove-Item -Recurse -Force $dist/lib/plugins/rz_yara.lib + +cd cutter-plugin +mkdir build +cd build +cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DRIZIN_INSTALL_PLUGDIR="../build" -DCMAKE_INSTALL_PREFIX="$dist" $cmake_opts .. +ninja +ninja install diff --git a/rizin b/rizin index 7665d0f3..1a0ce1fa 160000 --- a/rizin +++ b/rizin @@ -1 +1 @@ -Subproject commit 7665d0f30ef7771b305329502d94842ec4a97a62 +Subproject commit 1a0ce1faa3b552c4f1756d377ffa5973a9a358bf diff --git a/scripts/rz-libyara.sh b/scripts/rz-libyara.sh new file mode 100755 index 00000000..f316f2c5 --- /dev/null +++ b/scripts/rz-libyara.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +SCRIPTPATH=$(realpath "$(dirname "${BASH_SOURCE[0]}")") +INSTALL_PREFIX="$1" +EXTRA_CMAKE_OPTS="$2" + +cd "$SCRIPTPATH/.." + +if [[ ! -d rz_libyara ]]; then + git clone https://github.com/rizinorg/rz-libyara.git --depth 1 rz_libyara + git -C rz_libyara submodule init + git -C rz_libyara submodule update +fi + +cd rz_libyara + +meson --buildtype=release --pkg-config-path="$INSTALL_PREFIX/lib/pkgconfig" --prefix="$INSTALL_PREFIX" build +ninja -C build install + +cd cutter-plugin +mkdir build && cd build +cmake -G Ninja -DRIZIN_INSTALL_PLUGDIR="../build" -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" $EXTRA_CMAKE_OPTS .. +ninja +ninja install diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index bfd7679a..9d4d4dff 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -163,13 +163,8 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc appdir.cdUp(); // appdir auto sleighHome = appdir; - sleighHome.cd( - "share/rizin/plugins/rz_ghidra_sleigh"); // appdir/share/rizin/plugins/rz_ghidra_sleigh + sleighHome.cd("lib/rizin/plugins/rz_ghidra_sleigh/"); // appdir/lib/rizin/plugins/rz_ghidra_sleigh/ Core()->setConfig("ghidra.sleighhome", sleighHome.absolutePath()); - - auto jsdecHome = appdir; - jsdecHome.cd("share/rizin/plugins/jsdec"); // appdir/share/rizin/plugins/jsdec - qputenv("JSDEC_HOME", jsdecHome.absolutePath().toLocal8Bit()); } #endif diff --git a/src/plugins/PluginManager.cpp b/src/plugins/PluginManager.cpp index 28cffb44..ac9c6104 100644 --- a/src/plugins/PluginManager.cpp +++ b/src/plugins/PluginManager.cpp @@ -65,6 +65,7 @@ void PluginManager::loadPluginsFromDir(const QDir &pluginsDir, bool writable) nativePluginsDir.mkdir("native"); } if (nativePluginsDir.cd("native")) { + qInfo() << "Native plugins are loaded from" << nativePluginsDir.absolutePath(); loadNativePlugins(nativePluginsDir); } @@ -74,6 +75,7 @@ void PluginManager::loadPluginsFromDir(const QDir &pluginsDir, bool writable) pythonPluginsDir.mkdir("python"); } if (pythonPluginsDir.cd("python")) { + qInfo() << "Python plugins are loaded from" << pythonPluginsDir.absolutePath(); loadPythonPlugins(pythonPluginsDir.absolutePath()); } #endif