Bundle r2ghidra-dec

This commit is contained in:
Florian Märkl 2019-08-30 13:41:14 +02:00
parent 1d692db261
commit 33d97ee16a
9 changed files with 128 additions and 10 deletions

View File

@ -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

View File

@ -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" &&

8
scripts/appveyor_r2ghidra.sh Executable file
View File

@ -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"

16
scripts/r2ghidra.sh Executable file
View File

@ -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

View File

@ -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 += \

View File

@ -25,6 +25,10 @@
#include <cstdlib>
#if CUTTER_R2GHIDRA_STATIC
#include <R2GhidraDecompiler.h>
#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()

View File

@ -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}")

View File

@ -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);

View File

@ -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
}