public
Description: Toolkit for iPhone OS applications that communicate with Web services
Homepage: http://www.zergling.net/
Clone URL: git://github.com/costan/zergsupport.git
Click here to lend your support to: zergsupport and make a donation at www.pledgie.com !
costan (author)
Sun Aug 09 10:06:19 -0700 2009
commit  814d0f2ed311e0346d0c36abc7198f239ae54a2d
tree    a5db23b356e29a0c59845bebd4e7aff3ab3b0abb
parent  2fa569245455fc16d002e1c4da7206274263792d
zergsupport / ZergSupport / CryptoSupport / ZNDebugIntegrity.m
100644 42 lines (33 sloc) 1.158 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// ZNDebugIntegrity.h
// ZergSupport
//
// Created by Victor Costan on 5/12/09.
// Copyright Zergling.Net. Licensed under the MIT license.
//
 
#import <dlfcn.h>
#import <sys/types.h>
 
#import <Foundation/Foundation.h>
#import <TargetConditionals.h>
 
 
// The iPhone SDK doesn't have <sys/ptrace.h>, but it does have ptrace, and it
// works just fine.
typedef int (*ptrace_ptr_t)(int _request, pid_t _pid, caddr_t _addr, int _data);
#if !defined(PT_DENY_ATTACH)
#define PT_DENY_ATTACH 31
#endif // !defined(PT_DENY_ATTACH)
 
 
void ZNDebugIntegrity() {
  // If all assertions are enabled, we're in a legitimate debug build.
#if TARGET_IPHONE_SIMULATOR || defined(DEBUG) || (!defined(NS_BLOCK_ASSERTIONS) && !defined(NDEBUG))
  return;
#endif
 
  // Lame obfuscation of the string "ptrace".
  char* ptrace_root = "socket";
  char ptrace_name[] = {0xfd, 0x05, 0x0f, 0xf6, 0xfe, 0xf1, 0x00};
  for (size_t i = 0; i < sizeof(ptrace_name); i++) {
    ptrace_name[i] += ptrace_root[i];
  }
 
  void* handle = dlopen(0, RTLD_GLOBAL | RTLD_NOW);
  ptrace_ptr_t ptrace_ptr = dlsym(handle, ptrace_name);
  ptrace_ptr(PT_DENY_ATTACH, 0, 0, 0);
  dlclose(handle);
}