diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/Makefile.am | 7 | ||||
| -rw-r--r-- | tools/idevicediagnostics.c | 134 |
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 | |||
| 3 | AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(openssl_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) | 3 | AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(openssl_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) |
| 4 | AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(openssl_LIBS) $(libplist_LIBS) | 4 | AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(openssl_LIBS) $(libplist_LIBS) |
| 5 | 5 | ||
| 6 | bin_PROGRAMS = idevice_id ideviceinfo idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate idevicebackup idevicebackup2 ideviceprovision idevicedebugserverproxy | 6 | bin_PROGRAMS = idevice_id ideviceinfo idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate idevicebackup idevicebackup2 ideviceprovision idevicedebugserverproxy idevicediagnostics |
| 7 | 7 | ||
| 8 | ideviceinfo_SOURCES = ideviceinfo.c | 8 | ideviceinfo_SOURCES = ideviceinfo.c |
| 9 | ideviceinfo_CFLAGS = $(AM_CFLAGS) | 9 | ideviceinfo_CFLAGS = $(AM_CFLAGS) |
| @@ -64,3 +64,8 @@ idevicedebugserverproxy_SOURCES = idevicedebugserverproxy.c socket.c thread.c | |||
| 64 | idevicedebugserverproxy_CFLAGS = $(AM_CFLAGS) | 64 | idevicedebugserverproxy_CFLAGS = $(AM_CFLAGS) |
| 65 | idevicedebugserverproxy_LDFLAGS = $(AM_LDFLAGS) | 65 | idevicedebugserverproxy_LDFLAGS = $(AM_LDFLAGS) |
| 66 | idevicedebugserverproxy_LDADD = ../src/libimobiledevice.la | 66 | idevicedebugserverproxy_LDADD = ../src/libimobiledevice.la |
| 67 | |||
| 68 | idevicediagnostics_SOURCES = idevicediagnostics.c | ||
| 69 | idevicediagnostics_CFLAGS = $(AM_CFLAGS) | ||
| 70 | idevicediagnostics_LDFLAGS = $(AM_LDFLAGS) | ||
| 71 | 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 @@ | |||
| 1 | /** | ||
| 2 | * idevicediagnostics -- Retrieves diagnostics information from device | ||
| 3 | * | ||
| 4 | * Copyright (c) 2012 Martin Szulecki All Rights Reserved. | ||
| 5 | * | ||
| 6 | * Licensed under the GNU General Public License Version 2 | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2 of the License, or | ||
| 11 | * (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | * GNU General Public License for more profile. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||
| 21 | * USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <stdio.h> | ||
| 25 | #include <string.h> | ||
| 26 | #include <stdlib.h> | ||
| 27 | #include <errno.h> | ||
| 28 | #include <time.h> | ||
| 29 | |||
| 30 | #include <libimobiledevice/libimobiledevice.h> | ||
| 31 | #include <libimobiledevice/lockdown.h> | ||
| 32 | #include <libimobiledevice/diagnostics_relay.h> | ||
| 33 | |||
| 34 | static void print_xml(plist_t node) | ||
| 35 | { | ||
| 36 | char *xml = NULL; | ||
| 37 | uint32_t len = 0; | ||
| 38 | plist_to_xml(node, &xml, &len); | ||
| 39 | if (xml) | ||
| 40 | puts(xml); | ||
| 41 | } | ||
| 42 | |||
| 43 | void print_usage(int argc, char **argv); | ||
| 44 | |||
| 45 | int main(int argc, char **argv) | ||
| 46 | { | ||
| 47 | idevice_t device = NULL; | ||
| 48 | lockdownd_client_t lckd = NULL; | ||
| 49 | diagnostics_relay_client_t diagc = NULL; | ||
| 50 | uint16_t port = 0; | ||
| 51 | int result = -1; | ||
| 52 | int i; | ||
| 53 | char *udid = NULL; | ||
| 54 | |||
| 55 | /* parse cmdline args */ | ||
| 56 | for (i = 1; i < argc; i++) { | ||
| 57 | if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { | ||
| 58 | idevice_set_debug_level(1); | ||
| 59 | continue; | ||
| 60 | } | ||
| 61 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) { | ||
| 62 | i++; | ||
| 63 | if (!argv[i] || (strlen(argv[i]) != 40)) { | ||
| 64 | print_usage(argc, argv); | ||
| 65 | return 0; | ||
| 66 | } | ||
| 67 | udid = strdup(argv[i]); | ||
| 68 | continue; | ||
| 69 | } | ||
| 70 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | ||
| 71 | print_usage(argc, argv); | ||
| 72 | return 0; | ||
| 73 | } | ||
| 74 | else { | ||
| 75 | print_usage(argc, argv); | ||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | if (IDEVICE_E_SUCCESS != idevice_new(&device, udid)) { | ||
| 81 | printf("No device found, is it plugged in?\n"); | ||
| 82 | if (udid) { | ||
| 83 | free(udid); | ||
| 84 | } | ||
| 85 | return -1; | ||
| 86 | } | ||
| 87 | if (udid) { | ||
| 88 | free(udid); | ||
| 89 | } | ||
| 90 | |||
| 91 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lckd, NULL)) { | ||
| 92 | idevice_free(device); | ||
| 93 | printf("Exiting.\n"); | ||
| 94 | return -1; | ||
| 95 | } | ||
| 96 | |||
| 97 | lockdownd_start_service(lckd, "com.apple.mobile.diagnostics_relay", &port); | ||
| 98 | lockdownd_client_free(lckd); | ||
| 99 | if (port > 0) { | ||
| 100 | if (diagnostics_relay_client_new(device, port, &diagc) != DIAGNOSTICS_RELAY_E_SUCCESS) { | ||
| 101 | printf("Could not connect to diagnostics_relay!\n"); | ||
| 102 | result = -1; | ||
| 103 | } else { | ||
| 104 | plist_t node = NULL; | ||
| 105 | if (diagnostics_relay_request_diagnostics(diagc, &node) != DIAGNOSTICS_RELAY_E_SUCCESS) { | ||
| 106 | printf("Unable to retrieve diagnostics"); | ||
| 107 | } | ||
| 108 | if (node) { | ||
| 109 | print_xml(node); | ||
| 110 | plist_free(node); | ||
| 111 | } | ||
| 112 | diagnostics_relay_goodbye(diagc); | ||
| 113 | diagnostics_relay_client_free(diagc); | ||
| 114 | } | ||
| 115 | } else { | ||
| 116 | printf("Could not start diagnostics service!\n"); | ||
| 117 | } | ||
| 118 | idevice_free(device); | ||
| 119 | |||
| 120 | return result; | ||
| 121 | } | ||
| 122 | |||
| 123 | void print_usage(int argc, char **argv) | ||
| 124 | { | ||
| 125 | char *name = NULL; | ||
| 126 | |||
| 127 | name = strrchr(argv[0], '/'); | ||
| 128 | printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); | ||
| 129 | printf("Retrieves diagnostics information from a device.\n\n"); | ||
| 130 | printf(" -d, --debug\t\tenable communication debugging\n"); | ||
| 131 | printf(" -u, --udid UDID\ttarget specific device by its 40-digit device UDID\n"); | ||
| 132 | printf(" -h, --help\t\tprints usage information\n"); | ||
| 133 | printf("\n"); | ||
| 134 | } | ||
