mirror of
https://github.com/Vita3K/unicorn.git
synced 2024-11-23 13:29:40 +00:00
Update java bindings for new version of uc_mem_map
This commit is contained in:
parent
85ad7725da
commit
1d6bd17a13
13
bindings/java/Makefile
Normal file → Executable file
13
bindings/java/Makefile
Normal file → Executable file
@ -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
|
38
bindings/java/samples/SampleNetworkAuditing.java
Normal file → Executable file
38
bindings/java/samples/SampleNetworkAuditing.java
Normal file → Executable file
@ -245,25 +245,25 @@ public class SampleNetworkAuditing {
|
||||
static {
|
||||
SOCKET_TYPES = new Hashtable<Long, String>();
|
||||
ADDR_FAMILY = new Hashtable<Long, String>();
|
||||
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);
|
||||
|
4
bindings/java/samples/Sample_arm.java
Normal file → Executable file
4
bindings/java/samples/Sample_arm.java
Normal file → Executable file
@ -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);
|
||||
|
2
bindings/java/samples/Sample_arm64.java
Normal file → Executable file
2
bindings/java/samples/Sample_arm64.java
Normal file → Executable file
@ -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);
|
||||
|
2
bindings/java/samples/Sample_m68k.java
Normal file → Executable file
2
bindings/java/samples/Sample_m68k.java
Normal file → Executable file
@ -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);
|
||||
|
4
bindings/java/samples/Sample_mips.java
Normal file → Executable file
4
bindings/java/samples/Sample_mips.java
Normal file → Executable file
@ -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);
|
||||
|
2
bindings/java/samples/Sample_sparc.java
Normal file → Executable file
2
bindings/java/samples/Sample_sparc.java
Normal file → Executable file
@ -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);
|
||||
|
20
bindings/java/samples/Sample_x86.java
Normal file → Executable file
20
bindings/java/samples/Sample_x86.java
Normal file → Executable file
@ -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);
|
||||
|
2
bindings/java/samples/Shellcode.java
Normal file → Executable file
2
bindings/java/samples/Shellcode.java
Normal file → Executable file
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
6
bindings/java/unicorn_Unicorn.c
Normal file → Executable file
6
bindings/java/unicorn_Unicorn.c
Normal file → Executable file
@ -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);
|
||||
}
|
||||
|
2
include/unicorn/unicorn.h
Normal file → Executable file
2
include/unicorn/unicorn.h
Normal file → Executable file
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user