summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/idevicebackup.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index d7d7d1c..a8b37d9 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -150,17 +150,26 @@ static void buffer_read_from_filename(const char *filename, char **buffer, uint3
150 FILE *f; 150 FILE *f;
151 uint64_t size; 151 uint64_t size;
152 152
153 *length = 0;
154
153 f = fopen(filename, "rb"); 155 f = fopen(filename, "rb");
156 if (!f) {
157 return;
158 }
154 159
155 fseek(f, 0, SEEK_END); 160 fseek(f, 0, SEEK_END);
156 size = ftell(f); 161 size = ftell(f);
157 rewind(f); 162 rewind(f);
158 163
164 if (size == 0) {
165 return;
166 }
167
159 *buffer = (char*)malloc(sizeof(char)*size); 168 *buffer = (char*)malloc(sizeof(char)*size);
160 fread(*buffer, sizeof(char), size, f); 169 fread(*buffer, sizeof(char), size, f);
161 fclose(f); 170 fclose(f);
162 171
163 *length = size; 172 *length = (uint32_t)size;
164} 173}
165 174
166static void buffer_write_to_filename(const char *filename, const char *buffer, uint32_t length) 175static void buffer_write_to_filename(const char *filename, const char *buffer, uint32_t length)
@@ -186,7 +195,7 @@ static int plist_read_from_filename(plist_t *plist, const char *filename)
186 return 0; 195 return 0;
187 } 196 }
188 197
189 if (memcmp(buffer, "bplist00", 8) == 0) { 198 if ((length > 8) && (memcmp(buffer, "bplist00", 8) == 0)) {
190 plist_from_bin(buffer, length, plist); 199 plist_from_bin(buffer, length, plist);
191 } else { 200 } else {
192 plist_from_xml(buffer, length, plist); 201 plist_from_xml(buffer, length, plist);
@@ -553,7 +562,11 @@ int main(int argc, char *argv[])
553 printf("Reading Info.plist from backup.\n"); 562 printf("Reading Info.plist from backup.\n");
554 plist_read_from_filename(&info_plist, info_path); 563 plist_read_from_filename(&info_plist, info_path);
555 564
556 if (cmd == CMD_BACKUP) { 565 if (!info_plist) {
566 printf("Could not read Info.plist\n");
567 is_full_backup = 1;
568 }
569 if (info_plist && (cmd == CMD_BACKUP)) {
557 if (mobilebackup_info_is_current_device(info_plist)) { 570 if (mobilebackup_info_is_current_device(info_plist)) {
558 /* update the last backup time within Info.plist */ 571 /* update the last backup time within Info.plist */
559 mobilebackup_info_update_last_backup_date(info_plist); 572 mobilebackup_info_update_last_backup_date(info_plist);
@@ -587,16 +600,6 @@ int main(int argc, char *argv[])
587 /* TODO: check domain com.apple.mobile.backup key RequiresEncrypt and WillEncrypt with lockdown */ 600 /* TODO: check domain com.apple.mobile.backup key RequiresEncrypt and WillEncrypt with lockdown */
588 /* TODO: verify battery on AC enough battery remaining */ 601 /* TODO: verify battery on AC enough battery remaining */
589 602
590 /* Info.plist (Device infos, IC-Info.sidb, photos, app_ids, iTunesPrefs) */
591 /* create new Info.plist on new backups */
592 if (is_full_backup) {
593 printf("Creating Info.plist for new backup.\n");
594 info_plist = mobilebackup_factory_info_plist_new();
595 plist_write_to_filename(info_plist, info_path, PLIST_FORMAT_XML);
596 }
597
598 g_free(info_path);
599
600 /* Manifest.plist (backup manifest (backup state)) */ 603 /* Manifest.plist (backup manifest (backup state)) */
601 char *manifest_path = mobilebackup_build_path(backup_directory, "Manifest", ".plist"); 604 char *manifest_path = mobilebackup_build_path(backup_directory, "Manifest", ".plist");
602 605
@@ -604,7 +607,26 @@ int main(int argc, char *argv[])
604 if (!is_full_backup) { 607 if (!is_full_backup) {
605 printf("Reading existing Manifest.\n"); 608 printf("Reading existing Manifest.\n");
606 plist_read_from_filename(&manifest_plist, manifest_path); 609 plist_read_from_filename(&manifest_plist, manifest_path);
610 if (!manifest_plist) {
611 printf("Could not read Manifest.plist, switching to full backup mode.\n");
612 is_full_backup = 1;
613 }
614 }
615
616 /* Info.plist (Device infos, IC-Info.sidb, photos, app_ids, iTunesPrefs) */
617
618 /* create new Info.plist on new backups */
619 if (is_full_backup) {
620 if (info_plist) {
621 plist_free(info_plist);
622 info_plist = NULL;
623 }
624 remove(info_path);
625 printf("Creating Info.plist for new backup.\n");
626 info_plist = mobilebackup_factory_info_plist_new();
627 plist_write_to_filename(info_plist, info_path, PLIST_FORMAT_XML);
607 } 628 }
629 g_free(info_path);
608 630
609 plist_free(info_plist); 631 plist_free(info_plist);
610 info_plist = NULL; 632 info_plist = NULL;