Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#import <dlfcn.h>
#import <mach-o/dyld.h>
#import <mach-o/loader.h>
int main(int argc, char *argv[]) {
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] executablePath]];
NSData *codeSignatureData = nil;
const struct mach_header *header = [data bytes];
const struct load_command *cmd = (void *)(header + 1);
for (uint32_t i = 0; i < header->ncmds; i++) {
if (cmd->cmd == LC_CODE_SIGNATURE) {
struct linkedit_data_command *ldc = (void *)cmd;
codeSignatureData = [data subdataWithRange:NSMakeRange(ldc->dataoff, ldc->datasize)];
break;
}
cmd = (void *)((const char *)cmd) + cmd->cmdsize;
}
const char *ptr = [codeSignatureData bytes];
char *start = memmem([codeSignatureData bytes], [codeSignatureData length], "<plist version=", 15);
char *end = memmem(start, [codeSignatureData length] - (start - ptr), "</plist>", 8) + 8;
NSError *error = nil;
NSRange range = NSMakeRange(start - ptr, end - start);
NSData *plistData = [codeSignatureData subdataWithRange:range];
NSDictionary *plist = [NSPropertyListSerialization propertyListWithData:plistData options:0 format:NULL error:&error];
NSLog(@"%@", plist);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment