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