iOS 防止二次打包 笔记

检测embedded.mobileprovision是否被篡改:

// 校验值,可通过上一次打包获取
#define PROVISION_HASH @"Mfx1YZk7hZShm/IyV1QLWdogSQM="
static NSDictionary *rootDic=nil;

void checkSignatureMsg()
{
    NSString *newPath = [[NSBundle mainBundle] resourcePath];

    if (!rootDic) {
        rootDic = [[NSDictionary alloc] initWithContentsOfFile:[newPath stringByAppendingString:@"/_CodeSignature/CodeResources"]];
    }

    NSDictionary *fileDic = [rootDic objectForKey:@"files2"];
    NSDictionary *infoDic = [fileDic objectForKey:@"embedded.mobileprovision"];
    NSData *tempData = [infoDic objectForKey:@"hash"];
    NSString *hashStr = [tempData base64EncodedStringWithOptions:0];
    if (![PROVISION_HASH isEqualToString:hashStr]) {
        abort();//退出应用
    }
}
发布了201 篇原创文章 · 获赞 220 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/xjh093/article/details/97370370