Merge pull request #101 from lunixbochs/master
fix go binding hook arguments
This commit is contained in:
commit
256c7f01a5
@ -1,8 +1,12 @@
|
|||||||
#include <unicorn/unicorn.h>
|
#include <unicorn/unicorn.h>
|
||||||
#include "_cgo_export.h"
|
#include "_cgo_export.h"
|
||||||
|
|
||||||
uc_err uc_hook_add2(uch handle, uch *h2, uc_hook_t type, void *callback, void *user_data, int extra) {
|
uc_err uc_hook_add_i1(uch handle, uch *h2, uc_hook_t type, void *callback, void *user, int arg1) {
|
||||||
return uc_hook_add(handle, h2, type, callback, user_data, extra);
|
return uc_hook_add(handle, h2, type, callback, user, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
uc_err uc_hook_add_u2(uch handle, uch *h2, uc_hook_t type, void *callback, void *user, uint64_t arg1, uint64_t arg2) {
|
||||||
|
return uc_hook_add(handle, h2, type, callback, user, arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -60,21 +60,26 @@ func hookX86Syscall(handle C.uch, user unsafe.Pointer) {
|
|||||||
|
|
||||||
var hookRetain = make(map[C.uch]*HookData)
|
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{}, extra ...uint64) (C.uch, error) {
|
||||||
var callback unsafe.Pointer
|
var callback unsafe.Pointer
|
||||||
var extra C.int
|
var iarg1 C.int
|
||||||
|
var uarg1, uarg2 C.uint64_t
|
||||||
|
rangeMode := false
|
||||||
switch htype {
|
switch htype {
|
||||||
case UC_HOOK_BLOCK, UC_HOOK_CODE:
|
case UC_HOOK_BLOCK, UC_HOOK_CODE:
|
||||||
|
rangeMode = true
|
||||||
callback = C.hookCode_cgo
|
callback = C.hookCode_cgo
|
||||||
case UC_HOOK_MEM_INVALID:
|
case UC_HOOK_MEM_INVALID:
|
||||||
|
rangeMode = true
|
||||||
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:
|
||||||
|
rangeMode = true
|
||||||
callback = C.hookMemAccess_cgo
|
callback = C.hookMemAccess_cgo
|
||||||
case UC_HOOK_INTR:
|
case UC_HOOK_INTR:
|
||||||
callback = C.hookInterrupt_cgo
|
callback = C.hookInterrupt_cgo
|
||||||
case UC_HOOK_INSN:
|
case UC_HOOK_INSN:
|
||||||
extra = C.int(insn[0])
|
iarg1 = C.int(extra[0])
|
||||||
switch extra {
|
switch iarg1 {
|
||||||
case UC_X86_INS_IN:
|
case UC_X86_INS_IN:
|
||||||
callback = C.hookX86In_cgo
|
callback = C.hookX86In_cgo
|
||||||
case UC_X86_INS_OUT:
|
case UC_X86_INS_OUT:
|
||||||
@ -89,7 +94,17 @@ func (u *Uc) HookAdd(htype int, cb interface{}, insn ...int) (C.uch, error) {
|
|||||||
}
|
}
|
||||||
var h2 C.uch
|
var h2 C.uch
|
||||||
data := &HookData{u, cb}
|
data := &HookData{u, cb}
|
||||||
C.uc_hook_add2(u.Handle, &h2, C.uc_hook_t(htype), callback, unsafe.Pointer(data), extra)
|
if rangeMode {
|
||||||
|
if len(extra) == 2 {
|
||||||
|
uarg1 = C.uint64_t(extra[0])
|
||||||
|
uarg2 = C.uint64_t(extra[1])
|
||||||
|
} else {
|
||||||
|
uarg1, uarg2 = 1, 0
|
||||||
|
}
|
||||||
|
C.uc_hook_add_u2(u.Handle, &h2, C.uc_hook_t(htype), callback, unsafe.Pointer(data), uarg1, uarg2)
|
||||||
|
} else {
|
||||||
|
C.uc_hook_add_i1(u.Handle, &h2, C.uc_hook_t(htype), callback, unsafe.Pointer(data), iarg1)
|
||||||
|
}
|
||||||
hookRetain[h2] = data
|
hookRetain[h2] = data
|
||||||
return h2, nil
|
return h2, nil
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
uc_err uc_hook_add2(uch handle, uch *h2, uc_hook_t type, void *callback, void *user_data, int extra);
|
uc_err uc_hook_add_i1(uch handle, uch *h2, uc_hook_t type, void *callback, void *user_data, int arg1);
|
||||||
|
uc_err uc_hook_add_u2(uch handle, uch *h2, uc_hook_t type, void *callback, void *user_data, uint64_t arg1, uint64_t arg2);
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user