1 #include <stdio.h> // fprintf(), NULL
2 #include <stdlib.h> // exit(), EXIT_SUCCESS
5 #include <crt_externs.h>
6 #include <mach-o/dyld_priv.h>
9 int foo() { return 0; }
11 int alt_foo() { return 10; }
16 static const struct dyld_interpose_tuple sTable
[] = { {&alt_foo
, &foo
} };
19 __attribute__((constructor
))
22 // switch main executable to use alt_foo() when it calls foo()
23 dyld_dynamic_interpose((const struct mach_header
*)_NSGetMachExecuteHeader(), sTable
, 1);