]> git.saurik.com Git - winterboard.git/blob - Initialization.m
2ba6d8f178cd77291dca809ad3efd89d7c293df1
[winterboard.git] / Initialization.m
1 #import <Foundation/Foundation.h>
2 #include <objc/runtime.h>
3
4 #define WBPrefix "wb_"
5
6 void WBRename(const char *classname, const char *oldname) {
7 Class class = objc_getClass(classname);
8 size_t namelen = strlen(oldname);
9 char newname[sizeof(WBPrefix) + namelen];
10 memcpy(newname, WBPrefix, sizeof(WBPrefix) - 1);
11 memcpy(newname + sizeof(WBPrefix) - 1, oldname, namelen + 1);
12 Method method = class_getInstanceMethod(class, sel_getUid(oldname));
13 if (!class_addMethod(class, sel_registerName(newname), method->method_imp, method->method_types))
14 NSLog(@"WB: failed to rename %s::%s", classname, oldname);
15 }
16
17 void WBInitialize() {
18 if (NSClassFromString(@"SpringBoard") == nil)
19 return;
20
21 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
22
23 NSLog(@"WB: changing season");
24
25 WBRename("SBBluetoothController", "noteDevicesChanged");
26
27 NSBundle *bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/WinterBoard.framework"];
28 if (bundle == nil)
29 NSLog(@"WB: there is no Santa :(");
30 else if (![bundle load])
31 NSLog(@"WB: sleigh was too heavy");
32
33 [pool release];
34 }