/* 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/>.
**/
/* }}} */
bytes[i] = 0;
}
+__attribute__((__unused__))
+static void $memcpy(char *dst, const char *src, size_t size) {
+ for (size_t i(0); i != size; ++i)
+ dst[i] = src[i];
+}
+
static int $strcmp(const char *lhs, const char *rhs) {
while (*lhs == *rhs) {
if (*lhs == '\0')
} dst[i] = '\0';
}
+__attribute__((__unused__))
+static char *$strstr(const char *haystack, const char *needle) {
+ if (*needle == '\0')
+ return NULL;
+ for (; *haystack != '\0'; ++haystack)
+ for (size_t i(0); ; ++i)
+ if (needle[i] == '\0')
+ return const_cast<char *>(haystack);
+ else if (needle[i] != haystack[i])
+ break;
+ return NULL;
+}
+
+__attribute__((__unused__))
+static size_t $strlen(const char *data) {
+ for (size_t i(0); ; ++i)
+ if (data[i] == '\0')
+ return i;
+}
+
__attribute__((__unused__))
static void $snprintfp(char *dst, size_t size, const void *pointer) {
uintptr_t value(reinterpret_cast<uintptr_t>(pointer));
return Library(infos, name);
}
+#if defined(__i386__) || defined(__x86_64__)
+static bool Simulator(struct dyld_all_image_infos *infos) {
+ for (uint32_t i(0); i != infos->infoArrayCount; ++i) {
+ const dyld_image_info &info(infos->infoArray[i]);
+ const char *path(info.imageFilePath);
+ if ($strstr(path, "/SDKs/iPhoneSimulator") != NULL)
+ return true;
+ } return false;
+}
+
+static bool Simulator(Baton *baton) {
+ struct dyld_all_image_infos *infos(reinterpret_cast<struct dyld_all_image_infos *>(baton->dyld));
+ return Simulator(infos);
+}
+#endif
+
void *Routine(void *arg) {
Baton *baton(reinterpret_cast<Baton *>(arg));
void *(*$dlopen)(const char *, int);
cyset($dlopen, "_dlopen", dyld);
+#if defined(__i386__) || defined(__x86_64__)
+ size_t length($strlen(baton->library));
+ if (length >= 10 && $strcmp(baton->library + length - 10, "-###.dylib") == 0)
+ $memcpy(baton->library + length - 10, Simulator(baton) ? "-sim" : "-sys", 4);
+#endif
+
void *handle($dlopen(baton->library, RTLD_LAZY | RTLD_LOCAL));
if (handle == NULL) {
$strlcpy(baton->error, $dlerror(), sizeof(baton->error));
void *(*$dlsym)(void *, const char *);
cyset($dlsym, "_dlsym", dyld);
- void (*CYHandleServer)(pid_t, char *, size_t);
- CYHandleServer = reinterpret_cast<void (*)(pid_t, char *, size_t)>($dlsym(handle, "CYHandleServer"));
+ void (*CYHandleServer)(pid_t);
+ CYHandleServer = reinterpret_cast<void (*)(pid_t)>($dlsym(handle, "CYHandleServer"));
if (CYHandleServer == NULL) {
$strlcpy(baton->error, $dlerror(), sizeof(baton->error));
return NULL;
}
- CYHandleServer(baton->pid, baton->error, sizeof(baton->error));
+ CYHandleServer(baton->pid);
return NULL;
}