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 $CKTranscriptController;
119 Class $SBApplication;
120 Class $SBApplicationIcon;
122 Class $SBBookmarkIcon;
124 Class $SBCalendarIconContentsView;
127 Class $SBIconController;
131 //Class $SBImageCache;
133 Class $SBSearchTableViewCell;
134 Class $SBStatusBarContentsView;
135 Class $SBStatusBarController;
136 Class $SBStatusBarOperatorNameView;
137 Class $SBStatusBarTimeView;
138 Class $SBUIController;
139 Class $SBWidgetApplicationIcon;
141 @interface NSDictionary (WinterBoard)
142 - (UIColor *) wb$colorForKey:(NSString *)key;
143 - (BOOL) wb$boolForKey:(NSString *)key;
146 @implementation NSDictionary (WinterBoard)
148 - (UIColor *) wb$colorForKey:(NSString *)key {
149 NSString *value = [self objectForKey:key];
156 - (BOOL) wb$boolForKey:(NSString *)key {
157 if (NSString *value = [self objectForKey:key])
158 return [value boolValue];
164 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
165 #define $GSFontGetUseLegacyFontMetrics() \
166 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
169 bool Engineer_ = false;
171 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
172 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
173 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
174 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
175 static NSBundle *(*_UIKitBundle)();
176 static int (*_UISharedImageNameGetIdentifier)(NSString *);
177 static UIImage *(*_UISharedImageWithIdentifier)(int);
179 static NSMutableDictionary *UIImages_;
180 static NSMutableDictionary *PathImages_;
181 static NSMutableDictionary *Cache_;
182 static NSMutableDictionary *Strings_;
183 static NSMutableDictionary *Themed_;
184 static NSMutableDictionary *Bundles_;
186 static NSFileManager *Manager_;
187 static NSDictionary *English_;
188 static NSMutableDictionary *Info_;
189 static NSMutableArray *themes_;
191 static NSString *$getTheme$(NSArray *files, bool parent = false) {
193 if (NSString *path = [Themed_ objectForKey:files])
194 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
197 NSLog(@"WB:Debug: %@", [files description]);
201 for (NSString *theme in themes_)
202 for (NSString *file in files) {
203 path = [NSString stringWithFormat:@"%@/%@", theme, file];
204 if ([Manager_ fileExistsAtPath:path]) {
205 path = parent ? theme : path;
213 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
217 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
218 NSString *identifier = [bundle bundleIdentifier];
219 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
221 if (identifier != nil)
222 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
223 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
224 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
226 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
228 #define remapResourceName(oldname, newname) \
229 else if ([file isEqualToString:oldname]) \
230 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
232 if (identifier == nil);
233 else if ([identifier isEqualToString:@"com.apple.calculator"])
234 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
235 else if (![identifier isEqualToString:@"com.apple.springboard"]);
236 remapResourceName(@"FSO_BG.png", @"StatusBar")
237 remapResourceName(@"SBDockBG.png", @"Dock")
238 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
240 if (NSString *path = $getTheme$(names))
245 static NSString *$pathForIcon$(SBApplication *self) {
246 NSString *identifier = [self bundleIdentifier];
247 NSString *path = [self path];
248 NSString *folder = [path lastPathComponent];
249 NSString *dname = [self displayName];
250 NSString *didentifier = [self displayIdentifier];
253 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
255 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
257 if (identifier != nil)
258 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
260 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
262 #define testForIcon(Name) \
263 if (NSString *name = Name) \
264 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
266 testForIcon(identifier);
269 if (didentifier != nil) {
270 testForIcon([English_ objectForKey:didentifier]);
272 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
273 if ([parts count] != 1)
274 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
275 testForIcon([english objectForKey:[parts lastObject]]);
278 if (NSString *path = $getTheme$(names))
283 @interface NSBundle (WinterBoard)
284 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
287 @implementation NSBundle (WinterBoard)
289 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
290 path = [path stringByDeletingLastPathComponent];
291 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
294 NSBundle *bundle([Bundles_ objectForKey:path]);
295 if (reinterpret_cast<id>(bundle) == [NSNull null])
297 else if (bundle == nil) {
298 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
299 bundle = [NSBundle bundleWithPath:path];
301 bundle = [NSBundle wb$bundleWithFile:path];
303 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
304 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
312 @interface NSString (WinterBoard)
313 - (NSString *) wb$themedPath;
316 @implementation NSString (WinterBoard)
318 - (NSString *) wb$themedPath {
320 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
322 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
323 NSString *file([self stringByResolvingSymlinksInPath]);
324 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
325 if ([file hasPrefix:prefix]) {
326 NSUInteger length([prefix length]);
327 if (length != [file length])
328 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
338 void WBLogRect(const char *tag, struct CGRect rect) {
339 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
342 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
343 CGRect frame([view frame]);
344 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]);
346 for (UIView *child in [view subviews])
347 WBLogHierarchy(child, index++, indent + 1);
350 UIImage *$cacheForImage$(UIImage *image) {
351 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
352 CGRect rect = {CGPointMake(1, 1), [image size]};
353 CGSize size = {rect.size.width + 2, rect.size.height + 2};
355 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
356 CGColorSpaceRelease(space);
358 CGContextDrawImage(context, rect, [image CGImage]);
359 CGImageRef ref(CGBitmapContextCreateImage(context));
360 CGContextRelease(context);
362 UIImage *cache([UIImage imageWithCGImage:ref]);
368 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
369 //if ([name isEqualToString:@"icons"]) return nil;
370 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
373 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
374 NSString *key([icon displayIdentifier]);
376 if (UIImage *image = [icon icon]) {
377 CGSize size = [image size];
378 if (size.width != 59 || size.height != 60) {
379 UIImage *cache($cacheForImage$(image));
380 [Cache_ setObject:cache forKey:key];
385 _SBIconModel$cacheImageForIcon$(self, sel, icon);
388 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
389 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
390 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
392 NSString *key([icon displayIdentifier]);
394 if (UIImage *image = [icon icon]) {
395 CGSize size = [image size];
396 if (size.width != 59 || size.height != 60) {
397 UIImage *cache($cacheForImage$(image));
398 [Cache_ setObject:cache forKey:key];
404 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
405 NSString *key([icon displayIdentifier]);
406 if (UIImage *image = [Cache_ objectForKey:key])
409 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
412 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
414 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
415 NSString *key([icon displayIdentifier]);
416 if (UIImage *image = [Cache_ objectForKey:key])
419 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
422 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
423 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
424 [self setBackgroundColor:[UIColor clearColor]];
425 for (UIView *child in [self subviews])
426 [child setBackgroundColor:[UIColor clearColor]];
430 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
431 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
432 [self setBackgroundColor:[UIColor clearColor]];
436 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
437 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
438 float inset([self edgeInset]);
439 [[UIColor clearColor] set];
440 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
441 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
444 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
445 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
446 if (NSString *path = $pathForIcon$([self application]))
447 return [UIImage imageWithContentsOfFile:path];
448 return _SBApplicationIcon$icon(self, sel);
451 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
453 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
454 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
455 return [UIImage imageWithContentsOfFile:path];
456 return _SBWidgetApplicationIcon$icon(self, sel);
459 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
461 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
462 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
463 return [UIImage imageWithContentsOfFile:path];
464 return _SBBookmarkIcon$icon(self, sel);
467 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
468 if (NSString *path = $pathForIcon$(self))
470 return _SBApplication$pathForIcon(self, sel);
473 static UIImage *CachedImageAtPath(NSString *path) {
474 path = [path stringByResolvingSymlinksInPath];
475 UIImage *image = [PathImages_ objectForKey:path];
477 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
478 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
480 image = [image autorelease];
481 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
485 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
487 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
488 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
491 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
493 return __UIImageAtPath(name, nil);
495 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
496 UIImage *image = [PathImages_ objectForKey:key];
498 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
500 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
501 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
502 image = CachedImageAtPath(path);
504 image = __UIImageAtPath(name, bundle);
505 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
510 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
511 NSBundle *bundle = [NSBundle mainBundle];
513 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
514 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
515 return CachedImageAtPath(path);
516 return __UIApplicationImageWithName(name);
519 #define WBDelegate(delegate) \
520 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
522 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
523 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
525 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
529 - (void) forwardInvocation:(NSInvocation*)inv { \
530 SEL sel = [inv selector]; \
531 if ([delegate respondsToSelector:sel]) \
532 [inv invokeWithTarget:delegate]; \
534 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
537 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
538 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
540 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
541 if (NSString *path = $pathForFile$inBundle$(file, self, false))
543 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
546 void $setBarStyle$_(NSString *name, int &style) {
548 NSLog(@"WB:Debug:%@Style:%d", name, style);
549 NSNumber *number = nil;
551 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
553 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
555 style = [number intValue];
557 NSLog(@"WB:Debug:%@Style=%d", name, style);
561 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
562 NSBundle *bundle([NSBundle mainBundle]);
564 CFLocaleRef locale(CFLocaleCopyCurrent());
565 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
568 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
570 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
571 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
572 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
573 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
577 CFRelease(formatter);
579 NSString *datestyle(@""
580 "font-family: Helvetica; "
581 "font-weight: bold; "
587 NSString *daystyle(@""
588 "font-family: Helvetica; "
589 "font-weight: bold; "
592 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
595 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
596 datestyle = [datestyle stringByAppendingString:style];
597 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
598 daystyle = [daystyle stringByAppendingString:style];
600 float width([self bounds].size.width);
602 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
603 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
605 unsigned base($GSFontGetUseLegacyFontMetrics() ? 71 : 70);
607 [(NSString *)date drawAtPoint:CGPointMake(
608 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
609 ) withStyle:datestyle];
611 [(NSString *)day drawAtPoint:CGPointMake(
612 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
613 ) withStyle:daystyle];
619 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
622 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
623 style = [number intValue];
625 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
628 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
631 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
632 self = [self wb$initWithCoder:coder];
635 UINavigationBar$setBarStyle$_(self);
639 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
640 self = [self wb$initWithFrame:frame];
643 UINavigationBar$setBarStyle$_(self);
647 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
648 $setBarStyle$_(@"Toolbar", style);
649 return _UIToolbar$setBarStyle$(self, sel, style);
652 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
653 $setBarStyle$_(@"NavigationBar", style);
654 return _UINavigationBar$setBarStyle$(self, sel, style);
657 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
658 [[self superview] setBackgroundColor:[UIColor clearColor]];
659 _SBButtonBar$didMoveToSuperview(self, sel);
662 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
663 [[self superview] setBackgroundColor:[UIColor clearColor]];
664 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
667 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
669 NSLog(@"WB:Debug:DefaultDesktopImage");
670 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
671 return [UIImage imageWithContentsOfFile:path];
672 return _UIImage$defaultDesktopImage(self, sel);
675 static NSArray *Wallpapers_;
676 static NSString *WallpaperFile_;
677 static UIImageView *WallpaperImage_;
678 static UIWebDocumentView *WallpaperPage_;
679 static NSURL *WallpaperURL_;
681 #define _release(object) \
682 do if (object != nil) { \
687 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
688 self = _SBUIController$init(self, sel);
692 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
693 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
694 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
697 if (&_contentLayer != NULL)
698 layer = _contentLayer;
699 else if (&_contentView != NULL)
700 layer = _contentView;
704 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
705 [content setBackgroundColor:[layer backgroundColor]];
706 [layer setBackgroundColor:[UIColor clearColor]];
707 [layer setFrame:[content bounds]];
708 [_window setContentView:content];
710 _release(WallpaperFile_);
711 _release(WallpaperImage_);
712 _release(WallpaperPage_);
713 _release(WallpaperURL_);
715 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
716 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
717 if ([Manager_ fileExistsAtPath:mp4]) {
721 static AVController *controller_(nil);
722 if (controller_ == nil) {
723 AVQueue *queue([AVQueue avQueue]);
724 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
727 AVQueue *queue([controller_ queue]);
729 UIView *video([[[UIView alloc] initWithFrame:[content bounds]] autorelease]);
730 [controller_ setLayer:[video _layer]];
732 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
733 [queue appendItem:item error:&error];
735 [controller_ play:&error];
736 #elif UseMPMoviePlayerController
737 NSURL *url([NSURL fileURLWithPath:mp4]);
738 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
739 controller.movieControlMode = MPMovieControlModeHidden;
742 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[content bounds]] autorelease];
743 [video setMovieWithPath:mp4];
744 [video setRepeatMode:1];
745 [video setRepeatGap:-1];
746 [video playFromBeginning];;
749 [content addSubview:video];
752 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
753 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
756 if ([Manager_ fileExistsAtPath:png])
758 else if ([Manager_ fileExistsAtPath:jpg])
764 image = [[UIImage alloc] initWithContentsOfFile:path];
766 image = [image autorelease];
770 WallpaperFile_ = [path retain];
771 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
772 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
773 [WallpaperImage_ setAlpha:[number floatValue]];
774 [content addSubview:WallpaperImage_];
777 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
778 if ([Manager_ fileExistsAtPath:html]) {
779 CGRect bounds = [content bounds];
781 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
782 [view setAutoresizes:true];
784 WallpaperPage_ = [view retain];
785 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
787 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
789 [view setBackgroundColor:[UIColor clearColor]];
790 if ([view respondsToSelector:@selector(setDrawsBackground:)])
791 [view setDrawsBackground:NO];
792 [[view webView] setDrawsBackground:NO];
794 [content addSubview:view];
798 for (size_t i(0), e([themes_ count]); i != e; ++i) {
799 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
800 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
801 if ([Manager_ fileExistsAtPath:html]) {
802 CGRect bounds = [content bounds];
804 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
805 [view setAutoresizes:true];
807 NSURL *url = [NSURL fileURLWithPath:html];
808 [view loadRequest:[NSURLRequest requestWithURL:url]];
810 [view setBackgroundColor:[UIColor clearColor]];
811 if ([view respondsToSelector:@selector(setDrawsBackground:)])
812 [view setDrawsBackground:NO];
813 [[view webView] setDrawsBackground:NO];
815 [content addSubview:view];
819 [content addSubview:layer];
820 WBLogHierarchy(_window);
825 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
826 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
827 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
829 if (path != nil && _backgroundView != nil)
832 _SBAwayView$updateDesktopImage$(self, sel, image);
835 CGRect bounds = [self bounds];
837 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
838 [view setAutoresizes:true];
840 if (WallpaperPage_ != nil)
841 [WallpaperPage_ release];
842 WallpaperPage_ = [view retain];
844 if (WallpaperURL_ != nil)
845 [WallpaperURL_ release];
846 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
848 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
850 [[view webView] setDrawsBackground:false];
851 [view setBackgroundColor:[UIColor clearColor]];
853 [self insertSubview:view aboveSubview:_backgroundView];
857 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
858 extern "C" CGColorRef CGGStateGetFillColor(void *);
859 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
860 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
862 /* WBTimeLabel {{{ */
863 @interface WBTimeLabel : NSProxy {
865 _transient SBStatusBarTimeView *view_;
868 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
872 @implementation WBTimeLabel
879 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
880 time_ = [time retain];
885 - (NSString *) description {
891 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
892 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
893 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
895 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
896 "font-family: Helvetica; "
897 "font-weight: bold; "
900 "%@", _mode ? @"white" : @"black", custom]];
905 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
910 /* WBBadgeLabel {{{ */
911 @interface WBBadgeLabel : NSProxy {
915 - (id) initWithBadge:(NSString *)badge;
919 @implementation WBBadgeLabel
926 - (id) initWithBadge:(NSString *)badge {
927 badge_ = [badge retain];
933 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
934 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
935 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
936 "font-family: Helvetica; "
937 "font-weight: bold; "
945 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
951 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
952 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
953 alpha = [number floatValue];
954 return _SBIcon$setAlpha$(self, sel, alpha);
957 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
958 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
959 id &_badge(MSHookIvar<id>(self, "_badge"));
961 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
966 void SBStatusBarController$setStatusBarMode(int &mode) {
968 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
969 if (mode < 100) // 104:hidden 105:glowing
970 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
971 mode = [number intValue];
974 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
975 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
976 SBStatusBarController$setStatusBarMode(mode);
977 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
980 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
981 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
982 SBStatusBarController$setStatusBarMode(mode);
983 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
986 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) {
987 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
988 SBStatusBarController$setStatusBarMode(mode);
989 //NSLog(@"mode=%u", mode);
990 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
993 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
994 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
995 mode = [number intValue];
996 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
999 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1000 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1002 NSLog(@"operatorNameStyle= %@", style);
1003 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1004 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1008 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1010 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1011 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1014 // XXX: replace this with [SBStatusBarTimeView tile]
1015 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1016 id &_time(MSHookIvar<id>(self, "_time"));
1017 if (_time != nil && [_time class] != [WBTimeLabel class])
1018 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1019 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1022 @interface UIView (WinterBoard)
1023 - (bool) wb$isWBImageView;
1026 @implementation UIView (WinterBoard)
1028 - (bool) wb$isWBImageView {
1034 @interface WBImageView : UIImageView {
1037 - (bool) wb$isWBImageView;
1038 - (void) wb$updateFrame;
1041 @implementation WBImageView
1043 - (bool) wb$isWBImageView {
1047 - (void) wb$updateFrame {
1048 CGRect frame([self frame]);
1051 for (UIView *view(self); ; ) {
1052 view = [view superview];
1055 frame.origin.y -= [view frame].origin.y;
1058 [self setFrame:frame];
1063 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1064 NSArray *subviews([self subviews]);
1065 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1066 if (view != nil && [view wb$isWBImageView])
1067 [view wb$updateFrame];
1068 _SBIconList$setFrame$(self, sel, frame);
1071 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1072 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1073 NSArray *lists([_iconModel iconLists]);
1075 for (unsigned i(0), e([lists count]); i != e; ++i)
1076 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1077 SBIconList *list([lists objectAtIndex:i]);
1078 NSArray *subviews([list subviews]);
1080 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1081 if (view == nil || ![view wb$isWBImageView]) {
1082 view = [[[WBImageView alloc] init] autorelease];
1083 [list insertSubview:view atIndex:0];
1086 UIImage *image([UIImage imageWithContentsOfFile:path]);
1088 CGRect frame([view frame]);
1089 frame.size = [image size];
1090 [view setFrame:frame];
1092 [view setImage:image];
1093 [view wb$updateFrame];
1096 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1099 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1100 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1102 [self setClipsToBounds:NO];
1106 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1107 id &_label(MSHookIvar<id>(self, "_label"));
1108 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1110 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1111 [_label setInDock:docked];
1112 return _SBIconLabel$setInDock$(self, sel, docked);
1115 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1116 NSString *identifier = [self bundleIdentifier];
1117 NSLocale *locale = [NSLocale currentLocale];
1118 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1120 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1121 NSString *file = table == nil ? @"Localizable" : table;
1122 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1123 NSDictionary *strings;
1124 if ((strings = [Strings_ objectForKey:name]) != nil) {
1125 if (static_cast<id>(strings) != [NSNull null]) strings:
1126 if (NSString *value = [strings objectForKey:key])
1128 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1131 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1132 [Strings_ setObject:[strings autorelease] forKey:name];
1136 [Strings_ setObject:[NSNull null] forKey:name];
1137 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1140 @class WebCoreFrameBridge;
1141 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1144 void **core(reinterpret_cast<void **>([node _node]));
1145 if (core == NULL || core[6] == NULL)
1147 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1150 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1151 CGRect bounds = [self bounds];
1153 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1156 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1157 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1159 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1161 NSString *style = [NSString stringWithFormat:@""
1162 "font-family: Helvetica; "
1163 "font-weight: bold; "
1166 "", docked ? @"white" : @"#b3b3b3"];
1169 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1171 bool ellipsis(false);
1172 float max = 75, width;
1174 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1177 size_t length([label length]);
1178 float spacing((width - max) / (length - 1));
1180 if (spacing > 1.25) {
1182 label = [label substringToIndex:(length - 1)];
1186 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1190 label = [label stringByAppendingString:@"..."];
1192 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1193 style = [style stringByAppendingString:custom];
1195 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1196 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1199 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1200 _TranscriptController$loadView(self, sel);
1202 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1203 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1204 [image autorelease];
1206 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1207 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1209 if (&_transcriptTable != NULL)
1210 table = _transcriptTable;
1211 else if (&_transcriptLayer != NULL)
1212 table = _transcriptLayer;
1216 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1217 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1220 [placard insertSubview:background atIndex:0];
1222 [table setBackgroundColor:[UIColor clearColor]];
1223 [placard insertSubview:background belowSubview:table];
1226 WBLogHierarchy(placard);
1230 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1231 int id(_UISharedImageNameGetIdentifier(name));
1233 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1236 return _UIImageAtPath(name, _UIKitBundle());
1238 NSNumber *key([NSNumber numberWithInt:id]);
1239 UIImage *image = [UIImages_ objectForKey:key];
1241 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1242 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1243 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1245 [image autorelease];
1248 image = _UISharedImageWithIdentifier(id);
1249 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1254 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1255 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
1256 UIImage *image = [PathImages_ objectForKey:key];
1258 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1260 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1261 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1262 image = [[UIImage alloc] initWithContentsOfFile:path];
1264 [image autorelease];
1267 image = __UIImageWithNameInDomain(name, domain);
1268 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1272 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1274 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1275 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1276 name = [font UTF8String];
1277 return _GSFontCreateWithName(name, traits, size);
1280 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1281 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1283 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1285 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1287 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1288 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1290 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1293 NSString *path = [NSString stringWithUTF8String:a1];
1294 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1295 NSString *file = [path substringFromIndex:31];
1296 for (NSString *theme in themes_) {
1297 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1298 if ([Manager_ fileExistsAtPath:path]) {
1299 strcpy(a1, [path UTF8String]);
1308 static void ChangeWallpaper(
1309 CFNotificationCenterRef center,
1313 CFDictionaryRef info
1316 NSLog(@"WB:Debug:ChangeWallpaper!");
1319 if (WallpaperFile_ != nil) {
1320 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1322 image = [image autorelease];
1325 if (WallpaperImage_ != nil)
1326 [WallpaperImage_ setImage:image];
1327 if (WallpaperPage_ != nil)
1328 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1332 #define WBRename(name, sel, imp) \
1333 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1335 template <typename Type_>
1336 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1337 struct nlist &name(nl[index]);
1338 uintptr_t value(name.n_value);
1339 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1340 value |= 0x00000001;
1341 function = reinterpret_cast<Type_>(value);
1344 template <typename Type_>
1345 static void dlset(Type_ &function, const char *name) {
1346 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1349 extern "C" void WBInitialize() {
1350 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1352 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1354 NSLog(@"WB:Notice: WinterBoard");
1356 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1360 memset(nl, 0, sizeof(nl));
1361 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1362 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1363 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1364 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1365 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1366 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1367 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1370 nlset(_UIApplicationImageWithName, nl, 0);
1371 nlset(_UIImageAtPath, nl, 1);
1372 nlset(_UIImageRefAtPath, nl, 2);
1373 nlset(_UIImageWithNameInDomain, nl, 3);
1374 nlset(_UIKitBundle, nl, 4);
1375 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1376 nlset(_UISharedImageWithIdentifier, nl, 6);
1378 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1379 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1380 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1381 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1383 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1385 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1387 memset(nl, 0, sizeof(nl));
1388 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1389 nlist(AudioToolbox, nl);
1390 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1391 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1394 $NSBundle = objc_getClass("NSBundle");
1396 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1397 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1399 $UIImage = objc_getClass("UIImage");
1400 $UINavigationBar = objc_getClass("UINavigationBar");
1401 $UIToolbar = objc_getClass("UIToolbar");
1403 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1405 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1406 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1408 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1409 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1411 Manager_ = [[NSFileManager defaultManager] retain];
1412 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1413 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1414 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1415 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1416 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1418 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1420 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1421 [settings autorelease];
1423 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1424 Debug_ = [debug boolValue];
1426 NSArray *themes = [settings objectForKey:@"Themes"];
1428 if (NSString *theme = [settings objectForKey:@"Theme"])
1429 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1431 [NSNumber numberWithBool:true], @"Active",
1434 for (NSDictionary *theme in themes) {
1435 NSNumber *active = [theme objectForKey:@"Active"];
1436 if (![active boolValue])
1439 NSString *name = [theme objectForKey:@"Name"];
1443 NSString *theme = nil;
1445 #define testForTheme(format...) \
1446 if (theme == nil) { \
1447 NSString *path = [NSString stringWithFormat:format]; \
1448 if ([Manager_ fileExistsAtPath:path]) { \
1449 [themes_ addObject:path]; \
1454 testForTheme(@"/Library/Themes/%@.theme", name)
1455 testForTheme(@"/Library/Themes/%@", name)
1456 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1460 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1462 for (NSString *theme in themes_)
1463 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
1465 for (NSString *key in [info allKeys])
1466 if ([Info_ objectForKey:key] == nil)
1467 [Info_ setObject:[info objectForKey:key] forKey:key];
1470 $CKTranscriptController = objc_getClass("CKTranscriptController");
1471 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1473 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1474 if (_TranscriptController$loadView == NULL) {
1475 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1476 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1478 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1479 CFNotificationCenterAddObserver(
1480 CFNotificationCenterGetDarwinNotifyCenter(),
1481 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1484 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1485 if (MediaPlayer != nil)
1488 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1489 $MPVideoView = objc_getClass("MPVideoView");
1490 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1492 $SBApplication = objc_getClass("SBApplication");
1493 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1494 $SBAwayView = objc_getClass("SBAwayView");
1495 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1496 $SBButtonBar = objc_getClass("SBButtonBar");
1497 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1498 $SBIcon = objc_getClass("SBIcon");
1499 $SBIconBadge = objc_getClass("SBIconBadge");
1500 $SBIconController = objc_getClass("SBIconController");
1501 $SBIconLabel = objc_getClass("SBIconLabel");
1502 $SBIconList = objc_getClass("SBIconList");
1503 $SBIconModel = objc_getClass("SBIconModel");
1504 //$SBImageCache = objc_getClass("SBImageCache");
1505 $SBSearchView = objc_getClass("SBSearchView");
1506 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1507 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1508 $SBStatusBarController = objc_getClass("SBStatusBarController");
1509 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1510 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1511 $SBUIController = objc_getClass("SBUIController");
1512 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1514 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1516 WBRename(SBApplication, pathForIcon, pathForIcon);
1517 WBRename(SBApplicationIcon, icon, icon);
1518 WBRename(SBBookmarkIcon, icon, icon);
1519 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1520 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1521 WBRename(SBIcon, setAlpha:, setAlpha$);
1522 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1523 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1524 WBRename(SBUIController, init, init);
1525 WBRename(SBWidgetApplicationIcon, icon, icon);
1527 WBRename(SBIconLabel, drawRect:, drawRect$);
1528 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1529 WBRename(SBIconLabel, setInDock:, setInDock$);
1531 WBRename(SBIconList, setFrame:, setFrame$);
1533 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1534 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1535 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1536 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1538 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1539 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1540 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1542 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1544 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1545 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1546 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1547 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1548 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1549 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1550 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1551 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1552 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1554 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1555 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1558 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1560 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1561 [Info_ setObject:[NSNumber numberWithBool:(
1562 $getTheme$(Wallpapers_) == nil ||
1563 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1564 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1565 )] forKey:@"UndockedIconLabels"];
1568 NSLog(@"WB:Debug:Info = %@", [Info_ description]);