【发布时间】:2014-03-10 12:49:07
【问题描述】:
我阅读了一篇非常有趣的博客,内容是在您的应用中实施一些反盗版保护。他们中的一些人不再工作,他们中的一些人。在一定程度上仍然有效的 2 个是最后列出的 2 个。 http://shmoopi.wordpress.com/2011/06/19/27/
我感兴趣的是最后一个。代码如下。我已经在我的 AppDelegate.m 中实现了这个
通过加密检查反盗版。
必需的标题
#import <dlfcn.h>
#import <mach-o/dyld.h>
#import <TargetConditionals.h>
加密结构
#if TARGET_IPHONE_SIMULATOR && !defined(LC_ENCRYPTION_INFO)
#define LC_ENCRYPTION_INFO 0x21
struct encryption_info_command
{
uint32_t cmd;
uint32_t cmdsize;
uint32_t cryptoff;
uint32_t cryptsize;
uint32_t cryptid;
};
#endif
需要的方法
int main (int argc, char *argv[]);
static BOOL is_encrypted ()
{
const struct mach_header *header;
Dl_info dlinfo;
/* Fetch the dlinfo for main() */
if (dladdr(main, &dlinfo) == 0 || dlinfo.dli_fbase == NULL)
{
NSLog(@"Could not find main() symbol (very odd)");
return NO;
}
header = dlinfo.dli_fbase;
/* Compute the image size and search for a UUID */
struct load_command *cmd = (struct load_command *) (header+1);
for (uint32_t i = 0; cmd != NULL && i < header->ncmds; i++)
{
/* Encryption info segment */
if (cmd->cmd == LC_ENCRYPTION_INFO)
{
struct encryption_info_command *crypt_cmd = (struct encryption_info_command *) cmd;
/* Check if binary encryption is enabled */
if (crypt_cmd->cryptid < 1)
{
return NO;
}
return YES;
}
cmd = (struct load_command *) ((uint8_t *) cmd + cmd->cmdsize);
}
return NO;
}
此方法检查二进制文件是否仍处于加密状态。
当我在附加到 x-code 的设备上运行它时,它会给我这一行的误报
if (crypt_cmd->cryptid < 1)
{
NSLog(@"Pirated from (crypt_cmd->cryptid < 1) ");
return NO;
}
我想知道是否有可能将 xcode 构建到设备上用于调试目的未加密?只有在构建提交给 Apple 以在 iTunes 上使用时才会对其进行加密。因此,为什么我在检查代码时会得到这个误报。
非常感谢, -代码
【问题讨论】:
标签: iphone objective-c ios