diff --git a/bindings/java/Makefile b/bindings/java/Makefile old mode 100644 new mode 100755 index 94fcfee6..4d3af3e5 --- a/bindings/java/Makefile +++ b/bindings/java/Makefile @@ -1,3 +1,6 @@ + +.PHONY: gen_const clean + JAVA_HOME := $(shell jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));') JAVA_INC := $(shell realpath $(JAVA_HOME)/../include) @@ -63,3 +66,13 @@ jar: jarfiles install: lib jar cp libunicorn_java$(LIB_EXT) $(JAVA_HOME)/lib/ext cp $(JARFILE) $(JAVA_HOME)/lib/ext + +gen_const: + cd .. && python const_generator.py java + +clean: + rm unicorn/*.class + rm samples/*.class + rm *.so + rm *.dylib + rm *.dll \ No newline at end of file diff --git a/bindings/java/samples/SampleNetworkAuditing.java b/bindings/java/samples/SampleNetworkAuditing.java old mode 100644 new mode 100755 index 7242b9e7..c275a25d --- a/bindings/java/samples/SampleNetworkAuditing.java +++ b/bindings/java/samples/SampleNetworkAuditing.java @@ -245,25 +245,25 @@ public class SampleNetworkAuditing { static { SOCKET_TYPES = new Hashtable(); ADDR_FAMILY = new Hashtable(); - SOCKET_TYPES.put(1, "SOCK_STREAM"); - SOCKET_TYPES.put(2, "SOCK_DGRAM"); - SOCKET_TYPES.put(3, "SOCK_RAW"); - SOCKET_TYPES.put(4, "SOCK_RDM"); - SOCKET_TYPES.put(5, "SOCK_SEQPACKET"); - SOCKET_TYPES.put(10, "SOCK_PACKET"); + 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(0, "AF_UNSPEC"); - ADDR_FAMILY.put(1, "AF_UNIX"); - ADDR_FAMILY.put(2, "AF_INET"); - ADDR_FAMILY.put(3, "AF_AX25"); - ADDR_FAMILY.put(4, "AF_IPX"); - ADDR_FAMILY.put(5, "AF_APPLETALK"); - ADDR_FAMILY.put(6, "AF_NETROM"); - ADDR_FAMILY.put(7, "AF_BRIDGE"); - ADDR_FAMILY.put(8, "AF_AAL5"); - ADDR_FAMILY.put(9, "AF_X25"); - ADDR_FAMILY.put(10, "AF_INET6"); - ADDR_FAMILY.put(12, "AF_MAX"); + 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 @@ -395,7 +395,7 @@ public class SampleNetworkAuditing { 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); + mu.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory mu.mem_write(ADDRESS, code); diff --git a/bindings/java/samples/Sample_arm.java b/bindings/java/samples/Sample_arm.java old mode 100644 new mode 100755 index 8d6ddebe..ca3a8163 --- a/bindings/java/samples/Sample_arm.java +++ b/bindings/java/samples/Sample_arm.java @@ -51,7 +51,7 @@ public class Sample_arm { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, ARM_CODE); @@ -93,7 +93,7 @@ public class Sample_arm { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, THUMB_CODE); diff --git a/bindings/java/samples/Sample_arm64.java b/bindings/java/samples/Sample_arm64.java old mode 100644 new mode 100755 index d406d176..12464eaa --- a/bindings/java/samples/Sample_arm64.java +++ b/bindings/java/samples/Sample_arm64.java @@ -79,7 +79,7 @@ public class Sample_arm64 { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, ARM_CODE); diff --git a/bindings/java/samples/Sample_m68k.java b/bindings/java/samples/Sample_m68k.java old mode 100644 new mode 100755 index 1988c500..129cad2e --- a/bindings/java/samples/Sample_m68k.java +++ b/bindings/java/samples/Sample_m68k.java @@ -95,7 +95,7 @@ public class Sample_m68k { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, M68K_CODE); diff --git a/bindings/java/samples/Sample_mips.java b/bindings/java/samples/Sample_mips.java old mode 100644 new mode 100755 index 60c85fab..14ac5d14 --- a/bindings/java/samples/Sample_mips.java +++ b/bindings/java/samples/Sample_mips.java @@ -78,7 +78,7 @@ public class Sample_mips { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, MIPS_CODE_EB); @@ -116,7 +116,7 @@ public class Sample_mips { Unicorn u = new Unicorn(Unicorn.UC_ARCH_MIPS, Unicorn.UC_MODE_MIPS32); // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, MIPS_CODE_EL); diff --git a/bindings/java/samples/Sample_sparc.java b/bindings/java/samples/Sample_sparc.java old mode 100644 new mode 100755 index 0b109f86..e30daf60 --- a/bindings/java/samples/Sample_sparc.java +++ b/bindings/java/samples/Sample_sparc.java @@ -79,7 +79,7 @@ public class Sample_sparc { Unicorn u = new Unicorn(Unicorn.UC_ARCH_SPARC, Unicorn.UC_MODE_BIG_ENDIAN); // map 2MB memory for this emulation - u.mem_map(ADDRESS, 2 * 1024 * 1024); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, SPARC_CODE); diff --git a/bindings/java/samples/Sample_x86.java b/bindings/java/samples/Sample_x86.java old mode 100644 new mode 100755 index 5f847428..f92e1392 --- a/bindings/java/samples/Sample_x86.java +++ b/bindings/java/samples/Sample_x86.java @@ -91,7 +91,7 @@ public class Sample_x86 { 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); + u.mem_map(0xaaaa0000, 2 * 1024*1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // return true to indicate we want to continue return true; } @@ -193,7 +193,7 @@ public class Sample_x86 { } // map 2MB memory for this emulation - uc.mem_map(ADDRESS, 2 * 1024 * 1024); + uc.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory try { @@ -251,7 +251,7 @@ public class Sample_x86 { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, X86_CODE32_INOUT); @@ -294,7 +294,7 @@ public class Sample_x86 { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, X86_CODE32_JUMP); @@ -326,7 +326,7 @@ public class Sample_x86 { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, X86_CODE32_LOOP); @@ -363,7 +363,7 @@ public class Sample_x86 { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, X86_CODE32_MEM_READ); @@ -410,7 +410,7 @@ public class Sample_x86 { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, X86_CODE32_MEM_WRITE); @@ -470,7 +470,7 @@ public class Sample_x86 { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, X86_CODE32_JMP_INVALID); @@ -528,7 +528,7 @@ public class Sample_x86 { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, X86_CODE64); @@ -615,7 +615,7 @@ public class Sample_x86 { Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_16); // map 8KB memory for this emulation - u.mem_map(0, 8 * 1024); + u.mem_map(0, 8 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(0, X86_CODE16); diff --git a/bindings/java/samples/Shellcode.java b/bindings/java/samples/Shellcode.java old mode 100644 new mode 100755 index 7a15e7a3..9a1c1c81 --- a/bindings/java/samples/Shellcode.java +++ b/bindings/java/samples/Shellcode.java @@ -121,7 +121,7 @@ public class Shellcode { 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); + u.mem_map(ADDRESS, 2 * 1024 * 1024, Unicorn.UC_PROT_READ | Unicorn.UC_PROT_WRITE); // write machine code to be emulated to memory u.mem_write(ADDRESS, X86_CODE32_SELF); diff --git a/bindings/java/unicorn/Unicorn.java b/bindings/java/unicorn/Unicorn.java index 7d94c345..985a322d 100755 --- a/bindings/java/unicorn/Unicorn.java +++ b/bindings/java/unicorn/Unicorn.java @@ -623,7 +623,7 @@ public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, S * @param address Base address of the memory range * @param size Size of the memory block. */ - public native void mem_map(long address, long size) throws UnicornException; + public native void mem_map(long address, long size, int perms) throws UnicornException; } diff --git a/bindings/java/unicorn_Unicorn.c b/bindings/java/unicorn_Unicorn.c old mode 100644 new mode 100755 index aa141bb2..cd0428f9 --- a/bindings/java/unicorn_Unicorn.c +++ b/bindings/java/unicorn_Unicorn.c @@ -502,13 +502,13 @@ JNIEXPORT void JNICALL Java_unicorn_Unicorn_hook_1del /* * Class: unicorn_Unicorn * Method: mem_map - * Signature: (JJ)V + * Signature: (JJI)V */ JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1map - (JNIEnv *env, jobject self, jlong address, jlong size) { + (JNIEnv *env, jobject self, jlong address, jlong size, jint perms) { uch handle = getHandle(env, self); - uc_err err = uc_mem_map(handle, (uint64_t)address, (size_t)size); + uc_err err = uc_mem_map(handle, (uint64_t)address, (size_t)size, (uint32_t)perms); if (err != UC_ERR_OK) { throwException(env, err); } diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h old mode 100644 new mode 100755 index 556b6c17..fbe5991c --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -95,7 +95,7 @@ typedef enum uc_mode { UC_MODE_MIPS32R6 = 1 << 6, // Mips32r6 ISA UC_MODE_V9 = 1 << 4, // SparcV9 mode (Sparc) UC_MODE_QPX = 1 << 4, // Quad Processing eXtensions mode (PPC) - UC_MODE_BIG_ENDIAN = 1 << 31, // big-endian mode + UC_MODE_BIG_ENDIAN = 1 << 30, // big-endian mode UC_MODE_MIPS32 = UC_MODE_32, // Mips32 ISA (Mips) UC_MODE_MIPS64 = UC_MODE_64, // Mips64 ISA (Mips) } uc_mode;