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/SBSearchTableViewCell.h>
86 #import <SpringBoard/SBStatusBarContentsView.h>
87 #import <SpringBoard/SBStatusBarController.h>
88 #import <SpringBoard/SBStatusBarOperatorNameView.h>
89 #import <SpringBoard/SBStatusBarTimeView.h>
90 #import <SpringBoard/SBUIController.h>
91 #import <SpringBoard/SBWidgetApplicationIcon.h>
93 #import <MobileSMS/mSMSMessageTranscriptController.h>
95 #import <MediaPlayer/MPMoviePlayerController.h>
96 #import <MediaPlayer/MPVideoView.h>
97 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
99 #import <CoreGraphics/CGGeometry.h>
101 extern "C" void __clear_cache (char *beg, char *end);
103 @protocol WinterBoard
107 Class $MPMoviePlayerController;
109 Class $WebCoreFrameBridge;
114 Class $UINavigationBar;
117 Class $SBApplication;
118 Class $SBApplicationIcon;
120 Class $SBBookmarkIcon;
122 Class $SBCalendarIconContentsView;
125 Class $SBIconController;
129 //Class $SBImageCache;
131 Class $SBSearchTableViewCell;
132 Class $SBStatusBarContentsView;
133 Class $SBStatusBarController;
134 Class $SBStatusBarOperatorNameView;
135 Class $SBStatusBarTimeView;
136 Class $SBUIController;
137 Class $SBWidgetApplicationIcon;
139 @interface NSDictionary (WinterBoard)
140 - (UIColor *) wb$colorForKey:(NSString *)key;
141 - (BOOL) wb$boolForKey:(NSString *)key;
144 @implementation NSDictionary (WinterBoard)
146 - (UIColor *) wb$colorForKey:(NSString *)key {
147 NSString *value = [self objectForKey:key];
154 - (BOOL) wb$boolForKey:(NSString *)key {
155 if (NSString *value = [self objectForKey:key])
156 return [value boolValue];
162 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
163 #define $GSFontGetUseLegacyFontMetrics() \
164 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
167 bool Engineer_ = false;
169 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
170 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
171 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
172 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
173 static NSBundle *(*_UIKitBundle)();
174 static int (*_UISharedImageNameGetIdentifier)(NSString *);
175 static UIImage *(*_UISharedImageWithIdentifier)(int);
177 static NSMutableDictionary *UIImages_;
178 static NSMutableDictionary *PathImages_;
179 static NSMutableDictionary *Cache_;
180 static NSMutableDictionary *Strings_;
181 static NSMutableDictionary *Themed_;
182 static NSMutableDictionary *Bundles_;
184 static NSFileManager *Manager_;
185 static NSDictionary *English_;
186 static NSMutableDictionary *Info_;
187 static NSMutableArray *themes_;
189 static NSString *$getTheme$(NSArray *files, bool parent = false) {
191 if (NSString *path = [Themed_ objectForKey:files])
192 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
195 NSLog(@"WB:Debug: %@", [files description]);
199 for (NSString *theme in themes_)
200 for (NSString *file in files) {
201 path = [NSString stringWithFormat:@"%@/%@", theme, file];
202 if ([Manager_ fileExistsAtPath:path]) {
203 path = parent ? theme : path;
211 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
215 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
216 NSString *identifier = [bundle bundleIdentifier];
217 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
219 if (identifier != nil)
220 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
221 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
222 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
224 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
226 #define remapResourceName(oldname, newname) \
227 else if ([file isEqualToString:oldname]) \
228 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
230 if (identifier == nil);
231 else if ([identifier isEqualToString:@"com.apple.calculator"])
232 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
233 else if (![identifier isEqualToString:@"com.apple.springboard"]);
234 remapResourceName(@"FSO_BG.png", @"StatusBar")
235 remapResourceName(@"SBDockBG.png", @"Dock")
236 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
238 if (NSString *path = $getTheme$(names))
243 static NSString *$pathForIcon$(SBApplication *self) {
244 NSString *identifier = [self bundleIdentifier];
245 NSString *path = [self path];
246 NSString *folder = [path lastPathComponent];
247 NSString *dname = [self displayName];
248 NSString *didentifier = [self displayIdentifier];
251 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
253 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
255 if (identifier != nil)
256 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
258 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
260 #define testForIcon(Name) \
261 if (NSString *name = Name) \
262 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
264 testForIcon(identifier);
267 if (didentifier != nil) {
268 testForIcon([English_ objectForKey:didentifier]);
270 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
271 if ([parts count] != 1)
272 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
273 testForIcon([english objectForKey:[parts lastObject]]);
276 if (NSString *path = $getTheme$(names))
281 @interface NSBundle (WinterBoard)
282 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
285 @implementation NSBundle (WinterBoard)
287 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
288 path = [path stringByDeletingLastPathComponent];
289 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
292 NSBundle *bundle([Bundles_ objectForKey:path]);
293 if (reinterpret_cast<id>(bundle) == [NSNull null])
295 else if (bundle == nil) {
296 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
297 bundle = [NSBundle bundleWithPath:path];
299 bundle = [NSBundle wb$bundleWithFile:path];
301 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
302 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
310 @interface NSString (WinterBoard)
311 - (NSString *) wb$themedPath;
314 @implementation NSString (WinterBoard)
316 - (NSString *) wb$themedPath {
318 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
320 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
321 NSString *file([self stringByResolvingSymlinksInPath]);
322 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
323 if ([file hasPrefix:prefix]) {
324 NSUInteger length([prefix length]);
325 if (length != [file length])
326 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
336 void WBLogRect(const char *tag, struct CGRect rect) {
337 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
340 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
341 CGRect frame([view frame]);
342 NSLog(@"%*s|%2d:%s : {%f,%f+%f,%f} (%@)", indent * 3, "", index, class_getName([view class]), frame.origin.x, frame.origin.y, frame.size.width, frame.size.height, [view backgroundColor]);
344 for (UIView *child in [view subviews])
345 WBLogHierarchy(child, index++, indent + 1);
348 UIImage *$cacheForImage$(UIImage *image) {
349 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
350 CGRect rect = {CGPointMake(1, 1), [image size]};
351 CGSize size = {rect.size.width + 2, rect.size.height + 2};
353 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
354 CGColorSpaceRelease(space);
356 CGContextDrawImage(context, rect, [image CGImage]);
357 CGImageRef ref(CGBitmapContextCreateImage(context));
358 CGContextRelease(context);
360 UIImage *cache([UIImage imageWithCGImage:ref]);
366 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
367 //if ([name isEqualToString:@"icons"]) return nil;
368 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
371 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
372 NSString *key([icon displayIdentifier]);
374 if (UIImage *image = [icon icon]) {
375 CGSize size = [image size];
376 if (size.width != 59 || size.height != 60) {
377 UIImage *cache($cacheForImage$(image));
378 [Cache_ setObject:cache forKey:key];
383 _SBIconModel$cacheImageForIcon$(self, sel, icon);
386 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
387 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
388 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
390 NSString *key([icon displayIdentifier]);
392 if (UIImage *image = [icon icon]) {
393 CGSize size = [image size];
394 if (size.width != 59 || size.height != 60) {
395 UIImage *cache($cacheForImage$(image));
396 [Cache_ setObject:cache forKey:key];
402 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
403 NSString *key([icon displayIdentifier]);
404 if (UIImage *image = [Cache_ objectForKey:key])
407 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
410 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
412 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
413 NSString *key([icon displayIdentifier]);
414 if (UIImage *image = [Cache_ objectForKey:key])
417 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
420 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
421 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
422 [self setBackgroundColor:[UIColor clearColor]];
423 for (UIView *child in [self subviews])
424 [child setBackgroundColor:[UIColor clearColor]];
428 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
429 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
430 [self setBackgroundColor:[UIColor clearColor]];
434 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
435 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
436 float inset([self edgeInset]);
437 [[UIColor clearColor] set];
438 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
439 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
442 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
443 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
444 if (NSString *path = $pathForIcon$([self application]))
445 return [UIImage imageWithContentsOfFile:path];
446 return _SBApplicationIcon$icon(self, sel);
449 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
451 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
452 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
453 return [UIImage imageWithContentsOfFile:path];
454 return _SBWidgetApplicationIcon$icon(self, sel);
457 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
459 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
460 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
461 return [UIImage imageWithContentsOfFile:path];
462 return _SBBookmarkIcon$icon(self, sel);
465 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
466 if (NSString *path = $pathForIcon$(self))
468 return _SBApplication$pathForIcon(self, sel);
471 static UIImage *CachedImageAtPath(NSString *path) {
472 path = [path stringByResolvingSymlinksInPath];
473 UIImage *image = [PathImages_ objectForKey:path];
475 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
476 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
478 image = [image autorelease];
479 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
483 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
485 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
486 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
489 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
491 return __UIImageAtPath(name, nil);
493 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
494 UIImage *image = [PathImages_ objectForKey:key];
496 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
498 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
499 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
500 image = CachedImageAtPath(path);
502 image = __UIImageAtPath(name, bundle);
503 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
508 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
509 NSBundle *bundle = [NSBundle mainBundle];
511 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
512 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
513 return CachedImageAtPath(path);
514 return __UIApplicationImageWithName(name);
517 #define WBDelegate(delegate) \
518 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
520 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
521 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
523 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
527 - (void) forwardInvocation:(NSInvocation*)inv { \
528 SEL sel = [inv selector]; \
529 if ([delegate respondsToSelector:sel]) \
530 [inv invokeWithTarget:delegate]; \
532 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
535 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
536 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
538 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
539 if (NSString *path = $pathForFile$inBundle$(file, self, false))
541 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
544 void $setBarStyle$_(NSString *name, int &style) {
546 NSLog(@"WB:Debug:%@Style:%d", name, style);
547 NSNumber *number = nil;
549 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
551 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
553 style = [number intValue];
555 NSLog(@"WB:Debug:%@Style=%d", name, style);
559 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
560 NSBundle *bundle([NSBundle mainBundle]);
562 CFLocaleRef locale(CFLocaleCopyCurrent());
563 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
566 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
568 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
569 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
570 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
571 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
575 CFRelease(formatter);
577 NSString *datestyle(@""
578 "font-family: Helvetica; "
579 "font-weight: bold; "
585 NSString *daystyle(@""
586 "font-family: Helvetica; "
587 "font-weight: bold; "
590 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
593 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
594 datestyle = [datestyle stringByAppendingString:style];
595 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
596 daystyle = [daystyle stringByAppendingString:style];
598 float width([self bounds].size.width);
600 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
601 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
603 unsigned base($GSFontGetUseLegacyFontMetrics() ? 71 : 70);
605 [(NSString *)date drawAtPoint:CGPointMake(
606 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
607 ) withStyle:datestyle];
609 [(NSString *)day drawAtPoint:CGPointMake(
610 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
611 ) withStyle:daystyle];
617 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
620 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
621 style = [number intValue];
623 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
626 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
629 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
630 self = [self wb$initWithCoder:coder];
633 UINavigationBar$setBarStyle$_(self);
637 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
638 self = [self wb$initWithFrame:frame];
641 UINavigationBar$setBarStyle$_(self);
645 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
646 $setBarStyle$_(@"Toolbar", style);
647 return _UIToolbar$setBarStyle$(self, sel, style);
650 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
651 $setBarStyle$_(@"NavigationBar", style);
652 return _UINavigationBar$setBarStyle$(self, sel, style);
655 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
656 [[self superview] setBackgroundColor:[UIColor clearColor]];
657 _SBButtonBar$didMoveToSuperview(self, sel);
660 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
661 [[self superview] setBackgroundColor:[UIColor clearColor]];
662 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
665 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
667 NSLog(@"WB:Debug:DefaultDesktopImage");
668 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
669 return [UIImage imageWithContentsOfFile:path];
670 return _UIImage$defaultDesktopImage(self, sel);
673 static NSArray *Wallpapers_;
674 static NSString *WallpaperFile_;
675 static UIImageView *WallpaperImage_;
676 static UIWebDocumentView *WallpaperPage_;
677 static NSURL *WallpaperURL_;
679 #define _release(object) \
680 do if (object != nil) { \
685 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
686 self = _SBUIController$init(self, sel);
690 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
691 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
692 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
695 if (&_contentLayer != NULL)
696 layer = _contentLayer;
697 else if (&_contentView != NULL)
698 layer = _contentView;
702 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
703 [content setBackgroundColor:[layer backgroundColor]];
704 [layer setBackgroundColor:[UIColor clearColor]];
705 [layer setFrame:[content bounds]];
706 [_window setContentView:content];
708 _release(WallpaperFile_);
709 _release(WallpaperImage_);
710 _release(WallpaperPage_);
711 _release(WallpaperURL_);
713 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
714 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
715 if ([Manager_ fileExistsAtPath:mp4]) {
719 static AVController *controller_(nil);
720 if (controller_ == nil) {
721 AVQueue *queue([AVQueue avQueue]);
722 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
725 AVQueue *queue([controller_ queue]);
727 UIView *video([[[UIView alloc] initWithFrame:[content bounds]] autorelease]);
728 [controller_ setLayer:[video _layer]];
730 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
731 [queue appendItem:item error:&error];
733 [controller_ play:&error];
734 #elif UseMPMoviePlayerController
735 NSURL *url([NSURL fileURLWithPath:mp4]);
736 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
737 controller.movieControlMode = MPMovieControlModeHidden;
740 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[content bounds]] autorelease];
741 [video setMovieWithPath:mp4];
742 [video setRepeatMode:1];
743 [video setRepeatGap:-1];
744 [video playFromBeginning];;
747 [content addSubview:video];
750 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
751 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
754 if ([Manager_ fileExistsAtPath:png])
756 else if ([Manager_ fileExistsAtPath:jpg])
762 image = [[UIImage alloc] initWithContentsOfFile:path];
764 image = [image autorelease];
768 WallpaperFile_ = [path retain];
769 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
770 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
771 [WallpaperImage_ setAlpha:[number floatValue]];
772 [content addSubview:WallpaperImage_];
775 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
776 if ([Manager_ fileExistsAtPath:html]) {
777 CGRect bounds = [content bounds];
779 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
780 [view setAutoresizes:true];
782 WallpaperPage_ = [view retain];
783 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
785 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
787 [view setBackgroundColor:[UIColor clearColor]];
788 if ([view respondsToSelector:@selector(setDrawsBackground:)])
789 [view setDrawsBackground:NO];
790 [[view webView] setDrawsBackground:NO];
792 [content addSubview:view];
796 for (size_t i(0), e([themes_ count]); i != e; ++i) {
797 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
798 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
799 if ([Manager_ fileExistsAtPath:html]) {
800 CGRect bounds = [content bounds];
802 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
803 [view setAutoresizes:true];
805 NSURL *url = [NSURL fileURLWithPath:html];
806 [view loadRequest:[NSURLRequest requestWithURL:url]];
808 [view setBackgroundColor:[UIColor clearColor]];
809 if ([view respondsToSelector:@selector(setDrawsBackground:)])
810 [view setDrawsBackground:NO];
811 [[view webView] setDrawsBackground:NO];
813 [content addSubview:view];
817 [content addSubview:layer];
818 WBLogHierarchy(_window);
823 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
824 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
825 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
827 if (path != nil && _backgroundView != nil)
830 _SBAwayView$updateDesktopImage$(self, sel, image);
833 CGRect bounds = [self bounds];
835 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
836 [view setAutoresizes:true];
838 if (WallpaperPage_ != nil)
839 [WallpaperPage_ release];
840 WallpaperPage_ = [view retain];
842 if (WallpaperURL_ != nil)
843 [WallpaperURL_ release];
844 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
846 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
848 [[view webView] setDrawsBackground:false];
849 [view setBackgroundColor:[UIColor clearColor]];
851 [self insertSubview:view aboveSubview:_backgroundView];
855 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
856 extern "C" CGColorRef CGGStateGetFillColor(void *);
857 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
858 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
860 /* WBTimeLabel {{{ */
861 @interface WBTimeLabel : NSProxy {
863 _transient SBStatusBarTimeView *view_;
866 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
870 @implementation WBTimeLabel
877 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
878 time_ = [time retain];
883 - (NSString *) description {
889 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
890 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
891 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
893 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
894 "font-family: Helvetica; "
895 "font-weight: bold; "
898 "%@", _mode ? @"white" : @"black", custom]];
903 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
908 /* WBBadgeLabel {{{ */
909 @interface WBBadgeLabel : NSProxy {
913 - (id) initWithBadge:(NSString *)badge;
917 @implementation WBBadgeLabel
924 - (id) initWithBadge:(NSString *)badge {
925 badge_ = [badge retain];
931 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
932 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
933 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
934 "font-family: Helvetica; "
935 "font-weight: bold; "
943 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
949 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
950 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
951 alpha = [number floatValue];
952 return _SBIcon$setAlpha$(self, sel, alpha);
955 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
956 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
957 id &_badge(MSHookIvar<id>(self, "_badge"));
959 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
964 void SBStatusBarController$setStatusBarMode(int &mode) {
966 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
967 if (mode < 100) // 104:hidden 105:glowing
968 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
969 mode = [number intValue];
972 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
973 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
974 SBStatusBarController$setStatusBarMode(mode);
975 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
978 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
979 NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
980 SBStatusBarController$setStatusBarMode(mode);
981 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
984 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) {
985 NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
986 SBStatusBarController$setStatusBarMode(mode);
987 NSLog(@"mode=%u", mode);
988 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
991 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
992 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
993 mode = [number intValue];
994 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
997 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
998 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1000 NSLog(@"operatorNameStyle= %@", style);
1001 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1002 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1006 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1008 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1009 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1012 // XXX: replace this with [SBStatusBarTimeView tile]
1013 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1014 id &_time(MSHookIvar<id>(self, "_time"));
1015 if (_time != nil && [_time class] != [WBTimeLabel class])
1016 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1017 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1020 @interface UIView (WinterBoard)
1021 - (bool) wb$isWBImageView;
1024 @implementation UIView (WinterBoard)
1026 - (bool) wb$isWBImageView {
1032 @interface WBImageView : UIImageView {
1035 - (bool) wb$isWBImageView;
1036 - (void) wb$updateFrame;
1039 @implementation WBImageView
1041 - (bool) wb$isWBImageView {
1045 - (void) wb$updateFrame {
1046 CGRect frame([self frame]);
1049 for (UIView *view(self); ; ) {
1050 view = [view superview];
1053 frame.origin.y -= [view frame].origin.y;
1056 [self setFrame:frame];
1061 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1062 NSArray *subviews([self subviews]);
1063 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1064 if (view != nil && [view wb$isWBImageView])
1065 [view wb$updateFrame];
1066 _SBIconList$setFrame$(self, sel, frame);
1069 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1070 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1071 NSArray *lists([_iconModel iconLists]);
1073 for (unsigned i(0), e([lists count]); i != e; ++i)
1074 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1075 SBIconList *list([lists objectAtIndex:i]);
1076 NSArray *subviews([list subviews]);
1078 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1079 if (view == nil || ![view wb$isWBImageView]) {
1080 view = [[[WBImageView alloc] init] autorelease];
1081 [list insertSubview:view atIndex:0];
1084 UIImage *image([UIImage imageWithContentsOfFile:path]);
1086 CGRect frame([view frame]);
1087 frame.size = [image size];
1088 [view setFrame:frame];
1090 [view setImage:image];
1091 [view wb$updateFrame];
1094 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1097 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1098 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1100 [self setClipsToBounds:NO];
1104 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1105 id &_label(MSHookIvar<id>(self, "_label"));
1106 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1108 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1109 [_label setInDock:docked];
1110 return _SBIconLabel$setInDock$(self, sel, docked);
1113 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1114 NSString *identifier = [self bundleIdentifier];
1115 NSLocale *locale = [NSLocale currentLocale];
1116 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1118 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1119 NSString *file = table == nil ? @"Localizable" : table;
1120 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1121 NSDictionary *strings;
1122 if ((strings = [Strings_ objectForKey:name]) != nil) {
1123 if (static_cast<id>(strings) != [NSNull null]) strings:
1124 if (NSString *value = [strings objectForKey:key])
1126 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1129 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1130 [Strings_ setObject:[strings autorelease] forKey:name];
1134 [Strings_ setObject:[NSNull null] forKey:name];
1135 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1138 @class WebCoreFrameBridge;
1139 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1142 void **core(reinterpret_cast<void **>([node _node]));
1143 if (core == NULL || core[6] == NULL)
1145 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1148 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1149 CGRect bounds = [self bounds];
1151 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1154 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1155 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1157 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1159 NSString *style = [NSString stringWithFormat:@""
1160 "font-family: Helvetica; "
1161 "font-weight: bold; "
1164 "", docked ? @"white" : @"#b3b3b3"];
1167 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1169 bool ellipsis(false);
1170 float max = 75, width;
1172 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1175 size_t length([label length]);
1176 float spacing((width - max) / (length - 1));
1178 if (spacing > 1.25) {
1180 label = [label substringToIndex:(length - 1)];
1184 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1188 label = [label stringByAppendingString:@"..."];
1190 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1191 style = [style stringByAppendingString:custom];
1193 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1194 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1197 MSHook(void, mSMSMessageTranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1198 _mSMSMessageTranscriptController$loadView(self, sel);
1200 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1201 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1202 [image autorelease];
1203 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1204 UIView *parent([_transcriptLayer superview]);
1205 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1206 [parent insertSubview:background belowSubview:_transcriptLayer];
1207 [_transcriptLayer setBackgroundColor:[UIColor clearColor]];
1211 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1212 int id(_UISharedImageNameGetIdentifier(name));
1214 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1217 return _UIImageAtPath(name, _UIKitBundle());
1219 NSNumber *key([NSNumber numberWithInt:id]);
1220 UIImage *image = [UIImages_ objectForKey:key];
1222 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1223 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1224 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1226 [image autorelease];
1229 image = _UISharedImageWithIdentifier(id);
1230 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1235 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1236 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
1237 UIImage *image = [PathImages_ objectForKey:key];
1239 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1241 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1242 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1243 image = [[UIImage alloc] initWithContentsOfFile:path];
1245 [image autorelease];
1248 image = __UIImageWithNameInDomain(name, domain);
1249 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1253 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1255 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1256 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1257 name = [font UTF8String];
1258 return _GSFontCreateWithName(name, traits, size);
1261 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1262 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1264 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1266 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1268 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1269 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1271 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1274 NSString *path = [NSString stringWithUTF8String:a1];
1275 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1276 NSString *file = [path substringFromIndex:31];
1277 for (NSString *theme in themes_) {
1278 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1279 if ([Manager_ fileExistsAtPath:path]) {
1280 strcpy(a1, [path UTF8String]);
1289 static void ChangeWallpaper(
1290 CFNotificationCenterRef center,
1294 CFDictionaryRef info
1297 NSLog(@"WB:Debug:ChangeWallpaper!");
1300 if (WallpaperFile_ != nil) {
1301 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1303 image = [image autorelease];
1306 if (WallpaperImage_ != nil)
1307 [WallpaperImage_ setImage:image];
1308 if (WallpaperPage_ != nil)
1309 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1313 #define WBRename(name, sel, imp) \
1314 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1316 template <typename Type_>
1317 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1318 struct nlist &name(nl[index]);
1319 uintptr_t value(name.n_value);
1320 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1321 value |= 0x00000001;
1322 function = reinterpret_cast<Type_>(value);
1325 template <typename Type_>
1326 static void dlset(Type_ &function, const char *name) {
1327 _GSFontGetUseLegacyFontMetrics = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1330 extern "C" void WBInitialize() {
1331 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1333 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1335 NSLog(@"WB:Notice: WinterBoard");
1337 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1341 memset(nl, 0, sizeof(nl));
1342 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1343 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1344 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1345 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1346 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1347 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1348 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1351 nlset(_UIApplicationImageWithName, nl, 0);
1352 nlset(_UIImageAtPath, nl, 1);
1353 nlset(_UIImageRefAtPath, nl, 2);
1354 nlset(_UIImageWithNameInDomain, nl, 3);
1355 nlset(_UIKitBundle, nl, 4);
1356 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1357 nlset(_UISharedImageWithIdentifier, nl, 6);
1359 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1360 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1361 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1362 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1364 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1366 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1368 memset(nl, 0, sizeof(nl));
1369 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1370 nlist(AudioToolbox, nl);
1371 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1372 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1375 $NSBundle = objc_getClass("NSBundle");
1377 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1378 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1380 $UIImage = objc_getClass("UIImage");
1381 $UINavigationBar = objc_getClass("UINavigationBar");
1382 $UIToolbar = objc_getClass("UIToolbar");
1384 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1386 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1387 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1389 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1390 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1392 Manager_ = [[NSFileManager defaultManager] retain];
1393 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1394 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1395 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1396 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1397 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1399 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1401 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1402 [settings autorelease];
1404 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1405 Debug_ = [debug boolValue];
1407 NSArray *themes = [settings objectForKey:@"Themes"];
1409 if (NSString *theme = [settings objectForKey:@"Theme"])
1410 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1412 [NSNumber numberWithBool:true], @"Active",
1415 for (NSDictionary *theme in themes) {
1416 NSNumber *active = [theme objectForKey:@"Active"];
1417 if (![active boolValue])
1420 NSString *name = [theme objectForKey:@"Name"];
1424 NSString *theme = nil;
1426 #define testForTheme(format...) \
1427 if (theme == nil) { \
1428 NSString *path = [NSString stringWithFormat:format]; \
1429 if ([Manager_ fileExistsAtPath:path]) { \
1430 [themes_ addObject:path]; \
1435 testForTheme(@"/Library/Themes/%@.theme", name)
1436 testForTheme(@"/Library/Themes/%@", name)
1437 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1441 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1443 for (NSString *theme in themes_)
1444 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
1446 for (NSString *key in [info allKeys])
1447 if ([Info_ objectForKey:key] == nil)
1448 [Info_ setObject:[info objectForKey:key] forKey:key];
1451 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1452 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1453 _mSMSMessageTranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$mSMSMessageTranscriptController$loadView);
1454 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1455 CFNotificationCenterAddObserver(
1456 CFNotificationCenterGetDarwinNotifyCenter(),
1457 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1460 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1461 if (MediaPlayer != nil)
1464 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1465 $MPVideoView = objc_getClass("MPVideoView");
1466 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1468 $SBApplication = objc_getClass("SBApplication");
1469 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1470 $SBAwayView = objc_getClass("SBAwayView");
1471 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1472 $SBButtonBar = objc_getClass("SBButtonBar");
1473 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1474 $SBIcon = objc_getClass("SBIcon");
1475 $SBIconBadge = objc_getClass("SBIconBadge");
1476 $SBIconController = objc_getClass("SBIconController");
1477 $SBIconLabel = objc_getClass("SBIconLabel");
1478 $SBIconList = objc_getClass("SBIconList");
1479 $SBIconModel = objc_getClass("SBIconModel");
1480 //$SBImageCache = objc_getClass("SBImageCache");
1481 $SBSearchView = objc_getClass("SBSearchView");
1482 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1483 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1484 $SBStatusBarController = objc_getClass("SBStatusBarController");
1485 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1486 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1487 $SBUIController = objc_getClass("SBUIController");
1488 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1490 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1492 WBRename(SBApplication, pathForIcon, pathForIcon);
1493 WBRename(SBApplicationIcon, icon, icon);
1494 WBRename(SBBookmarkIcon, icon, icon);
1495 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1496 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1497 WBRename(SBIcon, setAlpha:, setAlpha$);
1498 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1499 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1500 WBRename(SBUIController, init, init);
1501 WBRename(SBWidgetApplicationIcon, icon, icon);
1503 WBRename(SBIconLabel, drawRect:, drawRect$);
1504 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1505 WBRename(SBIconLabel, setInDock:, setInDock$);
1507 WBRename(SBIconList, setFrame:, setFrame$);
1509 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1510 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1511 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1512 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1514 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1515 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1516 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1518 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1520 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1521 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1522 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1523 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1524 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1525 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1526 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1527 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1528 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1530 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1531 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1534 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1536 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1537 [Info_ setObject:[NSNumber numberWithBool:(
1538 $getTheme$(Wallpapers_) == nil ||
1539 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1540 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1541 )] forKey:@"UndockedIconLabels"];
1544 NSLog(@"WB:Debug:Info = %@", [Info_ description]);