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 // XXX: #import <SpringBoard/SBSearchView.h>
85 #import <SpringBoard/SBStatusBarContentsView.h>
86 #import <SpringBoard/SBStatusBarController.h>
87 #import <SpringBoard/SBStatusBarOperatorNameView.h>
88 #import <SpringBoard/SBStatusBarTimeView.h>
89 #import <SpringBoard/SBUIController.h>
90 #import <SpringBoard/SBWidgetApplicationIcon.h>
92 #import <MobileSMS/mSMSMessageTranscriptController.h>
94 #import <MediaPlayer/MPMoviePlayerController.h>
95 #import <MediaPlayer/MPVideoView.h>
96 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
98 #import <CoreGraphics/CGGeometry.h>
100 extern "C" void __clear_cache (char *beg, char *end);
102 @protocol WinterBoard
106 Class $MPMoviePlayerController;
108 Class $WebCoreFrameBridge;
113 Class $UINavigationBar;
116 Class $SBApplication;
117 Class $SBApplicationIcon;
119 Class $SBBookmarkIcon;
121 Class $SBCalendarIconContentsView;
124 Class $SBIconController;
128 //Class $SBImageCache;
130 Class $SBStatusBarContentsView;
131 Class $SBStatusBarController;
132 Class $SBStatusBarOperatorNameView;
133 Class $SBStatusBarTimeView;
134 Class $SBUIController;
135 Class $SBWidgetApplicationIcon;
137 @interface NSDictionary (WinterBoard)
138 - (UIColor *) wb$colorForKey:(NSString *)key;
139 - (BOOL) wb$boolForKey:(NSString *)key;
142 @implementation NSDictionary (WinterBoard)
144 - (UIColor *) wb$colorForKey:(NSString *)key {
145 NSString *value = [self objectForKey:key];
152 - (BOOL) wb$boolForKey:(NSString *)key {
153 if (NSString *value = [self objectForKey:key])
154 return [value boolValue];
160 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
161 #define $GSFontGetUseLegacyFontMetrics() \
162 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
165 bool Engineer_ = false;
167 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
168 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
169 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
170 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
171 static NSBundle *(*_UIKitBundle)();
172 static int (*_UISharedImageNameGetIdentifier)(NSString *);
173 static UIImage *(*_UISharedImageWithIdentifier)(int);
175 static NSMutableDictionary *UIImages_;
176 static NSMutableDictionary *PathImages_;
177 static NSMutableDictionary *Cache_;
178 static NSMutableDictionary *Strings_;
179 static NSMutableDictionary *Themed_;
180 static NSMutableDictionary *Bundles_;
182 static NSFileManager *Manager_;
183 static NSDictionary *English_;
184 static NSMutableDictionary *Info_;
185 static NSMutableArray *themes_;
187 static NSString *$getTheme$(NSArray *files, bool parent = false) {
189 if (NSString *path = [Themed_ objectForKey:files])
190 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
193 NSLog(@"WB:Debug: %@", [files description]);
197 for (NSString *theme in themes_)
198 for (NSString *file in files) {
199 path = [NSString stringWithFormat:@"%@/%@", theme, file];
200 if ([Manager_ fileExistsAtPath:path]) {
201 path = parent ? theme : path;
209 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
213 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
214 NSString *identifier = [bundle bundleIdentifier];
215 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
217 if (identifier != nil)
218 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
219 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
220 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
222 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
224 #define remapResourceName(oldname, newname) \
225 else if ([file isEqualToString:oldname]) \
226 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
228 if (identifier == nil);
229 else if ([identifier isEqualToString:@"com.apple.calculator"])
230 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
231 else if (![identifier isEqualToString:@"com.apple.springboard"]);
232 remapResourceName(@"FSO_BG.png", @"StatusBar")
233 remapResourceName(@"SBDockBG.png", @"Dock")
234 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
236 if (NSString *path = $getTheme$(names))
241 static NSString *$pathForIcon$(SBApplication *self) {
242 NSString *identifier = [self bundleIdentifier];
243 NSString *path = [self path];
244 NSString *folder = [path lastPathComponent];
245 NSString *dname = [self displayName];
246 NSString *didentifier = [self displayIdentifier];
249 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
251 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
253 if (identifier != nil)
254 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
256 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
258 #define testForIcon(Name) \
259 if (NSString *name = Name) \
260 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
262 testForIcon(identifier);
265 if (didentifier != nil) {
266 testForIcon([English_ objectForKey:didentifier]);
268 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
269 if ([parts count] != 1)
270 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
271 testForIcon([english objectForKey:[parts lastObject]]);
274 if (NSString *path = $getTheme$(names))
279 @interface NSBundle (WinterBoard)
280 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
283 @implementation NSBundle (WinterBoard)
285 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
286 path = [path stringByDeletingLastPathComponent];
287 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
290 NSBundle *bundle([Bundles_ objectForKey:path]);
291 if (reinterpret_cast<id>(bundle) == [NSNull null])
293 else if (bundle == nil) {
294 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
295 bundle = [NSBundle bundleWithPath:path];
297 bundle = [NSBundle wb$bundleWithFile:path];
299 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
300 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
308 @interface NSString (WinterBoard)
309 - (NSString *) wb$themedPath;
312 @implementation NSString (WinterBoard)
314 - (NSString *) wb$themedPath {
316 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
318 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
319 NSString *file([self stringByResolvingSymlinksInPath]);
320 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
321 if ([file hasPrefix:prefix]) {
322 NSUInteger length([prefix length]);
323 if (length != [file length])
324 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
334 void DumpHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
335 NSLog(@"%*s|%2d:%s", indent * 3, "", index, class_getName([view class]));
337 for (UIView *child in [view subviews])
338 DumpHierarchy(child, index++, indent + 1);
341 UIImage *$cacheForImage$(UIImage *image) {
342 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
343 CGRect rect = {CGPointMake(1, 1), [image size]};
344 CGSize size = {rect.size.width + 2, rect.size.height + 2};
346 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
347 CGColorSpaceRelease(space);
349 CGContextDrawImage(context, rect, [image CGImage]);
350 CGImageRef ref(CGBitmapContextCreateImage(context));
351 CGContextRelease(context);
353 UIImage *cache([UIImage imageWithCGImage:ref]);
359 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
360 //if ([name isEqualToString:@"icons"]) return nil;
361 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
364 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
365 NSString *key([icon displayIdentifier]);
367 if (UIImage *image = [icon icon]) {
368 CGSize size = [image size];
369 if (size.width != 59 || size.height != 60) {
370 UIImage *cache($cacheForImage$(image));
371 [Cache_ setObject:cache forKey:key];
376 _SBIconModel$cacheImageForIcon$(self, sel, icon);
379 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
380 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
381 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
383 NSString *key([icon displayIdentifier]);
385 if (UIImage *image = [icon icon]) {
386 CGSize size = [image size];
387 if (size.width != 59 || size.height != 60) {
388 UIImage *cache($cacheForImage$(image));
389 [Cache_ setObject:cache forKey:key];
395 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
396 NSString *key([icon displayIdentifier]);
397 if (UIImage *image = [Cache_ objectForKey:key])
400 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
403 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
405 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
406 NSString *key([icon displayIdentifier]);
407 if (UIImage *image = [Cache_ objectForKey:key])
410 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
413 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
414 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
415 [self setBackgroundColor:[UIColor clearColor]];
416 for (UIView *child in [self subviews])
417 [child setBackgroundColor:[UIColor clearColor]];
421 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
422 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
423 if (NSString *path = $pathForIcon$([self application]))
424 return [UIImage imageWithContentsOfFile:path];
425 return _SBApplicationIcon$icon(self, sel);
428 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
430 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
431 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
432 return [UIImage imageWithContentsOfFile:path];
433 return _SBWidgetApplicationIcon$icon(self, sel);
436 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
438 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
439 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
440 return [UIImage imageWithContentsOfFile:path];
441 return _SBBookmarkIcon$icon(self, sel);
444 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
445 if (NSString *path = $pathForIcon$(self))
447 return _SBApplication$pathForIcon(self, sel);
450 static UIImage *CachedImageAtPath(NSString *path) {
451 path = [path stringByResolvingSymlinksInPath];
452 UIImage *image = [PathImages_ objectForKey:path];
454 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
455 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
457 image = [image autorelease];
458 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
462 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
464 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
465 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
468 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
470 return __UIImageAtPath(name, nil);
472 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
473 UIImage *image = [PathImages_ objectForKey:key];
475 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
477 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
478 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
479 image = CachedImageAtPath(path);
481 image = __UIImageAtPath(name, bundle);
482 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
487 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
488 NSBundle *bundle = [NSBundle mainBundle];
490 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
491 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
492 return CachedImageAtPath(path);
493 return __UIApplicationImageWithName(name);
496 #define WBDelegate(delegate) \
497 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
499 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
500 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
502 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
506 - (void) forwardInvocation:(NSInvocation*)inv { \
507 SEL sel = [inv selector]; \
508 if ([delegate respondsToSelector:sel]) \
509 [inv invokeWithTarget:delegate]; \
511 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
514 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
515 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
517 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
518 if (NSString *path = $pathForFile$inBundle$(file, self, false))
520 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
523 void $setBarStyle$_(NSString *name, int &style) {
525 NSLog(@"WB:Debug:%@Style:%d", name, style);
526 NSNumber *number = nil;
528 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
530 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
532 style = [number intValue];
534 NSLog(@"WB:Debug:%@Style=%d", name, style);
538 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
539 NSBundle *bundle([NSBundle mainBundle]);
541 CFLocaleRef locale(CFLocaleCopyCurrent());
542 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
545 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
547 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
548 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
549 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
550 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
554 CFRelease(formatter);
556 NSString *datestyle(@""
557 "font-family: Helvetica; "
558 "font-weight: bold; "
564 NSString *daystyle(@""
565 "font-family: Helvetica; "
566 "font-weight: bold; "
569 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
572 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
573 datestyle = [datestyle stringByAppendingString:style];
574 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
575 daystyle = [daystyle stringByAppendingString:style];
577 float width([self bounds].size.width);
579 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
580 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
582 unsigned base($GSFontGetUseLegacyFontMetrics() ? 71 : 70);
584 [(NSString *)date drawAtPoint:CGPointMake(
585 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
586 ) withStyle:datestyle];
588 [(NSString *)day drawAtPoint:CGPointMake(
589 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
590 ) withStyle:daystyle];
596 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
599 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
600 style = [number intValue];
602 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
605 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
608 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
609 self = [self wb$initWithCoder:coder];
612 UINavigationBar$setBarStyle$_(self);
616 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
617 self = [self wb$initWithFrame:frame];
620 UINavigationBar$setBarStyle$_(self);
624 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
625 $setBarStyle$_(@"Toolbar", style);
626 return _UIToolbar$setBarStyle$(self, sel, style);
629 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
630 $setBarStyle$_(@"NavigationBar", style);
631 return _UINavigationBar$setBarStyle$(self, sel, style);
634 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
635 [[self superview] setBackgroundColor:[UIColor clearColor]];
636 _SBButtonBar$didMoveToSuperview(self, sel);
639 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
640 [[self superview] setBackgroundColor:[UIColor clearColor]];
641 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
644 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
646 NSLog(@"WB:Debug:DefaultDesktopImage");
647 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
648 return [UIImage imageWithContentsOfFile:path];
649 return _UIImage$defaultDesktopImage(self, sel);
652 static NSArray *Wallpapers_;
653 static NSString *WallpaperFile_;
654 static UIImageView *WallpaperImage_;
655 static UIWebDocumentView *WallpaperPage_;
656 static NSURL *WallpaperURL_;
658 #define _release(object) \
659 do if (object != nil) { \
664 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
665 self = _SBUIController$init(self, sel);
669 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
670 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
671 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
674 if (&_contentLayer != NULL)
675 layer = _contentLayer;
676 else if (&_contentView != NULL)
677 layer = _contentView;
681 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
682 [content setBackgroundColor:[layer backgroundColor]];
683 [layer setBackgroundColor:[UIColor clearColor]];
684 [layer setFrame:[content bounds]];
685 [_window setContentView:content];
687 _release(WallpaperFile_);
688 _release(WallpaperImage_);
689 _release(WallpaperPage_);
690 _release(WallpaperURL_);
692 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
693 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
694 if ([Manager_ fileExistsAtPath:mp4]) {
698 static AVController *controller_(nil);
699 if (controller_ == nil) {
700 AVQueue *queue([AVQueue avQueue]);
701 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
704 AVQueue *queue([controller_ queue]);
706 UIView *video([[[UIView alloc] initWithFrame:[content bounds]] autorelease]);
707 [controller_ setLayer:[video _layer]];
709 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
710 [queue appendItem:item error:&error];
712 [controller_ play:&error];
713 #elif UseMPMoviePlayerController
714 NSURL *url([NSURL fileURLWithPath:mp4]);
715 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
716 controller.movieControlMode = MPMovieControlModeHidden;
719 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[content bounds]] autorelease];
720 [video setMovieWithPath:mp4];
721 [video setRepeatMode:1];
722 [video setRepeatGap:-1];
723 [video playFromBeginning];;
726 [content addSubview:video];
729 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
730 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
733 if ([Manager_ fileExistsAtPath:png])
735 else if ([Manager_ fileExistsAtPath:jpg])
741 image = [[UIImage alloc] initWithContentsOfFile:path];
743 image = [image autorelease];
747 WallpaperFile_ = [path retain];
748 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
749 [content addSubview:WallpaperImage_];
752 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
753 if ([Manager_ fileExistsAtPath:html]) {
754 CGRect bounds = [content bounds];
756 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
757 [view setAutoresizes:true];
759 WallpaperPage_ = [view retain];
760 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
762 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
764 [view setBackgroundColor:[UIColor clearColor]];
765 if ([view respondsToSelector:@selector(setDrawsBackground:)])
766 [view setDrawsBackground:NO];
767 [[view webView] setDrawsBackground:NO];
769 [content addSubview:view];
773 for (size_t i(0), e([themes_ count]); i != e; ++i) {
774 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
775 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
776 if ([Manager_ fileExistsAtPath:html]) {
777 CGRect bounds = [content bounds];
779 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
780 [view setAutoresizes:true];
782 NSURL *url = [NSURL fileURLWithPath:html];
783 [view loadRequest:[NSURLRequest requestWithURL:url]];
785 [view setBackgroundColor:[UIColor clearColor]];
786 if ([view respondsToSelector:@selector(setDrawsBackground:)])
787 [view setDrawsBackground:NO];
788 [[view webView] setDrawsBackground:NO];
790 [content addSubview:view];
794 [content addSubview:layer];
795 DumpHierarchy(_window);
800 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
801 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
802 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
804 if (path != nil && _backgroundView != nil)
807 _SBAwayView$updateDesktopImage$(self, sel, image);
810 CGRect bounds = [self bounds];
812 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
813 [view setAutoresizes:true];
815 if (WallpaperPage_ != nil)
816 [WallpaperPage_ release];
817 WallpaperPage_ = [view retain];
819 if (WallpaperURL_ != nil)
820 [WallpaperURL_ release];
821 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
823 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
825 [[view webView] setDrawsBackground:false];
826 [view setBackgroundColor:[UIColor clearColor]];
828 [self insertSubview:view aboveSubview:_backgroundView];
832 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
833 extern "C" CGColorRef CGGStateGetFillColor(void *);
834 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
835 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
837 /* WBTimeLabel {{{ */
838 @interface WBTimeLabel : NSProxy {
840 _transient SBStatusBarTimeView *view_;
843 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
847 @implementation WBTimeLabel
854 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
855 time_ = [time retain];
860 - (NSString *) description {
866 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
867 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
868 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
870 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
871 "font-family: Helvetica; "
872 "font-weight: bold; "
875 "%@", _mode ? @"white" : @"black", custom]];
880 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
885 /* WBBadgeLabel {{{ */
886 @interface WBBadgeLabel : NSProxy {
890 - (id) initWithBadge:(NSString *)badge;
894 @implementation WBBadgeLabel
901 - (id) initWithBadge:(NSString *)badge {
902 badge_ = [badge retain];
908 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
909 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
910 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
911 "font-family: Helvetica; "
912 "font-weight: bold; "
920 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
926 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
927 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
928 alpha = [number floatValue];
929 return _SBIcon$setAlpha$(self, sel, alpha);
932 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
933 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
934 id &_badge(MSHookIvar<id>(self, "_badge"));
936 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
941 void SBStatusBarController$setStatusBarMode(int &mode) {
943 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
944 if (mode < 100) // 104:hidden 105:glowing
945 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
946 mode = [number intValue];
949 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
950 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
951 SBStatusBarController$setStatusBarMode(mode);
952 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
955 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
956 NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
957 SBStatusBarController$setStatusBarMode(mode);
958 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
961 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) {
962 NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
963 SBStatusBarController$setStatusBarMode(mode);
964 NSLog(@"mode=%u", mode);
965 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
968 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
969 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
970 mode = [number intValue];
971 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
974 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
975 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
977 NSLog(@"operatorNameStyle= %@", style);
978 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
979 style = [NSString stringWithFormat:@"%@; %@", style, custom];
983 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
985 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
986 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
989 // XXX: replace this with [SBStatusBarTimeView tile]
990 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
991 id &_time(MSHookIvar<id>(self, "_time"));
992 if (_time != nil && [_time class] != [WBTimeLabel class])
993 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
994 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
997 @interface UIView (WinterBoard)
998 - (bool) wb$isWBImageView;
1001 @implementation UIView (WinterBoard)
1003 - (bool) wb$isWBImageView {
1009 @interface WBImageView : UIImageView {
1012 - (bool) wb$isWBImageView;
1013 - (void) wb$updateFrame;
1016 @implementation WBImageView
1018 - (bool) wb$isWBImageView {
1022 - (void) wb$updateFrame {
1023 CGRect frame([self frame]);
1026 for (UIView *view(self); ; ) {
1027 view = [view superview];
1030 frame.origin.y -= [view frame].origin.y;
1033 [self setFrame:frame];
1038 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1039 NSArray *subviews([self subviews]);
1040 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1041 if (view != nil && [view wb$isWBImageView])
1042 [view wb$updateFrame];
1043 _SBIconList$setFrame$(self, sel, frame);
1046 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1047 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1048 NSArray *lists([_iconModel iconLists]);
1050 for (unsigned i(0), e([lists count]); i != e; ++i)
1051 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1052 SBIconList *list([lists objectAtIndex:i]);
1053 NSArray *subviews([list subviews]);
1055 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1056 if (view == nil || ![view wb$isWBImageView]) {
1057 view = [[[WBImageView alloc] init] autorelease];
1058 [list insertSubview:view atIndex:0];
1061 UIImage *image([UIImage imageWithContentsOfFile:path]);
1063 CGRect frame([view frame]);
1064 frame.size = [image size];
1065 [view setFrame:frame];
1067 [view setImage:image];
1068 [view wb$updateFrame];
1071 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1074 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1075 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1077 [self setClipsToBounds:NO];
1081 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1082 id &_label(MSHookIvar<id>(self, "_label"));
1083 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1085 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1086 [_label setInDock:docked];
1087 return _SBIconLabel$setInDock$(self, sel, docked);
1090 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1091 NSString *identifier = [self bundleIdentifier];
1092 NSLocale *locale = [NSLocale currentLocale];
1093 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1095 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1096 NSString *file = table == nil ? @"Localizable" : table;
1097 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1098 NSDictionary *strings;
1099 if ((strings = [Strings_ objectForKey:name]) != nil) {
1100 if (static_cast<id>(strings) != [NSNull null]) strings:
1101 if (NSString *value = [strings objectForKey:key])
1103 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1106 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1107 [Strings_ setObject:[strings autorelease] forKey:name];
1111 [Strings_ setObject:[NSNull null] forKey:name];
1112 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1115 @class WebCoreFrameBridge;
1116 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1119 void **core(reinterpret_cast<void **>([node _node]));
1120 if (core == NULL || core[6] == NULL)
1122 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1125 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1126 CGRect bounds = [self bounds];
1128 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1131 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1132 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1134 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1136 NSString *style = [NSString stringWithFormat:@""
1137 "font-family: Helvetica; "
1138 "font-weight: bold; "
1141 "", docked ? @"white" : @"#b3b3b3"];
1144 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1146 bool ellipsis(false);
1147 float max = 75, width;
1149 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1152 size_t length([label length]);
1153 float spacing((width - max) / (length - 1));
1155 if (spacing > 1.25) {
1157 label = [label substringToIndex:(length - 1)];
1161 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1165 label = [label stringByAppendingString:@"..."];
1167 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1168 style = [style stringByAppendingString:custom];
1170 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1171 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1174 MSHook(void, mSMSMessageTranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1175 _mSMSMessageTranscriptController$loadView(self, sel);
1177 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1178 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1179 [image autorelease];
1180 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1181 UIView *parent([_transcriptLayer superview]);
1182 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1183 [parent insertSubview:background belowSubview:_transcriptLayer];
1184 [_transcriptLayer setBackgroundColor:[UIColor clearColor]];
1188 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1189 int id(_UISharedImageNameGetIdentifier(name));
1191 NSLog(@"WB:Debug: _UIImageWithName(\"%@\", %d)", name, id);
1194 return _UIImageAtPath(name, _UIKitBundle());
1196 NSNumber *key([NSNumber numberWithInt:id]);
1197 UIImage *image = [UIImages_ objectForKey:key];
1199 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1200 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1201 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1203 [image autorelease];
1206 image = _UISharedImageWithIdentifier(id);
1207 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1212 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1213 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
1214 UIImage *image = [PathImages_ objectForKey:key];
1216 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1218 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1219 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1220 image = [[UIImage alloc] initWithContentsOfFile:path];
1222 [image autorelease];
1225 image = __UIImageWithNameInDomain(name, domain);
1226 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1230 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1231 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1232 name = [font UTF8String];
1233 return _GSFontCreateWithName(name, traits, size);
1236 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1237 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1239 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1241 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1242 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1244 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1247 NSString *path = [NSString stringWithUTF8String:a1];
1248 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1249 NSString *file = [path substringFromIndex:31];
1250 for (NSString *theme in themes_) {
1251 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1252 if ([Manager_ fileExistsAtPath:path]) {
1253 strcpy(a1, [path UTF8String]);
1262 static void ChangeWallpaper(
1263 CFNotificationCenterRef center,
1267 CFDictionaryRef info
1270 NSLog(@"WB:Debug:ChangeWallpaper!");
1273 if (WallpaperFile_ != nil) {
1274 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1276 image = [image autorelease];
1279 if (WallpaperImage_ != nil)
1280 [WallpaperImage_ setImage:image];
1281 if (WallpaperPage_ != nil)
1282 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1286 #define WBRename(name, sel, imp) \
1287 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1289 extern "C" void WBInitialize() {
1290 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1292 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1294 NSLog(@"WB:Notice: WinterBoard");
1296 _GSFontGetUseLegacyFontMetrics = reinterpret_cast<BOOL (*)()>(dlsym(RTLD_DEFAULT, "GSFontGetUseLegacyFontMetrics"));
1299 memset(nl, 0, sizeof(nl));
1301 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1302 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1303 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1304 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1305 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1306 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1307 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1311 _UIApplicationImageWithName = (UIImage *(*)(NSString *)) nl[0].n_value;
1312 _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[1].n_value;
1313 _UIImageRefAtPath = (CGImageRef (*)(NSString *, bool, UIImageOrientation *)) nl[2].n_value;
1314 _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[3].n_value;
1315 _UIKitBundle = (NSBundle *(*)()) nl[4].n_value;
1316 _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[5].n_value;
1317 _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[6].n_value;
1319 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1320 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1321 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1322 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1324 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1326 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1328 memset(nl, 0, sizeof(nl));
1329 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1330 nlist(AudioToolbox, nl);
1331 _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value;
1332 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1335 $NSBundle = objc_getClass("NSBundle");
1337 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1338 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1340 $UIImage = objc_getClass("UIImage");
1341 $UINavigationBar = objc_getClass("UINavigationBar");
1342 $UIToolbar = objc_getClass("UIToolbar");
1344 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1346 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1347 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1349 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1350 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1352 Manager_ = [[NSFileManager defaultManager] retain];
1353 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1354 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1355 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1356 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1357 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1359 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1361 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1362 [settings autorelease];
1364 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1365 Debug_ = [debug boolValue];
1367 NSArray *themes = [settings objectForKey:@"Themes"];
1369 if (NSString *theme = [settings objectForKey:@"Theme"])
1370 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1372 [NSNumber numberWithBool:true], @"Active",
1375 for (NSDictionary *theme in themes) {
1376 NSNumber *active = [theme objectForKey:@"Active"];
1377 if (![active boolValue])
1380 NSString *name = [theme objectForKey:@"Name"];
1384 NSString *theme = nil;
1386 #define testForTheme(format...) \
1387 if (theme == nil) { \
1388 NSString *path = [NSString stringWithFormat:format]; \
1389 if ([Manager_ fileExistsAtPath:path]) { \
1390 [themes_ addObject:path]; \
1395 testForTheme(@"/Library/Themes/%@.theme", name)
1396 testForTheme(@"/Library/Themes/%@", name)
1397 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1401 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1403 for (NSString *theme in themes_)
1404 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
1406 for (NSString *key in [info allKeys])
1407 if ([Info_ objectForKey:key] == nil)
1408 [Info_ setObject:[info objectForKey:key] forKey:key];
1411 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1412 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1413 _mSMSMessageTranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$mSMSMessageTranscriptController$loadView);
1414 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1415 CFNotificationCenterAddObserver(
1416 CFNotificationCenterGetDarwinNotifyCenter(),
1417 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1420 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1421 if (MediaPlayer != nil)
1424 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1425 $MPVideoView = objc_getClass("MPVideoView");
1426 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1428 $SBApplication = objc_getClass("SBApplication");
1429 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1430 $SBAwayView = objc_getClass("SBAwayView");
1431 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1432 $SBButtonBar = objc_getClass("SBButtonBar");
1433 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1434 $SBIcon = objc_getClass("SBIcon");
1435 $SBIconBadge = objc_getClass("SBIconBadge");
1436 $SBIconController = objc_getClass("SBIconController");
1437 $SBIconLabel = objc_getClass("SBIconLabel");
1438 $SBIconList = objc_getClass("SBIconList");
1439 $SBIconModel = objc_getClass("SBIconModel");
1440 //$SBImageCache = objc_getClass("SBImageCache");
1441 $SBSearchView = objc_getClass("SBSearchView");
1442 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1443 $SBStatusBarController = objc_getClass("SBStatusBarController");
1444 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1445 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1446 $SBUIController = objc_getClass("SBUIController");
1447 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1449 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1451 WBRename(SBApplication, pathForIcon, pathForIcon);
1452 WBRename(SBApplicationIcon, icon, icon);
1453 WBRename(SBBookmarkIcon, icon, icon);
1454 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1455 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1456 WBRename(SBIcon, setAlpha:, setAlpha$);
1457 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1458 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1459 WBRename(SBUIController, init, init);
1460 WBRename(SBWidgetApplicationIcon, icon, icon);
1462 WBRename(SBIconLabel, drawRect:, drawRect$);
1463 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1464 WBRename(SBIconLabel, setInDock:, setInDock$);
1466 WBRename(SBIconList, setFrame:, setFrame$);
1468 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1469 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1470 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1471 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1473 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1475 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1477 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1478 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1479 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1480 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1481 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1482 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1483 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1484 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1485 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1487 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1488 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1491 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1493 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1494 [Info_ setObject:[NSNumber numberWithBool:(
1495 $getTheme$(Wallpapers_) == nil ||
1496 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1497 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1498 )] forKey:@"UndockedIconLabels"];
1501 NSLog(@"WB:Debug:Info = %@", [Info_ description]);