MOAspects is AOP library for iOS.
Stable version for Objective-C language.
Swift language supported and development version.
pod 'MOAspects', '~> 1.0.0'
pod 'MOAspects'
#pragma mark - Hook instance method
+ (BOOL)hookInstanceMethodForClass:(Class)clazz
selector:(SEL)selector
aspectsPosition:(MOAspectsPosition)aspectsPosition
usingBlock:(id)block;
+ (BOOL)hookInstanceMethodForClass:(Class)clazz
selector:(SEL)selector
aspectsPosition:(MOAspectsPosition)aspectsPosition
hookRange:(MOAspectsHookRange)hookRange
usingBlock:(id)block;
#pragma mark - Hook class method
+ (BOOL)hookClassMethodForClass:(Class)clazz
selector:(SEL)selector
aspectsPosition:(MOAspectsPosition)aspectsPosition
usingBlock:(id)block;
+ (BOOL)hookClassMethodForClass:(Class)clazz
selector:(SEL)selector
aspectsPosition:(MOAspectsPosition)aspectsPosition
hookRange:(MOAspectsHookRange)hookRange
usingBlock:(id)block;
[MOAspects hookClassMethodForClass:[NSNumber class]
selector:@selector(numberWithInt:)
aspectsPosition:MOAspectsPositionBefore
usingBlock:^(id class, int intVar){
NSLog(@"hooked %d number!", intVar);
}];
[NSNumber numberWithInt:10]; // -> hooked 10 number!
[MOAspects hookInstanceMethodForClass:[NSString class]
selector:@selector(length)
aspectsPosition:MOAspectsPositionBefore
usingBlock:^(NSString *string){
NSLog(@"hooked %@!", string);
}];
[@"abcde" length]; // -> hooked abcde!
MOAspects.hookClassMethodForClass(UIScreen.self, selector:"mainScreen", position:.Before) {
NSLog("hooked screen!")
}
UIScreen.mainScreen() // -> hooked screen!
MOAspects.hookInstanceMethodForClass(ViewController.self, selector:"viewDidLoad", position:.After) {
NSLog("view did loaded!")
}
// -> view did loaded!
32bit | 64bit | Can Hook Method Type |
Class Hierarchy Hook |
Hook Return Value |
Natural Swift Method |
---|---|---|---|---|---|
○ | ○ | Instance / Class | Supported | Not supported | Not supported |