mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-03-26 20:25:07 +00:00
Merge branch 'master' into mem_map_ex_cse
This commit is contained in:
commit
de7ac7fc48
43
COMPILE.TXT
43
COMPILE.TXT
|
@ -120,11 +120,10 @@ Unicorn requires few dependent packages as followings
|
||||||
|
|
||||||
$ ./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
|
||||||
|
@ -176,21 +175,43 @@ Unicorn requires few dependent packages as followings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[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 under Cygwin, run:
|
- 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
|
||||||
|
|
||||||
$ ./make.sh cygwin-mingw32
|
- 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
|
||||||
|
|
||||||
- To compile Windows 64-bit binary under Cygwin, run:
|
Resulted files unicorn.dll, unicorn.lib & samples/sample*.exe can then
|
||||||
|
|
||||||
$ ./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
|
||||||
|
- %MSYS2%\mingw32\bin\libiconv-2.dll
|
||||||
|
- %MSYS2%\mingw32\bin\libintl-8.dll
|
||||||
|
- %MSYS2%\mingw32\bin\libglib-2.0-0.dll
|
||||||
|
- %MSYS2%\mingw32\bin\libgcc_s_dw2-1.dll
|
||||||
|
- %MSYS2%\mingw32\bin\libwinpthread-1.dll
|
||||||
|
|
||||||
|
To run sample_x86.exe on Windows 64-bit, you need the following files:
|
||||||
|
- unicorn.dll
|
||||||
|
- %MSYS2%\mingw64\bin\libiconv-2.dll
|
||||||
|
- %MSYS2%\mingw64\bin\libintl-8.dll
|
||||||
|
- %MSYS2%\mingw64\bin\libglib-2.0-0.dll
|
||||||
|
- %MSYS2%\mingw64\bin\libgcc_s_seh-1.dll
|
||||||
|
- %MSYS2%\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.
|
||||||
|
|
|
@ -37,6 +37,8 @@ Luke Burnett
|
||||||
Parker Thompson
|
Parker Thompson
|
||||||
Daniel Godas-Lopez
|
Daniel Godas-Lopez
|
||||||
Antonio "s4tan" Parata
|
Antonio "s4tan" Parata
|
||||||
|
Corey Kallenberg
|
||||||
|
Shift
|
||||||
|
|
||||||
Contributors (in no particular order)
|
Contributors (in no particular order)
|
||||||
=====================================
|
=====================================
|
||||||
|
|
|
@ -17,6 +17,10 @@ void hookMemAccess_cgo(uch handle, uc_mem_type type, uint64_t addr, int size, in
|
||||||
hookMemAccess(handle, type, addr, size, value, user);
|
hookMemAccess(handle, type, addr, size, value, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hookInterrupt_cgo(uch handle, uint32_t intno, void *user) {
|
||||||
|
hookInterrupt(handle, intno, 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) {
|
||||||
return hookX86In(handle, port, size, user);
|
return hookX86In(handle, port, size, user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,33 +17,39 @@ type HookData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//export hookCode
|
//export hookCode
|
||||||
func hookCode(handle C.uch, addr C.uint64_t, size C.uint32_t, user unsafe.Pointer) {
|
func hookCode(handle C.uch, addr uint64, size uint32, user unsafe.Pointer) {
|
||||||
hook := (*HookData)(user)
|
hook := (*HookData)(user)
|
||||||
hook.Callback.(func(*Uc, uint64, uint32))(hook.Uc, uint64(addr), uint32(size))
|
hook.Callback.(func(*Uc, uint64, uint32))(hook.Uc, uint64(addr), uint32(size))
|
||||||
}
|
}
|
||||||
|
|
||||||
//export hookMemInvalid
|
//export hookMemInvalid
|
||||||
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 {
|
func hookMemInvalid(handle C.uch, typ C.uc_mem_type, addr uint64, size int, value int64, user unsafe.Pointer) bool {
|
||||||
hook := (*HookData)(user)
|
hook := (*HookData)(user)
|
||||||
return C.bool(hook.Callback.(func(*Uc, int, uint64, int, int64) bool)(hook.Uc, int(typ), uint64(addr), size, int64(value)))
|
return hook.Callback.(func(*Uc, int, uint64, int, int64) bool)(hook.Uc, int(typ), addr, size, 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 uint64, size int, value int64, user unsafe.Pointer) {
|
||||||
hook := (*HookData)(user)
|
hook := (*HookData)(user)
|
||||||
hook.Callback.(func(*Uc, int, uint64, int, int64))(hook.Uc, int(typ), uint64(addr), size, int64(value))
|
hook.Callback.(func(*Uc, int, uint64, int, int64))(hook.Uc, int(typ), addr, size, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
//export hookInterrupt
|
||||||
|
func hookInterrupt(handle C.uch, intno uint32, user unsafe.Pointer) {
|
||||||
|
hook := (*HookData)(user)
|
||||||
|
hook.Callback.(func(*Uc, uint32))(hook.Uc, intno)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export hookX86In
|
//export hookX86In
|
||||||
func hookX86In(handle C.uch, port, size uint32, user unsafe.Pointer) C.uint32_t {
|
func hookX86In(handle C.uch, port, size uint32, user unsafe.Pointer) uint32 {
|
||||||
hook := (*HookData)(user)
|
hook := (*HookData)(user)
|
||||||
return C.uint32_t(hook.Callback.(func(*Uc, uint32, uint32) uint32)(hook.Uc, port, size))
|
return hook.Callback.(func(*Uc, uint32, uint32) uint32)(hook.Uc, port, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export hookX86Out
|
//export hookX86Out
|
||||||
func hookX86Out(handle C.uch, port, size, value uint32, user unsafe.Pointer) {
|
func hookX86Out(handle C.uch, port, size, value uint32, user unsafe.Pointer) {
|
||||||
hook := (*HookData)(user)
|
hook := (*HookData)(user)
|
||||||
hook.Callback.(func(*Uc, uint32, uint32, uint32))(hook.Uc, uint32(port), uint32(size), uint32(value))
|
hook.Callback.(func(*Uc, uint32, uint32, uint32))(hook.Uc, port, size, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export hookX86Syscall
|
//export hookX86Syscall
|
||||||
|
@ -64,6 +70,8 @@ func (u *Uc) HookAdd(htype int, cb interface{}, insn ...int) (C.uch, error) {
|
||||||
callback = C.hookMemInvalid_cgo
|
callback = C.hookMemInvalid_cgo
|
||||||
case UC_HOOK_MEM_READ, UC_HOOK_MEM_WRITE, UC_HOOK_MEM_READ_WRITE:
|
case UC_HOOK_MEM_READ, UC_HOOK_MEM_WRITE, UC_HOOK_MEM_READ_WRITE:
|
||||||
callback = C.hookMemAccess_cgo
|
callback = C.hookMemAccess_cgo
|
||||||
|
case UC_HOOK_INTR:
|
||||||
|
callback = C.hookInterrupt_cgo
|
||||||
case UC_HOOK_INSN:
|
case UC_HOOK_INSN:
|
||||||
extra = C.int(insn[0])
|
extra = C.int(insn[0])
|
||||||
switch extra {
|
switch extra {
|
||||||
|
|
|
@ -2,6 +2,7 @@ uc_err uc_hook_add2(uch handle, uch *h2, uc_hook_t type, void *callback, void *u
|
||||||
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, int size, 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);
|
||||||
|
void hookInterrupt_cgo(uch handle, uint32_t intno, 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);
|
||||||
void hookX86Syscall_cgo(uch handle, void *user);
|
void hookX86Syscall_cgo(uch handle, void *user);
|
||||||
|
|
33
regress/jmp_ebx_hang.py
Executable file
33
regress/jmp_ebx_hang.py
Executable 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"
|
Loading…
Reference in a new issue