From e3e070d09429d2caef804bbc1776718baf80fe83 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sun, 15 Oct 2017 21:19:48 +0200 Subject: [PATCH] Remove cutter win32 (#58) * remove cutter_win32 * build without compile errors * temporary workaround for sdb problems (now compiles again at least) * totally not a hack to get sdb working seriously, don't do this but it works --- .appveyor.yml | 39 ++++---------- .gitignore | 12 +++++ .gitmodules | 3 -- build.bat | 43 ++++++++++++++++ cutter_win32 | 1 - cutter_win32/include/r_addr_interval_msvc.h | 57 +++++++++++++++++++++ cutter_win32/include/sys/time.h | 0 cutter_win32/include/unistd.h | 10 ++++ cutter_win32/radare2/include/.gitignore | 2 + cutter_win32/radare2/lib32/.gitignore | 2 + cutter_win32/radare2/lib64/.gitignore | 2 + prepare_r2.bat | 54 +++++++++++++++++++ src/cutter.h | 19 ++++--- src/lib_radare2.pri | 3 +- src/utils/Highlighter.cpp | 4 +- src/utils/Highlighter.h | 4 +- src/widgets/DisassemblyWidget.h | 2 +- src/widgets/ExportsWidget.h | 2 +- src/widgets/PieView.cpp | 2 +- src/widgets/PreviewWidget.h | 2 +- 20 files changed, 212 insertions(+), 51 deletions(-) create mode 100644 build.bat delete mode 160000 cutter_win32 create mode 100644 cutter_win32/include/r_addr_interval_msvc.h create mode 100644 cutter_win32/include/sys/time.h create mode 100644 cutter_win32/include/unistd.h create mode 100644 cutter_win32/radare2/include/.gitignore create mode 100644 cutter_win32/radare2/lib32/.gitignore create mode 100644 cutter_win32/radare2/lib64/.gitignore create mode 100644 prepare_r2.bat diff --git a/.appveyor.yml b/.appveyor.yml index b6bdb60b..6e570cfb 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,45 +14,28 @@ branches: # Environment environment: - PYTHON: 'C:\\Python36-x64' - BDIR: build-cmake - NINJA_URL: https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip + PYTHON: 'C:\Python36-x64' + NINJA_URL: https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-win.zip QTDIR: 'C:\Qt\5.9.1\msvc2015_64' - -install: - - cmd: git submodule init && git submodule update - - cmd: if defined BDIR ( %PYTHON%\python.exe -m pip install meson && COPY %PYTHON%\Scripts\meson.py radare2\meson.py ) - - cmd: if defined NINJA_URL ( powershell -Command wget %NINJA_URL% -OutFile radare2\ninja.zip && unzip radare2\ninja.zip -d radare2\ ) + QT32PATH: 'C:\Qt\5.9.1\msvc2015' + QT64PATH: 'C:\Qt\5.9.1\msvc2015_64' + VSVARSALLPATH: 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat' before_build: - # Build r2 and generate sln - - cmd: cd radare2 && set "PATH=%PYTHON%;%PATH%" && call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 && meson.bat --release --shared && sys\meson_install.bat --with-static dist && cd .. - # Build cutter - - cmd: set "PATH=%PATH%;%QTDIR%\bin;" && call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 && cd src && qmake -config release -tp vc cutter.pro && cd .. + - cmd: prepare_r2.bat # Build config -build: - project: src\cutter.vcxproj - -after_build: - # Install r2 - - cmd: move radare2\dist cutter - - cmd: cd cutter && dir - - cmd: for %%v in (*.dll) do echo %%v - - cmd: for %%v in (*.dll) do ren %%v lib%%v - - cmd: cd .. - # Install cutter - - cmd: windeployqt src\release\cutter.exe --dir cutter - - cmd: move src\release\cutter.exe cutter\ - - cmd: set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PATH%" && zip -r cutter.zip cutter +build_script: + - cmd: build.bat 32 + - cmd: build.bat 64 # Tests test: off # Artifacts artifacts: - - path: cutter.zip - name: Cutter + - path: build32\cutter32 + - path: build64\cutter64 #deploy: # release: cutter-1.0-$(appveyor_build_version) diff --git a/.gitignore b/.gitignore index a2167a73..4ed5e2be 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,16 @@ Win32/ x64/ *.dir/ build*/ +release/ +debug/ *.orig +/src/*.vcxproj +/src/*.vcxproj.filters +/src/cutter_resource.rc + +#prepare_r2 +meson.py +ninja.exe +/dist32/ +/dist64/ +*.pdb diff --git a/.gitmodules b/.gitmodules index 268b2ac7..d3ca26d0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "radare2"] path = radare2 url = https://github.com/radare/radare2 -[submodule "cutter_win32"] - path = cutter_win32 - url = https://github.com/radareorg/cutter_win32 diff --git a/build.bat b/build.bat new file mode 100644 index 00000000..83881842 --- /dev/null +++ b/build.bat @@ -0,0 +1,43 @@ +@echo off + +echo Setting path +if "%OLDPATH%"=="" set OLDPATH=%PATH% +if "%QT32PATH%"=="" set QT32PATH=C:\Qt\5.9.1\msvc2015 +if "%QT64PATH%"=="" set QT64PATH=C:\Qt\5.9.1\msvc2015_64 +if "%VSVARSALLPATH%"=="" set VSVARSALLPATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat + +if "%1"=="32" ( + set "PATH=%QT32PATH%\bin;%PATH%" + call "%VSVARSALLPATH%" x86 + set MSBUILDPLATFORM=Win32 +) else if "%1"=="64" ( + set "PATH=%QT64PATH%\bin;%PATH%" + call "%VSVARSALLPATH%" x64 + set MSBUILDPLATFORM=x64 +) else ( + echo Usage: build.bat 32/64 + goto restorepath +) + +echo Preparing directory +rmdir /s /q build%1 +mkdir build%1 +cd build%1 + +echo Building cutter +qmake ..\src\cutter.pro -config release -tp vc +if not %ERRORLEVEL%==0 exit +msbuild /m cutter.vcxproj /p:Configuration=Release;Platform=%MSBUILDPLATFORM% +if not %ERRORLEVEL%==0 exit + +echo Deploying cutter +mkdir cutter%1 +move release\cutter.exe cutter%1\cutter.exe +xcopy /s ..\dist%1 cutter%1\ +windeployqt cutter%1\cutter.exe +cd .. + +:restorepath +echo Restoring path +set PATH=%OLDPATH% +set OLDPATH= \ No newline at end of file diff --git a/cutter_win32 b/cutter_win32 deleted file mode 160000 index 5f8109de..00000000 --- a/cutter_win32 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5f8109de359fc3e65cc0382691d99c5a7852f26e diff --git a/cutter_win32/include/r_addr_interval_msvc.h b/cutter_win32/include/r_addr_interval_msvc.h new file mode 100644 index 00000000..bbcc6cf7 --- /dev/null +++ b/cutter_win32/include/r_addr_interval_msvc.h @@ -0,0 +1,57 @@ +#ifndef R_ADDR_INTERVAL_H +#define R_ADDR_INTERVAL_H + +#pragma message("r_addr_interval_msvc.h(4): warning C1337: hacky implementation of r_addr_interval, be wary!") +//MSVC (C++) implementation of radare2/include/libr/r_util/r_addr_interval.h +//DO NOT REMOVE THE WARNING BEFORE R2 IS FIXED! + +#include + +// An interval in 64-bit address space which is aware of address space wraparound +// Precondition: 0 <= size < 2**64 and addr + size <= 2**64 +typedef struct r_addr_interval_t { + // public: + ut64 addr; + ut64 size; +} RAddrInterval; + +static inline ut64 r_itv_begin(RAddrInterval itv) { + return itv.addr; +} + +// Returns the right endpoint address (not included) +static inline ut64 r_itv_end(RAddrInterval itv) { + return itv.addr + itv.size; +} + +// Returns true if itv contained addr +static inline bool r_itv_contain(RAddrInterval itv, ut64 addr) { + ut64 end = itv.addr + itv.size; + return itv.addr <= addr && (!end || addr < end); +} + +// Returns true if x is a subset of itv +static inline bool r_itv_include(RAddrInterval itv, RAddrInterval x) { + ut64 end = itv.addr + itv.size; + return itv.addr <= x.addr && (!end || (x.addr + x.size && x.addr + x.size <= end)); +} + +// Returns true if itv and x overlap (implying they are non-empty) +static inline bool r_itv_overlap(RAddrInterval itv, RAddrInterval x) { + ut64 end = itv.addr + itv.size, end1 = x.addr + x.size; + return (!end1 || itv.addr < end1) && (!end || x.addr < end); +} + +static inline bool r_itv_overlap2(RAddrInterval itv, ut64 addr, ut64 size) { + return r_itv_overlap (itv, RAddrInterval{addr, size}); +} + +// Precondition: itv and x overlap +// Returns the intersection of itv and x +static inline RAddrInterval r_itv_intersect(RAddrInterval itv, RAddrInterval x) { + ut64 addr = R_MAX (itv.addr, x.addr), + end = R_MIN (itv.addr + itv.size - 1, x.addr + x.size - 1) + 1; + return RAddrInterval{addr, end - addr}; +} + +#endif // R_ADDR_INTERVAL_H \ No newline at end of file diff --git a/cutter_win32/include/sys/time.h b/cutter_win32/include/sys/time.h new file mode 100644 index 00000000..e69de29b diff --git a/cutter_win32/include/unistd.h b/cutter_win32/include/unistd.h new file mode 100644 index 00000000..c381ead0 --- /dev/null +++ b/cutter_win32/include/unistd.h @@ -0,0 +1,10 @@ +//http://stackoverflow.com/a/826027/1806760 + +#ifndef UNISTD_H +#define UNISTD_H + +#include +#include +#include + +#endif diff --git a/cutter_win32/radare2/include/.gitignore b/cutter_win32/radare2/include/.gitignore new file mode 100644 index 00000000..b4082bd4 --- /dev/null +++ b/cutter_win32/radare2/include/.gitignore @@ -0,0 +1,2 @@ +# Relevant files will be placed here after running prepare_r2.bat +/libr/ \ No newline at end of file diff --git a/cutter_win32/radare2/lib32/.gitignore b/cutter_win32/radare2/lib32/.gitignore new file mode 100644 index 00000000..35c917d0 --- /dev/null +++ b/cutter_win32/radare2/lib32/.gitignore @@ -0,0 +1,2 @@ +# Relevant files will be placed here after running prepare_r2.bat +/*.lib \ No newline at end of file diff --git a/cutter_win32/radare2/lib64/.gitignore b/cutter_win32/radare2/lib64/.gitignore new file mode 100644 index 00000000..35c917d0 --- /dev/null +++ b/cutter_win32/radare2/lib64/.gitignore @@ -0,0 +1,2 @@ +# Relevant files will be placed here after running prepare_r2.bat +/*.lib \ No newline at end of file diff --git a/prepare_r2.bat b/prepare_r2.bat new file mode 100644 index 00000000..0ecc08e2 --- /dev/null +++ b/prepare_r2.bat @@ -0,0 +1,54 @@ +@echo off + +if "%OLDPATH%"=="" set OLDPATH=%PATH% +if "%PYTHON%"=="" set PYTHON=C:\Python36-x64 +if "%NINJA_URL%"=="" set NINJA_URL=https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-win.zip +if "%VSVARSALLPATH%"=="" set VSVARSALLPATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat + +set "PYTHONHOME=%PYTHON%" +set "PATH=%PYTHON%;%PATH%" + +git submodule update --init + +echo Downloading meson and ninja +python -m pip install meson && COPY %PYTHON%\Scripts\meson.py meson.py +if defined NINJA_URL ( powershell -Command wget %NINJA_URL% -OutFile ninja.zip && unzip -o ninja.zip -d .\ && del ninja.zip ) + +cd radare2 + +echo Building radare2 (x86) +git clean -xfd +copy ..\ninja.exe .\ +copy ..\meson.py .\ +rmdir /s /q ..\dist32 +call "%VSVARSALLPATH%" x86 +call meson.bat --release --shared +if not %ERRORLEVEL%==0 exit +call sys\meson_install.bat --with-static ..\dist32 +copy /Y build\r_userconf.h ..\dist32\include\libr\ +copy /Y build\r_version.h ..\dist32\include\libr\ +copy /Y build\shlr\liblibr2sdb.a ..\dist32\r_sdb.lib + +echo Building radare2 (x64) +git clean -xfd +copy ..\ninja.exe .\ +copy ..\meson.py .\ +rmdir /s /q ..\dist64 +call "%VSVARSALLPATH%" x64 +call meson.bat --release --shared +if not %ERRORLEVEL%==0 exit +call sys\meson_install.bat --with-static ..\dist64 +copy /Y build\shlr\liblibr2sdb.a ..\dist64\r_sdb.lib + +cd .. + +echo Copying relevant files in cutter_win32 +xcopy /s /Y dist32\include\libr cutter_win32\radare2\include\libr\ +copy /Y dist32\*.lib cutter_win32\radare2\lib32\ +copy /Y dist64\*.lib cutter_win32\radare2\lib64\ + +del ninja.exe +del meson.py + +set PATH=%OLDPATH% +set OLDPATH= \ No newline at end of file diff --git a/src/cutter.h b/src/cutter.h index 4e398508..a06f90e5 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -1,18 +1,10 @@ #ifndef CUTTER_H #define CUTTER_H -#include -#include -#include -#include -#include -#include - - // Workaround for compile errors on Windows #ifdef _WIN32 -#include -#endif +#include +#endif //_WIN32 #include "r_core.h" @@ -22,6 +14,13 @@ #undef max #endif //_WIN32 +#include +#include +#include +#include +#include +#include + #define HAVE_LATEST_LIBR2 false #define CutterRListForeach(list, it, type, x) \ diff --git a/src/lib_radare2.pri b/src/lib_radare2.pri index d5973c2f..15f26d47 100644 --- a/src/lib_radare2.pri +++ b/src/lib_radare2.pri @@ -32,7 +32,8 @@ win32 { -lr_socket \ -lr_fs \ -lr_magic \ - -lr_crypto + -lr_crypto \ + -lr_sdb } else { USE_PKGCONFIG = 1 R2_USER_PKGCONFIG = $$(HOME)/bin/prefix/radare2/lib/pkgconfig diff --git a/src/utils/Highlighter.cpp b/src/utils/Highlighter.cpp index 148209e5..612a4efe 100644 --- a/src/utils/Highlighter.cpp +++ b/src/utils/Highlighter.cpp @@ -1,8 +1,8 @@ -#include - #include "Highlighter.h" #include "MainWindow.h" +#include + Highlighter::Highlighter(QTextDocument *parent) : QSyntaxHighlighter(parent) { diff --git a/src/utils/Highlighter.h b/src/utils/Highlighter.h index e75054a8..dfc5deee 100644 --- a/src/utils/Highlighter.h +++ b/src/utils/Highlighter.h @@ -1,9 +1,9 @@ #ifndef HIGHLIGHTER_H #define HIGHLIGHTER_H -#include - #include "cutter.h" + +#include #include #include diff --git a/src/widgets/DisassemblyWidget.h b/src/widgets/DisassemblyWidget.h index 20325c88..4b94524b 100644 --- a/src/widgets/DisassemblyWidget.h +++ b/src/widgets/DisassemblyWidget.h @@ -1,9 +1,9 @@ #ifndef DISASSEMBLYVIEW_H #define DISASSEMBLYVIEW_H +#include "cutter.h" #include #include -#include "cutter.h" class DisassemblyWidget : public QDockWidget { diff --git a/src/widgets/ExportsWidget.h b/src/widgets/ExportsWidget.h index 1acb18af..38a11be6 100644 --- a/src/widgets/ExportsWidget.h +++ b/src/widgets/ExportsWidget.h @@ -1,10 +1,10 @@ #ifndef EXPORTSWIDGET_H #define EXPORTSWIDGET_H +#include "cutter.h" #include #include #include -#include "cutter.h" #include "DockWidget.h" class MainWindow; diff --git a/src/widgets/PieView.cpp b/src/widgets/PieView.cpp index c64abbbb..d7608aab 100644 --- a/src/widgets/PieView.cpp +++ b/src/widgets/PieView.cpp @@ -38,6 +38,7 @@ ** ****************************************************************************/ +#include "cutter.h" #include #include #include @@ -46,7 +47,6 @@ #define M_PI 3.1415927 #endif -#include "cutter.h" #include "PieView.h" PieView::PieView(QWidget *parent) diff --git a/src/widgets/PreviewWidget.h b/src/widgets/PreviewWidget.h index 8a3ff2ff..ace10f04 100644 --- a/src/widgets/PreviewWidget.h +++ b/src/widgets/PreviewWidget.h @@ -1,6 +1,7 @@ #ifndef PREVIEWWIDGET_H #define PREVIEWWIDGET_H +#include "cutter.h" #include #include #include @@ -10,7 +11,6 @@ #include #include #include -#include "cutter.h" #include "utils/Highlighter.h" #include "utils/HexAsciiHighlighter.h" #include "utils/HexHighlighter.h"