]> git.saurik.com Git - winterboard.git/blob - Library.mm
6ec4a8d4af3b857e7222b7ad9e5c5fd4d55b183e
[winterboard.git] / Library.mm
1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008 Jay Freeman (saurik)
3 */
4
5 /*
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
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
17 * distribution.
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.
21 *
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.
36 */
37
38 #define _trace() NSLog(@"WB:_trace(%u)", __LINE__);
39 #define _transient
40
41 #import <CoreFoundation/CoreFoundation.h>
42 #import <Foundation/Foundation.h>
43 #import <CoreGraphics/CoreGraphics.h>
44
45 #import <Celestial/AVController.h>
46 #import <Celestial/AVItem.h>
47 #import <Celestial/AVQueue.h>
48
49 #include <substrate.h>
50
51 #import <UIKit/UIKit.h>
52
53 #import <SpringBoard/SBApplication.h>
54 #import <SpringBoard/SBApplicationIcon.h>
55 #import <SpringBoard/SBAppWindow.h>
56 #import <SpringBoard/SBBookmarkIcon.h>
57 #import <SpringBoard/SBButtonBar.h>
58 #import <SpringBoard/SBCalendarIconContentsView.h>
59 #import <SpringBoard/SBContentLayer.h>
60 #import <SpringBoard/SBIconController.h>
61 #import <SpringBoard/SBIconLabel.h>
62 #import <SpringBoard/SBSlidingAlertDisplay.h>
63 #import <SpringBoard/SBStatusBarContentsView.h>
64 #import <SpringBoard/SBStatusBarController.h>
65 #import <SpringBoard/SBStatusBarOperatorNameView.h>
66 #import <SpringBoard/SBStatusBarTimeView.h>
67 #import <SpringBoard/SBUIController.h>
68 #import <SpringBoard/SBWidgetApplicationIcon.h>
69
70 #import <MobileSMS/mSMSMessageTranscriptController.h>
71
72 #import <MediaPlayer/MPMoviePlayerController.h>
73 #import <MediaPlayer/MPVideoView.h>
74 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
75
76 #import <CoreGraphics/CGGeometry.h>
77
78 extern "C" void __clear_cache (char *beg, char *end);
79
80 @protocol WinterBoard
81 - (void *) _node;
82 @end
83
84 Class $MPMoviePlayerController;
85 Class $MPVideoView;
86 Class $WebCoreFrameBridge;
87
88 Class $NSBundle;
89
90 Class $UIImage;
91 Class $UINavigationBar;
92 Class $UIToolbar;
93
94 Class $SBApplication;
95 Class $SBApplicationIcon;
96 Class $SBBookmarkIcon;
97 Class $SBButtonBar;
98 Class $SBCalendarIconContentsView;
99 Class $SBContentLayer;
100 Class $SBIconBadge;
101 Class $SBIconController;
102 Class $SBIconLabel;
103 Class $SBIconModel;
104 Class $SBSlidingAlertDisplay;
105 Class $SBStatusBarContentsView;
106 Class $SBStatusBarController;
107 Class $SBStatusBarOperatorNameView;
108 Class $SBStatusBarTimeView;
109 Class $SBWidgetApplicationIcon;
110
111 @interface NSDictionary (WinterBoard)
112 - (UIColor *) colorForKey:(NSString *)key;
113 - (BOOL) boolForKey:(NSString *)key;
114 @end
115
116 @implementation NSDictionary (WinterBoard)
117
118 - (UIColor *) colorForKey:(NSString *)key {
119 NSString *value = [self objectForKey:key];
120 if (value == nil)
121 return nil;
122 /* XXX: incorrect */
123 return nil;
124 }
125
126 - (BOOL) boolForKey:(NSString *)key {
127 if (NSString *value = [self objectForKey:key])
128 return [value boolValue];
129 return false;
130 }
131
132 @end
133
134 bool Debug_ = false;
135 bool Engineer_ = false;
136
137 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
138 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
139 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
140 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
141 static NSBundle *(*_UIKitBundle)();
142 static void (*_UISharedImageInitialize)(bool);
143 static int (*_UISharedImageNameGetIdentifier)(NSString *);
144 static UIImage *(*_UISharedImageWithIdentifier)(int);
145
146 static NSMutableDictionary *UIImages_;
147 static NSMutableDictionary *PathImages_;
148 static NSMutableDictionary *Cache_;
149 static NSMutableDictionary *Strings_;
150 static NSMutableDictionary *Themed_;
151 static NSMutableDictionary *Bundles_;
152
153 static NSFileManager *Manager_;
154 static NSDictionary *English_;
155 static NSMutableDictionary *Info_;
156 static NSMutableArray *themes_;
157
158 static NSString *$getTheme$(NSArray *files, bool parent = false) {
159 if (!parent)
160 if (NSString *path = [Themed_ objectForKey:files])
161 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
162
163 if (Debug_)
164 NSLog(@"WB:Debug: %@", [files description]);
165
166 NSString *path;
167
168 for (NSString *theme in themes_)
169 for (NSString *file in files) {
170 path = [NSString stringWithFormat:@"%@/%@", theme, file];
171 if ([Manager_ fileExistsAtPath:path]) {
172 path = parent ? theme : path;
173 goto set;
174 }
175 }
176
177 path = nil;
178 set:
179 if (!parent)
180 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
181 return path;
182 }
183
184 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
185 NSString *identifier = [bundle bundleIdentifier];
186 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
187
188 if (identifier != nil)
189 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
190 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
191 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
192 if (ui)
193 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
194
195 #define remapResourceName(oldname, newname) \
196 else if ([file isEqualToString:oldname]) \
197 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
198
199 if (identifier == nil);
200 else if ([identifier isEqualToString:@"com.apple.calculator"])
201 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
202 else if (![identifier isEqualToString:@"com.apple.springboard"]);
203 remapResourceName(@"FSO_BG.png", @"StatusBar")
204 remapResourceName(@"SBDockBG.png", @"Dock")
205 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
206
207 if (NSString *path = $getTheme$(names))
208 return path;
209 return nil;
210 }
211
212 static NSString *$pathForIcon$(SBApplication *self) {
213 NSString *identifier = [self bundleIdentifier];
214 NSString *path = [self path];
215 NSString *folder = [path lastPathComponent];
216 NSString *dname = [self displayName];
217 NSString *didentifier = [self displayIdentifier];
218
219 if (Debug_)
220 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
221
222 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
223
224 if (identifier != nil)
225 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
226 if (folder != nil)
227 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
228
229 #define testForIcon(Name) \
230 if (NSString *name = Name) \
231 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
232
233 testForIcon(identifier);
234 testForIcon(dname);
235
236 if (didentifier != nil) {
237 testForIcon([English_ objectForKey:didentifier]);
238
239 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
240 if ([parts count] != 1)
241 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
242 testForIcon([english objectForKey:[parts lastObject]]);
243 }
244
245 if (NSString *path = $getTheme$(names))
246 return path;
247 return nil;
248 }
249
250 @interface NSBundle (WinterBoard)
251 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
252 @end
253
254 @implementation NSBundle (WinterBoard)
255
256 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
257 path = [path stringByDeletingLastPathComponent];
258 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
259 return nil;
260
261 NSBundle *bundle([Bundles_ objectForKey:path]);
262 if (reinterpret_cast<id>(bundle) == [NSNull null])
263 return nil;
264 else if (bundle == nil) {
265 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
266 bundle = [NSBundle bundleWithPath:path];
267 if (bundle == nil)
268 bundle = [NSBundle wb$bundleWithFile:path];
269 if (Debug_)
270 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
271 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
272 }
273
274 return bundle;
275 }
276
277 @end
278
279 @interface NSString (WinterBoard)
280 - (NSString *) wb$themedPath;
281 @end
282
283 @implementation NSString (WinterBoard)
284
285 - (NSString *) wb$themedPath {
286 if (Debug_)
287 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
288
289 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
290 NSString *file([self stringByResolvingSymlinksInPath]);
291 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
292 if ([file hasPrefix:prefix]) {
293 NSUInteger length([prefix length]);
294 if (length != [file length])
295 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
296 return path;
297 }
298 }
299
300 return self;
301 }
302
303 @end
304
305 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
306 _SBIconModel$cacheImageForIcon$(self, sel, icon);
307 NSString *key([icon displayIdentifier]);
308
309 if (UIImage *image = [icon icon]) {
310 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
311 CGRect rect = {CGPointMake(1, 1), [image size]};
312 CGSize size = {rect.size.width + 2, rect.size.height + 2};
313
314 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
315 CGColorSpaceRelease(space);
316
317 CGContextDrawImage(context, rect, [image CGImage]);
318 CGImageRef ref(CGBitmapContextCreateImage(context));
319 CGContextRelease(context);
320
321 UIImage *image([UIImage imageWithCGImage:ref]);
322 CGImageRelease(ref);
323
324 [Cache_ setObject:image forKey:key];
325 }
326 }
327
328 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
329 NSString *key([icon displayIdentifier]);
330 if (UIImage *image = [Cache_ objectForKey:key])
331 return image;
332 else
333 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
334 }
335
336 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
337 if (![Info_ boolForKey:@"ComposeStoreIcons"])
338 if (NSString *path = $pathForIcon$([self application]))
339 return [UIImage imageWithContentsOfFile:path];
340 return _SBApplicationIcon$icon(self, sel);
341 }
342
343 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
344 if (Debug_)
345 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
346 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
347 return [UIImage imageWithContentsOfFile:path];
348 return _SBWidgetApplicationIcon$icon(self, sel);
349 }
350
351 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
352 if (Debug_)
353 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
354 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
355 return [UIImage imageWithContentsOfFile:path];
356 return _SBBookmarkIcon$icon(self, sel);
357 }
358
359 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
360 if (NSString *path = $pathForIcon$(self))
361 return path;
362 return _SBApplication$pathForIcon(self, sel);
363 }
364
365 static UIImage *CachedImageAtPath(NSString *path) {
366 path = [path stringByResolvingSymlinksInPath];
367 UIImage *image = [PathImages_ objectForKey:path];
368 if (image != nil)
369 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
370 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
371 if (image != nil)
372 image = [image autorelease];
373 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
374 return image;
375 }
376
377 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
378 if (Debug_)
379 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
380 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
381 }
382
383 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
384 if (bundle == nil)
385 return __UIImageAtPath(name, nil);
386 else {
387 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
388 UIImage *image = [PathImages_ objectForKey:key];
389 if (image != nil)
390 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
391 if (Debug_)
392 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
393 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
394 image = CachedImageAtPath(path);
395 if (image == nil)
396 image = __UIImageAtPath(name, bundle);
397 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
398 return image;
399 }
400 }*/
401
402 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
403 NSBundle *bundle = [NSBundle mainBundle];
404 if (Debug_)
405 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
406 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
407 return CachedImageAtPath(path);
408 return __UIApplicationImageWithName(name);
409 }
410
411 #define WBDelegate(delegate) \
412 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
413 if (Engineer_) \
414 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
415 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
416 return sig; \
417 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
418 return nil; \
419 } \
420 \
421 - (void) forwardInvocation:(NSInvocation*)inv { \
422 SEL sel = [inv selector]; \
423 if ([delegate respondsToSelector:sel]) \
424 [inv invokeWithTarget:delegate]; \
425 else \
426 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
427 }
428
429 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
430 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
431 if (Debug_)
432 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
433 if (NSString *path = $pathForFile$inBundle$(file, self, false))
434 return path;
435 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
436 }
437
438 void $setBarStyle$_(NSString *name, int &style) {
439 if (Debug_)
440 NSLog(@"WB:Debug:%@Style:%d", name, style);
441 NSNumber *number = nil;
442 if (number == nil)
443 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
444 if (number == nil)
445 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
446 if (number != nil) {
447 style = [number intValue];
448 if (Debug_)
449 NSLog(@"WB:Debug:%@Style=%d", name, style);
450 }
451 }
452
453 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
454 NSBundle *bundle([NSBundle mainBundle]);
455
456 CFLocaleRef locale(CFLocaleCopyCurrent());
457 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
458 CFRelease(locale);
459
460 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
461
462 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
463 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
464 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"" table:@"SpringBoard"]);
465 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
466
467 CFRelease(now);
468
469 CFRelease(formatter);
470
471 NSString *datestyle(@""
472 "font-family: Helvetica; "
473 "font-weight: bold; "
474 "font-size: 39px; "
475 "color: #333333; "
476 "alpha: 1.0; "
477 "");
478
479 NSString *daystyle(@""
480 "font-family: Helvetica; "
481 "font-weight: bold; "
482 "font-size: 9px; "
483 "color: white; "
484 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
485 "");
486
487 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
488 datestyle = [datestyle stringByAppendingString:style];
489 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
490 daystyle = [daystyle stringByAppendingString:style];
491
492 float width([self bounds].size.width);
493 float leeway(10);
494 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
495 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
496
497 [(NSString *)date drawAtPoint:CGPointMake(
498 (width + 1 - datesize.width) / 2, (71 - datesize.height) / 2
499 ) withStyle:datestyle];
500
501 [(NSString *)day drawAtPoint:CGPointMake(
502 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
503 ) withStyle:daystyle];
504
505 CFRelease(date);
506 CFRelease(day);
507 }
508
509 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
510 _trace();
511
512 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
513 style = [number intValue];
514
515 if (UIColor *color = [Info_ colorForKey:@"NavigationBarTint"])
516 tint = color;
517
518 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
519 }*/
520
521 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
522 self = [self wb$initWithCoder:coder];
523 if (self == nil)
524 return nil;
525 UINavigationBar$setBarStyle$_(self);
526 return self;
527 }
528
529 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
530 self = [self wb$initWithFrame:frame];
531 if (self == nil)
532 return nil;
533 UINavigationBar$setBarStyle$_(self);
534 return self;
535 }*/
536
537 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
538 $setBarStyle$_(@"Toolbar", style);
539 return _UIToolbar$setBarStyle$(self, sel, style);
540 }
541
542 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
543 $setBarStyle$_(@"NavigationBar", style);
544 return _UINavigationBar$setBarStyle$(self, sel, style);
545 }
546
547 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
548 [[self superview] setBackgroundColor:[UIColor clearColor]];
549 _SBButtonBar$didMoveToSuperview(self, sel);
550 }
551
552 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
553 [[self superview] setBackgroundColor:[UIColor clearColor]];
554 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
555 }
556
557 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
558 if (Debug_)
559 NSLog(@"WB:Debug:DefaultDesktopImage");
560 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
561 return [UIImage imageWithContentsOfFile:path];
562 return _UIImage$defaultDesktopImage(self, sel);
563 }
564
565 static NSArray *Wallpapers_;
566 static NSString *WallpaperFile_;
567 static UIImageView *WallpaperImage_;
568 static UIWebDocumentView *WallpaperPage_;
569 static NSURL *WallpaperURL_;
570
571 #define _release(object) \
572 do if (object != nil) { \
573 [object release]; \
574 object = nil; \
575 } while (false)
576
577 MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize size) {
578 self = _SBContentLayer$initWithSize$(self, sel, size);
579 if (self == nil)
580 return nil;
581
582 _release(WallpaperFile_);
583 _release(WallpaperImage_);
584 _release(WallpaperPage_);
585 _release(WallpaperURL_);
586
587 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
588 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
589 if ([Manager_ fileExistsAtPath:mp4]) {
590 #if UseAVController
591 NSError *error;
592
593 static AVController *controller_(nil);
594 if (controller_ == nil) {
595 AVQueue *queue([AVQueue avQueue]);
596 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
597 }
598
599 AVQueue *queue([controller_ queue]);
600
601 UIView *video([[[UIView alloc] initWithFrame:[self bounds]] autorelease]);
602 [controller_ setLayer:[video _layer]];
603
604 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
605 [queue appendItem:item error:&error];
606
607 [controller_ play:&error];
608 #elif UseMPMoviePlayerController
609 NSURL *url([NSURL fileURLWithPath:mp4]);
610 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
611 controller.movieControlMode = MPMovieControlModeHidden;
612 [controller play];
613 #else
614 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease];
615 [video setMovieWithPath:mp4];
616 [video setRepeatMode:1];
617 [video setRepeatGap:-1];
618 [video playFromBeginning];;
619 #endif
620
621 [self addSubview:video];
622 }
623
624 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
625 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
626
627 NSString *path;
628 if ([Manager_ fileExistsAtPath:png])
629 path = png;
630 else if ([Manager_ fileExistsAtPath:jpg])
631 path = jpg;
632 else path = nil;
633
634 UIImage *image;
635 if (path != nil) {
636 image = [[UIImage alloc] initWithContentsOfFile:path];
637 if (image != nil)
638 image = [image autorelease];
639 } else image = nil;
640
641 if (image != nil) {
642 WallpaperFile_ = [path retain];
643 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
644 [self addSubview:WallpaperImage_];
645 }
646
647 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
648 if ([Manager_ fileExistsAtPath:html]) {
649 CGRect bounds = [self bounds];
650
651 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
652 [view setAutoresizes:true];
653
654 WallpaperPage_ = [view retain];
655 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
656
657 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
658
659 [[view webView] setDrawsBackground:false];
660 [view setBackgroundColor:[UIColor clearColor]];
661
662 [self addSubview:view];
663 }
664 }
665
666 for (size_t i(0), e([themes_ count]); i != e; ++i) {
667 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
668 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
669 if ([Manager_ fileExistsAtPath:html]) {
670 CGRect bounds = [self bounds];
671
672 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
673 [view setAutoresizes:true];
674
675 NSURL *url = [NSURL fileURLWithPath:html];
676 [view loadRequest:[NSURLRequest requestWithURL:url]];
677
678 [[view webView] setDrawsBackground:false];
679 [view setBackgroundColor:[UIColor clearColor]];
680
681 [self addSubview:view];
682 }
683 }
684
685 return self;
686 }
687
688 MSHook(void, SBSlidingAlertDisplay$updateDesktopImage$, SBSlidingAlertDisplay *self, SEL sel, UIImage *image) {
689 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
690 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
691
692 if (path != nil && _backgroundView != nil)
693 path = nil;
694
695 _SBSlidingAlertDisplay$updateDesktopImage$(self, sel, image);
696
697 if (path != nil) {
698 CGRect bounds = [self bounds];
699
700 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
701 [view setAutoresizes:true];
702
703 if (WallpaperPage_ != nil)
704 [WallpaperPage_ release];
705 WallpaperPage_ = [view retain];
706
707 if (WallpaperURL_ != nil)
708 [WallpaperURL_ release];
709 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
710
711 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
712
713 [[view webView] setDrawsBackground:false];
714 [view setBackgroundColor:[UIColor clearColor]];
715
716 [self insertSubview:view aboveSubview:_backgroundView];
717 }
718 }
719
720 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
721 extern "C" CGColorRef CGGStateGetFillColor(void *);
722 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
723 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
724
725 /* WBTimeLabel {{{ */
726 @interface WBTimeLabel : NSProxy {
727 NSString *time_;
728 _transient SBStatusBarTimeView *view_;
729 }
730
731 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
732
733 @end
734
735 @implementation WBTimeLabel
736
737 - (void) dealloc {
738 [time_ release];
739 [super dealloc];
740 }
741
742 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
743 time_ = [time retain];
744 view_ = view;
745 return self;
746 }
747
748 WBDelegate(time_)
749
750 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
751 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
752 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
753
754 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
755 "font-family: Helvetica; "
756 "font-weight: bold; "
757 "font-size: 14px; "
758 "color: %@; "
759 "%@", _mode ? @"white" : @"black", custom]];
760
761 return CGSizeZero;
762 }
763
764 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
765 }
766
767 @end
768 /* }}} */
769 /* WBBadgeLabel {{{ */
770 @interface WBBadgeLabel : NSProxy {
771 NSString *badge_;
772 }
773
774 - (id) initWithBadge:(NSString *)badge;
775
776 @end
777
778 @implementation WBBadgeLabel
779
780 - (void) dealloc {
781 [badge_ release];
782 [super dealloc];
783 }
784
785 - (id) initWithBadge:(NSString *)badge {
786 badge_ = [badge retain];
787 return self;
788 }
789
790 WBDelegate(badge_)
791
792 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
793 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
794 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
795 "font-family: Helvetica; "
796 "font-weight: bold; "
797 "font-size: 17px; "
798 "color: white; "
799 "%@", custom]];
800
801 return CGSizeZero;
802 }
803
804 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
805 }
806
807 @end
808 /* }}} */
809
810 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
811 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
812 id &_badge(MSHookIvar<id>(self, "_badge"));
813 if (_badge != nil)
814 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
815 _badge = label;
816 } return self;
817 }
818
819 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int id, int animation) {
820 if (Debug_)
821 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
822 if (mode < 100) // 104:hidden 105:glowing
823 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
824 mode = [number intValue];
825 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, id, animation);
826 }
827
828 MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
829 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
830 mode = [number intValue];
831 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
832 }
833
834 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
835 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
836 if (Debug_)
837 NSLog(@"operatorNameStyle= %@", style);
838 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
839 style = [NSString stringWithFormat:@"%@; %@", style, custom];
840 return style;
841 }
842
843 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
844 if (Debug_)
845 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
846 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
847 }
848
849 // XXX: replace this with [SBStatusBarTimeView tile]
850 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
851 id &_time(MSHookIvar<id>(self, "_time"));
852 if (_time != nil && [_time class] != [WBTimeLabel class])
853 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
854 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
855 }
856
857 MSHook(void, SBIconController$appendIconList$, SBIconController *self, SEL sel, SBIconList *list) {
858 if (Debug_)
859 NSLog(@"appendIconList:%@", list);
860 return _SBIconController$appendIconList$(self, sel, list);
861 }
862
863 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
864 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
865 if (self != nil)
866 [self setClipsToBounds:NO];
867 return self;
868 }
869
870 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
871 id &_label(MSHookIvar<id>(self, "_label"));
872 if (![Info_ boolForKey:@"UndockedIconLabels"])
873 docked = true;
874 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
875 [_label setInDock:docked];
876 return _SBIconLabel$setInDock$(self, sel, docked);
877 }
878
879 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
880 NSString *identifier = [self bundleIdentifier];
881 NSLocale *locale = [NSLocale currentLocale];
882 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
883 if (Debug_)
884 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
885 NSString *file = table == nil ? @"Localizable" : table;
886 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
887 NSDictionary *strings;
888 if ((strings = [Strings_ objectForKey:name]) != nil) {
889 if (static_cast<id>(strings) != [NSNull null]) strings:
890 if (NSString *value = [strings objectForKey:key])
891 return value;
892 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
893 language, file
894 ], self, false)) {
895 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
896 [Strings_ setObject:[strings autorelease] forKey:name];
897 goto strings;
898 } else goto null;
899 } else null:
900 [Strings_ setObject:[NSNull null] forKey:name];
901 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
902 }
903
904 @class WebCoreFrameBridge;
905 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
906 if (node == nil)
907 return CGSizeZero;
908 void **core(reinterpret_cast<void **>([node _node]));
909 if (core == NULL || core[6] == NULL)
910 return CGSizeZero;
911 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
912 }
913
914 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
915 CGRect bounds = [self bounds];
916
917 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
918
919 BOOL docked;
920 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
921 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
922
923 NSString *label(MSHookIvar<NSString *>(self, "_label"));
924
925 NSString *style = [NSString stringWithFormat:@""
926 "font-family: Helvetica; "
927 "font-weight: bold; "
928 "font-size: 11px; "
929 "color: %@; "
930 "", docked ? @"white" : @"#b3b3b3"];
931
932 if (docked)
933 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
934
935 bool ellipsis(false);
936 float max = 75, width;
937 width:
938 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
939
940 if (width > max) {
941 size_t length([label length]);
942 float spacing((width - max) / (length - 1));
943
944 if (spacing > 1.25) {
945 ellipsis = true;
946 label = [label substringToIndex:(length - 1)];
947 goto width;
948 }
949
950 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
951 }
952
953 if (ellipsis)
954 label = [label stringByAppendingString:@"..."];
955
956 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
957 style = [style stringByAppendingString:custom];
958
959 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
960 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
961 }
962
963 MSHook(void, mSMSMessageTranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
964 _mSMSMessageTranscriptController$loadView(self, sel);
965
966 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
967 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
968 [image autorelease];
969 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
970 UIView *parent([_transcriptLayer superview]);
971 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
972 [parent insertSubview:background belowSubview:_transcriptLayer];
973 [_transcriptLayer setBackgroundColor:[UIColor clearColor]];
974 }
975 }
976
977 MSHook(UIImage *, _UIImageWithName, NSString *name) {
978 int id(_UISharedImageNameGetIdentifier(name));
979 if (Debug_)
980 NSLog(@"WB:Debug: _UIImageWithName(\"%@\", %d)", name, id);
981
982 if (id == -1)
983 return _UIImageAtPath(name, _UIKitBundle());
984 else {
985 NSNumber *key([NSNumber numberWithInt:id]);
986 UIImage *image = [UIImages_ objectForKey:key];
987 if (image != nil)
988 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
989 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
990 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
991 if (image != nil)
992 [image autorelease];
993 }
994 if (image == nil)
995 image = _UISharedImageWithIdentifier(id);
996 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
997 return image;
998 }
999 }
1000
1001 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1002 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
1003 UIImage *image = [PathImages_ objectForKey:key];
1004 if (image != nil)
1005 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1006 if (Debug_)
1007 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1008 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1009 image = [[UIImage alloc] initWithContentsOfFile:path];
1010 if (image != nil)
1011 [image autorelease];
1012 }
1013 if (image == nil)
1014 image = __UIImageWithNameInDomain(name, domain);
1015 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1016 return image;
1017 }
1018
1019 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1020 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1021 name = [font UTF8String];
1022 return _GSFontCreateWithName(name, traits, size);
1023 }
1024
1025 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1026 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1027
1028 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1029
1030 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1031 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1032 if (Debug_)
1033 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1034
1035 if (value) {
1036 NSString *path = [NSString stringWithUTF8String:a1];
1037 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1038 NSString *file = [path substringFromIndex:31];
1039 NSLog(@"%@", file);
1040 for (NSString *theme in themes_) {
1041 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1042 if ([Manager_ fileExistsAtPath:path]) {
1043 strcpy(a1, [path UTF8String]);
1044 continue;
1045 }
1046 }
1047 }
1048 }
1049 return value;
1050 }
1051
1052 static void ChangeWallpaper(
1053 CFNotificationCenterRef center,
1054 void *observer,
1055 CFStringRef name,
1056 const void *object,
1057 CFDictionaryRef info
1058 ) {
1059 if (Debug_)
1060 NSLog(@"WB:Debug:ChangeWallpaper!");
1061
1062 UIImage *image;
1063 if (WallpaperFile_ != nil) {
1064 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1065 if (image != nil)
1066 image = [image autorelease];
1067 } else image = nil;
1068
1069 if (WallpaperImage_ != nil)
1070 [WallpaperImage_ setImage:image];
1071 if (WallpaperPage_ != nil)
1072 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1073
1074 }
1075
1076 #define WBRename(name, sel, imp) \
1077 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1078
1079 extern "C" void WBInitialize() {
1080 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1081
1082 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1083
1084 NSLog(@"WB:Notice: WinterBoard");
1085
1086 struct nlist nl[9];
1087 memset(nl, 0, sizeof(nl));
1088
1089 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1090 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1091 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1092 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1093 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1094 nl[5].n_un.n_name = (char *) "__UISharedImageInitialize";
1095 nl[6].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1096 nl[7].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1097
1098 nlist(UIKit, nl);
1099
1100 _UIApplicationImageWithName = (UIImage *(*)(NSString *)) nl[0].n_value;
1101 _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[1].n_value;
1102 _UIImageRefAtPath = (CGImageRef (*)(NSString *, bool, UIImageOrientation *)) nl[2].n_value;
1103 _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[3].n_value;
1104 _UIKitBundle = (NSBundle *(*)()) nl[4].n_value;
1105 _UISharedImageInitialize = (void (*)(bool)) nl[5].n_value;
1106 _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[6].n_value;
1107 _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[7].n_value;
1108
1109 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1110 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1111 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1112 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1113
1114 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1115
1116 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1117 struct nlist nl[2];
1118 memset(nl, 0, sizeof(nl));
1119 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1120 nlist(AudioToolbox, nl);
1121 _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value;
1122 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1123 }
1124
1125 $NSBundle = objc_getClass("NSBundle");
1126
1127 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1128 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1129
1130 $UIImage = objc_getClass("UIImage");
1131 $UINavigationBar = objc_getClass("UINavigationBar");
1132 $UIToolbar = objc_getClass("UIToolbar");
1133
1134 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1135
1136 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1137 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1138
1139 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1140 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1141
1142 _UISharedImageInitialize(false);
1143
1144 Manager_ = [[NSFileManager defaultManager] retain];
1145 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1146 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1147 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1148 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1149 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1150
1151 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1152
1153 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1154 [settings autorelease];
1155
1156 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1157 Debug_ = [debug boolValue];
1158
1159 NSArray *themes = [settings objectForKey:@"Themes"];
1160 if (themes == nil)
1161 if (NSString *theme = [settings objectForKey:@"Theme"])
1162 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1163 theme, @"Name",
1164 [NSNumber numberWithBool:true], @"Active",
1165 nil]];
1166 if (themes != nil)
1167 for (NSDictionary *theme in themes) {
1168 NSNumber *active = [theme objectForKey:@"Active"];
1169 if (![active boolValue])
1170 continue;
1171
1172 NSString *name = [theme objectForKey:@"Name"];
1173 if (name == nil)
1174 continue;
1175
1176 NSString *theme = nil;
1177
1178 #define testForTheme(format...) \
1179 if (theme == nil) { \
1180 NSString *path = [NSString stringWithFormat:format]; \
1181 if ([Manager_ fileExistsAtPath:path]) { \
1182 [themes_ addObject:path]; \
1183 continue; \
1184 } \
1185 }
1186
1187 testForTheme(@"/Library/Themes/%@.theme", name)
1188 testForTheme(@"/Library/Themes/%@", name)
1189 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1190 }
1191 }
1192
1193 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1194
1195 for (NSString *theme in themes_)
1196 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1197 for (NSString *key in [info allKeys])
1198 if ([Info_ objectForKey:key] == nil)
1199 [Info_ setObject:[info objectForKey:key] forKey:key];
1200
1201 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1202 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1203 _mSMSMessageTranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$mSMSMessageTranscriptController$loadView);
1204 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1205 CFNotificationCenterAddObserver(
1206 CFNotificationCenterGetDarwinNotifyCenter(),
1207 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1208 );
1209
1210 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1211 if (MediaPlayer != nil)
1212 [MediaPlayer load];
1213
1214 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1215 $MPVideoView = objc_getClass("MPVideoView");
1216 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1217
1218 $SBApplication = objc_getClass("SBApplication");
1219 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1220 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1221 $SBButtonBar = objc_getClass("SBButtonBar");
1222 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1223 $SBContentLayer = objc_getClass("SBContentLayer");
1224 $SBIconBadge = objc_getClass("SBIconBadge");
1225 $SBIconController = objc_getClass("SBIconController");
1226 $SBIconLabel = objc_getClass("SBIconLabel");
1227 $SBIconModel = objc_getClass("SBIconModel");
1228 $SBSlidingAlertDisplay = objc_getClass("SBSlidingAlertDisplay");
1229 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1230 $SBStatusBarController = objc_getClass("SBStatusBarController");
1231 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1232 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1233 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1234
1235 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1236
1237 WBRename(SBApplication, pathForIcon, pathForIcon);
1238 WBRename(SBApplicationIcon, icon, icon);
1239 WBRename(SBBookmarkIcon, icon, icon);
1240 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1241 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1242 WBRename(SBContentLayer, initWithSize:, initWithSize$);
1243 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1244 WBRename(SBIconController, appendIconList:, appendIconList$);
1245 WBRename(SBWidgetApplicationIcon, icon, icon);
1246
1247 WBRename(SBIconLabel, drawRect:, drawRect$);
1248 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1249 WBRename(SBIconLabel, setInDock:, setInDock$);
1250
1251 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1252 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1253
1254 WBRename(SBSlidingAlertDisplay, updateDesktopImage:, updateDesktopImage$);
1255 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1256 WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1257 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1258 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1259 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1260 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1261
1262 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1263 if (English_ != nil)
1264 English_ = [English_ retain];
1265
1266 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1267 }
1268
1269 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1270
1271 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1272 [Info_ setObject:[NSNumber numberWithBool:(
1273 $getTheme$(Wallpapers_) == nil ||
1274 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1275 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1276 )] forKey:@"UndockedIconLabels"];
1277
1278 if (Debug_)
1279 NSLog(@"WB:Debug:Info = %@", [Info_ description]);
1280
1281 [pool release];
1282 }