如何在不检查SignerIdentity的情况下检测应用程序是否已被破解?

时间:2012-10-08 01:23:53

标签: ios iphone ipad app-store

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

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

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

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

4 个答案:

答案 0 :(得分:10)

我个人喜欢Mick的回答,因为它很简单。

Greg的回复无效--Mick的代码只会检查应用是否可以打开该网址,因此不应该崩溃。

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

从分析来看,这种方法已经阻止了成千上万的盗版用户,并且花了大约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;
}

答案 1 :(得分: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

答案 2 :(得分:1)

我建议使用一个较小的代码片段,其功能与@ user1353482建议的相同(以相同的方式)。我会写评论,但代码将无法读取。此外,我可能是错的,但似乎即使在编译模拟器时也不再需要其他定义(至少这在xcode 4.5.1中工作,目标是5.0)。

请注意,此代码在debug和adhoc二进制文件中返回false,但我们正在谈论appstore,对吧?是Apple进行最终加密而你不应该在家里试试这个:)

#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;
}

答案 3 :(得分:-4)

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

+(BOOL)isJailbroken { 
    NSURL* url = [NSURL URLWithString:@"cydia://package/com.example.package"]; 
    return [[UIApplication sharedApplication] canOpenURL:url]; 
}