mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-14 04:38:20 +10:00
Implement logging library
This commit is contained in:
@@ -37,6 +37,7 @@ import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
from resources import constants, utilities, kdk_handler
|
||||
from resources.sys_patch import sys_patch_download, sys_patch_detect, sys_patch_auto, sys_patch_helpers
|
||||
@@ -90,25 +91,25 @@ class PatchSysVolume:
|
||||
# Returns boolean if Root Volume is available
|
||||
self.root_mount_path = utilities.get_disk_path()
|
||||
if self.root_mount_path.startswith("disk"):
|
||||
print(f"- Found Root Volume at: {self.root_mount_path}")
|
||||
logging.info(f"- Found Root Volume at: {self.root_mount_path}")
|
||||
if Path(self.mount_extensions).exists():
|
||||
print("- Root Volume is already mounted")
|
||||
logging.info("- Root Volume is already mounted")
|
||||
return True
|
||||
else:
|
||||
if self.root_supports_snapshot is True:
|
||||
print("- Mounting APFS Snapshot as writable")
|
||||
logging.info("- Mounting APFS Snapshot as writable")
|
||||
result = utilities.elevated(["mount", "-o", "nobrowse", "-t", "apfs", f"/dev/{self.root_mount_path}", self.mount_location], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if result.returncode == 0:
|
||||
print(f"- Mounted APFS Snapshot as writable at: {self.mount_location}")
|
||||
logging.info(f"- Mounted APFS Snapshot as writable at: {self.mount_location}")
|
||||
if Path(self.mount_extensions).exists():
|
||||
print("- Successfully mounted the Root Volume")
|
||||
logging.info("- Successfully mounted the Root Volume")
|
||||
return True
|
||||
else:
|
||||
print("- Root Volume appears to have unmounted unexpectedly")
|
||||
logging.info("- Root Volume appears to have unmounted unexpectedly")
|
||||
else:
|
||||
print("- Unable to mount APFS Snapshot as writable")
|
||||
print("Reason for mount failure:")
|
||||
print(result.stdout.decode().strip())
|
||||
logging.info("- Unable to mount APFS Snapshot as writable")
|
||||
logging.info("Reason for mount failure:")
|
||||
logging.info(result.stdout.decode().strip())
|
||||
return False
|
||||
|
||||
def merge_kdk_with_root(self, save_hid_cs=False):
|
||||
@@ -135,25 +136,25 @@ class PatchSysVolume:
|
||||
oclp_plist_data = plistlib.load(open(oclp_plist, "rb"))
|
||||
if "Kernel Debug Kit Used" in oclp_plist_data:
|
||||
if oclp_plist_data["Kernel Debug Kit Used"] == str(kdk_path):
|
||||
print("- Matching KDK determined to already be merged, skipping")
|
||||
logging.info("- Matching KDK determined to already be merged, skipping")
|
||||
return
|
||||
except:
|
||||
pass
|
||||
|
||||
if kdk_path is None:
|
||||
print(f"- Unable to find Kernel Debug Kit: {downloaded_kdk}")
|
||||
logging.info(f"- Unable to find Kernel Debug Kit: {downloaded_kdk}")
|
||||
raise Exception("Unable to find Kernel Debug Kit")
|
||||
self.kdk_path = kdk_path
|
||||
print(f"- Found KDK at: {kdk_path}")
|
||||
logging.info(f"- Found KDK at: {kdk_path}")
|
||||
|
||||
# Due to some IOHIDFamily oddities, we need to ensure their CodeSignature is retained
|
||||
cs_path = Path(self.mount_location) / Path("System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDEventDriver.kext/Contents/_CodeSignature")
|
||||
if save_hid_cs is True and cs_path.exists():
|
||||
print("- Backing up IOHIDEventDriver CodeSignature")
|
||||
logging.info("- Backing up IOHIDEventDriver CodeSignature")
|
||||
# Note it's a folder, not a file
|
||||
utilities.elevated(["cp", "-r", cs_path, f"{self.constants.payload_path}/IOHIDEventDriver_CodeSignature.bak"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
|
||||
print("- Merging KDK with Root Volume")
|
||||
logging.info("- Merging KDK with Root Volume")
|
||||
utilities.elevated(
|
||||
# Only merge '/System/Library/Extensions'
|
||||
# 'Kernels' and 'KernelSupport' is wasted space for root patching (we don't care above dev kernels)
|
||||
@@ -163,15 +164,15 @@ class PatchSysVolume:
|
||||
# During reversing, we found that kmutil uses this path to determine whether the KDK was successfully merged
|
||||
# Best to verify now before we cause any damage
|
||||
if not (Path(self.mount_location) / Path("System/Library/Extensions/System.kext/PlugIns/Libkern.kext/Libkern")).exists():
|
||||
print("- Failed to merge KDK with Root Volume")
|
||||
logging.info("- Failed to merge KDK with Root Volume")
|
||||
raise Exception("Failed to merge KDK with Root Volume")
|
||||
print("- Successfully merged KDK with Root Volume")
|
||||
logging.info("- Successfully merged KDK with Root Volume")
|
||||
|
||||
# Restore IOHIDEventDriver CodeSignature
|
||||
if save_hid_cs is True and Path(f"{self.constants.payload_path}/IOHIDEventDriver_CodeSignature.bak").exists():
|
||||
print("- Restoring IOHIDEventDriver CodeSignature")
|
||||
logging.info("- Restoring IOHIDEventDriver CodeSignature")
|
||||
if not cs_path.exists():
|
||||
print(" - CodeSignature folder missing, creating")
|
||||
logging.info(" - CodeSignature folder missing, creating")
|
||||
utilities.elevated(["mkdir", "-p", cs_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
utilities.elevated(["cp", "-r", f"{self.constants.payload_path}/IOHIDEventDriver_CodeSignature.bak", cs_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
utilities.elevated(["rm", "-rf", f"{self.constants.payload_path}/IOHIDEventDriver_CodeSignature.bak"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
@@ -179,36 +180,36 @@ class PatchSysVolume:
|
||||
|
||||
def unpatch_root_vol(self):
|
||||
if self.constants.detected_os > os_data.os_data.catalina and self.root_supports_snapshot is True:
|
||||
print("- Reverting to last signed APFS snapshot")
|
||||
logging.info("- Reverting to last signed APFS snapshot")
|
||||
result = utilities.elevated(["bless", "--mount", self.mount_location, "--bootefi", "--last-sealed-snapshot"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if result.returncode != 0:
|
||||
print("- Unable to revert root volume patches")
|
||||
print("Reason for unpatch Failure:")
|
||||
print(result.stdout.decode())
|
||||
print("- Failed to revert snapshot via Apple's 'bless' command")
|
||||
logging.info("- Unable to revert root volume patches")
|
||||
logging.info("Reason for unpatch Failure:")
|
||||
logging.info(result.stdout.decode())
|
||||
logging.info("- Failed to revert snapshot via Apple's 'bless' command")
|
||||
else:
|
||||
self.clean_skylight_plugins()
|
||||
self.delete_nonmetal_enforcement()
|
||||
self.clean_auxiliary_kc()
|
||||
self.constants.root_patcher_succeeded = True
|
||||
print("- Unpatching complete")
|
||||
print("\nPlease reboot the machine for patches to take effect")
|
||||
logging.info("- Unpatching complete")
|
||||
logging.info("\nPlease reboot the machine for patches to take effect")
|
||||
|
||||
def rebuild_snapshot(self):
|
||||
if self.rebuild_kernel_collection() is True:
|
||||
self.update_preboot_kernel_cache()
|
||||
self.rebuild_dyld_shared_cache()
|
||||
if self.create_new_apfs_snapshot() is True:
|
||||
print("- Patching complete")
|
||||
print("\nPlease reboot the machine for patches to take effect")
|
||||
logging.info("- Patching complete")
|
||||
logging.info("\nPlease reboot the machine for patches to take effect")
|
||||
if self.needs_kmutil_exemptions is True:
|
||||
print("Note: Apple will require you to open System Preferences -> Security to allow the new kernel extensions to be loaded")
|
||||
logging.info("Note: Apple will require you to open System Preferences -> Security to allow the new kernel extensions to be loaded")
|
||||
self.constants.root_patcher_succeeded = True
|
||||
if self.constants.gui_mode is False:
|
||||
input("\nPress [ENTER] to continue")
|
||||
|
||||
def rebuild_kernel_collection(self):
|
||||
print("- Rebuilding Kernel Cache (This may take some time)")
|
||||
logging.info("- Rebuilding Kernel Cache (This may take some time)")
|
||||
if self.constants.detected_os > os_data.os_data.catalina:
|
||||
# Base Arguments
|
||||
args = ["kmutil", "install"]
|
||||
@@ -255,7 +256,7 @@ class PatchSysVolume:
|
||||
if self.needs_kmutil_exemptions is True:
|
||||
# When installing to '/Library/Extensions', following args skip kext consent
|
||||
# prompt in System Preferences when SIP's disabled
|
||||
print(" (You will get a prompt by System Preferences, ignore for now)")
|
||||
logging.info(" (You will get a prompt by System Preferences, ignore for now)")
|
||||
args.append("--no-authentication")
|
||||
args.append("--no-authorization")
|
||||
else:
|
||||
@@ -271,11 +272,11 @@ class PatchSysVolume:
|
||||
# - will return 31 on 'No binaries or codeless kexts were provided'
|
||||
# - will return -10 if the volume is missing (ie. unmounted by another process)
|
||||
if result.returncode != 0 or (self.constants.detected_os < os_data.os_data.catalina and "KernelCache ID" not in result.stdout.decode()):
|
||||
print("- Unable to build new kernel cache")
|
||||
print(f"\nReason for Patch Failure ({result.returncode}):")
|
||||
print(result.stdout.decode())
|
||||
print("")
|
||||
print("\nPlease reboot the machine to avoid potential issues rerunning the patcher")
|
||||
logging.info("- Unable to build new kernel cache")
|
||||
logging.info(f"\nReason for Patch Failure ({result.returncode}):")
|
||||
logging.info(result.stdout.decode())
|
||||
logging.info("")
|
||||
logging.info("\nPlease reboot the machine to avoid potential issues rerunning the patcher")
|
||||
if self.constants.gui_mode is False:
|
||||
input("Press [ENTER] to continue")
|
||||
return False
|
||||
@@ -284,11 +285,11 @@ class PatchSysVolume:
|
||||
# Force rebuild the Auxiliary KC
|
||||
result = utilities.elevated(["killall", "syspolicyd", "kernelmanagerd"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if result.returncode != 0:
|
||||
print("- Unable to remove kernel extension policy files")
|
||||
print(f"\nReason for Patch Failure ({result.returncode}):")
|
||||
print(result.stdout.decode())
|
||||
print("")
|
||||
print("\nPlease reboot the machine to avoid potential issues rerunning the patcher")
|
||||
logging.info("- Unable to remove kernel extension policy files")
|
||||
logging.info(f"\nReason for Patch Failure ({result.returncode}):")
|
||||
logging.info(result.stdout.decode())
|
||||
logging.info("")
|
||||
logging.info("\nPlease reboot the machine to avoid potential issues rerunning the patcher")
|
||||
if self.constants.gui_mode is False:
|
||||
input("Press [ENTER] to continue")
|
||||
return False
|
||||
@@ -299,12 +300,12 @@ class PatchSysVolume:
|
||||
# Install RSRHelper utility to handle desynced KCs
|
||||
sys_patch_helpers.sys_patch_helpers(self.constants).install_rsr_repair_binary()
|
||||
|
||||
print("- Successfully built new kernel cache")
|
||||
logging.info("- Successfully built new kernel cache")
|
||||
return True
|
||||
|
||||
def create_new_apfs_snapshot(self):
|
||||
if self.root_supports_snapshot is True:
|
||||
print("- Creating new APFS snapshot")
|
||||
logging.info("- Creating new APFS snapshot")
|
||||
bless = utilities.elevated(
|
||||
[
|
||||
"bless",
|
||||
@@ -313,43 +314,43 @@ class PatchSysVolume:
|
||||
], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||
)
|
||||
if bless.returncode != 0:
|
||||
print("- Unable to create new snapshot")
|
||||
print("Reason for snapshot failure:")
|
||||
print(bless.stdout.decode())
|
||||
logging.info("- Unable to create new snapshot")
|
||||
logging.info("Reason for snapshot failure:")
|
||||
logging.info(bless.stdout.decode())
|
||||
if "Can't use last-sealed-snapshot or create-snapshot on non system volume" in bless.stdout.decode():
|
||||
print("- This is an APFS bug with Monterey and newer! Perform a clean installation to ensure your APFS volume is built correctly")
|
||||
logging.info("- This is an APFS bug with Monterey and newer! Perform a clean installation to ensure your APFS volume is built correctly")
|
||||
return False
|
||||
self.unmount_drive()
|
||||
return True
|
||||
|
||||
def unmount_drive(self):
|
||||
print("- Unmounting Root Volume (Don't worry if this fails)")
|
||||
logging.info("- Unmounting Root Volume (Don't worry if this fails)")
|
||||
utilities.elevated(["diskutil", "unmount", self.root_mount_path], stdout=subprocess.PIPE).stdout.decode().strip().encode()
|
||||
|
||||
def rebuild_dyld_shared_cache(self):
|
||||
if self.constants.detected_os <= os_data.os_data.catalina:
|
||||
print("- Rebuilding dyld shared cache")
|
||||
logging.info("- Rebuilding dyld shared cache")
|
||||
utilities.process_status(utilities.elevated(["update_dyld_shared_cache", "-root", f"{self.mount_location}/"]))
|
||||
|
||||
def update_preboot_kernel_cache(self):
|
||||
if self.constants.detected_os == os_data.os_data.catalina:
|
||||
print("- Rebuilding preboot kernel cache")
|
||||
logging.info("- Rebuilding preboot kernel cache")
|
||||
utilities.process_status(utilities.elevated(["kcditto"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
|
||||
def clean_skylight_plugins(self):
|
||||
if (Path(self.mount_application_support) / Path("SkyLightPlugins/")).exists():
|
||||
print("- Found SkylightPlugins folder, removing old plugins")
|
||||
logging.info("- Found SkylightPlugins folder, removing old plugins")
|
||||
utilities.process_status(utilities.elevated(["rm", "-Rf", f"{self.mount_application_support}/SkyLightPlugins"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
utilities.process_status(utilities.elevated(["mkdir", f"{self.mount_application_support}/SkyLightPlugins"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
else:
|
||||
print("- Creating SkylightPlugins folder")
|
||||
logging.info("- Creating SkylightPlugins folder")
|
||||
utilities.process_status(utilities.elevated(["mkdir", "-p", f"{self.mount_application_support}/SkyLightPlugins/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
|
||||
def delete_nonmetal_enforcement(self):
|
||||
for arg in ["useMetal", "useIOP"]:
|
||||
result = subprocess.run(["defaults", "read", "/Library/Preferences/com.apple.CoreDisplay", arg], stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
|
||||
if result in ["0", "false", "1", "true"]:
|
||||
print(f"- Removing non-Metal Enforcement Preference: {arg}")
|
||||
logging.info(f"- Removing non-Metal Enforcement Preference: {arg}")
|
||||
utilities.elevated(["defaults", "delete", "/Library/Preferences/com.apple.CoreDisplay", arg])
|
||||
|
||||
def clean_auxiliary_kc(self):
|
||||
@@ -360,7 +361,7 @@ class PatchSysVolume:
|
||||
if self.constants.detected_os < os_data.os_data.big_sur:
|
||||
return
|
||||
|
||||
print("- Cleaning Auxiliary Kernel Collection")
|
||||
logging.info("- Cleaning Auxiliary Kernel Collection")
|
||||
oclp_path = "/System/Library/CoreServices/OpenCore-Legacy-Patcher.plist"
|
||||
if Path(oclp_path).exists():
|
||||
oclp_plist_data = plistlib.load(Path(oclp_path).open("rb"))
|
||||
@@ -388,7 +389,7 @@ class PatchSysVolume:
|
||||
for file in Path("/Library/Extensions").glob("*.kext"):
|
||||
try:
|
||||
if datetime.fromtimestamp(file.stat().st_mtime) < datetime(2021, 10, 1):
|
||||
print(f" - Relocating {file.name} kext to {relocation_path}")
|
||||
logging.info(f" - Relocating {file.name} kext to {relocation_path}")
|
||||
if Path(relocation_path) / Path(file.name).exists():
|
||||
utilities.elevated(["rm", "-Rf", relocation_path / Path(file.name)])
|
||||
utilities.elevated(["mv", file, relocation_path])
|
||||
@@ -402,7 +403,7 @@ class PatchSysVolume:
|
||||
file_name = "OpenCore-Legacy-Patcher.plist"
|
||||
destination_path_file = f"{destination_path}/{file_name}"
|
||||
if sys_patch_helpers.sys_patch_helpers(self.constants).generate_patchset_plist(patchset, file_name, self.kdk_path):
|
||||
print("- Writing patchset information to Root Volume")
|
||||
logging.info("- Writing patchset information to Root Volume")
|
||||
if Path(destination_path_file).exists():
|
||||
utilities.process_status(utilities.elevated(["rm", destination_path_file], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
utilities.process_status(utilities.elevated(["cp", f"{self.constants.payload_path}/{file_name}", destination_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
@@ -429,7 +430,7 @@ class PatchSysVolume:
|
||||
|
||||
updated_install_location = str(self.mount_location_data) + "/Library/Extensions"
|
||||
|
||||
print(f" - Adding AuxKC support to {install_file}")
|
||||
logging.info(f" - Adding AuxKC support to {install_file}")
|
||||
plist_path = Path(Path(source_folder_path) / Path(install_file) / Path("Contents/Info.plist"))
|
||||
plist_data = plistlib.load((plist_path).open("rb"))
|
||||
|
||||
@@ -466,11 +467,11 @@ class PatchSysVolume:
|
||||
except PermissionError:
|
||||
pass
|
||||
|
||||
print(f" - {kext_name} requires authentication in System Preferences")
|
||||
logging.info(f" - {kext_name} requires authentication in System Preferences")
|
||||
self.constants.needs_to_open_preferences = True # Notify in GUI to open System Preferences
|
||||
|
||||
def patch_root_vol(self):
|
||||
print(f"- Running patches for {self.model}")
|
||||
logging.info(f"- Running patches for {self.model}")
|
||||
if self.patch_set_dictionary != {}:
|
||||
self.execute_patchset(self.patch_set_dictionary)
|
||||
else:
|
||||
@@ -485,10 +486,10 @@ class PatchSysVolume:
|
||||
source_files_path = str(self.constants.payload_local_binaries_root_path)
|
||||
self.preflight_checks(required_patches, source_files_path)
|
||||
for patch in required_patches:
|
||||
print("- Installing Patchset: " + patch)
|
||||
logging.info("- Installing Patchset: " + patch)
|
||||
if "Remove" in required_patches[patch]:
|
||||
for remove_patch_directory in required_patches[patch]["Remove"]:
|
||||
print("- Remove Files at: " + remove_patch_directory)
|
||||
logging.info("- Remove Files at: " + remove_patch_directory)
|
||||
for remove_patch_file in required_patches[patch]["Remove"][remove_patch_directory]:
|
||||
destination_folder_path = str(self.mount_location) + remove_patch_directory
|
||||
self.remove_file(destination_folder_path, remove_patch_file)
|
||||
@@ -497,7 +498,7 @@ class PatchSysVolume:
|
||||
for method_install in ["Install", "Install Non-Root"]:
|
||||
if method_install in required_patches[patch]:
|
||||
for install_patch_directory in list(required_patches[patch][method_install]):
|
||||
print(f"- Handling Installs in: {install_patch_directory}")
|
||||
logging.info(f"- Handling Installs in: {install_patch_directory}")
|
||||
for install_file in list(required_patches[patch][method_install][install_patch_directory]):
|
||||
source_folder_path = source_files_path + "/" + required_patches[patch][method_install][install_patch_directory][install_file] + install_patch_directory
|
||||
if method_install == "Install":
|
||||
@@ -526,10 +527,10 @@ class PatchSysVolume:
|
||||
# Some processes need sudo, however we cannot directly call sudo in some scenarios
|
||||
# Instead, call elevated funtion if string's boolean is True
|
||||
if required_patches[patch]["Processes"][process] is True:
|
||||
print(f"- Running Process as Root:\n{process}")
|
||||
logging.info(f"- Running Process as Root:\n{process}")
|
||||
utilities.process_status(utilities.elevated(process.split(" "), stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
else:
|
||||
print(f"- Running Process:\n{process}")
|
||||
logging.info(f"- Running Process:\n{process}")
|
||||
utilities.process_status(subprocess.run(process, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True))
|
||||
if any(x in required_patches for x in ["AMD Legacy GCN", "AMD Legacy Polaris", "AMD Legacy Vega"]):
|
||||
sys_patch_helpers.sys_patch_helpers(self.constants).disable_window_server_caching()
|
||||
@@ -538,7 +539,7 @@ class PatchSysVolume:
|
||||
self.write_patchset(required_patches)
|
||||
|
||||
def preflight_checks(self, required_patches, source_files_path):
|
||||
print("- Running Preflight Checks before patching")
|
||||
logging.info("- Running Preflight Checks before patching")
|
||||
|
||||
# Make sure old SkyLight plugins aren't being used
|
||||
self.clean_skylight_plugins()
|
||||
@@ -567,7 +568,7 @@ class PatchSysVolume:
|
||||
should_save_cs = True
|
||||
self.merge_kdk_with_root(save_hid_cs=should_save_cs)
|
||||
|
||||
print("- Finished Preflight, starting patching")
|
||||
logging.info("- Finished Preflight, starting patching")
|
||||
|
||||
def install_new_file(self, source_folder, destination_folder, file_name):
|
||||
# .frameworks are merged
|
||||
@@ -575,36 +576,36 @@ class PatchSysVolume:
|
||||
file_name_str = str(file_name)
|
||||
|
||||
if not Path(destination_folder).exists():
|
||||
print(f" - Skipping {file_name}, cannot locate {source_folder}")
|
||||
logging.info(f" - Skipping {file_name}, cannot locate {source_folder}")
|
||||
return
|
||||
|
||||
if file_name_str.endswith(".framework"):
|
||||
# merge with rsync
|
||||
print(f" - Installing: {file_name}")
|
||||
logging.info(f" - Installing: {file_name}")
|
||||
utilities.elevated(["rsync", "-r", "-i", "-a", f"{source_folder}/{file_name}", f"{destination_folder}/"], stdout=subprocess.PIPE)
|
||||
self.fix_permissions(destination_folder + "/" + file_name)
|
||||
elif Path(source_folder + "/" + file_name_str).is_dir():
|
||||
# Applicable for .kext, .app, .plugin, .bundle, all of which are directories
|
||||
if Path(destination_folder + "/" + file_name).exists():
|
||||
print(f" - Found existing {file_name}, overwriting...")
|
||||
logging.info(f" - Found existing {file_name}, overwriting...")
|
||||
utilities.process_status(utilities.elevated(["rm", "-R", f"{destination_folder}/{file_name}"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
else:
|
||||
print(f" - Installing: {file_name}")
|
||||
logging.info(f" - Installing: {file_name}")
|
||||
utilities.process_status(utilities.elevated(["cp", "-R", f"{source_folder}/{file_name}", destination_folder], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
self.fix_permissions(destination_folder + "/" + file_name)
|
||||
else:
|
||||
# Assume it's an individual file, replace as normal
|
||||
if Path(destination_folder + "/" + file_name).exists():
|
||||
print(f" - Found existing {file_name}, overwriting...")
|
||||
logging.info(f" - Found existing {file_name}, overwriting...")
|
||||
utilities.process_status(utilities.elevated(["rm", f"{destination_folder}/{file_name}"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
else:
|
||||
print(f" - Installing: {file_name}")
|
||||
logging.info(f" - Installing: {file_name}")
|
||||
utilities.process_status(utilities.elevated(["cp", f"{source_folder}/{file_name}", destination_folder], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
self.fix_permissions(destination_folder + "/" + file_name)
|
||||
|
||||
def remove_file(self, destination_folder, file_name):
|
||||
if Path(destination_folder + "/" + file_name).exists():
|
||||
print(f" - Removing: {file_name}")
|
||||
logging.info(f" - Removing: {file_name}")
|
||||
if Path(destination_folder + "/" + file_name).is_dir():
|
||||
utilities.process_status(utilities.elevated(["rm", "-R", f"{destination_folder}/{file_name}"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
else:
|
||||
@@ -624,7 +625,7 @@ class PatchSysVolume:
|
||||
|
||||
def check_files(self):
|
||||
if Path(self.constants.payload_local_binaries_root_path).exists():
|
||||
print("- Found local Apple Binaries")
|
||||
logging.info("- Found local Apple Binaries")
|
||||
if self.constants.gui_mode is False:
|
||||
patch_input = input("Would you like to redownload?(y/n): ")
|
||||
if patch_input in {"y", "Y", "yes", "Yes"}:
|
||||
@@ -646,65 +647,65 @@ class PatchSysVolume:
|
||||
link = sys_patch_download.grab_patcher_support_pkg(self.constants).generate_pkg_link()
|
||||
|
||||
if download_result and self.constants.payload_local_binaries_root_path_zip.exists():
|
||||
print("- Unzipping binaries...")
|
||||
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))
|
||||
print("- Binaries downloaded to:")
|
||||
print(self.constants.payload_path)
|
||||
logging.info("- Binaries downloaded to:")
|
||||
logging.info(self.constants.payload_path)
|
||||
return self.constants.payload_local_binaries_root_path
|
||||
else:
|
||||
if self.constants.gui_mode is True:
|
||||
print("- Download failed, please verify the below link work:")
|
||||
print(link)
|
||||
print("\nIf you continue to have issues, try using the Offline builds")
|
||||
print("located on Github next to the other builds")
|
||||
logging.info("- Download failed, please verify the below link work:")
|
||||
logging.info(link)
|
||||
logging.info("\nIf you continue to have issues, try using the Offline builds")
|
||||
logging.info("located on Github next to the other builds")
|
||||
else:
|
||||
input("\nPress enter to continue")
|
||||
return None
|
||||
|
||||
# Entry Function
|
||||
def start_patch(self):
|
||||
print("- Starting Patch Process")
|
||||
print(f"- Determining Required Patch set for Darwin {self.constants.detected_os}")
|
||||
logging.info("- Starting Patch Process")
|
||||
logging.info(f"- Determining Required Patch set for Darwin {self.constants.detected_os}")
|
||||
self.patch_set_dictionary = sys_patch_detect.detect_root_patch(self.computer.real_model, self.constants).generate_patchset(self.hardware_details)
|
||||
|
||||
if self.patch_set_dictionary == {}:
|
||||
change_menu = None
|
||||
print("- No Root Patches required for your machine!")
|
||||
logging.info("- No Root Patches required for your machine!")
|
||||
if self.constants.gui_mode is False:
|
||||
input("\nPress [ENTER] to return to the main menu: ")
|
||||
elif self.constants.gui_mode is False:
|
||||
change_menu = input("Would you like to continue with Root Volume Patching?(y/n): ")
|
||||
else:
|
||||
change_menu = "y"
|
||||
print("- Continuing root patching")
|
||||
logging.info("- Continuing root patching")
|
||||
if change_menu in ["y", "Y"]:
|
||||
print("- Verifying whether Root Patching possible")
|
||||
logging.info("- Verifying whether Root Patching possible")
|
||||
if sys_patch_detect.detect_root_patch(self.computer.real_model, self.constants).verify_patch_allowed(print_errors=not self.constants.wxpython_variant) is True:
|
||||
print("- Patcher is capable of patching")
|
||||
logging.info("- Patcher is capable of patching")
|
||||
if self.check_files():
|
||||
if self.mount_root_vol() is True:
|
||||
self.patch_root_vol()
|
||||
if self.constants.gui_mode is False:
|
||||
input("\nPress [ENTER] to return to the main menu")
|
||||
else:
|
||||
print("- Recommend rebooting the machine and trying to patch again")
|
||||
logging.info("- Recommend rebooting the machine and trying to patch again")
|
||||
if self.constants.gui_mode is False:
|
||||
input("- Press [ENTER] to exit: ")
|
||||
elif self.constants.gui_mode is False:
|
||||
input("\nPress [ENTER] to return to the main menu: ")
|
||||
|
||||
else:
|
||||
print("- Returning to main menu")
|
||||
logging.info("- Returning to main menu")
|
||||
|
||||
def start_unpatch(self):
|
||||
print("- Starting Unpatch Process")
|
||||
logging.info("- Starting Unpatch Process")
|
||||
if sys_patch_detect.detect_root_patch(self.computer.real_model, self.constants).verify_patch_allowed(print_errors=True) is True:
|
||||
if self.mount_root_vol() is True:
|
||||
self.unpatch_root_vol()
|
||||
if self.constants.gui_mode is False:
|
||||
input("\nPress [ENTER] to return to the main menu")
|
||||
else:
|
||||
print("- Recommend rebooting the machine and trying to patch again")
|
||||
logging.info("- Recommend rebooting the machine and trying to patch again")
|
||||
if self.constants.gui_mode is False:
|
||||
input("- Press [ENTER] to exit: ")
|
||||
elif self.constants.gui_mode is False:
|
||||
|
||||
@@ -12,6 +12,7 @@ from pathlib import Path
|
||||
import plistlib
|
||||
import subprocess
|
||||
import webbrowser
|
||||
import logging
|
||||
from resources import utilities, updates, global_settings
|
||||
from resources.sys_patch import sys_patch_detect
|
||||
from resources.gui import gui_main
|
||||
@@ -23,23 +24,23 @@ class AutomaticSysPatch:
|
||||
|
||||
|
||||
def start_auto_patch(self):
|
||||
print("- Starting Automatic Patching")
|
||||
logging.info("- Starting Automatic Patching")
|
||||
if self.constants.wxpython_variant is False:
|
||||
print("- Auto Patch option is not supported on TUI, please use GUI")
|
||||
logging.info("- Auto Patch option is not supported on TUI, please use GUI")
|
||||
return
|
||||
|
||||
if utilities.check_seal() is True:
|
||||
print("- Detected Snapshot seal intact, detecting patches")
|
||||
logging.info("- Detected Snapshot seal intact, detecting patches")
|
||||
patches = sys_patch_detect.detect_root_patch(self.constants.computer.real_model, self.constants).detect_patch_set()
|
||||
if not any(not patch.startswith("Settings") and not patch.startswith("Validation") and patches[patch] is True for patch in patches):
|
||||
patches = []
|
||||
if patches:
|
||||
print("- Detected applicable patches, determining whether possible to patch")
|
||||
logging.info("- Detected applicable patches, determining whether possible to patch")
|
||||
if patches["Validation: Patching Possible"] is False:
|
||||
print("- Cannot run patching")
|
||||
logging.info("- Cannot run patching")
|
||||
return
|
||||
|
||||
print("- Determined patching is possible, checking for OCLP updates")
|
||||
logging.info("- Determined patching is possible, checking for OCLP updates")
|
||||
patch_string = ""
|
||||
for patch in patches:
|
||||
if patches[patch] is True and not patch.startswith("Settings") and not patch.startswith("Validation"):
|
||||
@@ -47,7 +48,7 @@ class AutomaticSysPatch:
|
||||
# Check for updates
|
||||
dict = updates.check_binary_updates(self.constants).check_binary_updates()
|
||||
if not dict:
|
||||
print("- 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:
|
||||
args_string = f"'{self.constants.launcher_binary}' --gui_patch"
|
||||
else:
|
||||
@@ -87,7 +88,7 @@ class AutomaticSysPatch:
|
||||
for key in dict:
|
||||
version = dict[key]["Version"]
|
||||
github_link = dict[key]["Github Link"]
|
||||
print(f"- Found new version: {version}")
|
||||
logging.info(f"- Found new version: {version}")
|
||||
|
||||
# launch osascript to ask user if they want to apply the update
|
||||
# if yes, open the link in the default browser
|
||||
@@ -108,29 +109,29 @@ class AutomaticSysPatch:
|
||||
|
||||
return
|
||||
else:
|
||||
print("- No patches detected")
|
||||
logging.info("- No patches detected")
|
||||
else:
|
||||
print("- Detected Snapshot seal not intact, skipping")
|
||||
logging.info("- Detected Snapshot seal not intact, skipping")
|
||||
|
||||
if self.determine_if_versions_match() is False:
|
||||
self.determine_if_boot_matches()
|
||||
|
||||
|
||||
def determine_if_versions_match(self):
|
||||
print("- Checking booted vs installed OCLP Build")
|
||||
logging.info("- Checking booted vs installed OCLP Build")
|
||||
if self.constants.computer.oclp_version is None:
|
||||
print("- Booted version not found")
|
||||
logging.info("- Booted version not found")
|
||||
return False
|
||||
|
||||
if self.constants.computer.oclp_version == self.constants.patcher_version:
|
||||
print("- Versions match")
|
||||
logging.info("- Versions match")
|
||||
return False
|
||||
|
||||
# Check if installed version is newer than booted version
|
||||
if updates.check_binary_updates(self.constants).check_if_build_newer(
|
||||
self.constants.computer.oclp_version.split("."), self.constants.patcher_version.split(".")
|
||||
) is True:
|
||||
print("- Installed version is newer than booted version")
|
||||
logging.info("- Installed version is newer than booted version")
|
||||
return False
|
||||
|
||||
args = [
|
||||
@@ -145,7 +146,7 @@ class AutomaticSysPatch:
|
||||
stderr=subprocess.STDOUT
|
||||
)
|
||||
if output.returncode == 0:
|
||||
print("- Launching GUI's Build/Install menu")
|
||||
logging.info("- Launching GUI's Build/Install menu")
|
||||
self.constants.start_build_install = True
|
||||
gui_main.wx_python_gui(self.constants).main_menu(None)
|
||||
|
||||
@@ -159,31 +160,31 @@ class AutomaticSysPatch:
|
||||
# If we determine them to be mismatched, notify the user
|
||||
# and ask if they want to install to install to disk
|
||||
|
||||
print("- Determining if macOS drive matches boot drive")
|
||||
logging.info("- Determining if macOS drive matches boot drive")
|
||||
should_notify = global_settings.global_settings().read_property("AutoPatch_Notify_Mismatched_Disks")
|
||||
if should_notify is False:
|
||||
print("- Skipping due to user preference")
|
||||
logging.info("- Skipping due to user preference")
|
||||
return
|
||||
if self.constants.host_is_hackintosh is True:
|
||||
print("- Skipping due to hackintosh")
|
||||
logging.info("- Skipping due to hackintosh")
|
||||
return
|
||||
if not self.constants.booted_oc_disk:
|
||||
print("- Failed to find disk OpenCore launched from")
|
||||
logging.info("- Failed to find disk OpenCore launched from")
|
||||
return
|
||||
|
||||
root_disk = self.constants.booted_oc_disk.strip("disk")
|
||||
root_disk = "disk" + root_disk.split("s")[0]
|
||||
|
||||
print(f" - Boot Drive: {self.constants.booted_oc_disk} ({root_disk})")
|
||||
logging.info(f" - Boot Drive: {self.constants.booted_oc_disk} ({root_disk})")
|
||||
macOS_disk = utilities.get_disk_path()
|
||||
print(f" - macOS Drive: {macOS_disk}")
|
||||
logging.info(f" - macOS Drive: {macOS_disk}")
|
||||
physical_stores = utilities.find_apfs_physical_volume(macOS_disk)
|
||||
print(f" - APFS Physical Stores: {physical_stores}")
|
||||
logging.info(f" - APFS Physical Stores: {physical_stores}")
|
||||
|
||||
disk_match = False
|
||||
for disk in physical_stores:
|
||||
if root_disk in disk:
|
||||
print(f"- Boot drive matches macOS drive ({disk})")
|
||||
logging.info(f"- Boot drive matches macOS drive ({disk})")
|
||||
disk_match = True
|
||||
break
|
||||
|
||||
@@ -191,15 +192,15 @@ class AutomaticSysPatch:
|
||||
return
|
||||
|
||||
# Check if OpenCore is on a USB drive
|
||||
print("- Boot Drive does not match macOS drive, checking if OpenCore is on a USB drive")
|
||||
logging.info("- Boot Drive does not match macOS drive, checking if OpenCore is on a USB drive")
|
||||
|
||||
disk_info = plistlib.loads(subprocess.run(["diskutil", "info", "-plist", root_disk], stdout=subprocess.PIPE).stdout)
|
||||
try:
|
||||
if disk_info["Ejectable"] is False:
|
||||
print("- Boot Disk is not removable, skipping prompt")
|
||||
logging.info("- Boot Disk is not removable, skipping prompt")
|
||||
return
|
||||
|
||||
print("- Boot Disk is ejectable, prompting user to install to internal")
|
||||
logging.info("- Boot Disk is ejectable, prompting user to install to internal")
|
||||
|
||||
args = [
|
||||
"osascript",
|
||||
@@ -213,12 +214,12 @@ class AutomaticSysPatch:
|
||||
stderr=subprocess.STDOUT
|
||||
)
|
||||
if output.returncode == 0:
|
||||
print("- Launching GUI's Build/Install menu")
|
||||
logging.info("- Launching GUI's Build/Install menu")
|
||||
self.constants.start_build_install = True
|
||||
gui_main.wx_python_gui(self.constants).main_menu(None)
|
||||
|
||||
except KeyError:
|
||||
print("- Unable to determine if boot disk is removable, skipping prompt")
|
||||
logging.info("- Unable to determine if boot disk is removable, skipping prompt")
|
||||
|
||||
|
||||
def install_auto_patcher_launch_agent(self):
|
||||
@@ -226,52 +227,52 @@ class AutomaticSysPatch:
|
||||
# - OpenCore-Patcher.app in /Library/Application Support/Dortania/
|
||||
# - com.dortania.opencore-legacy-patcher.auto-patch.plist in /Library/LaunchAgents/
|
||||
if self.constants.launcher_script is not None:
|
||||
print("- Skipping Auto Patcher Launch Agent, not supported when running from source")
|
||||
logging.info("- Skipping Auto Patcher Launch Agent, not supported when running from source")
|
||||
return
|
||||
|
||||
if self.constants.launcher_binary.startswith("/Library/Application Support/Dortania/"):
|
||||
print("- Skipping Auto Patcher Launch Agent, already installed")
|
||||
logging.info("- Skipping Auto Patcher Launch Agent, already installed")
|
||||
return
|
||||
|
||||
# Verify our binary isn't located in '/Library/Application Support/Dortania/'
|
||||
# As we'd simply be duplicating ourselves
|
||||
print("- Installing Auto Patcher Launch Agent")
|
||||
logging.info("- Installing Auto Patcher Launch Agent")
|
||||
|
||||
if not Path("Library/Application Support/Dortania").exists():
|
||||
print("- Creating /Library/Application Support/Dortania/")
|
||||
logging.info("- Creating /Library/Application Support/Dortania/")
|
||||
utilities.process_status(utilities.elevated(["mkdir", "-p", "/Library/Application Support/Dortania"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
|
||||
print("- Copying OpenCore Patcher to /Library/Application Support/Dortania/")
|
||||
logging.info("- Copying OpenCore Patcher to /Library/Application Support/Dortania/")
|
||||
if Path("/Library/Application Support/Dortania/OpenCore-Patcher.app").exists():
|
||||
print("- Deleting existing OpenCore-Patcher")
|
||||
logging.info("- Deleting existing OpenCore-Patcher")
|
||||
utilities.process_status(utilities.elevated(["rm", "-R", "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
|
||||
# Strip everything after OpenCore-Patcher.app
|
||||
path = str(self.constants.launcher_binary).split("/Contents/MacOS/OpenCore-Patcher")[0]
|
||||
print(f"- Copying {path} to /Library/Application Support/Dortania/")
|
||||
logging.info(f"- Copying {path} to /Library/Application Support/Dortania/")
|
||||
utilities.process_status(utilities.elevated(["ditto", path, "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
|
||||
if not Path("/Library/Application Support/Dortania/OpenCore-Patcher.app").exists():
|
||||
# Sometimes the binary the user launches may have a suffix (ie. OpenCore-Patcher 3.app)
|
||||
# We'll want to rename it to OpenCore-Patcher.app
|
||||
path = path.split("/")[-1]
|
||||
print(f"- Renaming {path} to OpenCore-Patcher.app")
|
||||
logging.info(f"- Renaming {path} to OpenCore-Patcher.app")
|
||||
utilities.process_status(utilities.elevated(["mv", f"/Library/Application Support/Dortania/{path}", "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
|
||||
subprocess.run(["xattr", "-cr", "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
# Copy over our launch agent
|
||||
print("- Copying auto-patch.plist Launch Agent to /Library/LaunchAgents/")
|
||||
logging.info("- Copying auto-patch.plist Launch Agent to /Library/LaunchAgents/")
|
||||
if Path("/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist").exists():
|
||||
print("- Deleting existing auto-patch.plist")
|
||||
logging.info("- Deleting existing auto-patch.plist")
|
||||
utilities.process_status(utilities.elevated(["rm", "/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
if not Path("/Library/LaunchAgents/").exists():
|
||||
print("- Creating /Library/LaunchAgents/")
|
||||
logging.info("- Creating /Library/LaunchAgents/")
|
||||
utilities.process_status(utilities.elevated(["mkdir", "-p", "/Library/LaunchAgents/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
utilities.process_status(utilities.elevated(["cp", self.constants.auto_patch_launch_agent_path, "/Library/LaunchAgents/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
|
||||
# Set the permissions on the com.dortania.opencore-legacy-patcher.auto-patch.plist
|
||||
print("- Setting permissions on auto-patch.plist")
|
||||
logging.info("- Setting permissions on auto-patch.plist")
|
||||
utilities.process_status(utilities.elevated(["chmod", "644", "/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
utilities.process_status(utilities.elevated(["chown", "root:wheel", "/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
|
||||
@@ -279,5 +280,5 @@ class AutomaticSysPatch:
|
||||
# Simply an easy way for users to notice the app
|
||||
# If there's already an alias or exiting app, skip
|
||||
if not Path("/Applications/OpenCore-Patcher.app").exists():
|
||||
print("- Making app alias")
|
||||
logging.info("- Making app alias")
|
||||
utilities.process_status(utilities.elevated(["ln", "-s", "/Library/Application Support/Dortania/OpenCore-Patcher.app", "/Applications/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
@@ -10,6 +10,7 @@ from data import model_array, os_data, sip_data, sys_patch_dict, smbios_data, cp
|
||||
import py_sip_xnu
|
||||
from pathlib import Path
|
||||
import plistlib
|
||||
import logging
|
||||
|
||||
class detect_root_patch:
|
||||
def __init__(self, model, versions):
|
||||
@@ -67,7 +68,7 @@ class detect_root_patch:
|
||||
non_metal_os = os_data.os_data.catalina
|
||||
for i, gpu in enumerate(gpus):
|
||||
if gpu.class_code and gpu.class_code != 0xFFFFFFFF:
|
||||
print(f"- Found GPU ({i}): {utilities.friendly_hex(gpu.vendor_id)}:{utilities.friendly_hex(gpu.device_id)}")
|
||||
logging.info(f"- Found GPU ({i}): {utilities.friendly_hex(gpu.vendor_id)}:{utilities.friendly_hex(gpu.device_id)}")
|
||||
if gpu.arch in [device_probe.NVIDIA.Archs.Tesla] and self.constants.force_nv_web is False:
|
||||
if self.constants.detected_os > non_metal_os:
|
||||
self.nvidia_tesla = True
|
||||
@@ -510,50 +511,50 @@ class detect_root_patch:
|
||||
|
||||
if print_errors is True:
|
||||
if self.sip_enabled is True:
|
||||
print("\nCannot patch! Please disable System Integrity Protection (SIP).")
|
||||
print("Disable SIP in Patcher Settings and Rebuild OpenCore\n")
|
||||
print("Ensure the following bits are set for csr-active-config:")
|
||||
print("\n".join(sip))
|
||||
print(sip_value)
|
||||
logging.info("\nCannot patch! Please disable System Integrity Protection (SIP).")
|
||||
logging.info("Disable SIP in Patcher Settings and Rebuild OpenCore\n")
|
||||
logging.info("Ensure the following bits are set for csr-active-config:")
|
||||
logging.info("\n".join(sip))
|
||||
logging.info(sip_value)
|
||||
|
||||
if self.sbm_enabled is True:
|
||||
print("\nCannot patch! Please disable Apple Secure Boot.")
|
||||
print("Disable SecureBootModel in Patcher Settings and Rebuild OpenCore")
|
||||
print("For Hackintoshes, set SecureBootModel to Disabled")
|
||||
logging.info("\nCannot patch! Please disable Apple Secure Boot.")
|
||||
logging.info("Disable SecureBootModel in Patcher Settings and Rebuild OpenCore")
|
||||
logging.info("For Hackintoshes, set SecureBootModel to Disabled")
|
||||
|
||||
if self.fv_enabled is True:
|
||||
print("\nCannot patch! Please disable FileVault.")
|
||||
print("For OCLP Macs, please rebuild your config with 0.2.5 or newer")
|
||||
print("For others, Go to System Preferences -> Security and disable FileVault")
|
||||
logging.info("\nCannot patch! Please disable FileVault.")
|
||||
logging.info("For OCLP Macs, please rebuild your config with 0.2.5 or newer")
|
||||
logging.info("For others, Go to System Preferences -> Security and disable FileVault")
|
||||
|
||||
if self.amfi_enabled is True and self.amfi_must_disable is True:
|
||||
print("\nCannot patch! Please disable AMFI.")
|
||||
print("For Hackintoshes, please add amfi_get_out_of_my_way=1 to boot-args")
|
||||
logging.info("\nCannot patch! Please disable AMFI.")
|
||||
logging.info("For Hackintoshes, please add amfi_get_out_of_my_way=1 to boot-args")
|
||||
|
||||
if self.dosdude_patched is True:
|
||||
print("\nCannot patch! Detected machine has already been patched by another patcher")
|
||||
print("Please ensure your install is either clean or patched with OpenCore Legacy Patcher")
|
||||
logging.info("\nCannot patch! Detected machine has already been patched by another patcher")
|
||||
logging.info("Please ensure your install is either clean or patched with OpenCore Legacy Patcher")
|
||||
|
||||
if self.nvidia_web is True:
|
||||
if self.missing_nv_web_opengl is True:
|
||||
print("\nCannot patch! Force OpenGL property missing")
|
||||
print("Please ensure ngfxgl=1 is set in boot-args")
|
||||
logging.info("\nCannot patch! Force OpenGL property missing")
|
||||
logging.info("Please ensure ngfxgl=1 is set in boot-args")
|
||||
|
||||
if self.missing_nv_compat is True:
|
||||
print("\nCannot patch! Force Nvidia compatibility property missing")
|
||||
print("Please ensure ngfxcompat=1 is set in boot-args")
|
||||
logging.info("\nCannot patch! Force Nvidia compatibility property missing")
|
||||
logging.info("Please ensure ngfxcompat=1 is set in boot-args")
|
||||
|
||||
if self.missing_nv_web_nvram is True:
|
||||
print("\nCannot patch! nvda_drv(_vrl) variable missing")
|
||||
print("Please ensure nvda_drv_vrl=1 is set in boot-args")
|
||||
logging.info("\nCannot patch! nvda_drv(_vrl) variable missing")
|
||||
logging.info("Please ensure nvda_drv_vrl=1 is set in boot-args")
|
||||
|
||||
if self.missing_whatever_green is True:
|
||||
print("\nCannot patch! WhateverGreen.kext missing")
|
||||
print("Please ensure WhateverGreen.kext is installed")
|
||||
logging.info("\nCannot patch! WhateverGreen.kext missing")
|
||||
logging.info("Please ensure WhateverGreen.kext is installed")
|
||||
|
||||
if (not self.has_network) if (self.requires_root_kc and self.missing_kdk and self.constants.detected_os >= os_data.os_data.ventura.value) else False:
|
||||
print("\nCannot patch! Network Connection Required")
|
||||
print("Please ensure you have an active internet connection")
|
||||
logging.info("\nCannot patch! Network Connection Required")
|
||||
logging.info("Please ensure you have an active internet connection")
|
||||
|
||||
if any(
|
||||
[
|
||||
@@ -581,7 +582,7 @@ class detect_root_patch:
|
||||
all_hardware_patchset = sys_patch_dict.SystemPatchDictionary(self.constants.detected_os, self.constants.detected_os_minor, self.constants.legacy_accel_support)
|
||||
required_patches = {}
|
||||
utilities.cls()
|
||||
print("- The following patches will be applied:")
|
||||
logging.info("- The following patches will be applied:")
|
||||
if hardware_details["Graphics: Intel Ironlake"] is True:
|
||||
required_patches.update({"Non-Metal Common": all_hardware_patchset["Graphics"]["Non-Metal Common"]})
|
||||
required_patches.update({"WebKit Monterey Common": all_hardware_patchset["Graphics"]["WebKit Monterey Common"]})
|
||||
@@ -700,8 +701,8 @@ class detect_root_patch:
|
||||
del(required_patches[patch_name])
|
||||
else:
|
||||
if required_patches[patch_name]["Display Name"]:
|
||||
print(f" - {required_patches[patch_name]['Display Name']}")
|
||||
logging.info(f" - {required_patches[patch_name]['Display Name']}")
|
||||
else:
|
||||
print(" - No patch sets found for booted model")
|
||||
logging.info(" - No patch sets found for booted model")
|
||||
|
||||
return required_patches
|
||||
@@ -4,6 +4,7 @@
|
||||
from resources import utilities
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import logging
|
||||
|
||||
class grab_patcher_support_pkg:
|
||||
|
||||
@@ -17,16 +18,16 @@ class grab_patcher_support_pkg:
|
||||
def download_files(self):
|
||||
link = self.generate_pkg_link()
|
||||
if Path(self.constants.payload_local_binaries_root_path).exists():
|
||||
print("- Removing old Root Patcher Payload folder")
|
||||
logging.info("- Removing old Root Patcher Payload folder")
|
||||
# Delete folder
|
||||
shutil.rmtree(self.constants.payload_local_binaries_root_path)
|
||||
|
||||
download_result = None
|
||||
if Path(self.constants.payload_local_binaries_root_path_zip).exists():
|
||||
print(f"- Found local Universal-Binaries.zip, skipping download")
|
||||
logging.info(f"- Found local Universal-Binaries.zip, skipping download")
|
||||
download_result = True
|
||||
else:
|
||||
print(f"- No local version found, downloading...")
|
||||
logging.info(f"- No local version found, downloading...")
|
||||
download_result = utilities.download_file(link, self.constants.payload_local_binaries_root_path_zip)
|
||||
|
||||
return download_result, link
|
||||
@@ -9,6 +9,7 @@ from pathlib import Path
|
||||
from datetime import datetime
|
||||
import plistlib
|
||||
import os
|
||||
import logging
|
||||
|
||||
from resources import constants, bplist
|
||||
|
||||
@@ -25,9 +26,9 @@ class sys_patch_helpers:
|
||||
# to supplement the ideal Board ID
|
||||
source_files_path = str(source_files_path)
|
||||
if self.constants.computer.reported_board_id not in self.constants.sandy_board_id_stock:
|
||||
print(f"- Found unsupported Board ID {self.constants.computer.reported_board_id}, performing AppleIntelSNBGraphicsFB bin patching")
|
||||
logging.info(f"- Found unsupported Board ID {self.constants.computer.reported_board_id}, performing AppleIntelSNBGraphicsFB bin patching")
|
||||
board_to_patch = generate_smbios.determine_best_board_id_for_sandy(self.constants.computer.reported_board_id, self.constants.computer.gpus)
|
||||
print(f"- Replacing {board_to_patch} with {self.constants.computer.reported_board_id}")
|
||||
logging.info(f"- Replacing {board_to_patch} with {self.constants.computer.reported_board_id}")
|
||||
|
||||
board_to_patch_hex = bytes.fromhex(board_to_patch.encode('utf-8').hex())
|
||||
reported_board_hex = bytes.fromhex(self.constants.computer.reported_board_id.encode('utf-8').hex())
|
||||
@@ -36,7 +37,7 @@ class sys_patch_helpers:
|
||||
# Pad the reported Board ID with zeros to match the length of the board to patch
|
||||
reported_board_hex = reported_board_hex + bytes(len(board_to_patch_hex) - len(reported_board_hex))
|
||||
elif len(board_to_patch_hex) < len(reported_board_hex):
|
||||
print(f"- Error: Board ID {self.constants.computer.reported_board_id} is longer than {board_to_patch}")
|
||||
logging.info(f"- Error: Board ID {self.constants.computer.reported_board_id} is longer than {board_to_patch}")
|
||||
raise Exception("Host's Board ID is longer than the kext's Board ID, cannot patch!!!")
|
||||
|
||||
path = source_files_path + "/10.13.6/System/Library/Extensions/AppleIntelSNBGraphicsFB.kext/Contents/MacOS/AppleIntelSNBGraphicsFB"
|
||||
@@ -47,7 +48,7 @@ class sys_patch_helpers:
|
||||
with open(path, 'wb') as f:
|
||||
f.write(data)
|
||||
else:
|
||||
print(f"- Error: Could not find {path}")
|
||||
logging.info(f"- Error: Could not find {path}")
|
||||
raise Exception("Failed to find AppleIntelSNBGraphicsFB.kext, cannot patch!!!")
|
||||
|
||||
|
||||
@@ -80,7 +81,7 @@ class sys_patch_helpers:
|
||||
if not self.constants.kdk_download_path.exists():
|
||||
return
|
||||
|
||||
print(f"- Installing downloaded KDK (this may take a while)")
|
||||
logging.info(f"- Installing downloaded KDK (this may take a while)")
|
||||
with tempfile.TemporaryDirectory() as mount_point:
|
||||
utilities.process_status(subprocess.run(["hdiutil", "attach", self.constants.kdk_download_path, "-mountpoint", mount_point, "-nobrowse"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
# Due to a permissions bug in macOS, sometimes the OS will fail on a Read-only file system error
|
||||
@@ -92,15 +93,15 @@ class sys_patch_helpers:
|
||||
utilities.process_status(subprocess.run(["cp", f"{mount_point}/KernelDebugKit.pkg", self.constants.payload_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
result = utilities.elevated(["installer", "-pkg", kdk_dst_path, "-target", "/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if result.returncode != 0:
|
||||
print("- Failed to install KDK:")
|
||||
print(result.stdout.decode('utf-8'))
|
||||
logging.info("- Failed to install KDK:")
|
||||
logging.info(result.stdout.decode('utf-8'))
|
||||
if result.stderr:
|
||||
print(result.stderr.decode('utf-8'))
|
||||
logging.info(result.stderr.decode('utf-8'))
|
||||
utilities.elevated(["hdiutil", "detach", mount_point], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
raise Exception("Failed to install KDK")
|
||||
utilities.process_status(utilities.elevated(["rm", kdk_dst_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
|
||||
utilities.elevated(["hdiutil", "detach", mount_point], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
print("- Successfully installed KDK")
|
||||
logging.info("- Successfully installed KDK")
|
||||
|
||||
|
||||
def determine_kdk_present(self, match_closest=False, override_build=None):
|
||||
@@ -138,7 +139,7 @@ class sys_patch_helpers:
|
||||
|
||||
if match_closest is True:
|
||||
result = os_data.os_conversion.find_largest_build(kdk_array)
|
||||
print(f"- Closest KDK match to {search_build}: {result}")
|
||||
logging.info(f"- Closest KDK match to {search_build}: {result}")
|
||||
for kdk_folder in Path("/Library/Developer/KDKs").iterdir():
|
||||
if kdk_folder.name.endswith(f"{result}.kdk"):
|
||||
# Verify that the KDK is valid
|
||||
@@ -154,7 +155,7 @@ class sys_patch_helpers:
|
||||
# And force macOS into properly generating the Opaque shaders
|
||||
if self.constants.detected_os < os_data.os_data.ventura:
|
||||
return
|
||||
print("- Disabling WindowServer Caching")
|
||||
logging.info("- Disabling WindowServer Caching")
|
||||
# Invoke via 'bash -c' to resolve pathing
|
||||
utilities.elevated(["bash", "-c", "rm -rf /private/var/folders/*/*/*/WindowServer/com.apple.WindowServer"])
|
||||
# Disable writing to WindowServer folder
|
||||
@@ -170,12 +171,12 @@ class sys_patch_helpers:
|
||||
# we manually remove all News Widgets
|
||||
if self.constants.detected_os < os_data.os_data.ventura:
|
||||
return
|
||||
print("- Parsing Notification Centre Widgets")
|
||||
logging.info("- Parsing Notification Centre Widgets")
|
||||
file_path = "~/Library/Containers/com.apple.notificationcenterui/Data/Library/Preferences/com.apple.notificationcenterui.plist"
|
||||
file_path = Path(file_path).expanduser()
|
||||
|
||||
if not file_path.exists():
|
||||
print(" - Defaults file not found, skipping")
|
||||
logging.info(" - Defaults file not found, skipping")
|
||||
return
|
||||
|
||||
did_find = False
|
||||
@@ -194,7 +195,7 @@ class sys_patch_helpers:
|
||||
continue
|
||||
if not b'com.apple.news' in sub_data[sub_entry][2]:
|
||||
continue
|
||||
print(f" - Found News Widget to remove: {sub_data[sub_entry][2].decode('ascii')}")
|
||||
logging.info(f" - Found News Widget to remove: {sub_data[sub_entry][2].decode('ascii')}")
|
||||
data["widgets"]["instances"].remove(widget)
|
||||
did_find = True
|
||||
if did_find:
|
||||
@@ -218,7 +219,7 @@ class sys_patch_helpers:
|
||||
if self.constants.detected_os < os_data.os_data.big_sur:
|
||||
return
|
||||
|
||||
print("- Installing Kernel Collection syncing utility")
|
||||
logging.info("- Installing Kernel Collection syncing utility")
|
||||
result = utilities.elevated([self.constants.rsrrepair_userspace_path, "--install"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if result.returncode != 0:
|
||||
print(f" - Failed to install RSRRepair: {result.stdout.decode()}")
|
||||
logging.info(f" - Failed to install RSRRepair: {result.stdout.decode()}")
|
||||
Reference in New Issue
Block a user