summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2012-04-01 01:43:19 +0200
committerGravatar Martin Szulecki2012-10-21 14:19:50 +0200
commit446f1b8dbd65c95c7cb37ceca5e907181b9b6169 (patch)
treefbb6400e3e8175bd80d9eccf24a1368fa1fbae39
parent8b61d177dbfa5c12d582bd58df8243b6d21571b8 (diff)
downloadlibimobiledevice-446f1b8dbd65c95c7cb37ceca5e907181b9b6169.tar.gz
libimobiledevice-446f1b8dbd65c95c7cb37ceca5e907181b9b6169.tar.bz2
Add new idevicediagnostics tool
-rw-r--r--tools/Makefile.am7
-rw-r--r--tools/idevicediagnostics.c134
2 files changed, 140 insertions, 1 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 904159b..cf248f3 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -3,7 +3,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(openssl_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS)
AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(openssl_LIBS) $(libplist_LIBS)
-bin_PROGRAMS = idevice_id ideviceinfo idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate idevicebackup idevicebackup2 ideviceprovision idevicedebugserverproxy
+bin_PROGRAMS = idevice_id ideviceinfo idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate idevicebackup idevicebackup2 ideviceprovision idevicedebugserverproxy idevicediagnostics
ideviceinfo_SOURCES = ideviceinfo.c
ideviceinfo_CFLAGS = $(AM_CFLAGS)
@@ -64,3 +64,8 @@ idevicedebugserverproxy_SOURCES = idevicedebugserverproxy.c socket.c thread.c
idevicedebugserverproxy_CFLAGS = $(AM_CFLAGS)
idevicedebugserverproxy_LDFLAGS = $(AM_LDFLAGS)
idevicedebugserverproxy_LDADD = ../src/libimobiledevice.la
+
+idevicediagnostics_SOURCES = idevicediagnostics.c
+idevicediagnostics_CFLAGS = $(AM_CFLAGS)
+idevicediagnostics_LDFLAGS = $(AM_LDFLAGS)
+idevicediagnostics_LDADD = ../src/libimobiledevice.la
diff --git a/tools/idevicediagnostics.c b/tools/idevicediagnostics.c
new file mode 100644
index 0000000..6b8a68d
--- /dev/null
+++ b/tools/idevicediagnostics.c
@@ -0,0 +1,134 @@
+/**
+ * idevicediagnostics -- Retrieves diagnostics information from device
+ *
+ * Copyright (c) 2012 Martin Szulecki All Rights Reserved.
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more profile.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <time.h>
+
+#include <libimobiledevice/libimobiledevice.h>
+#include <libimobiledevice/lockdown.h>
+#include <libimobiledevice/diagnostics_relay.h>
+
+static void print_xml(plist_t node)
+{
+ char *xml = NULL;
+ uint32_t len = 0;
+ plist_to_xml(node, &xml, &len);
+ if (xml)
+ puts(xml);
+}
+
+void print_usage(int argc, char **argv);
+
+int main(int argc, char **argv)
+{
+ idevice_t device = NULL;
+ lockdownd_client_t lckd = NULL;
+ diagnostics_relay_client_t diagc = NULL;
+ uint16_t port = 0;
+ int result = -1;
+ int i;
+ char *udid = NULL;
+
+ /* 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], "--udid")) {
+ i++;
+ if (!argv[i] || (strlen(argv[i]) != 40)) {
+ print_usage(argc, argv);
+ return 0;
+ }
+ udid = strdup(argv[i]);
+ 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 (IDEVICE_E_SUCCESS != idevice_new(&device, udid)) {
+ printf("No device found, is it plugged in?\n");
+ if (udid) {
+ free(udid);
+ }
+ return -1;
+ }
+ if (udid) {
+ free(udid);
+ }
+
+ if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lckd, NULL)) {
+ idevice_free(device);
+ printf("Exiting.\n");
+ return -1;
+ }
+
+ lockdownd_start_service(lckd, "com.apple.mobile.diagnostics_relay", &port);
+ lockdownd_client_free(lckd);
+ if (port > 0) {
+ if (diagnostics_relay_client_new(device, port, &diagc) != DIAGNOSTICS_RELAY_E_SUCCESS) {
+ printf("Could not connect to diagnostics_relay!\n");
+ result = -1;
+ } else {
+ plist_t node = NULL;
+ if (diagnostics_relay_request_diagnostics(diagc, &node) != DIAGNOSTICS_RELAY_E_SUCCESS) {
+ printf("Unable to retrieve diagnostics");
+ }
+ if (node) {
+ print_xml(node);
+ plist_free(node);
+ }
+ diagnostics_relay_goodbye(diagc);
+ diagnostics_relay_client_free(diagc);
+ }
+ } else {
+ printf("Could not start diagnostics service!\n");
+ }
+ idevice_free(device);
+
+ return result;
+}
+
+void print_usage(int argc, char **argv)
+{
+ char *name = NULL;
+
+ name = strrchr(argv[0], '/');
+ printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
+ printf("Retrieves diagnostics information from a device.\n\n");
+ printf(" -d, --debug\t\tenable communication debugging\n");
+ printf(" -u, --udid UDID\ttarget specific device by its 40-digit device UDID\n");
+ printf(" -h, --help\t\tprints usage information\n");
+ printf("\n");
+}