]> git.saurik.com Git - cydget.git/blob - LockScreen.mm
Implement Cydget-specific media/bulletins @media.
[cydget.git] / LockScreen.mm
1 /* Cydget - open-source AwayView plugin multiplexer
2 * Copyright (C) 2009-2014 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
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.
11 *
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.
16 *
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/>.
19 **/
20 /* }}} */
21
22 #include <CydiaSubstrate/CydiaSubstrate.h>
23 #include <UIKit/UIKit.h>
24
25 #include <sys/sysctl.h>
26 #include <pthread.h>
27
28 #include <SpringBoardUI/SBAwayViewPluginController.h>
29
30 #include <WebKit/WebFrame.h>
31 #include <WebKit/WebView.h>
32 #include <WebKit/WebPreferences-WebPrivate.h>
33
34 #include "yieldToSelector.h"
35
36 #ifdef USE_ICU_REGEX
37 #include <unicode/uregex.h>
38 #else
39 #include <pcre.h>
40 #endif
41
42 #define _transient
43 #define _forever for (;;)
44
45 _disused static unsigned trace_;
46
47 #define _trace() do { \
48 NSLog(@"_trace(%u)@%s:%u[%s](%p)\n", \
49 trace_++, __FILE__, __LINE__, __FUNCTION__, pthread_self() \
50 ); \
51 } while (false)
52
53 #define _assert(test) do \
54 if (!(test)) { \
55 NSLog(@"_assert(%d:%s)@%s:%u[%s]\n", errno, #test, __FILE__, __LINE__, __FUNCTION__); \
56 exit(-1); \
57 } \
58 while (false)
59
60 #define _syscall(expr) \
61 do if ((long) (expr) != -1) \
62 break; \
63 else switch (errno) { \
64 case EINTR: \
65 continue; \
66 default: \
67 _assert(false); \
68 } while (true)
69
70 extern "C" UIImage *_UIImageWithName(NSString *name);
71
72 typedef uint16_t UChar;
73
74 @interface TPBottomLockBar
75 - (CGFloat) defaultHeight;
76 @end
77
78 @interface UIApplication (Apple)
79 - (void) applicationOpenURL:(NSURL *)url;
80 @end
81
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;
89 @end
90
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;
116 @end
117
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;
128 @end
129
130 @interface SBLockScreenView : UIView
131 - (BOOL) mediaControlsHidden;
132 @end
133
134 @interface SBLockScreenNotificationListController : NSObject
135 - (BOOL) hasAnyContent;
136 @end
137
138 @interface SBLockScreenViewController : UIViewController
139 - (SBLockScreenView *) lockScreenView;
140 - (BOOL) isShowingMediaControls;
141 - (void) _setMediaControlsVisible:(BOOL)visible;
142 - (SBLockScreenNotificationListController *) _notificationController;
143 @end
144
145 @interface SBLockScreenManager : NSObject
146 + (SBLockScreenManager *) sharedInstance;
147 - (SBLockScreenViewController *) lockScreenViewController;
148 @end
149
150 @protocol CydgetController
151 - (NSDictionary *) currentConfiguration;
152 - (NSString *) currentPath;
153 @end
154
155 static Class $CydgetController(objc_getClass("CydgetController"));
156
157 static bool iOS32, iOS4;
158
159 @interface NSString (UIKit)
160 - (NSString *) stringByAddingPercentEscapes;
161 @end
162
163 @implementation UIWebDocumentView (WebCycript)
164
165 - (void) _setScrollerOffset:(CGPoint)offset {
166 UIScroller *scroller([self _scroller]);
167
168 CGSize size([scroller contentSize]);
169 CGSize bounds([scroller bounds].size);
170
171 CGPoint max;
172 max.x = size.width - bounds.width;
173 max.y = size.height - bounds.height;
174
175 // wtf Apple?!
176 if (max.x < 0)
177 max.x = 0;
178 if (max.y < 0)
179 max.y = 0;
180
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;
183
184 [scroller setOffset:offset];
185 }
186
187 @end
188
189 #ifdef USE_ICU_REGEX
190 /* ICU Regular Expression {{{ */
191 class RegEx {
192 private:
193 URegularExpression *regex_;
194
195 public:
196 RegEx(const char *regex) {
197 UParseError error;
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];
202 }
203
204 ~RegEx() {
205 uregex_close(regex_);
206 }
207
208 bool operator ()(NSString *string) {
209 return operator ()(reinterpret_cast<const uint16_t *>([string cStringUsingEncoding:NSUTF16StringEncoding]), [string length]);
210 }
211
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));
218 return matches;
219 }
220 };
221 /* }}} */
222 #else
223 /* Perl-Compatible RegEx {{{ */
224 class RegEx {
225 private:
226 pcre *code_;
227 pcre_extra *study_;
228 int capture_;
229 int *matches_;
230 const char *data_;
231
232 public:
233 RegEx(const char *regex) :
234 study_(NULL)
235 {
236 const char *error;
237 int offset;
238 code_ = pcre_compile(regex, 0, &error, &offset, NULL);
239
240 if (code_ == NULL)
241 @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"*** RegEx(): [%u] %s", offset, error] userInfo:nil];
242
243 pcre_fullinfo(code_, study_, PCRE_INFO_CAPTURECOUNT, &capture_);
244 matches_ = new int[(capture_ + 1) * 3];
245 }
246
247 ~RegEx() {
248 pcre_free(code_);
249 delete matches_;
250 }
251
252 bool operator ()(NSString *data) {
253 // XXX: length is for characters, not for bytes
254 return operator ()([data UTF8String], [data length]);
255 }
256
257 bool operator ()(const char *data, size_t size) {
258 data_ = data;
259 return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0;
260 }
261 };
262 /* }}} */
263 #endif
264
265 static float CYScrollViewDecelerationRateNormal;
266
267 @interface NSURL (Apple)
268 - (BOOL) isSpringboardHandledURL;
269 @end
270
271 @interface UIScrollView (Apple)
272 - (void) setDecelerationRate:(CGFloat)value;
273 - (void) setScrollingEnabled:(BOOL)enabled;
274 - (void) setShowBackgroundShadow:(BOOL)show;
275 @end
276
277 @interface UIWebView (Apple)
278 - (UIWebDocumentView *) _documentView;
279 - (void) setDataDetectorTypes:(NSInteger)types;
280 - (void) _setDrawInWebThread:(BOOL)draw;
281 - (UIScrollView *) _scrollView;
282 - (UIScroller *) _scroller;
283 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message;
284 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
285 @end
286
287 @interface WebView (Apple)
288 - (void) _setLayoutInterval:(float)interval;
289 - (void) _setAllowsMessaging:(BOOL)allows;
290 - (void) setShouldUpdateWhileOffscreen:(BOOL)update;
291 @end
292
293 @protocol CydgetWebViewDelegate <UIWebViewDelegate>
294 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
295 @end
296
297 @class UIWebViewWebViewDelegate;
298
299 @interface CydgetWebView : UIWebView {
300 }
301
302 @end
303
304 MSClassHook(UIApplication)
305 MSClassHook(SBLockScreenManager)
306
307 MSInstanceMessageHook1(void, UIApplication, openURL, NSURL *, url) {
308 [self applicationOpenURL:url];
309 }
310
311 @implementation NSURL (Cydget)
312
313 - (NSNumber *) cydget$isSpringboardHandledURL {
314 return [NSNumber numberWithBool:[self isSpringboardHandledURL]];
315 }
316
317 @end
318
319 MSClassHook(NSURL)
320
321 MSInstanceMessageHook0(BOOL, NSURL, isSpringboardHandledURL) {
322 if (![NSThread isMainThread])
323 return MSOldCall();
324
325 return [[self cydget$yieldToSelector:@selector(cydget$isSpringboardHandledURL)] boolValue];
326 }
327
328 @implementation CydgetWebView
329
330 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
331 NSObject<CydgetWebViewDelegate> *delegate((NSObject<CydgetWebViewDelegate> *) [self delegate]);
332 if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
333 [delegate webView:view didClearWindowObject:window forFrame:frame];
334 if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)])
335 [super webView:view didClearWindowObject:window forFrame:frame];
336 }
337
338 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
339 NSLog(@"addMessageToConsole:%@", message);
340
341 if ([UIWebView instancesRespondToSelector:@selector(webView:addMessageToConsole:)])
342 [super webView:view addMessageToConsole:message];
343 }
344
345 @end
346
347 @interface WebCydgetLockScreenView : UIView <UIWebViewDelegate> {
348 CydgetWebView *webview_;
349 UIScrollView *scroller_;
350 NSString *cycript_;
351 }
352
353 @end
354
355 @implementation WebCydgetLockScreenView
356
357 //#include "UICaboodle/UCInternal.h"
358
359 - (void) dealloc {
360 [webview_ setDelegate:nil];
361 [webview_ release];
362 [super dealloc];
363 }
364
365 - (void) loadRequest:(NSURLRequest *)request {
366 [webview_ loadRequest:request];
367 }
368
369 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
370 [self loadRequest:[NSURLRequest
371 requestWithURL:url
372 cachePolicy:policy
373 timeoutInterval:30.0
374 ]];
375 }
376
377 - (void) loadURL:(NSURL *)url {
378 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
379 }
380
381 - (id) initWithURL:(NSURL *)url {
382 CGRect frame = [[UIScreen mainScreen] bounds];
383 if (kCFCoreFoundationVersionNumber < 800)
384 frame.size.height -= 20; //[[[$SBStatusBarController sharedStatusBarController] statusBarView] frame].size.height;
385
386 if ((self = [super initWithFrame:frame]) != nil) {
387 CGRect bounds([self bounds]);
388 if (kCFCoreFoundationVersionNumber < 800)
389 bounds.size.height -= [TPBottomLockBar defaultHeight];
390
391 webview_ = [[CydgetWebView alloc] initWithFrame:bounds];
392 [webview_ setDelegate:self];
393 [self addSubview:webview_];
394
395 if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
396 [webview_ setDataDetectorTypes:0x80000000];
397 else
398 [webview_ setDetectsPhoneNumbers:NO];
399
400 [webview_ setScalesPageToFit:YES];
401
402 if (kCFCoreFoundationVersionNumber < 478.61)
403 if ([webview_ respondsToSelector:@selector(_setDrawInWebThread:)])
404 [webview_ _setDrawInWebThread:NO];
405
406 UIWebDocumentView *document([webview_ _documentView]);
407 WebView *webview([document webView]);
408 WebPreferences *preferences([webview preferences]);
409
410 [document setTileSize:CGSizeMake(bounds.size.width, 500)];
411
412 [document setBackgroundColor:[UIColor clearColor]];
413 [document setDrawsBackground:NO];
414
415 [webview setPreferencesIdentifier:@"WebCycript"];
416
417 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
418 [webview _setLayoutInterval:0];
419 else
420 [preferences _setLayoutInterval:0];
421
422 [preferences setCacheModel:WebCacheModelDocumentViewer];
423 [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
424 [preferences setOfflineWebApplicationCacheEnabled:YES];
425
426 if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)])
427 [webview setShouldUpdateWhileOffscreen:NO];
428
429 if ([document respondsToSelector:@selector(setAllowsMessaging:)])
430 [document setAllowsMessaging:YES];
431 if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
432 [webview _setAllowsMessaging:YES];
433
434 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
435 scroller_ = [webview_ _scrollView];
436
437 [scroller_ setDirectionalLockEnabled:YES];
438 [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
439 [scroller_ setDelaysContentTouches:NO];
440
441 [scroller_ setCanCancelContentTouches:YES];
442
443 [scroller_ setAlwaysBounceVertical:NO];
444 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
445 UIScroller *scroller([webview_ _scroller]);
446 scroller_ = (UIScrollView *) scroller;
447
448 [scroller setDirectionalScrolling:YES];
449 [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
450 [scroller setScrollHysteresis:0]; /* 8 */
451
452 [scroller setThumbDetectionEnabled:NO];
453 }
454
455 [webview_ setOpaque:NO];
456 [webview_ setBackgroundColor:[UIColor clearColor]];
457
458 [scroller_ setFixedBackgroundPattern:YES];
459 [scroller_ setBackgroundColor:[UIColor clearColor]];
460 [scroller_ setClipsSubviews:NO];
461
462 [scroller_ setBounces:YES];
463 [scroller_ setShowBackgroundShadow:NO]; /* YES */
464
465 [self setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
466 [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
467
468 NSDictionary *configuration([$CydgetController currentConfiguration]);
469 cycript_ = [configuration objectForKey:@"CycriptURLs"];
470
471 [scroller_ setScrollingEnabled:[[configuration objectForKey:@"Scrollable"] boolValue]];
472
473 [self loadURL:url];
474 } return self;
475 }
476
477 - (void) webView:(WebView *)webview didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
478 if (cycript_ != nil)
479 if (NSString *href = [[[[frame dataSource] request] URL] absoluteString])
480 if (RegEx([cycript_ UTF8String])(href))
481 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
482 if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CydgetSetupContext"))) {
483 WebFrame *frame([webview mainFrame]);
484 JSGlobalContextRef context([frame globalContext]);
485 @try {
486 CYSetupContext(context);
487 } @catch (NSException *e) {
488 NSLog(@"*** CydgetSetupContext => %@", e);
489 }
490 }
491 }
492
493 @end
494
495 @interface WebCycriptLockScreenController : SBAwayViewPluginController {
496 NSDictionary *configuration_;
497 WebCydgetLockScreenView *background_;
498 WebCydgetLockScreenView *foreground_;
499 }
500
501 @end
502
503 #include <string>
504
505 struct State {
506 unsigned state;
507 };
508
509 namespace JSC {
510 class JSGlobalData;
511 class UString;
512 }
513
514 namespace WebCore {
515 class KURL;
516 }
517
518 namespace WebCore {
519 struct String {
520 void *impl_;
521 }; }
522
523 namespace JSC {
524 struct SourceCode {
525 void *provider_;
526 int start_;
527 int end_;
528 int line_;
529 }; }
530
531 namespace JSC {
532 union ScriptSourceCode {
533 struct {
534 JSC::SourceCode source_;
535 } Old;
536 struct {
537 void *provider_;
538 JSC::SourceCode source_;
539 } New;
540 }; }
541
542 // String Helpers {{{
543 static const UChar *(*_ZNK7WebCore6String10charactersEv)(const WebCore::String *);
544 static const UChar *(*_ZN7WebCore6String29charactersWithNullTerminationEv)(const WebCore::String *);
545 static unsigned (*_ZNK7WebCore6String6lengthEv)(const WebCore::String *);
546
547 static bool StringGet(const WebCore::String &string, const UChar *&data, size_t &length) {
548 bool terminated;
549
550 if (_ZNK7WebCore6String10charactersEv != NULL) {
551 data = (*_ZNK7WebCore6String10charactersEv)(&string);
552 terminated = false;
553 } else if (_ZN7WebCore6String29charactersWithNullTerminationEv != NULL) {
554 data = (*_ZN7WebCore6String29charactersWithNullTerminationEv)(&string);
555 terminated = true;
556 } else return false;
557
558 if (data == NULL)
559 return false;
560
561 if (_ZNK7WebCore6String6lengthEv != NULL)
562 length = (*_ZNK7WebCore6String6lengthEv)(&string);
563 else if (terminated)
564 for (length = 0; data[length] != 0; ++length);
565 else return false;
566
567 return true;
568 }
569
570 static bool StringEquals(const WebCore::String &string, const char *value) {
571 const UChar *data;
572 size_t size;
573 if (!StringGet(string, data, size))
574 return false;
575
576 size_t length(strlen(value));
577 if (size != length)
578 return false;
579
580 for (size_t index(0); index != length; ++index)
581 if (data[index] != value[index])
582 return false;
583
584 return true;
585 }
586 // }}}
587 // State Machine {{{
588 static bool cycript_;
589
590 MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) {
591 if (!StringEquals(mime, "text/cycript")) {
592 cycript_ = false;
593 return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime);
594 }
595
596 static void *handle(dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL));
597 if (handle == NULL)
598 return false;
599
600 cycript_ = true;
601 return true;
602 }
603 // }}}
604 // Script Compiler {{{
605 static void Log(const WebCore::String &string) {
606 #if 0
607 const UChar *data;
608 size_t length;
609 if (!StringGet(string, data, length))
610 return;
611
612 UChar terminated[length + 1];
613 terminated[length] = 0;
614 memcpy(terminated, data, length * 2);
615 NSLog(@"wtf %p:%zu:%S:", &string, length, terminated);
616 #endif
617 }
618
619 static bool Cycriptify(const uint16_t *&data, size_t &size) {
620 cycript_ = false;
621
622 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
623 if (void (*CydgetMemoryParse)(const uint16_t **, size_t *) = reinterpret_cast<void (*)(const uint16_t **, size_t *)>(dlsym(handle, "CydgetMemoryParse"))) @try {
624 CydgetMemoryParse(&data, &size);
625 return true;
626 } @catch (NSException *e) {
627 NSLog(@"*** CydgetMemoryParse => %@", e);
628 }
629 return false;
630 }
631
632 static void (*_ZN7WebCore6String6appendEPKtj)(WebCore::String *, const UChar *, unsigned);
633 static void (*_ZN7WebCore6String8truncateEj)(WebCore::String *, unsigned);
634
635 static void Cycriptify(const WebCore::String &source, int *psize = NULL) {
636 if (!cycript_)
637 return;
638 cycript_ = false;
639
640 const UChar *data;
641 size_t length;
642 if (!StringGet(source, data, length))
643 return;
644
645 size_t size(length);
646 if (!Cycriptify(data, size))
647 return;
648
649 WebCore::String &script(const_cast<WebCore::String &>(source));
650 _ZN7WebCore6String8truncateEj(&script, 0);
651 _ZN7WebCore6String6appendEPKtj(&script, data, size);
652
653 if (psize != NULL)
654 *psize = size;
655
656 free((void *) data);
657
658 Log(source);
659 }
660 // }}}
661
662 static WebCore::String *string;
663
664 // iOS 2.x
665 MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, void *_this, const WebCore::String &string, State state, const WebCore::String &url, int line) {
666 Cycriptify(string);
667 return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i(_this, string, state, url, line);
668 }
669
670 // iOS 3.x
671 MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::SourceCode **_this, JSC::JSGlobalData *global, int *line, JSC::UString *message) {
672 /*if (cycript_) {
673 JSC::SourceCode *source(_this[iOS32 ? 6 : 0]);
674 const uint16_t *data(source->data());
675 size_t size(source->length());
676
677 if (Cycriptify(data, size)) {
678 source->~SourceCode();
679 // XXX: I actually don't have the original URL here: pants
680 new (source) JSC::SourceCode(JSC::UStringSourceProvider::create(JSC::UString(data, size), "cycript://"), 1);
681 free((void *) data);
682 }
683 }*/
684
685 return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message);
686 }
687
688 // iOS 3.x cdata
689 MSHook(const WebCore::String &, _ZNK7WebCore4Node11textContentEb, void *_this, bool convert) {
690 const WebCore::String &code(__ZNK7WebCore4Node11textContentEb(_this, convert));
691 string = const_cast<WebCore::String *>(&code);
692 Log(code);
693 Cycriptify(code);
694 return code;
695 }
696
697 // iOS 4.x cdata
698 MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, void *_this, const WebCore::String &source, const WebCore::KURL &url, int line) {
699 Cycriptify(source);
700 return __ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi(_this, source, url, line);
701 }
702
703 // iOS 4.x+5.0 @src=
704 MSHook(const WebCore::String &, _ZN7WebCore12CachedScript6scriptEv, void *_this) {
705 const WebCore::String &script(__ZN7WebCore12CachedScript6scriptEv(_this));
706 string = const_cast<WebCore::String *>(&script);
707 Log(script);
708 return script;
709 }
710
711 // iOS 4.x @src=
712 MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, void *_this, JSC::ScriptSourceCode &script, State state) {
713 if (string != NULL) {
714 JSC::SourceCode *source(iOS4 ? &script.New.source_ : &script.Old.source_);
715 Cycriptify(*string, &source->end_);
716 string = NULL;
717 }
718
719 return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE(_this, script, state);
720 }
721
722 // iOS 5.0 cdata
723 MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE, void *_this, const WebCore::String &source, const WebCore::KURL &url, void *position) {
724 Cycriptify(source);
725 return __ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE(_this, source, url, position);
726 }
727
728 // iOS 5.0 @src=
729 MSHook(void, _ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE, void *_this, void *position, int legacy) {
730 string = NULL;
731 return __ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE(_this, position, legacy);
732 }
733
734 void (*$_ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE)(void *_this, int legacy);
735
736 // iOS 5.0 @src=
737 MSHook(void, _ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE, void *_this, JSC::ScriptSourceCode &script) {
738 if (string != NULL) {
739 JSC::SourceCode *source(&script.New.source_);
740 $_ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE(_this, 0);
741 Cycriptify(*string, &source->end_);
742 string = NULL;
743 }
744
745 return __ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE(_this, script);
746 }
747
748 // iOS 6.0 cdata
749 MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, void *_this, const WebCore::String &source, const WebCore::KURL &url, void *position) {
750 Cycriptify(source);
751 return __ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE(_this, source, url, position);
752 }
753
754 // iOS 6.0 @src=
755 MSHook(void, _ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE, void *_this, void *position, int legacy) {
756 string = NULL;
757 return __ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE(_this, position, legacy);
758 }
759
760 /* Cydget:// Protocol {{{ */
761 @interface CydgetURLProtocol : NSURLProtocol {
762 }
763
764 @end
765
766 @implementation CydgetURLProtocol
767
768 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
769 NSURL *url([request URL]);
770 if (url == nil)
771 return NO;
772 NSString *scheme([[url scheme] lowercaseString]);
773 if (scheme == nil || ![scheme isEqualToString:@"cydget"])
774 return NO;
775 return YES;
776 }
777
778 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
779 return request;
780 }
781
782 - (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request {
783 id<NSURLProtocolClient> client([self client]);
784 if (icon == nil)
785 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
786 else {
787 NSData *data(UIImagePNGRepresentation(icon));
788
789 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]);
790 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
791 [client URLProtocol:self didLoadData:data];
792 [client URLProtocolDidFinishLoading:self];
793 }
794 }
795
796 - (void) startLoading {
797 id<NSURLProtocolClient> client([self client]);
798 NSURLRequest *request([self request]);
799
800 NSURL *url([request URL]);
801 NSString *href([url absoluteString]);
802
803 NSString *path([href substringFromIndex:9]);
804 NSRange slash([path rangeOfString:@"/"]);
805
806 NSString *command;
807 if (slash.location == NSNotFound) {
808 command = path;
809 path = nil;
810 } else {
811 command = [path substringToIndex:slash.location];
812 path = [path substringFromIndex:(slash.location + 1)];
813 }
814
815 if ([command isEqualToString:@"_UIImageWithName"]) {
816 if (path == nil)
817 goto fail;
818 path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
819 UIImage *icon(_UIImageWithName(path));
820 [self _returnPNGWithImage:icon forRequest:request];
821 } else fail: {
822 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
823 }
824 }
825
826 - (void) stopLoading {
827 }
828
829 @end
830 /* }}} */
831 /* Cydget-CGI:// Protocol {{{ */
832 @interface CydgetCGIURLProtocol : NSURLProtocol {
833 pid_t pid_;
834 CFHTTPMessageRef http_;
835 NSFileHandle *handle_;
836 }
837
838 @end
839
840 @implementation CydgetCGIURLProtocol
841
842 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
843 NSURL *url([request URL]);
844 if (url == nil)
845 return NO;
846 NSString *scheme([[url scheme] lowercaseString]);
847 if (scheme == nil || ![scheme isEqualToString:@"cydget-cgi"])
848 return NO;
849 return YES;
850 }
851
852 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
853 return request;
854 }
855
856 - (id) initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)response client:(id<NSURLProtocolClient>)client {
857 if ((self = [super initWithRequest:request cachedResponse:response client:client]) != nil) {
858 pid_ = -1;
859 } return self;
860 }
861
862 - (void) startLoading {
863 id<NSURLProtocolClient> client([self client]);
864 NSURLRequest *request([self request]);
865 NSURL *url([request URL]);
866
867 NSString *path([url path]);
868 if (path == nil) {
869 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
870 return;
871 }
872
873 NSFileManager *manager([NSFileManager defaultManager]);
874 if (![manager fileExistsAtPath:path]) {
875 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
876 return;
877 }
878
879 int fds[2];
880 _assert(pipe(fds) != -1);
881
882 _assert(pid_ == -1);
883 pid_ = fork();
884 if (pid_ == -1) {
885 _assert(close(fds[0]) != -1);
886 _assert(close(fds[1]) != -1);
887 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
888 return;
889 }
890
891 if (pid_ == 0) {
892 const char *script([path UTF8String]);
893
894 setenv("GATEWAY_INTERFACE", "CGI/1.1", true);
895 setenv("SCRIPT_FILENAME", script, true);
896 NSString *query([url query]);
897 if (query != nil)
898 setenv("QUERY_STRING", [query UTF8String], true);
899
900 _assert(dup2(fds[1], 1) != -1);
901 _assert(close(fds[0]) != -1);
902 _assert(close(fds[1]) != -1);
903
904 execl(script, script, NULL);
905 exit(1);
906 _assert(false);
907 }
908
909 _assert(close(fds[1]) != -1);
910
911 _assert(http_ == NULL);
912 http_ = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE);
913 CFHTTPMessageAppendBytes(http_, (const uint8_t *) "HTTP/1.1 200 OK\r\n", 17);
914
915 _assert(handle_ == nil);
916 handle_ = [[NSFileHandle alloc] initWithFileDescriptor:fds[0] closeOnDealloc:YES];
917
918 [[NSNotificationCenter defaultCenter]
919 addObserver:self
920 selector:@selector(onRead:)
921 name:@"NSFileHandleReadCompletionNotification"
922 object:handle_
923 ];
924
925 [handle_ readInBackgroundAndNotify];
926 }
927
928 - (void) onRead:(NSNotification *)notification {
929 NSFileHandle *handle([notification object]);
930
931 NSData *data([[notification userInfo] objectForKey:NSFileHandleNotificationDataItem]);
932
933 if (size_t length = [data length]) {
934 CFHTTPMessageAppendBytes(http_, reinterpret_cast<const UInt8 *>([data bytes]), length);
935 [handle readInBackgroundAndNotify];
936 } else {
937 id<NSURLProtocolClient> client([self client]);
938
939 CFStringRef mime(CFHTTPMessageCopyHeaderFieldValue(http_, CFSTR("Content-type")));
940 if (mime == NULL)
941 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]];
942 else {
943 NSURLRequest *request([self request]);
944
945 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:(NSString *)mime expectedContentLength:-1 textEncodingName:nil] autorelease]);
946 CFRelease(mime);
947
948 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
949
950 CFDataRef body(CFHTTPMessageCopyBody(http_));
951 [client URLProtocol:self didLoadData:(NSData *)body];
952 CFRelease(body);
953
954 [client URLProtocolDidFinishLoading:self];
955 }
956
957 CFRelease(http_);
958 http_ = NULL;
959 }
960 }
961
962 //[client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNetworkConnectionLost userInfo:nil]];
963
964 - (void) stopLoading_ {
965 [[NSNotificationCenter defaultCenter] removeObserver:self];
966
967 if (handle_ != nil) {
968 [handle_ release];
969 handle_ = nil;
970 }
971
972 if (pid_ != -1) {
973 kill(pid_, SIGTERM);
974 int status;
975 _syscall(waitpid(pid_, &status, 0));
976 pid_ = -1;
977 }
978 }
979
980 - (void) stopLoading {
981 [self
982 performSelectorOnMainThread:@selector(stopLoading_)
983 withObject:nil
984 waitUntilDone:NO
985 ];
986 }
987
988 @end
989 /* }}} */
990
991 namespace WebCore {
992 class MediaQueryEvaluator;
993 class CSSParserValueList;
994 }
995
996 namespace WebCore {
997 struct MediaQueryExp {
998 String feature_;
999 void *value_;
1000 bool valid_;
1001 String cache_;
1002 }; }
1003
1004 MSHook(bool, _ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE, WebCore::MediaQueryEvaluator *_this, WebCore::String &query) {
1005 Log(query); if (false) {
1006 } else if (kCFCoreFoundationVersionNumber >= 800 && StringEquals(query, "cydget-media-controls")) {
1007 SBLockScreenView *view([[[$SBLockScreenManager sharedInstance] lockScreenViewController] lockScreenView]);
1008 return view != nil && ![view mediaControlsHidden];
1009 //return [[[$SBLockScreenManager sharedInstance] lockScreenViewController] isShowingMediaControls];
1010 } else if (kCFCoreFoundationVersionNumber >= 800 && StringEquals(query, "cydget-notification-list")) {
1011 SBLockScreenNotificationListController *controller([[[$SBLockScreenManager sharedInstance] lockScreenViewController] _notificationController]);
1012 return controller != nil && [controller hasAnyContent];
1013 } else
1014 return __ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE(_this, query);
1015 }
1016
1017 MSHook(void, _ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE, WebCore::MediaQueryExp *_this, WebCore::String &query, WebCore::CSSParserValueList *values) {
1018 Log(query);
1019 __ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE(_this, query, values);
1020 if (!_this->valid_) if (
1021 StringEquals(query, "cydget-media-controls") ||
1022 StringEquals(query, "cydget-notification-list") ||
1023 false) _this->valid_ = true;
1024 }
1025
1026 template <typename Type_>
1027 static void dlset(Type_ &function, const char *name) {
1028 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1029 }
1030
1031 template <typename Type_>
1032 static void msset_(Type_ &function, const char *name, MSImageRef handle) {
1033 function = reinterpret_cast<Type_>(MSFindSymbol(handle, name));
1034 }
1035
1036 #define msset(function, handle) \
1037 msset_(function, "_" #function, handle)
1038
1039 @implementation WebCycriptLockScreenController
1040
1041 static void $UIWebViewWebViewDelegate$webView$addMessageToConsole$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *message) {
1042 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
1043 if ([uiWebView respondsToSelector:@selector(webView:addMessageToConsole:)])
1044 [uiWebView webView:view addMessageToConsole:message];
1045 }
1046
1047 static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) {
1048 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
1049 if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
1050 [uiWebView webView:view didClearWindowObject:window forFrame:frame];
1051 }
1052
1053 + (void) initialize {
1054 if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) {
1055 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12");
1056 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16");
1057 }
1058
1059 if (CGFloat *_UIScrollViewDecelerationRateNormal = reinterpret_cast<CGFloat *>(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal")))
1060 CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal;
1061 else // XXX: this actually might be fast on some older systems: we should look into this
1062 CYScrollViewDecelerationRateNormal = 0.998;
1063
1064 iOS4 = kCFCoreFoundationVersionNumber >= 550.32;
1065 iOS32 = !iOS4 && kCFCoreFoundationVersionNumber >= 478.61;
1066
1067 int maxproc;
1068 size_t size(sizeof(maxproc));
1069 if (sysctlbyname("kern.maxproc", &maxproc, &size, NULL, 0) == -1)
1070 NSLog(@"sysctlbyname(\"kern.maxproc\", ?)");
1071 else if (maxproc < 72) {
1072 maxproc = 72;
1073 if (sysctlbyname("kern.maxproc", NULL, NULL, &maxproc, sizeof(maxproc)) == -1)
1074 NSLog(@"sysctlbyname(\"kern.maxproc\", #)");
1075 }
1076
1077 [NSURLProtocol registerClass:[CydgetURLProtocol class]];
1078 [WebView registerURLSchemeAsLocal:@"cydget"];
1079
1080 [NSURLProtocol registerClass:[CydgetCGIURLProtocol class]];
1081 [WebView registerURLSchemeAsLocal:@"cydget-cgi"];
1082
1083 MSImageRef JavaScriptCore(MSGetImageByName("/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore"));
1084 MSImageRef WebCore(MSGetImageByName("/System/Library/PrivateFrameworks/WebCore.framework/WebCore"));
1085
1086 if (!iOS4) {
1087 void (*_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)(JSC::SourceCode **, JSC::JSGlobalData *, int *, JSC::UString *);
1088 dlset(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, "_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE");
1089 if (_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE != NULL)
1090 MSHookFunction(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE));
1091 }
1092
1093 bool (*_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)(const WebCore::String &) = NULL;
1094 if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE == NULL)
1095 MSHookSymbol(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE", WebCore);
1096 if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE == NULL)
1097 MSHookSymbol(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKN3WTF6StringE", WebCore);
1098 if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE != NULL)
1099 MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE));
1100
1101 void (*_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi)(void *, const WebCore::String &, const WebCore::KURL &, int) = NULL;
1102 if (_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi == NULL)
1103 MSHookSymbol(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, "__ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi", WebCore);
1104 if (_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi != NULL)
1105 MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi));
1106
1107 if (!iOS4) {
1108 const WebCore::String &(*_ZNK7WebCore4Node11textContentEb)(void *, bool) = NULL;
1109 if (_ZNK7WebCore4Node11textContentEb == NULL)
1110 MSHookSymbol(_ZNK7WebCore4Node11textContentEb, "__ZNK7WebCore4Node11textContentEb", WebCore);
1111 if (_ZNK7WebCore4Node11textContentEb != NULL)
1112 MSHookFunction(_ZNK7WebCore4Node11textContentEb, MSHake(_ZNK7WebCore4Node11textContentEb));
1113 }
1114
1115 const WebCore::String &(*_ZN7WebCore12CachedScript6scriptEv)(void *) = NULL;
1116 if (_ZN7WebCore12CachedScript6scriptEv == NULL)
1117 MSHookSymbol(_ZN7WebCore12CachedScript6scriptEv, "__ZN7WebCore12CachedScript6scriptEv", WebCore);
1118 if (_ZN7WebCore12CachedScript6scriptEv != NULL)
1119 MSHookFunction(_ZN7WebCore12CachedScript6scriptEv, MSHake(_ZN7WebCore12CachedScript6scriptEv));
1120
1121 State (*_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i)(void *, const WebCore::String &, State, const WebCore::String &, int) = NULL;
1122 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i == NULL)
1123 MSHookSymbol(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i", WebCore);
1124 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i != NULL)
1125 MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i));
1126
1127 State (*_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE)(void *, JSC::ScriptSourceCode &, State) = NULL;
1128 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE == NULL)
1129 MSHookSymbol(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE", WebCore);
1130 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE != NULL)
1131 MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE));
1132
1133 void (*_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE)(void *, const WebCore::String &, const WebCore::KURL &, void *);
1134 msset(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE, WebCore);
1135 if (_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE != NULL)
1136 MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE));
1137
1138 void (*_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE)(void *, const WebCore::String &, const WebCore::KURL &, void *);
1139 msset(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, WebCore);
1140 if (_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE != NULL)
1141 MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE));
1142
1143 void (*_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE)(void *, void *, int);
1144 msset(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE, WebCore);
1145 if (_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE != NULL)
1146 MSHookFunction(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE, MSHake(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE));
1147
1148 void (*_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE)(void *, void *, int);
1149 msset(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE, WebCore);
1150 if (_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE != NULL)
1151 MSHookFunction(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE, MSHake(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE));
1152
1153 MSHookSymbol($_ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE, "__ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE", WebCore);
1154
1155 void (*_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE)(void *, JSC::ScriptSourceCode &);
1156 msset(_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE, WebCore);
1157 if (_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE != NULL)
1158 MSHookFunction(_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE, MSHake(_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE));
1159
1160 if (_ZN7WebCore6String6appendEPKtj == NULL)
1161 MSHookSymbol(_ZN7WebCore6String6appendEPKtj, "__ZN7WebCore6String6appendEPKtj", WebCore);
1162 if (_ZN7WebCore6String6appendEPKtj == NULL)
1163 msset(_ZN7WebCore6String6appendEPKtj, JavaScriptCore);
1164 if (_ZN7WebCore6String6appendEPKtj == NULL)
1165 MSHookSymbol(_ZN7WebCore6String6appendEPKtj, "__ZN3WTF6String6appendEPKtj", JavaScriptCore);
1166
1167 if (_ZN7WebCore6String8truncateEj == NULL)
1168 MSHookSymbol(_ZN7WebCore6String8truncateEj, "__ZN7WebCore6String8truncateEj", WebCore);
1169 if (_ZN7WebCore6String8truncateEj == NULL)
1170 msset(_ZN7WebCore6String8truncateEj, JavaScriptCore);
1171 if (_ZN7WebCore6String8truncateEj == NULL)
1172 MSHookSymbol(_ZN7WebCore6String8truncateEj, "__ZN3WTF6String8truncateEj", JavaScriptCore);
1173
1174 msset(_ZNK7WebCore6String10charactersEv, WebCore);
1175
1176 msset(_ZN7WebCore6String29charactersWithNullTerminationEv, JavaScriptCore);
1177 if (_ZN7WebCore6String29charactersWithNullTerminationEv == NULL)
1178 MSHookSymbol(_ZN7WebCore6String29charactersWithNullTerminationEv, "__ZN3WTF6String29charactersWithNullTerminationEv", JavaScriptCore);
1179
1180 msset(_ZNK7WebCore6String6lengthEv, WebCore);
1181
1182 bool (*_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE)(WebCore::MediaQueryEvaluator *, WebCore::String &);
1183 msset(_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE, WebCore);
1184 if (_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE != NULL)
1185 MSHookFunction(_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE, MSHake(_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE));
1186
1187 void (*_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE)(WebCore::MediaQueryExp *, WebCore::String &, WebCore::CSSParserValueList *);
1188 msset(_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE, WebCore);
1189 if (_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE != NULL)
1190 MSHookFunction(_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE, MSHake(_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE));
1191 }
1192
1193 + (id) rootViewController {
1194 return [[[self alloc] init] autorelease];
1195 }
1196
1197 - (void) dealloc {
1198 [configuration_ release];
1199 [background_ release];
1200 [super dealloc];
1201 }
1202
1203 - (id) init {
1204 if ((self = [super init]) != nil) {
1205 configuration_ = [[$CydgetController currentConfiguration] retain];
1206 } return self;
1207 }
1208
1209 - (void) loadView {
1210 NSURL *base([NSURL fileURLWithPath:[$CydgetController currentPath]]);
1211
1212 if (NSString *background = [configuration_ objectForKey:@"Background"])
1213 background_ = [[WebCydgetLockScreenView alloc] initWithURL:[NSURL URLWithString:background relativeToURL:base]];
1214
1215 if (NSString *homepage = [configuration_ objectForKey:@"Homepage"]) {
1216 foreground_ = [[WebCydgetLockScreenView alloc] initWithURL:[NSURL URLWithString:homepage relativeToURL:base]];
1217 [self setView:foreground_];
1218 } else if (kCFCoreFoundationVersionNumber < 800 && background_ != nil) {
1219 [self setView:[background_ autorelease]];
1220 background_ = nil;
1221 }
1222 }
1223
1224 - (void) purgeView {
1225 [background_ removeFromSuperview];
1226 [background_ release];
1227 background_ = nil;
1228 [foreground_ removeFromSuperview];
1229 [foreground_ release];
1230 foreground_ = nil;
1231 [super purgeView];
1232 }
1233
1234 - (UIView *) backgroundView {
1235 return background_;
1236 }
1237
1238 - (BOOL) showAwayItems {
1239 return YES;
1240 }
1241
1242 - (BOOL) updateHidden {
1243 if (foreground_ == nil)
1244 return true;
1245 SBLockScreenViewController *controller([[$SBLockScreenManager sharedInstance] lockScreenViewController]);
1246 SBLockScreenView *view([controller lockScreenView]);
1247 bool media(view != nil && ![view mediaControlsHidden]);
1248 [foreground_ setHidden:media];
1249 return media;
1250 }
1251
1252 - (BOOL) showDateView {
1253 bool homepage([configuration_ objectForKey:@"Homepage"] != nil);
1254 if (kCFCoreFoundationVersionNumber < 800)
1255 return !homepage;
1256 else if (!homepage)
1257 return true;
1258 return [self updateHidden];
1259 }
1260
1261 - (BOOL) allowsLockScreenMediaControls {
1262 if (kCFCoreFoundationVersionNumber < 800)
1263 return true;
1264 if (background_ == nil)
1265 return false;
1266 [self updateHidden];
1267 return true;
1268 }
1269
1270 /*- (BOOL) showHeaderView {
1271 return YES;
1272 }*/
1273
1274 // 1-3
1275 - (NSUInteger) presentationStyle {
1276 return 1;
1277 }
1278
1279 // 1-5
1280 - (NSUInteger) overlayStyle {
1281 if ([configuration_ objectForKey:@"Background"] == nil)
1282 return 1;
1283 return 4;
1284 }
1285
1286 // 1-[2/3?]
1287 - (NSUInteger) notificationBehavior {
1288 return 1;
1289 }
1290
1291 - (BOOL) viewWantsFullscreenLayout {
1292 return kCFCoreFoundationVersionNumber >= 800;
1293 }
1294
1295 /*- (BOOL) viewWantsOverlayLayout {
1296 return kCFCoreFoundationVersionNumber >= 800;
1297 }*/
1298
1299 - (BOOL) shouldDisableOnUnlock {
1300 return YES;
1301 }
1302
1303 - (BOOL) canBeAlwaysFullscreen {
1304 return YES;
1305 }
1306
1307 /*- (BOOL) wantsSwipeGestureRecognizer {
1308 return YES;
1309 }
1310
1311 - (BOOL) handleGesture:(int)arg1 fingerCount:(NSUInteger)fingers {
1312 return NO;
1313 return YES;
1314 }*/
1315
1316 // - (void) lockScreenMediaControlsShown:(BOOL)shown;
1317
1318 - (BOOL) handleMenuButtonDoubleTap {
1319 if (kCFCoreFoundationVersionNumber >= 800) {
1320 SBLockScreenViewController *controller([[$SBLockScreenManager sharedInstance] lockScreenViewController]);
1321 [controller _setMediaControlsVisible:![controller isShowingMediaControls]];
1322 [self updateHidden];
1323 }
1324
1325 return [super handleMenuButtonDoubleTap];
1326 }
1327
1328 @end
1329
1330 MSClassHook(WebView)
1331 MSMetaClassHook(WebView)
1332
1333 MSClassMessageHook0(void, WebView, enableWebThread) {
1334 if (kCFCoreFoundationVersionNumber >= 478.61)
1335 return MSOldCall();
1336
1337 NSLog(@"-[WebView enableWebThread]");
1338 }