Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hooking app frameworks #72

Open
haniag opened this issue May 7, 2022 · 1 comment
Open

Support hooking app frameworks #72

haniag opened this issue May 7, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@haniag
Copy link

haniag commented May 7, 2022

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

@haniag haniag added the enhancement New feature or request label May 7, 2022
@NSExceptional
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants