diff options
Diffstat (limited to 'dev/iphoneinfo.c')
| -rw-r--r-- | dev/iphoneinfo.c | 105 |
1 files changed, 32 insertions, 73 deletions
diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 9d690f9..7e275b2 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c | |||
| @@ -51,7 +51,6 @@ static const char *domains[] = { | |||
| 51 | 51 | ||
| 52 | int is_domain_known(char *domain); | 52 | int is_domain_known(char *domain); |
| 53 | void print_usage(int argc, char **argv); | 53 | void print_usage(int argc, char **argv); |
| 54 | void print_lckd_request_result(lockdownd_client_t client, const char *domain, const char *request, const char *key, int format); | ||
| 55 | void plist_node_to_string(plist_t *node); | 54 | void plist_node_to_string(plist_t *node); |
| 56 | void plist_children_to_string(plist_t *node); | 55 | void plist_children_to_string(plist_t *node); |
| 57 | 56 | ||
| @@ -65,13 +64,16 @@ int main(int argc, char *argv[]) | |||
| 65 | char uuid[41]; | 64 | char uuid[41]; |
| 66 | char *domain = NULL; | 65 | char *domain = NULL; |
| 67 | char *key = NULL; | 66 | char *key = NULL; |
| 67 | char *xml_doc = NULL; | ||
| 68 | uint32_t xml_length; | ||
| 69 | plist_t node = NULL; | ||
| 68 | uuid[0] = 0; | 70 | uuid[0] = 0; |
| 69 | 71 | ||
| 70 | /* parse cmdline args */ | 72 | /* parse cmdline args */ |
| 71 | for (i = 1; i < argc; i++) { | 73 | for (i = 1; i < argc; i++) { |
| 72 | if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { | 74 | if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { |
| 73 | iphone_set_debug_mask(DBGMASK_ALL); | 75 | iphone_set_debug_mask(DBGMASK_ALL); |
| 74 | iphone_set_debug(1); | 76 | iphone_set_debug_level(1); |
| 75 | continue; | 77 | continue; |
| 76 | } | 78 | } |
| 77 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { | 79 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { |
| @@ -134,18 +136,41 @@ int main(int argc, char *argv[]) | |||
| 134 | } | 136 | } |
| 135 | } | 137 | } |
| 136 | 138 | ||
| 137 | if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { | 139 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { |
| 138 | iphone_free_device(phone); | 140 | iphone_device_free(phone); |
| 139 | return -1; | 141 | return -1; |
| 140 | } | 142 | } |
| 141 | 143 | ||
| 142 | /* run query and output information */ | 144 | /* run query and output information */ |
| 143 | print_lckd_request_result(client, domain, "GetValue", key, format); | 145 | if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) |
| 146 | { | ||
| 147 | if (plist_get_node_type(node) == PLIST_DICT) { | ||
| 148 | if (plist_get_first_child(node)) | ||
| 149 | { | ||
| 150 | switch (format) { | ||
| 151 | case FORMAT_XML: | ||
| 152 | plist_to_xml(node, &xml_doc, &xml_length); | ||
| 153 | printf(xml_doc); | ||
| 154 | free(xml_doc); | ||
| 155 | break; | ||
| 156 | case FORMAT_KEY_VALUE: | ||
| 157 | default: | ||
| 158 | plist_children_to_string(node); | ||
| 159 | break; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | } | ||
| 163 | else if(node && (key != NULL)) | ||
| 164 | plist_node_to_string(node); | ||
| 165 | if (node) | ||
| 166 | plist_free(node); | ||
| 167 | node = NULL; | ||
| 168 | } | ||
| 144 | 169 | ||
| 145 | if (domain != NULL) | 170 | if (domain != NULL) |
| 146 | free(domain); | 171 | free(domain); |
| 147 | lockdownd_free_client(client); | 172 | lockdownd_client_free(client); |
| 148 | iphone_free_device(phone); | 173 | iphone_device_free(phone); |
| 149 | 174 | ||
| 150 | return 0; | 175 | return 0; |
| 151 | } | 176 | } |
| @@ -254,69 +279,3 @@ void plist_children_to_string(plist_t *node) | |||
| 254 | } | 279 | } |
| 255 | } | 280 | } |
| 256 | 281 | ||
| 257 | void print_lckd_request_result(lockdownd_client_t client, const char *domain, const char *request, const char *key, int format) { | ||
| 258 | char *xml_doc = NULL; | ||
| 259 | char *s = NULL; | ||
| 260 | uint32_t xml_length = 0; | ||
| 261 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | ||
| 262 | |||
| 263 | plist_t node = plist_new_dict(); | ||
| 264 | if (domain) { | ||
| 265 | plist_add_sub_key_el(node, "Domain"); | ||
| 266 | plist_add_sub_string_el(node, domain); | ||
| 267 | } | ||
| 268 | if (key) { | ||
| 269 | plist_add_sub_key_el(node, "Key"); | ||
| 270 | plist_add_sub_string_el(node, key); | ||
| 271 | } | ||
| 272 | plist_add_sub_key_el(node, "Request"); | ||
| 273 | plist_add_sub_string_el(node, request); | ||
| 274 | |||
| 275 | ret = lockdownd_send(client, node); | ||
| 276 | if (ret == IPHONE_E_SUCCESS) { | ||
| 277 | plist_free(node); | ||
| 278 | node = NULL; | ||
| 279 | ret = lockdownd_recv(client, &node); | ||
| 280 | if (ret == IPHONE_E_SUCCESS) { | ||
| 281 | /* seek to value node */ | ||
| 282 | for ( | ||
| 283 | node = plist_get_first_child(node); | ||
| 284 | node != NULL; | ||
| 285 | node = plist_get_next_sibling(node) | ||
| 286 | ) { | ||
| 287 | if(plist_get_node_type(node) == PLIST_KEY) | ||
| 288 | { | ||
| 289 | plist_get_key_val(node, &s); | ||
| 290 | |||
| 291 | if (strcmp("Value", s)) | ||
| 292 | continue; | ||
| 293 | |||
| 294 | node = plist_get_next_sibling(node); | ||
| 295 | |||
| 296 | if (plist_get_node_type(node) == PLIST_DICT) { | ||
| 297 | if (plist_get_first_child(node)) | ||
| 298 | { | ||
| 299 | switch (format) { | ||
| 300 | case FORMAT_XML: | ||
| 301 | plist_to_xml(node, &xml_doc, &xml_length); | ||
| 302 | printf(xml_doc); | ||
| 303 | free(xml_doc); | ||
| 304 | break; | ||
| 305 | case FORMAT_KEY_VALUE: | ||
| 306 | default: | ||
| 307 | plist_children_to_string(node); | ||
| 308 | break; | ||
| 309 | } | ||
| 310 | } | ||
| 311 | } | ||
| 312 | else if(node && (key != NULL)) | ||
| 313 | plist_node_to_string(node); | ||
| 314 | } | ||
| 315 | } | ||
| 316 | } | ||
| 317 | } | ||
| 318 | if (node) | ||
| 319 | plist_free(node); | ||
| 320 | node = NULL; | ||
| 321 | } | ||
| 322 | |||
