diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9778f802c8..1f7a6337e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,15 +102,16 @@ jobs: with: name: r2r.json path: /tmp/r2r.json + # TODO: Add job to build with capstone-next, for now v5 is stable build-syscapstone: name: linux-sys-capstone runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v3 - - name: Installing capstone + - name: Installing capstone v5 run: | - git clone --branch next --single-branch --depth=1 https://github.com/capstone-engine/capstone + git clone --branch v5 --single-branch --depth=1 https://github.com/capstone-engine/capstone cd capstone && ( git log | head ) && sh make.sh && sudo make install - name: Installing r2 with sys-capstone run: | diff --git a/config-user.mk.acr b/config-user.mk.acr index 307c342f4c..6e0e49852e 100644 --- a/config-user.mk.acr +++ b/config-user.mk.acr @@ -3,6 +3,7 @@ CC=@CC@ WITH_GPL=@WITH_GPL@ USE_CS4=@USE_CS4@ +USE_CSNEXT=@USE_CSNEXT@ DESTDIR= PREFIX=@PREFIX@ BINDIR=@BINDIR@ diff --git a/configure b/configure index 6cbb676f33..8dbb4eb4d5 100755 --- a/configure +++ b/configure @@ -30,6 +30,7 @@ WANT_GPERF=1 WANT_CAPSTONE=1 WITH_LIBR=0 WITH_STATIC_THEMES=0 +USE_CSNEXT=0 USE_CS5=0 USE_CS4=0 WITH_CAPSTONE=0 @@ -187,7 +188,8 @@ System types: --target=TARGET configure for building compilers for TARGET [HOST] EOF2 -printf "\nOptional Features: +printf " +Optional Features: --disable-debugger disable native debugger features --with-sysmagic force to use system's magic --disable-threads disable use of thread apis @@ -200,7 +202,8 @@ printf "\nOptional Features: --without-capstone dont build the capstone dependency --with-libr build libr.a and libr.dylib --with-static-themes default themes are compiled and fallback if not available on disk - --with-capstone5 build next branch of capstone5 (default) + --with-capstone-next build next branch of the capstone disassembler + --with-capstone5 build v5 branch of capstone5 (default) --with-capstone4 build v4 branch of capstone --with-syscapstone force to use system-wide capstone --with-syslz4 force to use system's liblz4 @@ -215,16 +218,20 @@ printf "\nOptional Features: --with-ostype Choose OS ( android windows wsl mingw32 bsd solaris gnulinux darwin haiku ) (USEROSTYPE=auto) --with-libversion specify different libversion (LIBVERSION=xxx) --without-jemalloc build without jemalloc - --with-checks-level value between 0 and 3 to enable different level of assert (see R_CHECKS_LEVEL) (R_CHECKS_LEVEL=2)\n" -printf "\nSome influential environment variables: + --with-checks-level value between 0 and 3 to enable different level of assert (see R_CHECKS_LEVEL) (R_CHECKS_LEVEL=2) +" +printf " +Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory - CPP C preprocessor\n" -printf "\nReport bugs to: pancake " + CPP C preprocessor +" +printf " +Report bugs to: pancake " echo "" exit 0 } @@ -288,7 +295,7 @@ echo "LANGS: c" echo "REQUIRED: libdl" echo "OPTIONAL: libmagic libz libzip libxxhash libssl liblibuv>=1.0.0" echo "PKGCONFIG: capstone liblz4 openssl libuv" -echo "FLAGS: --disable-debugger --with-sysmagic --disable-threads --disable-loadlibs --enable-threadsafety --without-dylink --without-fork --without-ptrace-wrap --without-gperf --without-capstone --with-libr --with-static-themes --with-capstone5 --with-capstone4 --with-syscapstone --with-syslz4 --with-syszip --with-sysxxhash --without-gpl --with-ssl --with-ssl-crypto --with-libuv --with-rpath --with-compiler=gcc --with-ostype=auto --with-libversion=xxx --without-jemalloc --with-checks-level=2" +echo "FLAGS: --disable-debugger --with-sysmagic --disable-threads --disable-loadlibs --enable-threadsafety --without-dylink --without-fork --without-ptrace-wrap --without-gperf --without-capstone --with-libr --with-static-themes --with-capstone-next --with-capstone5 --with-capstone4 --with-syscapstone --with-syslz4 --with-syszip --with-sysxxhash --without-gpl --with-ssl --with-ssl-crypto --with-libuv --with-rpath --with-compiler=gcc --with-ostype=auto --with-libversion=xxx --without-jemalloc --with-checks-level=2" exit 0 ;; --cache-file) @@ -352,6 +359,7 @@ echo "FLAGS: --disable-debugger --with-sysmagic --disable-threads --disabl "--without-capstone") WANT_CAPSTONE="0"; ;; "--with-libr") WITH_LIBR="1"; ;; "--with-static-themes") WITH_STATIC_THEMES="1"; ;; +"--with-capstone-next") USE_CSNEXT="1"; ;; "--with-capstone5") USE_CS5="1"; ;; "--with-capstone4") USE_CS4="1"; ;; "--with-syscapstone") WITH_CAPSTONE="1"; ;; @@ -385,7 +393,7 @@ parse_options "$1" shift done -ENVWORDS="MANDIR DESCRIPTION INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR ETCDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGCFG_LIBDIR PKGCFG_INCDIR PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS PKGCONFIG R2_BUILDSYSTEM HAVE_PATCH PATCH HAVE_AR AR HAVE_GIT GIT HAVE_GPERF GPERF HAVE_LIB_MAGIC HAVE_LINUX_CAN_H USE_MAGIC USE_LIB_MAGIC LIBMAGIC WANT_THREADS LOADLIBS R_CRITICAL_ENABLED WANT_DYLINK HAVE_FORK WANT_PTRACE_WRAP WANT_GPERF WANT_CAPSTONE WITH_LIBR WITH_STATIC_THEMES USE_CS5 USE_CS4 WITH_CAPSTONE CAPSTONE_CFLAGS CAPSTONE_LDFLAGS HAVE_PKGCFG_CAPSTONE USE_CAPSTONE LZ4_CFLAGS LZ4_LDFLAGS HAVE_PKGCFG_LIBLZ4 WITH_SYSLZ4 USE_SYSLZ4 HAVE_LIB_Z HAVE_LIB_ZIP USE_ZIP USE_LIB_ZIP LIBZIP HAVE_LIB_XXHASH USE_XXHASH USE_LIB_XXHASH LIBXXHASH WITH_GPL HAVE_DECL_ADDR_NO_RANDOMIZE HAVE_DECL___GLIBC__ HAVE_ARC4RANDOM_UNIFORM HAVE_EXPLICIT_BZERO HAVE_EXPLICIT_MEMSET HAVE_CLOCK_NANOSLEEP HAVE_SIGACTION HAVE_CLOCK_GETTIME CLOCK_LDFLAGS SUPPORT_GNU99 HAVE_LIB_GMP HAVE_LIB_SSL SSL_CFLAGS SSL_LDFLAGS HAVE_PKGCFG_OPENSSL HAVE_OPENSSL WANT_SSL WANT_SSL_CRYPTO WANT_LIBUV HAVE_LIBUV_VERSION_1_0_0 LIBUV_CFLAGS LIBUV_LDFLAGS HAVE_PKGCFG_LIBUV HAVE_LIBUV USE_RPATH USERCC USEROSTYPE LIBVERSION HAVE_JEMALLOC HAVE_PTRACE USE_PTRACE_WRAP R_CHECKS_LEVEL" +ENVWORDS="MANDIR DESCRIPTION INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR ETCDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGCFG_LIBDIR PKGCFG_INCDIR PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS PKGCONFIG R2_BUILDSYSTEM HAVE_PATCH PATCH HAVE_AR AR HAVE_GIT GIT HAVE_GPERF GPERF HAVE_LIB_MAGIC HAVE_LINUX_CAN_H USE_MAGIC USE_LIB_MAGIC LIBMAGIC WANT_THREADS LOADLIBS R_CRITICAL_ENABLED WANT_DYLINK HAVE_FORK WANT_PTRACE_WRAP WANT_GPERF WANT_CAPSTONE WITH_LIBR WITH_STATIC_THEMES USE_CSNEXT USE_CS5 USE_CS4 WITH_CAPSTONE CAPSTONE_CFLAGS CAPSTONE_LDFLAGS HAVE_PKGCFG_CAPSTONE USE_CAPSTONE LZ4_CFLAGS LZ4_LDFLAGS HAVE_PKGCFG_LIBLZ4 WITH_SYSLZ4 USE_SYSLZ4 HAVE_LIB_Z HAVE_LIB_ZIP USE_ZIP USE_LIB_ZIP LIBZIP HAVE_LIB_XXHASH USE_XXHASH USE_LIB_XXHASH LIBXXHASH WITH_GPL HAVE_DECL_ADDR_NO_RANDOMIZE HAVE_DECL___GLIBC__ HAVE_ARC4RANDOM_UNIFORM HAVE_EXPLICIT_BZERO HAVE_EXPLICIT_MEMSET HAVE_CLOCK_NANOSLEEP HAVE_SIGACTION HAVE_CLOCK_GETTIME CLOCK_LDFLAGS SUPPORT_GNU99 HAVE_LIB_GMP HAVE_LIB_SSL SSL_CFLAGS SSL_LDFLAGS HAVE_PKGCFG_OPENSSL HAVE_OPENSSL WANT_SSL WANT_SSL_CRYPTO WANT_LIBUV HAVE_LIBUV_VERSION_1_0_0 LIBUV_CFLAGS LIBUV_LDFLAGS HAVE_PKGCFG_LIBUV HAVE_LIBUV USE_RPATH USERCC USEROSTYPE LIBVERSION HAVE_JEMALLOC HAVE_PTRACE USE_PTRACE_WRAP R_CHECKS_LEVEL" create_environ diff --git a/configure.acr b/configure.acr index dd0e00745b..8c3bccc6db 100644 --- a/configure.acr +++ b/configure.acr @@ -50,7 +50,9 @@ ARG_WITH WITH_LIBR libr build libr.a and libr.dylib ; ARG_WITH WITH_STATIC_THEMES static-themes default themes are compiled and fallback if not available on disk ; (( CAPSTONE )) -ARG_WITH USE_CS5 capstone5 build next branch of capstone5 (default) ; +ARG_WITH USE_CSNEXT capstone-next build next branch of the capstone disassembler ; +(( TODO rename to capstone-v5 and capstone-v4 )) +ARG_WITH USE_CS5 capstone5 build v5 branch of capstone5 (default) ; ARG_WITH USE_CS4 capstone4 build v4 branch of capstone ; ARG_WITH WITH_CAPSTONE syscapstone force to use system-wide capstone ; diff --git a/libr/core/hack.c b/libr/core/hack.c index 5e2a4aaec9..3573b34fb2 100644 --- a/libr/core/hack.c +++ b/libr/core/hack.c @@ -11,11 +11,10 @@ static bool r_core_hack_riscv(RCore *core, const char *op, const RAnalOp *analop if (!strcmp (op, "nop")) { // TODO honor analop->size r_core_cmdf (core, "wx 13000000"); - } else { - R_LOG_ERROR ("Unsupported operation '%s'", op); - return false; + return true; } - return true; + R_LOG_ERROR ("Unsupported operation '%s'", op); + return false; } static bool r_core_hack_dalvik(RCore *core, const char *op, const RAnalOp *analop) { diff --git a/libr/include/r_userconf.h.acr b/libr/include/r_userconf.h.acr index b850cfaee1..95a99e9cae 100644 --- a/libr/include/r_userconf.h.acr +++ b/libr/include/r_userconf.h.acr @@ -21,8 +21,10 @@ extern "C" { #define HAVE_LINUX_CAN_H @HAVE_LINUX_CAN_H@ #define R_BUILDSYSTEM "@R2_BUILDSYSTEM@" -#if @USE_CS4@ > 0 +#if @USE_CS4@ == 1 #define R2_CSVERSION 4 +#elif @USE_CSNEXT@ == 1 +#define R2_CSVERSION 6 #else #define R2_CSVERSION 5 #endif diff --git a/meson.build b/meson.build index 452ad182d6..1ab4aa7684 100644 --- a/meson.build +++ b/meson.build @@ -378,6 +378,7 @@ userconf.set('BINDINGS', r2_bindings) userconf.set('R2_BUILDSYSTEM', 'meson') capstone_version = get_option('use_capstone_version') userconf.set10('USE_CS4', capstone_version == 'v4') +userconf.set10('USE_CSNEXT', capstone_version == 'v6') userconf.set10('HAVE_OPENSSL', use_sys_openssl) userconf.set10('WANT_SSL_CRYPTO', use_ssl_crypto) userconf.set10('HAVE_LIBUV', use_libuv) diff --git a/meson_options.txt b/meson_options.txt index 59c6ca3925..07a9e14856 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -28,7 +28,7 @@ option('capstone_in_builddir', type: 'boolean', value: false, description: 'When option('want_threads', type: 'boolean', value: true) option('want_capstone', type: 'boolean', value: true) option('use_sys_capstone', type: 'boolean', value: false) -option('use_capstone_version', type: 'combo', choices: ['v3', 'v4', 'v5'], value: 'v5') +option('use_capstone_version', type: 'combo', choices: ['v3', 'v4', 'v5', 'next'], value: 'v5') option('use_sys_magic', type: 'boolean', value: false) option('use_sys_zip', type: 'boolean', value: false) option('use_sys_zlib', type: 'boolean', value: false) diff --git a/shlr/Makefile b/shlr/Makefile index 2789a99b44..46c8fd5262 100644 --- a/shlr/Makefile +++ b/shlr/Makefile @@ -48,12 +48,17 @@ CS_URL=$(GIT_PREFIX)$(CS_URL_BASE).git CS_ARCHIVE=https://$(CS_URL_BASE)/archive CS_UPD=20201203 # NOTE: when you update CS_TIP or CS_BRA, also update them in shlr/meson.build +ifeq ($(USE_CSNEXT),1) +CS_TIP=a4df92eda647e739432860682be638da1b8b901a +CS_BRA=next +else ifeq ($(USE_CS4),1) -CS_TIP=1d230532840a37ac032c6ab80128238fc930c6c1 +CS_TIP=0efa3cc530ea188c0e03c945ab884ee19dd16342 CS_BRA=v4 else -CS_TIP=8ae8f68ea3abb7a68071908bad02baa39742870c -CS_BRA=next +CS_TIP=e1af2e249ab85c70594a8c975f27d072278257fb +CS_BRA=v5 +endif endif ifeq ($(CS_COMMIT_ARCHIVE),1) CS_ARCHIVE_URL=$(CS_ARCHIVE)/$(CS_TIP).zip diff --git a/shlr/capstone-patches/v5/fix-x86-16.patch b/shlr/capstone-patches/fix-x86-16.patch similarity index 82% rename from shlr/capstone-patches/v5/fix-x86-16.patch rename to shlr/capstone-patches/fix-x86-16.patch index 1232fed998..aeded18d8b 100644 --- a/shlr/capstone-patches/v5/fix-x86-16.patch +++ b/shlr/capstone-patches/fix-x86-16.patch @@ -1,28 +1,28 @@ diff --git a/arch/X86/X86ATTInstPrinter.c b/arch/X86/X86ATTInstPrinter.c -index 216efb25..37cab473 100644 +index 216efb2..37cab47 100644 --- a/arch/X86/X86ATTInstPrinter.c +++ b/arch/X86/X86ATTInstPrinter.c @@ -536,6 +536,9 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O) imm = imm & 0xffffffff; } - + + if (MI->csh->mode == CS_MODE_16) -+ imm = (imm & 0xf0000) + (imm&0xffff); ++ imm |= (MI->address >> 16) << 16; + if (imm < 0) { SStream_concat(O, "0x%"PRIx64, imm); } else { diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c -index 5361172d..45625ab1 100644 +index 6167e85..cff9237 100644 --- a/arch/X86/X86IntelInstPrinter.c +++ b/arch/X86/X86IntelInstPrinter.c @@ -767,6 +767,9 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O) imm = imm & 0xffffffff; } - + + if (MI->csh->mode == CS_MODE_16) -+ imm = (imm & 0xf0000) + (imm&0xffff); ++ imm |= (MI->address >> 16) << 16; + printImm(MI, O, imm, true); - + if (MI->csh->detail) { diff --git a/shlr/capstone-patches/v5/mmm.patch b/shlr/capstone-patches/v5/mmm.patch deleted file mode 100644 index 9c781c9e30..0000000000 --- a/shlr/capstone-patches/v5/mmm.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/functions.mk b/functions.mk -index d734ce5d..d946cd34 100644 ---- a/functions.mk -+++ b/functions.mk -@@ -2,7 +2,6 @@ - # Common functions used by Makefile & tests/Makefile - - define compile -- @$(CC) -MM -MP -MT $@ -MT $(@:.o=.d) $(CFLAGS) $< > $(@:.o=.d) - ${CC} ${CFLAGS} -c $< -o $@ - endef - diff --git a/shlr/capstone.sh b/shlr/capstone.sh index f603170f4d..0afefb2e74 100755 --- a/shlr/capstone.sh +++ b/shlr/capstone.sh @@ -26,14 +26,16 @@ fatal_msg() { patch_capstone() { echo "[capstone] Applying patches..." if [ "$CS_BRA" = next ]; then - CV=v5 + CV=v6 else - CV=v4 + CV=v5 + fi + if [ -n "`ls ../capstone-patches/$CV/ 2> /dev/null`" ]; then + for patchfile in ../capstone-patches/$CV/*.patch ; do + echo "Patch $patchFile" + patch -p 1 < "${patchfile}" + done fi - for patchfile in ../capstone-patches/$CV/*.patch ; do - echo "Patch $patchFile" - patch -p 1 < "${patchfile}" - done } parse_capstone_tip() { diff --git a/shlr/meson.build b/shlr/meson.build index 6566e65bcc..dee689de8b 100644 --- a/shlr/meson.build +++ b/shlr/meson.build @@ -18,21 +18,20 @@ if not capstone_dep.found() or not get_option('use_sys_capstone') patches_files = [] # NOTE: when you update CS_TIP or CS_BRA, also update them in shlr/Makefile - if capstone_version == 'v5' - CS_TIP = '8ae8f68ea3abb7a68071908bad02baa39742870c' + if capstone_version == 'next' + CS_TIP = 'a4df92eda647e739432860682be638da1b8b901a' CS_BRA = 'next' patches_files = [ 'fix-x86-16.patch', - 'mmm.patch' ] - elif capstone_version == 'v3' - CS_TIP = '61bf71c771680033651f16cff832446e421847b1' - CS_BRA = 'v3' + elif capstone_version == 'v5' + CS_TIP = 'e1af2e249ab85c70594a8c975f27d072278257fb' + CS_BRA = 'v5' patches_files = [ - 'capstone-include.patch' + 'fix-x86-16.patch' ] elif capstone_version == 'v4' - CS_TIP = '1d230532840a37ac032c6ab80128238fc930c6c1' + CS_TIP = '0efa3cc530ea188c0e03c945ab884ee19dd16342' CS_BRA = 'v4' patches_files = [ 'capstone-calloc.patch', @@ -40,6 +39,12 @@ if not capstone_dep.found() or not get_option('use_sys_capstone') 'sparc-crash.patch', 'sstream-null.patch' ] + elif capstone_version == 'v3' + CS_TIP = '61bf71c771680033651f16cff832446e421847b1' + CS_BRA = 'v3' + patches_files = [ + 'capstone-include.patch' + ] else error('Wrong capstone version selected. Please use one of the supported versions.') endif diff --git a/sys/build.sh b/sys/build.sh index 9ad5fb0bf7..728f6db3ec 100755 --- a/sys/build.sh +++ b/sys/build.sh @@ -53,6 +53,9 @@ ABSPREFIX=`realpath ${PREFIX} 2> /dev/null` if [ "${USE_CS4}" = 1 ]; then CFGARG="${CFGARG} --with-capstone4" fi +if [ "${USE_CSNEXT}" = 1 ]; then + CFGARG="${CFGARG} --with-capstone-next" +fi if [ "${OSNAME}" = Linux -a -n "${PREFIX}" -a "${PREFIX}" != /usr ]; then CFGARG="${CFGARG} --with-rpath" diff --git a/sys/install.sh b/sys/install.sh index 0697392b5f..f56b6cfd0d 100755 --- a/sys/install.sh +++ b/sys/install.sh @@ -27,6 +27,7 @@ if [ $? = 0 ]; then fi export USE_CS4=0 +export USE_CSNEXT=0 # if owner of sys/install.sh != uid && uid == 0 { exec sudo -u id -A $SUDO_UID sys/install.sh $* } ARGS="" while : ; do