summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am2
-rw-r--r--tools/ideviceprovision.c149
2 files changed, 111 insertions, 40 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 8a91234..959bdc4 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -62,7 +62,7 @@ idevicedate_LDADD = $(top_builddir)/src/libimobiledevice.la
62 62
63ideviceprovision_SOURCES = ideviceprovision.c 63ideviceprovision_SOURCES = ideviceprovision.c
64ideviceprovision_CFLAGS = $(AM_CFLAGS) 64ideviceprovision_CFLAGS = $(AM_CFLAGS)
65ideviceprovision_LDFLAGS = $(AM_LDFLAGS) 65ideviceprovision_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS)
66ideviceprovision_LDADD = $(top_builddir)/src/libimobiledevice.la 66ideviceprovision_LDADD = $(top_builddir)/src/libimobiledevice.la
67 67
68idevicedebugserverproxy_SOURCES = idevicedebugserverproxy.c 68idevicedebugserverproxy_SOURCES = idevicedebugserverproxy.c
diff --git a/tools/ideviceprovision.c b/tools/ideviceprovision.c
index 13fd239..82e929d 100644
--- a/tools/ideviceprovision.c
+++ b/tools/ideviceprovision.c
@@ -32,6 +32,7 @@
32#include <libimobiledevice/libimobiledevice.h> 32#include <libimobiledevice/libimobiledevice.h>
33#include <libimobiledevice/lockdown.h> 33#include <libimobiledevice/lockdown.h>
34#include <libimobiledevice/misagent.h> 34#include <libimobiledevice/misagent.h>
35#include "common/utils.h"
35 36
36static void print_usage(int argc, char **argv) 37static void print_usage(int argc, char **argv)
37{ 38{
@@ -47,10 +48,13 @@ static void print_usage(int argc, char **argv)
47 printf(" copy PATH\tRetrieves all provisioning profiles from the device and\n"); 48 printf(" copy PATH\tRetrieves all provisioning profiles from the device and\n");
48 printf(" \tstores them into the existing directory specified by PATH.\n"); 49 printf(" \tstores them into the existing directory specified by PATH.\n");
49 printf(" \tThe files will be stored as UUID.mobileprovision\n"); 50 printf(" \tThe files will be stored as UUID.mobileprovision\n");
50 printf(" remove UUID\tRemoves the provisioning profile identified by UUID.\n\n"); 51 printf(" remove UUID\tRemoves the provisioning profile identified by UUID.\n");
52 printf(" dump FILE\tPrints detailed information about the provisioning profile\n");
53 printf(" \tspecified by FILE.\n\n");
51 printf(" The following OPTIONS are accepted:\n"); 54 printf(" The following OPTIONS are accepted:\n");
52 printf(" -d, --debug enable communication debugging\n"); 55 printf(" -d, --debug enable communication debugging\n");
53 printf(" -u, --udid UDID target specific device by its 40-digit device UDID\n"); 56 printf(" -u, --udid UDID target specific device by its 40-digit device UDID\n");
57 printf(" -x, --xml print XML output when using the 'dump' command\n");
54 printf(" -h, --help prints usage information\n"); 58 printf(" -h, --help prints usage information\n");
55 printf("\n"); 59 printf("\n");
56} 60}
@@ -60,6 +64,7 @@ enum {
60 OP_LIST, 64 OP_LIST,
61 OP_COPY, 65 OP_COPY,
62 OP_REMOVE, 66 OP_REMOVE,
67 OP_DUMP,
63 NUM_OPS 68 NUM_OPS
64}; 69};
65 70
@@ -190,6 +195,52 @@ static plist_t profile_get_embedded_plist(plist_t profile)
190 return pl; 195 return pl;
191} 196}
192 197
198static int profile_read_from_file(const char* path, unsigned char **profile_data, unsigned int *profile_size)
199{
200 FILE* f = fopen(path, "rb");
201 if (!f) {
202 fprintf(stderr, "Could not open file '%s'\n", path);
203 return -1;
204 }
205 fseek(f, 0, SEEK_END);
206 long int size = ftell(f);
207 fseek(f, 0, SEEK_SET);
208
209 if (size >= 0x1000000) {
210 fprintf(stderr, "The file '%s' is too large for processing.\n", path);
211 fclose(f);
212 return -1;
213 }
214
215 unsigned char* buf = malloc(size);
216 if (!buf) {
217 fprintf(stderr, "Could not allocate memory...\n");
218 fclose(f);
219 return -1;
220 }
221
222 long int cur = 0;
223 while (cur < size) {
224 ssize_t r = fread(buf+cur, 1, 512, f);
225 if (r <= 0) {
226 break;
227 }
228 cur += r;
229 }
230 fclose(f);
231
232 if (cur != size) {
233 free(buf);
234 fprintf(stderr, "Could not read in file '%s' (size %ld read %ld)\n", path, size, cur);
235 return -1;
236 }
237
238 *profile_data = buf;
239 *profile_size = (unsigned int)size;
240
241 return 0;
242}
243
193int main(int argc, char *argv[]) 244int main(int argc, char *argv[])
194{ 245{
195 lockdownd_client_t client = NULL; 246 lockdownd_client_t client = NULL;
@@ -198,6 +249,7 @@ int main(int argc, char *argv[])
198 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; 249 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
199 int i; 250 int i;
200 int op = -1; 251 int op = -1;
252 int output_xml = 0;
201 const char* udid = NULL; 253 const char* udid = NULL;
202 const char* param = NULL; 254 const char* param = NULL;
203 255
@@ -249,6 +301,20 @@ int main(int argc, char *argv[])
249 op = OP_REMOVE; 301 op = OP_REMOVE;
250 continue; 302 continue;
251 } 303 }
304 else if (!strcmp(argv[i], "dump")) {
305 i++;
306 if (!argv[i] || (strlen(argv[i]) < 1)) {
307 print_usage(argc, argv);
308 return 0;
309 }
310 param = argv[i];
311 op = OP_DUMP;
312 continue;
313 }
314 else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) {
315 output_xml = 1;
316 continue;
317 }
252 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { 318 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
253 print_usage(argc, argv); 319 print_usage(argc, argv);
254 return 0; 320 return 0;
@@ -264,6 +330,43 @@ int main(int argc, char *argv[])
264 return 0; 330 return 0;
265 } 331 }
266 332
333 if (op == OP_DUMP) {
334 int res = 0;
335 unsigned char* profile_data = NULL;
336 unsigned int profile_size = 0;
337 if (profile_read_from_file(param, &profile_data, &profile_size) != 0) {
338 return -1;
339 }
340 plist_t pdata = plist_new_data((char*)profile_data, profile_size);
341 plist_t pl = profile_get_embedded_plist(pdata);
342 plist_free(pdata);
343 free(profile_data);
344
345 if (pl) {
346 if (output_xml) {
347 char* xml = NULL;
348 uint32_t xlen = 0;
349 plist_to_xml(pl, &xml, &xlen);
350 if (xml) {
351 printf("%s\n", xml);
352 free(xml);
353 }
354 } else {
355 if (pl && (plist_get_node_type(pl) == PLIST_DICT)) {
356 plist_print_to_stream(pl, stdout);
357 } else {
358 fprintf(stderr, "ERROR: unexpected node type in profile plist (not PLIST_DICT)\n");
359 res = -1;
360 }
361 }
362 } else {
363 fprintf(stderr, "ERROR: could not extract embedded plist from profile!\n");
364 }
365 plist_free(pl);
366
367 return res;
368 }
369
267 ret = idevice_new(&device, udid); 370 ret = idevice_new(&device, udid);
268 if (ret != IDEVICE_E_SUCCESS) { 371 if (ret != IDEVICE_E_SUCCESS) {
269 if (udid) { 372 if (udid) {
@@ -304,46 +407,15 @@ int main(int argc, char *argv[])
304 switch (op) { 407 switch (op) {
305 case OP_INSTALL: 408 case OP_INSTALL:
306 { 409 {
307 FILE* f = fopen(param, "rb"); 410 unsigned char* profile_data = NULL;
308 if (!f) { 411 unsigned int profile_size = 0;
309 fprintf(stderr, "Could not open file '%s'\n", param); 412 if (profile_read_from_file(param, &profile_data, &profile_size) != 0) {
310 break;
311 }
312 fseek(f, 0, SEEK_END);
313 long int size = ftell(f);
314 fseek(f, 0, SEEK_SET);
315
316 if (size >= 0x1000000) {
317 fprintf(stderr, "The file '%s' is too large for processing.\n", param);
318 fclose(f);
319 break;
320 }
321
322 char* buf = malloc(size);
323 if (!buf) {
324 fprintf(stderr, "Could not allocate memory...\n");
325 fclose(f);
326 break;
327 }
328
329 long int cur = 0;
330 while (cur < size) {
331 ssize_t r = fread(buf+cur, 1, 512, f);
332 if (r <= 0) {
333 break;
334 }
335 cur += r;
336 }
337 fclose(f);
338
339 if (cur != size) {
340 free(buf);
341 fprintf(stderr, "Could not read in file '%s' (size %ld read %ld)\n", param, size, cur);
342 break; 413 break;
343 } 414 }
344 415
345 uint64_t psize = size; 416 uint64_t psize = profile_size;
346 plist_t pdata = plist_new_data(buf, psize); 417 plist_t pdata = plist_new_data((const char*)profile_data, psize);
418 free(profile_data);
347 419
348 if (misagent_install(mis, pdata) == MISAGENT_E_SUCCESS) { 420 if (misagent_install(mis, pdata) == MISAGENT_E_SUCCESS) {
349 printf("Profile '%s' installed successfully.\n", param); 421 printf("Profile '%s' installed successfully.\n", param);
@@ -351,7 +423,6 @@ int main(int argc, char *argv[])
351 int sc = misagent_get_status_code(mis); 423 int sc = misagent_get_status_code(mis);
352 fprintf(stderr, "Could not install profile '%s', status code: 0x%x\n", param, sc); 424 fprintf(stderr, "Could not install profile '%s', status code: 0x%x\n", param, sc);
353 } 425 }
354 free(buf);
355 } 426 }
356 break; 427 break;
357 case OP_LIST: 428 case OP_LIST: