Created
March 1, 2023 12:41
-
-
Save EthanArbuckle/8a137ca4b97b4817835525a1e2846ebc to your computer and use it in GitHub Desktop.
control permissions of apps installed in the ios simulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// permission-changer | |
// | |
// Created by Ethan Arbuckle on 3/1/23. | |
// | |
#import <Foundation/Foundation.h> | |
#include <dlfcn.h> | |
#include <objc/runtime.h> | |
#include <objc/message.h> | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
NSString *targetAppBundleID = @"com.ea.test1"; | |
BOOL isGranted = YES; | |
NSString *permissionService = @"kTCCServiceUserTracking"; | |
// kTCCServiceAll | |
// kTCCServicePhotos | |
// kTCCServiceCalendar | |
// kTCCServiceMediaLibrary | |
// kTCCServiceMicrophone | |
// kTCCServicePhotosAdd | |
// kTCCServiceReminders | |
// kTCCServiceSiri | |
// kTCCServiceMotion | |
// kTCCServiceContactsFull | |
// kTCCServiceContactsLimited | |
dlopen("/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator", 0); | |
NSError *err; | |
Class SimServiceContext = objc_getClass("SimServiceContext"); | |
id serviceContext = ((id (*)(id, SEL, id, NSError **))objc_msgSend)(SimServiceContext, sel_registerName("sharedServiceContextForDeveloperDir:error:"), @"/Applications/Xcode.app/Contents/Developer", &err); | |
id deviceSet = ((id (*)(id, SEL, NSError **))objc_msgSend)(serviceContext, sel_registerName("defaultDeviceSetWithError:"), &err); | |
if (err) { | |
NSLog(@"failed to get deviceset using shared service context"); | |
return KERN_FAILURE; | |
} | |
id bootedDevice = nil; | |
for (id device in ((id (*)(id, SEL))objc_msgSend)(deviceSet, sel_registerName("devices"))) { | |
NSString *state = ((id (*)(id, SEL))objc_msgSend)(device, sel_registerName("stateString")); | |
if ([state isEqualToString:@"Booted"]) { | |
bootedDevice = device; | |
} | |
} | |
NSLog(@"device: %@", bootedDevice); | |
// Grant or Deny a permission | |
((void (*)(id, SEL, id, NSString *, BOOL, NSError **))objc_msgSend)(bootedDevice, sel_registerName("setPrivacyAccessForService:bundleID:granted:error:"), permissionService, targetAppBundleID, isGranted, &err); | |
// Reset permission | |
// ((void (*)(id, SEL, id, NSString *, NSError **))objc_msgSend)(bootedDevice, sel_registerName("resetPrivacyAccessForService:bundleID:error:"), permissionService, targetAppBundleID, &err); | |
if (err) { | |
NSLog(@"failed to change privacy access level: %@", err); | |
return KERN_FAILURE; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment