Skip to content

Instantly share code, notes, and snippets.

@zats
Last active Sep 16, 2019
Embed
What would you like to do?
Load private framework, core service, app, etc
void *handler = loadPrivate(@"ChatKit", TypePrivateFramework);
const Class CKGradientViewCls = NSClassFromString(@"CKGradientView");
UIView *const gradientView = [(UIView *)[CKGradientViewCls alloc] initWithFrame:{0, 0, 300, 200}];
#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;
}
@glm4

This comment has been minimized.

Copy link

@glm4 glm4 commented Sep 16, 2019

Hey there, is this allowed in AppStore submissions? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment