]> git.saurik.com Git - cydget.git/commitdiff
Finished implementing text/cycript.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 8 Nov 2009 14:13:14 +0000 (14:13 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 8 Nov 2009 14:13:14 +0000 (14:13 +0000)
LockScreen.mm
Welcome.html
control
make.sh
makefile

index f1963e73bcf61f87cf3dea78fe9b06fc7558f04a..06a6d4fb7e1133f30d938ce2a0237fc2aa5e20c4 100644 (file)
@@ -69,8 +69,10 @@ extern NSString * const kCAFilterNearest;
 #include <WebCore/WebCoreThread.h>
 #include <WebKit/WebPreferences-WebPrivate.h>
 
-//#include "Parser.h"
 #include "JSGlobalData.h"
+#include "SourceCode.h"
+
+#include <apr-1/apr_pools.h>
 
 @interface WebView (UICaboodle)
 - (void) setScriptDebugDelegate:(id)delegate;
@@ -95,8 +97,6 @@ _disused static unsigned trace_;
 - (NSDictionary *) currentConfiguration;
 @end
 
-static void (*CYSetupContext)(JSGlobalContextRef);
-
 static Class $CydgetController(objc_getClass("CydgetController"));
 
 @interface NSString (UIKit)
@@ -296,6 +296,7 @@ static Class $CydgetController(objc_getClass("CydgetController"));
 
     [scroller_ release];
     [indicator_ release];
+    [loading_ release];
     [super dealloc];
 }
 
@@ -358,6 +359,8 @@ static Class $CydgetController(objc_getClass("CydgetController"));
     frame.size.height -= GSDefaultStatusBarHeight();
 
     if ((self = [super initWithFrame:frame]) != nil) {
+        loading_ = [[NSMutableSet alloc] initWithCapacity:3];
+
         struct CGRect bounds([self bounds]);
 
         scroller_ = [[UIScroller alloc] initWithFrame:bounds];
@@ -592,12 +595,14 @@ static Class $CydgetController(objc_getClass("CydgetController"));
 }
 
 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
-    if (cycript_ && CYSetupContext != NULL) {
-        WebView *webview([document_ webView]);
-        WebFrame *frame([webview mainFrame]);
-        JSGlobalContextRef context([frame globalContext]);
-        CYSetupContext(context);
-    }
+    if (cycript_)
+        if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
+            if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CYSetupContext"))) {
+                WebView *webview([document_ webView]);
+                WebFrame *frame([webview mainFrame]);
+                JSGlobalContextRef context([frame globalContext]);
+                CYSetupContext(context);
+            }
 }
 
 - (bool) isLoading {
@@ -605,10 +610,13 @@ static Class $CydgetController(objc_getClass("CydgetController"));
 }
 
 - (void) reloadButtons {
-    if ([self isLoading])
+    if ([self isLoading]) {
+        [UIApp setNetworkActivityIndicatorVisible:YES];
         [indicator_ startAnimation];
-    else
+    } else {
+        [UIApp setNetworkActivityIndicatorVisible:NO];
         [indicator_ stopAnimation];
+    }
 }
 
 - (void) _finishLoading {
@@ -712,10 +720,94 @@ static Class $CydgetController(objc_getClass("CydgetController"));
 
 @end
 
-/*extern "C" void _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(JSC::Parser *, JSC::JSGlobalData *, int *, JSC::UString *);
-MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::Parser *_this, JSC::JSGlobalData *data, int *line, JSC::UString *message) {
-    return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, data, line, message);
-}*/
+#include <string>
+
+static bool cycript_;
+static bool jscript_;
+
+static void SetParser(bool cycript, bool jscript) {
+    cycript_ = cycript;
+    jscript_ = jscript;
+}
+
+static bool GetParser0() {
+    return cycript_;
+}
+
+static bool GetParser1() {
+    return jscript_;
+}
+
+static void Cycriptify(apr_pool_t *pool, const uint16_t *&data, size_t &size) {
+    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, "CYParseWebCore")))
+            CYParseUChar(pool, &data, &size);
+}
+
+MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::SourceCode **_this, JSC::JSGlobalData *global, int *line, JSC::UString *message) {
+    if (!GetParser0())
+        return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message);
+    else {
+        SetParser(false, true);
+        JSC::SourceCode *source(*_this);
+        const uint16_t *data(source->data());
+        size_t size(source->length());
+        apr_pool_t *pool;
+        apr_pool_create(&pool, NULL);
+        Cycriptify(pool, data, size);
+        std::string stuff(data, data + size);
+        JSC::SourceCode code(JSC::makeSource(JSC::UString(data, size)));
+        *_this = &code;
+        __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message);
+        apr_pool_destroy(pool);
+        *_this = source;
+    }
+}
+
+MSHook(void, _ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, void *_this, int start, const UChar *code, unsigned length, int *source, int *line, JSC::UString *message) {
+    if (!GetParser0())
+        return __ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE(_this, start, code, length, source, line, message);
+    else {
+        const uint16_t *data(code);
+        size_t size(length);
+        apr_pool_t *pool;
+        apr_pool_create(&pool, NULL);
+        Cycriptify(pool, data, size);
+        __ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE(_this, start, data, size, source, line, message);
+        apr_pool_destroy(pool);
+    }
+}
+
+struct State {
+    unsigned state;
+};
+
+MSHook(State, _ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, State state) {
+    SetParser(false, true);
+    state = __ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE(state);
+    SetParser(false, false);
+    return state;
+}
+
+MSHook(void, _ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, void *resource) {
+    SetParser(false, true);
+    __ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE(resource);
+    SetParser(false, false);
+}
+
+MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) {
+    bool jscript;
+
+    if (!GetParser1()) through:
+        jscript = __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime);
+    else if (mime == "text/cycript") {
+        SetParser(true, true);
+        jscript = true;
+    } else
+        goto through;
+
+    return jscript;
+}
 
 /* Cydget:// Protocol {{{ */
 @interface CydgetURLProtocol : NSURLProtocol {
@@ -789,13 +881,55 @@ MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::Parse
 @end
 /* }}} */
 
+template <typename Type_>
+static void nlset(Type_ &function, struct nlist *nl, size_t index) {
+    struct nlist &name(nl[index]);
+    uintptr_t value(name.n_value);
+    if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
+        value |= 0x00000001;
+    function = reinterpret_cast<Type_>(value);
+}
+
+template <typename Type_>
+static void dlset(Type_ &function, const char *name) {
+    function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
+}
+
 @implementation WebCycriptLockScreenController
 
 + (void) initialize {
+    apr_initialize();
+
     [NSURLProtocol registerClass:[CydgetURLProtocol class]];
-    //MSHookFunction(&_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE));
-    if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
-        CYSetupContext = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CYSetupContext"));
+
+    void (*_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)(JSC::SourceCode **, JSC::JSGlobalData *, int *, JSC::UString *);
+    dlset(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, "_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE");
+    if (_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE != NULL)
+        MSHookFunction(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE));
+
+    void (*_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE)(void *, int, const UChar *, unsigned, int *, int *, JSC::UString *);
+    dlset(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, "_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE");
+    if (_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE != NULL)
+        MSHookFunction(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, MSHake(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE));
+
+    struct nlist nl[4];
+    memset(nl, 0, sizeof(nl));
+    nl[0].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE";
+    nl[1].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE";
+    nl[2].n_un.n_name = (char *) "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE";
+    nlist("/System/Library/PrivateFrameworks/WebCore.framework/WebCore", nl);
+
+    State (*_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE)(State);
+    nlset(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, nl, 0);
+    MSHookFunction(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE));
+
+    void (*_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE)(void *);
+    nlset(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, nl, 1);
+    MSHookFunction(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, MSHake(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE));
+
+    bool (*_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)(const WebCore::String &);
+    nlset(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, nl, 2);
+    MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE));
 }
 
 + (id) rootViewController {
index 0863bb76f52be2eb693a790254a5c6e2510dd97e..724f31927f155f29f95c29bb0a8980fac64dfa47 100644 (file)
     }
 </style></head><body>
     <div id="lcd">
-        <h1 id="time">&nbsp;</h1>
+        <h1 id="time"><script type="text/javascript">
+            var now = new Date();
+            var minutes = now.getMinutes();
+            if (minutes.length == 1)
+                minutes = '0' + minutes
+            var time = now.getHours() + ':' + minutes;
+            document.write(time);
+        </script></h1>
+
         <h2>Welcome to Cydget!</h2>
     </div>
 
     <div id="content">
         <p>Cydget<sup>tm</sup> is a very simple SBAwayViewPlugin multiplexer, allowing both developers and web designers to extend the capabilities of the lock screen by tapping into the existing mechanism Apple is already using for VoiceRecorder and Nike+. The WebCycript Cydget framework is designed to be a powerful replacement for the Lock Widget feature from WinterBoard, which it hereby supercedes.</p>
+        <a href="http://www.saurik.com/">Home</a>
         <p>You can switch between Cydgets (your original SpringBoard away view is next in the rotation) using the Home/Menu button, and you can re-order them using Settings under "Cydget".</p>
     </div>
 
     <!-- XXX: extract this out to some kind of nifty Lock Cydget library -->
     <!-- XXX: this is incredibly indirect. I mean: wth, right? well, Cycript is the slowest thing on this page -->
-    <script type="text/javascript">document.addEventListener("DOMContentLoaded", function() {window.setTimeout(function() {with (Cycript.all) {
+    <!-- (in case anyone reading this: I believe it is entirely due to sqlite3, and I will be fixing this soon) -->
+    <script type="text/cycript">document.addEventListener("DOMContentLoaded", function() { window.setTimeout(function() { with (Cycript.all) {
         var locale = CFLocaleCopyCurrent();
         var now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
         var formatter = CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
diff --git a/control b/control
index a50e0b5dc97d20f4608951a8b94a2ff4e7490b13..797c1c9c7d049ee10b4f1d932fcfcacb4dfeefa4 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.3080-1
+Version: 0.9.3081-1
 Description: framework for managing lock screen plugins
 Name: Cydget
-Depends: mobilesubstrate (>= 0.9.2587-1), cycript (>= 0.9.252), firmware (>= 2.2)
+Depends: mobilesubstrate (>= 0.9.2587-1), firmware (>= 2.2), preferenceloader, apr-lib
 Replaces: cydialer (<< 0.9.17)
 Author: Jay Freeman (saurik) <saurik@saurik.com>
 Depiction: http://cydia.saurik.com/info/cydget/
diff --git a/make.sh b/make.sh
index 6d212b3101bcd9a827a34de118992e031df5972c..9ddd6573046d67cc5f4a6525fb696c130cdf8dd7 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -1,2 +1,2 @@
 #!/bin/bash
-PKG_ARCH=iphoneos-arm /apl/tel/exec.sh - make package "$@"
+PKG_ARCH=iphoneos-arm /apl/tel/exec.sh :apr:apr-lib make package "$@"
index 218a72115077dc25ef565f3526f9311b39ba0109..0f663889c3af14cbda319773af50599afbae973c 100644 (file)
--- a/makefile
+++ b/makefile
@@ -15,7 +15,7 @@ CydgetSettings: CydgetSettings.mm makefile
        ldid -S $@
 
 WebCycriptLockScreen: LockScreen.mm makefile $(base)/../mobilesubstrate/substrate.h
-       $(target)g++ -F. -bundle -mthumb -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -lobjc -I$(base)/../mobilesubstrate $(link) $(flags) -framework CoreGraphics -framework QuartzCore -framework SpringBoardUI -framework WebCore -framework JavaScriptCore -framework GraphicsServices -framework TelephonyUI -I$(jscore) -iquote$(webcore)/{bindings/js,dom,loader,platform{,/animation,/cf,/network{,/cf},/text},/rendering/style} -iquote$(jscore)/{bytecode,debugger,interpreter,jit,parser,runtime}
+       $(target)g++ -F. -bundle -mthumb -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -lobjc -I$(base)/../mobilesubstrate $(link) $(flags) -framework CoreGraphics -framework QuartzCore -framework SpringBoardUI -framework WebCore -framework JavaScriptCore -framework GraphicsServices -framework TelephonyUI -I$(jscore) -iquote$(webcore)/{bindings/js,dom,loader,platform{,/animation,/cf,/network{,/cf},/text},/rendering/style} -iquote$(jscore)/{bytecode,debugger,interpreter,jit,parser,runtime} -lapr-1
        ldid -S $@
 
 extra: