]> git.saurik.com Git - winterboard.git/blame - UIImages.mm
Just stop using isWildcat: too risky.
[winterboard.git] / UIImages.mm
CommitLineData
ca13798d
JF
1#import <Foundation/Foundation.h>
2#import <CoreGraphics/CoreGraphics.h>
95a5777b
JF
3
4#import <UIKit/UIKeyboard.h>
5#import <UIKit/UIImage.h>
ca13798d
JF
6
7extern "C" {
8 #include <mach-o/nlist.h>
9}
10
95a5777b
JF
11extern "C" NSData *UIImagePNGRepresentation(UIImage *image);
12
cd582987
JF
13template <typename Type_>
14static 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
ca13798d
JF
22int main(int argc, char *argv[]) {
23 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
24
2acbe5b8 25 struct nlist nl[4];
cd582987 26
ca13798d
JF
27 memset(nl, 0, sizeof(nl));
28 nl[0].n_un.n_name = (char *) "___mappedImages";
29 nl[1].n_un.n_name = (char *) "__UISharedImageInitialize";
2acbe5b8 30 nl[2].n_un.n_name = (char *) "_LoadMappedImageRef";
ca13798d 31 nlist("/System/Library/Frameworks/UIKit.framework/UIKit", nl);
cd582987
JF
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);
ca13798d
JF
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];
2acbe5b8
JF
48 CGImageRef ref;
49 if (_LoadMappedImageRef == NULL)
50 ref = reinterpret_cast<CGImageRef>([*images objectForKey:key]);
51 else
52 ref = _LoadMappedImageRef(reinterpret_cast<CFStringRef>(key));
ca13798d
JF
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}