Skip to content

Instantly share code, notes, and snippets.

@OliverLetterer
Last active August 29, 2015 14:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OliverLetterer/2e6ab0f8b259a20aa5de to your computer and use it in GitHub Desktop.
Save OliverLetterer/2e6ab0f8b259a20aa5de to your computer and use it in GitHub Desktop.
firstObject
IMP implementation = class_getMethodImplementation([NSArray class], @selector(firstObject));
Dl_info info;
if (dladdr(implementation, &info)) {
/*
info.dli_fname can be
* /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
* /private/var/mobile/Containers/Bundle/Application/E68D656E-7B57-4850-B2C9-86E31A053D24/cashier.app/cashier
*/
NSString *image = [NSString stringWithCString:info.dli_fname encoding:NSASCIIStringEncoding];
NSParameterAssert([image rangeOfString:@".app"].location == NSNotFound);
}
@implementation NSArray (BadThirdPartyImplementation)
- (id)firstObject
{
return self[0];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment