summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/iphonebackup.c63
1 files changed, 46 insertions, 17 deletions
diff --git a/tools/iphonebackup.c b/tools/iphonebackup.c
index f212fc8..bc61347 100644
--- a/tools/iphonebackup.c
+++ b/tools/iphonebackup.c
@@ -311,6 +311,9 @@ static int mobilebackup_info_is_current_device(plist_t info)
311 311
312 if(plist_compare_node_value(value_node, node)) 312 if(plist_compare_node_value(value_node, node))
313 ret = 1; 313 ret = 1;
314 else {
315 printf("Info.plist: UniqueDeviceID does not match.\n");
316 }
314 317
315 /* verify SerialNumber */ 318 /* verify SerialNumber */
316 if (ret == 1) { 319 if (ret == 1) {
@@ -319,8 +322,23 @@ static int mobilebackup_info_is_current_device(plist_t info)
319 322
320 if(plist_compare_node_value(value_node, node)) 323 if(plist_compare_node_value(value_node, node))
321 ret = 1; 324 ret = 1;
322 else 325 else {
326 printf("Info.plist: SerialNumber does not match.\n");
327 ret = 0;
328 }
329 }
330
331 /* verify ProductVersion to prevent using backup with different OS version */
332 if (ret == 1) {
333 value_node = plist_dict_get_item(root_node, "ProductVersion");
334 node = plist_dict_get_item(info, "Product Version");
335
336 if(plist_compare_node_value(value_node, node))
337 ret = 1;
338 else {
339 printf("Info.plist: ProductVersion does not match.\n");
323 ret = 0; 340 ret = 0;
341 }
324 } 342 }
325 343
326 plist_free(root_node); 344 plist_free(root_node);
@@ -553,11 +571,32 @@ int main(int argc, char *argv[])
553 printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, port); 571 printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, port);
554 mobilebackup_client_new(phone, port, &mobilebackup); 572 mobilebackup_client_new(phone, port, &mobilebackup);
555 573
574 /* check abort conditions */
556 if (quit_flag > 0) { 575 if (quit_flag > 0) {
557 printf("Aborting backup. Cancelled by user.\n"); 576 printf("Aborting backup. Cancelled by user.\n");
558 cmd = CMD_LEAVE; 577 cmd = CMD_LEAVE;
559 } 578 }
560 579
580 /* verify existing Info.plist */
581 if (stat(info_path, &st) == 0) {
582 printf("Reading Info.plist from backup.\n");
583 plist_read_from_filename(&info_plist, info_path);
584
585 if (cmd == CMD_BACKUP) {
586 if (mobilebackup_info_is_current_device(info_plist)) {
587 /* update the last backup time within Info.plist */
588 mobilebackup_info_update_last_backup_date(info_plist);
589 remove(info_path);
590 plist_write_to_filename(info_plist, info_path, PLIST_FORMAT_XML);
591 } else {
592 printf("Aborting backup. Backup is not compatible with the current device.\n");
593 cmd = CMD_LEAVE;
594 }
595 }
596 } else {
597 is_full_backup = 1;
598 }
599
561 do_post_notification(NP_SYNC_WILL_START); 600 do_post_notification(NP_SYNC_WILL_START);
562 uint64_t lockfile = 0; 601 uint64_t lockfile = 0;
563 afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); 602 afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile);
@@ -570,6 +609,7 @@ int main(int argc, char *argv[])
570 lockfile = 0; 609 lockfile = 0;
571 } 610 }
572 } 611 }
612
573 switch(cmd) { 613 switch(cmd) {
574 case CMD_BACKUP: 614 case CMD_BACKUP:
575 printf("Starting backup...\n"); 615 printf("Starting backup...\n");
@@ -577,31 +617,20 @@ int main(int argc, char *argv[])
577 /* TODO: verify battery on AC enough battery remaining */ 617 /* TODO: verify battery on AC enough battery remaining */
578 618
579 /* Info.plist (Device infos, IC-Info.sidb, photos, app_ids, iTunesPrefs) */ 619 /* Info.plist (Device infos, IC-Info.sidb, photos, app_ids, iTunesPrefs) */
580 620 /* create new Info.plist on new backups */
581 /* read existing Info.plist or create new one */ 621 if (is_full_backup) {
582 if (stat(info_path, &st) == 0) {
583 printf("Reading Info.plist from existing backup.\n");
584 plist_read_from_filename(&info_plist, info_path);
585
586 if(!is_full_backup) {
587 /* update the last backup time within Info.plist */
588 mobilebackup_info_update_last_backup_date(info_plist);
589 remove(info_path);
590 plist_write_to_filename(info_plist, info_path, PLIST_FORMAT_XML);
591 }
592 } else {
593 printf("Creating Info.plist for new backup.\n"); 622 printf("Creating Info.plist for new backup.\n");
594 info_plist = mobilebackup_factory_info_plist_new(); 623 info_plist = mobilebackup_factory_info_plist_new();
595 plist_write_to_filename(info_plist, info_path, PLIST_FORMAT_XML); 624 plist_write_to_filename(info_plist, info_path, PLIST_FORMAT_XML);
596 is_full_backup = 1;
597 } 625 }
598 626
599 g_free(info_path); 627 g_free(info_path);
600 628
601 /* Manifest.plist (backup manifest (backup state)) */ 629 /* Manifest.plist (backup manifest (backup state)) */
602 char *manifest_path = mobilebackup_build_path(backup_directory, "Manifest", ".plist"); 630 char *manifest_path = mobilebackup_build_path(backup_directory, "Manifest", ".plist");
603 /* read the last Manifest.plist if the current backup is for this device */ 631
604 if (!is_full_backup && mobilebackup_info_is_current_device(info_plist)) { 632 /* read the last Manifest.plist */
633 if (!is_full_backup) {
605 printf("Reading existing Manifest.\n"); 634 printf("Reading existing Manifest.\n");
606 plist_read_from_filename(&manifest_plist, manifest_path); 635 plist_read_from_filename(&manifest_plist, manifest_path);
607 } 636 }