diff options
| -rw-r--r-- | tools/Makefile.am | 4 | ||||
| -rw-r--r-- | tools/idevicebackup.c | 89 | ||||
| -rw-r--r-- | tools/idevicebackup2.c | 93 |
3 files changed, 4 insertions, 182 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index 5fcd692..5b743f8 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am | |||
| @@ -32,12 +32,12 @@ idevice_id_LDADD = $(top_builddir)/src/libimobiledevice.la | |||
| 32 | 32 | ||
| 33 | idevicebackup_SOURCES = idevicebackup.c | 33 | idevicebackup_SOURCES = idevicebackup.c |
| 34 | idevicebackup_CFLAGS = $(AM_CFLAGS) | 34 | idevicebackup_CFLAGS = $(AM_CFLAGS) |
| 35 | idevicebackup_LDFLAGS = $(AM_LDFLAGS) | 35 | idevicebackup_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS) |
| 36 | idevicebackup_LDADD = $(top_builddir)/src/libimobiledevice.la | 36 | idevicebackup_LDADD = $(top_builddir)/src/libimobiledevice.la |
| 37 | 37 | ||
| 38 | idevicebackup2_SOURCES = idevicebackup2.c | 38 | idevicebackup2_SOURCES = idevicebackup2.c |
| 39 | idevicebackup2_CFLAGS = $(AM_CFLAGS) | 39 | idevicebackup2_CFLAGS = $(AM_CFLAGS) |
| 40 | idevicebackup2_LDFLAGS = $(AM_LDFLAGS) | 40 | idevicebackup2_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS) |
| 41 | idevicebackup2_LDADD = $(top_builddir)/src/libimobiledevice.la | 41 | idevicebackup2_LDADD = $(top_builddir)/src/libimobiledevice.la |
| 42 | 42 | ||
| 43 | ideviceimagemounter_SOURCES = ideviceimagemounter.c | 43 | ideviceimagemounter_SOURCES = ideviceimagemounter.c |
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index e30540e..c126869 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c | |||
| @@ -43,6 +43,7 @@ | |||
| 43 | #include <libimobiledevice/mobilebackup.h> | 43 | #include <libimobiledevice/mobilebackup.h> |
| 44 | #include <libimobiledevice/notification_proxy.h> | 44 | #include <libimobiledevice/notification_proxy.h> |
| 45 | #include <libimobiledevice/afc.h> | 45 | #include <libimobiledevice/afc.h> |
| 46 | #include "common/utils.h" | ||
| 46 | 47 | ||
| 47 | #define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup" | 48 | #define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup" |
| 48 | #define NP_SERVICE_NAME "com.apple.mobile.notification_proxy" | 49 | #define NP_SERVICE_NAME "com.apple.mobile.notification_proxy" |
| @@ -67,11 +68,6 @@ enum cmd_mode { | |||
| 67 | CMD_LEAVE | 68 | CMD_LEAVE |
| 68 | }; | 69 | }; |
| 69 | 70 | ||
| 70 | enum plist_format_t { | ||
| 71 | PLIST_FORMAT_XML, | ||
| 72 | PLIST_FORMAT_BINARY | ||
| 73 | }; | ||
| 74 | |||
| 75 | enum device_link_file_status_t { | 71 | enum device_link_file_status_t { |
| 76 | DEVICE_LINK_FILE_STATUS_NONE = 0, | 72 | DEVICE_LINK_FILE_STATUS_NONE = 0, |
| 77 | DEVICE_LINK_FILE_STATUS_HUNK, | 73 | DEVICE_LINK_FILE_STATUS_HUNK, |
| @@ -353,89 +349,6 @@ static void mobilebackup_info_update_last_backup_date(plist_t info_plist) | |||
| 353 | node = NULL; | 349 | node = NULL; |
| 354 | } | 350 | } |
| 355 | 351 | ||
| 356 | static void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length) | ||
| 357 | { | ||
| 358 | FILE *f; | ||
| 359 | uint64_t size; | ||
| 360 | |||
| 361 | *length = 0; | ||
| 362 | |||
| 363 | f = fopen(filename, "rb"); | ||
| 364 | if (!f) { | ||
| 365 | return; | ||
| 366 | } | ||
| 367 | |||
| 368 | fseek(f, 0, SEEK_END); | ||
| 369 | size = ftell(f); | ||
| 370 | rewind(f); | ||
| 371 | |||
| 372 | if (size == 0) { | ||
| 373 | return; | ||
| 374 | } | ||
| 375 | |||
| 376 | *buffer = (char*)malloc(sizeof(char)*size); | ||
| 377 | fread(*buffer, sizeof(char), size, f); | ||
| 378 | fclose(f); | ||
| 379 | |||
| 380 | *length = size; | ||
| 381 | } | ||
| 382 | |||
| 383 | static void buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length) | ||
| 384 | { | ||
| 385 | FILE *f; | ||
| 386 | |||
| 387 | f = fopen(filename, "ab"); | ||
| 388 | fwrite(buffer, sizeof(char), length, f); | ||
| 389 | fclose(f); | ||
| 390 | } | ||
| 391 | |||
| 392 | static int plist_read_from_filename(plist_t *plist, const char *filename) | ||
| 393 | { | ||
| 394 | char *buffer = NULL; | ||
| 395 | uint64_t length; | ||
| 396 | |||
| 397 | if (!filename) | ||
| 398 | return 0; | ||
| 399 | |||
| 400 | buffer_read_from_filename(filename, &buffer, &length); | ||
| 401 | |||
| 402 | if (!buffer) { | ||
| 403 | return 0; | ||
| 404 | } | ||
| 405 | |||
| 406 | if ((length > 8) && (memcmp(buffer, "bplist00", 8) == 0)) { | ||
| 407 | plist_from_bin(buffer, length, plist); | ||
| 408 | } else { | ||
| 409 | plist_from_xml(buffer, length, plist); | ||
| 410 | } | ||
| 411 | |||
| 412 | free(buffer); | ||
| 413 | |||
| 414 | return 1; | ||
| 415 | } | ||
| 416 | |||
| 417 | static int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format) | ||
| 418 | { | ||
| 419 | char *buffer = NULL; | ||
| 420 | uint32_t length; | ||
| 421 | |||
| 422 | if (!plist || !filename) | ||
| 423 | return 0; | ||
| 424 | |||
| 425 | if (format == PLIST_FORMAT_XML) | ||
| 426 | plist_to_xml(plist, &buffer, &length); | ||
| 427 | else if (format == PLIST_FORMAT_BINARY) | ||
| 428 | plist_to_bin(plist, &buffer, &length); | ||
| 429 | else | ||
| 430 | return 0; | ||
| 431 | |||
| 432 | buffer_write_to_filename(filename, buffer, length); | ||
| 433 | |||
| 434 | free(buffer); | ||
| 435 | |||
| 436 | return 1; | ||
| 437 | } | ||
| 438 | |||
| 439 | static int plist_strcmp(plist_t node, const char *str) | 352 | static int plist_strcmp(plist_t node, const char *str) |
| 440 | { | 353 | { |
| 441 | char *buffer = NULL; | 354 | char *buffer = NULL; |
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index 35d3ccb..2da4971 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c | |||
| @@ -36,6 +36,7 @@ | |||
| 36 | #include <libimobiledevice/mobilebackup2.h> | 36 | #include <libimobiledevice/mobilebackup2.h> |
| 37 | #include <libimobiledevice/notification_proxy.h> | 37 | #include <libimobiledevice/notification_proxy.h> |
| 38 | #include <libimobiledevice/afc.h> | 38 | #include <libimobiledevice/afc.h> |
| 39 | #include "common/utils.h" | ||
| 39 | 40 | ||
| 40 | #include <endianness.h> | 41 | #include <endianness.h> |
| 41 | 42 | ||
| @@ -73,11 +74,6 @@ enum cmd_mode { | |||
| 73 | CMD_CLOUD | 74 | CMD_CLOUD |
| 74 | }; | 75 | }; |
| 75 | 76 | ||
| 76 | enum plist_format_t { | ||
| 77 | PLIST_FORMAT_XML, | ||
| 78 | PLIST_FORMAT_BINARY | ||
| 79 | }; | ||
| 80 | |||
| 81 | enum cmd_flags { | 77 | enum cmd_flags { |
| 82 | CMD_FLAG_RESTORE_SYSTEM_FILES = (1 << 1), | 78 | CMD_FLAG_RESTORE_SYSTEM_FILES = (1 << 1), |
| 83 | CMD_FLAG_RESTORE_REBOOT = (1 << 2), | 79 | CMD_FLAG_RESTORE_REBOOT = (1 << 2), |
| @@ -357,93 +353,6 @@ static plist_t mobilebackup_factory_info_plist_new(const char* udid, lockdownd_c | |||
| 357 | return ret; | 353 | return ret; |
| 358 | } | 354 | } |
| 359 | 355 | ||
| 360 | static void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length) | ||
| 361 | { | ||
| 362 | FILE *f; | ||
| 363 | uint64_t size; | ||
| 364 | |||
| 365 | *length = 0; | ||
| 366 | |||
| 367 | f = fopen(filename, "rb"); | ||
| 368 | if (!f) { | ||
| 369 | return; | ||
| 370 | } | ||
| 371 | |||
| 372 | fseek(f, 0, SEEK_END); | ||
| 373 | size = ftell(f); | ||
| 374 | rewind(f); | ||
| 375 | |||
| 376 | if (size == 0) { | ||
| 377 | return; | ||
| 378 | } | ||
| 379 | |||
| 380 | *buffer = (char*)malloc(sizeof(char)*size); | ||
| 381 | fread(*buffer, sizeof(char), size, f); | ||
| 382 | fclose(f); | ||
| 383 | |||
| 384 | *length = size; | ||
| 385 | } | ||
| 386 | |||
| 387 | static void buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length) | ||
| 388 | { | ||
| 389 | FILE *f; | ||
| 390 | |||
| 391 | f = fopen(filename, "ab"); | ||
| 392 | if (!f) | ||
| 393 | f = fopen(filename, "wb"); | ||
| 394 | if (f) { | ||
| 395 | fwrite(buffer, sizeof(char), length, f); | ||
| 396 | fclose(f); | ||
| 397 | } | ||
| 398 | } | ||
| 399 | |||
| 400 | static int plist_read_from_filename(plist_t *plist, const char *filename) | ||
| 401 | { | ||
| 402 | char *buffer = NULL; | ||
| 403 | uint64_t length; | ||
| 404 | |||
| 405 | if (!filename) | ||
| 406 | return 0; | ||
| 407 | |||
| 408 | buffer_read_from_filename(filename, &buffer, &length); | ||
| 409 | |||
| 410 | if (!buffer) { | ||
| 411 | return 0; | ||
| 412 | } | ||
| 413 | |||
| 414 | if ((length > 8) && (memcmp(buffer, "bplist00", 8) == 0)) { | ||
| 415 | plist_from_bin(buffer, length, plist); | ||
| 416 | } else { | ||
| 417 | plist_from_xml(buffer, length, plist); | ||
| 418 | } | ||
| 419 | |||
| 420 | free(buffer); | ||
| 421 | |||
| 422 | return 1; | ||
| 423 | } | ||
| 424 | |||
| 425 | static int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format) | ||
| 426 | { | ||
| 427 | char *buffer = NULL; | ||
| 428 | uint32_t length; | ||
| 429 | |||
| 430 | if (!plist || !filename) | ||
| 431 | return 0; | ||
| 432 | |||
| 433 | if (format == PLIST_FORMAT_XML) | ||
| 434 | plist_to_xml(plist, &buffer, &length); | ||
| 435 | else if (format == PLIST_FORMAT_BINARY) | ||
| 436 | plist_to_bin(plist, &buffer, &length); | ||
| 437 | else | ||
| 438 | return 0; | ||
| 439 | |||
| 440 | buffer_write_to_filename(filename, buffer, length); | ||
| 441 | |||
| 442 | free(buffer); | ||
| 443 | |||
| 444 | return 1; | ||
| 445 | } | ||
| 446 | |||
| 447 | static int mb2_status_check_snapshot_state(const char *path, const char *udid, const char *matches) | 356 | static int mb2_status_check_snapshot_state(const char *path, const char *udid, const char *matches) |
| 448 | { | 357 | { |
| 449 | int ret = -1; | 358 | int ret = -1; |
