summaryrefslogtreecommitdiffstats
path: root/tools/ideviceinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/ideviceinfo.c')
-rw-r--r--tools/ideviceinfo.c363
1 files changed, 139 insertions, 224 deletions
diff --git a/tools/ideviceinfo.c b/tools/ideviceinfo.c
index e05165b..fd45763 100644
--- a/tools/ideviceinfo.c
+++ b/tools/ideviceinfo.c
@@ -2,40 +2,59 @@
* ideviceinfo.c
* Simple utility to show information about an attached device
*
+ * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved.
* Copyright (c) 2009 Martin Szulecki All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define TOOL_NAME "ideviceinfo"
+
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
-#include <glib.h>
+#include <getopt.h>
+#ifndef WIN32
+#include <signal.h>
+#endif
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>
+#include <plist/plist.h>
#define FORMAT_KEY_VALUE 1
#define FORMAT_XML 2
static const char *domains[] = {
"com.apple.disk_usage",
+ "com.apple.disk_usage.factory",
"com.apple.mobile.battery",
-/* FIXME: For some reason lockdownd segfaults on this, works sometimes though
+/* FIXME: For some reason lockdownd segfaults on this, works sometimes though
"com.apple.mobile.debug",. */
+ "com.apple.iqagent",
+ "com.apple.purplebuddy",
+ "com.apple.PurpleBuddy",
+ "com.apple.mobile.chaperone",
+ "com.apple.mobile.third_party_termination",
+ "com.apple.mobile.lockdownd",
+ "com.apple.mobile.lockdown_cache",
"com.apple.xcode.developerdomain",
"com.apple.international",
"com.apple.mobile.data_sync",
@@ -55,12 +74,12 @@ static const char *domains[] = {
"com.apple.iTunes",
"com.apple.mobile.iTunes.store",
"com.apple.mobile.iTunes",
+ "com.apple.fmip",
+ "com.apple.Accessibility",
NULL
};
-static int indent_level = 0;
-
-static int is_domain_known(char *domain)
+static int is_domain_known(const char *domain)
{
int i = 0;
while (domains[i] != NULL) {
@@ -71,244 +90,147 @@ static int is_domain_known(char *domain)
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)
+static void print_usage(int argc, char **argv, int is_error)
{
int i = 0;
- char *name = NULL;
-
- name = strrchr(argv[0], '/');
- printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
- printf("Show information about a connected iPhone/iPod Touch.\n\n");
- printf(" -d, --debug\t\tenable communication debugging\n");
- printf(" -s, --simple\t\tuse a simple connection to avoid auto-pairing with the device\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");
+ char *name = strrchr(argv[0], '/');
+ fprintf(is_error ? stderr : stdout, "Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
+ fprintf(is_error ? stderr : stdout,
+ "\n"
+ "Show information about a connected device.\n"
+ "\n"
+ "OPTIONS:\n"
+ " -u, --udid UDID target specific device by UDID\n"
+ " -n, --network connect to network device\n"
+ " -s, --simple use simple connection to avoid auto-pairing with device\n"
+ " -q, --domain NAME set domain of query to NAME. Default: None\n" \
+ " -k, --key NAME only query key specified by NAME. Default: All keys.\n" \
+ " -x, --xml output information in XML property list format\n" \
+ " -h, --help prints usage information\n" \
+ " -d, --debug enable communication debugging\n" \
+ " -v, --version prints version information\n" \
+ "\n"
+ );
+ fprintf(is_error ? stderr : stdout, "Known domains are:\n\n");
while (domains[i] != NULL) {
- printf(" %s\n", domains[i++]);
+ fprintf(is_error ? stderr : stdout, " %s\n", domains[i++]);
}
- printf("\n");
+ fprintf(is_error ? stderr : stdout,
+ "\n" \
+ "Homepage: <" PACKAGE_URL ">\n"
+ "Bug Reports: <" PACKAGE_BUGREPORT ">\n"
+ );
}
int main(int argc, char *argv[])
{
lockdownd_client_t client = NULL;
- idevice_t phone = NULL;
+ lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR;
+ idevice_t device = 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;
+ const char* udid = NULL;
+ int use_network = 0;
+ const char *domain = NULL;
+ const 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")) {
+ int c = 0;
+ const struct option longopts[] = {
+ { "debug", no_argument, NULL, 'd' },
+ { "help", no_argument, NULL, 'h' },
+ { "udid", required_argument, NULL, 'u' },
+ { "network", no_argument, NULL, 'n' },
+ { "domain", required_argument, NULL, 'q' },
+ { "key", required_argument, NULL, 'k' },
+ { "simple", no_argument, NULL, 's' },
+ { "xml", no_argument, NULL, 'x' },
+ { "version", no_argument, NULL, 'v' },
+ { NULL, 0, NULL, 0}
+ };
+
+#ifndef WIN32
+ signal(SIGPIPE, SIG_IGN);
+#endif
+
+ while ((c = getopt_long(argc, argv, "dhu:nq:k:sxv", longopts, NULL)) != -1) {
+ switch (c) {
+ case 'd':
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;
+ break;
+ case 'u':
+ if (!*optarg) {
+ fprintf(stderr, "ERROR: UDID must not be empty!\n");
+ print_usage(argc, argv, 1);
+ return 2;
}
- if (!is_domain_known(argv[i])) {
- fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", argv[i]);
+ udid = optarg;
+ break;
+ case 'n':
+ use_network = 1;
+ break;
+ case 'q':
+ if (!*optarg) {
+ fprintf(stderr, "ERROR: 'domain' must not be empty!\n");
+ print_usage(argc, argv, 1);
+ return 2;
}
- 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;
+ domain = optarg;
+ break;
+ case 'k':
+ if (!*optarg) {
+ fprintf(stderr, "ERROR: 'key' must not be empty!\n");
+ print_usage(argc, argv, 1);
+ return 2;
}
- key = strdup(argv[i]);
- continue;
- }
- else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) {
+ key = optarg;
+ break;
+ case 'x':
format = FORMAT_XML;
- continue;
- }
- else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--simple")) {
+ break;
+ case 's':
simple = 1;
- continue;
- }
- else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
- print_usage(argc, argv);
+ break;
+ case 'h':
+ print_usage(argc, argv, 0);
return 0;
- }
- else {
- print_usage(argc, argv);
+ case 'v':
+ printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION);
return 0;
+ default:
+ print_usage(argc, argv, 1);
+ return 2;
}
}
- 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;
+ argc -= optind;
+ argv += optind;
+
+ ret = idevice_new_with_options(&device, udid, (use_network) ? IDEVICE_LOOKUP_NETWORK : IDEVICE_LOOKUP_USBMUX);
+ if (ret != IDEVICE_E_SUCCESS) {
+ if (udid) {
+ fprintf(stderr, "ERROR: Device %s not found!\n", udid);
+ } else {
+ fprintf(stderr, "ERROR: No device found!\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);
+ if (LOCKDOWN_E_SUCCESS != (ldret = simple ?
+ lockdownd_client_new(device, &client, TOOL_NAME):
+ lockdownd_client_new_with_handshake(device, &client, TOOL_NAME))) {
+ fprintf(stderr, "ERROR: Could not connect to lockdownd: %s (%d)\n", lockdownd_strerror(ldret), ldret);
+ idevice_free(device);
return -1;
}
+ if (domain && !is_domain_known(domain)) {
+ fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", domain);
+ }
+
/* run query and output information */
if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) {
if (node) {
@@ -319,16 +241,11 @@ int main(int argc, char *argv[])
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;
- }
+ plist_write_to_stream(node, stdout, PLIST_FORMAT_LIMD, 0);
+ break;
default:
if (key != NULL)
- plist_node_to_string(node);
+ plist_write_to_stream(node, stdout, PLIST_FORMAT_LIMD, 0);
break;
}
plist_free(node);
@@ -336,10 +253,8 @@ int main(int argc, char *argv[])
}
}
- if (domain != NULL)
- free(domain);
lockdownd_client_free(client);
- idevice_free(phone);
+ idevice_free(device);
return 0;
}