extern "C" void Start(Baton *baton) { struct _pthread self; $bzero(&self, sizeof(self)); const mach_header_xx *pthread(Library(baton, "/usr/lib/system/libsystem_pthread.dylib")); if (pthread == NULL) pthread = Library(baton, "/usr/lib/system/libsystem_c.dylib"); void (*$__pthread_set_self)(pthread_t); cyset($__pthread_set_self, "___pthread_set_self", pthread); self.tsd[0] = &self; $__pthread_set_self(&self); int (*$pthread_create)(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *); cyset($pthread_create, "_pthread_create", pthread); pthread_t thread; $pthread_create(&thread, NULL, &Routine, baton); const mach_header_xx *kernel(Library(baton, "/usr/lib/system/libsystem_kernel.dylib")); mach_port_t (*$mach_thread_self)(); cyset($mach_thread_self, "_mach_thread_self", kernel); kern_return_t (*$thread_terminate)(thread_act_t); cyset($thread_terminate, "_thread_terminate", kernel); $thread_terminate($mach_thread_self()); }
void entry(ptrdiff_t codeOffset, void *param, size_t paramSize, void *pthreadData) { #if defined(__i386__) || defined(__x86_64__) extern void __pthread_set_self(char *); __pthread_set_self(pthreadData); #endif printf("Access granted\n"); thread_suspend(mach_thread_self()); }