Merge pull request #1063 from dortania/dmg-rework

Implement DMG-based PatcherSupportPkg system
This commit is contained in:
Mykola Grymalyuk
2023-05-04 15:15:38 -07:00
committed by GitHub
7 changed files with 97 additions and 79 deletions

1
.gitignore vendored
View File

@@ -33,3 +33,4 @@ __pycache__/
/payloads/OpenCore-Legacy-Patcher-*.plist
/payloads/KDK.dmg
*.log
/Universal-Binaries.dmg

View File

@@ -236,7 +236,6 @@ class CreateBinary:
"launcher.sh",
"OC-Patcher-TUI.icns",
"OC-Patcher.icns",
"Universal-Binaries.zip",
]
@@ -261,16 +260,16 @@ class CreateBinary:
patcher_support_pkg_version = constants.Constants().patcher_support_pkg_version
required_resources = [
"Universal-Binaries.zip"
"Universal-Binaries.dmg"
]
print("- Downloading required resources...")
for resource in required_resources:
if Path(f"./payloads/{resource}").exists():
if Path(f"./{resource}").exists():
if self.args.reset_binaries:
print(f" - Removing old {resource}")
rm_output = subprocess.run(
["rm", "-rf", f"./payloads/{resource}"],
["rm", "-rf", f"./{resource}"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if rm_output.returncode != 0:
@@ -298,13 +297,6 @@ class CreateBinary:
print(f" - {resource} not found")
raise Exception(f"{resource} not found")
print(" - Moving into payloads")
mv_output = subprocess.run(["mv", resource, "./payloads/"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if mv_output.returncode != 0:
print(" - Move failed")
print(mv_output.stderr.decode('utf-8'))
raise Exception("Move failed")
def _generate_payloads_dmg(self):
"""
@@ -331,9 +323,9 @@ class CreateBinary:
print(" - Generating DMG...")
dmg_output = subprocess.run([
'hdiutil', 'create', './payloads.dmg',
'-megabytes', '32000',
'-megabytes', '32000', # Overlays can only be as large as the disk image allows
'-format', 'UDZO', '-ov',
'-volname', 'OpenCore Patcher Resources',
'-volname', 'OpenCore Patcher Resources (Base)',
'-fs', 'HFS+',
'-srcfolder', './payloads',
'-passphrase', 'password', '-encryption'

View File

@@ -9,7 +9,7 @@ block_cipher = None
a = Analysis(['OpenCore-Patcher-GUI.command'],
pathex=[],
binaries=[],
datas=[('payloads.dmg', '.')],
datas=[('payloads.dmg', '.'), ('Universal-Binaries.dmg', '.')],
hiddenimports=[],
hookspath=[],
hooksconfig={},

View File

@@ -13,7 +13,7 @@ class Constants:
def __init__(self) -> None:
# Patcher Versioning
self.patcher_version: str = "0.6.6" # OpenCore-Legacy-Patcher
self.patcher_support_pkg_version: str = "0.9.7" # PatcherSupportPkg
self.patcher_support_pkg_version: str = "1.0.0" # PatcherSupportPkg
self.copyright_date: str = "Copyright © 2020-2023 Dortania"
# URLs
@@ -106,8 +106,9 @@ class Constants:
self.kdkless_version: str = "1.0.0"
# Get resource path
self.current_path: Path = Path(__file__).parent.parent.resolve()
self.payload_path: Path = self.current_path / Path("payloads")
self.current_path: Path = Path(__file__).parent.parent.resolve()
self.original_path: Path = Path(__file__).parent.parent.resolve()
self.payload_path: Path = self.current_path / Path("payloads")
# Patcher Settings
## Internal settings
@@ -225,6 +226,17 @@ class Constants:
]
# Payload Location
# Support Disk Images
@property
def payload_path_dmg(self):
return self.original_path / Path("payloads.dmg")
@property
def payload_local_binaries_root_path_dmg(self):
return self.original_path / Path("Universal-Binaries.dmg")
# OpenCore
@property
def opencore_zip_source(self):
@@ -650,10 +662,6 @@ class Constants:
def payload_local_binaries_root_path(self):
return self.payload_path / Path("Universal-Binaries")
@property
def payload_local_binaries_root_path_zip(self):
return self.payload_path / Path("Universal-Binaries.zip")
@property
def kdk_download_path(self):
return self.payload_path / Path("KDK.dmg")

View File

@@ -36,7 +36,7 @@ class RoutePayloadDiskImage:
self._unmount_active_dmgs(unmount_all_active=False)
output = subprocess.run(
[
"hdiutil", "attach", "-noverify", f"{self.constants.payload_path}.dmg",
"hdiutil", "attach", "-noverify", f"{self.constants.payload_path_dmg}",
"-mountpoint", Path(self.temp_dir.name / Path("payloads")),
"-nobrowse",
"-shadow", Path(self.temp_dir.name / Path("payloads_overlay")),
@@ -55,7 +55,7 @@ class RoutePayloadDiskImage:
logging.info(f"Return Code: {output.returncode}")
def _unmount_active_dmgs(self, unmount_all_active=True) -> None:
def _unmount_active_dmgs(self, unmount_all_active: bool = True) -> None:
"""
Unmounts disk images associated with OCLP
@@ -70,20 +70,22 @@ class RoutePayloadDiskImage:
dmg_info = subprocess.run(["hdiutil", "info", "-plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
dmg_info = plistlib.loads(dmg_info.stdout)
for image in dmg_info["images"]:
if image["image-path"].endswith("payloads.dmg"):
if unmount_all_active is False:
# Check that only our personal payloads.dmg is unmounted
if "shadow-path" in image:
if self.temp_dir.name in image["shadow-path"]:
logging.info("- Unmounting personal payloads.dmg")
subprocess.run(
["hdiutil", "detach", image["system-entities"][0]["dev-entry"], "-force"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
else:
logging.info(f"- Unmounting payloads.dmg at: {image['system-entities'][0]['dev-entry']}")
subprocess.run(
["hdiutil", "detach", image["system-entities"][0]["dev-entry"], "-force"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
for variant in ["Universal-Binaries.dmg", "payloads.dmg"]:
for image in dmg_info["images"]:
if image["image-path"].endswith(variant):
if unmount_all_active is False:
# Check that only our personal payloads.dmg is unmounted
if "shadow-path" in image:
if self.temp_dir.name in image["shadow-path"]:
logging.info(f"- Unmounting personal {variant}")
subprocess.run(
["hdiutil", "detach", image["system-entities"][0]["dev-entry"], "-force"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
else:
logging.info(f"- Unmounting {variant} at: {image['system-entities'][0]['dev-entry']}")
subprocess.run(
["hdiutil", "detach", image["system-entities"][0]["dev-entry"], "-force"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)

View File

@@ -67,13 +67,6 @@ class PatchSysVolume:
self.skip_root_kmutil_requirement = self.hardware_details["Settings: Supports Auxiliary Cache"]
def __del__(self) -> None:
"""
Ensures that each time we're patching, we're using a clean PatcherSupportPkg folder
"""
if Path(self.constants.payload_local_binaries_root_path).exists():
shutil.rmtree(self.constants.payload_local_binaries_root_path)
def _init_pathing(self, custom_root_mount_path: Path = None, custom_data_mount_path: Path = None) -> None:
"""
@@ -854,10 +847,27 @@ class PatchSysVolume:
logging.info("- Local PatcherSupportPkg resources available, continuing...")
return True
if Path(self.constants.payload_local_binaries_root_path_zip).exists():
logging.info("- Local PatcherSupportPkg resources available, unzipping...")
logging.info("- Unzipping binaries...")
utilities.process_status(subprocess.run(["ditto", "-V", "-x", "-k", "--sequesterRsrc", "--rsrc", self.constants.payload_local_binaries_root_path_zip, self.constants.payload_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
if Path(self.constants.payload_local_binaries_root_path_dmg).exists():
logging.info("- Local PatcherSupportPkg resources available, mounting...")
output = subprocess.run(
[
"hdiutil", "attach", "-noverify", f"{self.constants.payload_local_binaries_root_path_dmg}",
"-mountpoint", Path(self.constants.payload_path / Path("Universal-Binaries")),
"-nobrowse",
"-shadow", Path(self.constants.payload_path / Path("Universal-Binaries_overlay")),
"-passphrase", "password"
],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
if output.returncode != 0:
logging.info("- Failed to mount Universal-Binaries.dmg")
logging.info(f"Output: {output.stdout.decode()}")
logging.info(f"Return Code: {output.returncode}")
return False
logging.info("- Mounted Universal-Binaries.dmg")
return True
logging.info("- PatcherSupportPkg resources missing, Patcher likely corrupted!!!")

View File

@@ -133,35 +133,40 @@ class PatcherValidation:
Validates sys_patch modules
"""
if Path(self.constants.payload_local_binaries_root_path_zip).exists():
logging.info("Validating Root Patch File integrity")
if not Path(self.constants.payload_local_binaries_root_path).exists():
subprocess.run(
[
"ditto", "-V", "-x", "-k", "--sequesterRsrc", "--rsrc",
self.constants.payload_local_binaries_root_path_zip,
self.constants.payload_path
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
for supported_os in [os_data.os_data.big_sur, os_data.os_data.monterey, os_data.os_data.ventura]:
for i in range(0, 10):
self._validate_root_patch_files(supported_os, i)
logging.info("Validating SNB Board ID patcher")
self.constants.computer.reported_board_id = "Mac-7BA5B2DFE22DDD8C"
sys_patch_helpers.SysPatchHelpers(self.constants).snb_board_id_patch(self.constants.payload_local_binaries_root_path)
# Clean up
subprocess.run(
[
"rm", "-rf", self.constants.payload_local_binaries_root_path
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
else:
if not Path(self.constants.payload_local_binaries_root_path_dmg).exists():
logging.info("- Skipping Root Patch File integrity validation")
return
logging.info("Validating Root Patch File integrity")
output = subprocess.run(
[
"hdiutil", "attach", "-noverify", f"{self.constants.payload_local_binaries_root_path_dmg}",
"-mountpoint", Path(self.constants.payload_path / Path("Universal-Binaries")),
"-nobrowse",
"-shadow", Path(self.constants.payload_path / Path("Universal-Binaries_overlay")),
"-passphrase", "password"
],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
if output.returncode != 0:
logging.info("- Failed to mount Universal-Binaries.dmg")
logging.info(f"Output: {output.stdout.decode()}")
logging.info(f"Return Code: {output.returncode}")
print(self.constants.payload_local_binaries_root_path_dmg)
raise Exception("Failed to mount Universal-Binaries.dmg")
logging.info("- Mounted Universal-Binaries.dmg")
for supported_os in [os_data.os_data.big_sur, os_data.os_data.monterey, os_data.os_data.ventura]:
for i in range(0, 10):
self._validate_root_patch_files(supported_os, i)
logging.info("Validating SNB Board ID patcher")
self.constants.computer.reported_board_id = "Mac-7BA5B2DFE22DDD8C"
sys_patch_helpers.SysPatchHelpers(self.constants).snb_board_id_patch(self.constants.payload_local_binaries_root_path)
def _validate_configs(self) -> None: