]> git.saurik.com Git - cycript.git/blobdiff - Mach/Inject.cpp
Support having multiple language hooks registered.
[cycript.git] / Mach / Inject.cpp
index 982ffe405964be894db3f19bffb327ce56fbbdef..d109cddb243cd6fadba749791841f736066a18d7 100644 (file)
@@ -1,26 +1,26 @@
 /* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2013  Jay Freeman (saurik)
+ * Copyright (C) 2009-2014  Jay Freeman (saurik)
 */
 
-/* GNU General Public License, Version 3 {{{ */
+/* GNU Affero General Public License, Version 3 {{{ */
 /*
- * Cycript is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation, either version 3 of the License,
- * or (at your option) any later version.
- *
- * Cycript is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Cycript.  If not, see <http://www.gnu.org/licenses/>.
+ * GNU Affero General Public License for more details.
+
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/
 /* }}} */
 
 #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
@@ -57,8 +57,8 @@ void InjectLibrary(pid_t pid) {
     memcpy(library, addr.dli_fname, flength);
     library[flength] = '\0';
     _assert(strcmp(library + flength - 6, ".dylib") == 0);
-#ifndef TARGET_OS_IPHONE
-    strcpy(library + flength - 6, "-any.dylib");
+#if !TARGET_OS_IPHONE
+    strcpy(library + flength - 6, "-###.dylib");
 #endif
 
     mach_port_t self(mach_task_self()), task;
@@ -207,6 +207,7 @@ void InjectLibrary(pid_t pid) {
 
     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_);
@@ -291,8 +292,11 @@ void InjectLibrary(pid_t pid) {
     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')
+
+    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));