Add patching utility for internal developers

This commit is contained in:
Mykola Grymalyuk
2023-06-08 15:44:41 -06:00
parent 0dbffc5a3e
commit 6020eae937
8 changed files with 99 additions and 17 deletions

Binary file not shown.

View File

@@ -1,15 +1,23 @@
# -*- mode: python ; coding: utf-8 -*- # -*- mode: python ; coding: utf-8 -*-
import sys, os, time, subprocess import sys, os, time, subprocess, pathlib
sys.path.append(os.path.abspath(os.getcwd())) sys.path.append(os.path.abspath(os.getcwd()))
from resources import constants from resources import constants
block_cipher = None block_cipher = None
datas = [
('payloads.dmg', '.'),
('Universal-Binaries.dmg', '.'),
]
if pathlib.Path("DortaniaInternalResources.dmg").exists():
datas.append(('DortaniaInternalResources.dmg', '.'))
a = Analysis(['OpenCore-Patcher-GUI.command'], a = Analysis(['OpenCore-Patcher-GUI.command'],
pathex=[], pathex=[],
binaries=[], binaries=[],
datas=[('payloads.dmg', '.'), ('Universal-Binaries.dmg', '.')], datas=datas,
hiddenimports=[], hiddenimports=[],
hookspath=[], hookspath=[],
hooksconfig={}, hooksconfig={},

View File

@@ -1006,7 +1006,7 @@ class SystemPatchDictionary():
"OS Minor": 99 "OS Minor": 99
}, },
}, },
"Install Reference": { "Install": {
"/System/Library/Extensions": { "/System/Library/Extensions": {
"IOGPUFamily.kext": "13.5 Beta 2", "IOGPUFamily.kext": "13.5 Beta 2",
"IOSurface.kext": "13.5 Beta 2", "IOSurface.kext": "13.5 Beta 2",
@@ -1031,7 +1031,7 @@ class SystemPatchDictionary():
"OS Minor": 99 "OS Minor": 99
}, },
}, },
"Install Reference": { "Install": {
"/System/Library/Extensions": { "/System/Library/Extensions": {
"IOAcceleratorFamily2.kext": "13.5 Beta 2", "IOAcceleratorFamily2.kext": "13.5 Beta 2",
}, },
@@ -1139,8 +1139,8 @@ class SystemPatchDictionary():
"CoreWiFi.framework": "12.6.2", "CoreWiFi.framework": "12.6.2",
"IO80211.framework": "12.6.2", "IO80211.framework": "12.6.2",
# TODO: When PatchSupportPkg has published binaries, remove comment # TODO: When PatchSupportPkg has published binaries, remove comment
# **({ "CoreAnalytics.framework": "13.5 Beta 2"} if self.os_major >= os_data.os_data.sonoma else {}), **({ "CoreAnalytics.framework": "13.5 Beta 2"} if self.os_major >= os_data.os_data.sonoma else {}),
# **({ "WiFiAnalytics.framework": "13.5 Beta 2"} if self.os_major >= os_data.os_data.sonoma else {}), **({ "WiFiAnalytics.framework": "13.5 Beta 2"} if self.os_major >= os_data.os_data.sonoma else {}),
}, },
}, },
}, },
@@ -1158,7 +1158,7 @@ class SystemPatchDictionary():
"OS Minor": 99 "OS Minor": 99
}, },
}, },
"Install Reference": { "Install": {
"/usr/libexec": { "/usr/libexec": {
"airportd": "13.5 Beta 2", "airportd": "13.5 Beta 2",
"wifianalyticsd": "13.5 Beta 2", "wifianalyticsd": "13.5 Beta 2",

View File

@@ -229,6 +229,7 @@ class Constants:
os_data.os_data.big_sur, os_data.os_data.big_sur,
os_data.os_data.monterey, os_data.os_data.monterey,
os_data.os_data.ventura, os_data.os_data.ventura,
os_data.os_data.sonoma,
] ]
# Payload Location # Payload Location
@@ -242,6 +243,9 @@ class Constants:
def payload_local_binaries_root_path_dmg(self): def payload_local_binaries_root_path_dmg(self):
return self.original_path / Path("Universal-Binaries.dmg") return self.original_path / Path("Universal-Binaries.dmg")
@property
def overlay_psp_path_dmg(self):
return self.original_path / Path("DortaniaInternalResources.dmg")
# OpenCore # OpenCore
@property @property

View File

@@ -71,7 +71,7 @@ class RoutePayloadDiskImage:
dmg_info = plistlib.loads(dmg_info.stdout) dmg_info = plistlib.loads(dmg_info.stdout)
for variant in ["Universal-Binaries.dmg", "payloads.dmg"]: for variant in ["Universal-Binaries.dmg", "payloads.dmg", "DortaniaInternal.dmg"]:
for image in dmg_info["images"]: for image in dmg_info["images"]:
if image["image-path"].endswith(variant): if image["image-path"].endswith(variant):
if unmount_all_active is False: if unmount_all_active is False:

View File

@@ -32,11 +32,13 @@
# This is because Apple removed on-disk binaries (ref: https://github.com/dortania/OpenCore-Legacy-Patcher/issues/998) # This is because Apple removed on-disk binaries (ref: https://github.com/dortania/OpenCore-Legacy-Patcher/issues/998)
# 'sudo ditto /Library/Developer/KDKs/<KDK Version>/System /System/Volumes/Update/mnt1/System' # 'sudo ditto /Library/Developer/KDKs/<KDK Version>/System /System/Volumes/Update/mnt1/System'
import logging
import plistlib import plistlib
import subprocess import subprocess
import applescript
from pathlib import Path from pathlib import Path
from datetime import datetime from datetime import datetime
import logging
from resources import constants, utilities, kdk_handler from resources import constants, utilities, kdk_handler
from resources.sys_patch import sys_patch_detect, sys_patch_auto, sys_patch_helpers, sys_patch_generate from resources.sys_patch import sys_patch_detect, sys_patch_auto, sys_patch_helpers, sys_patch_generate
@@ -863,6 +865,75 @@ class PatchSysVolume:
return False return False
logging.info("- Mounted Universal-Binaries.dmg") logging.info("- Mounted Universal-Binaries.dmg")
if Path(self.constants.overlay_psp_path_dmg).exists() and Path("~/.dortania_developer").expanduser().exists():
icon_path = str(self.constants.app_icon_path).replace("/", ":")[1:]
msg = "Welcome to the DortaniaInternal Program, please provided the decryption key to access internal resources. Press cancel to skip."
password = Path("~/.dortania_developer_key").expanduser().read_text().strip() if Path("~/.dortania_developer_key").expanduser().exists() else ""
for i in range(3):
try:
if password == "":
password = applescript.AppleScript(
f"""
set theResult to display dialog "{msg}" default answer "" with hidden answer with title "OpenCore Legacy Patcher" with icon file "{icon_path}"
return the text returned of theResult
"""
).run()
result = subprocess.run(
[
"hdiutil", "attach", "-noverify", f"{self.constants.overlay_psp_path_dmg}",
"-mountpoint", Path(self.constants.payload_path / Path("DortaniaInternal")),
"-nobrowse",
"-passphrase", password
],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
if result.returncode == 0:
logging.info("- Mounted DortaniaInternal resources")
result = subprocess.run(
[
"ditto", f"{self.constants.payload_path / Path('DortaniaInternal')}", f"{self.constants.payload_path / Path('Universal-Binaries')}"
],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
if result.returncode == 0:
return True
logging.info("- Failed to merge DortaniaInternal resources")
logging.info(f"Output: {result.stdout.decode()}")
logging.info(f"Return Code: {result.returncode}")
return False
logging.info("- Failed to mount DortaniaInternal resources")
logging.info(f"Output: {result.stdout.decode()}")
logging.info(f"Return Code: {result.returncode}")
if "Authentication error" not in result.stdout.decode():
try:
# Display that the disk image might be corrupted
applescript.AppleScript(
f"""
display dialog "Failed to mount DortaniaInternal resources, please file an internal radar:\n\n{result.stdout.decode()}" with title "OpenCore Legacy Patcher" with icon file "{icon_path}"
"""
).run()
return False
except Exception as e:
pass
break
msg = f"Decryption failed, please try again. {2 - i} attempts remaining. "
password = ""
if i == 2:
applescript.AppleScript(
f"""
display dialog "Failed to mount DortaniaInternal resources, too many incorrect passwords. If this continues with the correct decryption key, please file an internal radar." with title "OpenCore Legacy Patcher" with icon file "{icon_path}"
"""
).run()
return False
except Exception as e:
break
return True return True
logging.info("- PatcherSupportPkg resources missing, Patcher likely corrupted!!!") logging.info("- PatcherSupportPkg resources missing, Patcher likely corrupted!!!")

View File

@@ -84,7 +84,6 @@ class AutomaticSysPatch:
if patches[patch] is True and not patch.startswith("Settings") and not patch.startswith("Validation"): if patches[patch] is True and not patch.startswith("Settings") and not patch.startswith("Validation"):
patch_string += f"- {patch}\n" patch_string += f"- {patch}\n"
logging.info("- No new binaries found on Github, proceeding with patching")
logging.info("- No new binaries found on Github, proceeding with patching") logging.info("- No new binaries found on Github, proceeding with patching")
if self.constants.launcher_script is None: if self.constants.launcher_script is None:
args_string = f"'{self.constants.launcher_binary}' --gui_patch" args_string = f"'{self.constants.launcher_binary}' --gui_patch"

View File

@@ -543,13 +543,13 @@ class DetectRootPatch:
# Due to extracted frameworks for IO80211.framework and co, check library validation # Due to extracted frameworks for IO80211.framework and co, check library validation
self.amfi_must_disable = True self.amfi_must_disable = True
# if ( if (
# isinstance(self.constants.computer.wifi, device_probe.Broadcom) isinstance(self.constants.computer.wifi, device_probe.Broadcom)
# and self.constants.computer.wifi.chipset in [device_probe.Broadcom.Chipsets.AirPortBrcm4360, device_probe.Broadcom.Chipsets.AirportBrcmNIC]): and self.constants.computer.wifi.chipset in [device_probe.Broadcom.Chipsets.AirPortBrcm4360, device_probe.Broadcom.Chipsets.AirportBrcmNIC]):
# if self.constants.detected_os > os_data.os_data.ventura: if self.constants.detected_os > os_data.os_data.ventura:
# self.modern_wifi = True self.modern_wifi = True
# self.amfi_must_disable = True self.amfi_must_disable = True
# self.requires_root_kc = True self.requires_root_kc = True
# if self.model in ["MacBookPro5,1", "MacBookPro5,2", "MacBookPro5,3", "MacBookPro8,2", "MacBookPro8,3"]: # if self.model in ["MacBookPro5,1", "MacBookPro5,2", "MacBookPro5,3", "MacBookPro8,2", "MacBookPro8,3"]:
if self.model in ["MacBookPro8,2", "MacBookPro8,3"]: if self.model in ["MacBookPro8,2", "MacBookPro8,3"]: