diff options
Diffstat (limited to 'dev')
-rw-r--r-- | dev/Makefile.am | 36 | ||||
-rw-r--r-- | dev/afccheck.c | 146 | ||||
-rw-r--r-- | dev/filerelaytest.c | 108 | ||||
-rw-r--r-- | dev/housearresttest.c | 214 | ||||
-rw-r--r-- | dev/ideviceclient.c | 252 | ||||
-rw-r--r-- | dev/lckdclient.c | 115 |
6 files changed, 0 insertions, 871 deletions
diff --git a/dev/Makefile.am b/dev/Makefile.am deleted file mode 100644 index 72c00a3..0000000 --- a/dev/Makefile.am +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | AM_CPPFLAGS = -I$(top_srcdir)/include | ||
2 | |||
3 | AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) | ||
4 | AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) | ||
5 | |||
6 | if ENABLE_DEVTOOLS | ||
7 | noinst_PROGRAMS = ideviceclient lckd-client afccheck filerelaytest housearresttest | ||
8 | |||
9 | ideviceclient_SOURCES = ideviceclient.c | ||
10 | ideviceclient_CFLAGS = $(AM_CFLAGS) | ||
11 | ideviceclient_LDFLAGS = $(AM_LDFLAGS) | ||
12 | ideviceclient_LDADD = ../src/libimobiledevice.la | ||
13 | |||
14 | lckd_client_SOURCES = lckdclient.c | ||
15 | lckd_client_CFLAGS = $(AM_CFLAGS) | ||
16 | lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS) | ||
17 | lckd_client_LDADD = ../src/libimobiledevice.la | ||
18 | |||
19 | afccheck_SOURCES = afccheck.c | ||
20 | afccheck_CFLAGS = $(AM_CFLAGS) | ||
21 | afccheck_LDFLAGS = $(AM_LDFLAGS) | ||
22 | afccheck_LDADD = ../src/libimobiledevice.la | ||
23 | |||
24 | filerelaytest_SOURCES = filerelaytest.c | ||
25 | filerelaytest_CFLAGS = $(AM_CFLAGS) | ||
26 | filerelaytest_LDFLAGS = $(AM_LDFLAGS) | ||
27 | filerelaytest_LDADD = ../src/libimobiledevice.la | ||
28 | |||
29 | housearresttest_SOURCES = housearresttest.c | ||
30 | housearresttest_CFLAGS = $(AM_CFLAGS) | ||
31 | housearresttest_LDFLAGS = $(AM_LDFLAGS) | ||
32 | housearresttest_LDADD = ../src/libimobiledevice.la | ||
33 | |||
34 | endif # ENABLE_DEVTOOLS | ||
35 | |||
36 | EXTRA_DIST = ideviceclient.c lckdclient.c afccheck.c filerelaytest.c housearresttest.c | ||
diff --git a/dev/afccheck.c b/dev/afccheck.c deleted file mode 100644 index b4d8910..0000000 --- a/dev/afccheck.c +++ /dev/null | |||
@@ -1,146 +0,0 @@ | |||
1 | /* | ||
2 | * afccheck.c | ||
3 | * creates threads and check communication through AFC is done rigth | ||
4 | * | ||
5 | * Copyright (c) 2008 Jonathan Beck 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 <stdlib.h> | ||
23 | #include <stdio.h> | ||
24 | #include <string.h> | ||
25 | #include <glib.h> | ||
26 | |||
27 | #include <libimobiledevice/libimobiledevice.h> | ||
28 | #include <libimobiledevice/lockdown.h> | ||
29 | #include <libimobiledevice/afc.h> | ||
30 | |||
31 | #define BUFFER_SIZE 20000 | ||
32 | #define NB_THREADS 10 | ||
33 | |||
34 | |||
35 | typedef struct { | ||
36 | afc_client_t afc; | ||
37 | int id; | ||
38 | } param; | ||
39 | |||
40 | |||
41 | static void check_afc(gpointer data) | ||
42 | { | ||
43 | //prepare a buffer | ||
44 | unsigned int buffersize = BUFFER_SIZE * sizeof(unsigned int); | ||
45 | int *buf = (int *) malloc(buffersize); | ||
46 | int *buf2 = (int *) malloc(buffersize); | ||
47 | unsigned int bytes = 0; | ||
48 | uint64_t position = 0; | ||
49 | |||
50 | //fill buffer | ||
51 | int i = 0; | ||
52 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
53 | buf[i] = ((param *) data)->id * i; | ||
54 | } | ||
55 | |||
56 | //now writes buffer on device | ||
57 | uint64_t file = 0; | ||
58 | char path[50]; | ||
59 | sprintf(path, "/Buf%i", ((param *) data)->id); | ||
60 | afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RW, &file); | ||
61 | afc_file_write(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); | ||
62 | afc_file_close(((param *) data)->afc, file); | ||
63 | file = 0; | ||
64 | if (bytes != buffersize) | ||
65 | printf("Write operation failed\n"); | ||
66 | |||
67 | //now read it | ||
68 | bytes = 0; | ||
69 | afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); | ||
70 | afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize/2, &bytes); | ||
71 | afc_file_read(((param *) data)->afc, file, (char *) buf2 + (buffersize/2), buffersize/2, &bytes); | ||
72 | if(AFC_E_SUCCESS != afc_file_tell(((param *) data)->afc, file, &position)) | ||
73 | printf("Tell operation failed\n"); | ||
74 | afc_file_close(((param *) data)->afc, file); | ||
75 | if (position != buffersize) | ||
76 | printf("Read operation failed\n"); | ||
77 | |||
78 | //compare buffers | ||
79 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
80 | if (buf[i] != buf2[i]) { | ||
81 | printf("Buffers are differents, stream corrupted\n"); | ||
82 | break; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | //cleanup | ||
87 | afc_remove_path(((param *) data)->afc, path); | ||
88 | g_thread_exit(0); | ||
89 | } | ||
90 | |||
91 | int main(int argc, char *argv[]) | ||
92 | { | ||
93 | lockdownd_client_t client = NULL; | ||
94 | idevice_t phone = NULL; | ||
95 | GError *err; | ||
96 | uint16_t port = 0; | ||
97 | afc_client_t afc = NULL; | ||
98 | |||
99 | if (argc > 1 && !strcasecmp(argv[1], "--debug")) { | ||
100 | idevice_set_debug_level(1); | ||
101 | } else { | ||
102 | idevice_set_debug_level(0); | ||
103 | } | ||
104 | |||
105 | if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) { | ||
106 | printf("No device found, is it plugged in?\n"); | ||
107 | return 1; | ||
108 | } | ||
109 | |||
110 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "afccheck")) { | ||
111 | idevice_free(phone); | ||
112 | return 1; | ||
113 | } | ||
114 | |||
115 | if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &port) && !port) { | ||
116 | lockdownd_client_free(client); | ||
117 | idevice_free(phone); | ||
118 | fprintf(stderr, "Something went wrong when starting AFC."); | ||
119 | return 1; | ||
120 | } | ||
121 | |||
122 | afc_client_new(phone, port, &afc); | ||
123 | |||
124 | //makes sure thread environment is available | ||
125 | if (!g_thread_supported()) | ||
126 | g_thread_init(NULL); | ||
127 | |||
128 | GThread *threads[NB_THREADS]; | ||
129 | param data[NB_THREADS]; | ||
130 | |||
131 | int i = 0; | ||
132 | for (i = 0; i < NB_THREADS; i++) { | ||
133 | data[i].afc = afc; | ||
134 | data[i].id = i + 1; | ||
135 | threads[i] = g_thread_create((GThreadFunc) check_afc, data + i, TRUE, &err); | ||
136 | } | ||
137 | |||
138 | for (i = 0; i < NB_THREADS; i++) { | ||
139 | g_thread_join(threads[i]); | ||
140 | } | ||
141 | |||
142 | lockdownd_client_free(client); | ||
143 | idevice_free(phone); | ||
144 | |||
145 | return 0; | ||
146 | } | ||
diff --git a/dev/filerelaytest.c b/dev/filerelaytest.c deleted file mode 100644 index 6e611c0..0000000 --- a/dev/filerelaytest.c +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /* | ||
2 | * filerelaytest.c | ||
3 | * Simple Test program showing the usage of the file_relay interface. | ||
4 | * | ||
5 | * Copyright (c) 2010 Nikias Bassen 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 | #include <stdio.h> | ||
22 | #include <libimobiledevice/libimobiledevice.h> | ||
23 | #include <libimobiledevice/lockdown.h> | ||
24 | #include <libimobiledevice/file_relay.h> | ||
25 | |||
26 | int main(int argc, char **argv) | ||
27 | { | ||
28 | idevice_t dev = NULL; | ||
29 | lockdownd_client_t client = NULL; | ||
30 | file_relay_client_t frc = NULL; | ||
31 | |||
32 | if (idevice_new(&dev, NULL) != IDEVICE_E_SUCCESS) { | ||
33 | printf("no device connected?!\n"); | ||
34 | goto leave_cleanup; | ||
35 | } | ||
36 | |||
37 | printf("connecting...\n"); | ||
38 | if (lockdownd_client_new_with_handshake(dev, &client, NULL) != LOCKDOWN_E_SUCCESS) { | ||
39 | printf("could not connect to lockdownd!\n"); | ||
40 | goto leave_cleanup; | ||
41 | } | ||
42 | |||
43 | uint16_t port = 0; | ||
44 | if (lockdownd_start_service(client, "com.apple.mobile.file_relay", &port) != LOCKDOWN_E_SUCCESS) { | ||
45 | printf("could not start file_relay service!\n"); | ||
46 | goto leave_cleanup; | ||
47 | } | ||
48 | |||
49 | if (client) { | ||
50 | lockdownd_client_free(client); | ||
51 | client = NULL; | ||
52 | } | ||
53 | |||
54 | if (file_relay_client_new(dev, port, &frc) != FILE_RELAY_E_SUCCESS) { | ||
55 | printf("could not connect to file_relay service!\n"); | ||
56 | goto leave_cleanup; | ||
57 | } | ||
58 | |||
59 | idevice_connection_t dump = NULL; | ||
60 | const char *sources[] = {"AppleSupport", "Network", "VPN", "WiFi", "UserDatabases", "CrashReporter", "tmp", "SystemConfiguration", NULL}; | ||
61 | |||
62 | printf("Requesting"); | ||
63 | int i = 0; | ||
64 | while (sources[i]) { | ||
65 | printf(" %s", sources[i]); | ||
66 | i++; | ||
67 | } | ||
68 | printf("\n"); | ||
69 | |||
70 | if (file_relay_request_sources(frc, sources, &dump) != FILE_RELAY_E_SUCCESS) { | ||
71 | printf("could not get sources\n"); | ||
72 | goto leave_cleanup; | ||
73 | } | ||
74 | |||
75 | if (!dump) { | ||
76 | printf("did not get connection!\n"); | ||
77 | goto leave_cleanup; | ||
78 | } | ||
79 | |||
80 | uint32_t cnt = 0; | ||
81 | uint32_t len = 0; | ||
82 | char buf[4096]; | ||
83 | FILE *f = fopen("dump.cpio.gz", "w"); | ||
84 | setbuf(stdout, NULL); | ||
85 | printf("receiving "); | ||
86 | while (idevice_connection_receive(dump, buf, 4096, &len) == IDEVICE_E_SUCCESS) { | ||
87 | fwrite(buf, 1, len, f); | ||
88 | cnt += len; | ||
89 | printf("."); | ||
90 | len = 0; | ||
91 | } | ||
92 | printf("\n"); | ||
93 | fclose(f); | ||
94 | printf("total size received: %d\n", cnt); | ||
95 | |||
96 | leave_cleanup: | ||
97 | if (frc) { | ||
98 | file_relay_client_free(frc); | ||
99 | } | ||
100 | if (client) { | ||
101 | lockdownd_client_free(client); | ||
102 | } | ||
103 | if (dev) { | ||
104 | idevice_free(dev); | ||
105 | } | ||
106 | |||
107 | return 0; | ||
108 | } | ||
diff --git a/dev/housearresttest.c b/dev/housearresttest.c deleted file mode 100644 index 7282a8c..0000000 --- a/dev/housearresttest.c +++ /dev/null | |||
@@ -1,214 +0,0 @@ | |||
1 | /* | ||
2 | * housearresttest.c | ||
3 | * Simple Test program showing the usage of the house_arrest interface. | ||
4 | * | ||
5 | * Copyright (c) 2010 Nikias Bassen 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 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | |||
25 | #include <libimobiledevice/libimobiledevice.h> | ||
26 | #include <libimobiledevice/lockdown.h> | ||
27 | #include <libimobiledevice/house_arrest.h> | ||
28 | #include <libimobiledevice/afc.h> | ||
29 | |||
30 | static void print_usage(int argc, char **argv) | ||
31 | { | ||
32 | char *name = NULL; | ||
33 | |||
34 | name = strrchr(argv[0], '/'); | ||
35 | printf("Usage: %s [OPTIONS] APPID\n", (name ? name + 1: argv[0])); | ||
36 | printf("Test the house_arrest service.\n\n"); | ||
37 | printf(" -d, --debug\t\tenable communication debugging\n"); | ||
38 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); | ||
39 | printf(" -t, --test\t\ttest creating, writing, and deleting a file\n"); | ||
40 | printf(" -h, --help\t\tprints usage information\n"); | ||
41 | printf("\n"); | ||
42 | } | ||
43 | |||
44 | int main(int argc, char **argv) | ||
45 | { | ||
46 | idevice_t dev = NULL; | ||
47 | lockdownd_client_t client = NULL; | ||
48 | house_arrest_client_t hac = NULL; | ||
49 | house_arrest_error_t res; | ||
50 | int i; | ||
51 | char *uuid = NULL; | ||
52 | const char *appid = NULL; | ||
53 | int test_file_io = 0; | ||
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], "--uuid")) { | ||
62 | i++; | ||
63 | if (!argv[i] || (strlen(argv[i]) != 40)) { | ||
64 | print_usage(argc, argv); | ||
65 | return 0; | ||
66 | } | ||
67 | uuid = strdup(argv[i]); | ||
68 | continue; | ||
69 | } | ||
70 | else if (!strcmp(argv[i], "-t") || !strcmp(argv[i], "--test")) { | ||
71 | test_file_io = 1; | ||
72 | continue; | ||
73 | } | ||
74 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | ||
75 | print_usage(argc, argv); | ||
76 | return 0; | ||
77 | } | ||
78 | else { | ||
79 | appid = argv[i]; | ||
80 | break; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | if (!appid) { | ||
85 | print_usage(argc, argv); | ||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | if (idevice_new(&dev, uuid) != IDEVICE_E_SUCCESS) { | ||
90 | printf("no device connected?!\n"); | ||
91 | goto leave_cleanup; | ||
92 | } | ||
93 | |||
94 | if (lockdownd_client_new_with_handshake(dev, &client, NULL) != LOCKDOWN_E_SUCCESS) { | ||
95 | printf("could not connect to lockdownd!\n"); | ||
96 | goto leave_cleanup; | ||
97 | } | ||
98 | |||
99 | uint16_t port = 0; | ||
100 | if (lockdownd_start_service(client, "com.apple.mobile.house_arrest", &port) != LOCKDOWN_E_SUCCESS) { | ||
101 | printf("could not start house_arrest service!\n"); | ||
102 | goto leave_cleanup; | ||
103 | } | ||
104 | |||
105 | if (client) { | ||
106 | lockdownd_client_free(client); | ||
107 | client = NULL; | ||
108 | } | ||
109 | |||
110 | if (house_arrest_client_new(dev, port, &hac) != HOUSE_ARREST_E_SUCCESS) { | ||
111 | printf("could not connect to house_arrest service!\n"); | ||
112 | goto leave_cleanup; | ||
113 | } | ||
114 | |||
115 | res = house_arrest_send_command(hac, "VendDocuments", appid); | ||
116 | if (res != HOUSE_ARREST_E_SUCCESS) { | ||
117 | printf("error %d when trying to get VendDocuments\n", res); | ||
118 | goto leave_cleanup; | ||
119 | } | ||
120 | |||
121 | plist_t dict = NULL; | ||
122 | if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) { | ||
123 | if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) { | ||
124 | printf("hmmm....\n"); | ||
125 | goto leave_cleanup; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | plist_t node = plist_dict_get_item(dict, "Error"); | ||
130 | if (node) { | ||
131 | char *str = NULL; | ||
132 | plist_get_string_val(node, &str); | ||
133 | printf("Error: %s\n", str); | ||
134 | if (str) free(str); | ||
135 | plist_free(dict); | ||
136 | dict = NULL; | ||
137 | goto leave_cleanup; | ||
138 | } | ||
139 | node = plist_dict_get_item(dict, "Status"); | ||
140 | if (node) { | ||
141 | char *str = NULL; | ||
142 | plist_get_string_val(node, &str); | ||
143 | if (str && (strcmp(str, "Complete") != 0)) { | ||
144 | printf("Warning: Status is not 'Complete' but '%s'\n", str); | ||
145 | } | ||
146 | if (str) free(str); | ||
147 | plist_free(dict); | ||
148 | dict = NULL; | ||
149 | } | ||
150 | if (dict) { | ||
151 | plist_free(dict); | ||
152 | } | ||
153 | |||
154 | afc_client_t afc = NULL; | ||
155 | afc_error_t ae = afc_client_new_from_house_arrest_client(hac, &afc); | ||
156 | if (ae != AFC_E_SUCCESS) { | ||
157 | printf("afc error %d\n", ae); | ||
158 | } | ||
159 | if (ae == AFC_E_SUCCESS) { | ||
160 | char **list = NULL; | ||
161 | afc_read_directory(afc, "/", &list); | ||
162 | printf("Directory contents:\n"); | ||
163 | if (list) { | ||
164 | while (list[0]) { | ||
165 | if (strcmp(list[0], ".") && strcmp(list[0], "..")) { | ||
166 | puts(list[0]); | ||
167 | } | ||
168 | list++; | ||
169 | } | ||
170 | } | ||
171 | |||
172 | if (test_file_io) { | ||
173 | uint64_t tf = 0; | ||
174 | printf("\n==== Performing file tests ====\n"); | ||
175 | printf("Opening file 'foobar' for writing: "); | ||
176 | if (afc_file_open(afc, "/foobar", AFC_FOPEN_RW, &tf) == AFC_E_SUCCESS) { | ||
177 | uint32_t wb = 0; | ||
178 | printf("OK\n"); | ||
179 | |||
180 | printf("Writing to file: "); | ||
181 | if (afc_file_write(afc, tf, "test\r\n", 6, &wb) != AFC_E_SUCCESS) { | ||
182 | printf("ERROR\n"); | ||
183 | } else { | ||
184 | printf("OK\n"); | ||
185 | } | ||
186 | afc_file_close(afc, tf); | ||
187 | printf("Deleting file 'foobar': "); | ||
188 | if (afc_remove_path(afc, "/foobar") == AFC_E_SUCCESS) { | ||
189 | printf("OK\n"); | ||
190 | } else { | ||
191 | printf("ERROR\n"); | ||
192 | } | ||
193 | } else { | ||
194 | printf("ERROR\n"); | ||
195 | } | ||
196 | } | ||
197 | afc_client_free(afc); | ||
198 | } else { | ||
199 | printf("failed to connect to afc service, error %d\n", ae); | ||
200 | } | ||
201 | |||
202 | leave_cleanup: | ||
203 | if (hac) { | ||
204 | house_arrest_client_free(hac); | ||
205 | } | ||
206 | if (client) { | ||
207 | lockdownd_client_free(client); | ||
208 | } | ||
209 | if (dev) { | ||
210 | idevice_free(dev); | ||
211 | } | ||
212 | |||
213 | return 0; | ||
214 | } | ||
diff --git a/dev/ideviceclient.c b/dev/ideviceclient.c deleted file mode 100644 index d952594..0000000 --- a/dev/ideviceclient.c +++ /dev/null | |||
@@ -1,252 +0,0 @@ | |||
1 | /* | ||
2 | * main.c | ||
3 | * Test program for testing several services. | ||
4 | * | ||
5 | * Copyright (c) 2008 Zach C. 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 <stdlib.h> | ||
24 | #include <string.h> | ||
25 | #include <errno.h> | ||
26 | #include <glib.h> | ||
27 | |||
28 | #include <libimobiledevice/libimobiledevice.h> | ||
29 | #include <libimobiledevice/lockdown.h> | ||
30 | #include <libimobiledevice/afc.h> | ||
31 | #include <libimobiledevice/notification_proxy.h> | ||
32 | |||
33 | static void notifier(const char *notification, void *userdata) | ||
34 | { | ||
35 | printf("---------------------------------------------------------\n"); | ||
36 | printf("------> Notification received: %s\n", notification); | ||
37 | printf("---------------------------------------------------------\n"); | ||
38 | } | ||
39 | |||
40 | static void perform_notification(idevice_t phone, lockdownd_client_t client, const char *notification) | ||
41 | { | ||
42 | uint16_t nport = 0; | ||
43 | np_client_t np; | ||
44 | |||
45 | lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); | ||
46 | if (nport) { | ||
47 | printf("::::::::::::::: np was started ::::::::::::\n"); | ||
48 | np_client_new(phone, nport, &np); | ||
49 | if (np) { | ||
50 | printf("::::::::: PostNotification %s\n", notification); | ||
51 | np_post_notification(np, notification); | ||
52 | np_client_free(np); | ||
53 | } | ||
54 | } else { | ||
55 | printf("::::::::::::::: np was NOT started ::::::::::::\n"); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | int main(int argc, char *argv[]) | ||
60 | { | ||
61 | unsigned int bytes = 0; | ||
62 | uint16_t port = 0, i = 0; | ||
63 | uint16_t npp; | ||
64 | lockdownd_client_t client = NULL; | ||
65 | idevice_t phone = NULL; | ||
66 | uint64_t lockfile = 0; | ||
67 | np_client_t gnp = NULL; | ||
68 | |||
69 | if (argc > 1 && !strcasecmp(argv[1], "--debug")) { | ||
70 | idevice_set_debug_level(1); | ||
71 | } else { | ||
72 | idevice_set_debug_level(0); | ||
73 | } | ||
74 | |||
75 | if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) { | ||
76 | printf("No device found, is it plugged in?\n"); | ||
77 | return -1; | ||
78 | } | ||
79 | |||
80 | char *uuid = NULL; | ||
81 | if (IDEVICE_E_SUCCESS == idevice_get_uuid(phone, &uuid)) { | ||
82 | printf("DeviceUniqueID : %s\n", uuid); | ||
83 | } | ||
84 | if (uuid) | ||
85 | free(uuid); | ||
86 | |||
87 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "ideviceclient")) { | ||
88 | idevice_free(phone); | ||
89 | printf("Exiting.\n"); | ||
90 | return -1; | ||
91 | } | ||
92 | |||
93 | char *nnn = NULL; | ||
94 | if (LOCKDOWN_E_SUCCESS == lockdownd_get_device_name(client, &nnn)) { | ||
95 | printf("DeviceName : %s\n", nnn); | ||
96 | free(nnn); | ||
97 | } | ||
98 | |||
99 | lockdownd_start_service(client, "com.apple.afc", &port); | ||
100 | |||
101 | if (port) { | ||
102 | afc_client_t afc = NULL; | ||
103 | afc_client_new(phone, port, &afc); | ||
104 | if (afc) { | ||
105 | lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); | ||
106 | if (npp) { | ||
107 | printf("Notification Proxy started.\n"); | ||
108 | np_client_new(phone, npp, &gnp); | ||
109 | } else { | ||
110 | printf("ERROR: Notification proxy could not be started.\n"); | ||
111 | } | ||
112 | if (gnp) { | ||
113 | const char *nspec[5] = { | ||
114 | NP_SYNC_CANCEL_REQUEST, | ||
115 | NP_SYNC_SUSPEND_REQUEST, | ||
116 | NP_SYNC_RESUME_REQUEST, | ||
117 | NP_ITDBPREP_DID_END, | ||
118 | NULL | ||
119 | }; | ||
120 | np_observe_notifications(gnp, nspec); | ||
121 | np_set_notify_callback(gnp, notifier, NULL); | ||
122 | } | ||
123 | |||
124 | perform_notification(phone, client, NP_SYNC_WILL_START); | ||
125 | |||
126 | afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); | ||
127 | if (lockfile) { | ||
128 | printf("locking file\n"); | ||
129 | afc_file_lock(afc, lockfile, AFC_LOCK_EX); | ||
130 | |||
131 | perform_notification(phone, client, NP_SYNC_DID_START); | ||
132 | } | ||
133 | |||
134 | char **dirs = NULL; | ||
135 | afc_read_directory(afc, "/eafaedf", &dirs); | ||
136 | if (!dirs) | ||
137 | afc_read_directory(afc, "/", &dirs); | ||
138 | printf("Directory time.\n"); | ||
139 | for (i = 0; dirs[i]; i++) { | ||
140 | printf("/%s\n", dirs[i]); | ||
141 | } | ||
142 | |||
143 | g_strfreev(dirs); | ||
144 | |||
145 | dirs = NULL; | ||
146 | afc_get_device_info(afc, &dirs); | ||
147 | if (dirs) { | ||
148 | for (i = 0; dirs[i]; i += 2) { | ||
149 | printf("%s: %s\n", dirs[i], dirs[i + 1]); | ||
150 | } | ||
151 | } | ||
152 | g_strfreev(dirs); | ||
153 | |||
154 | uint64_t my_file = 0; | ||
155 | char **info = NULL; | ||
156 | uint64_t fsize = 0; | ||
157 | if (AFC_E_SUCCESS == afc_get_file_info(afc, "/readme.libimobiledevice.fx", &info) && info) { | ||
158 | for (i = 0; info[i]; i += 2) { | ||
159 | printf("%s: %s\n", info[i], info[i+1]); | ||
160 | if (!strcmp(info[i], "st_size")) { | ||
161 | fsize = atoll(info[i+1]); | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | |||
166 | if (AFC_E_SUCCESS == | ||
167 | afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { | ||
168 | printf("A file size: %llu\n", (long long)fsize); | ||
169 | char *file_data = (char *) malloc(sizeof(char) * fsize); | ||
170 | afc_file_read(afc, my_file, file_data, fsize, &bytes); | ||
171 | if (bytes > 0) { | ||
172 | printf("The file's data:\n"); | ||
173 | fwrite(file_data, 1, bytes, stdout); | ||
174 | } | ||
175 | printf("\nClosing my file.\n"); | ||
176 | afc_file_close(afc, my_file); | ||
177 | free(file_data); | ||
178 | } else | ||
179 | printf("couldn't open a file\n"); | ||
180 | |||
181 | afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_WR, &my_file); | ||
182 | if (my_file) { | ||
183 | char *outdatafile = strdup("this is a bitchin text file\n"); | ||
184 | afc_file_write(afc, my_file, outdatafile, strlen(outdatafile), &bytes); | ||
185 | free(outdatafile); | ||
186 | if (bytes > 0) | ||
187 | printf("Wrote a surprise. ;)\n"); | ||
188 | else | ||
189 | printf("I wanted to write a surprise, but... :(\n"); | ||
190 | afc_file_close(afc, my_file); | ||
191 | } | ||
192 | printf("Deleting a file...\n"); | ||
193 | bytes = afc_remove_path(afc, "/delme"); | ||
194 | if (bytes) | ||
195 | printf("Success.\n"); | ||
196 | else | ||
197 | printf("Failure. (expected unless you have a /delme file on your phone)\n"); | ||
198 | |||
199 | printf("Renaming a file...\n"); | ||
200 | bytes = afc_rename_path(afc, "/renme", "/renme2"); | ||
201 | if (bytes > 0) | ||
202 | printf("Success.\n"); | ||
203 | else | ||
204 | printf("Failure. (expected unless you have a /renme file on your phone)\n"); | ||
205 | |||
206 | printf("Seek & read\n"); | ||
207 | afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_RDONLY, &my_file); | ||
208 | if (AFC_E_SUCCESS != afc_file_seek(afc, my_file, 5, SEEK_CUR)) | ||
209 | printf("WARN: SEEK DID NOT WORK\n"); | ||
210 | char *threeletterword = (char *) malloc(sizeof(char) * 5); | ||
211 | afc_file_read(afc, my_file, threeletterword, 3, &bytes); | ||
212 | threeletterword[3] = '\0'; | ||
213 | if (bytes > 0) | ||
214 | printf("Result: %s\n", threeletterword); | ||
215 | else | ||
216 | printf("Couldn't read!\n"); | ||
217 | free(threeletterword); | ||
218 | afc_file_close(afc, my_file); | ||
219 | } | ||
220 | |||
221 | if (gnp && lockfile) { | ||
222 | printf("XXX sleeping\n"); | ||
223 | sleep(5); | ||
224 | |||
225 | printf("XXX unlocking file\n"); | ||
226 | afc_file_lock(afc, lockfile, AFC_LOCK_UN); | ||
227 | |||
228 | printf("XXX closing file\n"); | ||
229 | afc_file_close(afc, lockfile); | ||
230 | |||
231 | printf("XXX sleeping\n"); | ||
232 | sleep(5); | ||
233 | //perform_notification(phone, client, NP_SYNC_DID_FINISH); | ||
234 | } | ||
235 | |||
236 | if (gnp) { | ||
237 | np_client_free(gnp); | ||
238 | gnp = NULL; | ||
239 | } | ||
240 | |||
241 | afc_client_free(afc); | ||
242 | } else { | ||
243 | printf("Start service failure.\n"); | ||
244 | } | ||
245 | |||
246 | printf("All done.\n"); | ||
247 | |||
248 | lockdownd_client_free(client); | ||
249 | idevice_free(phone); | ||
250 | |||
251 | return 0; | ||
252 | } | ||
diff --git a/dev/lckdclient.c b/dev/lckdclient.c deleted file mode 100644 index 773de9f..0000000 --- a/dev/lckdclient.c +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | /* | ||
2 | * lckdclient.c | ||
3 | * Rudimentary command line interface to the Lockdown protocol | ||
4 | * | ||
5 | * Copyright (c) 2008 Jonathan Beck 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 <stdlib.h> | ||
24 | #include <string.h> | ||
25 | #include <glib.h> | ||
26 | #include <readline/readline.h> | ||
27 | #include <readline/history.h> | ||
28 | |||
29 | #include <libimobiledevice/libimobiledevice.h> | ||
30 | #include <libimobiledevice/lockdown.h> | ||
31 | |||
32 | int main(int argc, char *argv[]) | ||
33 | { | ||
34 | lockdownd_client_t client = NULL; | ||
35 | idevice_t phone = NULL; | ||
36 | |||
37 | idevice_set_debug_level(1); | ||
38 | |||
39 | if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) { | ||
40 | printf("No device found, is it plugged in?\n"); | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | char *uuid = NULL; | ||
45 | if (IDEVICE_E_SUCCESS == idevice_get_uuid(phone, &uuid)) { | ||
46 | printf("DeviceUniqueID : %s\n", uuid); | ||
47 | } | ||
48 | if (uuid) | ||
49 | free(uuid); | ||
50 | |||
51 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "lckdclient")) { | ||
52 | idevice_free(phone); | ||
53 | return -1; | ||
54 | } | ||
55 | |||
56 | using_history(); | ||
57 | int loop = TRUE; | ||
58 | while (loop) { | ||
59 | char *cmd = readline("> "); | ||
60 | if (cmd) { | ||
61 | |||
62 | gchar **args = g_strsplit(cmd, " ", 0); | ||
63 | |||
64 | int len = 0; | ||
65 | if (args) { | ||
66 | while (*(args + len)) { | ||
67 | g_strstrip(*(args + len)); | ||
68 | len++; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | if (len > 0) { | ||
73 | add_history(cmd); | ||
74 | if (!strcmp(*args, "quit")) | ||
75 | loop = FALSE; | ||
76 | |||
77 | if (!strcmp(*args, "get") && len >= 2) { | ||
78 | plist_t value = NULL; | ||
79 | if (LOCKDOWN_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL, len == 3 ? *(args + 2):*(args + 1), &value)) | ||
80 | { | ||
81 | char *xml = NULL; | ||
82 | uint32_t length; | ||
83 | plist_to_xml(value, &xml, &length); | ||
84 | printf("Success : value = %s\n", xml); | ||
85 | free(xml); | ||
86 | } | ||
87 | else | ||
88 | printf("Error\n"); | ||
89 | |||
90 | if (value) | ||
91 | plist_free(value); | ||
92 | } | ||
93 | |||
94 | if (!strcmp(*args, "start") && len == 2) { | ||
95 | uint16_t port = 0; | ||
96 | if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &port)) { | ||
97 | printf("started service %s on port %i\n", *(args + 1), port); | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | printf("failed to start service %s on device.\n", *(args + 1)); | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | g_strfreev(args); | ||
106 | } | ||
107 | free(cmd); | ||
108 | cmd = NULL; | ||
109 | } | ||
110 | clear_history(); | ||
111 | lockdownd_client_free(client); | ||
112 | idevice_free(phone); | ||
113 | |||
114 | return 0; | ||
115 | } | ||