可执行加密检查反盗版措施 [英] Executable encryption check anti piracy measure

查看:182
本文介绍了可执行加密检查反盗版措施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一篇非常有趣的博客,介绍如何在您的应用中实施一些反盗版保护。他们中的一些人不再工作,其中一些人不这样做。在一定程度上仍然有效的2个是最后列出的2个。
http://shmoopi.wordpress.com/2011/06/19/ 27 /

I read a very interesting blog about implementing some anti-piracy protection into your apps. Some of them dont work anymore, some of them do. The 2 ones that still are effective to an extent are the 2 last ones listed. http://shmoopi.wordpress.com/2011/06/19/27/

我感兴趣的是最后一个。代码如下。我已经在我的AppDelegate.m中实现了这个

The one I'm interested in is the very last one. Code below. I've implemented this in my 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;
}

此方法检查二进制文件是否仍然是加密的。

This method checks to see if the binary is still encrypted.

当我在附加到x-code的设备上运行它时,它会在这一行上给出误报

When I run this on the device attached to x-code it gives me a false positive on this line

if (crypt_cmd->cryptid < 1) 
{
    NSLog(@"Pirated from (crypt_cmd->cryptid < 1) ");
    return NO;
} 

我想知道是否有可能将构建的xcode放到设备上进行调试目的不加密?当构建提交给Apple在iTunes上使用时,它只会被加密。因此,为什么我在检查代码时会得到这种误报。

I was wondering is it possible that the builds xcode puts onto the device for debugging purposes not encrypted? And its only encrypted when the build is submitted to Apple for use on iTunes. Hence why I am getting this false positive when check the code.

非常感谢,
-Code

Many Thanks, -Code

推荐答案

此代码无法在iPhone 5s等64位设备上成功运行。标题已从 mach_header 更改为 mach_header_64 ,命令ID现在为 LC_ENCRYPTION_INFO_64

This code won't work successfully on a 64-bit device like the iPhone 5s. The header has been changed from mach_header to mach_header_64 and the command ID is now LC_ENCRYPTION_INFO_64.

我所做的是阅读标题然后看看幻数是多少。如果它是 MH_MAGIC_64 那么你在64位设备上,你需要使用 mach_header_64 结构并寻找 LC_ENCRYPTION_INFO_64 (定义为 0x2C )而不是 LC_ENCRYPTION_INFO

What I did was to read the header and then see what the magic number was. If it's MH_MAGIC_64 then you're on a 64-bit device and you need to use the mach_header_64 struct and look for LC_ENCRYPTION_INFO_64 (defined as 0x2C) instead of LC_ENCRYPTION_INFO.

这篇关于可执行加密检查反盗版措施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆