From 91fd6faef94753496b1f2d1c1442a292f067e0a2 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 9 Nov 2009 09:02:44 +0000 Subject: [PATCH] Re-envisioned Cycript configuration tag as a regex on URLs. --- LockScreen.mm | 67 +++++++++++++++++++++++++++++++++++++++++++-------- Welcome.plist | 2 +- control | 4 +-- make.sh | 2 +- makefile | 2 +- 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/LockScreen.mm b/LockScreen.mm index 1653fe8..bfb5432 100644 --- a/LockScreen.mm +++ b/LockScreen.mm @@ -73,6 +73,7 @@ extern NSString * const kCAFilterNearest; #include "SourceCode.h" #include +#include @interface WebView (UICaboodle) - (void) setScriptDebugDelegate:(id)delegate; @@ -129,6 +130,50 @@ static Class $CydgetController(objc_getClass("CydgetController")); @end +/* Perl-Compatible RegEx {{{ */ +class Pcre { + private: + pcre *code_; + pcre_extra *study_; + int capture_; + int *matches_; + const char *data_; + + public: + Pcre(const char *regex, int options = 0) : + study_(NULL) + { + const char *error; + int offset; + code_ = pcre_compile(regex, options, &error, &offset, NULL); + + if (code_ == NULL) + @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"*** Pcre(,): [%u] %s", offset, error] userInfo:nil]; + + pcre_fullinfo(code_, study_, PCRE_INFO_CAPTURECOUNT, &capture_); + matches_ = new int[(capture_ + 1) * 3]; + } + + ~Pcre() { + pcre_free(code_); + delete matches_; + } + + NSString *operator [](size_t match) { + return [[[NSString alloc] initWithBytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2]) encoding:NSUTF8StringEncoding] autorelease]; + } + + bool operator ()(NSString *data) { + // XXX: length is for characters, not for bytes + return operator ()([data UTF8String], [data length]); + } + + bool operator ()(const char *data, size_t size) { + data_ = data; + return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0; + } +}; +/* }}} */ /* WebCycript Delegate {{{ */ @interface WebCycriptDelegate : NSObject { _transient volatile id delegate_; @@ -236,7 +281,7 @@ static Class $CydgetController(objc_getClass("CydgetController")); UIScroller *scroller_; UIWebDocumentView *document_; - bool cycript_; + NSString *cycript_; bool scrollable_; float width_; @@ -487,7 +532,7 @@ static Class $CydgetController(objc_getClass("CydgetController")); NSDictionary *configuration([$CydgetController currentConfiguration]); - cycript_ = [[configuration objectForKey:@"Cycript"] boolValue]; + cycript_ = [configuration objectForKey:@"Cycript"]; scrollable_ = [[configuration objectForKey:@"Scrollable"] boolValue]; [scroller_ setScrollingEnabled:scrollable_]; @@ -595,14 +640,16 @@ static Class $CydgetController(objc_getClass("CydgetController")); } - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { - if (cycript_) - if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL)) - if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast(dlsym(handle, "CydgetSetupContext"))) { - WebView *webview([document_ webView]); - WebFrame *frame([webview mainFrame]); - JSGlobalContextRef context([frame globalContext]); - CYSetupContext(context); - } + if (cycript_ != nil) + if (NSString *href = [[[[frame dataSource] request] URL] absoluteString]) + if (Pcre([cycript_ UTF8String], 0 /*XXX:PCRE_UTF8*/)(href)) + if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL)) + if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast(dlsym(handle, "CydgetSetupContext"))) { + WebView *webview([document_ webView]); + WebFrame *frame([webview mainFrame]); + JSGlobalContextRef context([frame globalContext]); + CYSetupContext(context); + } } - (bool) isLoading { diff --git a/Welcome.plist b/Welcome.plist index 043ab38..ba23259 100644 --- a/Welcome.plist +++ b/Welcome.plist @@ -3,6 +3,6 @@ Plugin = "WebCycriptLockScreen"; Configuration = { Homepage = "file:///System/Library/LockCydgets/Welcome.cydget/Welcome.html"; - Cycript = "YES"; + Cycript = "^file:///System/Library/LockCydgets/Welcome\\.cydget/Welcome\\.html$"; Scrollable = "NO"; }; diff --git a/control b/control index 64a5ab2..c037282 100644 --- a/control +++ b/control @@ -3,10 +3,10 @@ Priority: optional Section: Development Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 0.9.3083-1 +Version: 0.9.3084-1 Description: framework for managing lock screen plugins Name: Cydget -Depends: mobilesubstrate (>= 0.9.2587-1), firmware (>= 2.2), preferenceloader, apr-lib +Depends: mobilesubstrate (>= 0.9.2587-1), firmware (>= 2.2), preferenceloader, apr-lib, pcre Replaces: cydialer (<< 0.9.17) Author: Jay Freeman (saurik) Depiction: http://cydia.saurik.com/info/cydget/ diff --git a/make.sh b/make.sh index 9ddd657..c36fb53 100755 --- a/make.sh +++ b/make.sh @@ -1,2 +1,2 @@ #!/bin/bash -PKG_ARCH=iphoneos-arm /apl/tel/exec.sh :apr:apr-lib make package "$@" +PKG_ARCH=iphoneos-arm /apl/tel/exec.sh :apr:apr-lib:pcre make package "$@" diff --git a/makefile b/makefile index 3d33f23..2f4df5d 100644 --- 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 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 -weak_reference_mismatches weak -framework JavaScriptCore + $(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 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 -weak_reference_mismatches weak -framework JavaScriptCore -lpcre ldid -S $@ extra: -- 2.45.2