diff options
Diffstat (limited to 'tools/iphoneinfo.c')
-rw-r--r-- | tools/iphoneinfo.c | 312 |
1 files changed, 177 insertions, 135 deletions
diff --git a/tools/iphoneinfo.c b/tools/iphoneinfo.c index 7c41033..5ee92f5 100644 --- a/tools/iphoneinfo.c +++ b/tools/iphoneinfo.c @@ -23,6 +23,7 @@ #include <string.h> #include <errno.h> #include <stdlib.h> +#include <glib.h> #include <libiphone/libiphone.h> #include <libiphone/lockdown.h> @@ -55,10 +56,161 @@ static const char *domains[] = { NULL }; -int is_domain_known(char *domain); -void print_usage(int argc, char **argv); -void plist_node_to_string(plist_t node); -void plist_children_to_string(plist_t node); +static int indent_level = 0; + +static int is_domain_known(char *domain) +{ + int i = 0; + while (domains[i] != NULL) { + if (strstr(domain, domains[i++])) { + return 1; + } + } + return 0; +} + +static void plist_node_to_string(plist_t node); + +static void plist_array_to_string(plist_t node) +{ + /* iterate over items */ + int i, count; + plist_t subnode = NULL; + + count = plist_array_get_size(node); + + for (i = 0; i < count; i++) { + subnode = plist_array_get_item(node, i); + printf("%*s", indent_level, ""); + printf("%d: ", i); + plist_node_to_string(subnode); + } +} + +static void plist_dict_to_string(plist_t node) +{ + /* iterate over key/value pairs */ + plist_dict_iter it = NULL; + + char* key = NULL; + plist_t subnode = NULL; + plist_dict_new_iter(node, &it); + plist_dict_next_item(node, it, &key, &subnode); + while (subnode) + { + printf("%*s", indent_level, ""); + printf("%s", key); + if (plist_get_node_type(subnode) == PLIST_ARRAY) + printf("[%d]: ", plist_array_get_size(subnode)); + else + printf(": "); + free(key); + key = NULL; + plist_node_to_string(subnode); + plist_dict_next_item(node, it, &key, &subnode); + } + free(it); +} + +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; + } +} + +static void print_usage(int argc, char **argv) +{ + int i = 0; + char *name = NULL; + + name = strrchr(argv[0], '/'); + printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); + printf("Show information about the first connected iPhone/iPod Touch.\n\n"); + printf(" -d, --debug\t\tenable communication debugging\n"); + printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); + printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n"); + printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n"); + printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n"); + printf(" -h, --help\t\tprints usage information\n"); + printf("\n"); + printf(" Known domains are:\n\n"); + while (domains[i] != NULL) { + printf(" %s\n", domains[i++]); + } + printf("\n"); +} int main(int argc, char *argv[]) { @@ -73,6 +225,7 @@ int main(int argc, char *argv[]) char *xml_doc = NULL; uint32_t xml_length; plist_t node = NULL; + plist_type node_type; uuid[0] = 0; /* parse cmdline args */ @@ -147,29 +300,30 @@ int main(int argc, char *argv[]) } /* run query and output information */ - if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) - { - if (plist_get_node_type(node) == PLIST_DICT) { - if (plist_dict_get_size(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: - default: - plist_children_to_string(node); + 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; } - } - else if(node && (key != NULL)) - plist_node_to_string(node); - if (node) plist_free(node); - node = NULL; + node = NULL; + } } if (domain != NULL) @@ -180,115 +334,3 @@ int main(int argc, char *argv[]) return 0; } -int is_domain_known(char *domain) -{ - int i = 0; - while (domains[i] != NULL) { - if (strstr(domain, domains[i++])) { - return 1; - } - } - return 0; -} - -void print_usage(int argc, char **argv) -{ - int i = 0; - char *name = NULL; - - name = strrchr(argv[0], '/'); - printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); - printf("Show information about the first connected iPhone/iPod Touch.\n\n"); - printf(" -d, --debug\t\tenable communication debugging\n"); - printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); - printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n"); - printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n"); - printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n"); - printf(" -h, --help\t\tprints usage information\n"); - printf("\n"); - printf(" Known domains are:\n\n"); - while (domains[i] != NULL) { - printf(" %s\n", domains[i++]); - } - printf("\n"); -} - -void plist_node_to_string(plist_t node) -{ - char *s = NULL; - double d; - uint8_t b; - - uint64_t u = 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: - printf("\n"); - break; - case PLIST_DATE: - printf("\n"); - break; - case PLIST_ARRAY: - case PLIST_DICT: - printf("\n"); - plist_children_to_string(node); - break; - default: - break; - } -} - -void plist_children_to_string(plist_t node) -{ - /* iterate over key/value pairs */ - plist_dict_iter it = NULL; - - char* key = NULL; - plist_t subnode = NULL; - plist_dict_new_iter(node, &it); - plist_dict_next_item(node, it, &key, &subnode); - while (subnode) - { - printf("%s: ", key); - free(key); - key = NULL; - plist_node_to_string(subnode); - plist_dict_next_item(node, it, &key, &subnode); - } - free(it); -} - |