static void plist_node_to_string(plist_t node) { char *s = NULL; char *data = NULL; double d; uint8_t b; uint64_t u = 0; GTimeVal tv = { 0, 0 }; plist_type t; if (!node) return; t = plist_get_node_type(node); switch (t) { case PLIST_BOOLEAN: plist_get_bool_val(node, &b); printf("%s\n", (b ? "true" : "false")); break; case PLIST_UINT: plist_get_uint_val(node, &u); printf("%llu\n", (long long)u); break; case PLIST_REAL: plist_get_real_val(node, &d); printf("%f\n", d); break; case PLIST_STRING: plist_get_string_val(node, &s); printf("%s\n", s); free(s); break; case PLIST_KEY: plist_get_key_val(node, &s); printf("%s: ", s); free(s); break; case PLIST_DATA: plist_get_data_val(node, &data, &u); s = g_base64_encode((guchar *)data, u); free(data); printf("%s\n", s); g_free(s); break; case PLIST_DATE: plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec); s = g_time_val_to_iso8601(&tv); printf("%s\n", s); free(s); break; case PLIST_ARRAY: printf("\n"); indent_level++; plist_array_to_string(node); indent_level--; break; case PLIST_DICT: printf("\n"); indent_level++; plist_dict_to_string(node); indent_level--; break; default: break; } }
int main(int argc, char *argv[]) { lockdownd_client_t client = NULL; idevice_t phone = NULL; idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; int i; int simple = 0; int format = FORMAT_KEY_VALUE; char uuid[41]; char *domain = NULL; char *key = NULL; char *xml_doc = NULL; uint32_t xml_length; plist_t node = NULL; plist_type node_type; uuid[0] = 0; /* parse cmdline args */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { idevice_set_debug_level(1); continue; } else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { i++; if (!argv[i] || (strlen(argv[i]) != 40)) { print_usage(argc, argv); return 0; } strcpy(uuid, argv[i]); continue; } else if (!strcmp(argv[i], "-q") || !strcmp(argv[i], "--domain")) { i++; if (!argv[i] || (strlen(argv[i]) < 4)) { print_usage(argc, argv); return 0; } if (!is_domain_known(argv[i])) { fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", argv[i]); } domain = strdup(argv[i]); continue; } else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--key")) { i++; if (!argv[i] || (strlen(argv[i]) <= 1)) { print_usage(argc, argv); return 0; } key = strdup(argv[i]); continue; } else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) { format = FORMAT_XML; continue; } else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--simple")) { simple = 1; continue; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { print_usage(argc, argv); return 0; } else { print_usage(argc, argv); return 0; } } if (uuid[0] != 0) { ret = idevice_new(&phone, uuid); if (ret != IDEVICE_E_SUCCESS) { printf("No device found with uuid %s, is it plugged in?\n", uuid); return -1; } } else { ret = idevice_new(&phone, NULL); if (ret != IDEVICE_E_SUCCESS) { printf("No device found, is it plugged in?\n"); return -1; } } if (LOCKDOWN_E_SUCCESS != (simple ? lockdownd_client_new(phone, &client, "ideviceinfo"): lockdownd_client_new_with_handshake(phone, &client, "ideviceinfo"))) { idevice_free(phone); return -1; } /* run query and output information */ if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) { if (node) { switch (format) { case FORMAT_XML: plist_to_xml(node, &xml_doc, &xml_length); printf("%s", xml_doc); free(xml_doc); break; case FORMAT_KEY_VALUE: node_type = plist_get_node_type(node); if (node_type == PLIST_DICT) { plist_dict_to_string(node); } else if (node_type == PLIST_ARRAY) { plist_array_to_string(node); break; } default: if (key != NULL) plist_node_to_string(node); break; } plist_free(node); node = NULL; } } if (domain != NULL) free(domain); lockdownd_client_free(client); idevice_free(phone); return 0; }
static void plist_node_to_string(plist_t node) { char *s = NULL; char *data = NULL; double d; uint8_t b; uint64_t u = 0; struct timeval tv = { 0, 0 }; plist_type t; if (!node) return; t = plist_get_node_type(node); switch (t) { case PLIST_BOOLEAN: plist_get_bool_val(node, &b); printf("%s\n", (b ? "true" : "false")); break; case PLIST_UINT: plist_get_uint_val(node, &u); printf("%llu\n", (long long)u); break; case PLIST_REAL: plist_get_real_val(node, &d); printf("%f\n", d); break; case PLIST_STRING: plist_get_string_val(node, &s); printf("%s\n", s); free(s); break; case PLIST_KEY: plist_get_key_val(node, &s); printf("%s: ", s); free(s); break; case PLIST_DATA: plist_get_data_val(node, &data, &u); uint64_t i; for (i = 0; i < u; i++) { printf("%02x", (unsigned char)data[i]); } free(data); printf("\n"); break; case PLIST_DATE: plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec); { time_t ti = (time_t)tv.tv_sec; struct tm *btime = localtime(&ti); if (btime) { s = (char*)malloc(24); memset(s, 0, 24); if (strftime(s, 24, "%Y-%m-%dT%H:%M:%SZ", btime) <= 0) { free (s); s = NULL; } } } if (s) { puts(s); free(s); } puts("\n"); break; case PLIST_ARRAY: printf("\n"); indent_level++; plist_array_to_string(node); indent_level--; break; case PLIST_DICT: printf("\n"); indent_level++; plist_dict_to_string(node); indent_level--; break; default: break; } }