]> git.saurik.com Git - uikittools.git/blob - gssc.mm
Merge uicache from WinterBoard Settings.
[uikittools.git] / gssc.mm
1 #import <GraphicsServices/GraphicsServices.h>
2 #import <UIKit/UIKit.h>
3 #include <stdio.h>
4 #include <dlfcn.h>
5 #include <objc/runtime.h>
6
7 static CFArrayRef (*$GSSystemCopyCapability)(CFStringRef);
8 static CFArrayRef (*$GSSystemGetCapability)(CFStringRef);
9
10 void OnGSCapabilityChanged(
11 CFNotificationCenterRef center,
12 void *observer,
13 CFStringRef name,
14 const void *object,
15 CFDictionaryRef info
16 ) {
17 CFRunLoopStop(CFRunLoopGetCurrent());
18 }
19
20 int main(int argc, char *argv[]) {
21 dlopen("/System/Library/Frameworks/Foundation.framework/Foundation", RTLD_GLOBAL | RTLD_LAZY);
22 dlopen("/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices", RTLD_GLOBAL | RTLD_LAZY);
23
24 NSAutoreleasePool *pool = [[objc_getClass("NSAutoreleasePool") alloc] init];
25
26 NSString *name = nil;
27
28 if (argc == 2)
29 name = [objc_getClass("NSString") stringWithUTF8String:argv[0]];
30 else if (argc > 2) {
31 fprintf(stderr, "usage: %s [capability]\n", argv[0]);
32 exit(1);
33 }
34
35 $GSSystemCopyCapability = reinterpret_cast<CFArrayRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemCopyCapability"));
36 $GSSystemGetCapability = reinterpret_cast<CFArrayRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemGetCapability"));
37
38 CFNotificationCenterAddObserver(
39 CFNotificationCenterGetDarwinNotifyCenter(),
40 NULL,
41 &OnGSCapabilityChanged,
42 CFSTR("GSCapabilitiesChanged"),
43 NULL,
44 NULL
45 );
46
47 const NSArray *capability;
48
49 for (;;) {
50 if ($GSSystemCopyCapability != NULL) {
51 capability = reinterpret_cast<const NSArray *>((*$GSSystemCopyCapability)(reinterpret_cast<CFStringRef>(name)));
52 if (capability != nil)
53 capability = [capability autorelease];
54 } else if ($GSSystemGetCapability != NULL) {
55 capability = reinterpret_cast<const NSArray *>((*$GSSystemGetCapability)(reinterpret_cast<CFStringRef>(name)));
56 } else {
57 capability = nil;
58 break;
59 }
60
61 if (capability != nil)
62 break;
63
64 CFRunLoopRun();
65 }
66
67 printf("%s\n", capability == nil ? "(null)" : [[capability description] UTF8String]);
68
69 [pool release];
70
71 return 0;
72 }