-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1833 from nneonneo/rework-java-api
Rework the Java bindings
- Loading branch information
Showing
97 changed files
with
14,056 additions
and
7,465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
.PHONY: gen_const clean jar all lib samples install | ||
# Makefile for the native JNI library. Automatically called by Maven. | ||
|
||
all: gen_const | ||
$(MAKE) -f Makefile.build all | ||
JAVA_HOME ?= $(shell java -XshowSettings:properties -version 2>&1 | sed -n 's/ *java.home = //p') | ||
|
||
lib: | ||
$(MAKE) -f Makefile.build lib | ||
ifeq ($(JAVA_HOME),) | ||
$(error JAVA_HOME could not be determined; please set it manually (make JAVA_HOME=...)) | ||
endif | ||
|
||
samples: | ||
$(MAKE) -f Makefile.build samples | ||
JAVA_INC := $(JAVA_HOME)/include | ||
JAVA_PLATFORM_INC := $(shell dirname `find $(JAVA_INC) -name jni_md.h`) | ||
UNICORN_INC := ../../include | ||
|
||
jar: | ||
$(MAKE) -f Makefile.build jar | ||
OS := $(shell uname) | ||
ifeq ($(OS),Darwin) | ||
LIB_EXT=.dylib | ||
else ifeq ($(OS),Linux) | ||
LIB_EXT=.so | ||
else | ||
LIB_EXT=.dll | ||
endif | ||
|
||
install: lib jar | ||
$(MAKE) -f Makefile.build install | ||
all: libunicorn_java$(LIB_EXT) | ||
|
||
uninstall: | ||
$(MAKE) -f Makefile.build uninstall | ||
CC=gcc | ||
CFLAGS=-fPIC | ||
LDFLAGS=-shared -fPIC | ||
# May also use -lunicorn to dynamically link against the installed unicorn | ||
LIBS=../../build/libunicorn.a | ||
INCS=-I target/headers -I$(JAVA_INC) -I$(JAVA_PLATFORM_INC) -I$(UNICORN_INC) | ||
|
||
gen_const: | ||
cd .. && python3 const_generator.py java | ||
OBJS=unicorn_Unicorn.o | ||
|
||
unicorn_Unicorn.o: unicorn_Unicorn.c target/headers/unicorn_Unicorn.h | ||
$(CC) -O2 -Wall -Wextra -Wno-unused-parameter -c $(CFLAGS) $(INCS) $< -o $@ | ||
|
||
libunicorn_java$(LIB_EXT): $(OBJS) | ||
$(CC) -o $@ $(LDFLAGS) $(OBJS) $(LIBS) | ||
|
||
clean: | ||
rm -f unicorn/*.class | ||
rm -f samples/*.class | ||
rm -f *.so | ||
rm -f *.dylib | ||
rm -f *.dll | ||
rm -f libunicorn_java$(LIB_EXT) | ||
rm -f $(OBJS) | ||
|
||
.PHONY: all clean |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
This documentation explains how to install the Java binding for Unicorn | ||
from source. | ||
|
||
0. Follow `docs/COMPILE.md` in the root directory to compile the core to the `build` directory. | ||
|
||
Note: by default, the Java binding native library will be built by statically linking to | ||
`../../build/libunicorn.a`, thereby removing `libunicorn` as a runtime dependency, but | ||
making the produced native library `libunicorn_java` bigger. | ||
|
||
If you instead want to dynamically link against the installed `libunicorn`, change | ||
`LIBS=../../build/libunicorn.a` to `LIBS=-lunicorn` in `Makefile`. | ||
|
||
1. Install a JDK for your platform. | ||
|
||
2. Install Maven: https://maven.apache.org/install.html. | ||
|
||
3. Change directories into the java bindings and build the Maven package: | ||
|
||
$ mvn package | ||
|
||
This will automatically build and test the Unicorn Java bindings. | ||
|
||
The bindings consist of the native JNI library (`libunicorn_java.{so,dylib,dll}`) | ||
and the Java JAR (`target/unicorn-2.xx.jar`). You will need to have the native | ||
library on `java.library.path` and the JAR on your classpath. | ||
|
||
The `src/main/test/java` directory contains some sample code to show how to use Unicorn API. | ||
`samples` is a set of sample classes showcasing the various features of the Unicorn API, | ||
while `tests` is a set of JUnit tests for the API. | ||
|
||
- `Sample_<arch>.java`: | ||
These show how to access architecture-specific information for each | ||
architecture. | ||
|
||
- `Shellcode.java`: | ||
This shows how to analyze a Linux shellcode. | ||
|
||
- `SampleNetworkAuditing.java`: | ||
Unicorn sample for auditing network connection and file handling in shellcode. |
Oops, something went wrong.