by rodionovd

rodionovd /rd_route

Function hooking for macOS

133 Stars 14 Forks Last release: over 5 years ago (1.1.1) MIT License 79 Commits 3 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


Build Status
Replace (aka «hook» or «override» or «route») implementation of any C function in runtime. Works on OS X with Mach–O binaries.

Do not use this code. It can destroy everthing. But if you do, I wish you a luck.


won't work on iOS. You should take a look at
Aaand it won't work for you too if you're targeting ARM64. Unfortunately I don't have a modern iOS device and thus unable to look into it, but maybe you do?


#include "rd_route.h"

static char* my_strerror(int err) { return "It's OK"; }

int main (void) {

void *(*original)(int) = NULL;
int err = 2;

printf("Error(%d): %s", err, strerror(err));
// >> No such file or directory

rd_route(strerror, my_strerror, (void **)&original);

// See if the patch works
assert(0 == strcmp("It's OK", strerror(err)));
// See if an original implementation is still available
assert(0 == strcmp("No such file or directory", original(err)));

return 0;

} </assert.h>


Using git submodules

$ cd /your/project/path
$ git submodule add https://github.com/rodionovd/rd_route

Not using git submodules

Just copy

files into your project's directory.

But wait, we already have
for this stuff

I've created this library because

requires an external disassembler in order to work properly. For those of us who don't want another few thousands of lines of foreign code in their projects, the only option is to hard-code every function prologue they know in order to patch it correctly — which isn't a great alternative to have, to be honest.


  • The source code is based on Landon Fuller's (@landonf) gorgeous


  • I'm also glade we have Jonathan 'Wolf' Rentzsch out there with his classy


If you found any bug(s) or something, please open an issue or a pull request — I'd appreciate your help!


Dmitry Rodionov, 2014-2015
[email protected]

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.