Skip to content

mikaelbo/AutoHookExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoHookExample

Sample project for creating a dynamic framework for method swizzling and code injection.

  • Create a class that conforms to MBAutoHook
  • Implement + (NSArray<NSString *> *)targetClasses to specify which classes you want to hook
  • hook_ + method name for the method you want to hook, e.g. - (void)hook_viewDidLoad
  • orig_ + method name as a placeholder for the original implementation, e.g. - (void)orig_viewDidLoad
@interface ViewControllerHook: UIViewController <MBAutoHook>
@end

@implementation ViewControllerHook

+ (NSArray<NSString *> *)targetClasses {
    return @[@"ViewController"];
}

- (void)hook_viewDidLoad {
    [self orig_viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
}

// MARK: Placeholder

- (void)orig_viewDidLoad { }

@end

Credits

John Coates for sharing his auto hook code. My implementation is slightly modified to properly work for class methods.

About

Sample project for creating a dynamic framework for method swizzling and code injection.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published