diff --git a/bindings/go/unicorn/hook.c b/bindings/go/unicorn/hook.c index a06f9901..f24dd1f1 100644 --- a/bindings/go/unicorn/hook.c +++ b/bindings/go/unicorn/hook.c @@ -1,8 +1,12 @@ #include #include "_cgo_export.h" -uc_err uc_hook_add2(uch handle, uch *h2, uc_hook_t type, void *callback, void *user_data, int extra) { - return uc_hook_add(handle, h2, type, callback, user_data, 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, 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) { diff --git a/bindings/go/unicorn/hook.go b/bindings/go/unicorn/hook.go index dcab893a..e6e01617 100644 --- a/bindings/go/unicorn/hook.go +++ b/bindings/go/unicorn/hook.go @@ -60,21 +60,26 @@ func hookX86Syscall(handle C.uch, user unsafe.Pointer) { 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 extra C.int + var iarg1 C.int + var uarg1, uarg2 C.uint64_t + rangeMode := false switch htype { case UC_HOOK_BLOCK, UC_HOOK_CODE: + rangeMode = true callback = C.hookCode_cgo case UC_HOOK_MEM_INVALID: + rangeMode = true callback = C.hookMemInvalid_cgo case UC_HOOK_MEM_READ, UC_HOOK_MEM_WRITE, UC_HOOK_MEM_READ_WRITE: + rangeMode = true callback = C.hookMemAccess_cgo case UC_HOOK_INTR: callback = C.hookInterrupt_cgo case UC_HOOK_INSN: - extra = C.int(insn[0]) - switch extra { + iarg1 = C.int(extra[0]) + switch iarg1 { case UC_X86_INS_IN: callback = C.hookX86In_cgo 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 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 return h2, nil } diff --git a/bindings/go/unicorn/hook.h b/bindings/go/unicorn/hook.h index c8c22267..b35fca27 100644 --- a/bindings/go/unicorn/hook.h +++ b/bindings/go/unicorn/hook.h @@ -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); 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);