]> git.saurik.com Git - cycript.git/blobdiff - Mach/Inject.cpp
Find all remote symbols via dyld_all_image_infos.
[cycript.git] / Mach / Inject.cpp
index 6e5f69ddd5920ec121f5b0ff78eda724f89400cb..a6dcf9f912e885441a18607bf498fca0e8e25092 100644 (file)
@@ -33,8 +33,6 @@
 #include "Pooling.hpp"
 #include "Trampoline.t.hpp"
 
-extern "C" void __pthread_set_self(pthread_t);
-
 void InjectLibrary(pid_t pid) {
     const char *library(CY_LIBRARY);
 
@@ -46,35 +44,32 @@ void InjectLibrary(pid_t pid) {
     uint8_t *local(pool.malloc<uint8_t>(depth));
     Baton *baton(reinterpret_cast<Baton *>(local));
 
-    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;
-
     baton->pid = getpid();
     memcpy(baton->library, library, length);
 
-    vm_size_t size(depth + Stack_);
-
     mach_port_t self(mach_task_self()), task;
     _krncall(task_for_pid(self, pid, &task));
 
+    mach_msg_type_number_t count;
+
+    task_dyld_info info;
+    count = TASK_DYLD_INFO_COUNT;
+    _krncall(task_info(task, TASK_DYLD_INFO, reinterpret_cast<task_info_t>(&info), &count));
+    _assert(count == TASK_DYLD_INFO_COUNT);
+    _assert(info.all_image_info_addr != 0);
+    baton->dyld = info.all_image_info_addr;
+
+    vm_size_t size(depth + Stack_);
     vm_address_t stack;
     _krncall(vm_allocate(task, &stack, size, true));
-    vm_address_t data(stack + Stack_);
 
+    vm_address_t data(stack + Stack_);
     _krncall(vm_write(task, data, reinterpret_cast<vm_address_t>(baton), depth));
 
     thread_act_t thread;
     _krncall(thread_create(task, &thread));
 
     thread_state_flavor_t flavor;
-    mach_msg_type_number_t count;
-
 #if defined (__i386__) || defined(__x86_64__)
     x86_thread_state_t state;
     flavor = x86_THREAD_STATE;
@@ -141,8 +136,8 @@ void InjectLibrary(pid_t pid) {
     }
 #elif defined(__arm__)
     state.__r[0] = data;
-    state.__sp = stack + Stack_;
     state.__pc = code + trampoline->entry_;
+    state.__sp = stack + Stack_ - sizeof(frame);
 
     if ((state.__pc & 0x1) != 0) {
         state.__pc &= ~0x1;