Skip to content

Instantly share code, notes, and snippets.

@kylehowells
Last active August 29, 2015 14:05
Show Gist options
  • Save kylehowells/eb380ea9c4221df31a17 to your computer and use it in GitHub Desktop.
Save kylehowells/eb380ea9c4221df31a17 to your computer and use it in GitHub Desktop.
How to correctly quit an application on iOS 7 (Correct = the same way the app switcher does)
// Function signature
void (*KH_BKSTerminateApplicationForReasonAndReportWithDescription)(NSString *app, int a, int b, NSString *description) = NULL;
// Find the Symbol.
if (KH_BKSTerminateApplicationForReasonAndReportWithDescription == NULL) {
// dlopen Handle
void* handle = dlopen(0,RTLD_NOW|RTLD_GLOBAL);
// Load the function to our pointer
KH_BKSTerminateApplicationForReasonAndReportWithDescription = dlsym(handle, "BKSTerminateApplicationForReasonAndReportWithDescription");
}
// If it all worked call it
if (KH_BKSTerminateApplicationForReasonAndReportWithDescription != NULL) {
KH_BKSTerminateApplicationForReasonAndReportWithDescription([application displayIdentifier], 1, 0, @"killed from app switcher");
}
// Old function
void *(*oldTerminateApplication)(NSString *app, int a, int b, NSString *description);
// New function
void *newTerminateApplication(NSString *app, int a, int b, NSString *description) {
NSLog(@"BKSTerminateApplicationForReasonAndReportWithDescription(%@, %d, %d, %@)", app, a, b, description);
return oldTerminateApplication(app, a, b, description);
}
// Find symbol
void *handle = dlopen(0,RTLD_NOW|RTLD_GLOBAL);
void *bskTerminateApplicationWithReasonReference = dlsym(handle, "BKSTerminateApplicationForReasonAndReportWithDescription");
// If it worked MSHookFunction it
if (!bskTerminateApplicationWithReasonReference) {
NSLog(@"dlsym FAILED to find BKSTerminateApplicationForReasonAndReportWithDescription");
}
else {
MSHookFunction(bskTerminateApplicationWithReasonReference, (void *)&newTerminateApplication, (void **)&oldTerminateApplication);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment