Make AppEntitlements() work in the simulator

This commit is contained in:
Theodore Dubois 2020-03-08 19:14:00 -07:00
parent fa03338402
commit 670dfeca8f

View File

@ -7,6 +7,7 @@
#import <Foundation/Foundation.h>
#include <mach-o/loader.h>
#include <mach-o/getsect.h>
#include <dlfcn.h>
struct cs_blob_index {
@ -45,6 +46,19 @@ static NSDictionary *AppEntitlements() {
if (header->magic != MH_MAGIC_64)
return nil;
// Simulator executables have fake entitlements in the code signature. The real entitlements can be found in an __entitlements section.
size_t entitlements_size;
uint8_t *entitlements_data = getsectiondata(header, "__TEXT", "__entitlements", &entitlements_size);
if (entitlements_data != NULL) {
NSData *data = [NSData dataWithBytesNoCopy:entitlements_data
length:entitlements_size
freeWhenDone:NO];
return entitlements = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListImmutable
format:nil
error:nil];
}
// Find the LC_CODE_SIGNATURE
struct load_command *lc = (void *) (base + sizeof(*header));
struct linkedit_data_command *cs_lc = NULL;