From 347abb953ddb7e1bb8556df90ad9c029bc5b3f2c Mon Sep 17 00:00:00 2001 From: Hoang Hong Quan Date: Wed, 11 Sep 2024 03:55:50 +0700 Subject: [PATCH] Update handling methods related to macOS version --- OpCore-Simplify.py | 67 +++++++++++++++---------------- Scripts/acpi_guru.py | 4 +- Scripts/compatibility_checker.py | 69 ++++++++++++++++---------------- Scripts/config_prodigy.py | 29 +++++++------- Scripts/datasets/os_data.py | 40 ++++++++++++++++++ Scripts/efi_builder.py | 27 ++++++++----- Scripts/kext_maestro.py | 31 ++++++-------- Scripts/utils.py | 7 ++++ 8 files changed, 160 insertions(+), 114 deletions(-) mode change 100755 => 100644 Scripts/compatibility_checker.py create mode 100644 Scripts/datasets/os_data.py diff --git a/OpCore-Simplify.py b/OpCore-Simplify.py index 63271c6..bc2919f 100644 --- a/OpCore-Simplify.py +++ b/OpCore-Simplify.py @@ -1,3 +1,4 @@ +from Scripts.datasets import os_data from Scripts import aida64 from Scripts import compatibility_checker from Scripts import efi_builder @@ -6,6 +7,7 @@ from Scripts import utils import updater import os import sys +import re class OCPE: def __init__(self): @@ -17,17 +19,6 @@ class OCPE: self.u = utils.Utils() self.hardware = None self.compatibility = None - self.macos_version = None - self.macos_version_data = { - "24": "macOS Sequoia 15 (Beta)", - "23": "macOS Sonoma 14 (14.4+)", - "22": "macOS Ventura 13", - "21": "macOS Monterey 12", - "20": "macOS Big Sur 11", - "19": "macOS Catalina 10.15", - "18": "macOS Mojave 10.14", - "17": "macOS High Sierra 10.13" - } self.result_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "Results") def gathering_files(self): @@ -98,17 +89,15 @@ class OCPE: self.hardware = self.c.check_compatibility(self.hardware) self.compatibility = self.hardware.get("Compatibility") supported_macOS_version = self.compatibility.get("macOS Version") - min_verion = supported_macOS_version.get("Min Version") - max_verion = supported_macOS_version.get("Max Version") self.u.head("Compatibility Checker") print("") - if max_verion == -1: + if not supported_macOS_version: self.u.request_input("Your hardware is not compatible with macOS!") self.u.exit_program() print("* Supported macOS Version:") - print("{}Max Version: {}".format(" "*4, self.macos_version_data[str(max_verion)])) - print("{}Min Version: {}".format(" "*4, self.macos_version_data[str(min_verion)])) + print("{}Max Version: {}".format(" "*4, os_data.get_macos_name_by_darwin(supported_macOS_version.get("Max Version")))) + print("{}Min Version: {}".format(" "*4, os_data.get_macos_name_by_darwin(supported_macOS_version.get("Min Version")))) if self.compatibility.get("Unsupported Devices"): print("* Unsupported devices:") for index, device_name in enumerate(self.compatibility.get("Unsupported Devices"), start=1): @@ -123,25 +112,35 @@ class OCPE: self.compatibility_check() supported_macOS_version = self.compatibility.get("macOS Version") - min_verion = supported_macOS_version.get("Min Version") - max_verion = supported_macOS_version.get("Max Version") + min_version = supported_macOS_version.get("Min Version") + max_version = supported_macOS_version.get("Max Version") + + version_pattern = re.compile(r'^(\d+)(?:\.(\d+)(?:\.(\d+))?)?$') while True: self.u.head("Select macOS Version") print("") - for index, macos_version in enumerate(range(max_verion, min_verion - 1, -1), start=1): - print("{}. {}".format(index, self.macos_version_data[str(macos_version)])) + for index, macos_version_name in enumerate(os_data.get_macos_names(min_version, max_version), start=min_version[0]): + print("{}. {}".format(index, macos_version_name)) + print("") + print("Please enter the macOS version you want to select:") + print("- To select a major version, enter the number (e.g., 19).") + print("- To specify a full version, enter it in 'major.minor.patch' format (e.g., 22.4.6).") + print("- The version must be in the range from {} to {}.".format(".".join(str(item) for item in min_version), ".".join(str(item) for item in max_version))) print("") print("Q. Quit") print("") - option = self.u.request_input("Please select the macOS version you wish to install: ") + option = self.u.request_input("Select macOS version: ") if option.lower() == "q": self.u.exit_program() - if "1" <= option <= str(max_verion - min_verion + 1): - self.macos_version = max_verion - int(option) + 1 - return - else: - continue + + match = version_pattern.match(option) + if match: + target_version = (int(match.group(1)), int(match.group(2)) if match.group(2) else 99, int(match.group(3)) if match.group(3) else 99) + + if min_version <= target_version <= max_version: + self.macos_version = target_version + return def show_result(self): def generate_tree_content(dir_path, prefix=''): @@ -204,11 +203,11 @@ class OCPE: if __name__ == '__main__': o = OCPE() - try: - update_flag = updater.Updater().run_update() - if update_flag: - os.execv(sys.executable, ['python3'] + sys.argv) - else: - o.main() - except Exception as e: - o.u.exit_program(o.u.message("\nAn error occurred: {}\n".format(e))) + #try: + update_flag = updater.Updater().run_update() + if update_flag: + os.execv(sys.executable, ['python3'] + sys.argv) + else: + o.main() + #except Exception as e: + # o.u.exit_program(o.u.message("\nAn error occurred: {}\n".format(e))) diff --git a/Scripts/acpi_guru.py b/Scripts/acpi_guru.py index b5c3757..fb54c63 100644 --- a/Scripts/acpi_guru.py +++ b/Scripts/acpi_guru.py @@ -2221,7 +2221,7 @@ DefinitionBlock ("", "SSDT", 2, "ZPSS", "RTCAWAC", 0x00000000) }) def fix_system_clock_hedt(self, motherboard_chipset, macos_version): - if macos_version < 20 or not self.utils.contains_any(["X99", "X299"], motherboard_chipset): + if macos_version < (20, 0, 0) or not self.utils.contains_any(["X99", "X299"], motherboard_chipset): return if not self.lpc_bus_device: @@ -2457,7 +2457,7 @@ DefinitionBlock ("", "SSDT", 2, "ZPSS", "_PRW", 0x00000000) }) def fix_uncore_bridge(self, motherboard_chipset, macos_version): - if macos_version < 20 or not self.utils.contains_any(["X79", "C602", "Patsburg", "C612", "X99", "Wellsburg"], motherboard_chipset): + if macos_version < (20, 0, 0) or not self.utils.contains_any(["X79", "C602", "Patsburg", "C612", "X99", "Wellsburg"], motherboard_chipset): return unc0_device = self.acpi.get_device_paths("UNC0") diff --git a/Scripts/compatibility_checker.py b/Scripts/compatibility_checker.py old mode 100755 new mode 100644 index 9a908f8..930b33f --- a/Scripts/compatibility_checker.py +++ b/Scripts/compatibility_checker.py @@ -1,27 +1,27 @@ from Scripts.datasets import chipset_data from Scripts.datasets import cpu_data from Scripts.datasets import gpu_data +from Scripts.datasets import os_data from Scripts.datasets import pci_data from Scripts import utils class CompatibilityChecker: def __init__(self): self.utils = utils.Utils() - self.latest_macos_version = 24 def is_low_end_intel_cpu(self, processor_name): return any(brand in processor_name for brand in ["Celeron", "Pentium"]) def check_cpu_compatibility(self, processor_name, instruction_set): if "x86-64" not in instruction_set or "SSE4" not in instruction_set: - self.max_supported_macos_version = self.min_supported_macos_version = -1 + self.max_supported_macos_version = self.min_supported_macos_version = (-1, -1, -1) self.unsupported_devices.append("CPU: {}".format(processor_name)) return if "SSE4.2" not in instruction_set: - self.min_supported_macos_version = 18 + self.min_supported_macos_version = (18, 0, 0) if "SSE4.1" in instruction_set: - self.max_supported_macos_version = 21 + self.max_supported_macos_version = (21, 99, 99) def check_gpu_compatibility(self, motherboard_chipset, processor_name, instruction_set, gpu_info): supported_gpus = {} @@ -39,67 +39,68 @@ class CompatibilityChecker: if self.utils.contains_any(cpu_data.IntelCPUGenerations, gpu_codename, end=12) and \ not self.is_low_end_intel_cpu(processor_name) and \ not "2000" in gpu_name and not "2500" in gpu_name: - self.min_supported_macos_version = max(17, self.min_supported_macos_version) + self.min_supported_macos_version = max((17, 0, 0), self.min_supported_macos_version) if "Sandy Bridge" in gpu_codename: - self.max_supported_macos_version = max(17, self.max_supported_macos_version if is_supported_discrete_gpu else -1) + self.max_supported_macos_version = max((17, 99, 99), self.max_supported_macos_version if is_supported_discrete_gpu else (-1, -1, -1)) elif "Ivy Bridge" in gpu_codename: - self.max_supported_macos_version = max(20, self.max_supported_macos_version if is_supported_discrete_gpu else -1) + self.max_supported_macos_version = max((20, 99, 99), self.max_supported_macos_version if is_supported_discrete_gpu else (-1, -1, -1)) elif "Haswell" in gpu_codename or "Broadwell" in gpu_codename: - self.max_supported_macos_version = max(21, self.max_supported_macos_version if is_supported_discrete_gpu else -1) + self.max_supported_macos_version = max((21, 99, 99), self.max_supported_macos_version if is_supported_discrete_gpu else (-1, -1, -1)) elif "Skylake" in gpu_codename or "Kaby Lake" in gpu_codename and not "-r" in gpu_codename.lower(): - self.max_supported_macos_version = max(22, self.max_supported_macos_version if is_supported_discrete_gpu else -1) + self.max_supported_macos_version = max((22, 99, 99), self.max_supported_macos_version if is_supported_discrete_gpu else (-1, -1, -1)) elif "Amber Lake" in gpu_codename or "Whiskey Lake" in gpu_codename: - self.min_supported_macos_version = max(17, self.min_supported_macos_version if is_supported_discrete_gpu else -1) - self.max_supported_macos_version = self.latest_macos_version + self.min_supported_macos_version = max((17, 0, 0), self.min_supported_macos_version if is_supported_discrete_gpu else (-1, -1, -1)) + self.max_supported_macos_version = os_data.get_latest_darwin_version() elif not is_supported_discrete_gpu and "Comet Lake" in gpu_codename and self.utils.contains_any(chipset_data.IntelChipsets, motherboard_chipset, start=110, end=122): - self.max_supported_macos_version = self.min_supported_macos_version = -1 + self.max_supported_macos_version = self.min_supported_macos_version = (-1, -1, -1) elif "Ice Lake" in gpu_codename: - self.min_supported_macos_version = max(19, self.min_supported_macos_version) - self.max_supported_macos_version = self.latest_macos_version + self.min_supported_macos_version = max((19, 0, 0), self.min_supported_macos_version) + self.max_supported_macos_version = os_data.get_latest_darwin_version() else: - self.max_supported_macos_version = self.latest_macos_version + self.max_supported_macos_version = os_data.get_latest_darwin_version() else: is_supported_gpu = False if not is_supported_discrete_gpu: - self.max_supported_macos_version = self.min_supported_macos_version = -1 + self.max_supported_macos_version = self.min_supported_macos_version = (-1, -1, -1) elif "AMD" in gpu_manufacturer: is_supported_gpu = gpu_props.get("Device ID") in pci_data.AMDGPUIDs if is_supported_gpu: - self.max_supported_macos_version = self.latest_macos_version - self.min_supported_macos_version = max(19, self.min_supported_macos_version) + self.max_supported_macos_version = os_data.get_latest_darwin_version() + self.min_supported_macos_version = max((19, 0, 0), self.min_supported_macos_version) elif "Discrete GPU" in device_type: if "AMD" in gpu_manufacturer: is_supported_discrete_gpu = True if "Navi 2" in gpu_codename: if not "AVX2" in instruction_set: - self.max_supported_macos_version = min(21, self.max_supported_macos_version) + self.max_supported_macos_version = min((21, 99, 99), self.max_supported_macos_version) else: if "Navi 23" in gpu_codename or "Navi 22" in gpu_codename: - self.min_supported_macos_version = max(21, self.min_supported_macos_version) + self.min_supported_macos_version = max((21, 0, 0), self.min_supported_macos_version) elif "Navi 21" in gpu_codename: - self.min_supported_macos_version = max(20, self.min_supported_macos_version) + self.min_supported_macos_version = max((20, 0, 0), self.min_supported_macos_version) else: - self.max_supported_macos_version = self.min_supported_macos_version = -1 + self.max_supported_macos_version = self.min_supported_macos_version = (-1, -1, -1) is_supported_discrete_gpu = is_supported_gpu = False elif "Navi 1" in gpu_codename: - self.min_supported_macos_version = max(19, self.min_supported_macos_version) + self.min_supported_macos_version = max((19, 0, 0), self.min_supported_macos_version) elif "Vega" in gpu_codename or "Polaris" in gpu_codename or "Baffin" in gpu_codename or "Ellesmere" in gpu_codename or device_id.endswith("699F"): - self.min_supported_macos_version = max(17, self.min_supported_macos_version) + self.min_supported_macos_version = max((17, 0, 0), self.min_supported_macos_version) elif self.utils.contains_any(gpu_data.AMDCodenames, gpu_codename): - self.max_supported_macos_version = 21 + self.max_supported_macos_version = (21, 99, 99) else: - self.max_supported_macos_version = self.min_supported_macos_version = -1 + self.max_supported_macos_version = self.min_supported_macos_version = (-1, -1, -1) is_supported_discrete_gpu = is_supported_gpu = False elif "NVIDIA" in gpu_manufacturer: is_supported_discrete_gpu = True if "Kepler" in gpu_codename: - self.max_supported_macos_version = 20 + self.max_supported_macos_version = (20, 99, 99) elif "Pascal" in gpu_codename or "Maxwell" in gpu_codename or "Fermi" in gpu_codename or "Tesla" in gpu_codename: - self.max_supported_macos_version = self.min_supported_macos_version = 17 + self.max_supported_macos_version = (17, 99, 99) + self.min_supported_macos_version = (17, 0, 0) else: - self.max_supported_macos_version = self.min_supported_macos_version = -1 + self.max_supported_macos_version = self.min_supported_macos_version = (-1, -1, -1) is_supported_discrete_gpu = is_supported_gpu = False if not is_supported_gpu: @@ -145,7 +146,7 @@ class CompatibilityChecker: if bus_type.startswith("PCI"): if device_id in ["8086-125B", "8086-125C", "8086-125D", "8086-3102"]: - self.min_supported_macos_version = 19 + self.min_supported_macos_version = (19, 0, 0) if not is_device_supported: self.unsupported_devices["Network: {}".format(device_name)] = device_props @@ -178,8 +179,8 @@ class CompatibilityChecker: del hardware["SD Controller"] def check_compatibility(self, hardware): - self.max_supported_macos_version = self.latest_macos_version - self.min_supported_macos_version = 17 + self.max_supported_macos_version = os_data.get_latest_darwin_version() + self.min_supported_macos_version = os_data.get_lowest_darwin_version() self.unsupported_devices = {} self.check_cpu_compatibility( @@ -187,7 +188,7 @@ class CompatibilityChecker: hardware.get("CPU").get("Instruction Set") ) - if self.max_supported_macos_version != -1: + if self.max_supported_macos_version != (-1, -1, -1): hardware["GPU"] = self.check_gpu_compatibility( hardware.get("Motherboard").get("Motherboard Chipset"), hardware.get("CPU").get("Processor Name"), @@ -205,7 +206,7 @@ class CompatibilityChecker: "macOS Version": { "Max Version": self.max_supported_macos_version, "Min Version": self.min_supported_macos_version - }, + } if self.max_supported_macos_version != (-1, -1, -1) else None, "Unsupported Devices": self.unsupported_devices } diff --git a/Scripts/config_prodigy.py b/Scripts/config_prodigy.py index 3ed7b6f..2bb37ce 100644 --- a/Scripts/config_prodigy.py +++ b/Scripts/config_prodigy.py @@ -1,6 +1,6 @@ from Scripts.datasets import chipset_data from Scripts.datasets import cpu_data -from Scripts.datasets import gpu_data +from Scripts.datasets import os_data from Scripts import codec_layouts from Scripts import gathering_files from Scripts import smbios @@ -12,7 +12,6 @@ class ConfigProdigy: self.g = gathering_files.gatheringFiles() self.smbios = smbios.SMBIOS() self.utils = utils.Utils() - self.latest_macos_version = "24.99.99" self.cpuids = { "Ivy Bridge": "A9060300", "Haswell": "C3060300", @@ -69,7 +68,7 @@ class ConfigProdigy: def block_kext_bundle(self, network, macos_version): kernel_block = [] - if macos_version > 22: + if macos_version > (22, 0, 0): for network_name, network_props in network.items(): if network_props.get("Device ID") in ["14E4-43A0", "14E4-43A3", "14E4-43BA"]: kernel_block.append({ @@ -101,7 +100,7 @@ class ConfigProdigy: elif "Ice Lake" not in cpu_codename and self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=10): if not "Comet Lake" in cpu_codename: return self.cpuids.get("Comet Lake") - if macos_version < 19: + if macos_version < (19, 0, 0): return self.cpuids.get("Coffee Lake") return None @@ -134,8 +133,8 @@ class ConfigProdigy: }) for index, patch in enumerate(kernel_patch): - max_supported_macos_version = patch.get("MaxKernel") or self.latest_macos_version - min_supported_macos_version = patch.get("MinKernel") or "17.0.0" + max_kernel = self.utils.parse_darwin_version(patch.get("MaxKernel") or os_data.get_latest_darwin_version()) + min_kernel = self.utils.parse_darwin_version(patch.get("MinKernel") or os_data.get_lowest_darwin_version()) if "cpuid_cores_per_package" in patch["Comment"]: patch["Replace"] = patch["Replace"].hex() @@ -152,7 +151,7 @@ class ConfigProdigy: elif "shaneee" in patch["Comment"].lower(): patch["Enabled"] = True - if not min_supported_macos_version[:2] <= str(macos_version) <= max_supported_macos_version[:2] or not patch["Enabled"]: + if not min_kernel <= macos_version <= max_kernel or not patch["Enabled"]: patches_to_remove.append(index) for index in patches_to_remove[::-1]: @@ -167,20 +166,20 @@ class ConfigProdigy: "keepsyms=1" ] - if codec_id in codec_layouts.data and not ("AMD" in cpu_manufacturer and macos_version > 23): + if codec_id in codec_layouts.data and not ("AMD" in cpu_manufacturer and macos_version > (23, 0, 0)): boot_args.append("alcid={}".format(random.choice(codec_layouts.data.get(codec_id)))) if "AMD" in cpu_manufacturer or self.is_intel_hedt_cpu(cpu_codename): boot_args.append("npci=0x2000") - if macos_version > 22: + if macos_version > (22, 0, 0): boot_args.append("revpatch=sbvmm{}".format(",cpuname" if custom_cpu_name else "")) if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=13) and int(cpu_cores) > 6: boot_args.append("-ctrsmt") if "Intel" in cpu_manufacturer: - if "UHD" in integrated_gpu_name and macos_version > 18: + if "UHD" in integrated_gpu_name and macos_version > (18, 0, 0): boot_args.append("igfxonln=1") if "Ice Lake" in cpu_codename: @@ -188,7 +187,7 @@ class ConfigProdigy: if "Laptop" in platform: if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=6): - boot_args.append("-igfxbl{}".format("t" if macos_version > 22 else "r")) + boot_args.append("-igfxbl{}".format("t" if macos_version > (22, 0, 0) else "r")) if "Navi" in discrete_gpu_codename and not "Navi 2" in discrete_gpu_codename: boot_args.append("agdpmod=pikera") @@ -196,7 +195,7 @@ class ConfigProdigy: if not "SURFACE" in motherboard_name and "I2C" in touchpad_communication: boot_args.append("-vi2c-force-polling") - if macos_version > 23: + if macos_version > (23, 0, 0): boot_args.append("-lilubetaall") if "Discrete GPU" in unsupported_devices: @@ -214,9 +213,9 @@ class ConfigProdigy: return " ".join(boot_args) def csr_active_config(self, macos_version): - if macos_version > 19: + if macos_version > (19, 0, 0): return "03080000" - elif macos_version > 17: + elif macos_version > (17, 0, 0): return "FF070000" else: return "FF030000" @@ -307,7 +306,7 @@ class ConfigProdigy: config["Misc"]["Entries"] = [] config["Misc"]["Security"]["AllowSetDefault"] = True config["Misc"]["Security"]["ScanPolicy"] = 0 - config["Misc"]["Security"]["SecureBootModel"] = "Default" if 19 < efi_option.get("macOS Version") < 23 else "Disabled" + config["Misc"]["Security"]["SecureBootModel"] = "Default" if (19, 0, 0) < efi_option.get("macOS Version") < (23, 0, 0) else "Disabled" config["Misc"]["Security"]["Vault"] = "Optional" config["Misc"]["Tools"] = [] diff --git a/Scripts/datasets/os_data.py b/Scripts/datasets/os_data.py new file mode 100644 index 0000000..d3524d4 --- /dev/null +++ b/Scripts/datasets/os_data.py @@ -0,0 +1,40 @@ +from Scripts import utils + +class macOSVersionInfo: + def __init__(self, name, macos_version, release_status = "final"): + self.name = name + self.darwin_version = (int(macos_version.split(".")[1]) + 4) if "10." in macos_version else (int(macos_version.split(".")[0]) + 9) + self.macos_version = macos_version + self.release_status = release_status + +macos_versions = [ + macOSVersionInfo("High Sierra", "10.13"), + macOSVersionInfo("Mojave", "10.14"), + macOSVersionInfo("Catalina", "10.15"), + macOSVersionInfo("Big Sur", "11"), + macOSVersionInfo("Monterey", "12"), + macOSVersionInfo("Ventura", "13"), + macOSVersionInfo("Sonoma", "14.4+"), + macOSVersionInfo("Sequoia", "15", "beta") +] + +u = utils.Utils() + +def get_latest_darwin_version(): + return macos_versions[-1].darwin_version, 99, 99 + +def get_lowest_darwin_version(): + return macos_versions[0].darwin_version, 0, 0 + +def get_macos_names(min_darwin, max_darwin): + return [ + "macOS {} {}{}".format(data.name, data.macos_version, "" if data.release_status == "final" else " (Beta)") + for data in macos_versions + if min_darwin[0] <= data.darwin_version <= max_darwin[0] + ] + +def get_macos_name_by_darwin(darwin_version): + for data in macos_versions: + if data.darwin_version == darwin_version[0]: + return "macOS {} {}{}".format(data.name, data.macos_version, "" if data.release_status == "final" else " (Beta)") + return None diff --git a/Scripts/efi_builder.py b/Scripts/efi_builder.py index bb352a4..0718203 100644 --- a/Scripts/efi_builder.py +++ b/Scripts/efi_builder.py @@ -177,12 +177,17 @@ class builder: return any(cpu_branding in processor_name for cpu_branding in ["Celeron", "Pentium"]) def check_igpu_compatibility(self, cpu_codename, macos_version): - return not (("Sandy Bridge" in cpu_codename and macos_version > 17) or ("Ivy Bridge" in cpu_codename and macos_version > 20) or (("Haswell" in cpu_codename or "Broadwell" in cpu_codename) and macos_version > 21) or (("Skylake" in cpu_codename or "Kaby Lake" in cpu_codename) and macos_version > 22) or (("Amber Lake" in cpu_codename or "Whiskey Lake" in cpu_codename) and macos_version == 17) or ("Ice Lake" in cpu_codename and 19 > macos_version)) + return not (("Sandy Bridge" in cpu_codename and macos_version > (17, 0, 0)) or \ + ("Ivy Bridge" in cpu_codename and macos_version > (20, 0, 0)) or \ + (("Haswell" in cpu_codename or "Broadwell" in cpu_codename) and macos_version > (21, 0, 0)) or \ + (("Skylake" in cpu_codename or "Kaby Lake" in cpu_codename) and macos_version > (22, 0, 0)) or \ + (("Amber Lake" in cpu_codename or "Whiskey Lake" in cpu_codename) and macos_version == (17, 0, 0)) or \ + ("Ice Lake" in cpu_codename and (19, 0, 0) > macos_version)) def igpu_properties(self, platform, processor_name, gpu_codename, discrete_gpu, integrated_gpu_manufacturer, integrated_gpu_name, macos_version): - if "Skylake".lower() in gpu_codename.lower() and macos_version > 21: + if "Skylake".lower() in gpu_codename.lower() and macos_version > (21, 0, 0): gpu_codename = "Kaby Lake" - if "Kaby Lake-R".upper() in gpu_codename.upper() and macos_version > 22: + if "Kaby Lake-R".upper() in gpu_codename.upper() and macos_version > (22, 0, 0): gpu_codename = "Coffee Lake" gpu_codename = self.utils.contains_any(cpu_data.IntelCPUGenerations, gpu_codename) @@ -253,18 +258,18 @@ class builder: return igpu_properties def system_product_info(self, platform, cpu_manufacturer, processor_name, cpu_codename, cpu_cores, discrete_gpu, igpu_props, macos_version): - product_name = "iMacPro1,1" if macos_version < 19 or self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=12) else "MacPro7,1" + product_name = "iMacPro1,1" if macos_version < (19, 0, 0) or self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=12) else "MacPro7,1" if "AMD" in cpu_manufacturer and not discrete_gpu: product_name = "MacBookPro16,3" if "Laptop" in platform else "iMacPro1,1" if igpu_props: - if "Kaby Lake-R".lower() in cpu_codename.lower() and macos_version > 22: + if "Kaby Lake-R".lower() in cpu_codename.lower() and macos_version > (22, 0, 0): cpu_codename = "Coffee Lake" if "Sandy Bridge" in cpu_codename: if "Desktop" in platform: - if macos_version < 18: + if macos_version < (18, 0, 0): product_name = "iMac12,2" else: product_name = "MacPro6,1" @@ -273,14 +278,14 @@ class builder: else: product_name = "MacBookPro8,1" if int(cpu_cores) < 4 else "MacBookPro8,2" elif "Ivy Bridge" in cpu_codename: - if macos_version == 20: + if macos_version == (20, 0, 0): if "Desktop" in platform: product_name = "iMac14,4" if not discrete_gpu else "iMac15,1" elif "NUC" in platform: product_name = "Macmini7,1" else: product_name = "MacBookPro11,1" if int(cpu_cores) < 4 else "MacBookPro11,5" - elif macos_version < 20: + elif macos_version < (20, 0, 0): if "Desktop" in platform: product_name = "iMac13,1" if not discrete_gpu else "iMac13,2" elif "NUC" in platform: @@ -292,12 +297,12 @@ class builder: elif "Haswell" in cpu_codename: if "Desktop" in platform: product_name = "iMac14,4" if not discrete_gpu else "iMac15,1" - if macos_version == 21: + if macos_version == (21, 0, 0): product_name = "iMac16,2" if not discrete_gpu else "iMac17,1" elif "NUC" in platform: product_name = "Macmini7,1" else: - product_name = "MacBookPro11,1" if macos_version < 21 and int(cpu_cores) < 4 else "MacBookPro11,5" + product_name = "MacBookPro11,1" if macos_version < (21, 0, 0) and int(cpu_cores) < 4 else "MacBookPro11,5" elif "Broadwell" in cpu_codename: if "Desktop" in platform: product_name = "iMac16,2" if not discrete_gpu else "iMac17,1" @@ -312,7 +317,7 @@ class builder: elif self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=8, end=11): product_name = "Macmini8,1" if "Desktop" in platform: - product_name = "iMac18,3" if macos_version == 17 else "iMac19,1" + product_name = "iMac18,3" if macos_version == (17, 0, 0) else "iMac19,1" if "Comet Lake" in cpu_codename: product_name = "iMac20,1" if int(cpu_cores) < 10 else "iMac20,2" elif "Laptop" in platform: diff --git a/Scripts/kext_maestro.py b/Scripts/kext_maestro.py index 51984b0..952d646 100644 --- a/Scripts/kext_maestro.py +++ b/Scripts/kext_maestro.py @@ -1,5 +1,6 @@ from Scripts.datasets import cpu_data +from Scripts.datasets import os_data from Scripts.datasets import pci_data from Scripts import utils import os @@ -537,7 +538,6 @@ class KextMaestro: "MinKernel": "" } ] - self.latest_macos_version = "24.99.99" def extract_pci_id(self, kext_path): if not os.path.exists(kext_path): @@ -548,7 +548,6 @@ class KextMaestro: pci_ids = [] - # Iterate through the personalities in the plist for personality_name, properties in plist_data.get("IOKitPersonalities", {}).items(): matching_keys = [key for key in self.matching_keys if key in properties] @@ -558,25 +557,21 @@ class KextMaestro: match_key = matching_keys[0] if match_key in ["IOPCIMatch", "IOPCIPrimaryMatch"]: - # Split PCI IDs and format them pci_list = properties[match_key].split(" ") for pci_id in pci_list: vendor_id = pci_id[-4:] device_id = pci_id[2:6] pci_ids.append("{}-{}".format(vendor_id, device_id).upper()) elif match_key == "IONameMatch": - # Process IONameMatch keys for pci_id in properties[match_key]: vendor_id = pci_id[3:7] device_id = pci_id[-4:] pci_ids.append("{}-{}".format(vendor_id, device_id).upper()) elif match_key == "idProduct": - # Process idProduct and idVendor vendor_id = self.utils.int_to_hex(properties["idVendor"]).zfill(4) device_id = self.utils.int_to_hex(properties["idProduct"]).zfill(4) pci_ids.append("{}-{}".format(vendor_id, device_id).upper()) elif match_key == "HDAConfigDefault": - # Handle AppleALC configurations for codec_layout in properties[match_key]: codec_id = self.utils.int_to_hex(codec_layout.get("CodecID")).zfill(8) pci_ids.append("{}-{}".format(codec_id[:4], codec_id[-4:])) @@ -591,16 +586,16 @@ class KextMaestro: "USBMap" ] - if macos_version > 22 or custom_cpu_name or "MacPro7,1" in smbios: + if macos_version > (22, 0, 0) or custom_cpu_name or "MacPro7,1" in smbios: kexts.append("RestrictEvents") - if codec_id in pci_data.CodecIDs and not ("AMD" in cpu_manufacturer and macos_version > 23): + if codec_id in pci_data.CodecIDs and not ("AMD" in cpu_manufacturer and macos_version > (23, 0, 0)): kexts.append("AppleALC") - if "AMD" in cpu_manufacturer and macos_version > 21 or int(cpu_configuration) > 1 and macos_version > 18: + if "AMD" in cpu_manufacturer and macos_version > (21, 0, 0) or int(cpu_configuration) > 1 and macos_version > (18, 0, 0): kexts.append("AppleMCEReporterDisabler") - if macos_version > 21 and self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, end=2): + if macos_version > (21, 0, 0) and self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, end=2): kexts.append("CryptexFixup") if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=13) and int(cpu_cores) > 6: @@ -624,12 +619,12 @@ class KextMaestro: if self.utils.contains_any(pci_data.NetworkIDs, device_id, end=21): wifi_pci = device_id if device_id in ["14E4-43A0", "14E4-43A3", "14E4-43BA"]: - if macos_version > 22: + if macos_version > (22, 0, 0): kexts.extend(["AirportBrcmFixup", "IOSkywalkFamily", "IO80211FamilyLegacy", "AMFIPass"]) elif device_id in pci_data.NetworkIDs: kexts.append("AirportBrcmFixup") elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=21, end=108): - kexts.append("AirportItlwm" if macos_version < 23 else "itlwm") + kexts.append("AirportItlwm" if macos_version < (23, 0, 0) else "itlwm") elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=108, end=115): kexts.append("AppleIGC") elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=115, end=122): @@ -645,7 +640,7 @@ class KextMaestro: elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=181, end=219): kexts.append("AppleIGB") - if bluetooth and macos_version > 20 and not wifi_pci in ["14E4-43A0", "14E4-43A3", "14E4-43BA"]: + if bluetooth and macos_version > (20, 0, 0) and not wifi_pci in ["14E4-43A0", "14E4-43A3", "14E4-43BA"]: kexts.append("BlueToolFixup") for usb_id in bluetooth: if usb_id in pci_data.BluetoothIDs: @@ -653,7 +648,7 @@ class KextMaestro: if idx < 99: kexts.append("BrcmPatchRAM") - if bluetooth and macos_version > 20: + if bluetooth and macos_version > (20, 0, 0): kexts.append("BlueToolFixup") else: kexts.append("IntelBluetoothFirmware") @@ -716,7 +711,7 @@ class KextMaestro: def install_kexts_to_efi(self, kexts, macos_version, kexts_directory): for kext_name in kexts: if "AirportItlwm" in kext_name: - kext_name = "{}{}".format(kext_name, macos_version) + kext_name = "{}{}".format(kext_name, macos_version[0]) elif "BlueToolFixup" in kext_name or "BrcmPatchRAM" in kext_name: kext_name = "BrcmPatchRAM" @@ -763,9 +758,9 @@ class KextMaestro: for kext in self.kext_loading_sequence: if not kext.get("MainKext") in kexts or os.path.splitext(os.path.basename(kext.get("BundlePath")))[0] in unload_kext: continue - max_supported_macos_version = kext.get("MaxKernel") or self.latest_macos_version - min_supported_macos_version = kext.get("MinKernel") or "17.0.0" - if not min_supported_macos_version[:2] <= str(macos_version) <= max_supported_macos_version[:2]: + max_kernel = self.utils.parse_darwin_version(kext.get("MaxKernel") or os_data.get_latest_darwin_version()) + min_kernel = self.utils.parse_darwin_version(kext.get("MinKernel") or os_data.get_lowest_darwin_version()) + if not min_kernel <= macos_version <= max_kernel: continue kernel_add.append({ diff --git a/Scripts/utils.py b/Scripts/utils.py index b359e11..9451c55 100644 --- a/Scripts/utils.py +++ b/Scripts/utils.py @@ -163,6 +163,13 @@ class Utils: # Convert the path to an absolute path and normalize it according to the OS return str(pathlib.Path(path).resolve()) + def parse_darwin_version(self, version): + if not isinstance(version, str): + return version + + major, minor, patch = map(int, version.split('.')) + return major, minor, patch + def open_folder(self, folder_path): if os.name == 'posix': if 'darwin' in os.uname().sysname.lower():