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

https://github.com/eleme/Stinger

posted @ 2017-08-29 00:34  七夜i  阅读(951)  评论(0编辑  收藏  举报