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