diff options
Diffstat (limited to 'tools/ideviceinfo.c')
-rw-r--r-- | tools/ideviceinfo.c | 363 |
1 files changed, 139 insertions, 224 deletions
diff --git a/tools/ideviceinfo.c b/tools/ideviceinfo.c index e05165b..fd45763 100644 --- a/tools/ideviceinfo.c +++ b/tools/ideviceinfo.c | |||
@@ -2,40 +2,59 @@ | |||
2 | * ideviceinfo.c | 2 | * ideviceinfo.c |
3 | * Simple utility to show information about an attached device | 3 | * Simple utility to show information about an attached device |
4 | * | 4 | * |
5 | * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved. | ||
5 | * Copyright (c) 2009 Martin Szulecki All Rights Reserved. | 6 | * Copyright (c) 2009 Martin Szulecki All Rights Reserved. |
6 | * | 7 | * |
7 | * This library is free software; you can redistribute it and/or | 8 | * This library is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Lesser General Public | 9 | * modify it under the terms of the GNU Lesser General Public |
9 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
10 | * version 2.1 of the License, or (at your option) any later version. | 11 | * version 2.1 of the License, or (at your option) any later version. |
11 | * | 12 | * |
12 | * This library is distributed in the hope that it will be useful, | 13 | * This library is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Lesser General Public License for more details. | 16 | * Lesser General Public License for more details. |
16 | * | 17 | * |
17 | * You should have received a copy of the GNU Lesser General Public | 18 | * You should have received a copy of the GNU Lesser General Public |
18 | * License along with this library; if not, write to the Free Software | 19 | * License along with this library; if not, write to the Free Software |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | */ | 21 | */ |
21 | 22 | ||
23 | #ifdef HAVE_CONFIG_H | ||
24 | #include <config.h> | ||
25 | #endif | ||
26 | |||
27 | #define TOOL_NAME "ideviceinfo" | ||
28 | |||
22 | #include <stdio.h> | 29 | #include <stdio.h> |
23 | #include <string.h> | 30 | #include <string.h> |
24 | #include <errno.h> | 31 | #include <errno.h> |
25 | #include <stdlib.h> | 32 | #include <stdlib.h> |
26 | #include <glib.h> | 33 | #include <getopt.h> |
34 | #ifndef WIN32 | ||
35 | #include <signal.h> | ||
36 | #endif | ||
27 | 37 | ||
28 | #include <libimobiledevice/libimobiledevice.h> | 38 | #include <libimobiledevice/libimobiledevice.h> |
29 | #include <libimobiledevice/lockdown.h> | 39 | #include <libimobiledevice/lockdown.h> |
40 | #include <plist/plist.h> | ||
30 | 41 | ||
31 | #define FORMAT_KEY_VALUE 1 | 42 | #define FORMAT_KEY_VALUE 1 |
32 | #define FORMAT_XML 2 | 43 | #define FORMAT_XML 2 |
33 | 44 | ||
34 | static const char *domains[] = { | 45 | static const char *domains[] = { |
35 | "com.apple.disk_usage", | 46 | "com.apple.disk_usage", |
47 | "com.apple.disk_usage.factory", | ||
36 | "com.apple.mobile.battery", | 48 | "com.apple.mobile.battery", |
37 | /* FIXME: For some reason lockdownd segfaults on this, works sometimes though | 49 | /* FIXME: For some reason lockdownd segfaults on this, works sometimes though |
38 | "com.apple.mobile.debug",. */ | 50 | "com.apple.mobile.debug",. */ |
51 | "com.apple.iqagent", | ||
52 | "com.apple.purplebuddy", | ||
53 | "com.apple.PurpleBuddy", | ||
54 | "com.apple.mobile.chaperone", | ||
55 | "com.apple.mobile.third_party_termination", | ||
56 | "com.apple.mobile.lockdownd", | ||
57 | "com.apple.mobile.lockdown_cache", | ||
39 | "com.apple.xcode.developerdomain", | 58 | "com.apple.xcode.developerdomain", |
40 | "com.apple.international", | 59 | "com.apple.international", |
41 | "com.apple.mobile.data_sync", | 60 | "com.apple.mobile.data_sync", |
@@ -55,12 +74,12 @@ static const char *domains[] = { | |||
55 | "com.apple.iTunes", | 74 | "com.apple.iTunes", |
56 | "com.apple.mobile.iTunes.store", | 75 | "com.apple.mobile.iTunes.store", |
57 | "com.apple.mobile.iTunes", | 76 | "com.apple.mobile.iTunes", |
77 | "com.apple.fmip", | ||
78 | "com.apple.Accessibility", | ||
58 | NULL | 79 | NULL |
59 | }; | 80 | }; |
60 | 81 | ||
61 | static int indent_level = 0; | 82 | static int is_domain_known(const char *domain) |
62 | |||
63 | static int is_domain_known(char *domain) | ||
64 | { | 83 | { |
65 | int i = 0; | 84 | int i = 0; |
66 | while (domains[i] != NULL) { | 85 | while (domains[i] != NULL) { |
@@ -71,244 +90,147 @@ static int is_domain_known(char *domain) | |||
71 | return 0; | 90 | return 0; |
72 | } | 91 | } |
73 | 92 | ||
74 | static void plist_node_to_string(plist_t node); | 93 | static void print_usage(int argc, char **argv, int is_error) |
75 | |||
76 | static void plist_array_to_string(plist_t node) | ||
77 | { | ||
78 | /* iterate over items */ | ||
79 | int i, count; | ||
80 | plist_t subnode = NULL; | ||
81 | |||
82 | count = plist_array_get_size(node); | ||
83 | |||
84 | for (i = 0; i < count; i++) { | ||
85 | subnode = plist_array_get_item(node, i); | ||
86 | printf("%*s", indent_level, ""); | ||
87 | printf("%d: ", i); | ||
88 | plist_node_to_string(subnode); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | static void plist_dict_to_string(plist_t node) | ||
93 | { | ||
94 | /* iterate over key/value pairs */ | ||
95 | plist_dict_iter it = NULL; | ||
96 | |||
97 | char* key = NULL; | ||
98 | plist_t subnode = NULL; | ||
99 | plist_dict_new_iter(node, &it); | ||
100 | plist_dict_next_item(node, it, &key, &subnode); | ||
101 | while (subnode) | ||
102 | { | ||
103 | printf("%*s", indent_level, ""); | ||
104 | printf("%s", key); | ||
105 | if (plist_get_node_type(subnode) == PLIST_ARRAY) | ||
106 | printf("[%d]: ", plist_array_get_size(subnode)); | ||
107 | else | ||
108 | printf(": "); | ||
109 | free(key); | ||
110 | key = NULL; | ||
111 | plist_node_to_string(subnode); | ||
112 | plist_dict_next_item(node, it, &key, &subnode); | ||
113 | } | ||
114 | free(it); | ||
115 | } | ||
116 | |||
117 | static void plist_node_to_string(plist_t node) | ||
118 | { | ||
119 | char *s = NULL; | ||
120 | char *data = NULL; | ||
121 | double d; | ||
122 | uint8_t b; | ||
123 | uint64_t u = 0; | ||
124 | GTimeVal tv = { 0, 0 }; | ||
125 | |||
126 | plist_type t; | ||
127 | |||
128 | if (!node) | ||
129 | return; | ||
130 | |||
131 | t = plist_get_node_type(node); | ||
132 | |||
133 | switch (t) { | ||
134 | case PLIST_BOOLEAN: | ||
135 | plist_get_bool_val(node, &b); | ||
136 | printf("%s\n", (b ? "true" : "false")); | ||
137 | break; | ||
138 | |||
139 | case PLIST_UINT: | ||
140 | plist_get_uint_val(node, &u); | ||
141 | printf("%llu\n", (long long)u); | ||
142 | break; | ||
143 | |||
144 | case PLIST_REAL: | ||
145 | plist_get_real_val(node, &d); | ||
146 | printf("%f\n", d); | ||
147 | break; | ||
148 | |||
149 | case PLIST_STRING: | ||
150 | plist_get_string_val(node, &s); | ||
151 | printf("%s\n", s); | ||
152 | free(s); | ||
153 | break; | ||
154 | |||
155 | case PLIST_KEY: | ||
156 | plist_get_key_val(node, &s); | ||
157 | printf("%s: ", s); | ||
158 | free(s); | ||
159 | break; | ||
160 | |||
161 | case PLIST_DATA: | ||
162 | plist_get_data_val(node, &data, &u); | ||
163 | s = g_base64_encode((guchar *)data, u); | ||
164 | free(data); | ||
165 | printf("%s\n", s); | ||
166 | g_free(s); | ||
167 | break; | ||
168 | |||
169 | case PLIST_DATE: | ||
170 | plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec); | ||
171 | s = g_time_val_to_iso8601(&tv); | ||
172 | printf("%s\n", s); | ||
173 | free(s); | ||
174 | break; | ||
175 | |||
176 | case PLIST_ARRAY: | ||
177 | printf("\n"); | ||
178 | indent_level++; | ||
179 | plist_array_to_string(node); | ||
180 | indent_level--; | ||
181 | break; | ||
182 | |||
183 | case PLIST_DICT: | ||
184 | printf("\n"); | ||
185 | indent_level++; | ||
186 | plist_dict_to_string(node); | ||
187 | indent_level--; | ||
188 | break; | ||
189 | |||
190 | default: | ||
191 | break; | ||
192 | } | ||
193 | } | ||
194 | |||
195 | static void print_usage(int argc, char **argv) | ||
196 | { | 94 | { |
197 | int i = 0; | 95 | int i = 0; |
198 | char *name = NULL; | 96 | char *name = strrchr(argv[0], '/'); |
199 | 97 | fprintf(is_error ? stderr : stdout, "Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); | |
200 | name = strrchr(argv[0], '/'); | 98 | fprintf(is_error ? stderr : stdout, |
201 | printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); | 99 | "\n" |
202 | printf("Show information about a connected iPhone/iPod Touch.\n\n"); | 100 | "Show information about a connected device.\n" |
203 | printf(" -d, --debug\t\tenable communication debugging\n"); | 101 | "\n" |
204 | printf(" -s, --simple\t\tuse a simple connection to avoid auto-pairing with the device\n"); | 102 | "OPTIONS:\n" |
205 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); | 103 | " -u, --udid UDID target specific device by UDID\n" |
206 | printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n"); | 104 | " -n, --network connect to network device\n" |
207 | printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n"); | 105 | " -s, --simple use simple connection to avoid auto-pairing with device\n" |
208 | printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n"); | 106 | " -q, --domain NAME set domain of query to NAME. Default: None\n" \ |
209 | printf(" -h, --help\t\tprints usage information\n"); | 107 | " -k, --key NAME only query key specified by NAME. Default: All keys.\n" \ |
210 | printf("\n"); | 108 | " -x, --xml output information in XML property list format\n" \ |
211 | printf(" Known domains are:\n\n"); | 109 | " -h, --help prints usage information\n" \ |
110 | " -d, --debug enable communication debugging\n" \ | ||
111 | " -v, --version prints version information\n" \ | ||
112 | "\n" | ||
113 | ); | ||
114 | fprintf(is_error ? stderr : stdout, "Known domains are:\n\n"); | ||
212 | while (domains[i] != NULL) { | 115 | while (domains[i] != NULL) { |
213 | printf(" %s\n", domains[i++]); | 116 | fprintf(is_error ? stderr : stdout, " %s\n", domains[i++]); |
214 | } | 117 | } |
215 | printf("\n"); | 118 | fprintf(is_error ? stderr : stdout, |
119 | "\n" \ | ||
120 | "Homepage: <" PACKAGE_URL ">\n" | ||
121 | "Bug Reports: <" PACKAGE_BUGREPORT ">\n" | ||
122 | ); | ||
216 | } | 123 | } |
217 | 124 | ||
218 | int main(int argc, char *argv[]) | 125 | int main(int argc, char *argv[]) |
219 | { | 126 | { |
220 | lockdownd_client_t client = NULL; | 127 | lockdownd_client_t client = NULL; |
221 | idevice_t phone = NULL; | 128 | lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR; |
129 | idevice_t device = NULL; | ||
222 | idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; | 130 | idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; |
223 | int i; | ||
224 | int simple = 0; | 131 | int simple = 0; |
225 | int format = FORMAT_KEY_VALUE; | 132 | int format = FORMAT_KEY_VALUE; |
226 | char uuid[41]; | 133 | const char* udid = NULL; |
227 | char *domain = NULL; | 134 | int use_network = 0; |
228 | char *key = NULL; | 135 | const char *domain = NULL; |
136 | const char *key = NULL; | ||
229 | char *xml_doc = NULL; | 137 | char *xml_doc = NULL; |
230 | uint32_t xml_length; | 138 | uint32_t xml_length; |
231 | plist_t node = NULL; | 139 | plist_t node = NULL; |
232 | plist_type node_type; | ||
233 | uuid[0] = 0; | ||
234 | 140 | ||
235 | /* parse cmdline args */ | 141 | int c = 0; |
236 | for (i = 1; i < argc; i++) { | 142 | const struct option longopts[] = { |
237 | if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { | 143 | { "debug", no_argument, NULL, 'd' }, |
144 | { "help", no_argument, NULL, 'h' }, | ||
145 | { "udid", required_argument, NULL, 'u' }, | ||
146 | { "network", no_argument, NULL, 'n' }, | ||
147 | { "domain", required_argument, NULL, 'q' }, | ||
148 | { "key", required_argument, NULL, 'k' }, | ||
149 | { "simple", no_argument, NULL, 's' }, | ||
150 | { "xml", no_argument, NULL, 'x' }, | ||
151 | { "version", no_argument, NULL, 'v' }, | ||
152 | { NULL, 0, NULL, 0} | ||
153 | }; | ||
154 | |||
155 | #ifndef WIN32 | ||
156 | signal(SIGPIPE, SIG_IGN); | ||
157 | #endif | ||
158 | |||
159 | while ((c = getopt_long(argc, argv, "dhu:nq:k:sxv", longopts, NULL)) != -1) { | ||
160 | switch (c) { | ||
161 | case 'd': | ||
238 | idevice_set_debug_level(1); | 162 | idevice_set_debug_level(1); |
239 | continue; | 163 | break; |
240 | } | 164 | case 'u': |
241 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { | 165 | if (!*optarg) { |
242 | i++; | 166 | fprintf(stderr, "ERROR: UDID must not be empty!\n"); |
243 | if (!argv[i] || (strlen(argv[i]) != 40)) { | 167 | print_usage(argc, argv, 1); |
244 | print_usage(argc, argv); | 168 | return 2; |
245 | return 0; | ||
246 | } | ||
247 | strcpy(uuid, argv[i]); | ||
248 | continue; | ||
249 | } | ||
250 | else if (!strcmp(argv[i], "-q") || !strcmp(argv[i], "--domain")) { | ||
251 | i++; | ||
252 | if (!argv[i] || (strlen(argv[i]) < 4)) { | ||
253 | print_usage(argc, argv); | ||
254 | return 0; | ||
255 | } | 169 | } |
256 | if (!is_domain_known(argv[i])) { | 170 | udid = optarg; |
257 | fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", argv[i]); | 171 | break; |
172 | case 'n': | ||
173 | use_network = 1; | ||
174 | break; | ||
175 | case 'q': | ||
176 | if (!*optarg) { | ||
177 | fprintf(stderr, "ERROR: 'domain' must not be empty!\n"); | ||
178 | print_usage(argc, argv, 1); | ||
179 | return 2; | ||
258 | } | 180 | } |
259 | domain = strdup(argv[i]); | 181 | domain = optarg; |
260 | continue; | 182 | break; |
261 | } | 183 | case 'k': |
262 | else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--key")) { | 184 | if (!*optarg) { |
263 | i++; | 185 | fprintf(stderr, "ERROR: 'key' must not be empty!\n"); |
264 | if (!argv[i] || (strlen(argv[i]) <= 1)) { | 186 | print_usage(argc, argv, 1); |
265 | print_usage(argc, argv); | 187 | return 2; |
266 | return 0; | ||
267 | } | 188 | } |
268 | key = strdup(argv[i]); | 189 | key = optarg; |
269 | continue; | 190 | break; |
270 | } | 191 | case 'x': |
271 | else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) { | ||
272 | format = FORMAT_XML; | 192 | format = FORMAT_XML; |
273 | continue; | 193 | break; |
274 | } | 194 | case 's': |
275 | else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--simple")) { | ||
276 | simple = 1; | 195 | simple = 1; |
277 | continue; | 196 | break; |
278 | } | 197 | case 'h': |
279 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | 198 | print_usage(argc, argv, 0); |
280 | print_usage(argc, argv); | ||
281 | return 0; | 199 | return 0; |
282 | } | 200 | case 'v': |
283 | else { | 201 | printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION); |
284 | print_usage(argc, argv); | ||
285 | return 0; | 202 | return 0; |
203 | default: | ||
204 | print_usage(argc, argv, 1); | ||
205 | return 2; | ||
286 | } | 206 | } |
287 | } | 207 | } |
288 | 208 | ||
289 | if (uuid[0] != 0) { | 209 | argc -= optind; |
290 | ret = idevice_new(&phone, uuid); | 210 | argv += optind; |
291 | if (ret != IDEVICE_E_SUCCESS) { | 211 | |
292 | printf("No device found with uuid %s, is it plugged in?\n", uuid); | 212 | ret = idevice_new_with_options(&device, udid, (use_network) ? IDEVICE_LOOKUP_NETWORK : IDEVICE_LOOKUP_USBMUX); |
293 | return -1; | 213 | if (ret != IDEVICE_E_SUCCESS) { |
294 | } | 214 | if (udid) { |
295 | } | 215 | fprintf(stderr, "ERROR: Device %s not found!\n", udid); |
296 | else | 216 | } else { |
297 | { | 217 | fprintf(stderr, "ERROR: No device found!\n"); |
298 | ret = idevice_new(&phone, NULL); | ||
299 | if (ret != IDEVICE_E_SUCCESS) { | ||
300 | printf("No device found, is it plugged in?\n"); | ||
301 | return -1; | ||
302 | } | 218 | } |
219 | return -1; | ||
303 | } | 220 | } |
304 | 221 | ||
305 | if (LOCKDOWN_E_SUCCESS != (simple ? | 222 | if (LOCKDOWN_E_SUCCESS != (ldret = simple ? |
306 | lockdownd_client_new(phone, &client, "ideviceinfo"): | 223 | lockdownd_client_new(device, &client, TOOL_NAME): |
307 | lockdownd_client_new_with_handshake(phone, &client, "ideviceinfo"))) { | 224 | lockdownd_client_new_with_handshake(device, &client, TOOL_NAME))) { |
308 | idevice_free(phone); | 225 | fprintf(stderr, "ERROR: Could not connect to lockdownd: %s (%d)\n", lockdownd_strerror(ldret), ldret); |
226 | idevice_free(device); | ||
309 | return -1; | 227 | return -1; |
310 | } | 228 | } |
311 | 229 | ||
230 | if (domain && !is_domain_known(domain)) { | ||
231 | fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", domain); | ||
232 | } | ||
233 | |||
312 | /* run query and output information */ | 234 | /* run query and output information */ |
313 | if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) { | 235 | if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) { |
314 | if (node) { | 236 | if (node) { |
@@ -319,16 +241,11 @@ int main(int argc, char *argv[]) | |||
319 | free(xml_doc); | 241 | free(xml_doc); |
320 | break; | 242 | break; |
321 | case FORMAT_KEY_VALUE: | 243 | case FORMAT_KEY_VALUE: |
322 | node_type = plist_get_node_type(node); | 244 | plist_write_to_stream(node, stdout, PLIST_FORMAT_LIMD, 0); |
323 | if (node_type == PLIST_DICT) { | 245 | break; |
324 | plist_dict_to_string(node); | ||
325 | } else if (node_type == PLIST_ARRAY) { | ||
326 | plist_array_to_string(node); | ||
327 | break; | ||
328 | } | ||
329 | default: | 246 | default: |
330 | if (key != NULL) | 247 | if (key != NULL) |
331 | plist_node_to_string(node); | 248 | plist_write_to_stream(node, stdout, PLIST_FORMAT_LIMD, 0); |
332 | break; | 249 | break; |
333 | } | 250 | } |
334 | plist_free(node); | 251 | plist_free(node); |
@@ -336,10 +253,8 @@ int main(int argc, char *argv[]) | |||
336 | } | 253 | } |
337 | } | 254 | } |
338 | 255 | ||
339 | if (domain != NULL) | ||
340 | free(domain); | ||
341 | lockdownd_client_free(client); | 256 | lockdownd_client_free(client); |
342 | idevice_free(phone); | 257 | idevice_free(device); |
343 | 258 | ||
344 | return 0; | 259 | return 0; |
345 | } | 260 | } |