Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ba0f3/subhook.nim

subhook wrapper for Nim https://github.com/Zeex/subhook
https://github.com/ba0f3/subhook.nim

api hook hooking linux macos nim subhook unix windows

Last synced: about 1 month ago
JSON representation

subhook wrapper for Nim https://github.com/Zeex/subhook

Awesome Lists containing this project

README

        

# subhook.nim
subhook wrapper for Nim https://github.com/Zeex/subhook

### Usage

```nim
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:
```nim
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
```