diff options
Diffstat (limited to 'dev/housearresttest.c')
-rw-r--r-- | dev/housearresttest.c | 214 |
1 files changed, 0 insertions, 214 deletions
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 | } | ||