8

I've been tryign to implement the following anti piracy code from this wiki: http://theiphonewiki.com/wiki/index.php?title=Bugging_Debuggers

But despite following it to the letter my app exits with a

Program exited with status value:45.

When i test it. If i comment out the function call disable_gdb(); the app runs as normal.

What is it that I'm doing wrong. Or is it that the code is doing as it should.. and exits while xcode is attached?

#import <UIKit/UIKit.h>
#import <dlfcn.h>
#import <sys/types.h>

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)

int main(int argc, char *argv[]) 
{
NSLog(@"Main Called ");
disable_gdb();
NSLog(@"After cracker code");
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}



void disable_gdb()
{
void* handle = dlopen(0, RTLD_GLOBAL | RTLD_NOW);
ptrace_ptr_t ptrace_ptr = dlsym(handle, "ptrace");
ptrace_ptr(PT_DENY_ATTACH, 0, 0, 0);
dlclose(handle);
}

int main3(int argc, char *argv[])
{
return -1;
}

Kindest Regards, -Code

1 Answers1

16

The code is functioning as intended. That said, I should tell you that you're wasting your time. This approach will only work if gdb and the attacker/programmer are cooperative. The whole point of tools like gdb is that they are extremely versatile and if a simple "bug" like this stopped them dead in their tracks, someone would fix it very quickly. :)

As described on this page, you can just do the following from within gdb:

(gdb) break ptrace
commands 1
    return
    continue
end
Aidan Steele
  • 10,999
  • 6
  • 38
  • 59
  • 9
    So, the answer is that there is no point in trying to prevent a debugger from debugging your application? – Chicowitz Nov 20 '14 at 04:21
  • I think there is valid point, you can't make yourself 100% secure, but you can make attacker's live harder so there is a chance he will go after easier target :) – Michal Gumny Feb 21 '19 at 15:10