From 88478ffb30e177ad516ed091a53036e6b7eed074 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Sat, 16 Jan 2021 18:48:31 +0800 Subject: [PATCH] New JSDec home (#2563) Switch from r2dec to jsdec --- .appveyor.yml | 2 +- .github/workflows/ccpp.yml | 4 ++-- CMakeLists.txt | 2 +- cmake/BundledRizin.cmake | 2 +- dist/CMakeLists.txt | 12 ++++++------ dist/{bundle_r2dec.ps1 => bundle_jsdec.ps1} | 7 +++---- docs/source/user-docs/features.rst | 2 +- scripts/{r2dec.sh => jsdec.sh} | 9 +++------ src/CMakeLists.txt | 4 ++-- src/CutterApplication.cpp | 20 ++++++++++---------- src/common/Decompiler.cpp | 12 ++++++------ src/common/Decompiler.h | 4 ++-- src/core/Cutter.h | 4 ++-- 13 files changed, 40 insertions(+), 44 deletions(-) rename dist/{bundle_r2dec.ps1 => bundle_jsdec.ps1} (57%) rename scripts/{r2dec.sh => jsdec.sh} (56%) diff --git a/.appveyor.yml b/.appveyor.yml index 496c0547..b7df2bc6 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -46,7 +46,7 @@ build_script: -DCUTTER_ENABLE_PACKAGING=ON -DCUTTER_PACKAGE_DEPENDENCIES=ON -DCUTTER_PACKAGE_RZ_GHIDRA=ON - -DCUTTER_PACKAGE_R2DEC=OFF + -DCUTTER_PACKAGE_JSDEC=ON -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON -DCUTTER_ENABLE_CRASH_REPORTS=ON -DCMAKE_PREFIX_PATH=%CUTTER_DEPS%\\pyside diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 3064dd3a..3d97fead 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -142,7 +142,7 @@ jobs: APP_PREFIX=`pwd`/appdir/usr # export LD_LIBRARY_PATH=${APP_PREFIX}/lib:$Shiboken2_ROOT/lib export PATH=$PATH:${APP_PREFIX}/bin - # "../scripts/r2dec.sh" --prefix=`pwd`/appdir/usr + "../scripts/jsdec.sh" --prefix=`pwd`/appdir/usr wget -c "https://github.com/probonopd/linuxdeployqt/releases/download/6/linuxdeployqt-6-x86_64.AppImage" chmod a+x linuxdeployqt*.AppImage rm -fv "../cutter-deps/qt/plugins/imageformats/libqjp2.so" @@ -218,7 +218,7 @@ jobs: -DCUTTER_ENABLE_PACKAGING=ON ^ -DCUTTER_PACKAGE_DEPENDENCIES=ON ^ -DCUTTER_PACKAGE_RZ_GHIDRA=ON ^ - -DCUTTER_PACKAGE_R2DEC=OFF ^ + -DCUTTER_PACKAGE_JSDEC=ON ^ -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON ^ -DCUTTER_ENABLE_CRASH_REPORTS=ON ^ -DCMAKE_PREFIX_PATH="%CUTTER_DEPS%\pyside" ^ diff --git a/CMakeLists.txt b/CMakeLists.txt index dc726da7..b747f291 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ option(CUTTER_ENABLE_DEPENDENCY_DOWNLOADS "Enable downloading of dependencies. S option(CUTTER_ENABLE_PACKAGING "Enable building platform-specific packages for distributing" 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_R2DEC "Compile and install r2dec during install step." OFF) +option(CUTTER_PACKAGE_JSDEC "Compile and install jsdec during install step." OFF) OPTION(CUTTER_QT6 "Use QT6" OFF) if(NOT CUTTER_ENABLE_PYTHON) diff --git a/cmake/BundledRizin.cmake b/cmake/BundledRizin.cmake index a9b144e6..d3611864 100644 --- a/cmake/BundledRizin.cmake +++ b/cmake/BundledRizin.cmake @@ -8,7 +8,7 @@ if(WIN32) set(RIZIN_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/$") endif() set(RIZIN_INSTALL_BINPATH ".") - set(MESON_OPTIONS "--prefix=${RIZIN_INSTALL_DIR}" "--bindir=${RIZIN_INSTALL_BINPATH}" "-Drz_incdir=include/librz") + set(MESON_OPTIONS "--prefix=${RIZIN_INSTALL_DIR}" "--bindir=${RIZIN_INSTALL_BINPATH}" "-DRZ_INCDIR=include/librz") else() set(RIZIN_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/Rizin-prefix") set(MESON_OPTIONS "--prefix=${RIZIN_INSTALL_DIR}" --libdir=lib) diff --git a/dist/CMakeLists.txt b/dist/CMakeLists.txt index 38e8eb98..8f7bacc7 100644 --- a/dist/CMakeLists.txt +++ b/dist/CMakeLists.txt @@ -20,15 +20,15 @@ if(WIN32) endif() install(SCRIPT WindowsBundleQt.cmake) endif() - if (CUTTER_PACKAGE_R2DEC AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) + if (CUTTER_PACKAGE_JSDEC AND CUTTER_ENABLE_DEPENDENCY_DOWNLOADS) install(CODE " set(ENV{RZ_ALT_SRC_DIR} 1) set(ENV{PATH} \"\${CMAKE_INSTALL_PREFIX};\$ENV{PATH}\") - execute_process(COMMAND powershell \"${CMAKE_CURRENT_SOURCE_DIR}/bundle_r2dec.ps1\" \"\${CMAKE_INSTALL_PREFIX}\" + execute_process(COMMAND powershell \"${CMAKE_CURRENT_SOURCE_DIR}/bundle_jsdec.ps1\" \"\${CMAKE_INSTALL_PREFIX}\" WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE SCRIPT_RESULT) if (SCRIPT_RESULT) - message(FATAL_ERROR \"Failed to package r2dec\") + message(FATAL_ERROR \"Failed to package jsdec\") endif() ") endif() @@ -48,7 +48,7 @@ if(APPLE) set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/macos/cutter_mac_app.png") set(CPACK_DMG_DS_STORE "${CMAKE_CURRENT_SOURCE_DIR}/macos/DS_Store_ForDMGBackground") - + find_program(MACDEPLOYQT_PATH macdeployqt HINTS "${Qt5_DIR}/../../../bin") if(NOT MACDEPLOYQT_PATH) message(FATAL_ERROR "Failed to find macdeployqt") @@ -76,7 +76,7 @@ if(APPLE) list(APPEND RZ_GHIDRA_PREFIX_PATH "${QT_PREFIX}") set(RIZIN_INSTALL_PLUGDIR "share/rizin/plugins") # escaped backslash on purpose, should be evaluated later - + endif() ################################################ @@ -112,7 +112,7 @@ if(CUTTER_PACKAGE_RZ_GHIDRA) execute_process( WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/rz-ghidra-prefix/src/rz-ghidra-build RESULT_VARIABLE SCRIPT_RESULT - COMMAND \${CMAKE_COMMAND} + COMMAND \${CMAKE_COMMAND} ../rz-ghidra -DCMAKE_BUILD_TYPE=Release \"-DCMAKE_PREFIX_PATH=\${CMAKE_INSTALL_PREFIX};\${CMAKE_INSTALL_PREFIX}/include/librz;\${CMAKE_INSTALL_PREFIX}/include/librz/sdb;${RZ_GHIDRA_PREFIX_PATH}\" diff --git a/dist/bundle_r2dec.ps1 b/dist/bundle_jsdec.ps1 similarity index 57% rename from dist/bundle_r2dec.ps1 rename to dist/bundle_jsdec.ps1 index e27c80c9..ab3df584 100644 --- a/dist/bundle_r2dec.ps1 +++ b/dist/bundle_jsdec.ps1 @@ -1,11 +1,10 @@ $dist = $args[0] $python = Split-Path((Get-Command python.exe).Path) -if (-not (Test-Path -Path 'r2dec-js' -PathType Container)) { - git clone https://github.com/rizinorg/r2dec-js.git --branch master --depth 1 +if (-not (Test-Path -Path 'jsdec' -PathType Container)) { + git clone https://github.com/rizinorg/jsdec.git --branch master --depth 1 } -cd r2dec-js -#git checkout b5a0d15c7bcc488f268ffb0931b7ced2919f6c9d +cd jsdec & 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/docs/source/user-docs/features.rst b/docs/source/user-docs/features.rst index cd238b7b..f7aedfe2 100644 --- a/docs/source/user-docs/features.rst +++ b/docs/source/user-docs/features.rst @@ -13,7 +13,7 @@ Here's an image that compares one of the decompiler Cutter supports with the Cut .. image:: ../images/decompiler_vs_disassembly.png -Cutter provides an interface that supports plugins of multiple decompilers including Ghidra, RetDec and R2Dec. The interface receives data from the decompiler and presenting the decompiler code in a context-sensitive decompiler widget. Check the `Decompilers `_ section on our Plugins repository to know more about the decompilers we support. +Cutter provides an interface that supports plugins of multiple decompilers including Ghidra, RetDec and JSDec. The interface receives data from the decompiler and presenting the decompiler code in a context-sensitive decompiler widget. Check the `Decompilers `_ section on our Plugins repository to know more about the decompilers we support. Out of the decompiler plugins that we support, the one that's officially maintained by the developers of Cutter is RzGhidra. :doc:`Click here ` to learn more about the functionalities we provide in the decompiler. diff --git a/scripts/r2dec.sh b/scripts/jsdec.sh similarity index 56% rename from scripts/r2dec.sh rename to scripts/jsdec.sh index f5a669e0..a6986140 100755 --- a/scripts/r2dec.sh +++ b/scripts/jsdec.sh @@ -6,14 +6,11 @@ SCRIPTPATH=$(realpath "$(dirname "${BASH_SOURCE[0]}")") cd "$SCRIPTPATH/.." -if [[ ! -d r2dec-js ]]; then - git clone https://github.com/rizinorg/r2dec-js.git --depth 1 --branch master - #cd r2dec-js - #git checkout b5a0d15c7bcc488f268ffb0931b7ced2919f6c9d - #cd .. +if [[ ! -d jsdec ]]; then + git clone https://github.com/rizinorg/jsdec.git --depth 1 --branch master fi -cd r2dec-js +cd jsdec rm -rf build mkdir build && cd build meson --buildtype=release --libdir=share/rizin/plugins --datadir=share/rizin/plugins "$@" ../p diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b9f75a0..88ef488b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -513,8 +513,8 @@ if (CUTTER_APPIMAGE_BUILD) target_compile_definitions(Cutter PRIVATE APPIMAGE) endif() -if (CUTTER_PACKAGE_R2DEC) - target_compile_definitions(Cutter PRIVATE CUTTER_APPVEYOR_R2DEC) +if (CUTTER_PACKAGE_JSDEC) + target_compile_definitions(Cutter PRIVATE CUTTER_APPVEYOR_JSDEC) endif() if(APPLE AND CUTTER_ENABLE_PACKAGING AND CUTTER_USE_BUNDLED_RIZIN) diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index 476aecd8..6ec59a4b 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -110,8 +110,8 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc Config()->setOutputRedirectionEnabled(clOptions.outputRedirectionEnabled); - if (R2DecDecompiler::isAvailable()) { - Core()->registerDecompiler(new R2DecDecompiler(Core())); + if (JSDecDecompiler::isAvailable()) { + Core()->registerDecompiler(new JSDecDecompiler(Core())); } #if CUTTER_RZGHIDRA_STATIC @@ -154,9 +154,9 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc sleighHome.cd("share/rizin/plugins/rz_ghidra_sleigh"); // appdir/share/rizin/plugins/rz_ghidra_sleigh Core()->setConfig("ghidra.sleighhome", sleighHome.absolutePath()); - auto r2decHome = appdir; - r2decHome.cd("share/rizin/plugins/r2dec-js"); // appdir/share/rizin/plugins/r2dec-js - qputenv("R2DEC_HOME", r2decHome.absolutePath().toLocal8Bit()); + auto jsdecHome = appdir; + jsdecHome.cd("share/rizin/plugins/jsdec"); // appdir/share/rizin/plugins/jsdec + qputenv("JSDEC_HOME", jsdecHome.absolutePath().toLocal8Bit()); } #endif @@ -170,14 +170,14 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc sleighHome.cd("share/rizin/plugins/rz_ghidra_sleigh"); // Contents/Resources/rz/share/rizin/plugins/rz_ghidra_sleigh Core()->setConfig("ghidra.sleighhome", sleighHome.absolutePath()); - auto r2decHome = rzprefix; - r2decHome.cd("share/rizin/plugins/r2dec-js"); // Contents/Resources/rz/share/rizin/plugins/r2dec-js - qputenv("R2DEC_HOME", r2decHome.absolutePath().toLocal8Bit()); + auto jsdecHome = rzprefix; + jsdecHome.cd("share/rizin/plugins/jsdec"); // Contents/Resources/rz/share/rizin/plugins/jsdec + qputenv("JSDEC_HOME", jsdecHome.absolutePath().toLocal8Bit()); } #endif -#ifdef CUTTER_APPVEYOR_R2DEC - qputenv("R2DEC_HOME", "lib\\plugins\\r2dec-js"); +#ifdef CUTTER_APPVEYOR_JSDEC + qputenv("JSDEC_HOME", "lib\\plugins\\jsdec"); #endif #ifdef Q_OS_WIN { diff --git a/src/common/Decompiler.cpp b/src/common/Decompiler.cpp index 56c6e8ff..d6b3b065 100644 --- a/src/common/Decompiler.cpp +++ b/src/common/Decompiler.cpp @@ -17,18 +17,18 @@ RzAnnotatedCode *Decompiler::makeWarning(QString warningMessage){ return rz_annotated_code_new(strdup(temporary.c_str())); } -R2DecDecompiler::R2DecDecompiler(QObject *parent) - : Decompiler("r2dec", "r2dec", parent) +JSDecDecompiler::JSDecDecompiler(QObject *parent) + : Decompiler("jsdec", "jsdec", parent) { task = nullptr; } -bool R2DecDecompiler::isAvailable() +bool JSDecDecompiler::isAvailable() { - return Core()->cmdList("e cmd.pdc=?").contains(QStringLiteral("pdd")); + return Core()->cmdList("es").contains("jsdec"); } -void R2DecDecompiler::decompileAt(RVA addr) +void JSDecDecompiler::decompileAt(RVA addr) { if (task) { return; @@ -39,7 +39,7 @@ void R2DecDecompiler::decompileAt(RVA addr) delete task; task = nullptr; if (json.isEmpty()) { - emit finished(Decompiler::makeWarning(tr("Failed to parse JSON from r2dec"))); + emit finished(Decompiler::makeWarning(tr("Failed to parse JSON from jsdec"))); return; } RzAnnotatedCode *code = rz_annotated_code_new(nullptr); diff --git a/src/common/Decompiler.h b/src/common/Decompiler.h index 2fefd65d..2eaa9e28 100644 --- a/src/common/Decompiler.h +++ b/src/common/Decompiler.h @@ -37,7 +37,7 @@ signals: void finished(RzAnnotatedCode *codeDecompiled); }; -class R2DecDecompiler: public Decompiler +class JSDecDecompiler: public Decompiler { Q_OBJECT @@ -45,7 +45,7 @@ private: RizinCmdTask *task; public: - explicit R2DecDecompiler(QObject *parent = nullptr); + explicit JSDecDecompiler(QObject *parent = nullptr); void decompileAt(RVA addr) override; bool isRunning() override { return task != nullptr; } diff --git a/src/core/Cutter.h b/src/core/Cutter.h index 5adcad96..8462429e 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -67,7 +67,7 @@ public: /** * @brief send a command to Rizin asynchronously * @param str the command you want to execute - * @param task a shared pointer that will be returned with the R2 command task + * @param task a shared pointer that will be returned with the Rizin command task * @note connect to the &RizinTask::finished signal to add your own logic once * the command is finished. Use task->getResult()/getResultJson() for the * return value. @@ -124,7 +124,7 @@ public: /** * @brief send a command to Rizin and check for ESIL errors * @param command the command you want to execute - * @param task a shared pointer that will be returned with the R2 command task + * @param task a shared pointer that will be returned with the Rizin command task * @note connect to the &RizinTask::finished signal to add your own logic once * the command is finished. Use task->getResult()/getResultJson() for the * return value.