From 3863b5af1e46ecb3fb60426f4975b71ad6a1f3d6 Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 28 Nov 2013 04:57:51 +0100 Subject: [PATCH 1/3] Use proper Makefile targets in tests --- tests/Makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 56cb43f942..f8baa5e1aa 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -12,12 +12,24 @@ LIBNAME = capstone .PHONY: all clean win_test -all: test.o test_detail.o test_x86.o test_arm64.o test_arm.o test_mips.o +all: test test_detail test_x86 test_arm64 test_arm test_mips + +test: test.o ${CC} $(CFLAGS) test.o -O3 -Wall -l$(LIBNAME) -o test + +test_detail: test_detail.o ${CC} $(CFLAGS) test_detail.o -O3 -Wall -l$(LIBNAME) -o test_detail + +test_x86: test_x86.o ${CC} $(CFLAGS) test_x86.o -O3 -Wall -l$(LIBNAME) -o test_x86 + +test_arm64: test_arm64.o ${CC} $(CFLAGS) test_arm64.o -O3 -Wall -l$(LIBNAME) -o test_arm64 + +test_arm: test_arm.o ${CC} $(CFLAGS) test_arm.o -O3 -Wall -l$(LIBNAME) -o test_arm + +test_mips: test_mips.o ${CC} $(CFLAGS) test_mips.o -O3 -Wall -l$(LIBNAME) -o test_mips # Mingw32 From 9bc4a4ac2d927aec845b5c72c45841f45345d240 Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 28 Nov 2013 05:02:18 +0100 Subject: [PATCH 2/3] Add initial Vala bindings --- bindings/vala/Makefile | 2 ++ bindings/vala/capstone.pc | 5 ++++ bindings/vala/capstone.vapi | 46 +++++++++++++++++++++++++++++++++++++ bindings/vala/test.vala | 28 ++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 bindings/vala/Makefile create mode 100644 bindings/vala/capstone.pc create mode 100644 bindings/vala/capstone.vapi create mode 100644 bindings/vala/test.vala diff --git a/bindings/vala/Makefile b/bindings/vala/Makefile new file mode 100644 index 0000000000..036045d968 --- /dev/null +++ b/bindings/vala/Makefile @@ -0,0 +1,2 @@ +all: + PKG_CONFIG_PATH=$$PWD valac test.vala --vapidir . --pkg capstone diff --git a/bindings/vala/capstone.pc b/bindings/vala/capstone.pc new file mode 100644 index 0000000000..ddf9af7b14 --- /dev/null +++ b/bindings/vala/capstone.pc @@ -0,0 +1,5 @@ +Name: capstone +Description: capstone engine disassembler library +Version: 0.1 +Libs: ../../libcapstone.a +Cflags: -I../../include diff --git a/bindings/vala/capstone.vapi b/bindings/vala/capstone.vapi new file mode 100644 index 0000000000..d4c7dd8f2d --- /dev/null +++ b/bindings/vala/capstone.vapi @@ -0,0 +1,46 @@ +[CCode (cprefix="CS_")] +namespace Capstone { + [CCode (cname="cs_insn", cheader_filename="capstone.h")] + //[CCode (cname="cs_insn", cheader_filename="capstone.h", copy_function="", destroy_function="")] + public struct Insn { + uint32 id; + uint64 addr; + uint16 size; + string mnemonic; + string op_str; + int[] regs_read; + int[] regs_write; + int[] groups; + } + + [CCode (cheader_filename="capstone.h", cprefix="CS_ARCH_")] + public enum ARCH { + ARM = 0, + ARM64 = 1, + MIPS = 2, + X86 = 3 + } + + [CCode (cheader_filename="capstone.h", cprefix="CS_MODE_")] + public enum MODE { + LITTLE_ENDIAN = 0, + SYNTAX_INTEL = 0, + ARM = 0, + [CCode (cname="CS_MODE_16")] + B16 = 1<<1, + [CCode (cname="CS_MODE_32")] + B32 = 1<<2, + [CCode (cname="CS_MODE_64")] + B64 = 1<<3, + THUMB = 1<<4, + SYNTAX_ATT = 1<<30, + BIG_ENDIAN = 1<<31 + } + [CCode (cname="cs_open")] + public static int open (ARCH arch, MODE mode, out uint64 handle); + [CCode (cname="cs_close")] + public static int close (uint64 handle); + + [CCode (cname="cs_disasm_dyn")] + public static int disasm_dyn (uint64 handle, void* code, int len, uint64 addr, int count, out Insn* insn ); +} diff --git a/bindings/vala/test.vala b/bindings/vala/test.vala new file mode 100644 index 0000000000..4bed38d3c7 --- /dev/null +++ b/bindings/vala/test.vala @@ -0,0 +1,28 @@ +/* Vala/Capstone Example -- pancake */ + +using Capstone; + +void main() { + Insn* insn; + uint64 handle; + + if (Capstone.open (Capstone.ARCH.X86, + Capstone.MODE.B32, out handle) != 0) { + stderr.printf ("Error initializing capstone\n"); + return; + } + + int n = Capstone.disasm_dyn (handle, + "\xc5\xf1\x6c\xc0\x90\xcc", + 6, 0x8048000, 0, out insn); + if (n == 0) { + stderr.printf ("invalid\n"); + } else + if (n>0) { + for (int i = 0; i Date: Thu, 28 Nov 2013 05:30:20 +0100 Subject: [PATCH 3/3] Do not let the archive grow --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 1378b0f061..062587bdcb 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ lib: $(LIBOBJ) #strip lib$(LIBNAME).$(EXT) archive: $(LIBOBJ) + rm -f lib$(LIBNAME).a $(AR) q lib$(LIBNAME).a $(LIBOBJ) $(RANLIB) lib$(LIBNAME).a