Skip to content

Instantly share code, notes, and snippets.

@dopcn
Created December 15, 2016 08:46
Show Gist options
  • Save dopcn/3ce7d562cfae32ad0dba85a8c24f1f71 to your computer and use it in GitHub Desktop.
Save dopcn/3ce7d562cfae32ad0dba85a8c24f1f71 to your computer and use it in GitHub Desktop.
fishhook hook NSSetUncaughtExceptionHandler
#import "AppDelegate.h"
#import "fishhook.h"
#import <dlfcn.h>
static NSUncaughtExceptionHandler *g_vaildUncaughtExceptionHandler;
static void (*ori_NSSetUncaughtExceptionHandler)( NSUncaughtExceptionHandler * );
void my_NSSetUncaughtExceptionHandler( NSUncaughtExceptionHandler * handler)
{
g_vaildUncaughtExceptionHandler = NSGetUncaughtExceptionHandler();
if (g_vaildUncaughtExceptionHandler != NULL) {
NSLog(@"UncaughtExceptionHandler=%p",g_vaildUncaughtExceptionHandler);
}
ori_NSSetUncaughtExceptionHandler(handler);
NSLog(@"%@",[NSThread callStackSymbols]);
g_vaildUncaughtExceptionHandler = NSGetUncaughtExceptionHandler();
NSLog(@"UncaughtExceptionHandler=%p",g_vaildUncaughtExceptionHandler);
}
int main(int argc, char *argv[])
{
@autoreleasepool {
ori_NSSetUncaughtExceptionHandler = dlsym(RTLD_DEFAULT, "NSSetUncaughtExceptionHandler");
rebind_symbols((struct rebinding[1]){{"NSSetUncaughtExceptionHandler", my_NSSetUncaughtExceptionHandler, (void **)&ori_NSSetUncaughtExceptionHandler}}, 1);
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment