9

曾经有一种方法可以检查应用程序是否是从 App Store 购买的,以防止破解:

NSBundle *bundle = [NSBundle mainBundle]; 
NSDictionary *info = [bundle infoDictionary]; 
if ([info objectForKey: @"SignerIdentity"] != nil) 
{ /* do something */  }

但是这种方法不再有效,因为破解者已经找到了改变 Info.plist 的方法。我知道这个较旧的问题,但那里提供的答案依赖于上述技术,该技术不再有效。

在不读取 Info.plist 中的 SignerIdentity 的情况下,如何检测您的应用程序是否被破解或从 App Store 合法购买?

4

4 回答 4

12

我个人喜欢米克的回答,因为它简短而简单。

Greg 的响应无效——Mick 的代码只检查应用程序是否可以打开该 URL,因此应该没有崩溃的机会。

我已经在我的一个应用程序中实现了以下功能,之前对应用程序是否加密进行了更严格的检查,如果不是,它很可能是破解的应用程序:

从分析来看,这种方法为我阻止了成千上万的盗版用户,并且可能需要 5 分钟来实施,所以这样做的成本几乎为零——对我来说,我不在乎它是否会增加销售额(我确信它是无论如何都不会——更重要的是,我不希望人们从我的辛勤工作中白白浪费)。此外,在确定应用程序是否为盗版后,我的应用程序的大量内容会提供信息,如果是,则返回垃圾数据。

在 main.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

static BOOL isEncrypted();

static BOOL isEncrypted () {
    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) {
                /* Disabled, probably pirated */
                return NO;
            }

            /* Probably not pirated <-- can't say for certain, maybe theres a way around it */
            return YES;
        }

        cmd = (struct load_command *) ((uint8_t *) cmd + cmd->cmdsize);
    }

    /* Encryption info not found */
    return NO;
}
于 2012-10-19T14:10:44.040 回答
3

苹果官方的回答:

Hello Dmitry,

Thank you for contacting Apple Developer Technical Support (DTS). 

DTS does not provide code-level support for DRM issues.  

Please try posting your inquiry to Apple Development Forum:

<https://devforums.apple.com>

While you were initially charged a Technical Support Incident (TSI) for this request, we have assigned a replacement TSI back to your account.

Thank you for understanding our support policies.

Best Regards,

Apple Developer Support 
Worldwide Developer Relations
于 2012-10-27T20:32:20.203 回答
1

我会建议一个更小的代码片段,它与@user1353482 建议的功能相同(并且方式相同)。我会写评论,但那时代码将不可读。此外,我可能是错的,但似乎即使在为模拟器编译时也不再需要额外的定义(至少这在 xcode 4.5.1 中有效,目标是 5.0)。

请注意,此代码在 debug 和 adhoc 二进制文件中返回 false,但我们谈论的是 appstore,对吗?最终加密的是苹果公司,你不应该在家里尝试这个:)

#include <execinfo.h>
#import <mach-o/ldsyms.h>

bool executableEncryption()
{
    const uint8_t *command = (const uint8_t *) (&_mh_execute_header + 1);
    for (uint32_t idx = 0; idx < _mh_execute_header.ncmds; ++idx)
    {
        if (((const struct load_command *) command)->cmd == LC_ENCRYPTION_INFO)
        {
            struct encryption_info_command *crypt_cmd = (struct encryption_info_command *) command;    
            if (crypt_cmd->cryptid < 1)
                return false;
            return true;
        }
        else
        {
            command += ((const struct load_command *) command)->cmdsize;
        }
    }
    return false;
}
于 2012-10-24T21:18:58.787 回答
-4

虽然不是检查应用程序是否是从 App Store 购买的,但我使用此代码检查我的应用程序是否在越狱设备上运行:

+(BOOL)isJailbroken { 
    NSURL* url = [NSURL URLWithString:@"cydia://package/com.example.package"]; 
    return [[UIApplication sharedApplication] canOpenURL:url]; 
} 
于 2012-10-12T08:32:36.437 回答