]> git.saurik.com Git - cydget.git/commitdiff
Port Cydget to 4.2.
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 24 Nov 2010 22:15:48 +0000 (22:15 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 24 Nov 2010 22:15:48 +0000 (22:15 +0000)
LockScreen.mm
control

index 868e2a21c9f0e07bf2d34dc2844ca22b615b84a5..ef4688a0bc922002377e1d024849b9c18a52c718 100644 (file)
@@ -935,12 +935,54 @@ struct State {
     unsigned state;
 };
 
+// String Helpers {{{
+static const UChar *(*_ZNK7WebCore6String10charactersEv)(const WebCore::String *);
+static const UChar *(*_ZN7WebCore6String29charactersWithNullTerminationEv)(const WebCore::String *);
+static unsigned (*_ZNK7WebCore6String6lengthEv)(const WebCore::String *);
+
+static bool StringGet(const WebCore::String &string, const UChar *&data, size_t &length) {
+    bool terminated;
+
+    if (_ZNK7WebCore6String10charactersEv != NULL) {
+        data = (*_ZNK7WebCore6String10charactersEv)(&string);
+        terminated = false;
+    } else if (_ZN7WebCore6String29charactersWithNullTerminationEv != NULL) {
+        data = (*_ZN7WebCore6String29charactersWithNullTerminationEv)(&string);
+        terminated = true;
+    } else return false;
+
+    if (_ZNK7WebCore6String6lengthEv != NULL)
+        length = (*_ZNK7WebCore6String6lengthEv)(&string);
+    else if (terminated)
+        for (length = 0; data[length] != 0; ++length);
+    else return false;
+
+    return true;
+}
+
+static bool StringEquals(const WebCore::String &string, const char *value) {
+    const UChar *data;
+    size_t size;
+    if (!StringGet(string, data, size))
+        return false;
+
+    size_t length(strlen(value));
+    if (size != length)
+        return false;
+
+    for (size_t index(0); index != length; ++index)
+        if (data[index] != value[index])
+            return false;
+
+    return true;
+}
+// }}}
 // State Machine {{{
 static bool cycript_;
 
 MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) {
     _trace();
-    if (mime != "text/cycript") {
+    if (!StringEquals(mime, "text/cycript")) {
         cycript_ = false;
         return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime);
     }
@@ -956,20 +998,23 @@ MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6
 // }}}
 // Script Compiler {{{
 static void Log(const WebCore::String &string) {
-    size_t length(string.length());
-    UChar data[length + 1];
-    data[length] = 0;
-    memcpy(data, string.characters(), length * 2);
-    NSLog(@"wtf %p:%S:", &string, data);
+    const UChar *data;
+    size_t length;
+    if (!StringGet(string, data, length))
+        return;
+
+    UChar terminated[length + 1];
+    terminated[length] = 0;
+    memcpy(terminated, data, length * 2);
+    NSLog(@"wtf %p:%zu:%S:", &string, length, terminated);
 }
 
 static void Cycriptify(apr_pool_t *pool, const uint16_t *&data, size_t &size) {
     cycript_ = false;
 
-    _trace();
     if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
-        if (void (*CYParseUChar)(apr_pool_t *, const uint16_t **, size_t *) = reinterpret_cast<void (*)(apr_pool_t *, const uint16_t **, size_t *)>(dlsym(handle, "CydgetPoolParse")))
-            CYParseUChar(pool, &data, &size);
+        if (void (*CydgetPoolParse)(apr_pool_t *, const uint16_t **, size_t *) = reinterpret_cast<void (*)(apr_pool_t *, const uint16_t **, size_t *)>(dlsym(handle, "CydgetPoolParse")))
+            CydgetPoolParse(pool, &data, &size);
 }
 
 static void (*_ZN7WebCore6String6appendEPKtj)(WebCore::String *, const UChar *, unsigned);
@@ -979,8 +1024,15 @@ static void Cycriptify(const WebCore::String &source, int *psize = NULL) {
     if (!cycript_)
         return;
 
-    const uint16_t *data(source.characters());
-    size_t length(source.length()), size(length);
+    const UChar *data;
+    size_t length;
+
+    if (!StringGet(source, data, length)) {
+        _trace();
+        return;
+    }
+
+    size_t size(length);
 
     apr_pool_t *pool;
     apr_pool_create(&pool, NULL);
@@ -1328,6 +1380,14 @@ static void dlset(Type_ &function, const char *name) {
     function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
 }
 
+template <typename Type_>
+static void msset_(Type_ &function, const char *name, MSImageRef handle) {
+    function = reinterpret_cast<Type_>(MSFindSymbol(handle, name));
+}
+
+#define msset(function, handle) \
+    msset_(function, "_" #function, handle)
+
 @implementation WebCycriptLockScreenController
 
 + (void) initialize {
@@ -1412,6 +1472,19 @@ static void dlset(Type_ &function, const char *name) {
 
     nlset(_ZN7WebCore6String6appendEPKtj, nl, 6);
     nlset(_ZN7WebCore6String8truncateEj, nl, 7);
+
+    MSImageRef JavaScriptCore(MSGetImageByName("/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore"));
+    //MSImageRef WebCore(MSGetImageByName("/System/Library/PrivateFrameworks/WebCore.framework/WebCore"));
+
+    if (_ZN7WebCore6String6appendEPKtj == NULL)
+        msset(_ZN7WebCore6String6appendEPKtj, JavaScriptCore);
+
+    if (_ZN7WebCore6String8truncateEj == NULL)
+        msset(_ZN7WebCore6String8truncateEj, JavaScriptCore);
+
+    msset(_ZNK7WebCore6String10charactersEv, JavaScriptCore);
+    msset(_ZN7WebCore6String29charactersWithNullTerminationEv, JavaScriptCore);
+    msset(_ZNK7WebCore6String6lengthEv, JavaScriptCore);
 }
 
 + (id) rootViewController {
diff --git a/control b/control
index 40de1b0586c08b515e0aae31b96aac8656e83791..e91f4b039cfe3dd2ee88a033d713a465f40a4239 100644 (file)
--- a/control
+++ b/control
@@ -3,10 +3,10 @@ Priority: optional
 Section: Development
 Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
 Architecture: iphoneos-arm
-Version: 0.9.3359-1
+Version: 0.9.3365-1
 Description: framework for managing lock screen plugins
 Name: Cydget
-Depends: mobilesubstrate (>= 0.9.2587-1), firmware (>= 2.2), firmware (<< 5.0), preferenceloader, apr-lib, pcre, cycript (>= 0.9.292-1)
+Depends: mobilesubstrate (>= 0.9.3366-1), firmware (>= 2.2), firmware (<< 5.0), preferenceloader, apr-lib, pcre, cycript (>= 0.9.292-1)
 Replaces: cydialer (<< 0.9.17)
 Conflicts: gsc.wildcat
 Author: Jay Freeman (saurik) <saurik@saurik.com>