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