1 #import <Foundation/Foundation.h>
2 #import <CoreGraphics/CoreGraphics.h>
4 #import <UIKit/UIKeyboard.h>
5 #import <UIKit/UIImage.h>
8 #include <mach-o/nlist.h>
11 extern "C" NSData *UIImagePNGRepresentation(UIImage *image);
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)
19 function = reinterpret_cast<Type_>(value);
22 int main(int argc, char *argv[]) {
23 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
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);
33 NSMutableDictionary **images;
36 void (*__UISharedImageInitialize)(bool);
37 nlset(__UISharedImageInitialize, nl, 1);
39 CGImageRef (*_LoadMappedImageRef)(CFStringRef);
40 nlset(_LoadMappedImageRef, nl, 2);
42 __UISharedImageInitialize(false);
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];
49 if (_LoadMappedImageRef == NULL)
50 ref = reinterpret_cast<CGImageRef>([*images objectForKey:key]);
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];