No description
Find a file
2024-12-23 10:03:33 +07:00
.github Create FUNDING.yml 2021-10-01 07:41:55 +07:00
src Sync w/ upstream: Added macos supports 2021-11-30 07:45:12 +07:00
tests add trampoline examples, refs #1 2020-06-25 08:49:41 +07:00
.gitignore Initial commit 2018-07-18 14:11:15 +07:00
.gitmodules Change subhook upstream to my mirror, closes #4 2024-12-23 10:03:33 +07:00
LICENSE Initial commit 2018-07-18 14:11:15 +07:00
README.md add trampoline examples, refs #1 2020-06-25 08:49:41 +07:00
subhook.nimble Change subhook upstream to my mirror, closes #4 2024-12-23 10:03:33 +07:00

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