Aspects icon indicating copy to clipboard operation
Aspects copied to clipboard

Find a bug and a serious bug

Open youlianchun opened this issue 8 years ago • 0 comments

bug:The interception of class methods and instance methods is not possible. Defect: instead of replacing the original method body with AspectPositionInstead, there is nothing you can do if the original method calls the super method. So let's say I'm going to replace it with a -- [UIViewController viewDidLoad:] method. and I have an idea.

//class: @interface ObjectS : NSObject -(void)function:(NSString*)str; -(void)function2:(NSString*)str; @end @implementation ObjectS -(void)function:(NSString*)str { NSLog(@"super"); [self function2:str]; } -(void)function2:(NSString*)str { NSLog(@"%s %@", func, str); } @end

@interface Object : ObjectS -(void)function:(NSString*)str; -(void)function2:(NSString*)str; +(void)classFunction:(NSString*)str; @end

@implementation Object -(void)function:(NSString*)str { [super function:str]; NSLog(@"%s %@", func, str); } -(void)function2:(NSString*)str { [super function2:str]; NSLog(@"%s %@", func, str); } +(void)classFunction:(NSString*)str { NSLog(@"%s %@", func, str); } @end

The test code, [intercept 1] and [intercept 2], is not valid. Single execution [intercept 1] - [Object function2:] cannot be executed (replace the original execution process, which can not be replaced by a single execution - [Object function:] comparison) code is as follows: Object * obj = [[Object alloc] init];

//intercept 1

[obj aspect_hookSelector:@selector(function:) withOptions:AspectPositionInstead usingBlock:^(NSString*str){ NSLog(@"object"); } error:NULL]; [obj function:@"1"];

//intercept 2

[[Object class] aspect_hookSelector:@selector(classFunction:) withOptions:AspectPositionAfter usingBlock:^(NSString*str){ NSLog(@"Object"); } error:NULL]; [Object classFunction:@"2"];

youlianchun avatar Jul 22 '17 05:07 youlianchun