1 /* Cydget - open-source AwayView plugin multiplexer
2 * Copyright (C) 2009-2014 Jay Freeman (saurik)
5 /* GNU General Public License, Version 3 {{{ */
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
22 #include <CydiaSubstrate/CydiaSubstrate.h>
23 #include <UIKit/UIKit.h>
25 #include <sys/sysctl.h>
28 #include <SpringBoardUI/SBAwayViewPluginController.h>
30 #include <WebKit/WebFrame.h>
31 #include <WebKit/WebView.h>
32 #include <WebKit/WebPreferences-WebPrivate.h>
34 #include "yieldToSelector.h"
37 #include <unicode/uregex.h>
43 #define _forever for (;;)
45 _disused static unsigned trace_;
47 #define _trace() do { \
48 NSLog(@"_trace(%u)@%s:%u[%s](%p)\n", \
49 trace_++, __FILE__, __LINE__, __FUNCTION__, pthread_self() \
53 #define _assert(test) do \
55 NSLog(@"_assert(%d:%s)@%s:%u[%s]\n", errno, #test, __FILE__, __LINE__, __FUNCTION__); \
60 #define _syscall(expr) \
61 do if ((long) (expr) != -1) \
63 else switch (errno) { \
70 extern "C" UIImage *_UIImageWithName(NSString *name);
72 typedef uint16_t UChar;
74 @interface TPBottomLockBar
75 - (CGFloat) defaultHeight;
78 @interface UIApplication (Apple)
79 - (void) applicationOpenURL:(NSURL *)url;
82 @interface UIScroller : UIView
83 - (CGSize) contentSize;
84 - (void) setDirectionalScrolling:(BOOL)directional;
85 - (void) setOffset:(CGPoint)offset;
86 - (void) setScrollDecelerationFactor:(CGFloat)factor;
87 - (void) setScrollHysteresis:(CGFloat)hysteresis;
88 - (void) setThumbDetectionEnabled:(BOOL)enabled;
91 @interface UIWebDocumentView : UIView
92 - (CGRect) documentBounds;
93 - (void) enableReachability;
94 - (void) loadRequest:(NSURLRequest *)request;
95 - (void) redrawScaledDocument;
96 - (void) setAllowsImageSheet:(BOOL)allows;
97 - (void) setAllowsMessaging:(BOOL)allows;
98 - (void) setAutoresizes:(BOOL)autoresizes;
99 - (void) setContentsPosition:(NSInteger)position;
100 - (void) setDrawsBackground:(BOOL)draws;
101 - (void) _setDocumentType:(NSInteger)type;
102 - (void) setDrawsGrid:(BOOL)draws;
103 - (void) setInitialScale:(float)scale forDocumentTypes:(NSInteger)types;
104 - (void) setLogsTilingChanges:(BOOL)logs;
105 - (void) setMinimumScale:(float)scale forDocumentTypes:(NSInteger)types;
106 - (void) setMinimumSize:(CGSize)size;
107 - (void) setMaximumScale:(float)scale forDocumentTypes:(NSInteger)tpyes;
108 - (void) setSmoothsFonts:(BOOL)smooths;
109 - (void) setTileMinificationFilter:(NSString *)filter;
110 - (void) setTileSize:(CGSize)size;
111 - (void) setTilingEnabled:(BOOL)enabled;
112 - (void) setViewportSize:(CGSize)size forDocumentTypes:(NSInteger)types;
113 - (void) setZoomsFocusedFormControl:(BOOL)zooms;
114 - (void) useSelectionAssistantWithMode:(NSInteger)mode;
115 - (WebView *) webView;
118 @interface UIView (Apple)
119 - (UIScroller *) _scroller;
120 - (void) setClipsSubviews:(BOOL)clips;
121 - (void) setEnabledGestures:(NSInteger)gestures;
122 - (void) setFixedBackgroundPattern:(BOOL)fixed;
123 - (void) setGestureDelegate:(id)delegate;
124 - (void) setNeedsDisplayOnBoundsChange:(BOOL)needs;
125 - (void) setValue:(NSValue *)value forGestureAttribute:(NSInteger)attribute;
126 - (void) setZoomScale:(float)scale duration:(double)duration;
127 - (void) _setZoomScale:(float)scale duration:(double)duration;
130 @interface SBLockScreenView : UIView
131 - (BOOL) mediaControlsHidden;
134 @interface SBLockScreenNotificationListController : NSObject
135 - (BOOL) hasAnyContent;
138 @interface SBLockScreenViewController : UIViewController
139 - (SBLockScreenView *) lockScreenView;
140 - (BOOL) isShowingMediaControls;
141 - (void) _setMediaControlsVisible:(BOOL)visible;
142 - (SBLockScreenNotificationListController *) _notificationController;
145 @interface SBLockScreenManager : NSObject
146 + (SBLockScreenManager *) sharedInstance;
147 - (SBLockScreenViewController *) lockScreenViewController;
150 @protocol CydgetController
151 - (NSDictionary *) currentConfiguration;
152 - (NSString *) currentPath;
155 static Class $CydgetController(objc_getClass("CydgetController"));
157 static bool iOS32, iOS4;
159 @interface NSString (UIKit)
160 - (NSString *) stringByAddingPercentEscapes;
163 @implementation UIWebDocumentView (WebCycript)
165 - (void) _setScrollerOffset:(CGPoint)offset {
166 UIScroller *scroller([self _scroller]);
168 CGSize size([scroller contentSize]);
169 CGSize bounds([scroller bounds].size);
172 max.x = size.width - bounds.width;
173 max.y = size.height - bounds.height;
181 offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x;
182 offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y;
184 [scroller setOffset:offset];
190 /* ICU Regular Expression {{{ */
193 URegularExpression *regex_;
196 RegEx(const char *regex) {
198 UErrorCode status(U_ZERO_ERROR);
199 regex_ = uregex_openC(regex, 0, &error, &status);
200 if (U_FAILURE(status))
201 @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"*** RegEx(): [%u] %s", error.offset, u_errorName(status)] userInfo:nil];
205 uregex_close(regex_);
208 bool operator ()(NSString *string) {
209 return operator ()(reinterpret_cast<const uint16_t *>([string cStringUsingEncoding:NSUTF16StringEncoding]), [string length]);
212 bool operator ()(const UChar *data, size_t size) {
213 UErrorCode status(U_ZERO_ERROR);
214 uregex_setText(regex_, data, size, &status);
215 _assert(U_SUCCESS(status));
216 bool matches(uregex_matches(regex_, 0, &status));
217 _assert(U_SUCCESS(status));
223 /* Perl-Compatible RegEx {{{ */
233 RegEx(const char *regex) :
238 code_ = pcre_compile(regex, 0, &error, &offset, NULL);
241 @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"*** RegEx(): [%u] %s", offset, error] userInfo:nil];
243 pcre_fullinfo(code_, study_, PCRE_INFO_CAPTURECOUNT, &capture_);
244 matches_ = new int[(capture_ + 1) * 3];
252 bool operator ()(NSString *data) {
253 // XXX: length is for characters, not for bytes
254 return operator ()([data UTF8String], [data length]);
257 bool operator ()(const char *data, size_t size) {
259 return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0;
265 @interface DOMCSSStyleSheet : NSObject
266 - (int) addRule:(NSString *)rule style:(NSString *)style index:(unsigned)index;
267 - (void) deleteRule:(unsigned)index;
270 @interface DOMStyleSheetList : NSObject
271 - (DOMCSSStyleSheet *) item:(unsigned)index;
274 @interface DOMDocument : NSObject
275 - (DOMStyleSheetList *) styleSheets;
278 static float CYScrollViewDecelerationRateNormal;
280 @interface NSURL (Apple)
281 - (BOOL) isSpringboardHandledURL;
284 @interface UIScrollView (Apple)
285 - (void) setDecelerationRate:(CGFloat)value;
286 - (void) setScrollingEnabled:(BOOL)enabled;
287 - (void) setShowBackgroundShadow:(BOOL)show;
290 @interface UIWebView (Apple)
291 - (UIWebDocumentView *) _documentView;
292 - (void) setDataDetectorTypes:(NSInteger)types;
293 - (void) _setDrawInWebThread:(BOOL)draw;
294 - (UIScrollView *) _scrollView;
295 - (UIScroller *) _scroller;
296 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message;
297 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
300 @interface WebView (Apple)
301 - (void) _setLayoutInterval:(float)interval;
302 - (void) _setAllowsMessaging:(BOOL)allows;
303 - (void) setShouldUpdateWhileOffscreen:(BOOL)update;
306 @protocol CydgetWebViewDelegate <UIWebViewDelegate>
307 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
310 @class UIWebViewWebViewDelegate;
312 @interface CydgetWebView : UIWebView {
315 - (void) updateStyles;
319 MSClassHook(UIApplication)
320 MSClassHook(SBLockScreenManager)
322 MSInstanceMessageHook1(void, UIApplication, openURL, NSURL *, url) {
323 [self applicationOpenURL:url];
326 @implementation NSURL (Cydget)
328 - (NSNumber *) cydget$isSpringboardHandledURL {
329 return [NSNumber numberWithBool:[self isSpringboardHandledURL]];
336 MSInstanceMessageHook0(BOOL, NSURL, isSpringboardHandledURL) {
337 if (![NSThread isMainThread])
340 return [[self cydget$yieldToSelector:@selector(cydget$isSpringboardHandledURL)] boolValue];
343 @implementation CydgetWebView
345 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
346 NSObject<CydgetWebViewDelegate> *delegate((NSObject<CydgetWebViewDelegate> *) [self delegate]);
347 if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
348 [delegate webView:view didClearWindowObject:window forFrame:frame];
349 if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)])
350 [super webView:view didClearWindowObject:window forFrame:frame];
353 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
354 NSLog(@"addMessageToConsole:%@", message);
356 if ([UIWebView instancesRespondToSelector:@selector(webView:addMessageToConsole:)])
357 [super webView:view addMessageToConsole:message];
360 - (void) updateStyles {
361 DOMCSSStyleSheet *sheet([[[[[[self _documentView] webView] mainFrame] DOMDocument] styleSheets] item:0]);
362 [sheet addRule:@"cydget" style:@"color: black" index:0];
363 [sheet deleteRule:0];
368 @interface WebCydgetLockScreenView : UIView <UIWebViewDelegate> {
369 CydgetWebView *webview_;
370 UIScrollView *scroller_;
374 - (void) updateStyles;
378 @implementation WebCydgetLockScreenView
380 //#include "UICaboodle/UCInternal.h"
383 [[NSNotificationCenter defaultCenter] removeObserver:self];
384 [webview_ setDelegate:nil];
389 - (void) loadRequest:(NSURLRequest *)request {
390 [webview_ loadRequest:request];
393 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
394 [self loadRequest:[NSURLRequest
401 - (void) loadURL:(NSURL *)url {
402 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
405 - (id) initWithURL:(NSURL *)url {
406 CGRect frame = [[UIScreen mainScreen] bounds];
407 if (kCFCoreFoundationVersionNumber < 800)
408 frame.size.height -= 20; //[[[$SBStatusBarController sharedStatusBarController] statusBarView] frame].size.height;
410 if ((self = [super initWithFrame:frame]) != nil) {
411 CGRect bounds([self bounds]);
412 if (kCFCoreFoundationVersionNumber < 800)
413 bounds.size.height -= [objc_getClass("TPBottomLockBar") defaultHeight];
415 webview_ = [[CydgetWebView alloc] initWithFrame:bounds];
416 [webview_ setDelegate:self];
417 [self addSubview:webview_];
419 if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
420 [webview_ setDataDetectorTypes:0x80000000];
422 [webview_ setDetectsPhoneNumbers:NO];
424 [webview_ setScalesPageToFit:YES];
426 if (kCFCoreFoundationVersionNumber < 478.61)
427 if ([webview_ respondsToSelector:@selector(_setDrawInWebThread:)])
428 [webview_ _setDrawInWebThread:NO];
430 UIWebDocumentView *document([webview_ _documentView]);
431 WebView *webview([document webView]);
432 WebPreferences *preferences([webview preferences]);
434 [document setTileSize:CGSizeMake(bounds.size.width, 500)];
436 [document setBackgroundColor:[UIColor clearColor]];
437 [document setDrawsBackground:NO];
439 [webview setPreferencesIdentifier:@"WebCycript"];
441 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
442 [webview _setLayoutInterval:0];
444 [preferences _setLayoutInterval:0];
446 [preferences setCacheModel:WebCacheModelDocumentViewer];
447 [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
448 [preferences setOfflineWebApplicationCacheEnabled:YES];
450 if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)])
451 [webview setShouldUpdateWhileOffscreen:NO];
453 if ([document respondsToSelector:@selector(setAllowsMessaging:)])
454 [document setAllowsMessaging:YES];
455 if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
456 [webview _setAllowsMessaging:YES];
458 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
459 scroller_ = [webview_ _scrollView];
461 [scroller_ setDirectionalLockEnabled:YES];
462 [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
463 [scroller_ setDelaysContentTouches:NO];
465 [scroller_ setCanCancelContentTouches:YES];
467 [scroller_ setAlwaysBounceVertical:NO];
468 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
469 UIScroller *scroller([webview_ _scroller]);
470 scroller_ = (UIScrollView *) scroller;
472 [scroller setDirectionalScrolling:YES];
473 [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
474 [scroller setScrollHysteresis:0]; /* 8 */
476 [scroller setThumbDetectionEnabled:NO];
479 [webview_ setOpaque:NO];
480 [webview_ setBackgroundColor:[UIColor clearColor]];
482 [scroller_ setFixedBackgroundPattern:YES];
483 [scroller_ setBackgroundColor:[UIColor clearColor]];
484 [scroller_ setClipsSubviews:NO];
486 [scroller_ setBounces:YES];
487 [scroller_ setShowBackgroundShadow:NO]; /* YES */
489 [self setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
490 [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
492 NSDictionary *configuration([$CydgetController currentConfiguration]);
493 cycript_ = [configuration objectForKey:@"CycriptURLs"];
495 [scroller_ setScrollingEnabled:[[configuration objectForKey:@"Scrollable"] boolValue]];
499 [[NSNotificationCenter defaultCenter]
501 selector:@selector(mediaControlsDidSomething:)
502 name:@"SBLockScreenViewControllerMediaControlsDidShow"
506 [[NSNotificationCenter defaultCenter]
508 selector:@selector(mediaControlsDidSomething:)
509 name:@"SBLockScreenViewControllerMediaControlsDidHide"
515 - (void) mediaControlsDidSomething:(NSNotification *)notification {
519 - (void) webView:(WebView *)webview didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
521 if (NSString *href = [[[[frame dataSource] request] URL] absoluteString])
522 if (RegEx([cycript_ UTF8String])(href))
523 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
524 if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CydgetSetupContext"))) {
525 WebFrame *frame([webview mainFrame]);
526 JSGlobalContextRef context([frame globalContext]);
528 CYSetupContext(context);
529 } @catch (NSException *e) {
530 NSLog(@"*** CydgetSetupContext => %@", e);
535 - (void) updateStyles {
536 [webview_ updateStyles];
541 @interface WebCycriptLockScreenController : SBAwayViewPluginController {
542 NSDictionary *configuration_;
546 WebCydgetLockScreenView *background_;
547 WebCydgetLockScreenView *foreground_;
581 union ScriptSourceCode {
583 JSC::SourceCode source_;
587 JSC::SourceCode source_;
591 class CFStringStruct {
604 operator CFStringRef() const {
608 operator NSString *() const {
609 return (NSString *) value_;
613 // String Helpers {{{
614 static const UChar *(*_ZNK7WebCore6String10charactersEv)(const WebCore::String *);
615 static const UChar *(*_ZN7WebCore6String29charactersWithNullTerminationEv)(const WebCore::String *);
616 static CFStringStruct (*_ZNK3WTF6String14createCFStringEv)(const WebCore::String *);
617 static unsigned (*_ZNK7WebCore6String6lengthEv)(const WebCore::String *);
619 static bool StringGet(const WebCore::String &string, const UChar *&data, size_t &length) {
623 } else if (_ZNK7WebCore6String10charactersEv != NULL) {
624 data = (*_ZNK7WebCore6String10charactersEv)(&string);
626 } else if (_ZN7WebCore6String29charactersWithNullTerminationEv != NULL) {
627 data = (*_ZN7WebCore6String29charactersWithNullTerminationEv)(&string);
629 } else if (_ZNK3WTF6String14createCFStringEv != NULL) {
630 CFStringStruct cf((*_ZNK3WTF6String14createCFStringEv)(&string));
631 data = (const UChar *) [cf cStringUsingEncoding:NSUTF16StringEncoding];
632 length = CFStringGetLength(cf);
639 if (_ZNK7WebCore6String6lengthEv != NULL)
640 length = (*_ZNK7WebCore6String6lengthEv)(&string);
642 for (length = 0; data[length] != 0; ++length);
648 static bool StringEquals(const WebCore::String &string, const char *value) {
651 if (!StringGet(string, data, size))
654 size_t length(strlen(value));
658 for (size_t index(0); index != length; ++index)
659 if (data[index] != value[index])
666 static bool cycript_;
668 MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) {
669 if (!StringEquals(mime, "text/cycript")) {
671 return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime);
674 static void *handle(dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL));
682 // Script Compiler {{{
683 static void Log(const WebCore::String &string) {
687 if (!StringGet(string, data, length))
690 UChar terminated[length + 1];
691 terminated[length] = 0;
692 memcpy(terminated, data, length * 2);
693 NSLog(@"wtf %p:%zu:%S:", &string, length, terminated);
697 static bool Cycriptify(const uint16_t *&data, size_t &size) {
700 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
701 if (void (*CydgetMemoryParse)(const uint16_t **, size_t *) = reinterpret_cast<void (*)(const uint16_t **, size_t *)>(dlsym(handle, "CydgetMemoryParse"))) @try {
702 CydgetMemoryParse(&data, &size);
704 } @catch (NSException *e) {
705 NSLog(@"*** CydgetMemoryParse => %@", e);
710 static void (*_ZN7WebCore6String6appendEPKtj)(WebCore::String *, const UChar *, unsigned);
711 static void (*_ZN7WebCore6String8truncateEj)(WebCore::String *, unsigned);
713 static void Cycriptify(const WebCore::String &source, int *psize = NULL) {
720 if (!StringGet(source, data, length))
724 if (!Cycriptify(data, size))
727 WebCore::String &script(const_cast<WebCore::String &>(source));
728 _ZN7WebCore6String8truncateEj(&script, 0);
729 _ZN7WebCore6String6appendEPKtj(&script, data, size);
740 static WebCore::String *string;
743 MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, void *_this, const WebCore::String &string, State state, const WebCore::String &url, int line) {
745 return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i(_this, string, state, url, line);
749 MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::SourceCode **_this, JSC::JSGlobalData *global, int *line, JSC::UString *message) {
751 JSC::SourceCode *source(_this[iOS32 ? 6 : 0]);
752 const uint16_t *data(source->data());
753 size_t size(source->length());
755 if (Cycriptify(data, size)) {
756 source->~SourceCode();
757 // XXX: I actually don't have the original URL here: pants
758 new (source) JSC::SourceCode(JSC::UStringSourceProvider::create(JSC::UString(data, size), "cycript://"), 1);
763 return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message);
767 MSHook(const WebCore::String &, _ZNK7WebCore4Node11textContentEb, void *_this, bool convert) {
768 const WebCore::String &code(__ZNK7WebCore4Node11textContentEb(_this, convert));
769 string = const_cast<WebCore::String *>(&code);
776 MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, void *_this, const WebCore::String &source, const WebCore::KURL &url, int line) {
778 return __ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi(_this, source, url, line);
782 MSHook(const WebCore::String &, _ZN7WebCore12CachedScript6scriptEv, void *_this) {
783 const WebCore::String &script(__ZN7WebCore12CachedScript6scriptEv(_this));
784 string = const_cast<WebCore::String *>(&script);
790 MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, void *_this, JSC::ScriptSourceCode &script, State state) {
791 if (string != NULL) {
792 JSC::SourceCode *source(iOS4 ? &script.New.source_ : &script.Old.source_);
793 Cycriptify(*string, &source->end_);
797 return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE(_this, script, state);
801 MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE, void *_this, const WebCore::String &source, const WebCore::KURL &url, void *position) {
803 return __ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE(_this, source, url, position);
807 MSHook(void, _ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE, void *_this, void *position, int legacy) {
809 return __ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE(_this, position, legacy);
812 void (*$_ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE)(void *_this, int legacy);
815 MSHook(void, _ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE, void *_this, JSC::ScriptSourceCode &script) {
816 if (string != NULL) {
817 JSC::SourceCode *source(&script.New.source_);
818 $_ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE(_this, 0);
819 Cycriptify(*string, &source->end_);
823 return __ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE(_this, script);
827 MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, void *_this, const WebCore::String &source, const WebCore::KURL &url, void *position) {
829 return __ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE(_this, source, url, position);
833 MSHook(void, _ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE, void *_this, void *position, int legacy) {
835 return __ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE(_this, position, legacy);
838 /* Cydget:// Protocol {{{ */
839 @interface CydgetURLProtocol : NSURLProtocol {
844 @implementation CydgetURLProtocol
846 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
847 NSURL *url([request URL]);
850 NSString *scheme([[url scheme] lowercaseString]);
851 if (scheme == nil || ![scheme isEqualToString:@"cydget"])
856 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
860 - (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request {
861 id<NSURLProtocolClient> client([self client]);
863 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
865 NSData *data(UIImagePNGRepresentation(icon));
867 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]);
868 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
869 [client URLProtocol:self didLoadData:data];
870 [client URLProtocolDidFinishLoading:self];
874 - (void) startLoading {
875 id<NSURLProtocolClient> client([self client]);
876 NSURLRequest *request([self request]);
878 NSURL *url([request URL]);
879 NSString *href([url absoluteString]);
881 NSString *path([href substringFromIndex:9]);
882 NSRange slash([path rangeOfString:@"/"]);
885 if (slash.location == NSNotFound) {
889 command = [path substringToIndex:slash.location];
890 path = [path substringFromIndex:(slash.location + 1)];
893 if ([command isEqualToString:@"_UIImageWithName"]) {
896 path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
897 UIImage *icon(_UIImageWithName(path));
898 [self _returnPNGWithImage:icon forRequest:request];
900 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
904 - (void) stopLoading {
909 /* Cydget-CGI:// Protocol {{{ */
910 @interface CydgetCGIURLProtocol : NSURLProtocol {
912 CFHTTPMessageRef http_;
913 NSFileHandle *handle_;
918 @implementation CydgetCGIURLProtocol
920 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
921 NSURL *url([request URL]);
924 NSString *scheme([[url scheme] lowercaseString]);
925 if (scheme == nil || ![scheme isEqualToString:@"cydget-cgi"])
930 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
934 - (id) initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)response client:(id<NSURLProtocolClient>)client {
935 if ((self = [super initWithRequest:request cachedResponse:response client:client]) != nil) {
940 - (void) startLoading {
941 id<NSURLProtocolClient> client([self client]);
942 NSURLRequest *request([self request]);
943 NSURL *url([request URL]);
945 NSString *path([url path]);
947 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
951 NSFileManager *manager([NSFileManager defaultManager]);
952 if (![manager fileExistsAtPath:path]) {
953 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
958 _assert(pipe(fds) != -1);
963 _assert(close(fds[0]) != -1);
964 _assert(close(fds[1]) != -1);
965 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
970 const char *script([path UTF8String]);
972 setenv("GATEWAY_INTERFACE", "CGI/1.1", true);
973 setenv("SCRIPT_FILENAME", script, true);
974 NSString *query([url query]);
976 setenv("QUERY_STRING", [query UTF8String], true);
978 _assert(dup2(fds[1], 1) != -1);
979 _assert(close(fds[0]) != -1);
980 _assert(close(fds[1]) != -1);
982 execl(script, script, NULL);
987 _assert(close(fds[1]) != -1);
989 _assert(http_ == NULL);
990 http_ = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE);
991 CFHTTPMessageAppendBytes(http_, (const uint8_t *) "HTTP/1.1 200 OK\r\n", 17);
993 _assert(handle_ == nil);
994 handle_ = [[NSFileHandle alloc] initWithFileDescriptor:fds[0] closeOnDealloc:YES];
996 [[NSNotificationCenter defaultCenter]
998 selector:@selector(onRead:)
999 name:@"NSFileHandleReadCompletionNotification"
1003 [handle_ readInBackgroundAndNotify];
1006 - (void) onRead:(NSNotification *)notification {
1007 NSFileHandle *handle([notification object]);
1009 NSData *data([[notification userInfo] objectForKey:NSFileHandleNotificationDataItem]);
1011 if (size_t length = [data length]) {
1012 CFHTTPMessageAppendBytes(http_, reinterpret_cast<const UInt8 *>([data bytes]), length);
1013 [handle readInBackgroundAndNotify];
1015 id<NSURLProtocolClient> client([self client]);
1017 CFStringRef mime(CFHTTPMessageCopyHeaderFieldValue(http_, CFSTR("Content-type")));
1019 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]];
1021 NSURLRequest *request([self request]);
1023 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:(NSString *)mime expectedContentLength:-1 textEncodingName:nil] autorelease]);
1026 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
1028 CFDataRef body(CFHTTPMessageCopyBody(http_));
1029 [client URLProtocol:self didLoadData:(NSData *)body];
1032 [client URLProtocolDidFinishLoading:self];
1040 //[client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNetworkConnectionLost userInfo:nil]];
1042 - (void) stopLoading_ {
1043 [[NSNotificationCenter defaultCenter] removeObserver:self];
1045 if (handle_ != nil) {
1051 kill(pid_, SIGTERM);
1053 _syscall(waitpid(pid_, &status, 0));
1058 - (void) stopLoading {
1060 performSelectorOnMainThread:@selector(stopLoading_)
1070 class MediaQueryEvaluator;
1071 class CSSParserValueList;
1075 struct MediaQueryExp {
1082 bool CYHaveMediaControls() {
1083 SBLockScreenView *view([[[$SBLockScreenManager sharedInstance] lockScreenViewController] lockScreenView]);
1084 return view != nil && ![view mediaControlsHidden];
1085 //return [[[$SBLockScreenManager sharedInstance] lockScreenViewController] isShowingMediaControls];
1088 bool CYHaveNotificationList() {
1089 SBLockScreenNotificationListController *controller([[[$SBLockScreenManager sharedInstance] lockScreenViewController] _notificationController]);
1090 return controller != nil && [controller hasAnyContent];
1093 MSHook(bool, _ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE, WebCore::MediaQueryEvaluator *_this, WebCore::String &query) {
1094 Log(query); if (false);
1095 else if (kCFCoreFoundationVersionNumber >= 800 && StringEquals(query, "-cydget-media-controls"))
1096 return CYHaveMediaControls();
1097 else if (kCFCoreFoundationVersionNumber >= 800 && StringEquals(query, "-cydget-notification-list"))
1098 return CYHaveNotificationList();
1100 return __ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE(_this, query);
1103 MSHook(void *, _ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE, WebCore::MediaQueryExp *_this, WebCore::String &query, WebCore::CSSParserValueList *values) {
1105 void *value(__ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE(_this, query, values));
1106 if (!_this->valid_) if (
1107 StringEquals(query, "-cydget-media-controls") ||
1108 StringEquals(query, "-cydget-notification-list") ||
1109 false) _this->valid_ = true;
1113 template <typename Type_>
1114 static void dlset(Type_ &function, const char *name) {
1115 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1118 #define msset(function, handle) \
1119 MSHookSymbol(function, "_" #function, handle)
1121 @implementation WebCycriptLockScreenController
1123 static void $UIWebViewWebViewDelegate$webView$addMessageToConsole$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *message) {
1124 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
1125 if ([uiWebView respondsToSelector:@selector(webView:addMessageToConsole:)])
1126 [uiWebView webView:view addMessageToConsole:message];
1129 static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) {
1130 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
1131 if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
1132 [uiWebView webView:view didClearWindowObject:window forFrame:frame];
1135 + (void) initialize {
1136 if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) {
1137 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12");
1138 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16");
1141 if (CGFloat *_UIScrollViewDecelerationRateNormal = reinterpret_cast<CGFloat *>(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal")))
1142 CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal;
1143 else // XXX: this actually might be fast on some older systems: we should look into this
1144 CYScrollViewDecelerationRateNormal = 0.998;
1146 iOS4 = kCFCoreFoundationVersionNumber >= 550.32;
1147 iOS32 = !iOS4 && kCFCoreFoundationVersionNumber >= 478.61;
1150 size_t size(sizeof(maxproc));
1151 if (sysctlbyname("kern.maxproc", &maxproc, &size, NULL, 0) == -1)
1152 NSLog(@"sysctlbyname(\"kern.maxproc\", ?)");
1153 else if (maxproc < 72) {
1155 if (sysctlbyname("kern.maxproc", NULL, NULL, &maxproc, sizeof(maxproc)) == -1)
1156 NSLog(@"sysctlbyname(\"kern.maxproc\", #)");
1159 [NSURLProtocol registerClass:[CydgetURLProtocol class]];
1160 [WebView registerURLSchemeAsLocal:@"cydget"];
1162 [NSURLProtocol registerClass:[CydgetCGIURLProtocol class]];
1163 [WebView registerURLSchemeAsLocal:@"cydget-cgi"];
1165 MSImageRef JavaScriptCore(NULL);
1166 if (JavaScriptCore == NULL)
1167 JavaScriptCore = MSGetImageByName("/System/Library/Frameworks/JavaScriptCore.framework/JavaScriptCore");
1168 if (JavaScriptCore == NULL)
1169 JavaScriptCore = MSGetImageByName("/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
1171 MSImageRef WebCore(MSGetImageByName("/System/Library/PrivateFrameworks/WebCore.framework/WebCore"));
1174 void (*_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)(JSC::SourceCode **, JSC::JSGlobalData *, int *, JSC::UString *);
1175 dlset(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, "_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE");
1176 if (_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE != NULL)
1177 MSHookFunction(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE));
1180 bool (*_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)(const WebCore::String &) = NULL;
1181 if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE == NULL)
1182 MSHookSymbol(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE", WebCore);
1183 if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE == NULL)
1184 MSHookSymbol(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKN3WTF6StringE", WebCore);
1185 if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE != NULL)
1186 MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE));
1188 void (*_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi)(void *, const WebCore::String &, const WebCore::KURL &, int) = NULL;
1189 if (_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi == NULL)
1190 MSHookSymbol(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, "__ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi", WebCore);
1191 if (_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi != NULL)
1192 MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi));
1195 const WebCore::String &(*_ZNK7WebCore4Node11textContentEb)(void *, bool) = NULL;
1196 if (_ZNK7WebCore4Node11textContentEb == NULL)
1197 MSHookSymbol(_ZNK7WebCore4Node11textContentEb, "__ZNK7WebCore4Node11textContentEb", WebCore);
1198 if (_ZNK7WebCore4Node11textContentEb != NULL)
1199 MSHookFunction(_ZNK7WebCore4Node11textContentEb, MSHake(_ZNK7WebCore4Node11textContentEb));
1202 const WebCore::String &(*_ZN7WebCore12CachedScript6scriptEv)(void *) = NULL;
1203 if (_ZN7WebCore12CachedScript6scriptEv == NULL)
1204 MSHookSymbol(_ZN7WebCore12CachedScript6scriptEv, "__ZN7WebCore12CachedScript6scriptEv", WebCore);
1205 if (_ZN7WebCore12CachedScript6scriptEv != NULL)
1206 MSHookFunction(_ZN7WebCore12CachedScript6scriptEv, MSHake(_ZN7WebCore12CachedScript6scriptEv));
1208 State (*_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i)(void *, const WebCore::String &, State, const WebCore::String &, int) = NULL;
1209 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i == NULL)
1210 MSHookSymbol(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i", WebCore);
1211 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i != NULL)
1212 MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i));
1214 State (*_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE)(void *, JSC::ScriptSourceCode &, State) = NULL;
1215 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE == NULL)
1216 MSHookSymbol(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE", WebCore);
1217 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE != NULL)
1218 MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE));
1220 void (*_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE)(void *, const WebCore::String &, const WebCore::KURL &, void *);
1221 msset(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE, WebCore);
1222 if (_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE != NULL)
1223 MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE));
1225 void (*_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE)(void *, const WebCore::String &, const WebCore::KURL &, void *);
1226 msset(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, WebCore);
1227 if (_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE == NULL)
1228 MSHookSymbol(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, "__ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_3URLERKNS1_12TextPositionE", WebCore);
1229 if (_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE != NULL)
1230 MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE));
1232 void (*_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE)(void *, void *, int);
1233 msset(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE, WebCore);
1234 if (_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE != NULL)
1235 MSHookFunction(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE, MSHake(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE));
1237 void (*_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE)(void *, void *, int);
1238 msset(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE, WebCore);
1239 if (_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE != NULL)
1240 MSHookFunction(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE, MSHake(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE));
1242 MSHookSymbol($_ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE, "__ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE", WebCore);
1244 void (*_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE)(void *, JSC::ScriptSourceCode &);
1245 msset(_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE, WebCore);
1246 if (_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE != NULL)
1247 MSHookFunction(_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE, MSHake(_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE));
1249 if (_ZN7WebCore6String6appendEPKtj == NULL)
1250 MSHookSymbol(_ZN7WebCore6String6appendEPKtj, "__ZN7WebCore6String6appendEPKtj", WebCore);
1251 if (_ZN7WebCore6String6appendEPKtj == NULL)
1252 msset(_ZN7WebCore6String6appendEPKtj, JavaScriptCore);
1253 if (_ZN7WebCore6String6appendEPKtj == NULL)
1254 MSHookSymbol(_ZN7WebCore6String6appendEPKtj, "__ZN3WTF6String6appendEPKtj", JavaScriptCore);
1256 if (_ZN7WebCore6String8truncateEj == NULL)
1257 MSHookSymbol(_ZN7WebCore6String8truncateEj, "__ZN7WebCore6String8truncateEj", WebCore);
1258 if (_ZN7WebCore6String8truncateEj == NULL)
1259 msset(_ZN7WebCore6String8truncateEj, JavaScriptCore);
1260 if (_ZN7WebCore6String8truncateEj == NULL)
1261 MSHookSymbol(_ZN7WebCore6String8truncateEj, "__ZN3WTF6String8truncateEj", JavaScriptCore);
1263 msset(_ZNK7WebCore6String10charactersEv, WebCore);
1265 msset(_ZN7WebCore6String29charactersWithNullTerminationEv, JavaScriptCore);
1266 if (_ZN7WebCore6String29charactersWithNullTerminationEv == NULL)
1267 MSHookSymbol(_ZN7WebCore6String29charactersWithNullTerminationEv, "__ZN3WTF6String29charactersWithNullTerminationEv", JavaScriptCore);
1269 msset(_ZNK3WTF6String14createCFStringEv, JavaScriptCore);
1271 msset(_ZNK7WebCore6String6lengthEv, WebCore);
1273 bool (*_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE)(WebCore::MediaQueryEvaluator *, WebCore::String &);
1274 msset(_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE, WebCore);
1275 if (_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE != NULL)
1276 MSHookFunction(_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE, MSHake(_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE));
1278 void *(*_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE)(WebCore::MediaQueryExp *, WebCore::String &, WebCore::CSSParserValueList *);
1279 msset(_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE, WebCore);
1280 if (_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE != NULL)
1281 MSHookFunction(_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE, MSHake(_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE));
1284 + (id) rootViewController {
1285 return [[[self alloc] init] autorelease];
1289 [configuration_ release];
1290 [background_ release];
1291 [foreground_ release];
1296 if ((self = [super init]) != nil) {
1297 configuration_ = [[$CydgetController currentConfiguration] retain];
1298 legacy_ = [configuration_ objectForKey:@"Background"] == nil;
1299 media_ = [[configuration_ objectForKey:@"MediaControls"] boolValue];
1300 items_ = [[configuration_ objectForKey:@"NotificationList"] boolValue];
1305 NSURL *base([NSURL fileURLWithPath:[$CydgetController currentPath]]);
1307 if (NSString *background = [configuration_ objectForKey:@"Background"])
1308 background_ = [[WebCydgetLockScreenView alloc] initWithURL:[NSURL URLWithString:background relativeToURL:base]];
1310 if (NSString *homepage = [configuration_ objectForKey:@"Homepage"]) {
1311 foreground_ = [[WebCydgetLockScreenView alloc] initWithURL:[NSURL URLWithString:homepage relativeToURL:base]];
1312 [self setView:foreground_];
1316 - (void) purgeView {
1317 [background_ removeFromSuperview];
1318 [background_ release];
1320 [foreground_ removeFromSuperview];
1321 [foreground_ release];
1326 - (void) updateStyles {
1327 [foreground_ updateStyles];
1328 [background_ updateStyles];
1331 - (UIView *) backgroundView {
1335 - (BOOL) showAwayItems {
1339 - (BOOL) updateHidden {
1340 if (foreground_ == nil)
1342 bool media(CYHaveMediaControls());
1343 [foreground_ setHidden:media];
1347 - (BOOL) showDateView {
1348 if (kCFCoreFoundationVersionNumber < 800)
1350 [self updateStyles];
1351 if (!legacy_ && foreground_ == nil)
1353 if (!items_ && CYHaveNotificationList())
1358 - (BOOL) allowsLockScreenMediaControls {
1359 if (kCFCoreFoundationVersionNumber < 800)
1364 /*- (BOOL) showHeaderView {
1368 // 0: view is rendered above head
1369 // 1: view moves as one with head
1370 // 2: view moves up and down only
1371 // 3: view simply never does move
1372 - (NSUInteger) presentationStyle {
1381 - (NSUInteger) overlayStyle {
1382 return legacy_ ? 1 : 4;
1385 // 1: blur -> view -> list
1386 // 2: view -> blur -> list
1387 // 3: view. unblur below?!
1388 // 4: blur -> list -> view
1389 - (NSUInteger) notificationBehavior {
1390 return items_ ? 1 : 2;
1393 - (BOOL) viewWantsFullscreenLayout {
1394 return kCFCoreFoundationVersionNumber >= 800;
1397 /*- (BOOL) viewWantsOverlayLayout {
1398 return kCFCoreFoundationVersionNumber >= 800;
1401 - (BOOL) shouldDisableOnUnlock {
1405 - (BOOL) canBeAlwaysFullscreen {
1409 /*- (BOOL) wantsSwipeGestureRecognizer {
1413 - (BOOL) handleGesture:(int)arg1 fingerCount:(NSUInteger)fingers {
1418 // - (void) lockScreenMediaControlsShown:(BOOL)shown;
1420 - (BOOL) handleMenuButtonDoubleTap {
1421 if (kCFCoreFoundationVersionNumber >= 800) {
1422 SBLockScreenViewController *controller([[$SBLockScreenManager sharedInstance] lockScreenViewController]);
1423 [controller _setMediaControlsVisible:![controller isShowingMediaControls]];
1426 return [super handleMenuButtonDoubleTap];
1431 MSClassHook(WebView)
1432 MSMetaClassHook(WebView)
1434 MSClassMessageHook0(void, WebView, enableWebThread) {
1435 if (kCFCoreFoundationVersionNumber >= 478.61)
1438 NSLog(@"-[WebView enableWebThread]");