1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008 Jay Freeman (saurik)
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the
11 * above copyright notice, this list of conditions
12 * and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the
14 * above copyright notice, this list of conditions
15 * and the following disclaimer in the documentation
16 * and/or other materials provided with the
18 * 3. The name of the author may not be used to endorse
19 * or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #define _trace() do { \
44 struct timeval _ctv; \
45 gettimeofday(&_ctv, NULL); \
50 fprintf(stderr, "%lu.%.6u[%f]:_trace()@%s:%u[%s]\n", \
51 _ctv.tv_sec, _ctv.tv_usec, \
52 (_ctv.tv_sec - _ltv.tv_sec) + (_ctv.tv_usec - _ltv.tv_usec) / 1000000.0, \
53 __FILE__, __LINE__, __FUNCTION__\
60 #import <CoreFoundation/CoreFoundation.h>
61 #import <Foundation/Foundation.h>
62 #import <CoreGraphics/CoreGraphics.h>
64 #import <Celestial/AVController.h>
65 #import <Celestial/AVItem.h>
66 #import <Celestial/AVQueue.h>
68 #include <substrate.h>
70 #import <UIKit/UIKit.h>
72 #import <SpringBoard/SBApplication.h>
73 #import <SpringBoard/SBApplicationIcon.h>
74 #import <SpringBoard/SBAppWindow.h>
75 #import <SpringBoard/SBAwayView.h>
76 #import <SpringBoard/SBBookmarkIcon.h>
77 #import <SpringBoard/SBButtonBar.h>
78 #import <SpringBoard/SBCalendarIconContentsView.h>
79 #import <SpringBoard/SBIconController.h>
80 #import <SpringBoard/SBIconLabel.h>
81 #import <SpringBoard/SBIconList.h>
82 #import <SpringBoard/SBIconModel.h>
83 #import <SpringBoard/SBImageCache.h>
84 #import <SpringBoard/SBStatusBarContentsView.h>
85 #import <SpringBoard/SBStatusBarController.h>
86 #import <SpringBoard/SBStatusBarOperatorNameView.h>
87 #import <SpringBoard/SBStatusBarTimeView.h>
88 #import <SpringBoard/SBUIController.h>
89 #import <SpringBoard/SBWidgetApplicationIcon.h>
91 #import <MobileSMS/mSMSMessageTranscriptController.h>
93 #import <MediaPlayer/MPMoviePlayerController.h>
94 #import <MediaPlayer/MPVideoView.h>
95 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
97 #import <CoreGraphics/CGGeometry.h>
99 extern "C" void __clear_cache (char *beg, char *end);
101 @protocol WinterBoard
105 Class $MPMoviePlayerController;
107 Class $WebCoreFrameBridge;
112 Class $UINavigationBar;
115 Class $SBApplication;
116 Class $SBApplicationIcon;
118 Class $SBBookmarkIcon;
120 Class $SBCalendarIconContentsView;
123 Class $SBIconController;
127 //Class $SBImageCache;
128 Class $SBStatusBarContentsView;
129 Class $SBStatusBarController;
130 Class $SBStatusBarOperatorNameView;
131 Class $SBStatusBarTimeView;
132 Class $SBUIController;
133 Class $SBWidgetApplicationIcon;
135 @interface NSDictionary (WinterBoard)
136 - (UIColor *) colorForKey:(NSString *)key;
137 - (BOOL) boolForKey:(NSString *)key;
140 @implementation NSDictionary (WinterBoard)
142 - (UIColor *) colorForKey:(NSString *)key {
143 NSString *value = [self objectForKey:key];
150 - (BOOL) boolForKey:(NSString *)key {
151 if (NSString *value = [self objectForKey:key])
152 return [value boolValue];
158 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
159 #define $GSFontGetUseLegacyFontMetrics() \
160 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
163 bool Engineer_ = false;
165 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
166 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
167 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
168 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
169 static NSBundle *(*_UIKitBundle)();
170 static int (*_UISharedImageNameGetIdentifier)(NSString *);
171 static UIImage *(*_UISharedImageWithIdentifier)(int);
173 static NSMutableDictionary *UIImages_;
174 static NSMutableDictionary *PathImages_;
175 static NSMutableDictionary *Cache_;
176 static NSMutableDictionary *Strings_;
177 static NSMutableDictionary *Themed_;
178 static NSMutableDictionary *Bundles_;
180 static NSFileManager *Manager_;
181 static NSDictionary *English_;
182 static NSMutableDictionary *Info_;
183 static NSMutableArray *themes_;
185 static NSString *$getTheme$(NSArray *files, bool parent = false) {
187 if (NSString *path = [Themed_ objectForKey:files])
188 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
191 NSLog(@"WB:Debug: %@", [files description]);
195 for (NSString *theme in themes_)
196 for (NSString *file in files) {
197 path = [NSString stringWithFormat:@"%@/%@", theme, file];
198 if ([Manager_ fileExistsAtPath:path]) {
199 path = parent ? theme : path;
207 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
211 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
212 NSString *identifier = [bundle bundleIdentifier];
213 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
215 if (identifier != nil)
216 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
217 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
218 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
220 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
222 #define remapResourceName(oldname, newname) \
223 else if ([file isEqualToString:oldname]) \
224 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
226 if (identifier == nil);
227 else if ([identifier isEqualToString:@"com.apple.calculator"])
228 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
229 else if (![identifier isEqualToString:@"com.apple.springboard"]);
230 remapResourceName(@"FSO_BG.png", @"StatusBar")
231 remapResourceName(@"SBDockBG.png", @"Dock")
232 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
234 if (NSString *path = $getTheme$(names))
239 static NSString *$pathForIcon$(SBApplication *self) {
240 NSString *identifier = [self bundleIdentifier];
241 NSString *path = [self path];
242 NSString *folder = [path lastPathComponent];
243 NSString *dname = [self displayName];
244 NSString *didentifier = [self displayIdentifier];
247 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
249 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
251 if (identifier != nil)
252 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
254 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
256 #define testForIcon(Name) \
257 if (NSString *name = Name) \
258 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
260 testForIcon(identifier);
263 if (didentifier != nil) {
264 testForIcon([English_ objectForKey:didentifier]);
266 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
267 if ([parts count] != 1)
268 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
269 testForIcon([english objectForKey:[parts lastObject]]);
272 if (NSString *path = $getTheme$(names))
277 @interface NSBundle (WinterBoard)
278 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
281 @implementation NSBundle (WinterBoard)
283 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
284 path = [path stringByDeletingLastPathComponent];
285 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
288 NSBundle *bundle([Bundles_ objectForKey:path]);
289 if (reinterpret_cast<id>(bundle) == [NSNull null])
291 else if (bundle == nil) {
292 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
293 bundle = [NSBundle bundleWithPath:path];
295 bundle = [NSBundle wb$bundleWithFile:path];
297 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
298 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
306 @interface NSString (WinterBoard)
307 - (NSString *) wb$themedPath;
310 @implementation NSString (WinterBoard)
312 - (NSString *) wb$themedPath {
314 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
316 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
317 NSString *file([self stringByResolvingSymlinksInPath]);
318 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
319 if ([file hasPrefix:prefix]) {
320 NSUInteger length([prefix length]);
321 if (length != [file length])
322 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
332 UIImage *$cacheForImage$(UIImage *image) {
333 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
334 CGRect rect = {CGPointMake(1, 1), [image size]};
335 CGSize size = {rect.size.width + 2, rect.size.height + 2};
337 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
338 CGColorSpaceRelease(space);
340 CGContextDrawImage(context, rect, [image CGImage]);
341 CGImageRef ref(CGBitmapContextCreateImage(context));
342 CGContextRelease(context);
344 UIImage *cache([UIImage imageWithCGImage:ref]);
350 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
351 //if ([name isEqualToString:@"icons"]) return nil;
352 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
355 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
356 NSString *key([icon displayIdentifier]);
358 if (UIImage *image = [icon icon]) {
359 CGSize size = [image size];
360 if (size.width != 59 || size.height != 60) {
361 UIImage *cache($cacheForImage$(image));
362 [Cache_ setObject:cache forKey:key];
367 _SBIconModel$cacheImageForIcon$(self, sel, icon);
370 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
371 NSString *key([icon displayIdentifier]);
372 if (UIImage *image = [Cache_ objectForKey:key])
375 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
378 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
379 if (![Info_ boolForKey:@"ComposeStoreIcons"])
380 if (NSString *path = $pathForIcon$([self application]))
381 return [UIImage imageWithContentsOfFile:path];
382 return _SBApplicationIcon$icon(self, sel);
385 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
387 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
388 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
389 return [UIImage imageWithContentsOfFile:path];
390 return _SBWidgetApplicationIcon$icon(self, sel);
393 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
395 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
396 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
397 return [UIImage imageWithContentsOfFile:path];
398 return _SBBookmarkIcon$icon(self, sel);
401 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
402 if (NSString *path = $pathForIcon$(self))
404 return _SBApplication$pathForIcon(self, sel);
407 static UIImage *CachedImageAtPath(NSString *path) {
408 path = [path stringByResolvingSymlinksInPath];
409 UIImage *image = [PathImages_ objectForKey:path];
411 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
412 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
414 image = [image autorelease];
415 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
419 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
421 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
422 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
425 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
427 return __UIImageAtPath(name, nil);
429 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
430 UIImage *image = [PathImages_ objectForKey:key];
432 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
434 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
435 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
436 image = CachedImageAtPath(path);
438 image = __UIImageAtPath(name, bundle);
439 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
444 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
445 NSBundle *bundle = [NSBundle mainBundle];
447 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
448 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
449 return CachedImageAtPath(path);
450 return __UIApplicationImageWithName(name);
453 #define WBDelegate(delegate) \
454 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
456 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
457 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
459 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
463 - (void) forwardInvocation:(NSInvocation*)inv { \
464 SEL sel = [inv selector]; \
465 if ([delegate respondsToSelector:sel]) \
466 [inv invokeWithTarget:delegate]; \
468 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
471 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
472 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
474 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
475 if (NSString *path = $pathForFile$inBundle$(file, self, false))
477 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
480 void $setBarStyle$_(NSString *name, int &style) {
482 NSLog(@"WB:Debug:%@Style:%d", name, style);
483 NSNumber *number = nil;
485 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
487 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
489 style = [number intValue];
491 NSLog(@"WB:Debug:%@Style=%d", name, style);
495 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
496 NSBundle *bundle([NSBundle mainBundle]);
498 CFLocaleRef locale(CFLocaleCopyCurrent());
499 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
502 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
504 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
505 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
506 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
507 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
511 CFRelease(formatter);
513 NSString *datestyle(@""
514 "font-family: Helvetica; "
515 "font-weight: bold; "
521 NSString *daystyle(@""
522 "font-family: Helvetica; "
523 "font-weight: bold; "
526 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
529 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
530 datestyle = [datestyle stringByAppendingString:style];
531 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
532 daystyle = [daystyle stringByAppendingString:style];
534 float width([self bounds].size.width);
536 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
537 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
539 unsigned base($GSFontGetUseLegacyFontMetrics() ? 71 : 70);
541 [(NSString *)date drawAtPoint:CGPointMake(
542 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
543 ) withStyle:datestyle];
545 [(NSString *)day drawAtPoint:CGPointMake(
546 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
547 ) withStyle:daystyle];
553 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
556 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
557 style = [number intValue];
559 if (UIColor *color = [Info_ colorForKey:@"NavigationBarTint"])
562 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
565 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
566 self = [self wb$initWithCoder:coder];
569 UINavigationBar$setBarStyle$_(self);
573 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
574 self = [self wb$initWithFrame:frame];
577 UINavigationBar$setBarStyle$_(self);
581 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
582 $setBarStyle$_(@"Toolbar", style);
583 return _UIToolbar$setBarStyle$(self, sel, style);
586 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
587 $setBarStyle$_(@"NavigationBar", style);
588 return _UINavigationBar$setBarStyle$(self, sel, style);
591 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
592 [[self superview] setBackgroundColor:[UIColor clearColor]];
593 _SBButtonBar$didMoveToSuperview(self, sel);
596 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
597 [[self superview] setBackgroundColor:[UIColor clearColor]];
598 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
601 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
603 NSLog(@"WB:Debug:DefaultDesktopImage");
604 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
605 return [UIImage imageWithContentsOfFile:path];
606 return _UIImage$defaultDesktopImage(self, sel);
609 static NSArray *Wallpapers_;
610 static NSString *WallpaperFile_;
611 static UIImageView *WallpaperImage_;
612 static UIWebDocumentView *WallpaperPage_;
613 static NSURL *WallpaperURL_;
615 #define _release(object) \
616 do if (object != nil) { \
621 void DumpHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
622 NSLog(@"%*s|%2d:%s", indent * 3, "", index, class_getName([view class]));
624 for (UIView *child in [view subviews])
625 DumpHierarchy(child, index++, indent + 1);
628 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
629 self = _SBUIController$init(self, sel);
633 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
634 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
635 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
638 if (&_contentLayer != NULL)
639 layer = _contentLayer;
640 else if (&_contentView != NULL)
641 layer = _contentView;
645 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
646 [content setBackgroundColor:[layer backgroundColor]];
647 [layer setBackgroundColor:[UIColor clearColor]];
648 [layer setFrame:[content bounds]];
649 [_window setContentView:content];
651 _release(WallpaperFile_);
652 _release(WallpaperImage_);
653 _release(WallpaperPage_);
654 _release(WallpaperURL_);
656 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
657 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
658 if ([Manager_ fileExistsAtPath:mp4]) {
662 static AVController *controller_(nil);
663 if (controller_ == nil) {
664 AVQueue *queue([AVQueue avQueue]);
665 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
668 AVQueue *queue([controller_ queue]);
670 UIView *video([[[UIView alloc] initWithFrame:[content bounds]] autorelease]);
671 [controller_ setLayer:[video _layer]];
673 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
674 [queue appendItem:item error:&error];
676 [controller_ play:&error];
677 #elif UseMPMoviePlayerController
678 NSURL *url([NSURL fileURLWithPath:mp4]);
679 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
680 controller.movieControlMode = MPMovieControlModeHidden;
683 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[content bounds]] autorelease];
684 [video setMovieWithPath:mp4];
685 [video setRepeatMode:1];
686 [video setRepeatGap:-1];
687 [video playFromBeginning];;
690 [content addSubview:video];
693 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
694 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
697 if ([Manager_ fileExistsAtPath:png])
699 else if ([Manager_ fileExistsAtPath:jpg])
705 image = [[UIImage alloc] initWithContentsOfFile:path];
707 image = [image autorelease];
711 WallpaperFile_ = [path retain];
712 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
713 [content addSubview:WallpaperImage_];
716 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
717 if ([Manager_ fileExistsAtPath:html]) {
718 CGRect bounds = [content bounds];
720 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
721 [view setAutoresizes:true];
723 WallpaperPage_ = [view retain];
724 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
726 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
728 [[view webView] setDrawsBackground:false];
729 [view setBackgroundColor:[UIColor clearColor]];
731 [content addSubview:view];
735 for (size_t i(0), e([themes_ count]); i != e; ++i) {
736 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
737 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
738 if ([Manager_ fileExistsAtPath:html]) {
739 CGRect bounds = [content bounds];
741 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
742 [view setAutoresizes:true];
744 NSURL *url = [NSURL fileURLWithPath:html];
745 [view loadRequest:[NSURLRequest requestWithURL:url]];
747 [[view webView] setDrawsBackground:false];
748 [view setBackgroundColor:[UIColor clearColor]];
750 [content addSubview:view];
754 [content addSubview:layer];
755 DumpHierarchy(_window);
760 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
761 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
762 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
764 if (path != nil && _backgroundView != nil)
767 _SBAwayView$updateDesktopImage$(self, sel, image);
770 CGRect bounds = [self bounds];
772 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
773 [view setAutoresizes:true];
775 if (WallpaperPage_ != nil)
776 [WallpaperPage_ release];
777 WallpaperPage_ = [view retain];
779 if (WallpaperURL_ != nil)
780 [WallpaperURL_ release];
781 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
783 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
785 [[view webView] setDrawsBackground:false];
786 [view setBackgroundColor:[UIColor clearColor]];
788 [self insertSubview:view aboveSubview:_backgroundView];
792 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
793 extern "C" CGColorRef CGGStateGetFillColor(void *);
794 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
795 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
797 /* WBTimeLabel {{{ */
798 @interface WBTimeLabel : NSProxy {
800 _transient SBStatusBarTimeView *view_;
803 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
807 @implementation WBTimeLabel
814 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
815 time_ = [time retain];
820 - (NSString *) description {
826 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
827 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
828 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
830 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
831 "font-family: Helvetica; "
832 "font-weight: bold; "
835 "%@", _mode ? @"white" : @"black", custom]];
840 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
845 /* WBBadgeLabel {{{ */
846 @interface WBBadgeLabel : NSProxy {
850 - (id) initWithBadge:(NSString *)badge;
854 @implementation WBBadgeLabel
861 - (id) initWithBadge:(NSString *)badge {
862 badge_ = [badge retain];
868 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
869 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
870 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
871 "font-family: Helvetica; "
872 "font-weight: bold; "
880 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
886 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
887 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
888 alpha = [number floatValue];
889 return _SBIcon$setAlpha$(self, sel, alpha);
892 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
893 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
894 id &_badge(MSHookIvar<id>(self, "_badge"));
896 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
901 void SBStatusBarController$setStatusBarMode(int &mode) {
903 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
904 if (mode < 100) // 104:hidden 105:glowing
905 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
906 mode = [number intValue];
909 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
910 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
911 SBStatusBarController$setStatusBarMode(mode);
912 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
915 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
916 NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
917 SBStatusBarController$setStatusBarMode(mode);
918 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
921 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int fenceID, int animation, double startTime) {
922 NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
923 SBStatusBarController$setStatusBarMode(mode);
924 NSLog(@"mode=%u", mode);
925 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
928 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
929 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
930 mode = [number intValue];
931 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
934 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
935 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
937 NSLog(@"operatorNameStyle= %@", style);
938 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
939 style = [NSString stringWithFormat:@"%@; %@", style, custom];
943 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
945 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
946 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
949 // XXX: replace this with [SBStatusBarTimeView tile]
950 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
951 id &_time(MSHookIvar<id>(self, "_time"));
952 if (_time != nil && [_time class] != [WBTimeLabel class])
953 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
954 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
957 @interface UIView (WinterBoard)
958 - (bool) wb$isWBImageView;
961 @implementation UIView (WinterBoard)
963 - (bool) wb$isWBImageView {
969 @interface WBImageView : UIImageView {
972 - (bool) wb$isWBImageView;
973 - (void) wb$updateFrame;
976 @implementation WBImageView
978 - (bool) wb$isWBImageView {
982 - (void) wb$updateFrame {
983 CGRect frame([self frame]);
986 for (UIView *view(self); ; ) {
987 view = [view superview];
990 frame.origin.y -= [view frame].origin.y;
993 [self setFrame:frame];
998 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
999 NSArray *subviews([self subviews]);
1000 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1001 if (view != nil && [view wb$isWBImageView])
1002 [view wb$updateFrame];
1003 _SBIconList$setFrame$(self, sel, frame);
1006 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1007 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1008 NSArray *lists([_iconModel iconLists]);
1010 for (unsigned i(0), e([lists count]); i != e; ++i)
1011 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1012 SBIconList *list([lists objectAtIndex:i]);
1013 NSArray *subviews([list subviews]);
1015 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1016 if (view == nil || ![view wb$isWBImageView]) {
1017 view = [[[WBImageView alloc] init] autorelease];
1018 [list insertSubview:view atIndex:0];
1021 UIImage *image([UIImage imageWithContentsOfFile:path]);
1022 [view setImage:image];
1023 [view wb$updateFrame];
1026 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1029 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1030 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1032 [self setClipsToBounds:NO];
1036 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1037 id &_label(MSHookIvar<id>(self, "_label"));
1038 if (![Info_ boolForKey:@"UndockedIconLabels"])
1040 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1041 [_label setInDock:docked];
1042 return _SBIconLabel$setInDock$(self, sel, docked);
1045 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1046 NSString *identifier = [self bundleIdentifier];
1047 NSLocale *locale = [NSLocale currentLocale];
1048 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1050 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1051 NSString *file = table == nil ? @"Localizable" : table;
1052 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1053 NSDictionary *strings;
1054 if ((strings = [Strings_ objectForKey:name]) != nil) {
1055 if (static_cast<id>(strings) != [NSNull null]) strings:
1056 if (NSString *value = [strings objectForKey:key])
1058 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1061 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1062 [Strings_ setObject:[strings autorelease] forKey:name];
1066 [Strings_ setObject:[NSNull null] forKey:name];
1067 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1070 @class WebCoreFrameBridge;
1071 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1074 void **core(reinterpret_cast<void **>([node _node]));
1075 if (core == NULL || core[6] == NULL)
1077 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1080 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1081 CGRect bounds = [self bounds];
1083 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1086 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1087 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1089 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1091 NSString *style = [NSString stringWithFormat:@""
1092 "font-family: Helvetica; "
1093 "font-weight: bold; "
1096 "", docked ? @"white" : @"#b3b3b3"];
1099 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1101 bool ellipsis(false);
1102 float max = 75, width;
1104 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1107 size_t length([label length]);
1108 float spacing((width - max) / (length - 1));
1110 if (spacing > 1.25) {
1112 label = [label substringToIndex:(length - 1)];
1116 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1120 label = [label stringByAppendingString:@"..."];
1122 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1123 style = [style stringByAppendingString:custom];
1125 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1126 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1129 MSHook(void, mSMSMessageTranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1130 _mSMSMessageTranscriptController$loadView(self, sel);
1132 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1133 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1134 [image autorelease];
1135 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1136 UIView *parent([_transcriptLayer superview]);
1137 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1138 [parent insertSubview:background belowSubview:_transcriptLayer];
1139 [_transcriptLayer setBackgroundColor:[UIColor clearColor]];
1143 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1144 int id(_UISharedImageNameGetIdentifier(name));
1146 NSLog(@"WB:Debug: _UIImageWithName(\"%@\", %d)", name, id);
1149 return _UIImageAtPath(name, _UIKitBundle());
1151 NSNumber *key([NSNumber numberWithInt:id]);
1152 UIImage *image = [UIImages_ objectForKey:key];
1154 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1155 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1156 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1158 [image autorelease];
1161 image = _UISharedImageWithIdentifier(id);
1162 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1167 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1168 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
1169 UIImage *image = [PathImages_ objectForKey:key];
1171 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1173 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1174 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1175 image = [[UIImage alloc] initWithContentsOfFile:path];
1177 [image autorelease];
1180 image = __UIImageWithNameInDomain(name, domain);
1181 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1185 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1186 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1187 name = [font UTF8String];
1188 return _GSFontCreateWithName(name, traits, size);
1191 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1192 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1194 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1196 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1197 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1199 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1202 NSString *path = [NSString stringWithUTF8String:a1];
1203 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1204 NSString *file = [path substringFromIndex:31];
1205 for (NSString *theme in themes_) {
1206 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1207 if ([Manager_ fileExistsAtPath:path]) {
1208 strcpy(a1, [path UTF8String]);
1217 static void ChangeWallpaper(
1218 CFNotificationCenterRef center,
1222 CFDictionaryRef info
1225 NSLog(@"WB:Debug:ChangeWallpaper!");
1228 if (WallpaperFile_ != nil) {
1229 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1231 image = [image autorelease];
1234 if (WallpaperImage_ != nil)
1235 [WallpaperImage_ setImage:image];
1236 if (WallpaperPage_ != nil)
1237 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1241 #define WBRename(name, sel, imp) \
1242 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1244 extern "C" void WBInitialize() {
1245 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1247 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1249 NSLog(@"WB:Notice: WinterBoard");
1251 _GSFontGetUseLegacyFontMetrics = reinterpret_cast<BOOL (*)()>(dlsym(RTLD_DEFAULT, "GSFontGetUseLegacyFontMetrics"));
1254 memset(nl, 0, sizeof(nl));
1256 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1257 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1258 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1259 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1260 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1261 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1262 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1266 _UIApplicationImageWithName = (UIImage *(*)(NSString *)) nl[0].n_value;
1267 _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[1].n_value;
1268 _UIImageRefAtPath = (CGImageRef (*)(NSString *, bool, UIImageOrientation *)) nl[2].n_value;
1269 _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[3].n_value;
1270 _UIKitBundle = (NSBundle *(*)()) nl[4].n_value;
1271 _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[5].n_value;
1272 _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[6].n_value;
1274 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1275 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1276 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1277 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1279 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1281 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1283 memset(nl, 0, sizeof(nl));
1284 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1285 nlist(AudioToolbox, nl);
1286 _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value;
1287 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1290 $NSBundle = objc_getClass("NSBundle");
1292 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1293 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1295 $UIImage = objc_getClass("UIImage");
1296 $UINavigationBar = objc_getClass("UINavigationBar");
1297 $UIToolbar = objc_getClass("UIToolbar");
1299 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1301 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1302 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1304 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1305 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1307 Manager_ = [[NSFileManager defaultManager] retain];
1308 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1309 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1310 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1311 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1312 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1314 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1316 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1317 [settings autorelease];
1319 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1320 Debug_ = [debug boolValue];
1322 NSArray *themes = [settings objectForKey:@"Themes"];
1324 if (NSString *theme = [settings objectForKey:@"Theme"])
1325 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1327 [NSNumber numberWithBool:true], @"Active",
1330 for (NSDictionary *theme in themes) {
1331 NSNumber *active = [theme objectForKey:@"Active"];
1332 if (![active boolValue])
1335 NSString *name = [theme objectForKey:@"Name"];
1339 NSString *theme = nil;
1341 #define testForTheme(format...) \
1342 if (theme == nil) { \
1343 NSString *path = [NSString stringWithFormat:format]; \
1344 if ([Manager_ fileExistsAtPath:path]) { \
1345 [themes_ addObject:path]; \
1350 testForTheme(@"/Library/Themes/%@.theme", name)
1351 testForTheme(@"/Library/Themes/%@", name)
1352 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1356 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1358 for (NSString *theme in themes_)
1359 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
1361 for (NSString *key in [info allKeys])
1362 if ([Info_ objectForKey:key] == nil)
1363 [Info_ setObject:[info objectForKey:key] forKey:key];
1366 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1367 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1368 _mSMSMessageTranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$mSMSMessageTranscriptController$loadView);
1369 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1370 CFNotificationCenterAddObserver(
1371 CFNotificationCenterGetDarwinNotifyCenter(),
1372 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1375 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1376 if (MediaPlayer != nil)
1379 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1380 $MPVideoView = objc_getClass("MPVideoView");
1381 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1383 $SBApplication = objc_getClass("SBApplication");
1384 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1385 $SBAwayView = objc_getClass("SBAwayView");
1386 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1387 $SBButtonBar = objc_getClass("SBButtonBar");
1388 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1389 $SBIcon = objc_getClass("SBIcon");
1390 $SBIconBadge = objc_getClass("SBIconBadge");
1391 $SBIconController = objc_getClass("SBIconController");
1392 $SBIconLabel = objc_getClass("SBIconLabel");
1393 $SBIconList = objc_getClass("SBIconList");
1394 $SBIconModel = objc_getClass("SBIconModel");
1395 //$SBImageCache = objc_getClass("SBImageCache");
1396 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1397 $SBStatusBarController = objc_getClass("SBStatusBarController");
1398 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1399 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1400 $SBUIController = objc_getClass("SBUIController");
1401 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1403 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1405 WBRename(SBApplication, pathForIcon, pathForIcon);
1406 WBRename(SBApplicationIcon, icon, icon);
1407 WBRename(SBBookmarkIcon, icon, icon);
1408 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1409 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1410 WBRename(SBIcon, setAlpha:, setAlpha$);
1411 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1412 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1413 WBRename(SBUIController, init, init);
1414 WBRename(SBWidgetApplicationIcon, icon, icon);
1416 WBRename(SBIconLabel, drawRect:, drawRect$);
1417 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1418 WBRename(SBIconLabel, setInDock:, setInDock$);
1420 WBRename(SBIconList, setFrame:, setFrame$);
1422 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1423 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1425 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1427 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1428 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1429 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1430 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1431 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1432 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1433 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1434 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1435 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1437 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1438 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1441 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1443 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1444 [Info_ setObject:[NSNumber numberWithBool:(
1445 $getTheme$(Wallpapers_) == nil ||
1446 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1447 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1448 )] forKey:@"UndockedIconLabels"];
1451 NSLog(@"WB:Debug:Info = %@", [Info_ description]);