Skip to content

Instantly share code, notes, and snippets.

@zats
Last active September 16, 2019 16:19
Show Gist options
  • Save zats/2bf04c91039492bfb976395e55b473a7 to your computer and use it in GitHub Desktop.
Save zats/2bf04c91039492bfb976395e55b473a7 to your computer and use it in GitHub Desktop.
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
Copy link

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