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/OpenCore-Legacy-Patcher-*.plist
/payloads/KDK.dmg /payloads/KDK.dmg
*.log *.log
/Universal-Binaries.dmg

View File

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

View File

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

View File

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

View File

@@ -36,7 +36,7 @@ class RoutePayloadDiskImage:
self._unmount_active_dmgs(unmount_all_active=False) self._unmount_active_dmgs(unmount_all_active=False)
output = subprocess.run( 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")), "-mountpoint", Path(self.temp_dir.name / Path("payloads")),
"-nobrowse", "-nobrowse",
"-shadow", Path(self.temp_dir.name / Path("payloads_overlay")), "-shadow", Path(self.temp_dir.name / Path("payloads_overlay")),
@@ -55,7 +55,7 @@ class RoutePayloadDiskImage:
logging.info(f"Return Code: {output.returncode}") 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 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 = subprocess.run(["hdiutil", "info", "-plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
dmg_info = plistlib.loads(dmg_info.stdout) dmg_info = plistlib.loads(dmg_info.stdout)
for image in dmg_info["images"]:
if image["image-path"].endswith("payloads.dmg"): for variant in ["Universal-Binaries.dmg", "payloads.dmg"]:
if unmount_all_active is False: for image in dmg_info["images"]:
# Check that only our personal payloads.dmg is unmounted if image["image-path"].endswith(variant):
if "shadow-path" in image: if unmount_all_active is False:
if self.temp_dir.name in image["shadow-path"]: # Check that only our personal payloads.dmg is unmounted
logging.info("- Unmounting personal payloads.dmg") if "shadow-path" in image:
subprocess.run( if self.temp_dir.name in image["shadow-path"]:
["hdiutil", "detach", image["system-entities"][0]["dev-entry"], "-force"], logging.info(f"- Unmounting personal {variant}")
stdout=subprocess.PIPE, stderr=subprocess.STDOUT subprocess.run(
) ["hdiutil", "detach", image["system-entities"][0]["dev-entry"], "-force"],
else: stdout=subprocess.PIPE, stderr=subprocess.STDOUT
logging.info(f"- Unmounting payloads.dmg at: {image['system-entities'][0]['dev-entry']}") )
subprocess.run( else:
["hdiutil", "detach", image["system-entities"][0]["dev-entry"], "-force"], logging.info(f"- Unmounting {variant} at: {image['system-entities'][0]['dev-entry']}")
stdout=subprocess.PIPE, stderr=subprocess.STDOUT 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"] 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: 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...") logging.info("- Local PatcherSupportPkg resources available, continuing...")
return True return True
if Path(self.constants.payload_local_binaries_root_path_zip).exists(): if Path(self.constants.payload_local_binaries_root_path_dmg).exists():
logging.info("- Local PatcherSupportPkg resources available, unzipping...") logging.info("- Local PatcherSupportPkg resources available, mounting...")
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)) 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 return True
logging.info("- PatcherSupportPkg resources missing, Patcher likely corrupted!!!") logging.info("- PatcherSupportPkg resources missing, Patcher likely corrupted!!!")

View File

@@ -133,35 +133,40 @@ class PatcherValidation:
Validates sys_patch modules Validates sys_patch modules
""" """
if Path(self.constants.payload_local_binaries_root_path_zip).exists(): if not Path(self.constants.payload_local_binaries_root_path_dmg).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:
logging.info("- Skipping Root Patch File integrity validation") 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: def _validate_configs(self) -> None: