From: Jay Freeman (saurik) Date: Sat, 2 Aug 2008 11:23:40 +0000 (+0000) Subject: This was so easy I can't believe no one else did it already. X-Git-Tag: v0.9.3900~93 X-Git-Url: https://git.saurik.com/winterboard.git/commitdiff_plain/d5168fd61a6baa46200ca1e5bbacd0f55447e5b5 This was so easy I can't believe no one else did it already. --- diff --git a/DevEngine.mm b/DevEngine.mm deleted file mode 100644 index e62a62c..0000000 --- a/DevEngine.mm +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -#import -#import -#import - -static unsigned connectedDevices_; - -@interface SBBluetoothController (_WinterBoard) -- (void) wb_noteDevicesChanged; -@end - -@implementation SBBluetoothController (WinterBoard) - -- (void) noteDevicesChanged { - if (NSArray *devices = [[BluetoothManager sharedInstance] pairedDevices]) { - connectedDevices_ = 0; - for (int i = 0, e = [devices count]; i != e; ++i) - if ([[devices objectAtIndex:i] connected]) - ++connectedDevices_; - if (connectedDevices_ == 0) - unlink("/tmp/neuter"); - else - close(open("/tmp/neuter", O_CREAT | O_TRUNC | O_WRONLY, 644)); - } - - [self wb_noteDevicesChanged]; -} - -@end diff --git a/Initialization.m b/Initialization.m deleted file mode 100644 index 2ba6d8f..0000000 --- a/Initialization.m +++ /dev/null @@ -1,34 +0,0 @@ -#import -#include - -#define WBPrefix "wb_" - -void WBRename(const char *classname, const char *oldname) { - Class class = objc_getClass(classname); - size_t namelen = strlen(oldname); - char newname[sizeof(WBPrefix) + namelen]; - memcpy(newname, WBPrefix, sizeof(WBPrefix) - 1); - memcpy(newname + sizeof(WBPrefix) - 1, oldname, namelen + 1); - Method method = class_getInstanceMethod(class, sel_getUid(oldname)); - if (!class_addMethod(class, sel_registerName(newname), method->method_imp, method->method_types)) - NSLog(@"WB: failed to rename %s::%s", classname, oldname); -} - -void WBInitialize() { - if (NSClassFromString(@"SpringBoard") == nil) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - NSLog(@"WB: changing season"); - - WBRename("SBBluetoothController", "noteDevicesChanged"); - - NSBundle *bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/WinterBoard.framework"]; - if (bundle == nil) - NSLog(@"WB: there is no Santa :("); - else if (![bundle load]) - NSLog(@"WB: sleigh was too heavy"); - - [pool release]; -} diff --git a/WinterBoard.mm b/WinterBoard.mm new file mode 100644 index 0000000..131624c --- /dev/null +++ b/WinterBoard.mm @@ -0,0 +1,188 @@ +/* WinterBoard - Theme Manager for the iPhone + * Copyright (C) 2008 Jay Freeman (saurik) +*/ + +/* + * Redistribution and use in source and binary + * forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the + * above copyright notice, this list of conditions + * and the following disclaimer. + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions + * and the following disclaimer in the documentation + * and/or other materials provided with the + * distribution. + * 3. The name of the author may not be used to endorse + * or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include + +#import + +#import +#import +#import +#import + +#import +#import +#import +#import + +#import + +/* WinterBoard Backend {{{ */ +#define WBPrefix "wb_" + +void WBInject(const char *classname, const char *oldname, IMP newimp, const char *type) { + Class _class = objc_getClass(classname); + if (_class == nil) + return; + if (!class_addMethod(_class, sel_registerName(oldname), newimp, type)) + NSLog(@"WB: failed to inject [%s %s]", classname, oldname); +} + +void WBRename(const char *classname, const char *oldname, IMP newimp) { + Class _class = objc_getClass(classname); + if (_class == nil) + return; + size_t namelen = strlen(oldname); + char newname[sizeof(WBPrefix) + namelen]; + memcpy(newname, WBPrefix, sizeof(WBPrefix) - 1); + memcpy(newname + sizeof(WBPrefix) - 1, oldname, namelen + 1); + Method method = class_getInstanceMethod(_class, sel_getUid(oldname)); + if (method == nil) + return; + const char *type = method_getTypeEncoding(method); + if (!class_addMethod(_class, sel_registerName(newname), method_getImplementation(method), type)) + NSLog(@"WB: failed to rename [%s %s]", classname, oldname); + unsigned int count; + Method *methods = class_copyMethodList(_class, &count); + for (unsigned int index(0); index != count; ++index) + if (methods[index] == method) + goto found; + if (newimp != NULL) + if (!class_addMethod(_class, sel_getUid(oldname), newimp, type)) + NSLog(@"WB: failed to rename [%s %s]", classname, oldname); + goto done; + found: + if (newimp != NULL) + method_setImplementation(method, newimp); + done: + free(methods); +} + +static NSString *Dylib_ = @"/System/Library/PrivateFrameworks/WinterBoard.framework/WinterBoard.dylib"; +/* }}} */ + +@protocol WinterBoard +- (NSString *) wb_pathForIcon; +- (NSString *) wb_pathForResource:(NSString *)resource ofType:(NSString *)type; +- (id) wb_initWithSize:(CGSize)size; +- (void) wb_setBackgroundColor:(id)color; +@end + +NSString *Themes_ = @"/System/Library/Themes"; +NSString *theme_ = @"Litho"; + +NSString *SBApplication$pathForIcon(SBApplication *self, SEL sel) { + NSFileManager *manager([NSFileManager defaultManager]); + NSString *path; + path = [NSString stringWithFormat:@"%@/%@/Icons/%@.png", Themes_, theme_, [self displayName]]; + if ([manager fileExistsAtPath:path]) + return path; + path = [NSString stringWithFormat:@"%@/%@/Icons/%@.png", Themes_, theme_, [self bundleIdentifier]]; + if ([manager fileExistsAtPath:path]) + return path; + return [self wb_pathForIcon]; +} + +NSString *NSBundle$pathForResource$ofType$(NSBundle *self, SEL sel, NSString *resource, NSString *type) { + if ([resource isEqualToString:@"SBDockBG"] && [type isEqualToString:@"png"]) { + NSFileManager *manager([NSFileManager defaultManager]); + NSString *path = [NSString stringWithFormat:@"%@/%@/Dock.png", Themes_, theme_]; + if ([manager fileExistsAtPath:path]) + return path; + } + + return [self wb_pathForResource:resource ofType:type]; +} + +void SBAppWindow$setBackgroundColor$(SBAppWindow *self, SEL sel, id color) { + [self wb_setBackgroundColor:[UIColor clearColor]]; +} + +id SBContentLayer$initWithSize$(SBContentLayer *self, SEL sel, CGSize size) { + self = [self wb_initWithSize:size]; + if (self == nil) + return nil; + + NSFileManager *manager([NSFileManager defaultManager]); + NSString *path = [NSString stringWithFormat:@"%@/%@/Wallpaper.png", Themes_, theme_]; + if ([manager fileExistsAtPath:path]) + if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) { + /*window_ = [[UIWindow alloc] initWithContentRect:CGRectMake(0, 0, 320, 480)]; + [window_ setHidden:NO];*/ + UIImageView *view = [[[UIImageView alloc] initWithImage:image] autorelease]; + //[view setFrame:CGRectMake(0, -10, 320, 480)]; + [self addSubview:view]; + } + + return self; +} + +extern "C" void WBInitialize() { + /* WinterBoard FrontEnd {{{ */ + if (NSClassFromString(@"SpringBoard") == nil) + return; + NSLog(@"WB: installing WinterBoard..."); + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + char *dil = getenv("DYLD_INSERT_LIBRARIES"); + if (dil == NULL) + NSLog(@"WB: DYLD_INSERT_LIBRARIES is unset?"); + else { + NSArray *dylibs = [[NSString stringWithUTF8String:dil] componentsSeparatedByString:@":"]; + int index = [dylibs indexOfObject:Dylib_]; + if (index == INT_MAX) + NSLog(@"WB: dylib not in DYLD_INSERT_LIBRARIES?"); + else if ([dylibs count] == 1) + unsetenv("DYLD_INSERT_LIBRARIES"); + else { + NSMutableArray *value = [[NSMutableArray alloc] init]; + [value setArray:dylibs]; + [value removeObjectAtIndex:index]; + setenv("DYLD_INSERT_LIBRARIES", [[value componentsJoinedByString:@":"] UTF8String], !0); + } + } + /* }}} */ + + WBRename("SBApplication", "pathForIcon", (IMP) &SBApplication$pathForIcon); + WBRename("NSBundle", "pathForResource:ofType:", (IMP) &NSBundle$pathForResource$ofType$); + WBRename("SBAppWindow", "setBackgroundColor:", (IMP) &SBAppWindow$setBackgroundColor$); + WBRename("SBContentLayer", "initWithSize:", (IMP) &SBContentLayer$initWithSize$); + + [pool release]; +} diff --git a/make.sh b/make.sh index 843df27..49b6930 100755 --- a/make.sh +++ b/make.sh @@ -1,2 +1,6 @@ #!/bin/bash -PATH=/apl/n42/pre/bin:$PATH exec /apl/tel/exec.sh com.saurik.winterboard make "$@" +set -e +export PKG_ARCH=${PKG_ARCH-iphoneos-arm} +PATH=/apl/n42/pre/bin:$PATH /apl/tel/exec.sh com.saurik.winterboard make "$@" +export CODESIGN_ALLOCATE=$(which arm-apple-darwin9-codesign_allocate) +/apl/tel/util/ldid -S WinterBoard.dylib diff --git a/makefile b/makefile index 2b58b06..d4deec3 100644 --- a/makefile +++ b/makefile @@ -4,15 +4,12 @@ else target := $(PKG_TARG)- endif -all: WinterBoard WinterBoard.dylib +all: WinterBoard.dylib clean: rm -f WinterBoard.dylib -WinterBoard: *.mm makefile - $(target)gcc -fobjc-call-cxx-cdtors -bundle -g3 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework CoreFoundation -framework Foundation -framework UIKit -lobjc -fobjc-exceptions -flat_namespace -undefined suppress -I../uicaboodle.m - -WinterBoard.dylib: Initialization.m makefile - $(target)gcc -dynamiclib -g3 -O2 -Wall -Werror -o $@ $(filter %.m,$^) -framework CoreFoundation -framework Foundation -lobjc -init _WBInitialize +WinterBoard.dylib: WinterBoard.mm makefile + $(target)g++ -dynamiclib -g3 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework CoreFoundation -framework Foundation -lobjc -init _WBInitialize -I/apl/inc/iPhoneOS-2.0 -framework UIKit .PHONY: all clean