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;
if (dladdr(main, &dlinfo) == 0 || dlinfo.dli_fbase == NULL)
{
NSLog(@"Could not find main() symbol (very odd)");
return NO;
}
header = dlinfo.dli_fbase;
struct load_command *cmd = (struct load_command *) (header+1);
for (uint32_t i = 0; cmd != NULL && i < header->ncmds; i++)
{
if (cmd->cmd == LC_ENCRYPTION_INFO)
{
struct encryption_info_command *crypt_cmd = (struct encryption_info_command *) cmd;
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. , .
,
-
user440096