]> git.saurik.com Git - uikittools.git/blob - gssc.mm
0e1f92f7ca942bb3e6e689a1907f87dc889e9465
[uikittools.git] / gssc.mm
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
40 #import <GraphicsServices/GraphicsServices.h>
41 #import <UIKit/UIKit.h>
42 #include <stdio.h>
43 #include <dlfcn.h>
44 #include <objc/runtime.h>
45
46 static CFArrayRef (*$GSSystemCopyCapability)(CFStringRef);
47 static CFArrayRef (*$GSSystemGetCapability)(CFStringRef);
48
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
59 int main(int argc, char *argv[]) {
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];
64
65 NSString *name = nil;
66
67 if (argc == 2)
68 name = [objc_getClass("NSString") stringWithUTF8String:argv[0]];
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
77 CFNotificationCenterAddObserver(
78 CFNotificationCenterGetDarwinNotifyCenter(),
79 NULL,
80 &OnGSCapabilityChanged,
81 CFSTR("GSCapabilitiesChanged"),
82 NULL,
83 NULL
84 );
85
86 for (;;) {
87 const NSDictionary *capability;
88
89 if ($GSSystemCopyCapability != NULL) {
90 capability = reinterpret_cast<const NSDictionary *>((*$GSSystemCopyCapability)(reinterpret_cast<CFStringRef>(name)));
91 if (capability != nil)
92 capability = [capability autorelease];
93 } else if ($GSSystemGetCapability != NULL) {
94 capability = reinterpret_cast<const NSDictionary *>((*$GSSystemGetCapability)(reinterpret_cast<CFStringRef>(name)));
95 } else {
96 if (void *libMobileGestalt = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_GLOBAL | RTLD_LAZY))
97 if (CFTypeRef (*$MGCopyAnswer)(CFStringRef) = reinterpret_cast<CFTypeRef (*)(CFStringRef)>(dlsym(libMobileGestalt, "MGCopyAnswer"))) {
98 NSMutableDictionary *answers([NSMutableDictionary dictionary]);
99 for (NSString *name in [NSArray arrayWithObjects:
100 @"ActiveWirelessTechnology",
101 //@"AirplaneMode",
102 @"AllDeviceCapabilities",
103 @"AllowYouTube",
104 @"AllowYouTubePlugin",
105 //@"ApNonce",
106 //@"AppleInternalInstallCapability",
107 @"assistant",
108 //@"BasebandBoardSnum",
109 //@"BasebandCertId",
110 //@"BasebandChipId",
111 //@"BasebandFirmwareManifestData",
112 @"BasebandFirmwareVersion",
113 //@"BasebandKeyHashInformation",
114 //@"BasebandRegionSKU",
115 //@"BasebandSerialNumber",
116 @"BatteryCurrentCapacity",
117 @"BatteryIsCharging",
118 @"BatteryIsFullyCharged",
119 //@"BluetoothAddress",
120 @"BoardId",
121 @"BuildVersion",
122 @"CPUArchitecture",
123 //@"CarrierBundleInfoArray",
124 @"CarrierInstallCapability",
125 @"cellular-data",
126 @"ChipID",
127 //@"CompassCalibration",
128 //@"CompassCalibrationDictionary",
129 //@"ComputerName",
130 @"contains-cellular-radio",
131 @"DeviceClass",
132 @"DeviceClassNumber",
133 @"DeviceColor",
134 @"DeviceEnclosureColor",
135 //@"DeviceName",
136 @"DeviceSupports1080p",
137 @"DeviceSupports3DImagery",
138 @"DeviceSupports3DMaps",
139 @"DeviceSupports4G",
140 @"DeviceSupports720p",
141 @"DeviceSupports9Pin",
142 @"DeviceSupportsFaceTime",
143 @"DeviceSupportsLineIn",
144 @"DeviceSupportsNavigation",
145 @"DeviceSupportsSimplisticRoadMesh",
146 @"DeviceSupportsTethering",
147 @"DeviceVariant",
148 //@"DiagData",
149 @"dictation",
150 //@"DieId",
151 //@"DiskUsage",
152 @"encrypted-data-partition",
153 //@"EthernetMacAddress",
154 @"ExternalChargeCapability",
155 @"ExternalPowerSourceConnected",
156 //@"FaceTimeBitRate2G",
157 //@"FaceTimeBitRate3G",
158 //@"FaceTimeBitRateLTE",
159 //@"FaceTimeBitRateWiFi",
160 //@"FaceTimeDecodings",
161 //@"FaceTimeEncodings",
162 //@"FaceTimePreferredDecoding",
163 //@"FaceTimePreferredEncoding",
164 //@"FirmwareNonce",
165 //@"FirmwarePreflightInfo",
166 @"FirmwareVersion",
167 @"ForwardCameraCapability",
168 @"gps",
169 @"green-tea",
170 @"HWModelStr",
171 @"HardwarePlatform",
172 //@"HasAllFeaturesCapability",
173 @"HasBaseband",
174 @"HasInternalSettingsBundle",
175 @"HasSpringBoard",
176 //@"IntegratedCircuitCardIdentifier",
177 //@"InternalBuild",
178 //@"InternationalMobileEquipmentIdentity",
179 //@"InverseDeviceID",
180 //@"IsSimulator",
181 //@"IsThereEnoughBatteryLevelForSoftwareUpdate",
182 //@"IsUIBuild",
183 //@"MLBSerialNumber",
184 @"main-screen-class",
185 @"main-screen-height",
186 @"main-screen-orientation",
187 @"main-screen-pitch",
188 @"main-screen-scale",
189 @"main-screen-width",
190 @"MinimumSupportediTunesVersion",
191 //@"MobileEquipmentIdentifier",
192 //@"MobileSubscriberCountryCode",
193 //@"MobileSubscriberNetworkCode",
194 @"wi-fi",
195 @"ModelNumber",
196 @"not-green-tea",
197 @"PanoramaCameraCapability",
198 @"PartitionType",
199 @"ProductName",
200 @"ProductType",
201 @"ProductVersion",
202 //@"ProximitySensorCalibration",
203 @"RearCameraCapability",
204 @"RegionCode",
205 @"RegionInfo",
206 //@"RegionalBehaviorAll",
207 @"RegionalBehaviorChinaBrick",
208 @"RegionalBehaviorEUVolumeLimit",
209 @"RegionalBehaviorGB18030",
210 @"RegionalBehaviorGoogleMail",
211 @"RegionalBehaviorNTSC",
212 @"RegionalBehaviorNoPasscodeLocationTiles",
213 @"RegionalBehaviorNoVOIP",
214 @"RegionalBehaviorNoWiFi",
215 @"RegionalBehaviorShutterClick",
216 @"RegionalBehaviorVolumeLimit",
217 @"RegulatoryIdentifiers",
218 //@"ReleaseType",
219 @"RequiredBatteryLevelForSoftwareUpdate",
220 @"SBAllowSensitiveUI",
221 @"SBCanForceDebuggingInfo",
222 @"SDIOManufacturerTuple",
223 @"SDIOProductInfo",
224 //@"SIMTrayStatus",
225 //@"ScreenDimensions",
226 //@"screen-dimensions",
227 //@"SerialNumber",
228 @"ShouldHactivate",
229 @"SigningFuse",
230 //@"SoftwareBehavior",
231 //@"SoftwareBundleVersion",
232 @"SupportedDeviceFamilies",
233 //@"SupportedKeyboards",
234 //@"SysCfg",
235 //@"UniqueChipID",
236 //@"UniqueDeviceID",
237 //@"UniqueDeviceIDData",
238 //@"UserAssignedDeviceName",
239 //@"WifiAddress",
240 //@"WifiAddressData",
241 //@"WifiVendor",
242 //@"WirelessBoardSnum",
243 @"iTunesFamilyID",
244
245 @"720p",
246 @"1080p",
247 @"accelerometer",
248 @"accessibility",
249 @"additional-text-tones",
250 @"all-features",
251 @"any-telephony",
252 @"app-store",
253 @"application-installation",
254 @"armv6",
255 @"armv7",
256 @"assistant",
257 @"auto-focus-camera",
258 @"bluetooth",
259 @"bluetooth-le",
260 @"camera-flash",
261 @"cellular-data",
262 @"contains-cellular-radio",
263 @"dictation",
264 @"display-mirroring",
265 @"displayport",
266 @"encode-aac",
267 @"encrypted-data-partition",
268 @"fcc-logos-via-software",
269 @"front-facing-camera",
270 @"gamekit",
271 @"gas-gauge-battery",
272 @"gps",
273 @"gyroscope",
274 @"h264-encoder",
275 @"hardware-keyboard",
276 @"hd-video-capture",
277 @"hdr-image-capture",
278 @"hiccough-interval",
279 @"hidpi",
280 @"homescreen-wallpaper",
281 @"hw-encode-snapshots",
282 @"international-settings",
283 @"io-surface-backed-images",
284 @"load-thumbnails-while-scrolling",
285 @"location-services",
286 @"magnetometer",
287 @"microphone",
288 @"mms",
289 @"multitasking",
290 @"music-store",
291 @"nike-ipod",
292 @"not-green-tea",
293 @"opengles-1",
294 @"opengles-2",
295 @"peer-peer",
296 @"photo-adjustments",
297 @"photo-stream",
298 @"proximity-sensor",
299 @"ptp-large-files",
300 @"ringer-switch",
301 @"sms",
302 @"stand-alone-contacts",
303 @"still-camera",
304 @"telephony",
305 @"telephony-maximum-generation",
306 @"tv-out-crossfade",
307 @"tv-out-settings",
308 @"unified-ipod",
309 @"venice",
310 @"video-camera",
311 @"voice-control",
312 @"voip",
313 @"volume-buttons",
314 @"wifi",
315 @"youtube",
316 @"youtube-plugin",
317 @"ipad",
318 @"wildcat",
319 nil])
320 if (CFTypeRef answer = $MGCopyAnswer(reinterpret_cast<CFStringRef>(name))) {
321 [answers setObject:(id)answer forKey:name];
322 CFRelease(answer);
323 }
324 capability = answers;
325 }
326 }
327
328 if (capability != nil) {
329 printf("%s\n", capability == nil ? "(null)" : [[capability description] UTF8String]);
330 break;
331 }
332
333 CFRunLoopRun();
334 }
335
336 [pool release];
337
338 return 0;
339 }