iOS 常用的Hook方式
常用的HOOK方式
1、Method Swizzling
Method originalMethod = class_getInstanceMethod([self class], originalSelector);
Method swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);
BOOL didAddMethod =
class_addMethod([self class],
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod([self class],
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
2、消息转发:Aspects
https://github.com/steipete/Aspects
3、通过fishhook:除了可以hook c函数,fishhook+汇编还可以hook objc_msgSend实现全打点.
https://github.com/facebook/fishhook
4、Cydia Substrate
5、通过libffi:饿了么开源的Stinger
解决问题的能力很关键~(iOS开发交流群:219926126)