From ccb4e34c0af3a2d318ce9c11ba1e98e1e1163b77 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 25 Nov 2015 17:50:39 -0800 Subject: [PATCH 1/1] Port to Linux: g++ 4.8 and JavaScriptCoreGTK+ 4.0. --- Console.cpp | 8 +++++--- Inject.cpp | 2 +- JavaScript.hpp | 18 +++++++++++------- ObjectiveC/Library.mm | 2 ++ configure | 6 +++--- configure.ac | 2 +- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Console.cpp b/Console.cpp index 6239c35..3089edc 100644 --- a/Console.cpp +++ b/Console.cpp @@ -612,7 +612,7 @@ static void Console(CYOptions &options) { } } -void InjectLibrary(pid_t, int, const char *[]); +void InjectLibrary(pid_t, int, const char *const []); int Main(int argc, char * const argv[], char const * const envp[]) { bool tty(isatty(STDIN_FILENO)); @@ -719,7 +719,8 @@ int Main(int argc, char * const argv[], char const * const envp[]) { // XXX: arg needs to be escaped in some horrendous way of doom // XXX: this is a memory leak now because I just don't care enough char *command; - asprintf(&command, "ps axc|sed -e '/^ *[0-9]/{s/^ *\\([0-9]*\\)\\( *[^ ]*\\)\\{3\\} *-*\\([^ ]*\\)/\\3 \\1/;/^%s /{s/^[^ ]* //;q;};};d'", optarg); + int writ(asprintf(&command, "ps axc|sed -e '/^ *[0-9]/{s/^ *\\([0-9]*\\)\\( *[^ ]*\\)\\{3\\} *-*\\([^ ]*\\)/\\3 \\1/;/^%s /{s/^[^ ]* //;q;};};d'", optarg)); + _assert(writ != -1); if (FILE *pids = popen(command, "r")) { char value[32]; @@ -867,7 +868,8 @@ int Main(int argc, char * const argv[], char const * const envp[]) { _syscall(chmod(address.sun_path, 0777)); _syscall(listen(server, 1)); - InjectLibrary(pid, 1, (const char *[]) {address.sun_path, NULL}); + const char *const argv[] = {address.sun_path, NULL}; + InjectLibrary(pid, 1, argv); client_ = _syscall(accept(server, NULL, NULL)); } #else diff --git a/Inject.cpp b/Inject.cpp index eb85351..b5136f6 100644 --- a/Inject.cpp +++ b/Inject.cpp @@ -55,7 +55,7 @@ Type_ *shift(Type_ *data, size_t size) { return reinterpret_cast(reinterpret_cast(data) + size); } -void InjectLibrary(int pid, int argc, const char *argv[]) { +void InjectLibrary(int pid, int argc, const char *const argv[]) { auto cynject(LibraryFor(reinterpret_cast(&main))); auto slash(cynject.rfind('/')); _assert(slash != std::string::npos); diff --git a/JavaScript.hpp b/JavaScript.hpp index bd1bd67..9a58ccf 100644 --- a/JavaScript.hpp +++ b/JavaScript.hpp @@ -210,17 +210,21 @@ class CYJSString { }; #ifdef __APPLE__ +#define _weak __attribute__((__weak_import__)); +#else +#define _weak +#endif + typedef struct OpaqueJSWeakObjectMap *JSWeakObjectMapRef; typedef void (*JSWeakMapDestroyedCallback)(JSWeakObjectMapRef map, void *data); -extern "C" JSWeakObjectMapRef JSWeakObjectMapCreate(JSContextRef ctx, void *data, JSWeakMapDestroyedCallback destructor) __attribute__((__weak_import__)); -extern "C" void JSWeakObjectMapSet(JSContextRef ctx, JSWeakObjectMapRef map, void *key, JSObjectRef) __attribute__((__weak_import__)); -extern "C" JSObjectRef JSWeakObjectMapGet(JSContextRef ctx, JSWeakObjectMapRef map, void *key) __attribute__((__weak_import__)); -extern "C" bool JSWeakObjectMapClear(JSContextRef ctx, JSWeakObjectMapRef map, void *key, JSObjectRef object) __attribute__((__weak_import__)); -extern "C" void JSWeakObjectMapRemove(JSContextRef ctx, JSWeakObjectMapRef map, void* key) __attribute__((__weak_import__)); +extern "C" JSWeakObjectMapRef JSWeakObjectMapCreate(JSContextRef ctx, void *data, JSWeakMapDestroyedCallback destructor) _weak; +extern "C" void JSWeakObjectMapSet(JSContextRef ctx, JSWeakObjectMapRef map, void *key, JSObjectRef) _weak; +extern "C" JSObjectRef JSWeakObjectMapGet(JSContextRef ctx, JSWeakObjectMapRef map, void *key) _weak; +extern "C" bool JSWeakObjectMapClear(JSContextRef ctx, JSWeakObjectMapRef map, void *key, JSObjectRef object) _weak; +extern "C" void JSWeakObjectMapRemove(JSContextRef ctx, JSWeakObjectMapRef map, void* key) _weak; typedef bool (*JSShouldTerminateCallback)(JSContextRef ctx, void *context); -extern "C" void JSContextGroupSetExecutionTimeLimit(JSContextGroupRef, double limit, JSShouldTerminateCallback, void *context) __attribute__((__weak_import__)); -#endif +extern "C" void JSContextGroupSetExecutionTimeLimit(JSContextGroupRef, double limit, JSShouldTerminateCallback, void *context) _weak; #endif/*CYCRIPT_JAVASCRIPT_HPP*/ diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index dccc3ad..c302305 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -1086,6 +1086,7 @@ NSObject *CYCopyNSObject(CYPool &pool, JSContextRef context, JSValueRef value) { @end /* }}} */ /* Bridge: NSOrderedSet {{{ */ +#ifdef __APPLE__ @implementation NSOrderedSet (Cycript) - (NSString *) cy$toCYON:(bool)objective inSet:(std::set &)objects { @@ -1099,6 +1100,7 @@ NSObject *CYCopyNSObject(CYPool &pool, JSContextRef context, JSValueRef value) { } @end +#endif /* }}} */ /* Bridge: NSProxy {{{ */ @implementation NSProxy (Cycript) diff --git a/configure b/configure index c5f9a0f..8be0f21 100755 --- a/configure +++ b/configure @@ -20178,7 +20178,7 @@ $as_echo "$ac_cv_framework_JavaScriptCore" >&6; } else - for cy_webkit_pkg in "webkit-1.0" "WebKitGtk"; do + for cy_webkit_pkg in "javascriptcoregtk-4.0"; do pkg_failed=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for WEBKIT" >&5 @@ -20447,7 +20447,7 @@ $as_echo "$ac_cv_framework_JavaScriptCore" >&6; } else - for cy_webkit_pkg in "webkit-1.0" "WebKitGtk"; do + for cy_webkit_pkg in "javascriptcoregtk-4.0"; do pkg_failed=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for WEBKIT" >&5 @@ -20716,7 +20716,7 @@ $as_echo "$ac_cv_framework_JavaScriptCore" >&6; } else - for cy_webkit_pkg in "webkit-1.0" "WebKitGtk"; do + for cy_webkit_pkg in "javascriptcoregtk-4.0"; do pkg_failed=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for WEBKIT" >&5 diff --git a/configure.ac b/configure.ac index aa81400..a8ef86b 100644 --- a/configure.ac +++ b/configure.ac @@ -150,7 +150,7 @@ AC_DEFUN([CY_CHECK_JAVASCRIPTCORE], [ ], [ AC_SUBST([CY_EXECUTE], [1]) ], [ - for cy_webkit_pkg in "webkit-1.0" "WebKitGtk"; do + for cy_webkit_pkg in "javascriptcoregtk-4.0"; do PKG_CHECK_MODULES([WEBKIT], [$cy_webkit_pkg], [ AC_SUBST([CY_EXECUTE], [1]) AC_LIB_APPENDTOVAR([CPPFLAGS], [`$PKG_CONFIG --cflags $cy_webkit_pkg`]) -- 2.45.2