]> git.saurik.com Git - cycript.git/blobdiff - Mach/Inject.cpp
Use OS X (not Simulator) build for x86_64 on OS X.
[cycript.git] / Mach / Inject.cpp
index 50ad0f8c368a5582ff60cc4fb4305f8d268d988a..7d805992c09c31a88515e0aa3b648b395f5cf0e6 100644 (file)
@@ -20,7 +20,7 @@
 /* }}} */
 
 #include "TargetConditionals.h"
 /* }}} */
 
 #include "TargetConditionals.h"
-#ifdef TARGET_OS_IPHONE
+#if TARGET_OS_IPHONE
 #undef __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
 #define __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ __IPHONE_5_0
 #endif
 #undef __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
 #define __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ __IPHONE_5_0
 #endif
@@ -57,7 +57,7 @@ void InjectLibrary(pid_t pid) {
     memcpy(library, addr.dli_fname, flength);
     library[flength] = '\0';
     _assert(strcmp(library + flength - 6, ".dylib") == 0);
     memcpy(library, addr.dli_fname, flength);
     library[flength] = '\0';
     _assert(strcmp(library + flength - 6, ".dylib") == 0);
-#ifndef TARGET_OS_IPHONE
+#if !TARGET_OS_IPHONE
     strcpy(library + flength - 6, "-any.dylib");
 #endif
 
     strcpy(library + flength - 6, "-any.dylib");
 #endif
 
@@ -207,6 +207,7 @@ void InjectLibrary(pid_t pid) {
 
     baton->dyld = info.all_image_info_addr;
     baton->pid = getpid();
 
     baton->dyld = info.all_image_info_addr;
     baton->pid = getpid();
+    memset(baton->error, 0, sizeof(baton->error));
     memcpy(baton->library, library, length);
 
     mach_vm_size_t size(depth + Stack_);
     memcpy(baton->library, library, length);
 
     mach_vm_size_t size(depth + Stack_);
@@ -288,6 +289,15 @@ void InjectLibrary(pid_t pid) {
 
     _krncall(mach_port_deallocate(self, thread));
 
 
     _krncall(mach_port_deallocate(self, thread));
 
+    mach_vm_size_t error(sizeof(baton->error));
+    _krncall(mach_vm_read_overwrite(task, data + offsetof(Baton, error), sizeof(baton->error), reinterpret_cast<mach_vm_address_t>(&baton->error), &error));
+    _assert(error == sizeof(baton->error));
+
+    if (baton->error[0] != '\0') {
+        baton->error[sizeof(baton->error) - 1] = '\0';
+        CYThrow("%s", baton->error);
+    }
+
     _krncall(mach_vm_deallocate(task, code, trampoline->size_));
     _krncall(mach_vm_deallocate(task, stack, size));
 
     _krncall(mach_vm_deallocate(task, code, trampoline->size_));
     _krncall(mach_vm_deallocate(task, stack, size));