From c49cbc9f01f10f132756a3a838d73c864cda1000 Mon Sep 17 00:00:00 2001 From: karliss Date: Sat, 3 Oct 2020 13:50:57 +0300 Subject: [PATCH] Add cmake script for packaging r2dec on windows. (#2425) --- .github/workflows/ccpp.yml | 1 + scripts/bundle_r2dec.ps1 | 6 ++- scripts/r2dec.sh | 8 ++-- src/CMakeLists.txt | 5 +++ src/cmake/Packaging.cmake | 91 +++++++++++++++++++++----------------- 5 files changed, 65 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index e6a7a04f..346fd62e 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -124,6 +124,7 @@ jobs: -DCUTTER_ENABLE_PYTHON_BINDINGS=ON ^ -DCUTTER_PACKAGE_DEPENDENCIES=ON ^ -DCUTTER_PACKAGE_R2GHIDRA=ON ^ + -DCUTTER_PACKAGE_R2DEC=ON ^ -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON ^ -DCUTTER_ENABLE_CRASH_REPORTS=ON ^ -DCMAKE_PREFIX_PATH="%CUTTER_DEPS%\pyside" ^ diff --git a/scripts/bundle_r2dec.ps1 b/scripts/bundle_r2dec.ps1 index ac3f66d3..a316ba9d 100644 --- a/scripts/bundle_r2dec.ps1 +++ b/scripts/bundle_r2dec.ps1 @@ -1,9 +1,11 @@ $dist = $args[0] $python = Split-Path((Get-Command python.exe).Path) -git clone https://github.com/radareorg/r2dec-js.git +if (-not (Test-Path -Path 'r2dec-js' -PathType Container)) { + git clone https://github.com/radareorg/r2dec-js.git --branch master --depth 1 +} cd r2dec-js -git checkout b5a0d15c7bcc488f268ffb0931b7ced2919f6c9d +#git checkout b5a0d15c7bcc488f268ffb0931b7ced2919f6c9d & meson.exe --buildtype=release -Dc_args=-DDUK_USE_DATE_NOW_WINDOWS --prefix=$dist --libdir=lib\plugins --datadir=lib\plugins p build ninja -C build install Remove-Item -Recurse -Force $dist\lib\plugins\core_pdd.lib diff --git a/scripts/r2dec.sh b/scripts/r2dec.sh index e6702804..8c7668b8 100755 --- a/scripts/r2dec.sh +++ b/scripts/r2dec.sh @@ -7,10 +7,10 @@ SCRIPTPATH=$(realpath "$(dirname "${BASH_SOURCE[0]}")") cd "$SCRIPTPATH/.." if [[ ! -d r2dec-js ]]; then - git clone https://github.com/wargio/r2dec-js.git - cd r2dec-js - git checkout b5a0d15c7bcc488f268ffb0931b7ced2919f6c9d - cd .. + git clone https://github.com/radareorg/r2dec-js.git --depth 1 --branch master + #cd r2dec-js + #git checkout b5a0d15c7bcc488f268ffb0931b7ced2919f6c9d + #cd .. fi cd r2dec-js diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 33b22e03..2f8dcf0c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ 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 r2 build." OFF) option(CUTTER_PACKAGE_DEPENDENCIES "During install step include the third party dependencies." OFF) option(CUTTER_PACKAGE_R2GHIDRA "Compile and install r2ghidra during install step." OFF) +option(CUTTER_PACKAGE_R2DEC "Compile and install r2dec during install step." OFF) if(NOT CUTTER_ENABLE_PYTHON) set(CUTTER_ENABLE_PYTHON_BINDINGS OFF) @@ -263,6 +264,10 @@ if (CUTTER_APPIMAGE_BUILD) target_compile_definitions(Cutter PRIVATE APPIMAGE) endif() +if (CUTTER_PACKAGE_R2DEC) + target_compile_definitions(Cutter PRIVATE CUTTER_APPVEYOR_R2DEC) +endif() + include(Translations) # Install files diff --git a/src/cmake/Packaging.cmake b/src/cmake/Packaging.cmake index bbc3cecf..b9725e02 100644 --- a/src/cmake/Packaging.cmake +++ b/src/cmake/Packaging.cmake @@ -12,47 +12,58 @@ if(WIN32) install(FILES ${CUTTER_DEPS}/pyside/bin/shiboken2.abi3.dll ${CUTTER_DEPS}/pyside/bin/pyside2.abi3.dll DESTINATION .) endif() install(SCRIPT cmake/WindowsBundleQt.cmake) - - if (CUTTER_PACKAGE_R2GHIDRA) - if (CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) - # Currently using external project only for downloading source - # It neeeds to link against compiled cutter so for now build it using custom install script. - # That way r2ghidra build process is the same as with any other external plugin built against - # installed Cutter. - ExternalProject_Add(R2Ghidra - GIT_REPOSITORY https://github.com/radareorg/r2ghidra.git - GIT_TAG master - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - ) - endif() - install(CODE " - execute_process( - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/R2Ghidra-prefix/src/R2Ghidra-build - RESULT_VARIABLE SCRIPT_RESULT - COMMAND \${CMAKE_COMMAND} - ../R2Ghidra - -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=\"\${CMAKE_INSTALL_PREFIX}\;\${CMAKE_INSTALL_PREFIX}/include/libr\;\${CMAKE_INSTALL_PREFIX}/include/libr/sdb\" - -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} - -DRADARE2_INSTALL_PLUGDIR=\${CMAKE_INSTALL_PREFIX}/lib/plugins - -DCUTTER_INSTALL_PLUGDIR=plugins/native - -DBUILD_CUTTER_PLUGIN=ON - -DBUILD_SLEIGH_PLUGIN=OFF - -G Ninja - ) - if (SCRIPT_RESULT) - message(FATAL_ERROR \"Failed to configure r2ghidra\") - endif() - execute_process(WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/R2Ghidra-prefix/src/R2Ghidra-build - RESULT_VARIABLE SCRIPT_RESULT - COMMAND \${CMAKE_COMMAND} --build . --target install - ) - if (SCRIPT_RESULT) - message(FATAL_ERROR \"Failed to install r2ghidra plugin\") - endif() - ") + endif() + if (CUTTER_PACKAGE_R2GHIDRA) + if (CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) + # Currently using external project only for downloading source + # It neeeds to link against compiled cutter so for now build it using custom install script. + # That way r2ghidra build process is the same as with any other external plugin built against + # installed Cutter. + ExternalProject_Add(R2Ghidra + GIT_REPOSITORY https://github.com/radareorg/r2ghidra.git + GIT_TAG master + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + ) endif() + install(CODE " + execute_process( + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/R2Ghidra-prefix/src/R2Ghidra-build + RESULT_VARIABLE SCRIPT_RESULT + COMMAND \${CMAKE_COMMAND} + ../R2Ghidra + -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=\"\${CMAKE_INSTALL_PREFIX}\;\${CMAKE_INSTALL_PREFIX}/include/libr\;\${CMAKE_INSTALL_PREFIX}/include/libr/sdb\" + -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} + -DRADARE2_INSTALL_PLUGDIR=\${CMAKE_INSTALL_PREFIX}/lib/plugins + -DCUTTER_INSTALL_PLUGDIR=plugins/native + -DBUILD_CUTTER_PLUGIN=ON + -DBUILD_SLEIGH_PLUGIN=OFF + -G Ninja + ) + if (SCRIPT_RESULT) + message(FATAL_ERROR \"Failed to configure r2ghidra\") + endif() + execute_process(WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/R2Ghidra-prefix/src/R2Ghidra-build + RESULT_VARIABLE SCRIPT_RESULT + COMMAND \${CMAKE_COMMAND} --build . --target install + ) + if (SCRIPT_RESULT) + message(FATAL_ERROR \"Failed to install r2ghidra plugin\") + endif() + ") + endif() + if (CUTTER_PACKAGE_R2DEC AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) + install(CODE " + set(ENV{R_ALT_SRC_DIR} 1) + set(ENV{PATH} \"\${CMAKE_INSTALL_PREFIX};\$ENV{PATH}\") + execute_process(COMMAND powershell ../scripts/bundle_r2dec.ps1 \"\${CMAKE_INSTALL_PREFIX}\" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE SCRIPT_RESULT) + if (SCRIPT_RESULT) + message(FATAL_ERROR \"Failed to package r2dec\") + endif() + ") endif() endif() include(CPack)