Ongoing encryption check anti-piracy measures

I read a very interesting blog about introducing anti-virus protection into your applications. Some of them no longer work, some of them. 2, which are still effective to the extent, are the last two listed. http://shmoopi.wordpress.com/2011/06/19/27/

The one I'm interested in is the very last. The code is below. I implemented this in my AppDelegate.m

Anti-piracy through encryption verification.

Mandatory Headers

#import <dlfcn.h>
#import <mach-o/dyld.h>
#import <TargetConditionals.h>

Encryption

#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

Necessary Methods

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 if the binary is all encrypted.

When I run this on a device attached to the 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. , .

, -

+5
4

64- , iPhone 5s. mach_header mach_header_64, LC_ENCRYPTION_INFO_64.

, , , , . MH_MAGIC_64, 64- , mach_header_64 LC_ENCRYPTION_INFO_64 ( 0x2C) LC_ENCRYPTION_INFO.

+4

otool , :

otool -arch armv7 -l YourAppName | grep crypt
+3

. , "" "" , Apple FairPlay DRM. , , NO.

iPhone-, , otool.

, , build/Debug-iphoneos/MyApp.app ( )

otool -l MyApp |

LC_ENCRYPTION_INFO. , 0. , ~/Music/iTunes/Mobile Applications .ipa. otool .ipa, 1 .

+1

, dyload. , . , (), , .

You might want to make all this control conditional in a project running on an iOS device, and not in a simulator. Any binaries sent to the iOS device must be signed.

#if !(TARGET_IPHONE_SIMULATOR)
your check
#endif // 
0
source

All Articles