X-Git-Url: https://git.saurik.com/cydget.git/blobdiff_plain/f4203e18e6cb7a9a435bbed0b63ef94c77c36881..672fa884bee5352a88404de7015b608ad83015a0:/LockScreen.mm diff --git a/LockScreen.mm b/LockScreen.mm index f1457da..56999ca 100644 --- a/LockScreen.mm +++ b/LockScreen.mm @@ -1,5 +1,5 @@ -/* CydgetScript - open-source IntelliDial replacement - * Copyright (C) 2009 Jay Freeman (saurik) +/* Cydget - open-source AwayView plugin multiplexer + * Copyright (C) 2009-2011 Jay Freeman (saurik) */ /* @@ -78,22 +78,14 @@ extern NSString * const kCAFilterNearest; #include #include -@interface WebView (UICaboodle) -- (void) setScriptDebugDelegate:(id)delegate; -- (void) _setFormDelegate:(id)delegate; -- (void) _setUIKitDelegate:(id)delegate; -- (void) setWebMailDelegate:(id)delegate; -- (void) _setLayoutInterval:(float)interval; -@end - #define _transient #define _forever for (;;) _disused static unsigned trace_; #define _trace() do { \ - NSLog(@"_trace(%u)@%s:%u[%s]\n", \ - trace_++, __FILE__, __LINE__, __FUNCTION__\ + NSLog(@"_trace(%u)@%s:%u[%s](%p)\n", \ + trace_++, __FILE__, __LINE__, __FUNCTION__, pthread_self() \ ); \ } while (false) @@ -119,11 +111,8 @@ while (false) @end static Class $CydgetController(objc_getClass("CydgetController")); -static Class $UIFormAssistant(objc_getClass("UIFormAssistant")); -//static Class $SBStatusBarController(objc_getClass("SBStatusBarController")); -static Class $UIWebBrowserView; -static bool Wildcat_, iOS4; +static bool iOS32, iOS4; @interface NSString (UIKit) - (NSString *) stringByAddingPercentEscapes; @@ -199,127 +188,63 @@ class Pcre { } }; /* }}} */ -/* WebCycript Delegate {{{ */ -@interface WebCycriptDelegate : NSObject { - _transient volatile id delegate_; -} - -- (void) setDelegate:(id)delegate; -- (id) initWithDelegate:(id)delegate; -@end - -@implementation WebCycriptDelegate -- (void) setDelegate:(id)delegate { - delegate_ = delegate; -} +static float CYScrollViewDecelerationRateNormal; -- (id) initWithDelegate:(id)delegate { - delegate_ = delegate; - return self; -} +@interface UIScrollView (Apple) +- (void) setDecelerationRate:(float)value; +- (void) setScrollingEnabled:(BOOL)enabled; +@end -- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didClearWindowObject:window forFrame:frame]; -} +@interface UIWebView (Apple) +- (void) setDataDetectorTypes:(int)types; +- (UIScrollView *) _scrollView; +- (UIScroller *) _scroller; +- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message; +- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame; +@end -- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didCommitLoadForFrame:frame]; -} +@interface WebView (Apple) +- (void) _setLayoutInterval:(float)interval; +- (void) _setAllowsMessaging:(BOOL)allows; +- (void) setShouldUpdateWhileOffscreen:(BOOL)update; +@end -- (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didFailLoadWithError:error forFrame:frame]; -} +@protocol CydgetWebViewDelegate // +- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame; +@end -- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didFailProvisionalLoadWithError:error forFrame:frame]; -} +@class UIWebViewWebViewDelegate; -- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didFinishLoadForFrame:frame]; +@interface CydgetWebView : UIWebView { } -/*- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didReceiveTitle:title forFrame:frame]; -}*/ - -- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didStartProvisionalLoadForFrame:frame]; -} +@end -/*- (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source { - if (delegate_ != nil) - return [delegate_ webView:sender resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source]; -}*/ - -/*- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source { - if (delegate_ != nil) - return [delegate_ webView:sender resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:source]; - return nil; -}*/ - -- (IMP) methodForSelector:(SEL)sel { - if (IMP method = [super methodForSelector:sel]) - return method; - fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel)); - return NULL; -} +@implementation CydgetWebView -- (BOOL) respondsToSelector:(SEL)sel { - if ([super respondsToSelector:sel]) - return YES; - // XXX: WebThreadCreateNSInvocation returns nil - //fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel)); - return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel]; +- (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { + [listener use]; } -- (NSMethodSignature *) methodSignatureForSelector:(SEL)sel { - if (NSMethodSignature *method = [super methodSignatureForSelector:sel]) - return method; - //fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel)); - if (delegate_ != nil) - if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel]) - return sig; - // XXX: I fucking hate Apple so very very bad - return [NSMethodSignature signatureWithObjCTypes:"v@:"]; +- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { + NSObject *delegate([self delegate]); + if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)]) + [delegate webView:view didClearWindowObject:window forFrame:frame]; + if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)]) + [super webView:view didClearWindowObject:window forFrame:frame]; } -- (void) forwardInvocation:(NSInvocation *)inv { - SEL sel = [inv selector]; - if (delegate_ != nil && [delegate_ respondsToSelector:sel]) - [inv invokeWithTarget:delegate_]; +- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message { + NSLog(@"addMessageToConsole:%@", message); } @end -/* }}} */ @interface WebCydgetLockScreenView : UIView { - WebCycriptDelegate *indirect_; - UIProgressIndicator *indicator_; - UIScroller *scroller_; - UIWebDocumentView *document_; - + CydgetWebView *webview_; + UIScrollView *scroller_; NSString *cycript_; - bool scrollable_; - - float width_; - CGSize size_; - bool editing_; - - NSNumber *confirm_; - - NSMutableSet *loading_; - bool error_; - bool reloading_; - - //UIKeyboard *keyboard_; } @end @@ -329,176 +254,13 @@ class Pcre { //#include "UICaboodle/UCInternal.h" - (void) dealloc { - WebThreadLock(); - - WebView *webview([document_ webView]); - [webview setFrameLoadDelegate:nil]; - [webview setResourceLoadDelegate:nil]; - [webview setUIDelegate:nil]; - [webview setScriptDebugDelegate:nil]; - [webview setPolicyDelegate:nil]; - - /* XXX: these are set by UIWebDocumentView - [webview setDownloadDelegate:nil]; - [webview _setFormDelegate:nil]; - [webview _setUIKitDelegate:nil]; - [webview setEditingDelegate:nil];*/ - - /* XXX: no one sets this, ever - [webview setWebMailDelegate:nil];*/ - - [document_ setDelegate:nil]; - [document_ setGestureDelegate:nil]; - - if ([document_ respondsToSelector:@selector(setFormEditingDelegate:)]) - [document_ setFormEditingDelegate:nil]; - - [document_ setInteractionDelegate:nil]; - - [indirect_ setDelegate:nil]; - - [webview close]; - [document_ release]; - - [indirect_ release]; - - WebThreadUnlock(); - - [scroller_ setDelegate:nil]; - - if (confirm_ != nil) - [confirm_ release]; - - //[keyboard_ release]; - - [scroller_ release]; - [indicator_ release]; - [loading_ release]; + [webview_ setDelegate:nil]; + [webview_ release]; [super dealloc]; } -+ (float) defaultWidth { - return 980; -} - -- (void) webView:(WebView *)sender didReceiveMessage:(NSDictionary *)dictionary { -#if LogBrowser || ForSaurik - NSLog(@"Console:%@\n", [dictionary description]); -#endif - if ([document_ respondsToSelector:@selector(webView:didReceiveMessage:)]) - [document_ webView:sender didReceiveMessage:dictionary]; -} - -- (void) webView:(id)sender willCloseFrame:(id)frame { - if ([document_ respondsToSelector:@selector(webView:willCloseFrame:)]) - [document_ webView:sender willCloseFrame:frame]; -} - -- (void) webView:(id)sender didFinishDocumentLoadForFrame:(id)frame { - if ([document_ respondsToSelector:@selector(webView:didFinishDocumentLoadForFrame:)]) - [document_ webView:sender didFinishDocumentLoadForFrame:frame]; -} - -- (void) webView:(id)sender didFirstLayoutInFrame:(id)frame { - if ([document_ respondsToSelector:@selector(webView:didFirstLayoutInFrame:)]) - [document_ webView:sender didFirstLayoutInFrame:frame]; -} - -- (void) webViewFormEditedStatusHasChanged:(id)changed { - if ([document_ respondsToSelector:@selector(webViewFormEditedStatusHasChanged:)]) - [document_ webViewFormEditedStatusHasChanged:changed]; -} - -- (void) webView:(id)sender formStateDidFocusNode:(id)formState { - if ([document_ respondsToSelector:@selector(webView:formStateDidFocusNode:)]) - [document_ webView:sender formStateDidFocusNode:formState]; -} - -- (void) webView:(id)sender formStateDidBlurNode:(id)formState { - if ([document_ respondsToSelector:@selector(webView:formStateDidBlurNode:)]) - [document_ webView:sender formStateDidBlurNode:formState]; -} - -- (void) webViewDidLayout:(id)sender { - [document_ webViewDidLayout:sender]; -} - -- (void) webView:(id)sender didFirstVisuallyNonEmptyLayoutInFrame:(id)frame { - [document_ webView:sender didFirstVisuallyNonEmptyLayoutInFrame:frame]; -} - -- (void) webView:(id)sender saveStateToHistoryItem:(id)item forFrame:(id)frame { - [document_ webView:sender saveStateToHistoryItem:item forFrame:frame]; -} - -- (void) webView:(id)sender restoreStateFromHistoryItem:(id)item forFrame:(id)frame force:(BOOL)force { - [document_ webView:sender restoreStateFromHistoryItem:item forFrame:frame force:force]; -} - -- (void) webView:(id)sender attachRootLayer:(id)layer { - [document_ webView:sender attachRootLayer:layer]; -} - -- (id) webView:(id)sender plugInViewWithArguments:(id)arguments fromPlugInPackage:(id)package { - return [document_ webView:sender plugInViewWithArguments:arguments fromPlugInPackage:package]; -} - -- (void) webView:(id)sender willShowFullScreenForPlugInView:(id)view { - [document_ webView:sender willShowFullScreenForPlugInView:view]; -} - -- (void) webView:(id)sender didHideFullScreenForPlugInView:(id)view { - [document_ webView:sender didHideFullScreenForPlugInView:view]; -} - -- (void) webView:(id)sender willAddPlugInView:(id)view { - [document_ webView:sender willAddPlugInView:view]; -} - -- (void) webView:(id)sender didObserveDeferredContentChange:(int)change forFrame:(id)frame { - [document_ webView:sender didObserveDeferredContentChange:change forFrame:frame]; -} - -- (void) webViewDidPreventDefaultForEvent:(id)sender { - [document_ webViewDidPreventDefaultForEvent:sender]; -} - -- (void) _setTileDrawingEnabled:(BOOL)enabled { - //[document_ setTileDrawingEnabled:enabled]; -} - -- (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event { - [self _setTileDrawingEnabled:NO]; -} - -- (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event { - [self _setTileDrawingEnabled:YES]; - [document_ redrawScaledDocument]; -} - -- (void) setViewportWidth:(float)width { - width_ = width != 0 ? width : [[self class] defaultWidth]; - [document_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; -} - -- (void) scrollerWillStartDragging:(UIScroller *)scroller { - [self _setTileDrawingEnabled:NO]; -} - -- (void) scrollerDidEndDragging:(UIScroller *)scroller willSmoothScroll:(BOOL)smooth { - [self _setTileDrawingEnabled:YES]; -} - -- (void) scrollerDidEndDragging:(UIScroller *)scroller { - [self _setTileDrawingEnabled:YES]; -} - - (void) loadRequest:(NSURLRequest *)request { - error_ = false; - - WebThreadLock(); - [document_ loadRequest:request]; - WebThreadUnlock(); + [webview_ loadRequest:request]; } - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy { @@ -518,410 +280,102 @@ class Pcre { frame.size.height -= 20; //[[[$SBStatusBarController sharedStatusBarController] statusBarView] frame].size.height; if ((self = [super initWithFrame:frame]) != nil) { - loading_ = [[NSMutableSet alloc] initWithCapacity:3]; - - struct CGRect bounds([self bounds]); - - scroller_ = [[objc_getClass(Wildcat_ ? "UIScrollView" : "UIScroller") alloc] initWithFrame:bounds]; - [self addSubview:scroller_]; - - [scroller_ setFixedBackgroundPattern:YES]; - [scroller_ setBackgroundColor:[UIColor blackColor]]; - - [scroller_ setScrollingEnabled:YES]; - [scroller_ setClipsSubviews:YES]; - - if (!Wildcat_) - [scroller_ setAllowsRubberBanding:YES]; - - [scroller_ setDelegate:self]; - [scroller_ setBounces:YES]; - - if (!Wildcat_) { - [scroller_ setScrollHysteresis:8]; - [scroller_ setThumbDetectionEnabled:NO]; - [scroller_ setDirectionalScrolling:YES]; - //[scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */ - [scroller_ setEventMode:YES]; - } - - if (Wildcat_) { - UIScrollView *scroller((UIScrollView *)scroller_); - //[scroller setDirectionalLockEnabled:NO]; - [scroller setDelaysContentTouches:NO]; - //[scroller setScrollsToTop:NO]; - //[scroller setCanCancelContentTouches:NO]; - } - - [scroller_ setShowBackgroundShadow:NO]; /* YES */ - //[scroller_ setAllowsRubberBanding:YES]; /* Vertical */ - - if (!Wildcat_) - [scroller_ setAdjustForContentSizeChange:YES]; /* NO */ - - CGRect rect([scroller_ bounds]); - //rect.size.height = 0; - - WebThreadLock(); - - document_ = [[$UIWebBrowserView alloc] initWithFrame:rect]; - WebView *webview([document_ webView]); - - [document_ setBackgroundColor:[UIColor blackColor]]; - if ([document_ respondsToSelector:@selector(setDrawsBackground:)]) - [document_ setDrawsBackground:NO]; - [webview setDrawsBackground:NO]; - - [webview setPreferencesIdentifier:@"WebCycript"]; - - [document_ setTileSize:CGSizeMake(rect.size.width, 500)]; - - if ([document_ respondsToSelector:@selector(enableReachability)]) - [document_ enableReachability]; - if ([document_ respondsToSelector:@selector(setAllowsMessaging:)]) - [document_ setAllowsMessaging:YES]; - if ([document_ respondsToSelector:@selector(useSelectionAssistantWithMode:)]) - [document_ useSelectionAssistantWithMode:0]; + CGRect bounds([self bounds]); + bounds.size.height -= [TPBottomLockBar defaultHeight]; - [document_ setTilingEnabled:YES]; - [document_ setDrawsGrid:NO]; - [document_ setLogsTilingChanges:NO]; - [document_ setTileMinificationFilter:kCAFilterNearest]; + webview_ = [[CydgetWebView alloc] initWithFrame:bounds]; + [webview_ setDelegate:self]; + [self addSubview:webview_]; - if ([document_ respondsToSelector:@selector(setDataDetectorTypes:)]) - /* XXX: abstractify */ - [document_ setDataDetectorTypes:0x80000000]; + if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)]) + [webview_ setDataDetectorTypes:0x80000000]; else - [document_ setDetectsPhoneNumbers:NO]; - - [document_ setAutoresizes:YES]; - - [document_ setMinimumScale:0.25f forDocumentTypes:0x10]; - [document_ setMaximumScale:5.00f forDocumentTypes:0x10]; - [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10]; - //[document_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; + [webview_ setDetectsPhoneNumbers:NO]; - [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2]; + [webview_ setScalesPageToFit:YES]; - [document_ setMinimumScale:1.00f forDocumentTypes:0x8]; - [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8]; - [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8]; - - [document_ _setDocumentType:0x4]; - - if ([document_ respondsToSelector:@selector(setZoomsFocusedFormControl:)]) - [document_ setZoomsFocusedFormControl:YES]; - [document_ setContentsPosition:7]; - [document_ setEnabledGestures:0xa]; - [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled]; - [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller]; + UIWebDocumentView *document([webview_ _documentView]); + WebView *webview([document webView]); + WebPreferences *preferences([webview preferences]); - [document_ setSmoothsFonts:YES]; - [document_ setAllowsImageSheet:YES]; - [webview _setUsesLoaderCache:YES]; + [document setTileSize:CGSizeMake(bounds.size.width, 500)]; - [webview setGroupName:@"CydgetGroup"]; + [document setBackgroundColor:[UIColor blackColor]]; + [document setDrawsBackground:NO]; - WebPreferences *preferences([webview preferences]); + [webview setPreferencesIdentifier:@"WebCycript"]; if ([webview respondsToSelector:@selector(_setLayoutInterval:)]) [webview _setLayoutInterval:0]; else [preferences _setLayoutInterval:0]; - [self setViewportWidth:0]; + [preferences setCacheModel:WebCacheModelDocumentViewer]; + [preferences setJavaScriptCanOpenWindowsAutomatically:YES]; + [preferences setOfflineWebApplicationCacheEnabled:YES]; - [document_ setDelegate:self]; - [document_ setGestureDelegate:self]; + if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)]) + [webview setShouldUpdateWhileOffscreen:NO]; - if ([document_ respondsToSelector:@selector(setFormEditingDelegate:)]) - [document_ setFormEditingDelegate:self]; - [document_ setInteractionDelegate:self]; + if ([document respondsToSelector:@selector(setAllowsMessaging:)]) + [document setAllowsMessaging:YES]; + if ([webview respondsToSelector:@selector(_setAllowsMessaging:)]) + [webview _setAllowsMessaging:YES]; - [scroller_ addSubview:document_]; + if ([webview_ respondsToSelector:@selector(_scrollView)]) { + scroller_ = [webview_ _scrollView]; - //NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [scroller_ setDirectionalLockEnabled:YES]; + [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal]; + [scroller_ setDelaysContentTouches:NO]; - indirect_ = [[WebCycriptDelegate alloc] initWithDelegate:self]; + [scroller_ setCanCancelContentTouches:YES]; - [webview setFrameLoadDelegate:indirect_]; - [webview setPolicyDelegate:indirect_]; - [webview setResourceLoadDelegate:indirect_]; - [webview setUIDelegate:indirect_]; + [scroller_ setAlwaysBounceVertical:NO]; + } else if ([webview_ respondsToSelector:@selector(_scroller)]) { + UIScroller *scroller([webview_ _scroller]); + scroller_ = (UIScrollView *) scroller; - /* XXX: do not turn this on under penalty of extreme pain */ - [webview setScriptDebugDelegate:nil]; + [scroller setDirectionalScrolling:YES]; + [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */ + [scroller setScrollHysteresis:0]; /* 8 */ - WebThreadUnlock(); + [scroller setThumbDetectionEnabled:NO]; + } - CGSize indsize([UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite]); - indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)]; - [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite]; + [scroller_ setFixedBackgroundPattern:YES]; + [scroller_ setBackgroundColor:[UIColor blackColor]]; + [scroller_ setClipsSubviews:NO]; + + [scroller_ setBounces:YES]; + [scroller_ setShowBackgroundShadow:NO]; /* YES */ - [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; - [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; + [self setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; NSDictionary *configuration([$CydgetController currentConfiguration]); cycript_ = [configuration objectForKey:@"CycriptURLs"]; - scrollable_ = [[configuration objectForKey:@"Scrollable"] boolValue]; - [scroller_ setScrollingEnabled:scrollable_]; + [scroller_ setScrollingEnabled:[[configuration objectForKey:@"Scrollable"] boolValue]]; NSString *homepage([configuration objectForKey:@"Homepage"]); [self loadURL:[NSURL URLWithString:homepage]]; - - /*[UIKeyboard initImplementationNow]; - CGSize keysize = [UIKeyboard defaultSize]; - CGRect keyrect = {{0, [self bounds].size.height - 100}, keysize}; - keyboard_ = [[UIKeyboard alloc] initWithFrame:keyrect]; - [self addSubview:keyboard_]; - - [self addSubview:[[UITextView alloc] initWithFrame:CGRectMake(200, 0, 100, 100)]]; - [self addSubview:[[UITextView alloc] initWithFrame:CGRectMake(200, 150, 100, 100)]]; - [self addSubview:[[UITextView alloc] initWithFrame:CGRectMake(200, 300, 100, 100)]];*/ } return self; } -- (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { - [self retain]; - - UIActionSheet *sheet = [[[UIActionSheet alloc] - initWithTitle:nil - buttons:[NSArray arrayWithObjects:@"OK", nil] - defaultButtonIndex:0 - delegate:self - context:@"alert" - ] autorelease]; - - [sheet setBodyText:message]; - [sheet popupAlertAnimated:YES]; -} - -- (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { - [self retain]; - - UIActionSheet *sheet = [[[UIActionSheet alloc] - initWithTitle:nil - buttons:[NSArray arrayWithObjects:@"OK", @"CANCEL", nil] - defaultButtonIndex:0 - delegate:indirect_ - context:@"confirm" - ] autorelease]; - - [sheet setNumberOfRows:1]; - [sheet setBodyText:message]; - [sheet popupAlertAnimated:YES]; - - NSRunLoop *loop([NSRunLoop currentRunLoop]); - NSDate *future([NSDate distantFuture]); - - while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]); - - NSNumber *confirm([confirm_ autorelease]); - confirm_ = nil; - - [self autorelease]; - return [confirm boolValue]; -} - -/* XXX: WebThreadLock? */ -- (void) _fixScroller:(CGRect)bounds { - float extra; - if (!editing_ || $UIFormAssistant == nil) - extra = 0; - else { - UIFormAssistant *assistant([$UIFormAssistant sharedFormAssistant]); - CGRect peripheral([assistant peripheralFrame]); - extra = peripheral.size.height; - } - - CGRect subrect([scroller_ frame]); - subrect.size.height -= [TPBottomLockBar defaultHeight]; - subrect.size.height -= extra; - - if ([scroller_ respondsToSelector:@selector(setScrollerIndicatorSubrect:)]) - [scroller_ setScrollerIndicatorSubrect:subrect]; - - [document_ setValue:[NSValue valueWithSize:NSMakeSize(subrect.size.width, subrect.size.height)] forGestureAttribute:UIGestureAttributeVisibleSize]; - - CGSize size(size_); - size.height += extra; - size.height += [TPBottomLockBar defaultHeight]; - [scroller_ setContentSize:size]; - - if ([scroller_ respondsToSelector:@selector(releaseRubberBandIfNecessary)]) - [scroller_ releaseRubberBandIfNecessary]; -} - -- (void) fixScroller { - CGRect bounds([document_ documentBounds]); - [self _fixScroller:bounds]; -} - -- (void) view:(UIView *)sender didSetFrame:(CGRect)frame { - size_ = frame.size; - [self _fixScroller:frame]; -} - -- (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old { - [self view:sender didSetFrame:frame]; -} - -- (void) formAssistant:(id)sender didBeginEditingFormNode:(id)node { -} - -- (void) formAssistant:(id)sender didEndEditingFormNode:(id)node { - [self fixScroller]; -} - -- (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element { - editing_ = true; -} - -- (void) webView:(WebView *)sender didBeginEditingFormElement:(id)element { - [self fixScroller]; -} - -- (void) webViewDidEndEditingFormElements:(WebView *)sender { - editing_ = false; - [self fixScroller]; -} - -- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { +- (void) webView:(WebView *)webview didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { if (cycript_ != nil) if (NSString *href = [[[[frame dataSource] request] URL] absoluteString]) if (Pcre([cycript_ UTF8String], 0 /*XXX:PCRE_UTF8*/)(href)) if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL)) if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast(dlsym(handle, "CydgetSetupContext"))) { - WebView *webview([document_ webView]); WebFrame *frame([webview mainFrame]); JSGlobalContextRef context([frame globalContext]); CYSetupContext(context); } } -- (bool) isLoading { - return [loading_ count] != 0; -} - -- (void) reloadButtons { - if ([self isLoading]) { - [UIApp setNetworkActivityIndicatorVisible:YES]; - [indicator_ startAnimation]; - } else { - [UIApp setNetworkActivityIndicatorVisible:NO]; - [indicator_ stopAnimation]; - } -} - -- (void) _finishLoading { - size_t count([loading_ count]); - /*if (count == 0) - [self autorelease];*/ - if (reloading_ || count != 0) - return; - [self reloadButtons]; -} - -- (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame { - return [document_ webView:sender shouldScrollToPoint:point forFrame:frame]; -} - -- (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame { - return [document_ webView:sender didReceiveViewportArguments:arguments forFrame:frame]; -} - -- (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame { - return [document_ webView:sender needsScrollNotifications:notifications forFrame:frame]; -} - -- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame { - return [document_ webView:sender didCommitLoadForFrame:frame]; -} - -- (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame { - return [document_ webView:sender didReceiveDocTypeForFrame:frame]; -} - -- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { - [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]]; - [self _finishLoading]; - return [document_ webView:sender didFinishLoadForFrame:frame]; -} - -- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { - /*if ([loading_ count] == 0) - [self retain];*/ - [loading_ addObject:[NSValue valueWithNonretainedObject:frame]]; - - if ([frame parentFrame] == nil) { - [document_ resignFirstResponder]; - - reloading_ = false; - - if (Wildcat_) { - CGRect webrect = [scroller_ bounds]; - webrect.size.height = 1; - [document_ setFrame:webrect]; - } - - if ([scroller_ respondsToSelector:@selector(scrollPointVisibleAtTopLeft:)]) - [scroller_ scrollPointVisibleAtTopLeft:CGPointZero]; - else - [scroller_ scrollRectToVisible:CGRectZero animated:NO]; - - if ([scroller_ respondsToSelector:@selector(setZoomScale:duration:)]) - [scroller_ setZoomScale:1 duration:0]; - else if ([scroller_ respondsToSelector:@selector(_setZoomScale:duration:)]) - [scroller_ _setZoomScale:1 duration:0]; - /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)]) - [scroller_ setZoomScale:1 animated:NO];*/ - - if (!Wildcat_) { - CGRect webrect = [scroller_ bounds]; - webrect.size.height = 1; - [document_ setFrame:webrect]; - } - } - - [self reloadButtons]; -} - -- (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame { - /*if ([frame parentFrame] == nil) - [self autorelease];*/ - - [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]]; - [self _finishLoading]; - - if (reloading_) - return; - - if ([frame parentFrame] == nil) { - [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", - [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString], - [[error localizedDescription] stringByAddingPercentEscapes] - ]]]; - - error_ = true; - } -} - -- (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - [self _didFailWithError:error forFrame:frame]; - if ([document_ respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)]) - [document_ webView:sender didFailLoadWithError:error forFrame:frame]; -} - -- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - [self _didFailWithError:error forFrame:frame]; -} - -- (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary { - NSLog(@"Console:%@\n", [dictionary description]); -} - @end @interface WebCycriptLockScreenController : SBAwayViewPluginController { @@ -935,42 +389,56 @@ struct State { unsigned state; }; -// State Machine {{{ -static bool cycript_; -static bool jscript_; +// String Helpers {{{ +static const UChar *(*_ZNK7WebCore6String10charactersEv)(const WebCore::String *); +static const UChar *(*_ZN7WebCore6String29charactersWithNullTerminationEv)(const WebCore::String *); +static unsigned (*_ZNK7WebCore6String6lengthEv)(const WebCore::String *); -struct ParserSet { - bool backup_; +static bool StringGet(const WebCore::String &string, const UChar *&data, size_t &length) { + bool terminated; - ParserSet() { - backup_ = jscript_; - jscript_ = true; - cycript_ = false; - } + if (_ZNK7WebCore6String10charactersEv != NULL) { + data = (*_ZNK7WebCore6String10charactersEv)(&string); + terminated = false; + } else if (_ZN7WebCore6String29charactersWithNullTerminationEv != NULL) { + data = (*_ZN7WebCore6String29charactersWithNullTerminationEv)(&string); + terminated = true; + } else return false; - ~ParserSet() { - jscript_ = backup_; - } -}; + if (_ZNK7WebCore6String6lengthEv != NULL) + length = (*_ZNK7WebCore6String6lengthEv)(&string); + else if (terminated) + for (length = 0; data[length] != 0; ++length); + else return false; -MSHook(State, _ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, void *_this, State state) { - ParserSet set; - return __ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE(_this, state); + return true; } -MSHook(void, _ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, void *_this, void *resource) { - ParserSet set; - return __ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE(_this, resource); -} +static bool StringEquals(const WebCore::String &string, const char *value) { + const UChar *data; + size_t size; + if (!StringGet(string, data, size)) + return false; + + size_t length(strlen(value)); + if (size != length) + return false; + + for (size_t index(0); index != length; ++index) + if (data[index] != value[index]) + return false; -MSHook(void, _ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv, void *_this) { - ParserSet set; - return __ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv(_this); + return true; } +// }}} +// State Machine {{{ +static bool cycript_; MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) { - if (!jscript_ || mime != "text/cycript") + if (!StringEquals(mime, "text/cycript")) { + cycript_ = false; return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime); + } static void *handle(dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL)); if (handle == NULL) @@ -981,18 +449,43 @@ MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6 } // }}} // Script Compiler {{{ +static void Log(const WebCore::String &string) { +#if 0 + const UChar *data; + size_t length; + if (!StringGet(string, data, length)) + return; + + UChar terminated[length + 1]; + terminated[length] = 0; + memcpy(terminated, data, length * 2); + NSLog(@"wtf %p:%zu:%S:", &string, length, terminated); +#endif +} + static void Cycriptify(apr_pool_t *pool, const uint16_t *&data, size_t &size) { + cycript_ = false; + if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL)) - if (void (*CYParseUChar)(apr_pool_t *, const uint16_t **, size_t *) = reinterpret_cast(dlsym(handle, "CydgetPoolParse"))) - CYParseUChar(pool, &data, &size); + if (void (*CydgetPoolParse)(apr_pool_t *, const uint16_t **, size_t *) = reinterpret_cast(dlsym(handle, "CydgetPoolParse"))) + CydgetPoolParse(pool, &data, &size); } static void (*_ZN7WebCore6String6appendEPKtj)(WebCore::String *, const UChar *, unsigned); static void (*_ZN7WebCore6String8truncateEj)(WebCore::String *, unsigned); static void Cycriptify(const WebCore::String &source, int *psize = NULL) { - const uint16_t *data(source.characters()); - size_t length(source.length()), size(length); + if (!cycript_) + return; + + const UChar *data; + size_t length; + + if (!StringGet(source, data, length)) { + return; + } + + size_t size(length); apr_pool_t *pool; apr_pool_create(&pool, NULL); @@ -1008,6 +501,8 @@ static void Cycriptify(const WebCore::String &source, int *psize = NULL) { *psize = size; apr_pool_destroy(pool); + + Log(source); } // }}} @@ -1033,13 +528,18 @@ bool CYWeakHell() { false; } -MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::SourceCode **_this, JSC::JSGlobalData *global, int *line, JSC::UString *message) { - if (!cycript_) - return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message); - else { - cycript_ = false; +static WebCore::String *string; - JSC::SourceCode *source(*_this); +// iOS 2.x +MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, void *_this, const WebCore::String &string, State state, const WebCore::String &url, int line) { + Cycriptify(string); + return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i(_this, string, state, url, line); +} + +// iOS 3.x +MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::SourceCode **_this, JSC::JSGlobalData *global, int *line, JSC::UString *message) { + if (cycript_) { + JSC::SourceCode *source(_this[iOS32 ? 6 : 0]); const uint16_t *data(source->data()); size_t size(source->length()); @@ -1048,66 +548,39 @@ MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::Sourc Cycriptify(pool, data, size); source->~SourceCode(); + // XXX: I actually don't have the original URL here: pants new (source) JSC::SourceCode(JSC::UStringSourceProvider::create(JSC::UString(data, size), "cycript://"), 1); apr_pool_destroy(pool); - __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message); } -} -MSHook(void, _ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, void *_this, int start, const UChar *code, unsigned length, int *source, int *line, JSC::UString *message) { - if (!cycript_) - return __ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE(_this, start, code, length, source, line, message); - else { - const uint16_t *data(code); - size_t size(length); - - apr_pool_t *pool; - apr_pool_create(&pool, NULL); - - Cycriptify(pool, data, size); - __ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE(_this, start, data, size, source, line, message); - - apr_pool_destroy(pool); - } + return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message); } -static WebCore::String *string; - +// iOS 4.x cdata MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, void *_this, const WebCore::String &source, const WebCore::KURL &url, int line) { - if (cycript_) - Cycriptify(source); + Cycriptify(source); return __ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi(_this, source, url, line); } -/*void Log(const WebCore::String &string) { - size_t length(string.length()); - UChar data[length + 1]; - data[length] = 0; - memcpy(data, string.characters(), length * 2); - NSLog(@"wtf :%S:", data); -}*/ - +// iOS 4.x @src= MSHook(const WebCore::String &, _ZN7WebCore12CachedScript6scriptEv, void *_this) { const WebCore::String &script(__ZN7WebCore12CachedScript6scriptEv(_this)); - - //NSLog(@"wtf evil %s %s -- %p %p", jscript_ ? "true" : "false", cycript_ ? "true" : "false", _this, &script); - //Log(script); - string = const_cast(&script); + Log(script); return script; } +// iOS 4.x @src= MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, void *_this, void *source, State state) { - //NSLog(@"wtf tree %s %s %p", jscript_ ? "true" : "false", cycript_ ? "true" : "false", string); - - if (cycript_ && string != NULL) - Cycriptify(*string, reinterpret_cast(source) + 3); - - cycript_ = false; + if (string != NULL) { + if (iOS4) + Cycriptify(*string, reinterpret_cast(source) + 3); + else + Cycriptify(*string); + } string = NULL; - return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE(_this, source, state); } @@ -1356,19 +829,42 @@ static void dlset(Type_ &function, const char *name) { function = reinterpret_cast(dlsym(RTLD_DEFAULT, name)); } +template +static void msset_(Type_ &function, const char *name, MSImageRef handle) { + function = reinterpret_cast(MSFindSymbol(handle, name)); +} + +#define msset(function, handle) \ + msset_(function, "_" #function, handle) + @implementation WebCycriptLockScreenController -+ (void) initialize { - iOS4 = kCFCoreFoundationVersionNumber >= 550.32; +static void $UIWebViewWebViewDelegate$webView$addMessageToConsole$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *message) { + UIWebView *uiWebView(MSHookIvar(self, "uiWebView")); + if ([uiWebView respondsToSelector:@selector(webView:addMessageToConsole:)]) + [uiWebView webView:view addMessageToConsole:message]; +} - $UIWebBrowserView = objc_getClass("UIWebBrowserView"); - if ($UIWebBrowserView == nil) { - Wildcat_ = false; - $UIWebBrowserView = objc_getClass("UIWebDocumentView"); - } else { - Wildcat_ = true; +static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) { + UIWebView *uiWebView(MSHookIvar(self, "uiWebView")); + if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)]) + [uiWebView webView:view didClearWindowObject:window forFrame:frame]; +} + ++ (void) initialize { + if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) { + class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12"); + class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16"); } + if (float *_UIScrollViewDecelerationRateNormal = reinterpret_cast(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal"))) + CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal; + else // XXX: this actually might be fast on some older systems: we should look into this + CYScrollViewDecelerationRateNormal = 0.998; + + iOS4 = kCFCoreFoundationVersionNumber >= 550.32; + iOS32 = !iOS4 && kCFCoreFoundationVersionNumber >= 478.61; + int maxproc; size_t size(sizeof(maxproc)); if (sysctlbyname("kern.maxproc", &maxproc, &size, NULL, 0) == -1) @@ -1391,62 +887,68 @@ static void dlset(Type_ &function, const char *name) { MSHookFunction(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)); } - void (*_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE)(void *, int, const UChar *, unsigned, int *, int *, JSC::UString *); - dlset(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, "_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE"); - if (_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE != NULL) - MSHookFunction(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, MSHake(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE)); - - struct nlist nl[10]; + struct nlist nl[9]; memset(nl, 0, sizeof(nl)); - nl[0].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE"; - nl[1].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE"; - nl[2].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv"; - nl[3].n_un.n_name = (char *) "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE"; - - nl[4].n_un.n_name = (char *) "__ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi"; - nl[5].n_un.n_name = (char *) "__ZN7WebCore12CachedScript6scriptEv"; - nl[6].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE"; + nl[0].n_un.n_name = (char *) "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE"; - nl[7].n_un.n_name = (char *) "__ZN7WebCore6String6appendEPKtj"; - nl[8].n_un.n_name = (char *) "__ZN7WebCore6String8truncateEj"; + nl[1].n_un.n_name = (char *) "__ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi"; - nlist("/System/Library/PrivateFrameworks/WebCore.framework/WebCore", nl); + nl[2].n_un.n_name = (char *) "__ZN7WebCore12CachedScript6scriptEv"; + nl[3].n_un.n_name = (char *) "__ZNK7WebCore20StringSourceProvider6sourceEv"; - State (*_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE)(void *, State); - nlset(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, nl, 0); - MSHookFunction(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE)); + nl[4].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i"; + nl[5].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE"; - void (*_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE)(void *, void *); - nlset(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, nl, 1); - if (_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE != NULL) - MSHookFunction(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, MSHake(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE)); + nl[6].n_un.n_name = (char *) "__ZN7WebCore6String6appendEPKtj"; + nl[7].n_un.n_name = (char *) "__ZN7WebCore6String8truncateEj"; - void (*_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv)(void *); - nlset(_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv, nl, 2); - if (_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv != NULL) - MSHookFunction(_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv, MSHake(_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv)); + nlist("/System/Library/PrivateFrameworks/WebCore.framework/WebCore", nl); bool (*_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)(const WebCore::String &); - nlset(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, nl, 3); - MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)); + nlset(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, nl, 0); + if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE != NULL) + MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)); - if (iOS4) { - void (*_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi)(void *, const WebCore::String &, const WebCore::KURL &, int); - nlset(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, nl, 4); + void (*_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi)(void *, const WebCore::String &, const WebCore::KURL &, int); + nlset(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, nl, 1); + if (_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi != NULL) MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi)); + if (iOS4) { const WebCore::String &(*_ZN7WebCore12CachedScript6scriptEv)(void *); - nlset(_ZN7WebCore12CachedScript6scriptEv, nl, 5); - MSHookFunction(_ZN7WebCore12CachedScript6scriptEv, MSHake(_ZN7WebCore12CachedScript6scriptEv)); + nlset(_ZN7WebCore12CachedScript6scriptEv, nl, 2); + if (_ZN7WebCore12CachedScript6scriptEv != NULL) + MSHookFunction(_ZN7WebCore12CachedScript6scriptEv, MSHake(_ZN7WebCore12CachedScript6scriptEv)); + } + State (*_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i)(void *, const WebCore::String &, State, const WebCore::String &, int); + nlset(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, nl, 4); + if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i != NULL) + MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i)); + + if (iOS4) { State (*_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE)(void *, void *, State); - nlset(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, nl, 6); - MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE)); + nlset(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, nl, 5); + if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE != NULL) + MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE)); } - nlset(_ZN7WebCore6String6appendEPKtj, nl, 7); - nlset(_ZN7WebCore6String8truncateEj, nl, 8); + nlset(_ZN7WebCore6String6appendEPKtj, nl, 6); + nlset(_ZN7WebCore6String8truncateEj, nl, 7); + + MSImageRef JavaScriptCore(MSGetImageByName("/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore")); + MSImageRef WebCore(MSGetImageByName("/System/Library/PrivateFrameworks/WebCore.framework/WebCore")); + + if (_ZN7WebCore6String6appendEPKtj == NULL) + msset(_ZN7WebCore6String6appendEPKtj, JavaScriptCore); + + if (_ZN7WebCore6String8truncateEj == NULL) + msset(_ZN7WebCore6String8truncateEj, JavaScriptCore); + + msset(_ZNK7WebCore6String10charactersEv, WebCore); + msset(_ZN7WebCore6String29charactersWithNullTerminationEv, JavaScriptCore); + msset(_ZNK7WebCore6String6lengthEv, WebCore); } + (id) rootViewController { @@ -1458,3 +960,10 @@ static void dlset(Type_ &function, const char *name) { } @end + +MSClassHook(WebView) +MSMetaClassHook(WebView) + +MSClassMessageHook0(void, WebView, enableWebThread) { + NSLog(@"-[WebView enableWebThread]"); +}