Skip to content

bakkesmodorg/funchook

 
 

Repository files navigation

Funchook - an API hook library

This library depends on diStorm3.

Build Status Build status

TODO

  • write documents.

Supported Platforms

  • Linux x86_64 (*1)
  • Linux x86 (*1)
  • OS X x86_64 (*1)
  • OS X x86 (*1)
  • Windows x64 (*2) (except C-runtime functions under Wine)
  • Windows 32-bit (*2)

*1 tested on Travis CI
*2 tested on AppVeyor

Compilation

$ git clone --recursive https://github.com/kubo/funchook.git
$ cd funchook
$ ./autogen.sh
$ ./configure
$ make
$ make test

Example

static ssize_t (*send_func)(int sockfd, const void *buf, size_t len, int flags);
static ssize_t (*recv_func)(int sockfd, void *buf, size_t len, int flags);

static ssize_t send_hook(int sockfd, const void *buf, size_t len, int flags);
{
    ssize_t rv;

    ... do your task: logging, etc. ...
    rv = send_func(sockfd, buf, len, flags); /* call the original send(). */
    ... do your task: logging, checking the return value, etc. ...
    return rv;
}

static ssize_t recv_hook(int sockfd, void *buf, size_t len, int flags);
{
    ssize_t rv;

    ... do your task: logging, etc. ...
    rv = recv_func(sockfd, buf, len, flags); /* call the original recv(). */
    ... do your task: logging, checking received data, etc. ...
    return rv;
}

int install_hooks()
{
    funchook_t *funchook = funchook_create();
    int rv;

    /* Prepare hooking.
     * The return value is used to call the original send function
     * in send_hook.
     */
    send_func = send;
    rv = funchook_prepare(funchook, (void**)&send_func, send_hook);
    if (rv != 0) {
       /* error */
       ...
    }

    /* ditto */
    recv_func = recv;
    rv = funchook_prepare(funchook, (void**)&recv_func, recv_hook);
    if (rv != 0) {
       /* error */
       ...
    }

    /* Install hooks.
     * The first 5-byte code of send() and recv() are changed respectively.
     */
    rv = funchook_install(funchook, 0);
    if (rv != 0) {
       /* error */
       ...
    }
}

License

GPLv2 or later with a GPL linking exception.

You can use funchook in any software. Though funchook is licensed under the GPL, it doesn't affect outside of funchook due to the linking exception. You have no need to open your souce code under the GPL except funchook itself.

If you modify funchook itself and release it, the modifed part must be open under the GPL with or without the linking exception because funchook itself is under the GPL.

diStorm3 has been released under 3-clause BSD since Nov 19, 2016. The license is compatible with the GPL.

About

Funchook - an API Hook Library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 83.1%
  • Shell 7.9%
  • Assembly 6.2%
  • Makefile 2.2%
  • M4 0.6%