diff --git a/.appveyor.yml b/.appveyor.yml index a5883afc..72633008 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -31,6 +31,7 @@ environment: DEPLOY: false install: + - cmd: if defined QMAKE ( git clone --depth 1 --recurse-submodules https://github.com/radareorg/r2ghidra-dec.git %APPVEYOR_BUILD_FOLDER%/r2ghidra-dec ) - ps: $env:path = ($env:path -split ";").Where({!($_ -like "*Microsoft SQL Server*")}) -join ";" - cmd: C:\msys64\usr\bin\bash -lc "cd $APPVEYOR_BUILD_FOLDER && scripts/fetch_deps.sh" - cmd: set "CUTTER_DEPS_DIR=%APPVEYOR_BUILD_FOLDER%\cutter-deps" @@ -49,11 +50,12 @@ before_build: # Build config build_script: - - cmd: if defined QMAKE ( call prepare_r2.bat && call build.bat CUTTER_APPVEYOR_R2DEC=true CUTTER_ENABLE_CRASH_REPORTS=true CUTTER_ENABLE_PYTHON=true CUTTER_ENABLE_PYTHON_BINDINGS=true CUTTER_DEPS_DIR="%CUTTER_DEPS_DIR%" ) + - cmd: if defined QMAKE ( call prepare_r2.bat && call build.bat CUTTER_APPVEYOR_R2DEC=true CUTTER_R2GHIDRA_STATIC=true R2GHIDRA_SOURCE="%APPVEYOR_BUILD_FOLDER%/r2ghidra-dec" CUTTER_ENABLE_CRASH_REPORTS=true CUTTER_ENABLE_PYTHON=true CUTTER_ENABLE_PYTHON_BINDINGS=true CUTTER_DEPS_DIR="%CUTTER_DEPS_DIR%" ) - cmd: if defined MESON ( python meson.py --release --dist=%ARTIFACT_PATH% --backend=%BACKEND% --python ) after_build: - cmd: if defined QMAKE ( xcopy r2_dist_%ARCH%\bin r2_dist_%ARCH% && set "PATH=%CD%\r2_dist_%ARCH%;%PATH%" && powershell scripts\bundle_r2dec.ps1 "%CD%\%ARTIFACT_PATH%" ) + - cmd: if defined QMAKE ( C:\msys64\usr\bin\bash -lc "export PATH=\"/c/msys64/usr/bin:$PATH\" && cd \"$APPVEYOR_BUILD_FOLDER\" && scripts/appveyor_r2ghidra.sh" ) - cmd: powershell scripts\bundle_openssl.ps1 %ARCH% "%CD%\%ARTIFACT_PATH%" - cmd: powershell scripts\bundle_python.ps1 %ARCH% "%CD%\%ARTIFACT_PATH%" - cmd: xcopy "%CUTTER_DEPS_DIR%\pyside\lib\site-packages" "%ARTIFACT_PATH%\python36\site-packages" /e /i /h diff --git a/.travis.yml b/.travis.yml index 00b749bf..e1d2894c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,29 +14,44 @@ matrix: - name: Linux QMake + Deploy os: linux env: BUILD_SYSTEM=qmake DEPLOY=1 + addons: + apt: + packages: + - ninja-build - name: Linux CMake os: linux env: BUILD_SYSTEM=cmake + addons: + apt: + packages: + - ninja-build + - libgraphviz-dev before_install: - - sudo apt-get update && sudo apt-get install ninja-build libgraphviz-dev # because the apt addon is broken on bionic - pyenv global 3.7.1 - pip install meson - name: macOS QMake + Deploy os: osx - osx_image: xcode10.2 + osx_image: xcode10.3 env: BUILD_SYSTEM=qmake DEPLOY=1 - name: macOS CMake os: osx - osx_image: xcode10.2 + osx_image: xcode10.3 env: BUILD_SYSTEM=cmake - name: Documentation + Deploy os: linux cache: ~ - before_install: sudo apt-get update && sudo apt-get install doxygen python3-sphinx python3-breathe python3-sphinx-rtd-theme libgraphviz-dev # because the apt addon is broken on bionic + addons: + apt: + packages: + - doxygen + - python3-sphinx + - python3-breathe + - python3-sphinx-rtd-theme + - libgraphviz-dev install: ~ before_script: ~ after_success: ~ @@ -160,6 +175,7 @@ after_success: chmod +x Cutter.app/Contents/MacOS/Cutter && mkdir -p Cutter.app/Contents/Resources/r2/share && cp -a /usr/local/share/radare2 Cutter.app/Contents/Resources/r2/share/ && + "$TRAVIS_BUILD_DIR/scripts/r2ghidra.sh" -DCMAKE_INSTALL_PREFIX="`pwd`/Cutter.app/Contents/Resources/r2" -DBUILD_CUTTER_PLUGIN=ON -DCUTTER_INSTALL_PLUGDIR="`pwd`/Cutter.app/Contents/Resources/plugins/native" -DCUTTER_SOURCE_DIR="$TRAVIS_BUILD_DIR" && mkdir image && cp -a Cutter.app image/ && export VOL_NAME="Cutter v${CUTTER_VERSION}" && export DMG_TMP_FILE="Cutter-v$CUTTER_VERSION-x64.macOS-tmp.dmg" && @@ -180,6 +196,7 @@ after_success: mkdir -p appdir/usr/bin/translations && cp ../src/translations/*.qm appdir/usr/bin/translations/ && "$TRAVIS_BUILD_DIR/scripts/appimage_embed_python.sh" appdir && + "$TRAVIS_BUILD_DIR/scripts/r2ghidra.sh" -DCMAKE_INSTALL_PREFIX="`pwd`/appdir/usr" -DBUILD_CUTTER_PLUGIN=ON -DCUTTER_SOURCE_DIR="$TRAVIS_BUILD_DIR" && wget -c "https://github.com/probonopd/linuxdeployqt/releases/download/6/linuxdeployqt-6-x86_64.AppImage" && chmod a+x linuxdeployqt*.AppImage && rm -fv "$TRAVIS_BUILD_DIR/cutter-deps/qt/plugins/imageformats/libqjp2.so" && diff --git a/scripts/appveyor_r2ghidra.sh b/scripts/appveyor_r2ghidra.sh new file mode 100755 index 00000000..af6fd2a8 --- /dev/null +++ b/scripts/appveyor_r2ghidra.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +scripts/r2ghidra.sh \ + -DCMAKE_C_COMPILER=cl \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_PREFIX_PATH="$APPVEYOR_BUILD_FOLDER/r2_dist_$ARCH;$APPVEYOR_BUILD_FOLDER/r2_dist_$ARCH/radare2;$QT64PATH" \ + -DCMAKE_INSTALL_PREFIX="$APPVEYOR_BUILD_FOLDER/$ARTIFACT_PATH/radare2" \ + -DRADARE2_INSTALL_PLUGDIR="$APPVEYOR_BUILD_FOLDER/$ARTIFACT_PATH/radare2/lib/plugins" \ No newline at end of file diff --git a/scripts/r2ghidra.sh b/scripts/r2ghidra.sh new file mode 100755 index 00000000..14a3b12f --- /dev/null +++ b/scripts/r2ghidra.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +SCRIPTPATH=$(realpath "$(dirname "${BASH_SOURCE[0]}")") + +cd "$SCRIPTPATH/.." + +if [[ ! -d r2ghidra-dec ]]; then + git clone --depth 1 --recurse-submodules https://github.com/radareorg/r2ghidra-dec.git || exit 1 +fi +cd r2ghidra-dec || exit 1 + +mkdir build && cd build || exit 1 +cmake -G Ninja "$@" .. || exit 1 +ninja || exit 1 +ninja install || exit 1 + diff --git a/src/Cutter.pro b/src/Cutter.pro index ff08d88c..a233a2d7 100644 --- a/src/Cutter.pro +++ b/src/Cutter.pro @@ -51,6 +51,9 @@ equals(CUTTER_BUNDLE_R2_APPBUNDLE, true) CONFIG += CUTTER_BUNDLE_R2_APPBU !defined(CUTTER_APPVEYOR_R2DEC, var) CUTTER_APPVEYOR_R2DEC=false equals(CUTTER_APPVEYOR_R2DEC, true) CONFIG += CUTTER_APPVEYOR_R2DEC +!defined(CUTTER_R2GHIDRA_STATIC, var) CUTTER_R2GHIDRA_STATIC=false +equals(CUTTER_R2GHIDRA_STATIC, true) CONFIG += CUTTER_R2GHIDRA_STATIC + CUTTER_ENABLE_CRASH_REPORTS { message("Crash report support enabled.") DEFINES += CUTTER_ENABLE_CRASH_REPORTS @@ -240,6 +243,14 @@ CUTTER_APPVEYOR_R2DEC { DEFINES += CUTTER_APPVEYOR_R2DEC } +CUTTER_R2GHIDRA_STATIC { + message("Building with static r2ghidra support") + DEFINES += CUTTER_R2GHIDRA_STATIC + SOURCES += $$R2GHIDRA_SOURCE/cutter-plugin/R2GhidraDecompiler.cpp + HEADERS += $$R2GHIDRA_SOURCE/cutter-plugin/R2GhidraDecompiler.h + INCLUDEPATH += $$R2GHIDRA_SOURCE/cutter-plugin +} + QMAKE_SUBSTITUTES += CutterConfig.h.in SOURCES += \ diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index df6c6371..b4c7299b 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -25,6 +25,10 @@ #include +#if CUTTER_R2GHIDRA_STATIC +#include +#endif + CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc, argv) { // Setup application information @@ -123,6 +127,10 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc Core()->registerDecompiler(new R2DecDecompiler(Core())); } +#if CUTTER_R2GHIDRA_STATIC + Core()->registerDecompiler(new R2GhidraDecompiler(Core())); +#endif + bool analLevelSpecified = false; int analLevel = 0; @@ -187,6 +195,32 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc #ifdef CUTTER_APPVEYOR_R2DEC qputenv("R2DEC_HOME", "radare2\\lib\\plugins\\r2dec-js"); #endif + +#ifdef APPIMAGE + { + auto sleighHome = QDir(QCoreApplication::applicationDirPath()); // appdir/bin + sleighHome.cdUp(); // appdir + sleighHome.cd("share/radare2/plugins/r2ghidra_sleigh"); // appdir/share/radare2/plugins/r2ghidra_sleigh + Core()->setConfig("r2ghidra.sleighhome", sleighHome.absolutePath()); + } +#endif + +#ifdef Q_OS_MACOS + { + auto sleighHome = QDir(QCoreApplication::applicationDirPath()); // Contents/MacOS + sleighHome.cdUp(); // Contents + sleighHome.cd("Resources/r2/share/radare2/plugins/r2ghidra_sleigh"); // Contents/Resources/r2/share/radare2/plugins/r2ghidra_sleigh + Core()->setConfig("r2ghidra.sleighhome", sleighHome.absolutePath()); + } +#endif + +#ifdef Q_OS_WIN + { + auto sleighHome = QDir(QCoreApplication::applicationDirPath()); + sleighHome.cd("radare2/lib/plugins/r2ghidra_sleigh"); + Core()->setConfig("r2ghidra.sleighhome", sleighHome.absolutePath()); + } +#endif } CutterApplication::~CutterApplication() diff --git a/src/cmake/FindRadare2.cmake b/src/cmake/FindRadare2.cmake index e543ef9b..4e73a73e 100644 --- a/src/cmake/FindRadare2.cmake +++ b/src/cmake/FindRadare2.cmake @@ -66,7 +66,7 @@ if(WIN32) add_library(Radare2::libr UNKNOWN IMPORTED) set_target_properties(Radare2::libr PROPERTIES - IMPORTED_LOCATION "${Radare2_CORE_LIBRARY}" + IMPORTED_LOCATION "${Radare2_LIBRARY_core}" IMPORTED_LINK_INTERFACE_LIBRARIES "${Radare2_LIBRARIES}" INTERFACE_LINK_DIRECTORIES "${Radare2_LIBRARY_DIRS}" INTERFACE_INCLUDE_DIRECTORIES "${Radare2_INCLUDE_DIRS}") diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 37a0ac36..362f4f2a 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -175,6 +175,14 @@ void CutterCore::initialize() qInfo() << "Setting r2 prefix =" << prefix.absolutePath() << " for macOS Application Bundle."; #endif setConfig("dir.prefix", prefix.absolutePath()); + + auto pluginsDir = prefix; + if (pluginsDir.cd("share/radare2/plugins")) { + qInfo() << "Setting r2 plugins dir =" << pluginsDir.absolutePath(); + setConfig("dir.plugins", pluginsDir.absolutePath()); + } else { + qInfo() << "r2 plugins dir =" << pluginsDir.absolutePath() << "does not exist!"; + } #endif r_core_loadlibs(this->core_, R_CORE_LOADLIBS_ALL, NULL); diff --git a/src/plugins/PluginManager.cpp b/src/plugins/PluginManager.cpp index 6ccf8a79..ce1836db 100644 --- a/src/plugins/PluginManager.cpp +++ b/src/plugins/PluginManager.cpp @@ -57,10 +57,32 @@ void PluginManager::loadPlugins() loadPluginsFromDir(QDir(pluginsDirStr)); #ifdef Q_OS_WIN - QDir appDir; - appDir.mkdir("plugins"); - if (appDir.cd("plugins")) { - loadPluginsFromDir(appDir); + { + QDir appDir; + appDir.mkdir("plugins"); + if (appDir.cd("plugins")) { + loadPluginsFromDir(appDir); + } + } +#endif + +#ifdef APPIMAGE + { + auto plugdir = QDir(QCoreApplication::applicationDirPath()); // appdir/bin + plugdir.cdUp(); // appdir + if (plugdir.cd("share/RadareOrg/Cutter/plugins")) { // appdir/share/RadareOrg/Cutter/plugins + loadPluginsFromDir(plugdir); + } + } +#endif + +#ifdef Q_OS_MACOS + { + auto plugdir = QDir(QCoreApplication::applicationDirPath()); // Contents/MacOS + plugdir.cdUp(); // Contents + if (plugdir.cd("Resources/plugins")) { // Contents/Resources/plugins + loadPluginsFromDir(plugdir); + } } #endif }