Merge branch 'master' of github.com:unicorn-engine/unicorn into fpip_update

This commit is contained in:
mothran 2015-08-30 11:13:23 -07:00
commit 2febbb6021
37 changed files with 781 additions and 645 deletions

View file

@ -66,11 +66,11 @@ Unicorn requires few dependent packages as followings
- To compile for current platform, run: - To compile for current platform, run:
$ ./make.sh $ ./make.sh
- On 64-bit OS, run the command below to cross-compile Unicorn for 32-bit binary: - On 64-bit OS, run the command below to cross-compile Unicorn for 32-bit binary:
$ ./make.sh nix32 $ ./make.sh nix32
@ -78,11 +78,11 @@ Unicorn requires few dependent packages as followings
To install Unicorn, run: To install Unicorn, run:
$ sudo ./make.sh install $ sudo ./make.sh install
For FreeBSD/OpenBSD, where sudo is unavailable, run: For FreeBSD/OpenBSD, where sudo is unavailable, run:
$ su; ./make.sh install $ su; ./make.sh install
Users are then required to enter root password to copy Unicorn into machine Users are then required to enter root password to copy Unicorn into machine
system directories. system directories.
@ -93,17 +93,17 @@ Unicorn requires few dependent packages as followings
NOTE: The core framework installed by "./make.sh install" consist of NOTE: The core framework installed by "./make.sh install" consist of
following files: following files:
/usr/include/unicorn/unicorn.h /usr/include/unicorn/unicorn.h
/usr/include/unicorn/x86.h /usr/include/unicorn/x86.h
/usr/include/unicorn/arm.h /usr/include/unicorn/arm.h
/usr/include/unicorn/arm64.h /usr/include/unicorn/arm64.h
/usr/include/unicorn/mips.h /usr/include/unicorn/mips.h
/usr/include/unicorn/ppc.h /usr/include/unicorn/ppc.h
/usr/include/unicorn/sparc.h /usr/include/unicorn/sparc.h
/usr/include/unicorn/m68k.h /usr/include/unicorn/m68k.h
/usr/include/unicorn/platform.h /usr/include/unicorn/platform.h
/usr/lib/libunicorn.so (for Linux/*nix), or /usr/lib/libunicorn.dylib (OSX) /usr/lib/libunicorn.so (for Linux/*nix), or /usr/lib/libunicorn.dylib (OSX)
/usr/lib/libunicorn.a /usr/lib/libunicorn.a
@ -112,19 +112,18 @@ Unicorn requires few dependent packages as followings
To cross-compile for Windows, Linux & gcc-mingw-w64-i686 (and also gcc-mingw-w64-x86-64 To cross-compile for Windows, Linux & gcc-mingw-w64-i686 (and also gcc-mingw-w64-x86-64
for 64-bit binaries) are required. for 64-bit binaries) are required.
- To cross-compile Windows 32-bit binary, simply run: - To cross-compile Windows 32-bit binary, simply run:
$ ./make.sh cross-win32 $ ./make.sh cross-win32
- To cross-compile Windows 64-bit binary, run: - To cross-compile Windows 64-bit binary, run:
$ ./make.sh cross-win64 $ ./make.sh cross-win64
Resulted files libunicorn.dll, libunicorn.dll.a & tests/test*.exe can then Resulted files unicorn.dll, unicorn.lib & samples/sample*.exe can then
be used on Windows machine. be used on Windows machine.
To run sample_x86.exe on Windows 32-bit, you need the following files: To run sample_x86.exe on Windows 32-bit, you need the following files:
- unicorn.dll - unicorn.dll
- /usr/i686-w64-mingw32/sys-root/mingw/bin/libglib-2.0-0.dll - /usr/i686-w64-mingw32/sys-root/mingw/bin/libglib-2.0-0.dll
- /usr/lib/gcc/i686-w64-mingw32/4.8/libgcc_s_sjlj-1.dll - /usr/lib/gcc/i686-w64-mingw32/4.8/libgcc_s_sjlj-1.dll
@ -145,17 +144,17 @@ Unicorn requires few dependent packages as followings
To cross-compile for iOS (iPhone/iPad/iPod), Mac OSX with XCode installed is required. To cross-compile for iOS (iPhone/iPad/iPod), Mac OSX with XCode installed is required.
- To cross-compile for ArmV7 (iPod 4, iPad 1/2/3, iPhone4, iPhone4S), run: - To cross-compile for ArmV7 (iPod 4, iPad 1/2/3, iPhone4, iPhone4S), run:
$ ./make.sh ios_armv7 $ ./make.sh ios_armv7
- To cross-compile for ArmV7s (iPad 4, iPhone 5C, iPad mini), run: - To cross-compile for ArmV7s (iPad 4, iPhone 5C, iPad mini), run:
$ ./make.sh ios_armv7s $ ./make.sh ios_armv7s
- To cross-compile for Arm64 (iPhone 5S, iPad mini Retina, iPad Air), run: - To cross-compile for Arm64 (iPhone 5S, iPad mini Retina, iPad Air), run:
$ ./make.sh ios_arm64 $ ./make.sh ios_arm64
- To cross-compile for all iDevices (armv7 + armv7s + arm64), run: - To cross-compile for all iDevices (armv7 + armv7s + arm64), run:
$ ./make.sh ios $ ./make.sh ios
Resulted files libunicorn.dylib, libunicorn.a & tests/test* can then Resulted files libunicorn.dylib, libunicorn.a & tests/test* can then
be used on iOS devices. be used on iOS devices.
@ -167,47 +166,69 @@ Unicorn requires few dependent packages as followings
To cross-compile for Android (smartphone/tablet), Android NDK is required. To cross-compile for Android (smartphone/tablet), Android NDK is required.
NOTE: Only ARM and ARM64 are currently supported. NOTE: Only ARM and ARM64 are currently supported.
$ NDK=/android/android-ndk-r10e ./make.sh cross-android arm $ NDK=/android/android-ndk-r10e ./make.sh cross-android arm
or or
$ NDK=/android/android-ndk-r10e ./make.sh cross-android arm64 $ NDK=/android/android-ndk-r10e ./make.sh cross-android arm64
Resulted files libunicorn.so, libunicorn.a & tests/test* can then Resulted files libunicorn.so, libunicorn.a & tests/test* can then
be used on Android devices. be used on Android devices.
[7] Compile on Windows with Cygwin [7] Compile on Windows with MinGW (MSYS2)
To compile under Cygwin gcc-mingw-w64-i686 or x86_64-w64-mingw32 run: To compile with MinGW you need to install MSYS2: https://msys2.github.io/
Follow the install instructions and don't forget to update the system packages as written in 5 & 6 paragraphs
- To compile Windows 32-bit binary with MinGW, run:
$ pacman -S make
$ pacman -S pkg-config
$ pacman -S mingw-w64-i686-glib2
$ pacman -S mingw-w64-i686-toolchain
$ ./make.sh cross-win32
- To compile Windows 32-bit binary under Cygwin, run: - To compile Windows 64-bit binary with MinGW, run:
$ pacman -S make
$ pacman -S pkg-config
$ pacman -S mingw-w64-x86_64-glib2
$ pacman -S mingw-w64-x86_64-toolchain
$ ./make.sh cross-win64
$ ./make.sh cygwin-mingw32 Resulted files unicorn.dll, unicorn.lib & samples/sample*.exe can then
- To compile Windows 64-bit binary under Cygwin, run:
$ ./make.sh cygwin-mingw64
Resulted files libunicorn.dll, libunicorn.dll.a & tests/test*.exe can then
be used on Windows machine. be used on Windows machine.
To run sample_x86.exe on Windows 32-bit, you need the following files:
- unicorn.dll
- C:\msys32\mingw32\bin\libiconv-2.dll
- C:\msys32\mingw32\bin\libintl-8.dll
- C:\msys32\mingw32\bin\libglib-2.0-0.dll
- C:\msys32\mingw32\bin\libgcc_s_seh-1.dll
- C:\msys32\mingw32\bin\libwinpthread-1.dll
To run sample_x86.exe on Windows 64-bit, you need the following files:
- unicorn.dll
- C:\msys64\mingw64\bin\libiconv-2.dll
- C:\msys64\mingw64\bin\libintl-8.dll
- C:\msys64\mingw64\bin\libglib-2.0-0.dll
- C:\msys64\mingw64\bin\libgcc_s_seh-1.dll
- C:\msys64\mingw64\bin\libwinpthread-1.dll
[8] By default, "cc" (default C compiler on the system) is used as compiler. [8] By default, "cc" (default C compiler on the system) is used as compiler.
- To use "clang" compiler instead, run the command below: - To use "clang" compiler instead, run the command below:
$ ./make.sh clang $ ./make.sh clang
- To use "gcc" compiler instead, run: - To use "gcc" compiler instead, run:
$ ./make.sh gcc $ ./make.sh gcc
[9] To uninstall Unicorn, run the command below: [9] To uninstall Unicorn, run the command below:
$ sudo ./make.sh uninstall $ sudo ./make.sh uninstall

View file

@ -40,6 +40,22 @@ template = {
'comment_open': '//', 'comment_open': '//',
'comment_close': '', 'comment_close': '',
}, },
'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 %s = %s;\n',
'out_file': './java/unicorn/%sConst.java',
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'Arm',
'arm64.h': 'Arm64',
'mips.h': 'Mips',
'x86.h': 'X86',
'sparc.h': 'Sparc',
'm68k.h': 'M68k',
'unicorn.h': 'Unicorn',
'comment_open': '//',
'comment_close': '',
},
} }
# markup for comments to be added to autogen files # markup for comments to be added to autogen files

View file

@ -9,8 +9,8 @@ void hookCode_cgo(uch handle, uint64_t addr, uint32_t size, void *user) {
hookCode(handle, addr, size, user); hookCode(handle, addr, size, user);
} }
bool hookMemInvalid_cgo(uch handle, uc_mem_type type, uint64_t addr, int64_t value, void *user) { bool hookMemInvalid_cgo(uch handle, uc_mem_type type, uint64_t addr, int size, int64_t value, void *user) {
return hookMemInvalid(handle, type, addr, value, user); return hookMemInvalid(handle, type, addr, size, value, user);
} }
void hookMemAccess_cgo(uch handle, uc_mem_type type, uint64_t addr, int size, int64_t value, void *user) { void hookMemAccess_cgo(uch handle, uc_mem_type type, uint64_t addr, int size, int64_t value, void *user) {

View file

@ -23,15 +23,15 @@ func hookCode(handle C.uch, addr C.uint64_t, size C.uint32_t, user unsafe.Pointe
} }
//export hookMemInvalid //export hookMemInvalid
func hookMemInvalid(handle C.uch, typ C.uc_mem_type, addr C.uint64_t, value C.int64_t, user unsafe.Pointer) C.bool { func hookMemInvalid(handle C.uch, typ C.uc_mem_type, addr C.uint64_t, size int, value C.int64_t, user unsafe.Pointer) C.bool {
hook := (*HookData)(user) hook := (*HookData)(user)
return C.bool(hook.Callback.(func(*Uc, int, uint64, int64) bool)(hook.Uc, int(typ), uint64(addr), int64(value))) return C.bool(hook.Callback.(func(*Uc, int, uint64, int, int64) bool)(hook.Uc, int(typ), uint64(addr), size, int64(value)))
} }
//export hookMemAccess //export hookMemAccess
func hookMemAccess(handle C.uch, typ C.uc_mem_type, addr C.uint64_t, size int, value C.int64_t, user unsafe.Pointer) { func hookMemAccess(handle C.uch, typ C.uc_mem_type, addr C.uint64_t, size int, value C.int64_t, user unsafe.Pointer) {
hook := (*HookData)(user) hook := (*HookData)(user)
hook.Callback.(func(*Uc, int, uint64, uint32, int64))(hook.Uc, int(typ), uint64(addr), uint32(size), int64(value)) hook.Callback.(func(*Uc, int, uint64, int, int64))(hook.Uc, int(typ), uint64(addr), size, int64(value))
} }
//export hookX86In //export hookX86In
@ -52,6 +52,8 @@ func hookX86Syscall(handle C.uch, user unsafe.Pointer) {
hook.Callback.(func(*Uc))(hook.Uc) hook.Callback.(func(*Uc))(hook.Uc)
} }
var hookRetain = make(map[C.uch]*HookData)
func (u *Uc) HookAdd(htype int, cb interface{}, insn ...int) (C.uch, error) { func (u *Uc) HookAdd(htype int, cb interface{}, insn ...int) (C.uch, error) {
var callback unsafe.Pointer var callback unsafe.Pointer
var extra C.int var extra C.int
@ -78,10 +80,13 @@ func (u *Uc) HookAdd(htype int, cb interface{}, insn ...int) (C.uch, error) {
return 0, errors.New("Unknown hook type.") return 0, errors.New("Unknown hook type.")
} }
var h2 C.uch var h2 C.uch
C.uc_hook_add2(u.Handle, &h2, C.uc_hook_t(htype), callback, unsafe.Pointer(&HookData{u, cb}), extra) data := &HookData{u, cb}
C.uc_hook_add2(u.Handle, &h2, C.uc_hook_t(htype), callback, unsafe.Pointer(data), extra)
hookRetain[h2] = data
return h2, nil return h2, nil
} }
func (u *Uc) HookDel(hook *C.uch) error { func (u *Uc) HookDel(hook *C.uch) error {
delete(hookRetain, *hook)
return errReturn(C.uc_hook_del(u.Handle, hook)) return errReturn(C.uc_hook_del(u.Handle, hook))
} }

View file

@ -1,6 +1,6 @@
uc_err uc_hook_add2(uch handle, uch *h2, uc_hook_t type, void *callback, void *user_data, int extra); uc_err uc_hook_add2(uch handle, uch *h2, uc_hook_t type, void *callback, void *user_data, int extra);
void hookCode_cgo(uch handle, uint64_t addr, uint32_t size, void *user); void hookCode_cgo(uch handle, uint64_t addr, uint32_t size, void *user);
bool hookMemInvalid_cgo(uch handle, uc_mem_type type, uint64_t addr, int64_t value, void *user); bool hookMemInvalid_cgo(uch handle, uc_mem_type type, uint64_t addr, int size, int64_t value, void *user);
void hookMemAccess_cgo(uch handle, uc_mem_type type, uint64_t addr, int size, int64_t value, void *user); void hookMemAccess_cgo(uch handle, uc_mem_type type, uint64_t addr, int size, int64_t value, void *user);
uint32_t hookX86In_cgo(uch handle, uint32_t port, uint32_t size, void *user); uint32_t hookX86In_cgo(uch handle, uint32_t port, uint32_t size, void *user);
void hookX86Out_cgo(uch handle, uint32_t port, uint32_t size, uint32_t value, void *user); void hookX86Out_cgo(uch handle, uint32_t port, uint32_t size, uint32_t value, void *user);

View file

@ -72,10 +72,16 @@ func (u *Uc) RegRead(reg int) (uint64, error) {
} }
func (u *Uc) MemWrite(addr uint64, data []byte) error { func (u *Uc) MemWrite(addr uint64, data []byte) error {
if len(data) == 0 {
return nil
}
return errReturn(C.uc_mem_write(u.Handle, C.uint64_t(addr), (*C.uint8_t)(unsafe.Pointer(&data[0])), C.size_t(len(data)))) return errReturn(C.uc_mem_write(u.Handle, C.uint64_t(addr), (*C.uint8_t)(unsafe.Pointer(&data[0])), C.size_t(len(data))))
} }
func (u *Uc) MemReadInto(dst []byte, addr uint64) error { func (u *Uc) MemReadInto(dst []byte, addr uint64) error {
if len(dst) == 0 {
return nil
}
return errReturn(C.uc_mem_read(u.Handle, C.uint64_t(addr), (*C.uint8_t)(unsafe.Pointer(&dst[0])), C.size_t(len(dst)))) return errReturn(C.uc_mem_read(u.Handle, C.uint64_t(addr), (*C.uint8_t)(unsafe.Pointer(&dst[0])), C.size_t(len(dst))))
} }
@ -84,6 +90,10 @@ func (u *Uc) MemRead(addr, size uint64) ([]byte, error) {
return dst, u.MemReadInto(dst, addr) return dst, u.MemReadInto(dst, addr)
} }
func (u *Uc) MemMap(addr, size uint64) error { func (u *Uc) MemMapProt(addr, size uint64, prot int) error {
return errReturn(C.uc_mem_map(u.Handle, C.uint64_t(addr), C.size_t(size))) return errReturn(C.uc_mem_map(u.Handle, C.uint64_t(addr), C.size_t(size), C.uint32_t(prot)))
}
func (u *Uc) MemMap(addr, size uint64) error {
return u.MemMapProt(addr, size, UC_PROT_ALL)
} }

View file

@ -29,7 +29,7 @@ const (
UC_MODE_MIPS32R6 = 64 UC_MODE_MIPS32R6 = 64
UC_MODE_V9 = 16 UC_MODE_V9 = 16
UC_MODE_QPX = 16 UC_MODE_QPX = 16
UC_MODE_BIG_ENDIAN = 2147483648 UC_MODE_BIG_ENDIAN = 1073741824
UC_MODE_MIPS32 = 4 UC_MODE_MIPS32 = 4
UC_MODE_MIPS64 = 8 UC_MODE_MIPS64 = 8

View 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_HOME := $(shell jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')
JAVA_INC := $(shell realpath $(JAVA_HOME)/../include) JAVA_INC := $(shell realpath $(JAVA_HOME)/../include)
@ -63,3 +66,13 @@ jar: jarfiles
install: lib jar install: lib jar
cp libunicorn_java$(LIB_EXT) $(JAVA_HOME)/lib/ext cp libunicorn_java$(LIB_EXT) $(JAVA_HOME)/lib/ext
cp $(JARFILE) $(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

View file

@ -245,25 +245,25 @@ public class SampleNetworkAuditing {
static { static {
SOCKET_TYPES = new Hashtable<Long, String>(); SOCKET_TYPES = new Hashtable<Long, String>();
ADDR_FAMILY = new Hashtable<Long, String>(); ADDR_FAMILY = new Hashtable<Long, String>();
SOCKET_TYPES.put(1, "SOCK_STREAM"); SOCKET_TYPES.put(1L, "SOCK_STREAM");
SOCKET_TYPES.put(2, "SOCK_DGRAM"); SOCKET_TYPES.put(2L, "SOCK_DGRAM");
SOCKET_TYPES.put(3, "SOCK_RAW"); SOCKET_TYPES.put(3L, "SOCK_RAW");
SOCKET_TYPES.put(4, "SOCK_RDM"); SOCKET_TYPES.put(4L, "SOCK_RDM");
SOCKET_TYPES.put(5, "SOCK_SEQPACKET"); SOCKET_TYPES.put(5L, "SOCK_SEQPACKET");
SOCKET_TYPES.put(10, "SOCK_PACKET"); SOCKET_TYPES.put(10L, "SOCK_PACKET");
ADDR_FAMILY.put(0, "AF_UNSPEC"); ADDR_FAMILY.put(0L, "AF_UNSPEC");
ADDR_FAMILY.put(1, "AF_UNIX"); ADDR_FAMILY.put(1L, "AF_UNIX");
ADDR_FAMILY.put(2, "AF_INET"); ADDR_FAMILY.put(2L, "AF_INET");
ADDR_FAMILY.put(3, "AF_AX25"); ADDR_FAMILY.put(3L, "AF_AX25");
ADDR_FAMILY.put(4, "AF_IPX"); ADDR_FAMILY.put(4L, "AF_IPX");
ADDR_FAMILY.put(5, "AF_APPLETALK"); ADDR_FAMILY.put(5L, "AF_APPLETALK");
ADDR_FAMILY.put(6, "AF_NETROM"); ADDR_FAMILY.put(6L, "AF_NETROM");
ADDR_FAMILY.put(7, "AF_BRIDGE"); ADDR_FAMILY.put(7L, "AF_BRIDGE");
ADDR_FAMILY.put(8, "AF_AAL5"); ADDR_FAMILY.put(8L, "AF_AAL5");
ADDR_FAMILY.put(9, "AF_X25"); ADDR_FAMILY.put(9L, "AF_X25");
ADDR_FAMILY.put(10, "AF_INET6"); ADDR_FAMILY.put(10L, "AF_INET6");
ADDR_FAMILY.put(12, "AF_MAX"); ADDR_FAMILY.put(12L, "AF_MAX");
} }
// http://shell-storm.org/shellcode/files/shellcode-861.php // 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); Unicorn mu = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
mu.mem_write(ADDRESS, code); mu.mem_write(ADDRESS, code);

View file

@ -51,7 +51,7 @@ public class Sample_arm {
Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_ARM); Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_ARM);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, ARM_CODE); 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM, Unicorn.UC_MODE_THUMB);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, THUMB_CODE); u.mem_write(ADDRESS, THUMB_CODE);

View file

@ -79,7 +79,7 @@ public class Sample_arm64 {
Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM); Unicorn u = new Unicorn(Unicorn.UC_ARCH_ARM64, Unicorn.UC_MODE_ARM);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, ARM_CODE); u.mem_write(ADDRESS, ARM_CODE);

View file

@ -95,7 +95,7 @@ public class Sample_m68k {
Unicorn u = new Unicorn(Unicorn.UC_ARCH_M68K, Unicorn.UC_MODE_BIG_ENDIAN); Unicorn u = new Unicorn(Unicorn.UC_ARCH_M68K, Unicorn.UC_MODE_BIG_ENDIAN);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, M68K_CODE); u.mem_write(ADDRESS, M68K_CODE);

View 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_MIPS, Unicorn.UC_MODE_MIPS32 + Unicorn.UC_MODE_BIG_ENDIAN);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, MIPS_CODE_EB); 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_MIPS, Unicorn.UC_MODE_MIPS32);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, MIPS_CODE_EL); u.mem_write(ADDRESS, MIPS_CODE_EL);

View file

@ -79,7 +79,7 @@ public class Sample_sparc {
Unicorn u = new Unicorn(Unicorn.UC_ARCH_SPARC, Unicorn.UC_MODE_BIG_ENDIAN); Unicorn u = new Unicorn(Unicorn.UC_ARCH_SPARC, Unicorn.UC_MODE_BIG_ENDIAN);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, SPARC_CODE); u.mem_write(ADDRESS, SPARC_CODE);

View 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", System.out.printf(">>> Missing memory is being WRITE at 0x%x, data size = %d, data value = 0x%x\n",
address, size, value); address, size, value);
// map this memory in with 2MB in size // 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 to indicate we want to continue
return true; return true;
} }
@ -193,7 +193,7 @@ public class Sample_x86 {
} }
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
try { try {
@ -251,7 +251,7 @@ public class Sample_x86 {
Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, X86_CODE32_INOUT); 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, X86_CODE32_JUMP); 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, X86_CODE32_LOOP); 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, X86_CODE32_MEM_READ); 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, X86_CODE32_MEM_WRITE); 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, X86_CODE32_JMP_INVALID); 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_64);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, X86_CODE64); 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); Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_16);
// map 8KB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(0, X86_CODE16); u.mem_write(0, X86_CODE16);

View file

@ -121,7 +121,7 @@ public class Shellcode {
Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32); Unicorn u = new Unicorn(Unicorn.UC_ARCH_X86, Unicorn.UC_MODE_32);
// map 2MB memory for this emulation // 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 // write machine code to be emulated to memory
u.mem_write(ADDRESS, X86_CODE32_SELF); u.mem_write(ADDRESS, X86_CODE32_SELF);

View file

@ -1,27 +1,11 @@
/* // For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
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; package unicorn;
public interface Arm64Regs { public interface Arm64Const {
// ARM64 registers
public static final int UC_ARM64_REG_INVALID = 0; 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_X29 = 1;
public static final int UC_ARM64_REG_X30 = 2; public static final int UC_ARM64_REG_X30 = 2;
@ -282,10 +266,15 @@ public interface Arm64Regs {
public static final int UC_ARM64_REG_V29 = 257; 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_V30 = 258;
public static final int UC_ARM64_REG_V31 = 259; 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_PC = 260;
public static final int UC_ARM64_REG_ENDING = 261; public static final int UC_ARM64_REG_ENDING = 261;
public static final int UC_ARM64_REG_IP1 = UC_ARM64_REG_X16;
public static final int UC_ARM64_REG_IP0 = UC_ARM64_REG_X17; // alias registers
public static final int UC_ARM64_REG_FP = UC_ARM64_REG_X29; public static final int UC_ARM64_REG_IP1 = 215;
public static final int UC_ARM64_REG_LR = UC_ARM64_REG_X30; public static final int UC_ARM64_REG_IP0 = 216;
public static final int UC_ARM64_REG_FP = 1;
public static final int UC_ARM64_REG_LR = 2;
} }

View file

@ -1,27 +1,11 @@
/* // For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
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; package unicorn;
public interface ArmRegs { public interface ArmConst {
// ARM registers
public static final int UC_ARM_REG_INVALID = 0; 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 = 1;
public static final int UC_ARM_REG_APSR_NZCV = 2; public static final int UC_ARM_REG_APSR_NZCV = 2;
@ -134,11 +118,14 @@ public interface ArmRegs {
public static final int UC_ARM_REG_S30 = 109; 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_S31 = 110;
public static final int UC_ARM_REG_ENDING = 111; public static final int UC_ARM_REG_ENDING = 111;
public static final int UC_ARM_REG_R13 = UC_ARM_REG_SP;
public static final int UC_ARM_REG_R14 = UC_ARM_REG_LR; // alias registers
public static final int UC_ARM_REG_R15 = UC_ARM_REG_PC; public static final int UC_ARM_REG_R13 = 12;
public static final int UC_ARM_REG_SB = UC_ARM_REG_R9; public static final int UC_ARM_REG_R14 = 10;
public static final int UC_ARM_REG_SL = UC_ARM_REG_R10; public static final int UC_ARM_REG_R15 = 11;
public static final int UC_ARM_REG_FP = UC_ARM_REG_R11; public static final int UC_ARM_REG_SB = 75;
public static final int UC_ARM_REG_IP = UC_ARM_REG_R12; 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;
} }

View file

@ -1,27 +1,11 @@
/* // For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
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; package unicorn;
public interface M68kRegs { public interface M68kConst {
// M68K registers
public static final int UC_M68K_REG_INVALID = 0; 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_A0 = 1;
public static final int UC_M68K_REG_A1 = 2; public static final int UC_M68K_REG_A1 = 2;
@ -42,4 +26,5 @@ public interface M68kRegs {
public static final int UC_M68K_REG_SR = 17; 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_PC = 18;
public static final int UC_M68K_REG_ENDING = 19; public static final int UC_M68K_REG_ENDING = 19;
} }

View file

@ -1,28 +1,14 @@
/* // For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
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; package unicorn;
public interface MipsRegs { public interface MipsConst {
// MIPS registers
public static final int UC_MIPS_REG_INVALID = 0; 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_PC = 1;
public static final int UC_MIPS_REG_0 = 2; 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_1 = 3;
@ -56,6 +42,8 @@ public interface MipsRegs {
public static final int UC_MIPS_REG_29 = 31; 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_30 = 32;
public static final int UC_MIPS_REG_31 = 33; 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_DSPCCOND = 34;
public static final int UC_MIPS_REG_DSPCARRY = 35; 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_DSPEFI = 36;
@ -67,10 +55,14 @@ public interface MipsRegs {
public static final int UC_MIPS_REG_DSPOUTFLAG23 = 42; 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_DSPPOS = 43;
public static final int UC_MIPS_REG_DSPSCOUNT = 44; 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_AC0 = 45;
public static final int UC_MIPS_REG_AC1 = 46; 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_AC2 = 47;
public static final int UC_MIPS_REG_AC3 = 48; 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_CC0 = 49;
public static final int UC_MIPS_REG_CC1 = 50; 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_CC2 = 51;
@ -79,6 +71,8 @@ public interface MipsRegs {
public static final int UC_MIPS_REG_CC5 = 54; 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_CC6 = 55;
public static final int UC_MIPS_REG_CC7 = 56; 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_F0 = 57;
public static final int UC_MIPS_REG_F1 = 58; 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_F2 = 59;
@ -119,6 +113,8 @@ public interface MipsRegs {
public static final int UC_MIPS_REG_FCC5 = 94; 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_FCC6 = 95;
public static final int UC_MIPS_REG_FCC7 = 96; 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_W0 = 97;
public static final int UC_MIPS_REG_W1 = 98; 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_W2 = 99;
@ -160,45 +156,46 @@ public interface MipsRegs {
public static final int UC_MIPS_REG_MPL1 = 135; 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_MPL2 = 136;
public static final int UC_MIPS_REG_ENDING = 137; public static final int UC_MIPS_REG_ENDING = 137;
public static final int UC_MIPS_REG_ZERO = UC_MIPS_REG_0; public static final int UC_MIPS_REG_ZERO = 2;
public static final int UC_MIPS_REG_AT = UC_MIPS_REG_1; public static final int UC_MIPS_REG_AT = 3;
public static final int UC_MIPS_REG_V0 = UC_MIPS_REG_2; public static final int UC_MIPS_REG_V0 = 4;
public static final int UC_MIPS_REG_V1 = UC_MIPS_REG_3; public static final int UC_MIPS_REG_V1 = 5;
public static final int UC_MIPS_REG_A0 = UC_MIPS_REG_4; public static final int UC_MIPS_REG_A0 = 6;
public static final int UC_MIPS_REG_A1 = UC_MIPS_REG_5; public static final int UC_MIPS_REG_A1 = 7;
public static final int UC_MIPS_REG_A2 = UC_MIPS_REG_6; public static final int UC_MIPS_REG_A2 = 8;
public static final int UC_MIPS_REG_A3 = UC_MIPS_REG_7; public static final int UC_MIPS_REG_A3 = 9;
public static final int UC_MIPS_REG_T0 = UC_MIPS_REG_8; public static final int UC_MIPS_REG_T0 = 10;
public static final int UC_MIPS_REG_T1 = UC_MIPS_REG_9; public static final int UC_MIPS_REG_T1 = 11;
public static final int UC_MIPS_REG_T2 = UC_MIPS_REG_10; public static final int UC_MIPS_REG_T2 = 12;
public static final int UC_MIPS_REG_T3 = UC_MIPS_REG_11; public static final int UC_MIPS_REG_T3 = 13;
public static final int UC_MIPS_REG_T4 = UC_MIPS_REG_12; public static final int UC_MIPS_REG_T4 = 14;
public static final int UC_MIPS_REG_T5 = UC_MIPS_REG_13; public static final int UC_MIPS_REG_T5 = 15;
public static final int UC_MIPS_REG_T6 = UC_MIPS_REG_14; public static final int UC_MIPS_REG_T6 = 16;
public static final int UC_MIPS_REG_T7 = UC_MIPS_REG_15; public static final int UC_MIPS_REG_T7 = 17;
public static final int UC_MIPS_REG_S0 = UC_MIPS_REG_16; public static final int UC_MIPS_REG_S0 = 18;
public static final int UC_MIPS_REG_S1 = UC_MIPS_REG_17; public static final int UC_MIPS_REG_S1 = 19;
public static final int UC_MIPS_REG_S2 = UC_MIPS_REG_18; public static final int UC_MIPS_REG_S2 = 20;
public static final int UC_MIPS_REG_S3 = UC_MIPS_REG_19; public static final int UC_MIPS_REG_S3 = 21;
public static final int UC_MIPS_REG_S4 = UC_MIPS_REG_20; public static final int UC_MIPS_REG_S4 = 22;
public static final int UC_MIPS_REG_S5 = UC_MIPS_REG_21; public static final int UC_MIPS_REG_S5 = 23;
public static final int UC_MIPS_REG_S6 = UC_MIPS_REG_22; public static final int UC_MIPS_REG_S6 = 24;
public static final int UC_MIPS_REG_S7 = UC_MIPS_REG_23; public static final int UC_MIPS_REG_S7 = 25;
public static final int UC_MIPS_REG_T8 = UC_MIPS_REG_24; public static final int UC_MIPS_REG_T8 = 26;
public static final int UC_MIPS_REG_T9 = UC_MIPS_REG_25; public static final int UC_MIPS_REG_T9 = 27;
public static final int UC_MIPS_REG_K0 = UC_MIPS_REG_26; public static final int UC_MIPS_REG_K0 = 28;
public static final int UC_MIPS_REG_K1 = UC_MIPS_REG_27; public static final int UC_MIPS_REG_K1 = 29;
public static final int UC_MIPS_REG_GP = UC_MIPS_REG_28; public static final int UC_MIPS_REG_GP = 30;
public static final int UC_MIPS_REG_SP = UC_MIPS_REG_29; public static final int UC_MIPS_REG_SP = 31;
public static final int UC_MIPS_REG_FP = UC_MIPS_REG_30; public static final int UC_MIPS_REG_FP = 32;
public static final int UC_MIPS_REG_S8 = UC_MIPS_REG_30; public static final int UC_MIPS_REG_S8 = 32;
public static final int UC_MIPS_REG_RA = UC_MIPS_REG_31; public static final int UC_MIPS_REG_RA = 33;
public static final int UC_MIPS_REG_HI0 = UC_MIPS_REG_AC0; public static final int UC_MIPS_REG_HI0 = 45;
public static final int UC_MIPS_REG_HI1 = UC_MIPS_REG_AC1; public static final int UC_MIPS_REG_HI1 = 46;
public static final int UC_MIPS_REG_HI2 = UC_MIPS_REG_AC2; public static final int UC_MIPS_REG_HI2 = 47;
public static final int UC_MIPS_REG_HI3 = UC_MIPS_REG_AC3; public static final int UC_MIPS_REG_HI3 = 48;
public static final int UC_MIPS_REG_LO0 = UC_MIPS_REG_HI0; public static final int UC_MIPS_REG_LO0 = 45;
public static final int UC_MIPS_REG_LO1 = UC_MIPS_REG_HI1; public static final int UC_MIPS_REG_LO1 = 46;
public static final int UC_MIPS_REG_LO2 = UC_MIPS_REG_HI2; public static final int UC_MIPS_REG_LO2 = 47;
public static final int UC_MIPS_REG_LO3 = UC_MIPS_REG_HI3; public static final int UC_MIPS_REG_LO3 = 48;
} }

View file

@ -1,27 +1,11 @@
/* // For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
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; package unicorn;
public interface SparcRegs { public interface SparcConst {
// SPARC registers
public static final int UC_SPARC_REG_INVALID = 0; 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_F0 = 1;
public static final int UC_SPARC_REG_F1 = 2; public static final int UC_SPARC_REG_F1 = 2;
@ -112,6 +96,7 @@ public interface SparcRegs {
public static final int UC_SPARC_REG_XCC = 87; 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_PC = 88;
public static final int UC_SPARC_REG_ENDING = 89; public static final int UC_SPARC_REG_ENDING = 89;
public static final int UC_SPARC_REG_O6 = UC_SPARC_REG_SP; public static final int UC_SPARC_REG_O6 = 85;
public static final int UC_SPARC_REG_I6 = UC_SPARC_REG_FP; public static final int UC_SPARC_REG_I6 = 53;
} }

View file

@ -23,8 +23,7 @@ package unicorn;
import java.util.*; import java.util.*;
public class Unicorn implements UnicornArchs, UnicornModes, UnicornHooks, public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, SparcConst, MipsConst, X86Const {
ArmRegs, Arm64Regs, M68kRegs, SparcRegs, MipsRegs, X86Regs, X86Instructions {
// Scales to calculate timeout on microsecond unit // Scales to calculate timeout on microsecond unit
// 1 second = 1000,000 microseconds // 1 second = 1000,000 microseconds

View file

@ -1,34 +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 UnicornArchs {
public static final int UC_ARCH_ARM = 1; // ARM architecture (including Thumb, Thumb-2)
public static final int UC_ARCH_ARM64 = 2; // ARM-64, also called AArch64
public static final int UC_ARCH_MIPS = 3; // Mips architecture
public static final int UC_ARCH_X86 = 4; // X86 architecture (including x86 & x86-64)
public static final int UC_ARCH_PPC = 5; // PowerPC architecture
public static final int UC_ARCH_SPARC = 6; // Sparc architecture
public static final int UC_ARCH_M68K = 7; // M68K architecture
public static final int UC_ARCH_MAX = 8;
public static final int UC_ARCH_ALL = 0xFFFF; // All architectures - for uc_support()
}

View file

@ -0,0 +1,71 @@
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
package unicorn;
public interface UnicornConst {
public static final int UC_API_MAJOR = 0;
public static final int UC_API_MINOR = 9;
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_MAX = 8;
public static final int UC_MODE_LITTLE_ENDIAN = 0;
public static final int UC_MODE_ARM = 0;
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_THUMB = 16;
public static final int UC_MODE_MCLASS = 32;
public static final int UC_MODE_V8 = 64;
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_V9 = 16;
public static final int UC_MODE_QPX = 16;
public static final int UC_MODE_BIG_ENDIAN = 0x80000000;
public static final int UC_MODE_MIPS32 = 4;
public static final int UC_MODE_MIPS64 = 8;
public static final int UC_ERR_OK = 0;
public static final int UC_ERR_OOM = 1;
public static final int UC_ERR_ARCH = 2;
public static final int UC_ERR_HANDLE = 3;
public static final int UC_ERR_UCH = 4;
public static final int UC_ERR_MODE = 5;
public static final int UC_ERR_VERSION = 6;
public static final int UC_ERR_MEM_READ = 7;
public static final int UC_ERR_MEM_WRITE = 8;
public static final int UC_ERR_CODE_INVALID = 9;
public static final int UC_ERR_HOOK = 10;
public static final int UC_ERR_INSN_INVALID = 11;
public static final int UC_ERR_MAP = 12;
public static final int UC_ERR_MEM_WRITE_NW = 13;
public static final int UC_ERR_MEM_READ_NR = 14;
public static final int UC_MEM_READ = 16;
public static final int UC_MEM_WRITE = 17;
public static final int UC_MEM_READ_WRITE = 18;
public static final int UC_MEM_WRITE_NW = 19;
public static final int UC_MEM_READ_NR = 20;
public static final int UC_MEM_NX = 21;
public static final int UC_HOOK_INTR = 32;
public static final int UC_HOOK_INSN = 33;
public static final int UC_HOOK_CODE = 34;
public static final int UC_HOOK_BLOCK = 35;
public static final int UC_HOOK_MEM_INVALID = 36;
public static final int UC_HOOK_MEM_READ = 37;
public static final int UC_HOOK_MEM_WRITE = 38;
public static final int UC_HOOK_MEM_READ_WRITE = 39;
public static final int UC_PROT_READ = 1;
public static final int UC_PROT_WRITE = 2;
public static final int UC_PROT_EXEC = 4;
}

View file

@ -1,38 +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 UnicornHooks {
public static final int UC_MEM_READ = 16; // Memory is read from
public static final int UC_MEM_WRITE = 17; // Memory is written to
public static final int UC_MEM_READ_WRITE = 18; // Memory is accessed (either READ or WRITE)
public static final int UC_HOOK_INTR = 32; // Hook all interrupt events
public static final int UC_HOOK_INSN = 33; // Hook a particular instruction
public static final int UC_HOOK_CODE = 34; // Hook a range of code
public static final int UC_HOOK_BLOCK = 35; // Hook basic blocks
public static final int UC_HOOK_MEM_INVALID = 36; // Hook for all invalid memory access events
public static final int UC_HOOK_MEM_READ = 37; // Hook all memory read events.
public static final int UC_HOOK_MEM_WRITE = 38; // Hook all memory write events.
public static final int UC_HOOK_MEM_READ_WRITE = 39; // Hook all memory accesses (either READ or WRITE).
}

View file

@ -1,20 +0,0 @@
package unicorn;
public interface UnicornModes {
public static final int UC_MODE_LITTLE_ENDIAN = 0; // little-endian mode (default mode)
public static final int UC_MODE_ARM = 0; // 32-bit ARM
public static final int UC_MODE_16 = 1 << 1; // 16-bit mode (X86)
public static final int UC_MODE_32 = 1 << 2; // 32-bit mode (X86)
public static final int UC_MODE_64 = 1 << 3; // 64-bit mode (X86; PPC)
public static final int UC_MODE_THUMB = 1 << 4; // ARM's Thumb mode; including Thumb-2
public static final int UC_MODE_MCLASS = 1 << 5; // ARM's Cortex-M series
public static final int UC_MODE_V8 = 1 << 6; // ARMv8 A32 encodings for ARM
public static final int UC_MODE_MICRO = 1 << 4; // MicroMips mode (MIPS)
public static final int UC_MODE_MIPS3 = 1 << 5; // Mips III ISA
public static final int UC_MODE_MIPS32R6 = 1 << 6; // Mips32r6 ISA
public static final int UC_MODE_V9 = 1 << 4; // SparcV9 mode (Sparc)
public static final int UC_MODE_QPX = 1 << 4; // Quad Processing eXtensions mode (PPC)
public static final int UC_MODE_BIG_ENDIAN = 1 << 31; // big-endian mode
public static final int UC_MODE_MIPS32 = UC_MODE_32; // Mips32 ISA (Mips)
public static final int UC_MODE_MIPS64 = UC_MODE_64; // Mips64 ISA (Mips)
}

View file

@ -1,27 +1,257 @@
/* // For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
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; package unicorn;
public interface X86Instructions { public interface X86Const {
// 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_EIZ = 27;
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_RIZ = 42;
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_CR5 = 55;
public static final int UC_X86_REG_CR6 = 56;
public static final int UC_X86_REG_CR7 = 57;
public static final int UC_X86_REG_CR8 = 58;
public static final int UC_X86_REG_CR9 = 59;
public static final int UC_X86_REG_CR10 = 60;
public static final int UC_X86_REG_CR11 = 61;
public static final int UC_X86_REG_CR12 = 62;
public static final int UC_X86_REG_CR13 = 63;
public static final int UC_X86_REG_CR14 = 64;
public static final int UC_X86_REG_CR15 = 65;
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_DR8 = 74;
public static final int UC_X86_REG_DR9 = 75;
public static final int UC_X86_REG_DR10 = 76;
public static final int UC_X86_REG_DR11 = 77;
public static final int UC_X86_REG_DR12 = 78;
public static final int UC_X86_REG_DR13 = 79;
public static final int UC_X86_REG_DR14 = 80;
public static final int UC_X86_REG_DR15 = 81;
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_ENDING = 242;
// X86 instructions
public static final int UC_X86_INS_INVALID = 0; 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_AAA = 1;
public static final int UC_X86_INS_AAD = 2; public static final int UC_X86_INS_AAD = 2;
@ -1361,4 +1591,5 @@ public interface X86Instructions {
public static final int UC_X86_INS_FDISI8087_NOP = 1336; 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_FENI8087_NOP = 1337;
public static final int UC_X86_INS_ENDING = 1338; public static final int UC_X86_INS_ENDING = 1338;
} }

View file

@ -1,268 +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 X86Regs {
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_EIZ = 27;
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_RIZ = 42;
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_CR5 = 55;
public static final int UC_X86_REG_CR6 = 56;
public static final int UC_X86_REG_CR7 = 57;
public static final int UC_X86_REG_CR8 = 58;
public static final int UC_X86_REG_CR9 = 59;
public static final int UC_X86_REG_CR10 = 60;
public static final int UC_X86_REG_CR11 = 61;
public static final int UC_X86_REG_CR12 = 62;
public static final int UC_X86_REG_CR13 = 63;
public static final int UC_X86_REG_CR14 = 64;
public static final int UC_X86_REG_CR15 = 65;
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_DR8 = 74;
public static final int UC_X86_REG_DR9 = 75;
public static final int UC_X86_REG_DR10 = 76;
public static final int UC_X86_REG_DR11 = 77;
public static final int UC_X86_REG_DR12 = 78;
public static final int UC_X86_REG_DR13 = 79;
public static final int UC_X86_REG_DR14 = 80;
public static final int UC_X86_REG_DR15 = 81;
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_ENDING = 242;
}

View file

@ -27,7 +27,7 @@ UC_MODE_MIPS3 = 32
UC_MODE_MIPS32R6 = 64 UC_MODE_MIPS32R6 = 64
UC_MODE_V9 = 16 UC_MODE_V9 = 16
UC_MODE_QPX = 16 UC_MODE_QPX = 16
UC_MODE_BIG_ENDIAN = 2147483648 UC_MODE_BIG_ENDIAN = 1073741824
UC_MODE_MIPS32 = 4 UC_MODE_MIPS32 = 4
UC_MODE_MIPS64 = 8 UC_MODE_MIPS64 = 8

View file

@ -95,7 +95,6 @@ struct uc_struct {
void* cpu; void* cpu;
MemoryRegion *system_memory; // qemu/exec.c MemoryRegion *system_memory; // qemu/exec.c
MemoryRegion *ram;
MemoryRegion io_mem_rom; // qemu/exec.c MemoryRegion io_mem_rom; // qemu/exec.c
MemoryRegion io_mem_notdirty; // qemu/exec.c MemoryRegion io_mem_notdirty; // qemu/exec.c
MemoryRegion io_mem_unassigned; // qemu/exec.c MemoryRegion io_mem_unassigned; // qemu/exec.c

View file

@ -95,7 +95,7 @@ typedef enum uc_mode {
UC_MODE_MIPS32R6 = 1 << 6, // Mips32r6 ISA UC_MODE_MIPS32R6 = 1 << 6, // Mips32r6 ISA
UC_MODE_V9 = 1 << 4, // SparcV9 mode (Sparc) UC_MODE_V9 = 1 << 4, // SparcV9 mode (Sparc)
UC_MODE_QPX = 1 << 4, // Quad Processing eXtensions mode (PPC) 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_MIPS32 = UC_MODE_32, // Mips32 ISA (Mips)
UC_MODE_MIPS64 = UC_MODE_64, // Mips64 ISA (Mips) UC_MODE_MIPS64 = UC_MODE_64, // Mips64 ISA (Mips)
} uc_mode; } uc_mode;

View file

@ -38,8 +38,8 @@ build_cross() {
[ "$UNAME" = Darwin ] && LIBARCHS="i386 x86_64" [ "$UNAME" = Darwin ] && LIBARCHS="i386 x86_64"
CROSS=$1 CROSS=$1
CC=$CROSS-gcc \ CC=$CROSS-gcc \
AR=$CROSS-ar \ AR=$CROSS-gcc-ar \
RANLIB=$CROSS-ranlib \ RANLIB=$CROSS-gcc-ranlib \
GLIB="-L/usr/$CROSS/lib/ -lglib-2.0" \ GLIB="-L/usr/$CROSS/lib/ -lglib-2.0" \
${MAKE} ${MAKE}
} }

View file

@ -33,16 +33,16 @@
// Unicorn engine // Unicorn engine
MemoryRegion *memory_map(struct uc_struct *uc, ram_addr_t begin, size_t size, uint32_t perms) MemoryRegion *memory_map(struct uc_struct *uc, ram_addr_t begin, size_t size, uint32_t perms)
{ {
uc->ram = g_new(MemoryRegion, 1); MemoryRegion *ram = g_new(MemoryRegion, 1);
memory_region_init_ram(uc, uc->ram, NULL, "pc.ram", size, perms, &error_abort); memory_region_init_ram(uc, ram, NULL, "pc.ram", size, perms, &error_abort);
memory_region_add_subregion(get_system_memory(uc), begin, uc->ram); memory_region_add_subregion(get_system_memory(uc), begin, ram);
if (uc->current_cpu) if (uc->current_cpu)
tlb_flush(uc->current_cpu, 1); tlb_flush(uc->current_cpu, 1);
return uc->ram; return ram;
} }
int memory_free(struct uc_struct *uc) int memory_free(struct uc_struct *uc)

View file

@ -5,6 +5,7 @@ TESTS = map_crash map_write
TESTS += sigill sigill2 TESTS += sigill sigill2
TESTS += block_test TESTS += block_test
TESTS += ro_mem_test nr_mem_test TESTS += ro_mem_test nr_mem_test
TESTS += timeout_segfault
all: $(TESTS) all: $(TESTS)

33
regress/jmp_ebx_hang.py Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env python
"""See https://github.com/unicorn-engine/unicorn/issues/82"""
import unicorn
CODE_ADDR = 0x10101000
CODE = b'\xff\xe3'
mu = unicorn.Uc(unicorn.UC_ARCH_X86, unicorn.UC_MODE_32)
mu.mem_map(CODE_ADDR, 1024 * 4)
mu.mem_write(CODE_ADDR, CODE)
# If EBX is zero then an exception is raised, as expected
mu.reg_write(unicorn.x86_const.UC_X86_REG_EBX, 0x0)
try:
mu.emu_start(CODE_ADDR, CODE_ADDR + 2, count=1)
except unicorn.UcError as e:
assert(e.errno == unicorn.UC_ERR_CODE_INVALID)
else:
assert(False)
mu = unicorn.Uc(unicorn.UC_ARCH_X86, unicorn.UC_MODE_32)
mu.mem_map(CODE_ADDR, 1024 * 4)
# If we write this address to EBX then the emulator hangs on emu_start
mu.reg_write(unicorn.x86_const.UC_X86_REG_EBX, 0xaa96a47f)
mu.mem_write(CODE_ADDR, CODE)
try:
mu.emu_start(CODE_ADDR, CODE_ADDR + 2, count=1)
except unicorn.UcError as e:
assert(e.errno == unicorn.UC_ERR_CODE_INVALID)
else:
assert(False)
print "Success"

149
regress/timeout_segfault.c Normal file
View file

@ -0,0 +1,149 @@
/*
timeout_segfault.c
This program shows a case where the emulation timer keeps running after
emulation has ended. It triggers an intermittent segfault when _timeout_fn()
tries to call uc_emu_stop() after emulation has already been cleaned up. This
code is the same as samples/sample_arm.c, except that it adds a timeout on each
call to uc_emu_start(). See issue #78 for more details:
https://github.com/unicorn-engine/unicorn/issues/78
*/
#include <inttypes.h>
#include <unicorn/unicorn.h>
// code to be emulated
#define ARM_CODE "\x37\x00\xa0\xe3\x03\x10\x42\xe0" // mov r0, #0x37; sub r1, r2, r3
#define THUMB_CODE "\x83\xb0" // sub sp, #0xc
// memory address where emulation starts
#define ADDRESS 0x10000
// number of seconds to wait before timeout
#define TIMEOUT 5
static void hook_block(uch handle, uint64_t address, uint32_t size, void *user_data)
{
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
}
static void hook_code(uch handle, uint64_t address, uint32_t size, void *user_data)
{
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
}
static void test_arm(void)
{
uch handle;
uc_err err;
uch trace1, trace2;
int r0 = 0x1234; // R0 register
int r2 = 0x6789; // R1 register
int r3 = 0x3333; // R2 register
int r1; // R1 register
printf("Emulate ARM code\n");
// Initialize emulator in ARM mode
err = uc_open(UC_ARCH_ARM, UC_MODE_ARM, &handle);
if (err) {
printf("Failed on uc_open() with error returned: %u (%s)\n",
err, uc_strerror(err));
return;
}
// map 2MB memory for this emulation
uc_mem_map(handle, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL);
// write machine code to be emulated to memory
uc_mem_write(handle, ADDRESS, (uint8_t *)ARM_CODE, sizeof(ARM_CODE) - 1);
// initialize machine registers
uc_reg_write(handle, UC_ARM_REG_R0, &r0);
uc_reg_write(handle, UC_ARM_REG_R2, &r2);
uc_reg_write(handle, UC_ARM_REG_R3, &r3);
// tracing all basic blocks with customized callback
uc_hook_add(handle, &trace1, UC_HOOK_BLOCK, hook_block, NULL, (uint64_t)1, (uint64_t)0);
// tracing one instruction at ADDRESS with customized callback
uc_hook_add(handle, &trace2, UC_HOOK_CODE, hook_code, NULL, (uint64_t)ADDRESS, (uint64_t)ADDRESS);
// emulate machine code in infinite time (last param = 0), or when
// finishing all the code.
err = uc_emu_start(handle, ADDRESS, ADDRESS + sizeof(ARM_CODE) -1, UC_SECOND_SCALE * TIMEOUT, 0);
if (err) {
printf("Failed on uc_emu_start() with error returned: %u\n", err);
}
// now print out some registers
printf(">>> Emulation done. Below is the CPU context\n");
uc_reg_read(handle, UC_ARM_REG_R0, &r0);
uc_reg_read(handle, UC_ARM_REG_R1, &r1);
printf(">>> R0 = 0x%x\n", r0);
printf(">>> R1 = 0x%x\n", r1);
uc_close(&handle);
}
static void test_thumb(void)
{
uch handle;
uc_err err;
uch trace1, trace2;
int sp = 0x1234; // R0 register
printf("Emulate THUMB code\n");
// Initialize emulator in ARM mode
err = uc_open(UC_ARCH_ARM, UC_MODE_THUMB, &handle);
if (err) {
printf("Failed on uc_open() with error returned: %u (%s)\n",
err, uc_strerror(err));
return;
}
// map 2MB memory for this emulation
uc_mem_map(handle, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL);
// write machine code to be emulated to memory
uc_mem_write(handle, ADDRESS, (uint8_t *)THUMB_CODE, sizeof(THUMB_CODE) - 1);
// initialize machine registers
uc_reg_write(handle, UC_ARM_REG_SP, &sp);
// tracing all basic blocks with customized callback
uc_hook_add(handle, &trace1, UC_HOOK_BLOCK, hook_block, NULL, (uint64_t)1, (uint64_t)0);
// tracing one instruction at ADDRESS with customized callback
uc_hook_add(handle, &trace2, UC_HOOK_CODE, hook_code, NULL, (uint64_t)ADDRESS, (uint64_t)ADDRESS);
// emulate machine code in infinite time (last param = 0), or when
// finishing all the code.
err = uc_emu_start(handle, ADDRESS, ADDRESS + sizeof(THUMB_CODE) -1, UC_SECOND_SCALE * TIMEOUT, 0);
if (err) {
printf("Failed on uc_emu_start() with error returned: %u\n", err);
}
// now print out some registers
printf(">>> Emulation done. Below is the CPU context\n");
uc_reg_read(handle, UC_ARM_REG_SP, &sp);
printf(">>> SP = 0x%x\n", sp);
uc_close(&handle);
}
int main(int argc, char **argv, char **envp)
{
test_arm();
printf("==========================\n");
test_thumb();
return 0;
}

5
uc.c
View file

@ -549,6 +549,11 @@ uc_err uc_emu_start(uch handle, uint64_t begin, uint64_t until, uint64_t timeout
// emulation is done // emulation is done
uc->emulation_done = true; uc->emulation_done = true;
if (timeout) {
// wait for the timer to finish
qemu_thread_join(&uc->timer);
}
return uc->invalid_error; return uc->invalid_error;
} }