:: horsing around with the C++ programming language


If you need to make an existing function behave differently, but all you have is a compiled binary, API hooking may be what you need.

By creating a function with the same signature, you can install it as a replacement!

nanohook performs a similar job to Microsoft Detours and EasyHook but has a less restrictive license.

Recent activity


Clone the repository using mercurial:

> hg clone

Or get a zip file of the code.

Quick start

Let's replace Windows' ExitProcess function as an example.

// basic.cpp
#include <nanohook/nanohook.hpp>
#include <windows.h>
#include <cstdio>

nanohook::hook ExitProcess_hook;

VOID WINAPI ExitProcess_replacement(UINT code)

    // Now we call the original ExitProcess function to actually exit.
    VOID (WINAPI *old)(UINT) = ExitProcess_hook.original();

int main()
    // Install the hook
    nanohook::hook h(ExitProcess, ExitProcess_replacement);

    // Call ExitProcess, which will now invoke our hook, ExitProcess_replacement
    // rather than the original ExitProcess.

    return 0;
P:\software\nanohook> basic.exe

nanohook supports Win32 and Win64.

Further reading


(required, hint)

Links can be added like [this one ->], to my homepage.
Phrases and blocks of code can be enclosed in {{{triple braces}}}.
Any HTML markup will be escaped.