X-Git-Url: https://git.saurik.com/cydget.git/blobdiff_plain/91fd6faef94753496b1f2d1c1442a292f067e0a2..672fa884bee5352a88404de7015b608ad83015a0:/LockScreen.mm diff --git a/LockScreen.mm b/LockScreen.mm index bfb5432..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) */ /* @@ -36,11 +36,13 @@ */ #include +#include #import #import #import +#import #import #import @@ -70,36 +72,48 @@ extern NSString * const kCAFilterNearest; #include #include "JSGlobalData.h" + #include "SourceCode.h" #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) +#define _assert(test) do \ + if (!(test)) { \ + fprintf(stderr, "_assert(%d:%s)@%s:%u[%s]\n", errno, #test, __FILE__, __LINE__, __FUNCTION__); \ + exit(-1); \ + } \ +while (false) + +#define _syscall(expr) \ + do if ((long) (expr) != -1) \ + break; \ + else switch (errno) { \ + case EINTR: \ + continue; \ + default: \ + _assert(false); \ + } while (true) + @protocol CydgetController - (NSDictionary *) currentConfiguration; @end static Class $CydgetController(objc_getClass("CydgetController")); +static bool iOS32, iOS4; + @interface NSString (UIKit) - (NSString *) stringByAddingPercentEscapes; @end @@ -174,125 +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; -} - -- (id) initWithDelegate:(id)delegate { - delegate_ = delegate; - return self; -} - -- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didClearWindowObject:window forFrame:frame]; -} +static float CYScrollViewDecelerationRateNormal; -- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didCommitLoadForFrame:frame]; -} +@interface UIScrollView (Apple) +- (void) setDecelerationRate:(float)value; +- (void) setScrollingEnabled:(BOOL)enabled; +@end -- (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didFailLoadWithError:error 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 didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didFailProvisionalLoadWithError:error forFrame:frame]; -} +@interface WebView (Apple) +- (void) _setLayoutInterval:(float)interval; +- (void) _setAllowsMessaging:(BOOL)allows; +- (void) setShouldUpdateWhileOffscreen:(BOOL)update; +@end -- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didFinishLoadForFrame:frame]; -} +@protocol CydgetWebViewDelegate // +- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame; +@end -/*- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didReceiveTitle:title forFrame:frame]; -}*/ +@class UIWebViewWebViewDelegate; -- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { - if (delegate_ != nil) - return [delegate_ webView:sender didStartProvisionalLoadForFrame:frame]; +@interface CydgetWebView : UIWebView { } -/*- (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; -}*/ +@end -- (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_; } @end @@ -302,89 +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]; - [document_ setFormEditingDelegate:nil]; - [document_ setInteractionDelegate:nil]; - - [indirect_ setDelegate:nil]; - - [webview close]; - [document_ release]; - - [indirect_ release]; - - WebThreadUnlock(); - - [scroller_ setDelegate:nil]; - - if (confirm_ != nil) - [confirm_ release]; - - [scroller_ release]; - [indicator_ release]; - [loading_ release]; + [webview_ setDelegate:nil]; + [webview_ release]; [super dealloc]; } -+ (float) defaultWidth { - return 980; -} - -- (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 { @@ -401,399 +277,239 @@ class Pcre { - (id) init { CGRect frame = {{0, 0}, {320, 480}}; - frame.size.height -= GSDefaultStatusBarHeight(); + 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_ = [[UIScroller alloc] initWithFrame:bounds]; - [self addSubview:scroller_]; - - [scroller_ setFixedBackgroundPattern:YES]; - [scroller_ setBackgroundColor:[UIColor blackColor]]; - - [scroller_ setScrollingEnabled:YES]; - [scroller_ setClipsSubviews:YES]; - [scroller_ setAllowsRubberBanding:YES]; - - [scroller_ setDelegate:self]; - [scroller_ setBounces:YES]; - [scroller_ setScrollHysteresis:8]; - [scroller_ setThumbDetectionEnabled:NO]; - [scroller_ setDirectionalScrolling:YES]; - [scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */ - [scroller_ setEventMode:YES]; - [scroller_ setShowBackgroundShadow:NO]; /* YES */ - [scroller_ setAllowsRubberBanding:YES]; /* Vertical */ - [scroller_ setAdjustForContentSizeChange:YES]; /* NO */ - - CGRect rect([scroller_ bounds]); - //rect.size.height = 0; - - WebThreadLock(); - - document_ = [[UIWebDocumentView 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]; - - [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]; + [webview_ setDetectsPhoneNumbers:NO]; - [document_ setAutoresizes:YES]; + [webview_ setScalesPageToFit: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]; - - [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2]; - - [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]; + + if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)]) + [webview setShouldUpdateWhileOffscreen:NO]; - [document_ setDelegate:self]; - [document_ setGestureDelegate:self]; - [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]; + } + + [scroller_ setFixedBackgroundPattern:YES]; + [scroller_ setBackgroundColor:[UIColor blackColor]]; + [scroller_ setClipsSubviews:NO]; - CGSize indsize([UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite]); - indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)]; - [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite]; + [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:@"Cycript"]; + 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]]; } 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_) - 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; - [scroller_ setScrollerIndicatorSubrect:subrect]; - -#undef NSSize - NSSize visible(NSMakeSize(subrect.size.width, subrect.size.height)); - [document_ setValue:[NSValue valueWithSize:visible] forGestureAttribute:UIGestureAttributeVisibleSize]; - - CGSize size(size_); - size.height += extra; - size.height += [TPBottomLockBar defaultHeight]; - [scroller_ setContentSize:size]; - - [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) 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]; -} +@end -- (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame { - return [document_ webView:sender shouldScrollToPoint:point forFrame:frame]; +@interface WebCycriptLockScreenController : SBAwayViewPluginController { } -- (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame { - return [document_ webView:sender didReceiveViewportArguments:arguments forFrame:frame]; -} +@end -- (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame { - return [document_ webView:sender needsScrollNotifications:notifications forFrame:frame]; -} +#include -- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame { - return [document_ webView:sender didCommitLoadForFrame:frame]; -} +struct State { + unsigned state; +}; -- (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame { - return [document_ webView:sender didReceiveDocTypeForFrame:frame]; -} +// String Helpers {{{ +static const UChar *(*_ZNK7WebCore6String10charactersEv)(const WebCore::String *); +static const UChar *(*_ZN7WebCore6String29charactersWithNullTerminationEv)(const WebCore::String *); +static unsigned (*_ZNK7WebCore6String6lengthEv)(const WebCore::String *); -- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { - [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]]; - [self _finishLoading]; - return [document_ webView:sender didFinishLoadForFrame:frame]; -} +static bool StringGet(const WebCore::String &string, const UChar *&data, size_t &length) { + bool terminated; -- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { - /*if ([loading_ count] == 0) - [self retain];*/ - [loading_ addObject:[NSValue valueWithNonretainedObject:frame]]; + if (_ZNK7WebCore6String10charactersEv != NULL) { + data = (*_ZNK7WebCore6String10charactersEv)(&string); + terminated = false; + } else if (_ZN7WebCore6String29charactersWithNullTerminationEv != NULL) { + data = (*_ZN7WebCore6String29charactersWithNullTerminationEv)(&string); + terminated = true; + } else return false; - if ([frame parentFrame] == nil) { - [document_ resignFirstResponder]; + if (_ZNK7WebCore6String6lengthEv != NULL) + length = (*_ZNK7WebCore6String6lengthEv)(&string); + else if (terminated) + for (length = 0; data[length] != 0; ++length); + else return false; - reloading_ = false; + return true; +} - [scroller_ scrollPointVisibleAtTopLeft:CGPointZero]; +static bool StringEquals(const WebCore::String &string, const char *value) { + const UChar *data; + size_t size; + if (!StringGet(string, data, size)) + return false; - 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];*/ + size_t length(strlen(value)); + if (size != length) + return false; - CGRect rect([scroller_ bounds]); - //rect.size.height = 0; - [document_ setFrame:rect]; - } + for (size_t index(0); index != length; ++index) + if (data[index] != value[index]) + return false; - [self reloadButtons]; + return true; } +// }}} +// State Machine {{{ +static bool cycript_; -- (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame { - /*if ([frame parentFrame] == nil) - [self autorelease];*/ +MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) { + if (!StringEquals(mime, "text/cycript")) { + cycript_ = false; + return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime); + } - [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]]; - [self _finishLoading]; + static void *handle(dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL)); + if (handle == NULL) + return false; - if (reloading_) + cycript_ = true; + return true; +} +// }}} +// Script Compiler {{{ +static void Log(const WebCore::String &string) { +#if 0 + const UChar *data; + size_t length; + if (!StringGet(string, data, length)) 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; - } + UChar terminated[length + 1]; + terminated[length] = 0; + memcpy(terminated, data, length * 2); + NSLog(@"wtf %p:%zu:%S:", &string, length, terminated); +#endif } -- (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - [self _didFailWithError:error forFrame:frame]; -} +static void Cycriptify(apr_pool_t *pool, const uint16_t *&data, size_t &size) { + cycript_ = false; -- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - [self _didFailWithError:error forFrame:frame]; + if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL)) + if (void (*CydgetPoolParse)(apr_pool_t *, const uint16_t **, size_t *) = reinterpret_cast(dlsym(handle, "CydgetPoolParse"))) + CydgetPoolParse(pool, &data, &size); } -- (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary { - fprintf(stderr, "Console:%s\n", [[dictionary description] UTF8String]); -} +static void (*_ZN7WebCore6String6appendEPKtj)(WebCore::String *, const UChar *, unsigned); +static void (*_ZN7WebCore6String8truncateEj)(WebCore::String *, unsigned); -@end +static void Cycriptify(const WebCore::String &source, int *psize = NULL) { + if (!cycript_) + return; -@interface WebCycriptLockScreenController : SBAwayViewPluginController { -} + const UChar *data; + size_t length; -@end + if (!StringGet(source, data, length)) { + return; + } -#include + size_t size(length); -static bool cycript_; -static bool jscript_; + apr_pool_t *pool; + apr_pool_create(&pool, NULL); -static void SetParser(bool cycript, bool jscript) { - cycript_ = cycript; - jscript_ = jscript; -} + Cycriptify(pool, data, size); -static bool GetParser0() { - return cycript_; -} + WebCore::String &script(const_cast(source)); -static bool GetParser1() { - return jscript_; -} + _ZN7WebCore6String8truncateEj(&script, 0); + _ZN7WebCore6String6appendEPKtj(&script, data, size); -static void Cycriptify(apr_pool_t *pool, const uint16_t *&data, size_t &size) { - 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 (psize != NULL) + *psize = size; + + apr_pool_destroy(pool); + + Log(source); } +// }}} extern "C" void *_ZN3JSC7UString3Rep14nullBaseStringE __attribute__((__weak_import__)); extern "C" void *_ZN3JSC7UString3Rep7destroyEv __attribute__((__weak_import__)); extern "C" void *_ZN3JSC7UStringC1EPKti __attribute__((__weak_import__)); +extern "C" void *_ZN3JSC7UStringC1EPKc __attribute__((__weak_import__)); extern "C" void *_ZNK3JSC7UString6substrEii __attribute__((__weak_import__)); extern "C" void *_ZN3WTF10fastMallocEm __attribute__((__weak_import__)); extern "C" void WTFReportAssertionFailure(const char *, int, const char *, const char *) __attribute__((__weak_import__)); @@ -804,6 +520,7 @@ bool CYWeakHell() { &_ZN3JSC7UString3Rep14nullBaseStringE == NULL || &_ZN3JSC7UString3Rep7destroyEv == NULL || &_ZN3JSC7UStringC1EPKti == NULL || + &_ZN3JSC7UStringC1EPKc == NULL || &_ZNK3JSC7UString6substrEii == NULL || &_ZN3WTF10fastMallocEm == NULL || &WTFReportAssertionFailure == NULL || @@ -811,66 +528,60 @@ bool CYWeakHell() { false; } +static WebCore::String *string; + +// 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 (!GetParser0()) - return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message); - else { - SetParser(false, true); - JSC::SourceCode *source(*_this); + if (cycript_) { + JSC::SourceCode *source(_this[iOS32 ? 6 : 0]); const uint16_t *data(source->data()); size_t size(source->length()); - apr_pool_t *pool; - apr_pool_create(&pool, NULL); - Cycriptify(pool, data, size); - JSC::SourceCode code(JSC::makeSource(JSC::UString(data, size))); - *_this = &code; - __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message); - apr_pool_destroy(pool); - *_this = source; - } -} -MSHook(void, _ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, void *_this, int start, const UChar *code, unsigned length, int *source, int *line, JSC::UString *message) { - if (!GetParser0()) - 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); + 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); - } -} -struct State { - unsigned state; -}; + } -MSHook(State, _ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, State state) { - SetParser(false, true); - state = __ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE(state); - SetParser(false, false); - return state; + return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message); } -MSHook(void, _ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, void *resource) { - SetParser(false, true); - __ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE(resource); - SetParser(false, false); +// iOS 4.x cdata +MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, void *_this, const WebCore::String &source, const WebCore::KURL &url, int line) { + Cycriptify(source); + return __ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi(_this, source, url, line); } -MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) { - if (!GetParser1() || mime != "text/cycript") - return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime); - - static void *handle(dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL)); - if (handle == NULL) - return false; +// iOS 4.x @src= +MSHook(const WebCore::String &, _ZN7WebCore12CachedScript6scriptEv, void *_this) { + const WebCore::String &script(__ZN7WebCore12CachedScript6scriptEv(_this)); + string = const_cast(&script); + Log(script); + return script; +} - SetParser(true, true); - return true; +// iOS 4.x @src= +MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, void *_this, void *source, State state) { + if (string != NULL) { + if (iOS4) + Cycriptify(*string, reinterpret_cast(source) + 3); + else + Cycriptify(*string); + } + string = NULL; + return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE(_this, source, state); } /* Cydget:// Protocol {{{ */ @@ -942,6 +653,165 @@ MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6 - (void) stopLoading { } +@end +/* }}} */ +/* Cydget-CGI:// Protocol {{{ */ +@interface CydgetCGIURLProtocol : NSURLProtocol { + pid_t pid_; + CFHTTPMessageRef http_; + NSFileHandle *handle_; +} + +@end + +@implementation CydgetCGIURLProtocol + ++ (BOOL) canInitWithRequest:(NSURLRequest *)request { + NSURL *url([request URL]); + if (url == nil) + return NO; + NSString *scheme([[url scheme] lowercaseString]); + if (scheme == nil || ![scheme isEqualToString:@"cydget-cgi"]) + return NO; + return YES; +} + ++ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request { + return request; +} + +- (id) initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)response client:(id)client { + if ((self = [super initWithRequest:request cachedResponse:response client:client]) != nil) { + pid_ = -1; + } return self; +} + +- (void) startLoading { + id client([self client]); + NSURLRequest *request([self request]); + NSURL *url([request URL]); + + NSString *path([url path]); + if (path == nil) { + [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]]; + return; + } + + NSFileManager *manager([NSFileManager defaultManager]); + if (![manager fileExistsAtPath:path]) { + [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]]; + return; + } + + int fds[2]; + _assert(pipe(fds) != -1); + + _assert(pid_ == -1); + pid_ = fork(); + if (pid_ == -1) { + _assert(close(fds[0]) != -1); + _assert(close(fds[1]) != -1); + [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]]; + return; + } + + if (pid_ == 0) { + const char *script([path UTF8String]); + + setenv("GATEWAY_INTERFACE", "CGI/1.1", true); + setenv("SCRIPT_FILENAME", script, true); + NSString *query([url query]); + if (query != nil) + setenv("QUERY_STRING", [query UTF8String], true); + + _assert(dup2(fds[1], 1) != -1); + _assert(close(fds[0]) != -1); + _assert(close(fds[1]) != -1); + + execl(script, script, NULL); + exit(1); + _assert(false); + } + + _assert(close(fds[1]) != -1); + + _assert(http_ == NULL); + http_ = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE); + CFHTTPMessageAppendBytes(http_, (const uint8_t *) "HTTP/1.1 200 OK\r\n", 17); + + _assert(handle_ == nil); + handle_ = [[NSFileHandle alloc] initWithFileDescriptor:fds[0] closeOnDealloc:YES]; + + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(onRead:) + name:@"NSFileHandleReadCompletionNotification" + object:handle_ + ]; + + [handle_ readInBackgroundAndNotify]; +} + +- (void) onRead:(NSNotification *)notification { + NSFileHandle *handle([notification object]); + + NSData *data([[notification userInfo] objectForKey:NSFileHandleNotificationDataItem]); + + if (size_t length = [data length]) { + CFHTTPMessageAppendBytes(http_, reinterpret_cast([data bytes]), length); + [handle readInBackgroundAndNotify]; + } else { + id client([self client]); + + CFStringRef mime(CFHTTPMessageCopyHeaderFieldValue(http_, CFSTR("Content-type"))); + if (mime == NULL) + [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]]; + else { + NSURLRequest *request([self request]); + + NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:(NSString *)mime expectedContentLength:-1 textEncodingName:nil] autorelease]); + CFRelease(mime); + + [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; + + CFDataRef body(CFHTTPMessageCopyBody(http_)); + [client URLProtocol:self didLoadData:(NSData *)body]; + CFRelease(body); + + [client URLProtocolDidFinishLoading:self]; + } + + CFRelease(http_); + http_ = NULL; + } +} + + //[client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNetworkConnectionLost userInfo:nil]]; + +- (void) stopLoading_ { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + if (handle_ != nil) { + [handle_ release]; + handle_ = nil; + } + + if (pid_ != -1) { + kill(pid_, SIGTERM); + int status; + _syscall(waitpid(pid_, &status, 0)); + pid_ = -1; + } +} + +- (void) stopLoading { + [self + performSelectorOnMainThread:@selector(stopLoading_) + withObject:nil + waitUntilDone:NO + ]; +} + @end /* }}} */ @@ -959,41 +829,126 @@ 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 +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]; +} + +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) + NSLog(@"sysctlbyname(\"kern.maxproc\", ?)"); + else if (maxproc < 72) { + maxproc = 72; + if (sysctlbyname("kern.maxproc", NULL, NULL, &maxproc, sizeof(maxproc)) == -1) + NSLog(@"sysctlbyname(\"kern.maxproc\", #)"); + } + apr_initialize(); [NSURLProtocol registerClass:[CydgetURLProtocol class]]; + [NSURLProtocol registerClass:[CydgetCGIURLProtocol class]]; - void (*_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)(JSC::SourceCode **, JSC::JSGlobalData *, int *, JSC::UString *); - dlset(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, "_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE"); - if (_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE != NULL) - 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)); + if (!iOS4) { + void (*_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)(JSC::SourceCode **, JSC::JSGlobalData *, int *, JSC::UString *); + dlset(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, "_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE"); + if (_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE != NULL) + MSHookFunction(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)); + } - struct nlist nl[4]; + 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 *) "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE"; - nlist("/System/Library/PrivateFrameworks/WebCore.framework/WebCore", nl); - State (*_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE)(State); - nlset(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, nl, 0); - MSHookFunction(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE)); + nl[0].n_un.n_name = (char *) "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE"; + + nl[1].n_un.n_name = (char *) "__ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi"; + + nl[2].n_un.n_name = (char *) "__ZN7WebCore12CachedScript6scriptEv"; + nl[3].n_un.n_name = (char *) "__ZNK7WebCore20StringSourceProvider6sourceEv"; + + 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 *); - nlset(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, nl, 1); - MSHookFunction(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, MSHake(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE)); + nl[6].n_un.n_name = (char *) "__ZN7WebCore6String6appendEPKtj"; + nl[7].n_un.n_name = (char *) "__ZN7WebCore6String8truncateEj"; + + nlist("/System/Library/PrivateFrameworks/WebCore.framework/WebCore", nl); bool (*_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)(const WebCore::String &); - nlset(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, nl, 2); - MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)); + nlset(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, nl, 0); + if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE != NULL) + MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)); + + 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, 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, 5); + if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE != NULL) + MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE)); + } + + 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 { @@ -1005,3 +960,10 @@ static void dlset(Type_ &function, const char *name) { } @end + +MSClassHook(WebView) +MSMetaClassHook(WebView) + +MSClassMessageHook0(void, WebView, enableWebThread) { + NSLog(@"-[WebView enableWebThread]"); +}