unicorn/bindings/java
Martin Atkins 7d8fe2ab11
riscv: Expose privilege level as pseudo-register PRIV (#1989)
Unlike some other architectures, RISC-V does not expose the current
privilege mode in any architecturally-defined register. That is intentional
to make it easier to implement virtualization in software, but a Unicorn
caller operates outside of the emulated hart and so it can and should be
able to observe and change the current privilege mode in order to properly
emulate certain behaviors of a real CPU.

The current privilege level is therefore now exposed as a new
pseudo-register using the name "priv", which matches the name of the
virtual register used by RISC-V's debug extension to allow the debugger
to read and change the privilege mode while the hart is halted. Unicorn's
use of it is conceptually similar to a debugger.

The bit encoding of this register is the same as specified in RISC-V Debug
Specification v1.0-rc3 Section 4.10.1. It's defined as a "virtual"
register exposing a subset of fields from the dcsr register, although here
it's implemented directly inside the Unicorn code because QEMU doesn't
currently have explicit support for the CSRs from the debug specification.
If it supports "dcsr" in a future release then this implementation could
change to wrap reading and writing that CSR and then projecting the "prv"
and "v" bitfields into the correct locations for the virtual register.
2024-11-11 21:09:45 +08:00
..
src riscv: Expose privilege level as pseudo-register PRIV (#1989) 2024-11-11 21:09:45 +08:00
.gitignore Replace javah by javac -h, only write new constant files if something changes. 2023-07-06 20:12:36 -07:00
CMakeLists.txt Bump version and generate bindings 2024-09-21 23:00:57 +08:00
eclipse-formatter.xml
Makefile Bump version and generate bindings 2024-09-21 23:00:57 +08:00
pom.xml Tag and release 2.1.1 2024-09-26 18:44:51 +08:00
README.md
unicorn_Unicorn.c

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.