iphone - 可执行加密检查防盗版措施

标签 iphone objective-c ios

我读了一篇非常有趣的博客,内容是关于在您的应用中实现一些反盗版保护。他们中的一些人不再工作,他们中的一些人。在某种程度上仍然有效的 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 5s 等 64 位设备上成功运行。 header 已从 mach_header 更改为 mach_header_64,命令 ID 现在为 LC_ENCRYPTION_INFO_64

我所做的是阅读标题,然后查看魔数(Magic Number)是什么。如果是 MH_MAGIC_64,那么您使用的是 64 位设备,您需要使用 mach_header_64 结构并查找 LC_ENCRYPTION_INFO_64(定义为 0x2C) 而不是 LC_ENCRYPTION_INFO

关于iphone - 可执行加密检查防盗版措施,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7038143/

相关文章:

objective-c - "Flatten compiled xib files"项目构建选项 "do"是什么

iphone - 从应用程序编辑 iPhone 音乐 ID3 标签

javascript - 如何在真实设备上捆绑和部署 React-Native iOS 应用程序

iphone - RaptureXML 有点慢

ios - iphone sdl vector 类型之间的转换无效 '__m64'

iphone - iPad的iAd何时可用?

iphone - 向网站发送请求(例如登录)?

iphone - 什么时候在模态视图 Controller 上设置父/呈现 View Controller ?

iphone - iOS:在自动布局下更改 UITableView 高度

ios - 计时器在 Viper 架构中的什么位置