Skip to content

Instantly share code, notes, and snippets.

@samdmarshall
Created March 5, 2014 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samdmarshall/9369619 to your computer and use it in GitHub Desktop.
Save samdmarshall/9369619 to your computer and use it in GitHub Desktop.
#define DYLD_INTERPOSE(_replacement,_replacee) \
__attribute__((used)) static struct{ const void* replacement; const void* replacee; } _interpose_##_replacee \
__attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacement, (const void*)(unsigned long)&_replacee };
DYLD_INTERPOSE(my_function_replacement, original_function);
int original_function() {
return 5;
}
int my_function_replacement() {
int result = original_function();
printf("%i\n",result);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment