ba0f3 / funchook.nim

kubo's funchook wrapper

Home Page:https://ba0f3.github.io/funchook.nim/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

funchook.nim

Build Status (github) made-with-python

funchook wrapper for Nim

This wrapper compiles funchook with diStorm3 disassembler.

Suports both x64 and x86-64 on:

  • Linux
  • Windows
  • MacOS (not tested yet)

Installation

nimble install funchook

Usage

import funchook

proc my_add(a, b: int): int =
  ## original proc to be hooked
  a + b

var add_func = my_add

proc hook_add(a, b: int): int =
  ## proc to replace my_add
  echo add_func(a, b) # call original proc with trampoline
  a * b

var h = initHook()

if h == nil:
  quit("Error: create funchook failed")

if h.prepare(addr add_func, hook_add) != SUCCESS:
  quit("Error: " & h.errorMessage())

assert my_add(4, 5) == 9, "pre-hook"

if h.install(0) != SUCCESS:
  quit("Error: " & h.errorMessage())

assert my_add(4, 5) == 20, "post-hook"

About

kubo's funchook wrapper

https://ba0f3.github.io/funchook.nim/

License:GNU General Public License v2.0


Languages

Language:Nim 99.6%Language:C 0.4%