summaryrefslogtreecommitdiffstats
path: root/dev
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-07-28 10:58:50 +0200
committerGravatar Martin Szulecki2009-07-28 10:58:50 +0200
commite169cf993dbf7515cad3da03993a4d224d6cf181 (patch)
tree6aca7a4e59779232d9b50bd06ce25abf4ec1f294 /dev
parentc443a1fbc2fe5e9858015193628ef66623535766 (diff)
downloadlibimobiledevice-e169cf993dbf7515cad3da03993a4d224d6cf181.tar.gz
libimobiledevice-e169cf993dbf7515cad3da03993a4d224d6cf181.tar.bz2
Move production ready tools into tools/ and do not install the dev/ ones
Diffstat (limited to 'dev')
-rw-r--r--dev/Makefile.am19
-rw-r--r--dev/iphone_id.c94
-rw-r--r--dev/iphoneclient.c (renamed from dev/main.c)0
-rw-r--r--dev/iphoneinfo.c281
-rw-r--r--dev/syslog_relay.c169
5 files changed, 2 insertions, 561 deletions
diff --git a/dev/Makefile.am b/dev/Makefile.am
index 9e06339..70cd52b 100644
--- a/dev/Makefile.am
+++ b/dev/Makefile.am
@@ -3,9 +3,9 @@ INCLUDES = -I$(top_srcdir)/include
3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) 3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS)
4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) 4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS)
5 5
6bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog iphone_id 6noinst_PROGRAMS = iphoneclient lckd-client afccheck msyncclient
7 7
8iphoneclient_SOURCES = main.c 8iphoneclient_SOURCES = iphoneclient.c
9iphoneclient_LDADD = ../src/libiphone.la 9iphoneclient_LDADD = ../src/libiphone.la
10 10
11lckd_client_SOURCES = lckdclient.c 11lckd_client_SOURCES = lckdclient.c
@@ -22,18 +22,3 @@ msyncclient_SOURCES = msyncclient.c
22msyncclient_CFLAGS = $(AM_CFLAGS) 22msyncclient_CFLAGS = $(AM_CFLAGS)
23msyncclient_LDFLAGS = $(AM_LDFLAGS) 23msyncclient_LDFLAGS = $(AM_LDFLAGS)
24msyncclient_LDADD = ../src/libiphone.la 24msyncclient_LDADD = ../src/libiphone.la
25
26iphoneinfo_SOURCES = iphoneinfo.c
27iphoneinfo_CFLAGS = $(AM_CFLAGS)
28iphoneinfo_LDFLAGS = $(AM_LDFLAGS)
29iphoneinfo_LDADD = ../src/libiphone.la
30
31iphonesyslog_SOURCES = syslog_relay.c
32iphonesyslog_CFLAGS = $(AM_CFLAGS)
33iphonesyslog_LDFLAGS = $(AM_LDFLAGS)
34iphonesyslog_LDADD = ../src/libiphone.la
35
36iphone_id_SOURCES = iphone_id.c
37iphone_id_CFLAGS = $(AM_CFLAGS)
38iphone_id_LDFLAGS = $(AM_LDFLAGS)
39iphone_id_LDADD = ../src/libiphone.la
diff --git a/dev/iphone_id.c b/dev/iphone_id.c
deleted file mode 100644
index f68fc8b..0000000
--- a/dev/iphone_id.c
+++ /dev/null
@@ -1,94 +0,0 @@
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <getopt.h>
5#include <libiphone/libiphone.h>
6#include <libiphone/lockdown.h>
7#include <usbmuxd.h>
8
9static void usage()
10{
11 printf("usage: iphone_id <device_uuid>\n"
12 "\tdevice_uuid is the 40-digit hexadecimal UUID of the device\n"
13 "\tfor which the name should be retrieved.\n\n"
14 "usage: iphone_id -l\n"
15 "\tList all attached devices.\n");
16 exit(0);
17}
18
19int main(int argc, char **argv)
20{
21 iphone_device_t phone = NULL;
22 lockdownd_client_t client = NULL;
23 usbmuxd_scan_result *dev_list;
24 char *devname = NULL;
25 int ret = 0;
26 int c;
27 int i;
28 int opt_list = 0;
29
30 while ((c = getopt(argc, argv, "lh")) != -1) {
31 switch (c) {
32 case 'l':
33 opt_list = 1;
34 break;
35 case 'h':
36 default:
37 usage();
38 }
39 }
40
41 if (argc < 2) {
42 usage();
43 }
44
45 argc -= optind;
46 argv += optind;
47
48 if ((!opt_list) && (strlen(argv[0]) != 40)) {
49 usage();
50 }
51
52 if (opt_list) {
53 if (usbmuxd_scan(&dev_list) < 0) {
54 fprintf(stderr, "ERROR: usbmuxd is not running!\n");
55 return -1;
56 }
57 for (i = 0; dev_list[i].handle > 0; i++) {
58 printf("handle=%d product_id=%04x uuid=%s\n", dev_list[i].handle, dev_list[i].product_id, dev_list[i].serial_number);
59 }
60 return 0;
61 }
62
63 iphone_set_debug_level(0);
64
65 iphone_get_device_by_uuid(&phone, argv[0]);
66 if (!phone) {
67 fprintf(stderr, "ERROR: No device with UUID=%s attached.\n", argv[0]);
68 return -2;
69 }
70
71 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) {
72 iphone_device_free(phone);
73 fprintf(stderr, "ERROR: Connecting to device failed!\n");
74 return -2;
75 }
76
77 if ((LOCKDOWN_E_SUCCESS != lockdownd_get_device_name(client, &devname)) || !devname) {
78 fprintf(stderr, "ERROR: Could not get device name!\n");
79 ret = -2;
80 }
81
82 lockdownd_client_free(client);
83 iphone_device_free(phone);
84
85 if (ret == 0) {
86 printf("%s\n", devname);
87 }
88
89 if (devname) {
90 free(devname);
91 }
92
93 return ret;
94}
diff --git a/dev/main.c b/dev/iphoneclient.c
index bb5dfdd..bb5dfdd 100644
--- a/dev/main.c
+++ b/dev/iphoneclient.c
diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c
deleted file mode 100644
index 7e275b2..0000000
--- a/dev/iphoneinfo.c
+++ /dev/null
@@ -1,281 +0,0 @@
1/*
2 * iphoneinfo.c
3 * Simple utility to show information about an attached device
4 *
5 * Copyright (c) 2009 Martin Szulecki All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <errno.h>
25#include <stdlib.h>
26
27#include <libiphone/libiphone.h>
28#include <libiphone/lockdown.h>
29
30#define FORMAT_KEY_VALUE 1
31#define FORMAT_XML 2
32
33static const char *domains[] = {
34 "com.apple.disk_usage",
35 "com.apple.mobile.battery",
36/* FIXME: For some reason lockdownd segfaults on this, works sometimes though
37 "com.apple.mobile.debug",. */
38 "com.apple.xcode.developerdomain",
39 "com.apple.international",
40 "com.apple.mobile.mobile_application_usage",
41 "com.apple.mobile.backup",
42 "com.apple.mobile.user_preferences",
43 "com.apple.mobile.sync_data_class",
44 "com.apple.mobile.software_behavior",
45 "com.apple.mobile.iTunes.SQLMusicLibraryPostProcessCommands",
46 "com.apple.iTunes",
47 "com.apple.mobile.iTunes.store",
48 "com.apple.mobile.iTunes",
49 NULL
50};
51
52int is_domain_known(char *domain);
53void print_usage(int argc, char **argv);
54void plist_node_to_string(plist_t *node);
55void plist_children_to_string(plist_t *node);
56
57int main(int argc, char *argv[])
58{
59 lockdownd_client_t client = NULL;
60 iphone_device_t phone = NULL;
61 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
62 int i;
63 int format = FORMAT_KEY_VALUE;
64 char uuid[41];
65 char *domain = NULL;
66 char *key = NULL;
67 char *xml_doc = NULL;
68 uint32_t xml_length;
69 plist_t node = NULL;
70 uuid[0] = 0;
71
72 /* parse cmdline args */
73 for (i = 1; i < argc; i++) {
74 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
75 iphone_set_debug_mask(DBGMASK_ALL);
76 iphone_set_debug_level(1);
77 continue;
78 }
79 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) {
80 i++;
81 if (!argv[i] || (strlen(argv[i]) != 40)) {
82 print_usage(argc, argv);
83 return 0;
84 }
85 strcpy(uuid, argv[i]);
86 continue;
87 }
88 else if (!strcmp(argv[i], "-q") || !strcmp(argv[i], "--domain")) {
89 i++;
90 if (!argv[i] || (strlen(argv[i]) < 4)) {
91 print_usage(argc, argv);
92 return 0;
93 }
94 if (!is_domain_known(argv[i])) {
95 fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", argv[i]);
96 }
97 domain = strdup(argv[i]);
98 continue;
99 }
100 else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--key")) {
101 i++;
102 if (!argv[i] || (strlen(argv[i]) <= 1)) {
103 print_usage(argc, argv);
104 return 0;
105 }
106 key = strdup(argv[i]);
107 continue;
108 }
109 else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) {
110 format = FORMAT_XML;
111 continue;
112 }
113 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
114 print_usage(argc, argv);
115 return 0;
116 }
117 else {
118 print_usage(argc, argv);
119 return 0;
120 }
121 }
122
123 if (uuid[0] != 0) {
124 ret = iphone_get_device_by_uuid(&phone, uuid);
125 if (ret != IPHONE_E_SUCCESS) {
126 printf("No device found with uuid %s, is it plugged in?\n", uuid);
127 return -1;
128 }
129 }
130 else
131 {
132 ret = iphone_get_device(&phone);
133 if (ret != IPHONE_E_SUCCESS) {
134 printf("No device found, is it plugged in?\n");
135 return -1;
136 }
137 }
138
139 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) {
140 iphone_device_free(phone);
141 return -1;
142 }
143
144 /* run query and output information */
145 if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS)
146 {
147 if (plist_get_node_type(node) == PLIST_DICT) {
148 if (plist_get_first_child(node))
149 {
150 switch (format) {
151 case FORMAT_XML:
152 plist_to_xml(node, &xml_doc, &xml_length);
153 printf(xml_doc);
154 free(xml_doc);
155 break;
156 case FORMAT_KEY_VALUE:
157 default:
158 plist_children_to_string(node);
159 break;
160 }
161 }
162 }
163 else if(node && (key != NULL))
164 plist_node_to_string(node);
165 if (node)
166 plist_free(node);
167 node = NULL;
168 }
169
170 if (domain != NULL)
171 free(domain);
172 lockdownd_client_free(client);
173 iphone_device_free(phone);
174
175 return 0;
176}
177
178int is_domain_known(char *domain)
179{
180 int i = 0;
181 while (domains[i] != NULL) {
182 if (strstr(domain, domains[i++])) {
183 return 1;
184 }
185 }
186 return 0;
187}
188
189void print_usage(int argc, char **argv)
190{
191 int i = 0;
192 char *name = NULL;
193
194 name = strrchr(argv[0], '/');
195 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
196 printf("Show information about the first connected iPhone/iPod Touch.\n\n");
197 printf(" -d, --debug\t\tenable communication debugging\n");
198 printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n");
199 printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n");
200 printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n");
201 printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n");
202 printf(" -h, --help\t\tprints usage information\n");
203 printf("\n");
204 printf(" Known domains are:\n\n");
205 while (domains[i] != NULL) {
206 printf(" %s\n", domains[i++]);
207 }
208 printf("\n");
209}
210
211void plist_node_to_string(plist_t *node)
212{
213 char *s = NULL;
214 double d;
215 uint8_t b;
216
217 uint64_t u = 0;
218
219 plist_type t;
220
221 if (!node)
222 return;
223
224 t = plist_get_node_type(node);
225
226 switch (t) {
227 case PLIST_BOOLEAN:
228 plist_get_bool_val(node, &b);
229 printf("%s\n", (b ? "true" : "false"));
230 break;
231
232 case PLIST_UINT:
233 plist_get_uint_val(node, &u);
234 printf("%llu\n", (long long)u);
235 break;
236
237 case PLIST_REAL:
238 plist_get_real_val(node, &d);
239 printf("%f\n", d);
240 break;
241
242 case PLIST_STRING:
243 plist_get_string_val(node, &s);
244 printf("%s\n", s);
245 free(s);
246 break;
247
248 case PLIST_KEY:
249 plist_get_key_val(node, &s);
250 printf("%s: ", s);
251 free(s);
252 break;
253
254 case PLIST_DATA:
255 printf("\n");
256 break;
257 case PLIST_DATE:
258 printf("\n");
259 break;
260 case PLIST_ARRAY:
261 case PLIST_DICT:
262 printf("\n");
263 plist_children_to_string(node);
264 break;
265 default:
266 break;
267 }
268}
269
270void plist_children_to_string(plist_t *node)
271{
272 /* iterate over key/value pairs */
273 for (
274 node = plist_get_first_child(node);
275 node != NULL;
276 node = plist_get_next_sibling(node)
277 ) {
278 plist_node_to_string(node);
279 }
280}
281
diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c
deleted file mode 100644
index a096101..0000000
--- a/dev/syslog_relay.c
+++ /dev/null
@@ -1,169 +0,0 @@
1/*
2 * syslog_relay.c
3 * Relay the syslog of a device to stdout
4 *
5 * Copyright (c) 2009 Martin Szulecki All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <errno.h>
25#include <netinet/in.h>
26#include <signal.h>
27#include <stdlib.h>
28
29#include <libiphone/libiphone.h>
30#include <libiphone/lockdown.h>
31#include <usbmuxd.h>
32
33static int quit_flag = 0;
34
35void print_usage(int argc, char **argv);
36
37/**
38 * signal handler function for cleaning up properly
39 */
40static void clean_exit(int sig)
41{
42 fprintf(stderr, "Exiting...\n");
43 quit_flag++;
44}
45
46int main(int argc, char *argv[])
47{
48 lockdownd_client_t client = NULL;
49 iphone_device_t phone = NULL;
50 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
51 int i;
52 char uuid[41];
53 int port = 0;
54 uuid[0] = 0;
55 uint32_t handle = 0;
56
57 signal(SIGINT, clean_exit);
58 signal(SIGQUIT, clean_exit);
59 signal(SIGTERM, clean_exit);
60 signal(SIGPIPE, SIG_IGN);
61
62 /* parse cmdline args */
63 for (i = 1; i < argc; i++) {
64 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
65 iphone_set_debug_mask(DBGMASK_ALL);
66 iphone_set_debug_level(1);
67 continue;
68 }
69 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) {
70 i++;
71 if (!argv[i] || (strlen(argv[i]) != 40)) {
72 print_usage(argc, argv);
73 return 0;
74 }
75 strcpy(uuid, argv[i]);
76 continue;
77 }
78 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
79 print_usage(argc, argv);
80 return 0;
81 }
82 else {
83 print_usage(argc, argv);
84 return 0;
85 }
86 }
87
88 if (uuid[0] != 0) {
89 ret = iphone_get_device_by_uuid(&phone, uuid);
90 if (ret != IPHONE_E_SUCCESS) {
91 printf("No device found with uuid %s, is it plugged in?\n", uuid);
92 return -1;
93 }
94 }
95 else
96 {
97 ret = iphone_get_device(&phone);
98 if (ret != IPHONE_E_SUCCESS) {
99 printf("No device found, is it plugged in?\n");
100 return -1;
101 }
102 }
103
104 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) {
105 iphone_device_free(phone);
106 return -1;
107 }
108
109 /* start syslog_relay service and retrieve port */
110 ret = lockdownd_start_service(client, "com.apple.syslog_relay", &port);
111 if ((ret == LOCKDOWN_E_SUCCESS) && port) {
112 lockdownd_client_free(client);
113
114 /* connect to socket relay messages */
115 iphone_device_get_handle(phone, &handle);
116 int sfd = usbmuxd_connect(handle, port);
117 if (sfd < 0) {
118 printf("ERROR: Could not open usbmux connection.\n");
119 } else {
120 while (!quit_flag) {
121 char *receive = NULL;
122 uint32_t datalen = 0, bytes = 0, recv_bytes = 0;
123
124 ret = usbmuxd_recv(sfd, (char *) &datalen, sizeof(datalen), &bytes);
125 datalen = ntohl(datalen);
126
127 if (datalen == 0)
128 continue;
129
130 recv_bytes += bytes;
131 receive = (char *) malloc(sizeof(char) * datalen);
132
133 while (!quit_flag && (recv_bytes <= datalen)) {
134 ret = usbmuxd_recv(sfd, receive, datalen, &bytes);
135
136 if (bytes == 0)
137 break;
138
139 recv_bytes += bytes;
140
141 fwrite(receive, sizeof(char), bytes, stdout);
142 }
143
144 free(receive);
145 }
146 }
147 usbmuxd_disconnect(sfd);
148 } else {
149 printf("ERROR: Could not start service com.apple.syslog_relay.\n");
150 }
151
152 iphone_device_free(phone);
153
154 return 0;
155}
156
157void print_usage(int argc, char **argv)
158{
159 char *name = NULL;
160
161 name = strrchr(argv[0], '/');
162 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
163 printf("Relay syslog of a connected iPhone/iPod Touch.\n\n");
164 printf(" -d, --debug\t\tenable communication debugging\n");
165 printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n");
166 printf(" -h, --help\t\tprints usage information\n");
167 printf("\n");
168}
169