Support hooking app frameworks
haniag opened this issue · 1 comments
haniag commented
Feature Request
Is your feature request related to a problem? Please describe.
When I run the application, only code within it can be swizzled. The code within the frameworks used by the application can't be swizzled/accessed.
Describe the solution you'd like
I used this code to load all frameworks on iOS using dlopen to hook app frameworks, and it can be adapted to MacForge:
NSString *pfpath = [[NSBundle mainBundle] privateFrameworksPath];
for (NSString *dir in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pfpath error:NULL]) {
NSMutableString *fpath = [pfpath mutableCopy];
NSArray *components = [dir componentsSeparatedByString:@"."];
NSString *fname = components[0];
[fpath appendFormat:@"/%@/%@", dir, fname];
if ([fpath rangeOfString:@"swift"].location == NSNotFound) {
dlopen([fpath UTF8String], RTLD_NOW);
}
}
Describe alternatives you've considered
None.
Teachability, Documentation, Adoption, Migration Strategy
N/A
NSExceptional commented
If you want to hook a framework class, all you need to do is dlopen
that one framework (not all of them) to ensure it is first loaded, and then use NSClassFromString()
to look up the class by name to swizzle it with.