-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathezfunchook.nim
33 lines (24 loc) · 960 Bytes
/
ezfunchook.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import ezfunchook/bindings
import ezutils
type FuncHook* = object
raw: ptr RawFuncHook
type FuncHookError* = object of ValueError
template check_result(res: HookResult) =
let re = res
if re != HookResult.hk_success:
raise newException(FuncHookError, $re)
proc `=destroy`*(fh: var FuncHook) =
if fh.raw != nil:
check_result fh.raw.funchook_destroy()
proc `=copy`*(self: var FuncHook, rhs: FuncHook) {.error.}
proc initFuncHook*(): FuncHook {.genrefnew.} =
result.raw = funchook_create()
if result.raw == nil:
raise newException(FuncHookError, "Failed to create funchook instance")
proc hook*[T](hk: var FuncHook, target: T, hooked: T): T {.genref.} =
result = target
check_result funchook_prepare(hk.raw, cast[ptr pointer](addr result), hooked)
proc install*(hk: var FuncHook) {.genref.} =
check_result funchook_install(hk.raw, 0)
proc uninstall*(hk: var FuncHook) {.genref.} =
check_result funchook_uninstall(hk.raw, 0)