diff options
Diffstat (limited to 'tools/ideviceinfo.c')
| -rw-r--r-- | tools/ideviceinfo.c | 154 |
1 files changed, 88 insertions, 66 deletions
diff --git a/tools/ideviceinfo.c b/tools/ideviceinfo.c index a1124cf..bd3819e 100644 --- a/tools/ideviceinfo.c +++ b/tools/ideviceinfo.c | |||
| @@ -2,6 +2,7 @@ | |||
| 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 |
| @@ -27,6 +28,7 @@ | |||
| 27 | #include <string.h> | 28 | #include <string.h> |
| 28 | #include <errno.h> | 29 | #include <errno.h> |
| 29 | #include <stdlib.h> | 30 | #include <stdlib.h> |
| 31 | #include <getopt.h> | ||
| 30 | #ifndef WIN32 | 32 | #ifndef WIN32 |
| 31 | #include <signal.h> | 33 | #include <signal.h> |
| 32 | #endif | 34 | #endif |
| @@ -84,28 +86,32 @@ static int is_domain_known(char *domain) | |||
| 84 | return 0; | 86 | return 0; |
| 85 | } | 87 | } |
| 86 | 88 | ||
| 87 | static void print_usage(int argc, char **argv) | 89 | static void print_usage(int argc, char **argv, int is_error) |
| 88 | { | 90 | { |
| 89 | int i = 0; | 91 | int i = 0; |
| 90 | char *name = NULL; | 92 | char *name = NULL; |
| 91 | |||
| 92 | name = strrchr(argv[0], '/'); | 93 | name = strrchr(argv[0], '/'); |
| 93 | printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); | 94 | fprintf(is_error ? stderr : stdout, "Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); |
| 94 | printf("Show information about a connected device.\n\n"); | 95 | fprintf(is_error ? stderr : stdout, |
| 95 | printf(" -d, --debug\t\tenable communication debugging\n"); | 96 | "Show information about a connected device.\n\n" \ |
| 96 | printf(" -s, --simple\t\tuse a simple connection to avoid auto-pairing with the device\n"); | 97 | " -s, --simple use a simple connection to avoid auto-pairing with the device\n" \ |
| 97 | printf(" -u, --udid UDID\ttarget specific device by UDID\n"); | 98 | " -u, --udid UDID target specific device by UDID\n" \ |
| 98 | printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n"); | 99 | " -n, --network connect to network device even if available via USB\n" \ |
| 99 | printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n"); | 100 | " -q, --domain NAME set domain of query to NAME. Default: None\n" \ |
| 100 | printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n"); | 101 | " -k, --key NAME only query key specified by NAME. Default: All keys.\n" \ |
| 101 | printf(" -h, --help\t\tprints usage information\n"); | 102 | " -x, --xml output information as xml plist instead of key/value pairs\n" \ |
| 102 | printf("\n"); | 103 | " -h, --help prints usage information\n" \ |
| 103 | printf(" Known domains are:\n\n"); | 104 | " -d, --debug enable communication debugging\n" \ |
| 105 | "\n" | ||
| 106 | ); | ||
| 107 | fprintf(is_error ? stderr : stdout, " Known domains are:\n\n"); | ||
| 104 | while (domains[i] != NULL) { | 108 | while (domains[i] != NULL) { |
| 105 | printf(" %s\n", domains[i++]); | 109 | fprintf(is_error ? stderr : stdout, " %s\n", domains[i++]); |
| 106 | } | 110 | } |
| 107 | printf("\n"); | 111 | fprintf(is_error ? stderr : stdout, |
| 108 | printf("Homepage: <" PACKAGE_URL ">\n"); | 112 | "\n" \ |
| 113 | "Homepage: <" PACKAGE_URL ">\n" | ||
| 114 | ); | ||
| 109 | } | 115 | } |
| 110 | 116 | ||
| 111 | int main(int argc, char *argv[]) | 117 | int main(int argc, char *argv[]) |
| @@ -114,79 +120,91 @@ int main(int argc, char *argv[]) | |||
| 114 | lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR; | 120 | lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR; |
| 115 | idevice_t device = NULL; | 121 | idevice_t device = NULL; |
| 116 | idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; | 122 | idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; |
| 117 | int i; | ||
| 118 | int simple = 0; | 123 | int simple = 0; |
| 119 | int format = FORMAT_KEY_VALUE; | 124 | int format = FORMAT_KEY_VALUE; |
| 120 | const char* udid = NULL; | 125 | char* udid = NULL; |
| 121 | char *domain = NULL; | 126 | char *domain = NULL; |
| 122 | char *key = NULL; | 127 | char *key = NULL; |
| 123 | char *xml_doc = NULL; | 128 | char *xml_doc = NULL; |
| 124 | uint32_t xml_length; | 129 | uint32_t xml_length; |
| 125 | plist_t node = NULL; | 130 | plist_t node = NULL; |
| 131 | enum idevice_options lookup_opts = IDEVICE_LOOKUP_USBMUX | IDEVICE_LOOKUP_NETWORK; | ||
| 132 | |||
| 133 | int c = 0; | ||
| 134 | const struct option longopts[] = { | ||
| 135 | { "debug", no_argument, NULL, 'd' }, | ||
| 136 | { "help", no_argument, NULL, 'h' }, | ||
| 137 | { "udid", required_argument, NULL, 'u' }, | ||
| 138 | { "network", no_argument, NULL, 'n' }, | ||
| 139 | { "domain", required_argument, NULL, 'q' }, | ||
| 140 | { "key", required_argument, NULL, 'k' }, | ||
| 141 | { "xml", no_argument, NULL, 'x' }, | ||
| 142 | { NULL, 0, NULL, 0} | ||
| 143 | }; | ||
| 126 | 144 | ||
| 127 | #ifndef WIN32 | 145 | #ifndef WIN32 |
| 128 | signal(SIGPIPE, SIG_IGN); | 146 | signal(SIGPIPE, SIG_IGN); |
| 129 | #endif | 147 | #endif |
| 130 | /* parse cmdline args */ | 148 | |
| 131 | for (i = 1; i < argc; i++) { | 149 | while ((c = getopt_long(argc, argv, "dhu:nq:k:x", longopts, NULL)) != -1) { |
| 132 | if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { | 150 | switch (c) { |
| 151 | case 'd': | ||
| 133 | idevice_set_debug_level(1); | 152 | idevice_set_debug_level(1); |
| 134 | continue; | 153 | break; |
| 135 | } | 154 | case 'u': |
| 136 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) { | 155 | if (!*optarg) { |
| 137 | i++; | 156 | fprintf(stderr, "ERROR: UDID must not be empty!\n"); |
| 138 | if (!argv[i] || !*argv[i]) { | 157 | print_usage(argc, argv, 1); |
| 139 | print_usage(argc, argv); | 158 | return 2; |
| 140 | return 0; | ||
| 141 | } | ||
| 142 | udid = argv[i]; | ||
| 143 | continue; | ||
| 144 | } | ||
| 145 | else if (!strcmp(argv[i], "-q") || !strcmp(argv[i], "--domain")) { | ||
| 146 | i++; | ||
| 147 | if (!argv[i] || (strlen(argv[i]) < 4)) { | ||
| 148 | print_usage(argc, argv); | ||
| 149 | return 0; | ||
| 150 | } | 159 | } |
| 151 | if (!is_domain_known(argv[i])) { | 160 | free(udid); |
| 152 | fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", argv[i]); | 161 | udid = strdup(optarg); |
| 162 | break; | ||
| 163 | case 'n': | ||
| 164 | lookup_opts |= IDEVICE_LOOKUP_PREFER_NETWORK; | ||
| 165 | break; | ||
| 166 | case 'q': | ||
| 167 | if (!*optarg) { | ||
| 168 | fprintf(stderr, "ERROR: 'domain' must not be empty!\n"); | ||
| 169 | print_usage(argc, argv, 1); | ||
| 170 | return 2; | ||
| 153 | } | 171 | } |
| 154 | domain = strdup(argv[i]); | 172 | free(domain); |
| 155 | continue; | 173 | domain = strdup(optarg); |
| 156 | } | 174 | break; |
| 157 | else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--key")) { | 175 | case 'k': |
| 158 | i++; | 176 | if (!*optarg) { |
| 159 | if (!argv[i] || (strlen(argv[i]) <= 1)) { | 177 | fprintf(stderr, "ERROR: 'key' must not be empty!\n"); |
| 160 | print_usage(argc, argv); | 178 | print_usage(argc, argv, 1); |
| 161 | return 0; | 179 | return 2; |
| 162 | } | 180 | } |
| 163 | key = strdup(argv[i]); | 181 | free(key); |
| 164 | continue; | 182 | key = strdup(optarg); |
| 165 | } | 183 | break; |
| 166 | else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) { | 184 | case 'x': |
| 167 | format = FORMAT_XML; | 185 | format = FORMAT_XML; |
| 168 | continue; | 186 | break; |
| 169 | } | 187 | case 's': |
| 170 | else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--simple")) { | ||
| 171 | simple = 1; | 188 | simple = 1; |
| 172 | continue; | 189 | break; |
| 173 | } | 190 | case 'h': |
| 174 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | 191 | print_usage(argc, argv, 0); |
| 175 | print_usage(argc, argv); | ||
| 176 | return 0; | ||
| 177 | } | ||
| 178 | else { | ||
| 179 | print_usage(argc, argv); | ||
| 180 | return 0; | 192 | return 0; |
| 193 | default: | ||
| 194 | print_usage(argc, argv, 1); | ||
| 195 | return 2; | ||
| 181 | } | 196 | } |
| 182 | } | 197 | } |
| 183 | 198 | ||
| 184 | ret = idevice_new(&device, udid); | 199 | argc -= optind; |
| 200 | argv += optind; | ||
| 201 | |||
| 202 | ret = idevice_new_with_options(&device, udid, lookup_opts); | ||
| 185 | if (ret != IDEVICE_E_SUCCESS) { | 203 | if (ret != IDEVICE_E_SUCCESS) { |
| 186 | if (udid) { | 204 | if (udid) { |
| 187 | printf("No device found with udid %s, is it plugged in?\n", udid); | 205 | printf("ERROR: Device %s not found!\n", udid); |
| 188 | } else { | 206 | } else { |
| 189 | printf("No device found, is it plugged in?\n"); | 207 | printf("ERROR: No device found!\n"); |
| 190 | } | 208 | } |
| 191 | return -1; | 209 | return -1; |
| 192 | } | 210 | } |
| @@ -194,11 +212,15 @@ int main(int argc, char *argv[]) | |||
| 194 | if (LOCKDOWN_E_SUCCESS != (ldret = simple ? | 212 | if (LOCKDOWN_E_SUCCESS != (ldret = simple ? |
| 195 | lockdownd_client_new(device, &client, "ideviceinfo"): | 213 | lockdownd_client_new(device, &client, "ideviceinfo"): |
| 196 | lockdownd_client_new_with_handshake(device, &client, "ideviceinfo"))) { | 214 | lockdownd_client_new_with_handshake(device, &client, "ideviceinfo"))) { |
| 197 | fprintf(stderr, "ERROR: Could not connect to lockdownd, error code %d\n", ldret); | 215 | fprintf(stderr, "ERROR: Could not connect to lockdownd: %s (%d)\n", lockdownd_strerror(ldret), ldret); |
| 198 | idevice_free(device); | 216 | idevice_free(device); |
| 199 | return -1; | 217 | return -1; |
| 200 | } | 218 | } |
| 201 | 219 | ||
| 220 | if (domain && !is_domain_known(domain)) { | ||
| 221 | fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", domain); | ||
| 222 | } | ||
| 223 | |||
| 202 | /* run query and output information */ | 224 | /* run query and output information */ |
| 203 | if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) { | 225 | if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) { |
| 204 | if (node) { | 226 | if (node) { |
