]>
Commit | Line | Data |
---|---|---|
a4ccf03b JF |
1 | /* UIKit Tools - command-line utilities for UIKit |
2 | * Copyright (C) 2008-2012 Jay Freeman (saurik) | |
3 | */ | |
4 | ||
5 | /* Modified BSD License {{{ */ | |
6 | /* | |
7 | * Redistribution and use in source and binary | |
8 | * forms, with or without modification, are permitted | |
9 | * provided that the following conditions are met: | |
10 | * | |
11 | * 1. Redistributions of source code must retain the | |
12 | * above copyright notice, this list of conditions | |
13 | * and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the | |
15 | * above copyright notice, this list of conditions | |
16 | * and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the | |
18 | * distribution. | |
19 | * 3. The name of the author may not be used to endorse | |
20 | * or promote products derived from this software | |
21 | * without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
25 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
36 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | |
38 | /* }}} */ | |
39 | ||
020dfc54 JF |
40 | #import <GraphicsServices/GraphicsServices.h> |
41 | #import <UIKit/UIKit.h> | |
42 | #include <stdio.h> | |
43 | #include <dlfcn.h> | |
7141b425 | 44 | #include <objc/runtime.h> |
020dfc54 JF |
45 | |
46 | static CFArrayRef (*$GSSystemCopyCapability)(CFStringRef); | |
47 | static CFArrayRef (*$GSSystemGetCapability)(CFStringRef); | |
48 | ||
04ee9f37 JF |
49 | void OnGSCapabilityChanged( |
50 | CFNotificationCenterRef center, | |
51 | void *observer, | |
52 | CFStringRef name, | |
53 | const void *object, | |
54 | CFDictionaryRef info | |
55 | ) { | |
56 | CFRunLoopStop(CFRunLoopGetCurrent()); | |
57 | } | |
58 | ||
020dfc54 | 59 | int main(int argc, char *argv[]) { |
7141b425 JF |
60 | dlopen("/System/Library/Frameworks/Foundation.framework/Foundation", RTLD_GLOBAL | RTLD_LAZY); |
61 | dlopen("/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices", RTLD_GLOBAL | RTLD_LAZY); | |
62 | ||
63 | NSAutoreleasePool *pool = [[objc_getClass("NSAutoreleasePool") alloc] init]; | |
020dfc54 JF |
64 | |
65 | NSString *name = nil; | |
66 | ||
67 | if (argc == 2) | |
7141b425 | 68 | name = [objc_getClass("NSString") stringWithUTF8String:argv[0]]; |
020dfc54 JF |
69 | else if (argc > 2) { |
70 | fprintf(stderr, "usage: %s [capability]\n", argv[0]); | |
71 | exit(1); | |
72 | } | |
73 | ||
74 | $GSSystemCopyCapability = reinterpret_cast<CFArrayRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemCopyCapability")); | |
75 | $GSSystemGetCapability = reinterpret_cast<CFArrayRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemGetCapability")); | |
76 | ||
04ee9f37 JF |
77 | CFNotificationCenterAddObserver( |
78 | CFNotificationCenterGetDarwinNotifyCenter(), | |
79 | NULL, | |
80 | &OnGSCapabilityChanged, | |
81 | CFSTR("GSCapabilitiesChanged"), | |
82 | NULL, | |
83 | NULL | |
84 | ); | |
85 | ||
020dfc54 JF |
86 | const NSArray *capability; |
87 | ||
04ee9f37 JF |
88 | for (;;) { |
89 | if ($GSSystemCopyCapability != NULL) { | |
90 | capability = reinterpret_cast<const NSArray *>((*$GSSystemCopyCapability)(reinterpret_cast<CFStringRef>(name))); | |
91 | if (capability != nil) | |
92 | capability = [capability autorelease]; | |
93 | } else if ($GSSystemGetCapability != NULL) { | |
94 | capability = reinterpret_cast<const NSArray *>((*$GSSystemGetCapability)(reinterpret_cast<CFStringRef>(name))); | |
95 | } else { | |
96 | capability = nil; | |
97 | break; | |
98 | } | |
99 | ||
100 | if (capability != nil) | |
101 | break; | |
102 | ||
103 | CFRunLoopRun(); | |
104 | } | |
020dfc54 | 105 | |
7141b425 | 106 | printf("%s\n", capability == nil ? "(null)" : [[capability description] UTF8String]); |
020dfc54 JF |
107 | |
108 | [pool release]; | |
109 | ||
110 | return 0; | |
111 | } |