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