欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[转]防止你的iPhone程序遭盗版(入门篇)

程序员文章站 2022-06-01 21:01:56
...
原文: http://b.imi.im/?p=356

先澄清一下, 我也是盗版用户(先自己抽两嘴巴, 但是我已经花了$200买app, 买觉得值得的程序, 而不是apple推崇的冲动式购买, 装盗版是先预览一下这个程序是不是值得买). 在中国做软件, 想不被盗版, 不太现实.
不想自己辛辛苦苦写出来的程序被盗版? 接着看.

首先简单介绍一下原理:

现在大多数的**苹果验证安装app的办法都会动一个文件, 就是在.app文件夹下的”Info.plist”, 也就是那个程序信息文件.

代码很简单, 不再详细解释什么意思了

1. 检查Info.plist 是否存在 SignerIdentity这个键名(Key).
未**的程序是不会有这个键名的, 苹果没给你加, 你自己没有加, 如果有, 那是哪儿来的呢?? 嘻嘻….

if ([[[NSBundle mainBundle] infoDictionary] objectForKey: @”SignerIdentity”] != nil) {

// 这就是被**过的app

}


2. 检查3个文件是否存在

NSString* bundlePath = [[NSBundle mainBundle] bundlePath];

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:(@”%@/_CodeSignature”, bundlePath)];

if (!fileExists) {

// 这就是被**过的app

}

BOOL fileExists2 = [[NSFileManager defaultManager] fileExistsAtPath:(@”%@/CodeResources”, bundlePath)];

if (!fileExists2) {

/// 这就是被**过的app

}

BOOL fileExists3 = [[NSFileManager defaultManager] fileExistsAtPath:(@”%@/ResourceRules.plist”, bundlePath)];

if (!fileExists3) {

// 这就是被**过的app

}

3. 对比文件修改时间是否一致, 看看你的程序是不是被二进制编辑器修改过了

NSString* bundlePath = [[NSBundle mainBundle] bundlePath];

NSString* path = [NSString stringWithFormat:@"%@/Info.plist", bundlePath];

NSString* path2 = [NSString stringWithFormat:@"%@/程序名字", bundlePath];

NSDate* infoModifiedDate = [[[NSFileManager defaultManager] fileAttributesAtPath:path traverseLink:YES] fileModificationDate];

NSDate* infoModifiedDate2 = [[[NSFileManager defaultManager] fileAttributesAtPath:path2 traverseLink:YES] fileModificationDate];

NSDate* pkgInfoModifiedDate = [[[NSFileManager defaultManager] fileAttributesAtPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@”PkgInfo”] traverseLink:YES] fileModificationDate];

if([infoModifiedDate timeIntervalSinceReferenceDate] > [pkgInfoModifiedDate timeIntervalSinceReferenceDate]) {

//Pirated

}

if([infoModifiedDate2 timeIntervalSinceReferenceDate] > [pkgInfoModifiedDate timeIntervalSinceReferenceDate]) {

//Pirated

}


如果以上3条都没挡住丫挺的步伐, 请等我出高级篇吧 :) 恭喜发财!
相关标签: Apple