From e66f07bd052ced1d238634caf55ad16bc0f5fc52 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 24 Nov 2010 22:15:48 +0000 Subject: [PATCH] Port Cydget to 4.2. --- LockScreen.mm | 95 +++++++++++++++++++++++++++++++++++++++++++++------ control | 4 +-- 2 files changed, 86 insertions(+), 13 deletions(-) diff --git a/LockScreen.mm b/LockScreen.mm index 868e2a2..ef4688a 100644 --- a/LockScreen.mm +++ b/LockScreen.mm @@ -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(dlsym(handle, "CydgetPoolParse"))) - CYParseUChar(pool, &data, &size); + if (void (*CydgetPoolParse)(apr_pool_t *, const uint16_t **, size_t *) = reinterpret_cast(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(dlsym(RTLD_DEFAULT, name)); } +template +static void msset_(Type_ &function, const char *name, MSImageRef handle) { + function = reinterpret_cast(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 40de1b0..e91f4b0 100644 --- a/control +++ b/control @@ -3,10 +3,10 @@ Priority: optional Section: Development Maintainer: Jay Freeman (saurik) 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) -- 2.45.2