美文网首页
1、使用Category和Hook 给集合做保护

1、使用Category和Hook 给集合做保护

作者: 奋斗的蝼蚁 | 来源:发表于2018-01-27 18:55 被阅读0次

1、数组一般新建一个Safe的Category、添加一些安全措施得方法。

、、、

- (id)cdf_safeObjectAtIndex:(NSUInteger)index

{

    if (index < self.count) {

        return [self objectAtIndex:index];

    }

    return nil;

}

- (id)cdf_safeSubarrayWithRange:(NSRange)range

{

    if (range.location + range.length <= self.count) {

        return [self subarrayWithRange:range];

    }

    return nil;

}

、、、

2、hook 数组调用的系统方法。

hook系统的方法原理是SEL 对应的IMP 更换了。

相关文章

网友评论

      本文标题:1、使用Category和Hook 给集合做保护

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