Fix support for capstone3

This commit is contained in:
pancake 2016-01-22 20:53:01 +01:00
parent 5b199f2578
commit 0d0e4e985d
12 changed files with 86 additions and 26 deletions

View file

@ -72,7 +72,7 @@ depgraph.png:
cd libr ; perl depgraph.pl | dot -Tpng -odepgraph.png
android:
@if [ -z "$(NDK_ARCH)" ]; then echo "Set NDK_ARCH=[arm|mips|x86]" ; false; fi
@if [ -z "$(NDK_ARCH)" ]; then echo "Set NDK_ARCH=[arm|arm64|mips|x86]" ; false; fi
sys/android-${NDK_ARCH}.sh
w32dist:
@ -314,6 +314,7 @@ tests:
osx-sign:
$(MAKE) -C binr/radare2 osx-sign
osx-sign-libs:
$(MAKE) -C binr/radare2 osx-sign-libs

35
doc/capstone.md Normal file
View file

@ -0,0 +1,35 @@
Capstone
========
Capstone Engine is the disassembler engine used by radare2 by default for
some architectures.
Radare2 ships its own version of capstone based on the -next branch with
some minor patches. The problem is that latest release have some compile
time dependencies that make compilation with older releases a bit harder.
In order to build r2 against capstone3 you can do the following things:
$ cd shlr
$ rm -rf capstone
$ make capstone-sync CS_RELEASE=1
$ make -j4
If you are a distro packager it will be necessary to fix the include path
in the package script like this:
$ ln -fs /usr/include libr/include/capstone
This is because capstone3 pkg-config file references the files directly
inside the /usr/include/capstone directory. so the includes in code must
be like this:
#include <capstone.h>
#include <arm.h>
This was fixed in capstone4 that will be released later this year, but as
long as distros will take some time to upgrade it is good to provide a
clean workaround to support both without having to change all the C files
#include <capstone/capstone.h>
#include <capstone/arm.h>

View file

@ -1,4 +1,5 @@
include ../config.mk
EXTRA_TARGETS+=do
EXTRA_CLEAN=doclean

View file

@ -25,8 +25,13 @@
#define ISREG(x) insn->detail->arm.operands[x].type == ARM_OP_REG
#define ISREG64(x) insn->detail->arm64.operands[x].type == ARM64_OP_REG
#define ISMEM(x) insn->detail->arm.operands[x].type == ARM_OP_MEM
#if CS_API_MAJOR > 3
#define LSHIFT(x) insn->detail->arm.operands[x].mem.lshift
#define LSHIFT2(x) insn->detail->arm.operands[x].shift.value
#else
#define LSHIFT(x) 0
#define LSHIFT2(x) 0
#endif
#define OPCOUNT() insn->detail->arm.op_count
#define ISSHIFTED(x) (insn->detail->arm.operands[x].shift.type != ARM_SFT_INVALID && insn->detail->arm.operands[x].shift.value != 0)

View file

@ -6,7 +6,6 @@
#include <capstone/systemz.h>
// instruction set: http://www.tachyonsoft.com/inst390m.htm
#if CS_API_MAJOR < 2
#error Old Capstone not supported
#endif

View file

@ -1,7 +1,8 @@
N=anal_arm_cs
OBJ_ARM_CS=anal_arm_cs.o
include p/capstone.mk
include $(CURDIR)capstone.mk
STATIC_OBJ+=${OBJ_ARM_CS}
TARGET_ARM_CS=$(N).${EXT_SO}

View file

@ -1,9 +1,11 @@
ifeq ($(USE_CAPSTONE),1)
# use system capstone
CS_CFLAGS=${CAPSTONE_CFLAGS}
CS_LDFLAGS=${CAPSTONE_LDFLAGS}
else
CS_CFLAGS=-I../../shlr/capstone/include
CS_CFLAGS+=-I../../../shlr/capstone/include
# use capstone from shlr/capstone
CS_CFLAGS=-I${SHLR}/capstone/include
CS_LDFLAGS=$(SHLR)/capstone/libcapstone.a
#SHARED_OBJ+=${CS_LDFLAGS}
endif

View file

@ -1,5 +1,7 @@
OBJ_M68K=anal_m68k.o
include ${CURDIR}capstone.mk
STATIC_OBJ+=${OBJ_M68K}
TARGET_M68K=anal_m68k.${EXT_SO}

View file

@ -1,6 +1,6 @@
OBJ_MIPS_CS=anal_mips_cs.o
include p/capstone.mk
include $(CURDIR)capstone.mk
STATIC_OBJ+=$(OBJ_MIPS_CS)
TARGET_MIPS_CS=anal_mips_cs.${EXT_SO}

View file

@ -1,6 +1,7 @@
OBJ_PPC_CS=anal_ppc_cs.o
#include p/capstone.mk
include $(CURDIR)capstone.mk
STATIC_OBJ+=${OBJ_PPC_CS}
TARGET_PPC_CS=anal_ppc_cs.${EXT_SO}

View file

@ -1,6 +1,6 @@
OBJ_X86_CS=anal_x86_cs.o
include ${CURDIR}capstone.mk
include $(CURDIR)capstone.mk
STATIC_OBJ+=$(OBJ_X86_CS)

View file

@ -6,9 +6,17 @@ include ../mk/platform.mk
_INCLUDE_MK_GCC_=
include ../mk/${COMPILER}.mk
# Build against last capstone release or next
CS_RELEASE=0
WGET?=wget
CS_VER=3.0
CS_TAR=http://capstone-engine.org/download/$(CS_VER)/capstone-$(CS_VER).tgz
ifeq ($(CS_RELEASE),1)
CS_VER=3.0.4
CS_TAR=https://codeload.github.com/aquynh/capstone/tar.gz/$(CS_VER)
#CS_TAR=http://capstone-engine.org/download/$(CS_VER)/capstone-$(CS_VER).tgz
CS_PATCHES=0
else
CS_TAR=
CS_URL=$(GIT_PREFIX)github.com/aquynh/capstone.git
CS_UPD=20160120
@ -18,6 +26,7 @@ CS_TIP=3722c74f69ffa5b705d36cd49c19acdf958a9b7a
CS_REV=
#21b9b25e9dae4af0ef309d4089a54e53b8f5b479
CS_PATCHES=1
endif
.PHONY: capstone-sync capstone-build all clean mrproper libgdbr libwind
@ -196,7 +205,26 @@ capstone-build:
else
ifeq ($(CS_TAR),)
ifeq ($(CS_RELEASE),1)
capstone-sync: capstone
capstone-clean:
cd capstone ; $(MAKE) clean
capstone: capstone-$(CS_VER).tar.gz
tar xzvf capstone-$(CS_VER).tar.gz
rm -rf capstone
mv capstone-$(CS_VER) capstone
ifeq ($(CS_PATCHES),1)
cd capstone ; for PATCH in ../capstone-patches/* ; do patch -p1 < $$PATCH ; done
endif
mkdir -p capstone/include/capstone
cp -rf capstone/include/*.h capstone/include/capstone
capstone-$(CS_VER).tar.gz:
$(WGET) --no-check-certificate -O capstone-$(CS_VER).tar.gz -c $(CS_TAR)
else
capstone: capstone-sync
capstone-sync:
@ -207,21 +235,6 @@ ifeq ($(CS_PATCHES),1)
endif
.PHONY: capstone
else
capstone-sync: capstone
capstone-clean:
cd capstone ; $(MAKE) clean
capstone: capstone-$(CS_VER).tar.gz
tar xzvf capstone-$(CS_VER).tar.gz
rm -rf capstone
mv capstone-$(CS_VER) capstone
cd capstone ; for PATCH in ../capstone-patches/* ; do patch -p1 < $$PATCH ; done
capstone-$(CS_VER).tar.gz:
$(WGET) --no-check-certificate -O capstone-$(CS_VER).tar.gz -c $(CS_TAR)
endif
CAPSTONE_CFLAGS=-g