unicorn/bindings/java
Robert Xiao f55e7834ba Replace javah by javac -h, only write new constant files if something changes.
The const_generator changes help to ensure that e.g. Java rebuilds don't keep
rebuilding everything.
2023-07-06 20:12:36 -07:00
..
src Switch to Maven to build the Java bits. 2023-06-29 16:08:18 -07:00
.gitignore Replace javah by javac -h, only write new constant files if something changes. 2023-07-06 20:12:36 -07:00
eclipse-formatter.xml Reformat Java bindings. 2023-06-17 14:17:57 -07:00
Makefile Replace javah by javac -h, only write new constant files if something changes. 2023-07-06 20:12:36 -07:00
pom.xml Replace javah by javac -h, only write new constant files if something changes. 2023-07-06 20:12:36 -07:00
README.md Switch to Maven to build the Java bits. 2023-06-29 16:08:18 -07:00
unicorn_Unicorn.c Switch Java bindings to reg2 API. 2023-06-29 16:37:42 -07:00

This documentation explains how to install the Java binding for Unicorn from source.

  1. 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.

  2. Install a JDK for your platform.

  3. Install Maven: https://maven.apache.org/install.html.

  4. 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.