]>
Commit | Line | Data |
---|---|---|
020dfc54 JF |
1 | #import <GraphicsServices/GraphicsServices.h> |
2 | #import <UIKit/UIKit.h> | |
3 | #include <stdio.h> | |
4 | #include <dlfcn.h> | |
7141b425 | 5 | #include <objc/runtime.h> |
020dfc54 JF |
6 | |
7 | static CFArrayRef (*$GSSystemCopyCapability)(CFStringRef); | |
8 | static CFArrayRef (*$GSSystemGetCapability)(CFStringRef); | |
9 | ||
04ee9f37 JF |
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 | ||
020dfc54 | 20 | int main(int argc, char *argv[]) { |
7141b425 JF |
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]; | |
020dfc54 JF |
25 | |
26 | NSString *name = nil; | |
27 | ||
28 | if (argc == 2) | |
7141b425 | 29 | name = [objc_getClass("NSString") stringWithUTF8String:argv[0]]; |
020dfc54 JF |
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 | ||
04ee9f37 JF |
38 | CFNotificationCenterAddObserver( |
39 | CFNotificationCenterGetDarwinNotifyCenter(), | |
40 | NULL, | |
41 | &OnGSCapabilityChanged, | |
42 | CFSTR("GSCapabilitiesChanged"), | |
43 | NULL, | |
44 | NULL | |
45 | ); | |
46 | ||
020dfc54 JF |
47 | const NSArray *capability; |
48 | ||
04ee9f37 JF |
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 | } | |
020dfc54 | 66 | |
7141b425 | 67 | printf("%s\n", capability == nil ? "(null)" : [[capability description] UTF8String]); |
020dfc54 JF |
68 | |
69 | [pool release]; | |
70 | ||
71 | return 0; | |
72 | } |