diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/iphoneinfo.c | 126 |
1 files changed, 105 insertions, 21 deletions
diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index cee8dff..641b47d 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c | |||
| @@ -26,8 +26,26 @@ | |||
| 26 | 26 | ||
| 27 | #include <libiphone/libiphone.h> | 27 | #include <libiphone/libiphone.h> |
| 28 | 28 | ||
| 29 | #define FORMAT_KEY_VALUE 1 | ||
| 30 | #define FORMAT_XML 2 | ||
| 31 | |||
| 32 | static const char *domains[] = { | ||
| 33 | "com.apple.disk_usage", | ||
| 34 | "com.apple.mobile.battery", | ||
| 35 | /* FIXME: For some reason lockdownd segfaults on this, works sometimes though | ||
| 36 | "com.apple.mobile.debug",. */ | ||
| 37 | "com.apple.xcode.developerdomain", | ||
| 38 | "com.apple.international", | ||
| 39 | "com.apple.mobile.sync_data_class", | ||
| 40 | "com.apple.iTunes", | ||
| 41 | "com.apple.mobile.iTunes.store", | ||
| 42 | "com.apple.mobile.iTunes", | ||
| 43 | NULL | ||
| 44 | }; | ||
| 45 | |||
| 46 | int is_domain_known(char *domain); | ||
| 29 | void print_usage(int argc, char **argv); | 47 | void print_usage(int argc, char **argv); |
| 30 | void print_lckd_request_info(iphone_lckd_client_t control, const char *domain, const char *request, const char *key); | 48 | void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, const char *request, const char *key, int format); |
| 31 | void plist_node_to_string(plist_t *node); | 49 | void plist_node_to_string(plist_t *node); |
| 32 | void plist_children_to_string(plist_t *node); | 50 | void plist_children_to_string(plist_t *node); |
| 33 | 51 | ||
| @@ -37,7 +55,10 @@ int main(int argc, char *argv[]) | |||
| 37 | iphone_device_t phone = NULL; | 55 | iphone_device_t phone = NULL; |
| 38 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 56 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 39 | int i; | 57 | int i; |
| 58 | int format = FORMAT_KEY_VALUE; | ||
| 40 | char uuid[41]; | 59 | char uuid[41]; |
| 60 | char *domain = NULL; | ||
| 61 | char *key = NULL; | ||
| 41 | uuid[0] = 0; | 62 | uuid[0] = 0; |
| 42 | 63 | ||
| 43 | /* parse cmdline args */ | 64 | /* parse cmdline args */ |
| @@ -56,6 +77,31 @@ int main(int argc, char *argv[]) | |||
| 56 | strcpy(uuid, argv[i]); | 77 | strcpy(uuid, argv[i]); |
| 57 | continue; | 78 | continue; |
| 58 | } | 79 | } |
| 80 | else if (!strcmp(argv[i], "-q") || !strcmp(argv[i], "--domain")) { | ||
| 81 | i++; | ||
| 82 | if (!argv[i] || (strlen(argv[i]) < 4)) { | ||
| 83 | print_usage(argc, argv); | ||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | if (!is_domain_known(argv[i])) { | ||
| 87 | fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", argv[i]); | ||
| 88 | } | ||
| 89 | domain = strdup(argv[i]); | ||
| 90 | continue; | ||
| 91 | } | ||
| 92 | else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--key")) { | ||
| 93 | i++; | ||
| 94 | if (!argv[i] || (strlen(argv[i]) <= 1)) { | ||
| 95 | print_usage(argc, argv); | ||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | key = strdup(argv[i]); | ||
| 99 | continue; | ||
| 100 | } | ||
| 101 | else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) { | ||
| 102 | format = FORMAT_XML; | ||
| 103 | continue; | ||
| 104 | } | ||
| 59 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | 105 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { |
| 60 | print_usage(argc, argv); | 106 | print_usage(argc, argv); |
| 61 | return 0; | 107 | return 0; |
| @@ -87,35 +133,45 @@ int main(int argc, char *argv[]) | |||
| 87 | return -1; | 133 | return -1; |
| 88 | } | 134 | } |
| 89 | 135 | ||
| 90 | /* dump all information we can retrieve */ | 136 | /* run query and output information */ |
| 91 | printf("# general\n"); | 137 | print_lckd_request_result(control, domain, "GetValue", key, format); |
| 92 | print_lckd_request_info(control, NULL, "GetValue", NULL); | ||
| 93 | print_lckd_request_info(control, "com.apple.disk_usage", "GetValue", NULL); | ||
| 94 | print_lckd_request_info(control, "com.apple.mobile.battery", "GetValue", NULL); | ||
| 95 | /* FIXME: For some reason lockdownd segfaults on this, works sometimes though | ||
| 96 | print_lckd_request_info(control, "com.apple.mobile.debug", "GetValue", NULL); | ||
| 97 | */ | ||
| 98 | print_lckd_request_info(control, "com.apple.xcode.developerdomain", "GetValue", NULL); | ||
| 99 | print_lckd_request_info(control, "com.apple.international", "GetValue", NULL); | ||
| 100 | print_lckd_request_info(control, "com.apple.mobile.sync_data_class", "GetValue", NULL); | ||
| 101 | print_lckd_request_info(control, "com.apple.iTunes", "GetValue", NULL); | ||
| 102 | print_lckd_request_info(control, "com.apple.mobile.iTunes.store", "GetValue", NULL); | ||
| 103 | print_lckd_request_info(control, "com.apple.mobile.iTunes", "GetValue", NULL); | ||
| 104 | 138 | ||
| 139 | if (domain != NULL) | ||
| 140 | free(domain); | ||
| 105 | iphone_lckd_free_client(control); | 141 | iphone_lckd_free_client(control); |
| 106 | iphone_free_device(phone); | 142 | iphone_free_device(phone); |
| 107 | 143 | ||
| 108 | return 0; | 144 | return 0; |
| 109 | } | 145 | } |
| 110 | 146 | ||
| 147 | int is_domain_known(char *domain) | ||
| 148 | { | ||
| 149 | int i = 0; | ||
| 150 | while (domains[i] != NULL) { | ||
| 151 | if (strstr(domain, domains[i++])) { | ||
| 152 | return 1; | ||
| 153 | } | ||
| 154 | } | ||
| 155 | return 0; | ||
| 156 | } | ||
| 157 | |||
| 111 | void print_usage(int argc, char **argv) | 158 | void print_usage(int argc, char **argv) |
| 112 | { | 159 | { |
| 160 | int i = 0; | ||
| 113 | printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); | 161 | printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); |
| 114 | printf("Show information about the first connected iPhone/iPod Touch.\n\n"); | 162 | printf("Show information about the first connected iPhone/iPod Touch.\n\n"); |
| 115 | printf(" -d, --debug\t\tenable communication debugging\n"); | 163 | printf(" -d, --debug\t\tenable communication debugging\n"); |
| 116 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); | 164 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); |
| 165 | printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n"); | ||
| 166 | printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n"); | ||
| 167 | printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n"); | ||
| 117 | printf(" -h, --help\t\tprints usage information\n"); | 168 | printf(" -h, --help\t\tprints usage information\n"); |
| 118 | printf("\n"); | 169 | printf("\n"); |
| 170 | printf(" Known domains are:\n\n"); | ||
| 171 | while (domains[i] != NULL) { | ||
| 172 | printf(" %s\n", domains[i++]); | ||
| 173 | } | ||
| 174 | printf("\n"); | ||
| 119 | } | 175 | } |
| 120 | 176 | ||
| 121 | void plist_node_to_string(plist_t *node) | 177 | void plist_node_to_string(plist_t *node) |
| @@ -189,14 +245,16 @@ void plist_children_to_string(plist_t *node) | |||
| 189 | } | 245 | } |
| 190 | } | 246 | } |
| 191 | 247 | ||
| 192 | void print_lckd_request_info(iphone_lckd_client_t control, const char *domain, const char *request, const char *key) { | 248 | void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, const char *request, const char *key, int format) { |
| 249 | char *xml_doc = NULL; | ||
| 250 | char *s = NULL; | ||
| 251 | uint32_t xml_length = 0; | ||
| 193 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 252 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 194 | 253 | ||
| 195 | plist_t node = plist_new_dict(); | 254 | plist_t node = plist_new_dict(); |
| 196 | if (domain) { | 255 | if (domain) { |
| 197 | plist_add_sub_key_el(node, "Domain"); | 256 | plist_add_sub_key_el(node, "Domain"); |
| 198 | plist_add_sub_string_el(node, domain); | 257 | plist_add_sub_string_el(node, domain); |
| 199 | printf("# %s\n", domain); | ||
| 200 | } | 258 | } |
| 201 | if (key) { | 259 | if (key) { |
| 202 | plist_add_sub_key_el(node, "Key"); | 260 | plist_add_sub_key_el(node, "Key"); |
| @@ -211,15 +269,41 @@ void print_lckd_request_info(iphone_lckd_client_t control, const char *domain, c | |||
| 211 | node = NULL; | 269 | node = NULL; |
| 212 | ret = iphone_lckd_recv(control, &node); | 270 | ret = iphone_lckd_recv(control, &node); |
| 213 | if (ret == IPHONE_E_SUCCESS) { | 271 | if (ret == IPHONE_E_SUCCESS) { |
| 214 | /* seek to first dict node */ | 272 | /* seek to value node */ |
| 215 | for ( | 273 | for ( |
| 216 | node = plist_get_first_child(node); | 274 | node = plist_get_first_child(node); |
| 217 | node && (plist_get_node_type(node) != PLIST_DICT); | 275 | node != NULL; |
| 218 | node = plist_get_next_sibling(node) | 276 | node = plist_get_next_sibling(node) |
| 219 | ) { | 277 | ) { |
| 278 | if(plist_get_node_type(node) == PLIST_KEY) | ||
| 279 | { | ||
| 280 | plist_get_key_val(node, &s); | ||
| 281 | |||
| 282 | if (strcmp("Value", s)) | ||
| 283 | continue; | ||
| 284 | |||
| 285 | node = plist_get_next_sibling(node); | ||
| 286 | |||
| 287 | if (plist_get_node_type(node) == PLIST_DICT) { | ||
| 288 | if (plist_get_first_child(node)) | ||
| 289 | { | ||
| 290 | switch (format) { | ||
| 291 | case FORMAT_XML: | ||
| 292 | plist_to_xml(node, &xml_doc, &xml_length); | ||
| 293 | printf(xml_doc); | ||
| 294 | free(xml_doc); | ||
| 295 | break; | ||
| 296 | case FORMAT_KEY_VALUE: | ||
| 297 | default: | ||
| 298 | plist_children_to_string(node); | ||
| 299 | break; | ||
| 300 | } | ||
| 301 | } | ||
| 302 | } | ||
| 303 | else if(node && (key != NULL)) | ||
| 304 | plist_node_to_string(node); | ||
| 305 | } | ||
| 220 | } | 306 | } |
| 221 | if(plist_get_first_child(node)) | ||
| 222 | plist_children_to_string(node); | ||
| 223 | } | 307 | } |
| 224 | } | 308 | } |
| 225 | if (node) | 309 | if (node) |
