Last active
September 16, 2019 16:19
-
-
Save zats/2bf04c91039492bfb976395e55b473a7 to your computer and use it in GitHub Desktop.
Load private framework, core service, app, etc
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
void *handler = loadPrivate(@"ChatKit", TypePrivateFramework); | |
const Class CKGradientViewCls = NSClassFromString(@"CKGradientView"); | |
UIView *const gradientView = [(UIView *)[CKGradientViewCls alloc] initWithFrame:{0, 0, 300, 200}]; |
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
#import <dlfcn.h> | |
typedef NS_ENUM(NSInteger, Type) { | |
TypePrivateFramework, | |
TypeCoreService, | |
TypeApplication, | |
TypePreferenceBundles, | |
TypeControlCenterBundles, | |
}; | |
static void *loadPrivate(NSString *name, Type type) | |
{ | |
NSString *const uiKitPath = [NSBundle bundleForClass:[UIButton class]].bundlePath; | |
NSString *containerFolderPath; | |
switch (type) { | |
case TypePrivateFramework: | |
containerFolderPath = | |
[uiKitPath | |
.stringByDeletingLastPathComponent // Frameworks | |
.stringByDeletingLastPathComponent // Library | |
stringByAppendingPathComponent:@"PrivateFrameworks"]; | |
break; | |
case TypeControlCenterBundles: | |
containerFolderPath = | |
[uiKitPath | |
.stringByDeletingLastPathComponent // Frameworks | |
.stringByDeletingLastPathComponent // Library | |
stringByAppendingPathComponent:@"ControlCenter/Bundles"]; | |
break; | |
case TypePreferenceBundles: | |
containerFolderPath = | |
[uiKitPath | |
.stringByDeletingLastPathComponent // Frameworks | |
.stringByDeletingLastPathComponent // Library | |
stringByAppendingPathComponent:@"PreferenceBundles"]; | |
break; | |
case TypeCoreService: | |
containerFolderPath = | |
[uiKitPath | |
.stringByDeletingLastPathComponent // Frameworks | |
.stringByDeletingLastPathComponent // Library | |
stringByAppendingPathComponent:@"CoreServices"]; | |
break; | |
case TypeApplication: | |
containerFolderPath = | |
[uiKitPath | |
.stringByDeletingLastPathComponent // Frameworks | |
.stringByDeletingLastPathComponent // Library | |
.stringByDeletingLastPathComponent // System | |
.stringByDeletingLastPathComponent // / | |
stringByAppendingPathComponent:@"Applications"]; | |
break; | |
} | |
NSArray *const extensionsToTry = @[ @"framework", @"app", @"bundle" ]; | |
for (NSString *const extension in extensionsToTry) { | |
NSString *const binaryPath = | |
[[[containerFolderPath | |
stringByAppendingPathComponent:name] | |
stringByAppendingPathExtension:extension] | |
stringByAppendingPathComponent:name]; | |
void *handler = dlopen([binaryPath cStringUsingEncoding:NSUTF8StringEncoding], RTLD_NOW); | |
if (handler) { | |
return handler; | |
} | |
} | |
NSCAssert(NO, @"Failed to find %@ of type %tu", name, type); | |
return nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey there, is this allowed in AppStore submissions? 🤔