Skip to content

Commit

Permalink
Upgrade to 3.1 b3
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveJessyChen committed Oct 28, 2024
1 parent 61dc195 commit 5e5e3c0
Show file tree
Hide file tree
Showing 18 changed files with 4,067 additions and 341 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
build
com.apple.MobileGestalt.plist
.DS_Store
__pycache__
15 changes: 10 additions & 5 deletions Sparserestore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

from . import backup

def reboot_device(reboot: bool = False, lockdown_client: LockdownClient = None):
if reboot and lockdown_client != None:
print("Success! Rebooting your device...")
with DiagnosticsService(lockdown_client) as diagnostics_service:
diagnostics_service.restart()
print("Remember to turn Find My back on!")

def perform_restore(backup: backup.Backup, reboot: bool = False, lockdown_client: LockdownClient = None):
try:
with TemporaryDirectory() as backup_dir:
Expand All @@ -18,6 +25,8 @@ def perform_restore(backup: backup.Backup, reboot: bool = False, lockdown_client
lockdown_client = create_using_usbmux()
with Mobilebackup2Service(lockdown_client) as mb:
mb.restore(backup_dir, system=True, reboot=False, copy=False, source=".")
# reboot the device
reboot_device(reboot, lockdown_client)
except PyMobileDevice3Exception as e:
if "Find My" in str(e):
print("Find My must be disabled in order to use this tool.")
Expand All @@ -26,8 +35,4 @@ def perform_restore(backup: backup.Backup, reboot: bool = False, lockdown_client
elif "crash_on_purpose" not in str(e):
raise e
else:
if reboot and lockdown_client != None:
print("Success! Rebooting your device...")
with DiagnosticsService(lockdown_client) as diagnostics_service:
diagnostics_service.restart()
print("Remember to turn Find My back on!")
reboot_device(reboot, lockdown_client)
111 changes: 82 additions & 29 deletions Sparserestore/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,81 @@
import os

class FileToRestore:
def __init__(self, contents: str, restore_path: str, owner: int = 501, group: int = 501):
def __init__(self, contents: str, restore_path: str, domain: str = None, owner: int = 501, group: int = 501):
self.contents = contents
self.restore_path = restore_path
self.domain = domain
self.owner = owner
self.group = group

def concat_exploit_file(file: FileToRestore, files_list: list[FileToRestore], last_domain: str) -> str:
base_path = "/var/backup"
# set it to work in the separate volumes (prevents a bootloop)
if file.restore_path.startswith("/var/mobile/"):
# required on iOS 17.0+ since /var/mobile is on a separate partition
base_path = "/var/mobile/backup"
elif file.restore_path.startswith("/private/var/mobile/"):
base_path = "/private/var/mobile/backup"
elif file.restore_path.startswith("/private/var/"):
base_path = "/private/var/backup"
# don't append the directory if it has already been added (restore will fail)
path, name = os.path.split(file.restore_path)
domain_path = f"SysContainerDomain-../../../../../../../..{base_path}{path}/"
new_last_domain = last_domain
if last_domain != domain_path:
files_list.append(backup.Directory(
"",
f"{domain_path}/",
owner=file.owner,
group=file.group
))
new_last_domain = domain_path
files_list.append(backup.ConcreteFile(
"",
f"{domain_path}/{name}",
owner=file.owner,
group=file.group,
contents=file.contents
))
return new_last_domain

def concat_regular_file(file: FileToRestore, files_list: list[FileToRestore], last_domain: str, last_path: str):
path, name = os.path.split(file.restore_path)
paths = path.split("/")
new_last_domain = last_domain
# append the domain first
if last_domain != file.domain:
files_list.append(backup.Directory(
"",
file.domain,
owner=file.owner,
group=file.group
))
new_last_domain = file.domain
# append each part of the path if it is not already there
full_path = ""
for path_item in paths:
if full_path != "":
full_path += "/"
full_path += path_item
if not last_path.startswith(full_path):
files_list.append(backup.Directory(
full_path,
file.domain,
owner=file.owner,
group=file.group
))
last_path = full_path
# finally, append the file
files_list.append(backup.ConcreteFile(
f"{full_path}/{name}",
file.domain,
owner=file.owner,
group=file.group,
contents=file.contents
))
return new_last_domain, full_path

# files is a list of FileToRestore objects
def restore_files(files: list, reboot: bool = False, lockdown_client: LockdownClient = None):
# create the files to be backed up
Expand All @@ -17,42 +86,26 @@ def restore_files(files: list, reboot: bool = False, lockdown_client: LockdownCl
sorted_files = sorted(files, key=lambda x: x.restore_path, reverse=True)
# add the file paths
last_domain = ""
last_path = ""
exploit_only = True
for file in sorted_files:
base_path = "/var/backup"
# set it to work in the separate volumes (prevents a bootloop)
if file.restore_path.startswith("/var/mobile/"):
# required on iOS 17.0+ since /var/mobile is on a separate partition
base_path = "/var/mobile/backup"
elif file.restore_path.startswith("/private/var/mobile/"):
base_path = "/private/var/mobile/backup"
elif file.restore_path.startswith("/private/var/"):
base_path = "/private/var/backup"
# don't append the directory if it has already been added (restore will fail)
path, name = os.path.split(file.restore_path)
domain_path = f"SysContainerDomain-../../../../../../../..{base_path}{path}/"
if last_domain != domain_path:
files_list.append(backup.Directory(
"",
f"{domain_path}/",
owner=file.owner,
group=file.group
))
last_domain = domain_path
files_list.append(backup.ConcreteFile(
"",
f"{domain_path}/{name}",
owner=file.owner,
group=file.group,
contents=file.contents
))
files_list.append(backup.ConcreteFile("", "SysContainerDomain-../../../../../../../.." + "/crash_on_purpose", contents=b""))
if file.domain == None:
last_domain = concat_exploit_file(file, files_list, last_domain)
else:
last_domain, last_path = concat_regular_file(file, files_list, last_domain, last_path)
exploit_only = False

# crash the restore to skip the setup (only works for exploit files)
if exploit_only:
files_list.append(backup.ConcreteFile("", "SysContainerDomain-../../../../../../../.." + "/crash_on_purpose", contents=b""))

# create the backup
back = backup.Backup(files=files_list)

perform_restore(backup=back, reboot=reboot, lockdown_client=lockdown_client)


# DEPRICATED
def restore_file(fp: str, restore_path: str, restore_name: str, reboot: bool = False, lockdown_client: LockdownClient = None):
# open the file and read the contents
contents = open(fp, "rb").read()
Expand Down
2 changes: 1 addition & 1 deletion cli_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_apply_number(num: int) -> int:
'---' \\ \\ / \\ \\ / `----'
`--`-' `--`-'
""")
print("CLI v3.0")
print("CLI v3.1")
print("by LeminLimez")
print("Thanks @disfordottie for the clock animation and @lrdsnow for EU Enabler\n")
print("Please back up your device before using!")
Expand Down
6 changes: 3 additions & 3 deletions devicemanagement/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def __init__(self, uuid: int, name: str, version: str, build: str, model: str, l

def supported(self) -> bool:
parsed_ver: Version = Version(self.version)
if (parsed_ver < Version("17.0")) or (parsed_ver > Version("18.1")):
if parsed_ver > Version("18.1"):
return False
if (parsed_ver == Version("18.1")
and self.build != "22B5007p" and self.build == "22B5023e"
and self.build == "22B5034e" and self.build == "22B5045g"):
and self.build != "22B5007p" and self.build != "22B5023e"
and self.build != "22B5034e" and self.build != "22B5045g"):
return False
return True

Expand Down
Loading

0 comments on commit 5e5e3c0

Please sign in to comment.