]> git.saurik.com Git - winterboard.git/blob - UIImages.mm
I forgot the version.sh.
[winterboard.git] / UIImages.mm
1 #import <Foundation/Foundation.h>
2 #import <CoreGraphics/CoreGraphics.h>
3
4 #import <UIKit/UIKeyboard.h>
5 #import <UIKit/UIImage.h>
6
7 extern "C" {
8 #include <mach-o/nlist.h>
9 }
10
11 extern "C" NSData *UIImagePNGRepresentation(UIImage *image);
12
13 template <typename Type_>
14 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
15 struct nlist &name(nl[index]);
16 uintptr_t value(name.n_value);
17 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
18 value |= 0x00000001;
19 function = reinterpret_cast<Type_>(value);
20 }
21
22 int main(int argc, char *argv[]) {
23 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
24
25 struct nlist nl[4];
26
27 memset(nl, 0, sizeof(nl));
28 nl[0].n_un.n_name = (char *) "___mappedImages";
29 nl[1].n_un.n_name = (char *) "__UISharedImageInitialize";
30 nl[2].n_un.n_name = (char *) "_LoadMappedImageRef";
31 nlist("/System/Library/Frameworks/UIKit.framework/UIKit", nl);
32
33 NSMutableDictionary **images;
34 nlset(images, nl, 0);
35
36 void (*__UISharedImageInitialize)(bool);
37 nlset(__UISharedImageInitialize, nl, 1);
38
39 CGImageRef (*_LoadMappedImageRef)(CFStringRef);
40 nlset(_LoadMappedImageRef, nl, 2);
41
42 __UISharedImageInitialize(false);
43
44 NSArray *keys = [*images allKeys];
45 for (int i(0), e([keys count]); i != e; ++i) {
46 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
47 NSString *key = [keys objectAtIndex:i];
48 CGImageRef ref;
49 if (_LoadMappedImageRef == NULL)
50 ref = reinterpret_cast<CGImageRef>([*images objectForKey:key]);
51 else
52 ref = _LoadMappedImageRef(reinterpret_cast<CFStringRef>(key));
53 UIImage *image = [UIImage imageWithCGImage:ref];
54 NSData *data = UIImagePNGRepresentation(image);
55 [data writeToFile:[NSString stringWithFormat:@"%@", key] atomically:YES];
56 [pool release];
57 }
58
59 [pool release];
60 return 0;
61 }