Skip to content

Use proper Makefile targets in tests and add Vala bindings #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions bindings/vala/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
PKG_CONFIG_PATH=$$PWD valac test.vala --vapidir . --pkg capstone
5 changes: 5 additions & 0 deletions bindings/vala/capstone.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Name: capstone
Description: capstone engine disassembler library
Version: 0.1
Libs: ../../libcapstone.a
Cflags: -I../../include
46 changes: 46 additions & 0 deletions bindings/vala/capstone.vapi
Original file line number Diff line number Diff line change
@@ -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 );
}
28 changes: 28 additions & 0 deletions bindings/vala/test.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Vala/Capstone Example -- pancake <pancake@nopcode.org> */

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<n; i++) {
var op = &insn[i];
stdout.printf ("%s %s\n", op.mnemonic, op.op_str);
}
}
Capstone.close (handle);
}
14 changes: 13 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down