mirror of
https://github.com/ba0f3/subhook.nim
synced 2026-01-08 04:51:15 +00:00
No description
| .github | ||
| src | ||
| tests | ||
| .gitignore | ||
| .gitmodules | ||
| LICENSE | ||
| README.md | ||
| subhook.nimble | ||
subhook.nim
subhook wrapper for Nim https://github.com/Zeex/subhook
Usage
import subhook, subhook/helpers
proc recv(s: SOCKET, buf: cstring, len: int32, flags: int32): int32 {.fptr.} = 0x123456
proc MY_recv(s: SOCKET, buf: cstring, len: int32, flags: int32): int32 {.stdcall.} =
discard
let hook = initHook(recv, MY_recv)
if hook.install() != 0:
quit "Unable to install revc hook"
Trampoline example:
import subhook
proc add2(a, b: int): int =
result = a + b
echo "add2 result = ", result
var addHook: Hook
proc double_add2(a, b: int): int =
echo "add called"
result = cast[typeof(add2)](addHook.getTrampoline())(a, b) * 2
addHook = initHook(add2, double_add2, true)
assert add2(1, 3) == 8