From 603984d918c086e5e72944ba5d278f6eedcd54f0 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 20 Oct 2011 01:45:04 +0000 Subject: [PATCH] Add a new UIImages dumping mechanism. --- .gitignore | 1 - Library.mm | 17 ++++++++++++++- UIImages.mm | 61 ----------------------------------------------------- makefile | 10 +++------ 4 files changed, 19 insertions(+), 70 deletions(-) delete mode 100644 UIImages.mm diff --git a/.gitignore b/.gitignore index cb27325..2d07efa 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ WinterBoard.dylib WinterBoardSettings *.deb Optimize -UIImages winterboard diff --git a/Library.mm b/Library.mm index 6b1d4fa..e97e739 100644 --- a/Library.mm +++ b/Library.mm @@ -193,6 +193,7 @@ static BOOL (*_GSFontGetUseLegacyFontMetrics)(); (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics()) static bool Debug_ = false; +static bool UIDebug_ = false; static bool Engineer_ = false; static bool SummerBoard_ = true; static bool SpringBoard_; @@ -1546,7 +1547,18 @@ MSHook(UIImage *, _UIImageWithName, NSString *name) { if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) image = $getImage$(path); [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast(image)) forKey:key]; - return image == nil ? __UIImageWithName(name) : image; + if (image != nil) + return image; + + image = __UIImageWithName(name); + + if (UIDebug_) { + NSString *path([@"/tmp/UIImages/" stringByAppendingString:name]); + if (![Manager_ fileExistsAtPath:path]) + [UIImagePNGRepresentation(image) writeToFile:path atomically:YES]; + } + + return image; } } // }}} @@ -1855,5 +1867,8 @@ MSInitialize { } // }}} + if (Debug_ && [Manager_ fileExistsAtPath:@"/tmp/UIImages"]) + UIDebug_ = true; + [pool release]; } diff --git a/UIImages.mm b/UIImages.mm deleted file mode 100644 index f83b772..0000000 --- a/UIImages.mm +++ /dev/null @@ -1,61 +0,0 @@ -#import -#import - -#import -#import - -extern "C" { - #include -} - -extern "C" NSData *UIImagePNGRepresentation(UIImage *image); - -template -static void nlset(Type_ &function, struct nlist *nl, size_t index) { - struct nlist &name(nl[index]); - uintptr_t value(name.n_value); - if ((name.n_desc & N_ARM_THUMB_DEF) != 0) - value |= 0x00000001; - function = reinterpret_cast(value); -} - -int main(int argc, char *argv[]) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - struct nlist nl[4]; - - memset(nl, 0, sizeof(nl)); - nl[0].n_un.n_name = (char *) "___mappedImages"; - nl[1].n_un.n_name = (char *) "__UISharedImageInitialize"; - nl[2].n_un.n_name = (char *) "_LoadMappedImageRef"; - nlist("/System/Library/Frameworks/UIKit.framework/UIKit", nl); - - NSMutableDictionary **images; - nlset(images, nl, 0); - - void (*__UISharedImageInitialize)(bool); - nlset(__UISharedImageInitialize, nl, 1); - - CGImageRef (*_LoadMappedImageRef)(CFStringRef); - nlset(_LoadMappedImageRef, nl, 2); - - __UISharedImageInitialize(false); - - NSArray *keys = [*images allKeys]; - for (int i(0), e([keys count]); i != e; ++i) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *key = [keys objectAtIndex:i]; - CGImageRef ref; - if (_LoadMappedImageRef == NULL) - ref = reinterpret_cast([*images objectForKey:key]); - else - ref = _LoadMappedImageRef(reinterpret_cast(key)); - UIImage *image = [UIImage imageWithCGImage:ref]; - NSData *data = UIImagePNGRepresentation(image); - [data writeToFile:[NSString stringWithFormat:@"%@", key] atomically:YES]; - [pool release]; - } - - [pool release]; - return 0; -} diff --git a/makefile b/makefile index 3735b69..429d952 100644 --- a/makefile +++ b/makefile @@ -6,10 +6,10 @@ endif substrate := -I../mobilesubstrate -L../mobilesubstrate -lsubstrate -all: WinterBoard WinterBoard.dylib UIImages WinterBoardSettings Optimize +all: WinterBoard WinterBoard.dylib WinterBoardSettings Optimize clean: - rm -f WinterBoard WinterBoard.dylib UIImages + rm -f WinterBoard WinterBoard.dylib WinterBoardSettings: Settings.mm makefile $(target)g++ -dynamiclib -g0 -O2 -Wall -o $@ $(filter %.mm,$^) -framework UIKit -framework CoreFoundation -framework Foundation -lobjc -framework CoreGraphics -framework Preferences -F$(PKG_ROOT)/System/Library/PrivateFrameworks @@ -19,10 +19,6 @@ WinterBoard.dylib: Library.mm WBMarkup.mm WBMarkup.h makefile ../mobilesubstrate $(target)g++ -dynamiclib -g0 -O2 -Wall -o $@ $(filter %.mm,$^) -framework CoreFoundation -framework Foundation -lobjc -I/apl/inc/iPhoneOS-2.0 -framework CoreGraphics -framework ImageIO -framework GraphicsServices -framework Celestial $(substrate) -framework UIKit -framework WebCore -framework WebKit -F$(PKG_ROOT)/System/Library/PrivateFrameworks ldid -S $@ -UIImages: UIImages.mm makefile - $(target)g++ -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework Foundation -framework CoreFoundation -lobjc -I/apl/inc/iPhoneOS-2.0 $(substrate) - ldid -S $@ - WinterBoard: Application.mm makefile $(target)g++ -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework Foundation -framework CoreFoundation -lobjc -framework CoreGraphics -I/apl/sdk -framework Preferences -F$(PKG_ROOT)/System/Library/PrivateFrameworks ldid -S $@ @@ -53,7 +49,7 @@ package: all find winterboard -name .svn | while read -r line; do rm -rf "$${line}"; done cp -a extrainst_ preinst prerm winterboard/DEBIAN sed -e 's/VERSION/$(shell ./version.sh)/g' control >winterboard/DEBIAN/control - cp -a Test.sh Icon-Small.png icon.png icon-72.png icon@2x.png WinterBoard.dylib WinterBoard UIImages Info.plist winterboard/Applications/WinterBoard.app + cp -a Test.sh Icon-Small.png icon.png icon-72.png icon@2x.png WinterBoard.dylib WinterBoard Info.plist winterboard/Applications/WinterBoard.app file="winterboard_$$(grep ^Version: winterboard/DEBIAN/control | cut -d ' ' -f 2)_iphoneos-arm.deb"; echo "$$file"; ln -sf "$$file" winterboard.deb dpkg-deb -b winterboard winterboard.deb -- 2.45.2