]> git.saurik.com Git - cycript.git/blobdiff - Mach/Inject.cpp
Allow the use of void as a primitive data type.
[cycript.git] / Mach / Inject.cpp
index 92a395ec371f29f21b9c66c669327be97c70d6f8..8679e03a332c938e184dfff53b88532423de6ef3 100644 (file)
@@ -1,5 +1,5 @@
 /* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2010  Jay Freeman (saurik)
+ * Copyright (C) 2009-2012  Jay Freeman (saurik)
 */
 
 /* GNU Lesser General Public License, Version 3 {{{ */
@@ -22,7 +22,7 @@
 #include <dlfcn.h>
 #include <mach/mach.h>
 
-#include <mach/i386/thread_status.h>
+#include <mach/machine/thread_status.h>
 
 #include <cstdio>
 #include <pthread.h>
@@ -33,9 +33,7 @@
 #include "Pooling.hpp"
 #include "Trampoline.t.hpp"
 
-#include <substrate.h>
-
-extern "C" void _pthread_start(pthread_t, mach_port_t, void *(*)(void *), void *, size_t, unsigned int);
+extern "C" void __pthread_set_self(pthread_t);
 
 void InjectLibrary(pid_t pid) {
     const char *library(CY_LIBRARY);
@@ -48,7 +46,12 @@ void InjectLibrary(pid_t pid) {
     uint8_t *local(reinterpret_cast<uint8_t *>(apr_palloc(pool, depth)));
     Baton *baton(reinterpret_cast<Baton *>(local));
 
-    baton->_pthread_start = reinterpret_cast<void (*)(pthread_t, mach_port_t, void *(*)(void *), void *, size_t, unsigned int)>(MSFindSymbol(NULL, "__pthread_start"));
+    baton->__pthread_set_self = &__pthread_set_self;
+    baton->pthread_create = &pthread_create;
+
+    baton->mach_thread_self = &mach_thread_self;
+    baton->thread_terminate = &thread_terminate;
+
     baton->dlerror = &dlerror;
     baton->dlsym = &dlsym;
 
@@ -76,7 +79,7 @@ void InjectLibrary(pid_t pid) {
     Trampoline *trampoline;
 
 #if defined(__arm__)
-    trampoline = &Trampoline_arm_;
+    trampoline = &Trampoline_armv6_;
     arm_thread_state_t state;
     flavor = ARM_THREAD_STATE;
     count = ARM_THREAD_STATE_COUNT;
@@ -103,8 +106,7 @@ void InjectLibrary(pid_t pid) {
     _krncall(vm_protect(task, code, trampoline->size_, false, VM_PROT_READ | VM_PROT_EXECUTE));
 
     /*
-    printf("_pts:%p\n", baton->_pthread_start);
-    printf("dlerror:%p\n", baton->dlerror);
+    printf("_ptss:%p\n", baton->__pthread_set_self);
     printf("dlsym:%p\n", baton->dlsym);
     printf("code:%zx\n", (size_t) code);
     */
@@ -119,13 +121,13 @@ void InjectLibrary(pid_t pid) {
     _assert(count == count);
 
 #if defined(__arm__)
-    state.r[0] = data;
-    state.sp = stack + Stack_;
-    state.pc = code + trampoline->entry_;
+    state.__r[0] = data;
+    state.__sp = stack + Stack_;
+    state.__pc = code + trampoline->entry_;
 
-    if ((state.pc & 0x1) != 0) {
-        state.pc &= ~0x1;
-        state.cpsr |= 0x20;
+    if ((state.__pc & 0x1) != 0) {
+        state.__pc &= ~0x1;
+        state.__cpsr |= 0x20;
     }
 #elif defined(__i386__)
     frame[1] = data;