第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

iOS 代碼混淆的新進(jìn)展

標(biāo)簽:
iOS

最近研究了基于LLVM的混淆工具 Hikari 中文文档 ,从编译器层面完成了代码的安全加固,可以说是非常牛了。但作者并没有实现Objective-C的方法名/类名混淆,于是想到了老办法。这个办法最大的难点在于如何提取混淆的关键字,之前都是尝试用脚本去提取关键字,方法名加前缀等等,github有不少工具、Demo,大多都不太好使。后来经大神提点,可以用Objective-C强大的运行时来处理关键字的提取。

周末抽空写了个小工具 XDSecurityDefense,实现了

  1. 过滤掉苹果SDK的类名、方法名

  2. 过滤掉setter、getter方法

  3. 过滤掉协议方法

  4. 过滤掉继承自父类的方法

/**
 获取所有开发者创建的类的名称

 @return 类的名称集合
 */- (NSSet *)customClassNames {    NSMutableSet *customClassName = [NSMutableSet set];    unsigned int classNamesCount = 0;    // 用 executablePath 获取当前 app image
    NSString *appImage = [NSBundle mainBundle].executablePath;    // objc_copyClassNamesForImage 获取到的是 image 下的类,直接排除了系统的类
    const char **classNames = objc_copyClassNamesForImage([appImage UTF8String], &classNamesCount);    if (classNames) {        for (unsigned int i = 0; i < classNamesCount; i++) {            const char *className = classNames[i];            NSString *classNameString = [NSString stringWithUTF8String:className];
            [customClassName addObject:classNameString];
        }
        free(classNames);
    }    return customClassName;
}
/**
 检查方法是否继承自父类

 @param class 类
 @param sel 方法名
 @return 是否继承自父类
 */- (BOOL)superClass:(Class)class respondsToSelector:(SEL)sel
{
    Class supClass = class_getSuperclass(class);    BOOL bTespondsToSelector= NO;    while (supClass != nil) {        if (class_respondsToSelector(supClass,sel)) {
            bTespondsToSelector = YES;
            supClass = nil;
        } else {
            supClass = class_getSuperclass(supClass);
        }
    }    return bTespondsToSelector;
}
/**
 获取类遵循所有协议的协议方法名

 @param classNameString 类的集合
 @return 方法名集合
 */- (NSSet *)protocalMethodListWithClass:(NSString *)classNameString {    NSMutableSet *protocalMethodList = [NSMutableSet set];
    Class className = NSClassFromString(classNameString);    unsigned int methodCount = 0;
    __unsafe_unretained Protocol **protocolList = class_copyProtocolList(className, &methodCount);    for (int i = 0; i < methodCount; i++) {
        Protocol *protocal = protocolList[i];//        const char *pName = protocol_getName(protocal);//        NSLog(@"protocol[%d] ---- %@", i, [NSString stringWithUTF8String:pName]);
        
        unsigned int protocolMethodCount = 0;        struct objc_method_description * methodList = protocol_copyMethodDescriptionList(protocal, NO, YES, &protocolMethodCount);        for (int i = 0; i < protocolMethodCount; i++) {            struct objc_method_description method = methodList[i];            NSString *protocolMethodName = NSStringFromSelector(method.name);
            [protocalMethodList addObject:protocolMethodName];
        }
        free(methodList);
        methodList = protocol_copyMethodDescriptionList(protocal, YES, YES, &protocolMethodCount);        for (int i = 0; i < protocolMethodCount; i++) {            struct objc_method_description method = methodList[i];            NSString *protocolMethodName = NSStringFromSelector(method.name);
            [protocalMethodList addObject:protocolMethodName];
        }
    }
    free(protocolList);    return protocalMethodList;
}

使用方法 不再赘述

踩的一些坑

1.如果有用到 NSClassFromString NSSelectorFromString等方法要检查是否会出错
2.有使用NSCodingarchivedDataWithRootObject等归档操作也要注意运行时是否出错



作者:施孝达
链接:https://www.jianshu.com/p/c0a81c904b4b

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消