Back to the origin project by LGPerson
:
// .h
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface LGPerson : NSObject
- (void)saySomething;
+ (void)sayLove;
@end
NS_ASSUME_NONNULL_END
// .m
#import "LGPerson.h"
@implementation LGPerson
- (void)sayAwesome {
NSLog(@"%s",__func__);
}
+ (void)sayHappay {
NSLog(@"%s",__func__);
}
@end
The LGStudent
:
// .h
#import "LGPerson.h"
NS_ASSUME_NONNULL_BEGIN
@interface LGStudent : LGPerson
- (void)sayHello;
+ (void)sayObject;
@end
NS_ASSUME_NONNULL_END
// .m
#import "LGStudent.h"
#import <objc/message.h>
@implementation LGStudent
- (void)sayHello {
NSLog(@"%s",__func__);
}
+ (void)sayObject {
NSLog(@"%s",__func__);
}
@end
The NSObject+LG
:
// .h
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSObject (LG)
- (void)sayMaster;
+ (void)sayEasy;
@end
NS_ASSUME_NONNULL_END
// .m
#import "NSObject+LG.h"
#import <objc/message.h>
#import <AppKit/AppKit.h>
@implementation NSObject (LG)
- (void)sayMaster {
NSLog(@"%s",__func__);
}
+ (void)sayEasy {
NSLog(@"%s",__func__);
}
@end
Then in main.m
#import <Foundation/Foundation.h>
#import "LGStudent.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
LGStudent *student = [[LGStudent alloc] init];
[student saySomething];
}
return 0;
}
Run and crash. But watch carefully here:
stack_info_forwarding.pngCoreFoundation`___forwarding___:
...
0x7fff3c7df605 <+185>: movq 0x58dacdc4(%rip), %r14 ; "forwardingTargetForSelector:"
...
0x7fff3c7df6a9 <+349>: movq 0x58dacce8(%rip), %rbx ; "methodSignatureForSelector:"
...
0x7fff3c7df76d <+545>: movq 0x58dacc64(%rip), %rsi ; "_forwardStackInvocation:"
...
0x7fff3c7df826 <+730>: movq 0x58dacbab(%rip), %rsi ; "_forwardStackInvocation:"
...
0x7fff3c7df840 <+756>: movq 0x58dacba9(%rip), %r15 ; "forwardInvocation:"
...
0x7fff3c7dfaa6 <+1370>: movq 0x58dab7c3(%rip), %rbx ; "doesNotRecognizeSelector:"
If you want to check the code in CoreFoundation here:
core_foundation.pngNothing can be found. Now it's time for Hopper
/ IDA
and try path like (I use the Hopper here):
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework
We will compare with each other:
hopper_1.png hopper_2.png hopper_3.png hopper_4.png hopper_5.pngThat's another way to check the Slow Path.
网友评论