1#include <stdio.h> // fprintf(), NULL 2#include <stdlib.h> // exit(), EXIT_SUCCESS 3#include <string.h> 4#include <dlfcn.h> 5#include <crt_externs.h> 6#include <mach-o/dyld_priv.h> 7 8 9int foo() { return 0; } 10 11int alt_foo() { return 10; } 12 13 14 15 16static const struct dyld_interpose_tuple sTable[] = { {&alt_foo, &foo} }; 17 18 19__attribute__((constructor)) 20void init() 21{ 22 // switch main executable to use alt_foo() when it calls foo() 23 dyld_dynamic_interpose((const struct mach_header*)_NSGetMachExecuteHeader(), sTable, 1); 24 25} 26 27