美文网首页
iOS源码安全

iOS源码安全

作者: 赤狼_杨昆宏 | 来源:发表于2016-12-23 11:59 被阅读26次

    话不多说直接上代码,欢迎共同探讨!

    + (BOOL)swizzle:(SEL)original with:(IMP)replacement store:(IMPPointer)store {

    return class_swizzleMethodAndStore(self, original, replacement, store);

    }

    BOOL class_swizzleMethodAndStore(Class class, SEL original, IMP replacement, IMPPointer store) {

    IMP imp = NULL;

    Method method = class_getInstanceMethod(class, original);

    if (method) {

    const char *type = method_getTypeEncoding(method);

    imp = class_replaceMethod(class, original, replacement, type);

    if (!imp) {

    imp = method_getImplementation(method);

    }

    }

    if (imp && store) { *store = imp; }

    return (imp != NULL);

    }

    程序入口

    +(void)load{

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

    [self swizzle:@selector(viewWillAppear:) with:(IMP)xxx_viewWillAppear store:(IMP *)&Setxxx_viewWillAppearIMP];

    });

    }

    static void xxx_viewWillAppear(id self,SEL _cmd,BOOL animated);

    static void (*Setxxx_viewWillAppearIMP)(id self, SEL _cmd, BOOL animated);

    static void xxx_viewWillAppear(id self, SEL _cmd, BOOL animated) {

    Setxxx_viewWillAppearIMP(self, _cmd, animated);

    NSLog(@"viewWillAppear = %s",__func__);

    }

    相关文章

      网友评论

          本文标题:iOS源码安全

          本文链接:https://www.haomeiwen.com/subject/rtdkvttx.html