diff --git a/OpCore-Simplify.py b/OpCore-Simplify.py index 85d8a2f..8ebdee7 100644 --- a/OpCore-Simplify.py +++ b/OpCore-Simplify.py @@ -4,6 +4,7 @@ from Scripts import aida64 from Scripts import compatibility_checker from Scripts import efi_builder from Scripts import gathering_files +from Scripts import kext_maestro from Scripts import smbios from Scripts import utils import updater @@ -19,6 +20,7 @@ class OCPE: self.a = aida64.AIDA64() self.c = compatibility_checker.CompatibilityChecker() self.b = efi_builder.builder() + self.k = kext_maestro.KextMaestro() self.s = smbios.SMBIOS() self.u = utils.Utils() self.result_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "Results") @@ -181,8 +183,9 @@ class OCPE: print("1. Select Hardware Report") print("2. Select macOS Version") print("3. Customize ACPI Patch") - print("4. Customize SMBIOS Model") - print("5. Build OpenCore EFI") + print("4. Customize Kexts") + print("5. Customize SMBIOS Model") + print("6. Build OpenCore EFI") print("") print("Q. Quit") print("") @@ -205,7 +208,8 @@ class OCPE: smbios_model = self.s.select_smbios_model(hardware_report, macos_version) self.ac.select_acpi_tables() self.ac.select_acpi_patches(hardware_report, unsupported_devices, smbios_model) - elif option < 6: + self.k.select_required_kexts(hardware_report, smbios_model, macos_version, self.ac.patches) + elif option < 7: try: hardware_report except: @@ -215,13 +219,17 @@ class OCPE: if option == 2: macos_version = self.select_macos_version(supported_macos_version) smbios_model = self.s.select_smbios_model(hardware_report, macos_version) + self.k.select_required_kexts(hardware_report, smbios_model, macos_version, self.ac.patches) elif option == 3: self.ac.customize_patch_selection(hardware_report, unsupported_devices, smbios_model) elif option == 4: - smbios_model = self.s.customize_smbios_model(hardware_report, smbios_model, macos_version) + self.k.kext_configuration_menu(hardware_report, smbios_model, macos_version, self.ac.patches) elif option == 5: + smbios_model = self.s.customize_smbios_model(hardware_report, smbios_model, macos_version) + self.k.kext_configuration_menu(hardware_report, smbios_model, macos_version, self.ac.patches) + elif option == 6: self.gathering_files() - self.b.build_efi(hardware_report, unsupported_devices, smbios_model, macos_version, self.ac) + self.b.build_efi(hardware_report, unsupported_devices, smbios_model, macos_version, self.ac, self.k) self.show_result(hardware_report) if __name__ == '__main__': @@ -233,4 +241,4 @@ if __name__ == '__main__': else: o.main() except Exception as e: - o.u.exit_program(o.u.message("\nAn error occurred: {}\n".format(e))) + o.u.exit_program(o.u.message("\nAn error occurred: {}\n".format(e))) \ No newline at end of file diff --git a/Scripts/config_prodigy.py b/Scripts/config_prodigy.py index 083246e..c49939c 100644 --- a/Scripts/config_prodigy.py +++ b/Scripts/config_prodigy.py @@ -69,8 +69,8 @@ class ConfigProdigy: return not self.utils.contains_any(chipset_data.AMDChipsets, motherboard_chipset) is None or not self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=10) is None def is_low_end_intel_cpu(self, processor_name): - return any(brand in processor_name for brand in ["Celeron", "Pentium"]) - + return any(cpu_branding in processor_name for cpu_branding in ["Celeron", "Pentium"]) + def deviceproperties(self, cpu_codename, intel_mei, igpu_properties): deviceproperties_add = {} @@ -133,31 +133,33 @@ class ConfigProdigy: return None - def load_kernel_patch(self, motherboard_chipset, cpu_manufacturer, cpu_codename, cpu_cores, gpu_manufacturer, tsc_sync): + def load_kernel_patch(self, motherboard_chipset, cpu_manufacturer, cpu_cores, gpu_manufacturer, kexts): kernel_patch = [] if "AMD" in cpu_manufacturer: kernel_patch.extend(self.g.get_amd_kernel_patches()) - elif tsc_sync: - kernel_patch.extend(self.g.get_amd_kernel_patches()[-6:-4]) - - if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=13) and int(cpu_cores) > 6: - kernel_patch.append({ - "Arch": "Any", - "Base": "_cpu_thread_alloc", - "Comment": "Force enable Hyper Threading for macOS Mojave or later", - "Count": 1, - "Enabled": True, - "Find": self.utils.hex_to_bytes("8B8894010000"), - "Identifier": "kernel", - "Limit": 0, - "Mask": self.utils.hex_to_bytes(""), - "MaxKernel": "", - "MinKernel": "18.0.0", - "Replace": self.utils.hex_to_bytes("B9FF00000090"), - "ReplaceMask": self.utils.hex_to_bytes(""), - "Skip": 0 - }) + + for kext in kexts: + if kext.checked: + if kext.name == "CpuTopologyRebuild": + kernel_patch.append({ + "Arch": "Any", + "Base": "_cpu_thread_alloc", + "Comment": "Force enable Hyper Threading for macOS Mojave or later", + "Count": 1, + "Enabled": True, + "Find": self.utils.hex_to_bytes("8B8894010000"), + "Identifier": "kernel", + "Limit": 0, + "Mask": self.utils.hex_to_bytes(""), + "MaxKernel": "", + "MinKernel": "18.0.0", + "Replace": self.utils.hex_to_bytes("B9FF00000090"), + "ReplaceMask": self.utils.hex_to_bytes(""), + "Skip": 0 + }) + elif kext.name == "ForgedInvariant": + kernel_patch.extend(self.g.get_amd_kernel_patches()[-6:-4]) for patch in kernel_patch: if "cpuid_cores_per_package" in patch["Comment"]: @@ -177,57 +179,62 @@ class ConfigProdigy: return kernel_patch - def boot_args(self, motherboard_name, platform, cpu_manufacturer, cpu_codename, cpu_cores, discrete_gpu_codename, discrete_gpu_id, integrated_gpu_name, codec_id, touchpad_communication, unsupported_devices, custom_cpu_name, macos_version): + def boot_args(self, hardware_report, unsupported_devices, macos_version): boot_args = [ "-v", "debug=0x100", "keepsyms=1" ] + codec_id = list(hardware_report.get("Audio").items())[0][-1].get("Codec ID") if codec_id in codec_layouts.data: 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): + if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") or self.is_intel_hedt_cpu(hardware_report.get("CPU").get("CPU Codename")): boot_args.append("npci=0x2000") if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0"): - boot_args.append("revpatch=sbvmm{}".format(",cpuname" if custom_cpu_name else "")) + boot_args.append("revpatch=sbvmm{}".format(",cpuname" if not (" Core" in hardware_report.get("CPU").get("Processor Name") and \ + self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=12)) else "")) - if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=13) and int(cpu_cores) > 6: + if self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=13) and int(hardware_report.get("CPU").get("CPU Cores")) > 6: boot_args.append("-ctrsmt") - if "Intel" in cpu_manufacturer: - if "UHD" in integrated_gpu_name and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("19.0.0"): + if "Intel" in hardware_report.get("CPU").get("CPU Manufacturer"): + if "UHD" in list(hardware_report.get("GPU").keys())[0] and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("19.0.0"): boot_args.append("igfxonln=1") - if "Ice Lake" in cpu_codename: + if "Ice Lake" in list(hardware_report.get("GPU").items())[0][-1].get("GPU Codename"): boot_args.extend(["-noDC9", "-igfxcdc", "-igfxdvmt", "-igfxdbeo"]) - if "Laptop" in platform: - if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=6): + if "Laptop" in hardware_report.get("Motherboard").get("Platform"): + if self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=6): boot_args.append("-igfxbl{}".format("t" if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0") else "r")) - if "Navi" in discrete_gpu_codename and not "Navi 2" in discrete_gpu_codename: + if "Navi 1" in list(hardware_report.get("GPU").items())[-1][-1].get("GPU Codename"): boot_args.append("agdpmod=pikera") - if not "SURFACE" in motherboard_name and "I2C" in touchpad_communication: - boot_args.append("-vi2c-force-polling") + if not "SURFACE" in hardware_report.get("Motherboard").get("Motherboard Name"): + for input in hardware_report.get("Input").keys(): + if "I2C" in input: + boot_args.append("-vi2c-force-polling") + break if "Beta" in os_data.get_macos_name_by_darwin(macos_version): boot_args.append("-lilubetaall") - if "Discrete GPU" in unsupported_devices: - boot_args.append("-wegnoegpu") - - if "Integrated GPU" in unsupported_devices: - boot_args.append("-wegnoigpu") - - if discrete_gpu_id in ["1002-6610", "1002-682B", "1002-6837", "1002-683D", "1002-683F"]: + if list(hardware_report.get("GPU").items())[-1][-1].get("Device ID") in ("1002-6610", "1002-682B", "1002-6837", "1002-683D", "1002-683F"): boot_args.append("radpg=15") - if discrete_gpu_id in ["1002-67B0", "1002-67B1", "1002-67B8", "1002-6810", "1002-6811"]: + if list(hardware_report.get("GPU").items())[-1][-1].get("Device ID") in ("1002-67B0", "1002-67B1", "1002-67B8", "1002-6810", "1002-6811"): boot_args.append("-raddvi") + if any("Discrete GPU" in device_name for device_name in unsupported_devices): + boot_args.append("-wegnoegpu") + + if any("Integrated GPU" in device_name for device_name in unsupported_devices): + boot_args.append("-wegnoigpu") + return " ".join(boot_args) def csr_active_config(self, macos_version): @@ -252,66 +259,67 @@ class ConfigProdigy: return uefi_drivers - def genarate(self, hardware, efi_option, config): + def genarate(self, hardware_report, unsupported_devices, smbios_model, macos_version, kexts, config): del config["#WARNING - 1"] del config["#WARNING - 2"] del config["#WARNING - 3"] del config["#WARNING - 4"] - + config["ACPI"]["Add"] = [] config["ACPI"]["Delete"] = [] config["ACPI"]["Patch"] = [] - config["Booter"]["MmioWhitelist"] = self.mmio_whitelist(hardware.get("Motherboard Chipset")) - config["Booter"]["Patch"] = self.add_booter_patch(efi_option.get("SMBIOS"), efi_option.get("macOS Version")) - config["Booter"]["Quirks"]["DevirtualiseMmio"] = self.check_mats_support(hardware.get("CPU Manufacturer"), hardware.get("Motherboard Chipset")) - if "AMD" in hardware.get("CPU Manufacturer") and not "TRX40" in hardware.get("Motherboard Chipset"): + config["Booter"]["MmioWhitelist"] = self.mmio_whitelist(hardware_report.get("Motherboard").get("Motherboard Chipset")) + config["Booter"]["Patch"] = self.add_booter_patch(smbios_model, macos_version) + config["Booter"]["Quirks"]["DevirtualiseMmio"] = self.check_mats_support(hardware_report.get("CPU").get("CPU Manufacturer"), hardware_report.get("Motherboard").get("Motherboard Chipset")) + if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") and not "TRX40" in hardware_report.get("Motherboard").get("Motherboard Chipset"): config["Booter"]["Quirks"]["DevirtualiseMmio"] = False - config["Booter"]["Quirks"]["EnableWriteUnprotector"] = False if "AMD" in hardware.get("CPU Manufacturer") else not config["Booter"]["Quirks"]["DevirtualiseMmio"] - config["Booter"]["Quirks"]["ProtectUefiServices"] = "Z390" in hardware.get("Motherboard Chipset") or \ - not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), start=10) is None + config["Booter"]["Quirks"]["EnableWriteUnprotector"] = False if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") else not config["Booter"]["Quirks"]["DevirtualiseMmio"] + config["Booter"]["Quirks"]["ProtectUefiServices"] = "Z390" in hardware_report.get("Motherboard").get("Motherboard Chipset") or \ + not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=10) is None config["Booter"]["Quirks"]["RebuildAppleMemoryMap"] = not config["Booter"]["Quirks"]["EnableWriteUnprotector"] config["Booter"]["Quirks"]["ResizeAppleGpuBars"] = 0 if self.check_resizable_bar_support( - hardware.get("Motherboard Chipset"), - hardware.get("CPU Codename") + hardware_report.get("Motherboard").get("Motherboard Chipset"), + hardware_report.get("CPU").get("CPU Codename") ) else -1 - config["Booter"]["Quirks"]["SetupVirtualMap"] = not (not self.utils.contains_any(chipset_data.AMDChipsets, hardware.get("Motherboard Chipset"), end=5) is None or \ - "ASUS" in hardware.get("Motherboard Name") and self.is_intel_hedt_cpu(hardware.get("CPU Codename")) and config["Booter"]["Quirks"]["DevirtualiseMmio"]) + config["Booter"]["Quirks"]["SetupVirtualMap"] = not (not self.utils.contains_any(chipset_data.AMDChipsets, hardware_report.get("Motherboard").get("Motherboard Chipset"), end=5) is None or \ + "ASUS" in hardware_report.get("Motherboard").get("Motherboard Name") and self.is_intel_hedt_cpu(hardware_report.get("CPU").get("CPU Codename")) and config["Booter"]["Quirks"]["DevirtualiseMmio"]) config["Booter"]["Quirks"]["SyncRuntimePermissions"] = config["Booter"]["Quirks"]["RebuildAppleMemoryMap"] - config["DeviceProperties"]["Add"] = self.deviceproperties(hardware.get("CPU Codename"), hardware.get("Intel MEI"), efi_option.get("iGPU Properties")) + config["DeviceProperties"]["Add"] = self.deviceproperties( + hardware_report.get("CPU").get("CPU Codename"), + next((device_props for device_name, device_props in hardware_report.get("System Devices").items() if "HECI" in device_name or "Management Engine Interface" in device_name), None), {}) config["Kernel"]["Add"] = [] - config["Kernel"]["Block"] = self.block_kext_bundle(hardware.get("Network"), efi_option.get("macOS Version")) + config["Kernel"]["Block"] = self.block_kext_bundle(hardware_report.get("Network"), macos_version) spoof_cpuid = self.spoof_cpuid( - hardware.get("Processor Name"), - hardware.get("CPU Codename"), - efi_option.get("macOS Version") + hardware_report.get("CPU").get("Processor Name"), + hardware_report.get("CPU").get("CPU Codename"), + macos_version ) if spoof_cpuid: config["Kernel"]["Emulate"]["Cpuid1Data"] = self.utils.hex_to_bytes("{}{}".format(spoof_cpuid, "0"*8*3)) config["Kernel"]["Emulate"]["Cpuid1Mask"] = self.utils.hex_to_bytes("{}{}".format("F"*8, "0"*8*3)) - config["Kernel"]["Emulate"]["DummyPowerManagement"] = "AMD" in hardware.get("CPU Manufacturer") or \ - self.is_low_end_intel_cpu(hardware.get("Processor Name")) + config["Kernel"]["Emulate"]["DummyPowerManagement"] = "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") or \ + self.is_low_end_intel_cpu(hardware_report.get("CPU").get("Processor Name")) config["Kernel"]["Force"] = [] config["Kernel"]["Patch"] = self.load_kernel_patch( - hardware.get("Motherboard Chipset"), - hardware.get("CPU Manufacturer"), - hardware.get("CPU Codename"), - hardware["CPU Cores"], - hardware["Discrete GPU"].get("Manufacturer", "") or hardware["Integrated GPU"].get("Manufacturer", ""), - efi_option.get("Synchronize the TSC") + hardware_report.get("Motherboard").get("Motherboard Chipset"), + hardware_report.get("CPU").get("CPU Manufacturer"), + hardware_report.get("CPU").get("CPU Cores"), + list(hardware_report.get("GPU").items())[-1][-1].get("Manufacturer"), + kexts ) - config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"] = not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), end=2) is None - config["Kernel"]["Quirks"]["AppleXcpmCfgLock"] = False if "AMD" in hardware.get("CPU Manufacturer") else not config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"] - config["Kernel"]["Quirks"]["AppleXcpmExtraMsrs"] = self.is_intel_hedt_cpu(hardware.get("CPU Codename")) and not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), end=4) is None + config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"] = not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=2) is None + config["Kernel"]["Quirks"]["AppleXcpmCfgLock"] = False if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") else not config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"] + config["Kernel"]["Quirks"]["AppleXcpmExtraMsrs"] = self.is_intel_hedt_cpu(hardware_report.get("CPU").get("CPU Codename")) and not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=4) is None config["Kernel"]["Quirks"]["CustomSMBIOSGuid"] = True - config["Kernel"]["Quirks"]["DisableIoMapper"] = not "AMD" in hardware.get("CPU Manufacturer") - config["Kernel"]["Quirks"]["DisableRtcChecksum"] = "ASUS" in hardware.get("Motherboard Name") or "HP" in hardware.get("Motherboard Name") - config["Kernel"]["Quirks"]["LapicKernelPanic"] = "HP" in hardware.get("Motherboard Name") + config["Kernel"]["Quirks"]["DisableIoMapper"] = not "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") + config["Kernel"]["Quirks"]["DisableRtcChecksum"] = "ASUS" in hardware_report.get("Motherboard").get("Motherboard Name") or "HP" in hardware_report.get("Motherboard").get("Motherboard Name") + config["Kernel"]["Quirks"]["LapicKernelPanic"] = "HP" in hardware_report.get("Motherboard").get("Motherboard Name") config["Kernel"]["Quirks"]["PanicNoKextDump"] = config["Kernel"]["Quirks"]["PowerTimeoutKernelPanic"] = True - config["Kernel"]["Quirks"]["ProvideCurrentCpuInfo"] = "AMD" in hardware.get("CPU Manufacturer") or \ - not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), start=13) is None + config["Kernel"]["Quirks"]["ProvideCurrentCpuInfo"] = "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") or \ + not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=13) is None config["Misc"]["BlessOverride"] = [] config["Misc"]["Boot"]["HideAuxiliary"] = False @@ -324,46 +332,32 @@ class ConfigProdigy: config["Misc"]["Entries"] = [] config["Misc"]["Security"]["AllowSetDefault"] = True config["Misc"]["Security"]["ScanPolicy"] = 0 - config["Misc"]["Security"]["SecureBootModel"] = "Default" if self.utils.parse_darwin_version("20.0.0") <= self.utils.parse_darwin_version(efi_option.get("macOS Version")) < self.utils.parse_darwin_version("23.0.0") else "Disabled" + config["Misc"]["Security"]["SecureBootModel"] = "Default" if self.utils.parse_darwin_version("20.0.0") <= self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("23.0.0") else "Disabled" config["Misc"]["Security"]["Vault"] = "Optional" config["Misc"]["Tools"] = [] - if efi_option.get("Custom CPU Name"): - config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpu"] = 1 - config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = hardware.get("Processor Name") del config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["#INFO (prev-lang:kbd)"] - config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] = self.boot_args( - hardware.get("Motherboard Name"), - hardware.get("Platform"), - hardware.get("CPU Manufacturer"), - hardware.get("CPU Codename"), - hardware.get("CPU Cores"), - hardware.get("Discrete GPU").get("GPU Codename", ""), - hardware.get("Discrete GPU").get("Device ID", ""), - hardware.get("Integrated GPU Name"), - hardware.get("Codec ID"), - hardware.get("Touchpad Communication"), - ", ".join(list(hardware.get("Unsupported Devices").keys())), - efi_option.get("Custom CPU Name"), - efi_option.get("macOS Version") - ) - config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["csr-active-config"] = self.utils.hex_to_bytes(self.csr_active_config(efi_option.get("macOS Version"))) + config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] = self.boot_args(hardware_report, unsupported_devices, macos_version) + config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["csr-active-config"] = self.utils.hex_to_bytes(self.csr_active_config(macos_version)) config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["prev-lang:kbd"] = "en:252" - if efi_option.get("Custom CPU Name"): - config["NVRAM"]["Delete"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"].extend(["revcpu", "revcpuname"]) config["NVRAM"]["Delete"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"].append("csr-active-config") - config["PlatformInfo"]["Generic"].update(self.smbios.generate_smbios(efi_option.get("SMBIOS"))) - if efi_option.get("Custom CPU Name"): - config["PlatformInfo"]["Generic"]["ProcessorType"] = 1537 if int(hardware["CPU Cores"]) < 8 else 3841 + config["PlatformInfo"]["Generic"].update(self.smbios.generate_smbios(smbios_model)) config["PlatformInfo"]["Generic"]["ROM"] = self.utils.hex_to_bytes(config["PlatformInfo"]["Generic"]["ROM"]) config["PlatformInfo"]["UpdateSMBIOSMode"] = "Custom" config["UEFI"]["APFS"]["MinDate"] = config["UEFI"]["APFS"]["MinVersion"] = -1 config["UEFI"]["Drivers"] = self.load_drivers() - config["UEFI"]["Quirks"]["IgnoreInvalidFlexRatio"] = not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), end=4) is None + config["UEFI"]["Quirks"]["IgnoreInvalidFlexRatio"] = not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=4) is None config["UEFI"]["Quirks"]["ReleaseUsbOwnership"] = True - config["UEFI"]["Quirks"]["UnblockFsConnect"] = "HP" in hardware.get("Motherboard Name") + config["UEFI"]["Quirks"]["UnblockFsConnect"] = "HP" in hardware_report.get("Motherboard").get("Motherboard Name") config["UEFI"]["ReservedMemory"] = [] + if not (" Core" in hardware_report.get("CPU").get("Processor Name") and \ + self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=12)): + config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpu"] = 1 + config["NVRAM"]["Add"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["revcpuname"] = hardware_report.get("CPU").get("Processor Name") + config["NVRAM"]["Delete"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"].extend(["revcpu", "revcpuname"]) + config["PlatformInfo"]["Generic"]["ProcessorType"] = 1537 if int(hardware_report.get("CPU").get("CPU Cores")) < 8 else 3841 + return config \ No newline at end of file diff --git a/Scripts/efi_builder.py b/Scripts/efi_builder.py index bd2127c..f155ec6 100644 --- a/Scripts/efi_builder.py +++ b/Scripts/efi_builder.py @@ -1,4 +1,3 @@ -from Scripts.datasets import cpu_data from Scripts import config_prodigy from Scripts import kext_maestro from Scripts import utils @@ -11,249 +10,7 @@ class builder: self.config = config_prodigy.ConfigProdigy() self.kext = kext_maestro.KextMaestro() self.utils = utils.Utils() - self.intel_igpu_properties = { - "Ice Lake": { - "Laptop": { - "AAPL,ig-platform-id": "0000528A", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - } - }, - "Comet Lake": { - "Desktop": { - "AAPL,ig-platform-idEx": "0300C89B", - "AAPL,ig-platform-id": "07009B3E", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - }, - "NUC": { - "AAPL,ig-platform-id": "07009B3E", - "device-id": "9B3E0000", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - }, - "Laptop": { - "AAPL,ig-platform-id": "00009B3E", - "device-id": "9B3E0000", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - } - }, - "Coffee Lake": { - "Desktop": { - "AAPL,ig-platform-idEx": "0300913E", - "AAPL,ig-platform-id": "07009B3E" - }, - "NUC": { - "AAPL,ig-platform-id": "07009B3E", - "device-id": "9B3E0000", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - }, - "Laptop": { - "AAPL,ig-platform-id": "0900A53E", - "device-id": "9B3E0000", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - } - }, - "Whiskey Lake": { - "NUC": { - "AAPL,ig-platform-id": "07009B3E", - "device-id": "9B3E0000", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - }, - "Laptop": { - "AAPL,ig-platform-id": "0900A53E", - "device-id": "9B3E0000", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - } - }, - "Amber Lake": { - "Laptop": { - "AAPL,ig-platform-id": "0000C087", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - } - }, - "Kaby Lake": { - "Desktop": { - "AAPL,ig-platform-idEx": "03001259", - "AAPL,ig-platform-id": "00001259", - "device-id": "12590000" - }, - "NUC": { - "AAPL,ig-platform-id": "00001659", - "device-id": "16590000", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - }, - "Laptop": { - "AAPL,ig-platform-id": "00001B59", - "device-id": "1B590000", - "framebuffer-con1-alldata": "01050A00 00080000 87010000 02040A00 00080000 87010000 FF000000 01000000 20000000", - "framebuffer-con1-enable": "01000000", - "#framebuffer-con2-alldata": "01050A00 00080000 87010000 03060A00 00040000 87010000 FF000000 01000000 20000000", - "#framebuffer-con2-enable": "01000000", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - } - }, - "Skylake": { - "Desktop": { - "AAPL,ig-platform-idEx": "01001219", - "AAPL,ig-platform-id": "00001219" - }, - "NUC": { - "AAPL,ig-platform-id": "05003B19", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - }, - "Laptop": { - "AAPL,ig-platform-id": "00001619", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - } - }, - "Broadwell": { - "Desktop": { - "AAPL,ig-platform-idEx": "07002216", - "AAPL,ig-platform-id": "07002216" - }, - "NUC": { - "AAPL,ig-platform-id": "02001616", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - }, - "Laptop": { - "AAPL,ig-platform-id": "06002616", - "framebuffer-fbmem": "00009000", - "framebuffer-stolenmem": "00003001" - } - }, - "Haswell": { - "Desktop": { - "AAPL,ig-platform-idEx": "04001204", - "AAPL,ig-platform-id": "0300220D" - }, - "NUC": { - "AAPL,ig-platform-id": "0300220D", - "device-id": "12040000", - "framebuffer-cursormem": "00009000" - }, - "Laptop": { - "AAPL,ig-platform-id": "0600260A", - "device-id": "12040000", - "framebuffer-cursormem": "00009000" - } - }, - "Ivy Bridge": { - "Desktop": { - "AAPL,ig-platform-idEx": "07006201", - "AAPL,ig-platform-id": "0A006601" - }, - "Laptop": { - "AAPL,ig-platform-id": "03006601" - } - }, - "Sandy Bridge": { - "Desktop": { - "AAPL,snb-platform-idEx": "00000500", - "AAPL,snb-platform-id": "10000300", - "device-id": "26010000" - }, - "Laptop": { - "AAPL,snb-platform-id": "00000100" - } - } - } - - def is_low_end_intel_cpu(self, processor_name): - 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 self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("18.0.0")) or \ - ("Ivy Bridge" in cpu_codename and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("21.0.0")) or \ - (("Haswell" in cpu_codename or "Broadwell" in cpu_codename) and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("22.0.0")) or \ - (("Skylake" in cpu_codename or "Kaby Lake" in cpu_codename) and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0")) or \ - (("Amber Lake" in cpu_codename or "Whiskey Lake" in cpu_codename) and self.utils.parse_darwin_version(macos_version) == self.utils.parse_darwin_version("17.0.0")) or \ - ("Ice Lake" in cpu_codename and self.utils.parse_darwin_version("19.4.0") >= self.utils.parse_darwin_version(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 self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("22.0.0"): - gpu_codename = "Kaby Lake" - if "Kaby Lake-R".upper() in gpu_codename.upper() and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0"): - gpu_codename = "Coffee Lake" - - gpu_codename = self.utils.contains_any(cpu_data.IntelCPUGenerations, gpu_codename) - if not "Intel" in integrated_gpu_manufacturer or not integrated_gpu_name or self.is_low_end_intel_cpu(processor_name) or not self.check_igpu_compatibility(gpu_codename, macos_version) or not self.intel_igpu_properties.get(gpu_codename, True): - return {} - igpu_properties = self.intel_igpu_properties[gpu_codename][platform] - - if "Desktop" in platform: - if discrete_gpu: - if "Sandy Bridge" in gpu_codename: - return { - "AAPL,snb-platform-id": igpu_properties["AAPL,snb-platform-idEx"], - "device-id": "02010000", - } - else: - return { - "AAPL,ig-platform-id": igpu_properties["AAPL,ig-platform-idEx"] - } - del igpu_properties["AAPL,ig-platform-idEx"] - if "Haswell" in gpu_codename and not "440" in integrated_gpu_name: - igpu_properties["device-id"] = "12040000" - elif "Skylake" in gpu_codename and "P530" in integrated_gpu_name: - igpu_properties["device-id"] = "12040000" - else: - if "Haswell" in gpu_codename and "5" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "0500260A" - del igpu_properties["device-id"] - elif "Broadwell" in gpu_codename and "56" in integrated_gpu_name: - igpu_properties["device-id"] = "26160000" - elif "Skylake" in gpu_codename: - if "NUC" in platform: - if "51" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "00001E19" - elif "52" in integrated_gpu_name or "53" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "02001619" - elif "54" in integrated_gpu_name or "55" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "02002619" - - if "510" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "00001B19" - igpu_properties["device-id"] = "02190000" - elif "550" in integrated_gpu_name or "P530" in integrated_gpu_name: - igpu_properties["device-id"] = "16190000" - elif "Kaby Lake" in gpu_codename: - if "NUC" in platform: - if "15" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "00001E59" - elif "63" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "00001B59" - elif "40" in integrated_gpu_name or "65" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "02002659" - else: - if "UHD" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "0000C087" - igpu_properties["device-id"] = "16590000" - elif self.utils.contains_any(cpu_data.IntelCPUGenerations, gpu_codename, start=8, end=11): - if "NUC" in platform: - if "55" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "0000A53E" - del igpu_properties["device-id"] - else: - if "3" in integrated_gpu_name: - igpu_properties["AAPL,ig-platform-id"] = "0900A53E" - - igpu_properties["hda-gfx"] = "onboard-1" - igpu_properties["framebuffer-patch-enable"] = "01000000" - return igpu_properties - def clean_up(self, config, efi_directory): files_to_remove = [] @@ -264,13 +21,6 @@ class builder: if not driver_path in driver_loaded: files_to_remove.append(os.path.join(drivers_directory, driver_path)) - kexts_directory = os.path.join(efi_directory, "EFI", "OC", "Kexts") - kext_list = self.utils.find_matching_paths(kexts_directory, extension_filter=".kext") - kext_loaded = [os.path.basename(kext.get("BundlePath")) for kext in config.get("Kernel").get("Add")] - for kext_path, type in kext_list: - if not os.path.basename(kext_path) in kext_loaded: - files_to_remove.append(os.path.join(kexts_directory, kext_path)) - tools_directory = os.path.join(efi_directory, "EFI", "OC", "Tools") tool_list = self.utils.find_matching_paths(tools_directory, extension_filter=".efi") tool_loaded = [tool.get("Path") for tool in config.get("Misc").get("Tools")] @@ -294,59 +44,19 @@ class builder: print("") self.utils.request_input() - def build_efi(self, hardware, unsupported_devices, smbios_model, macos_version, acpi_guru): + def build_efi(self, hardware_report, unsupported_devices, smbios_model, macos_version, acpi_guru, kext_maestro): efi_directory = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "Results") self.utils.create_folder(efi_directory, remove_content=True) forbidden_chars = r'[<>:"/\\|?*]' - self.utils.write_file(os.path.join(efi_directory, re.sub(forbidden_chars, '_', hardware.get("Motherboard").get("Motherboard Name")) + ".json"), hardware) + self.utils.write_file(os.path.join(efi_directory, re.sub(forbidden_chars, '_', hardware_report.get("Motherboard").get("Motherboard Name")) + ".json"), hardware_report) if not os.path.exists(self.kext.ock_files_dir): raise Exception("Directory '{}' does not exist.".format(self.kext.ock_files_dir)) source_efi_dir = os.path.join(self.kext.ock_files_dir, "OpenCore") shutil.copytree(source_efi_dir, efi_directory, dirs_exist_ok=True) - - hardware_shorc = {} - hardware_shorc["Motherboard Name"] = hardware["Motherboard"].get("Motherboard Name").upper() - hardware_shorc["Motherboard Chipset"] = hardware["Motherboard"].get("Motherboard Chipset").upper() - hardware_shorc["Platform"] = hardware["Motherboard"].get("Platform") - hardware_shorc["CPU Configuration"] = hardware["CPU"].get("CPU Configuration") - hardware_shorc["CPU Manufacturer"] = hardware["CPU"].get("CPU Manufacturer") - hardware_shorc["Processor Name"] = hardware["CPU"].get("Processor Name") - hardware_shorc["CPU Cores"] = hardware["CPU"].get("CPU Cores") - hardware_shorc["CPU Codename"] = hardware["CPU"].get("CPU Codename") - hardware_shorc["Instruction Set"] = hardware["CPU"].get("Instruction Set") - hardware_shorc["Integrated GPU"] = list(hardware.get("GPU").items())[-1][1] if "Integrated GPU" in list(hardware.get("GPU").items())[-1][1]["Device Type"] else {} - hardware_shorc["Integrated GPU Name"] = list(hardware.get("GPU").keys())[-1] if hardware_shorc["Integrated GPU"] else "" - hardware_shorc["Discrete GPU"] = list(hardware.get("GPU").items())[0][1].copy() if "Discrete GPU" in list(hardware.get("GPU").items())[0][1]["Device Type"] else {} - if hardware_shorc["Discrete GPU"]: - hardware_shorc["Discrete GPU"]["GPU Name"] = list(hardware.get("GPU").keys())[0] - hardware_shorc["Network"] = hardware.get("Network") - hardware_shorc["Bluetooth"] = [device_props.get("Device ID") for device_name, device_props in hardware.get("Bluetooth", {}).items()] - hardware_shorc["Codec ID"] = next((device_props.get("Codec ID") for device_name, device_props in hardware.get("Audio").items()), None) - hardware_shorc["SD Controller"] = hardware.get("SD Controller") - hardware_shorc["Input"] = hardware.get("Input") - input_devices = ", ".join(list(hardware_shorc.get("Input", {}).keys())) - hardware_shorc["Touchpad Communication"] = "None" if not "Laptop" in hardware_shorc.get("Platform") else "I2C" if "I2C" in input_devices else "PS2" if "PS2" in input_devices else "None" - hardware_shorc["Storage Controllers"] = hardware.get("Storage Controllers") - hardware_shorc["Intel MEI"] = hardware.get("Intel MEI") - hardware_shorc["Unsupported Devices"] = unsupported_devices - - efi_option = {} - efi_option["macOS Version"] = macos_version - efi_option["Custom CPU Name"] = not (" Core" in hardware_shorc.get("Processor Name") and self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_shorc.get("CPU Codename"), end=12)) - efi_option["Synchronize the TSC"] = "Laptop" in hardware_shorc["Platform"] and "ASUS" in hardware_shorc["Motherboard Name"] or "AMD" in hardware_shorc["Integrated GPU"].get("Manufacturer", "") or self.config.is_intel_hedt_cpu(hardware_shorc["CPU Codename"]) - efi_option["iGPU Properties"] = self.igpu_properties( - hardware_shorc["Platform"], - hardware_shorc.get("Processor Name"), - hardware_shorc["Integrated GPU"].get("GPU Codename", ""), - hardware_shorc["Discrete GPU"], - hardware_shorc["Integrated GPU"].get("Manufacturer", ""), - hardware_shorc["Integrated GPU Name"], - efi_option.get("macOS Version")) - efi_option["SMBIOS"] = smbios_model config_file = os.path.join(efi_directory, "EFI", "OC", "config.plist") config_data = self.utils.read_file(config_file) @@ -354,9 +64,9 @@ class builder: if not config_data: raise Exception("Error: The file {} does not exist.".format(config_file)) - self.config.genarate(hardware_shorc, efi_option, config_data) + self.config.genarate(hardware_report, unsupported_devices, smbios_model, macos_version, kext_maestro.kexts, config_data) - acpi_guru.hardware_report = hardware + acpi_guru.hardware_report = hardware_report acpi_guru.unsupported_devices = unsupported_devices acpi_guru.acpi_directory = os.path.join(efi_directory, "EFI", "OC", "ACPI") acpi_guru.smbios_model = smbios_model @@ -379,40 +89,9 @@ class builder: config_data["ACPI"]["Patch"] = acpi_guru.apply_acpi_patches(config_data["ACPI"]["Patch"]) - kexts = self.kext.gathering_kexts( - hardware_shorc["Motherboard Name"], - hardware_shorc["Platform"], - hardware_shorc["CPU Configuration"], - hardware_shorc["CPU Manufacturer"], - hardware_shorc["CPU Codename"], - hardware_shorc["CPU Cores"], - hardware_shorc["Instruction Set"], - hardware_shorc["Discrete GPU"].get("GPU Codename", ""), - hardware_shorc["Integrated GPU"], - hardware_shorc.get("Network"), - hardware_shorc.get("Bluetooth"), - hardware_shorc.get("Codec ID"), - hardware_shorc["Input"], - hardware_shorc.get("SD Controller"), - hardware_shorc.get("Storage Controllers"), - hardware.get("USB Controllers"), - efi_option.get("SMBIOS"), - efi_option.get("Custom CPU Name"), - efi_option.get("Synchronize the TSC"), - acpi_guru.patches, - efi_option.get("macOS Version") - ) - kexts_directory = os.path.join(efi_directory, "EFI", "OC", "Kexts") - self.kext.install_kexts_to_efi(kexts, efi_option.get("macOS Version"), kexts_directory) - config_data["Kernel"]["Add"] = self.kext.load_kexts( - kexts, - hardware_shorc["Motherboard Name"], - hardware_shorc["Platform"], - hardware_shorc["CPU Manufacturer"], - hardware_shorc["Discrete GPU"].get("GPU Codename", ""), - efi_option["macOS Version"] - ) + kext_maestro.install_kexts_to_efi(macos_version, kexts_directory) + config_data["Kernel"]["Add"] = kext_maestro.load_kexts(macos_version, kexts_directory) self.utils.write_file(config_file, config_data) diff --git a/Scripts/kext_maestro.py b/Scripts/kext_maestro.py index 56314fb..353cb1a 100644 --- a/Scripts/kext_maestro.py +++ b/Scripts/kext_maestro.py @@ -1,6 +1,6 @@ from Scripts.datasets import cpu_data -from Scripts.datasets import os_data +from Scripts.datasets import kext_data from Scripts.datasets import pci_data from Scripts import codec_layouts from Scripts import utils @@ -19,527 +19,8 @@ class KextMaestro: "HDAConfigDefault" ] self.ock_files_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "OCK_Files") - self.kext_loading_sequence = [ - { - "MainKext": "Lilu", - "BundlePath": "Lilu.kext", - "ExecutablePath": "Contents/MacOS/Lilu", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VirtualSMC", - "BundlePath": "VirtualSMC.kext", - "ExecutablePath": "Contents/MacOS/VirtualSMC", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "ECEnabler", - "BundlePath": "ECEnabler.kext", - "ExecutablePath": "Contents/MacOS/ECEnabler", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VirtualSMC", - "BundlePath": "SMCBatteryManager.kext", - "ExecutablePath": "Contents/MacOS/SMCBatteryManager", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VirtualSMC", - "BundlePath": "SMCDellSensors.kext", - "ExecutablePath": "Contents/MacOS/SMCDellSensors", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VirtualSMC", - "BundlePath": "SMCLightSensor.kext", - "ExecutablePath": "Contents/MacOS/SMCLightSensor", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VirtualSMC", - "BundlePath": "SMCProcessor.kext", - "ExecutablePath": "Contents/MacOS/SMCProcessor", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VirtualSMC", - "BundlePath": "SMCSuperIO.kext", - "ExecutablePath": "Contents/MacOS/SMCSuperIO", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "WhateverGreen", - "BundlePath": "WhateverGreen.kext", - "ExecutablePath": "Contents/MacOS/WhateverGreen", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "NootedRed", - "BundlePath": "NootedRed.kext", - "ExecutablePath": "Contents/MacOS/NootedRed", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "NootRX", - "BundlePath": "NootRX.kext", - "ExecutablePath": "Contents/MacOS/NootRX", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "AppleALC", - "BundlePath": "AppleALC.kext", - "ExecutablePath": "Contents/MacOS/AppleALC", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "AirportItlwm", - "BundlePath": "AirportItlwm.kext", - "ExecutablePath": "Contents/MacOS/AirportItlwm", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "itlwm", - "BundlePath": "itlwm.kext", - "ExecutablePath": "Contents/MacOS/itlwm", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "IOSkywalkFamily", - "BundlePath": "IOSkywalkFamily.kext", - "ExecutablePath": "Contents/MacOS/IOSkywalkFamily", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "IO80211FamilyLegacy", - "BundlePath": "IO80211FamilyLegacy.kext", - "ExecutablePath": "Contents/MacOS/IO80211FamilyLegacy", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "IO80211FamilyLegacy", - "BundlePath": "IO80211FamilyLegacy.kext/Contents/PlugIns/AirPortBrcmNIC.kext", - "ExecutablePath": "Contents/MacOS/AirPortBrcmNIC", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "AirportBrcmFixup", - "BundlePath": "AirportBrcmFixup.kext", - "ExecutablePath": "Contents/MacOS/AirportBrcmFixup", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "AirportBrcmFixup", - "BundlePath": "AirportBrcmFixup.kext/Contents/PlugIns/AirPortBrcm4360_Injector.kext", - "ExecutablePath": "", - "MaxKernel": "19.99.99", - "MinKernel": "" - }, - { - "MainKext": "AirportBrcmFixup", - "BundlePath": "AirportBrcmFixup.kext/Contents/PlugIns/AirPortBrcmNIC_Injector.kext", - "ExecutablePath": "", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "IntelBluetoothFirmware", - "BundlePath": "IntelBluetoothFirmware.kext", - "ExecutablePath": "Contents/MacOS/IntelBluetoothFirmware", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "IntelBluetoothFirmware", - "BundlePath": "IntelBTPatcher.kext", - "ExecutablePath": "Contents/MacOS/IntelBTPatcher", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "IntelBluetoothFirmware", - "BundlePath": "IntelBluetoothInjector.kext", - "ExecutablePath": "", - "MaxKernel": "20.99.99", - "MinKernel": "" - }, - { - "MainKext": "BlueToolFixup", - "BundlePath": "BlueToolFixup.kext", - "ExecutablePath": "Contents/MacOS/BlueToolFixup", - "MaxKernel": "", - "MinKernel": "21.0.0" - }, - { - "MainKext": "BrcmPatchRAM", - "BundlePath": "BrcmBluetoothInjector.kext", - "ExecutablePath": "", - "MaxKernel": "20.99.99", - "MinKernel": "" - }, - { - "MainKext": "BrcmPatchRAM", - "BundlePath": "BrcmFirmwareData.kext", - "ExecutablePath": "Contents/MacOS/BrcmFirmwareData", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "BrcmPatchRAM", - "BundlePath": "BrcmPatchRAM2.kext", - "ExecutablePath": "Contents/MacOS/BrcmPatchRAM2", - "MaxKernel": "18.99.99", - "MinKernel": "" - }, - { - "MainKext": "BrcmPatchRAM", - "BundlePath": "BrcmPatchRAM3.kext", - "ExecutablePath": "Contents/MacOS/BrcmPatchRAM3", - "MaxKernel": "", - "MinKernel": "19.0.0" - }, - { - "MainKext": "AppleIGC", - "BundlePath": "AppleIGC.kext", - "ExecutablePath": "Contents/MacOS/AppleIGC", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "AtherosE2200Ethernet", - "BundlePath": "AtherosE2200Ethernet.kext", - "ExecutablePath": "Contents/MacOS/AtherosE2200Ethernet", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "IntelMausi", - "BundlePath": "IntelMausi.kext", - "ExecutablePath": "Contents/MacOS/IntelMausi", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "LucyRTL8125Ethernet", - "BundlePath": "LucyRTL8125Ethernet.kext", - "ExecutablePath": "Contents/MacOS/LucyRTL8125Ethernet", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "NullEthernet", - "BundlePath": "NullEthernet.kext", - "ExecutablePath": "Contents/MacOS/NullEthernet", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "RealtekRTL8100", - "BundlePath": "RealtekRTL8100.kext", - "ExecutablePath": "Contents/MacOS/RealtekRTL8100", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "RealtekRTL8111", - "BundlePath": "RealtekRTL8111.kext", - "ExecutablePath": "Contents/MacOS/RealtekRTL8111", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "BrightnessKeys", - "BundlePath": "BrightnessKeys.kext", - "ExecutablePath": "Contents/MacOS/BrightnessKeys", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "AsusSMC", - "BundlePath": "AsusSMC.kext", - "ExecutablePath": "Contents/MacOS/AsusSMC", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooInput", - "BundlePath": "VoodooInput.kext", - "ExecutablePath": "Contents/MacOS/VoodooInput", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooPS2", - "BundlePath": "VoodooPS2Controller.kext", - "ExecutablePath": "Contents/MacOS/VoodooPS2Controller", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooPS2", - "BundlePath": "VoodooPS2Controller.kext/Contents/PlugIns/VoodooPS2Keyboard.kext", - "ExecutablePath": "Contents/MacOS/VoodooPS2Keyboard", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooPS2", - "BundlePath": "VoodooPS2Controller.kext/Contents/PlugIns/VoodooPS2Mouse.kext", - "ExecutablePath": "Contents/MacOS/VoodooPS2Mouse", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooPS2", - "BundlePath": "VoodooPS2Controller.kext/Contents/PlugIns/VoodooPS2Trackpad.kext", - "ExecutablePath": "Contents/MacOS/VoodooPS2Trackpad", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooRMI", - "BundlePath": "VoodooRMI.kext", - "ExecutablePath": "Contents/MacOS/VoodooRMI", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooRMI", - "BundlePath": "VoodooSMBus.kext", - "ExecutablePath": "Contents/MacOS/VoodooSMBus", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooSMBus", - "BundlePath": "VoodooSMBus.kext", - "ExecutablePath": "Contents/MacOS/VoodooSMBus", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooRMI", - "BundlePath": "VoodooRMI.kext/Contents/PlugIns/RMISMBus.kext", - "ExecutablePath": "Contents/MacOS/RMISMBus", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooI2C", - "BundlePath": "VoodooI2C.kext/Contents/PlugIns/VoodooI2CServices.kext", - "ExecutablePath": "Contents/MacOS/VoodooI2CServices", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooI2C", - "BundlePath": "VoodooI2C.kext/Contents/PlugIns/VoodooGPIO.kext", - "ExecutablePath": "Contents/MacOS/VoodooGPIO", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooI2C", - "BundlePath": "VoodooI2C.kext", - "ExecutablePath": "Contents/MacOS/VoodooI2C", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "BigSurface", - "BundlePath": "BigSurface.kext/Contents/PlugIns/VoodooInput.kext", - "ExecutablePath": "Contents/MacOS/VoodooInput", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "BigSurface", - "BundlePath": "BigSurface.kext/Contents/PlugIns/VoodooGPIO.kext", - "ExecutablePath": "Contents/MacOS/VoodooGPIO", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "BigSurface", - "BundlePath": "BigSurface.kext/Contents/PlugIns/VoodooSerial.kext", - "ExecutablePath": "Contents/MacOS/VoodooSerial", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "BigSurface", - "BundlePath": "BigSurface.kext", - "ExecutablePath": "Contents/MacOS/BigSurface", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "BigSurface", - "BundlePath": "BigSurface.kext/Contents/PlugIns/BigSurfaceHIDDriver.kext", - "ExecutablePath": "Contents/MacOS/BigSurfaceHIDDriver", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooRMI", - "BundlePath": "VoodooRMI.kext/Contents/PlugIns/RMII2C.kext", - "ExecutablePath": "Contents/MacOS/RMII2C", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "lzh", - "BundlePath": "VoodooI2CELAN.kext", - "ExecutablePath": "Contents/MacOS/VoodooI2CELAN", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "VoodooI2C", - "BundlePath": "VoodooI2CHID.kext", - "ExecutablePath": "Contents/MacOS/VoodooI2CHID", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "AlpsHID", - "BundlePath": "AlpsHID.kext", - "ExecutablePath": "Contents/MacOS/AlpsHID", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "lzh", - "BundlePath": "VoodooI2CSynaptics.kext", - "ExecutablePath": "Contents/MacOS/VoodooI2CSynaptics", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "AppleMCEReporterDisabler", - "BundlePath": "AppleMCEReporterDisabler.kext", - "ExecutablePath": "", - "MaxKernel": "", - "MinKernel": "21.0.0" - }, - { - "MainKext": "AMFIPass", - "BundlePath": "AMFIPass.kext", - "ExecutablePath": "Contents/MacOS/AMFIPass", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "CpuTopologyRebuild", - "BundlePath": "CpuTopologyRebuild.kext", - "ExecutablePath": "Contents/MacOS/CpuTopologyRebuild", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "CtlnaAHCIPort", - "BundlePath": "CtlnaAHCIPort.kext", - "ExecutablePath": "Contents/MacOS/CtlnaAHCIPort", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "RealtekCardReader", - "BundlePath": "RealtekCardReader.kext", - "ExecutablePath": "Contents/MacOS/RealtekCardReader", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "RealtekCardReaderFriend", - "BundlePath": "RealtekCardReaderFriend.kext", - "ExecutablePath": "Contents/MacOS/RealtekCardReaderFriend", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "ForgedInvariant", - "BundlePath": "ForgedInvariant.kext", - "ExecutablePath": "Contents/MacOS/ForgedInvariant", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "RestrictEvents", - "BundlePath": "RestrictEvents.kext", - "ExecutablePath": "Contents/MacOS/RestrictEvents", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "HibernationFixup", - "BundlePath": "HibernationFixup.kext", - "ExecutablePath": "Contents/MacOS/HibernationFixup", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "RTCMemoryFixup", - "BundlePath": "RTCMemoryFixup.kext", - "ExecutablePath": "Contents/MacOS/RTCMemoryFixup", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "NVMeFix", - "BundlePath": "NVMeFix.kext", - "ExecutablePath": "Contents/MacOS/NVMeFix", - "MaxKernel": "", - "MinKernel": "18.0.0" - }, - { - "MainKext": "CryptexFixup", - "BundlePath": "CryptexFixup.kext", - "ExecutablePath": "Contents/MacOS/CryptexFixup", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "GenericUSBXHCI", - "BundlePath": "GenericUSBXHCI.kext", - "ExecutablePath": "Contents/MacOS/GenericUSBXHCI", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "XHCI-unsupported", - "BundlePath": "XHCI-unsupported.kext", - "ExecutablePath": "", - "MaxKernel": "", - "MinKernel": "" - }, - { - "MainKext": "USBMap", - "BundlePath": "USBMap.kext", - "ExecutablePath": "", - "MaxKernel": "", - "MinKernel": "" - } - ] - + self.kexts = kext_data.kexts + def extract_pci_id(self, kext_path): if not os.path.exists(kext_path): return [] @@ -580,89 +61,134 @@ class KextMaestro: return pci_ids - def gathering_kexts(self, motherboard_name, platform, cpu_configuration, cpu_manufacturer, cpu_codename, cpu_cores, simd_features, discrete_gpu_codename, integrated_gpu, network, bluetooth, codec_id, input, sd_controller, storage_controllers, usb_controllers, smbios, custom_cpu_name, tsc_sync, acpi_patches, macos_version): - kexts = [ - "Lilu", - "VirtualSMC", - "USBMap" - ] + def is_intel_hedt_cpu(self, cpu_codename): + return "-E" in cpu_codename and not self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, end=4) is None or \ + ("-X" in cpu_codename or "-W" in cpu_codename) and not self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=4, end=6) is None + + def get_kext_index(self, name): + for index, kext in enumerate(self.kexts): + if kext.name == name: + return index + return None - if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0") or custom_cpu_name or "MacPro7,1" in smbios: - kexts.append("RestrictEvents") + def check_kext(self, index, target_darwin_version): + kext = self.kexts[index] - if codec_id in codec_layouts.data: - kexts.append("AppleALC") + if kext.checked or not self.utils.parse_darwin_version(kext.min_darwin_version) <= self.utils.parse_darwin_version(target_darwin_version) <= self.utils.parse_darwin_version(kext.max_darwin_version): + return + + kext.checked = True + + for requires_kext_name in kext.requires_kexts: + requires_kext_index = self.get_kext_index(requires_kext_name) + if requires_kext_index: + self.check_kext(requires_kext_index, target_darwin_version) + + if kext.conflict_group_id: + for other_kext in self.kexts: + if other_kext.conflict_group_id == kext.conflict_group_id and other_kext.name != kext.name: + other_kext.checked = False + + def select_required_kexts(self, hardware_report, smbios_model, macos_version, acpi_patches): + for kext in self.kexts: + kext.checked = kext.required + + selected_kexts = [] + + if "Intel" in hardware_report.get("CPU").get("CPU Manufacturer"): + selected_kexts.extend(("SMCProcessor", "SMCSuperIO")) + + if "Laptop" in hardware_report.get("Motherboard").get("Platform") and not "SURFACE" in hardware_report.get("Motherboard").get("Motherboard Name"): + selected_kexts.append("SMCBatteryManager") + if "DELL" in hardware_report.get("Motherboard").get("Motherboard Name"): + selected_kexts.append("SMCDellSensors") + selected_kexts.append("SMCLightSensor") + + if not (" Core" in hardware_report.get("CPU").get("Processor Name") and \ + self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), end=12)) or \ + self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0") or "MacPro7,1" in smbios_model: + selected_kexts.append("RestrictEvents") + + if list(hardware_report.get("Audio").items())[0][-1].get("Codec ID") in codec_layouts.data: + selected_kexts.append("AppleALC") - if "AMD" in cpu_manufacturer and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("21.4.0") or int(cpu_configuration) > 1 and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("19.0.0"): - kexts.append("AppleMCEReporterDisabler") + if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("21.4.0") or \ + int(hardware_report.get("CPU").get("CPU Configuration")) > 1 and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("19.0.0"): + selected_kexts.append("AppleMCEReporterDisabler") - if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("22.0.0") and not "AVX2" in simd_features: - kexts.append("CryptexFixup") + if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("22.0.0") and not "AVX2" in hardware_report.get("CPU").get("Instruction Set"): + selected_kexts.append("CryptexFixup") - if self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=13) and int(cpu_cores) > 6: - kexts.append("CpuTopologyRebuild") + if self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("CPU Codename"), start=13) and \ + int(hardware_report.get("CPU").get("CPU Cores")) > 6: + selected_kexts.append("CpuTopologyRebuild") - if tsc_sync: - kexts.append("ForgedInvariant") - - if "AMD" in cpu_manufacturer and integrated_gpu and not discrete_gpu_codename: - kexts.append("NootedRed") + if "AMD" in hardware_report.get("CPU").get("CPU Manufacturer") and \ + "Integrated GPU" in list(hardware_report.get("GPU").items())[0][-1].get("Device Type") and \ + "Integrated GPU" in list(hardware_report.get("GPU").items())[-1][-1].get("Device Type"): + selected_kexts.append("NootedRed") else: - kexts.append("NootRX" if "Navi 2" in discrete_gpu_codename else "WhateverGreen") + selected_kexts.append("NootRX" if "Navi 2" in list(hardware_report.get("GPU").items())[-1][-1].get("GPU Codename") else "WhateverGreen") - if any(patch.checked for patch in acpi_patches if patch.name == "RMNE"): - kexts.append("NullEthernet") + if "Laptop" in hardware_report.get("Motherboard").get("Platform") and "ASUS" in hardware_report.get("Motherboard").get("Motherboard Name") or \ + "NootedRed" in selected_kexts or \ + self.is_intel_hedt_cpu(hardware_report.get("CPU").get("CPU Codename")): + selected_kexts.append("ForgedInvariant") + ethernet_pci = None wifi_pci = None - for network_name, network_props in network.items(): + for network_name, network_props in hardware_report.get("Network", {}).items(): device_id = network_props.get("Device ID") 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 self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.0.0"): - kexts.extend(["AirportBrcmFixup", "IOSkywalkFamily", "IO80211FamilyLegacy", "AMFIPass"]) + selected_kexts.extend(("AirportBrcmFixup", "IOSkywalkFamily", "AMFIPass")) elif device_id in pci_data.NetworkIDs: - kexts.append("AirportBrcmFixup") + selected_kexts.append("AirportBrcmFixup") elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=21, end=108): - kexts.append("AirportItlwm" if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_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): - kexts.append("AtherosE2200Ethernet") - elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=122, end=173): - kexts.append("IntelMausi") - elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=173, end=176): - kexts.append("LucyRTL8125Ethernet") - elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=176, end=177): - kexts.append("RealtekRTL8100") - elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=177, end=181): - kexts.append("RealtekRTL8111") - elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=181, end=219): - kexts.append("AppleIGB") + selected_kexts.append("AirportItlwm" if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("23.0.0") else "itlwm") + elif self.utils.contains_any(pci_data.NetworkIDs, device_id, start=108, end=219): + ethernet_pci = pci_data.NetworkIDs.index(device_id) + if 107 < ethernet_pci < 115: + selected_kexts.append("AppleIGC") + elif 114 < ethernet_pci < 122: + selected_kexts.append("AtherosE2200Ethernet") + elif 121 < ethernet_pci < 173: + selected_kexts.append("IntelMausi") + elif 172 < ethernet_pci < 176: + selected_kexts.append("LucyRTL8125Ethernet") + elif 175 < ethernet_pci < 177: + selected_kexts.append("RealtekRTL8100") + elif 176 < ethernet_pci < 181: + selected_kexts.append("RealtekRTL8111") + elif 180 < ethernet_pci < 219: + selected_kexts.append("AppleIGB") - if bluetooth and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("21.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: - idx = pci_data.BluetoothIDs.index(usb_id) - - if idx < 99: - kexts.append("BrcmPatchRAM") - if bluetooth and self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("21.0.0"): - kexts.append("BlueToolFixup") + if not ethernet_pci: + selected_kexts.append("NullEthernet") + + for bluetooth_name, bluetooth_props in hardware_report.get("Bluetooth", {}).items(): + usb_id = bluetooth_props.get("Device ID") + + if usb_id in pci_data.BluetoothIDs: + if pci_data.BluetoothIDs.index(usb_id) < 99: + selected_kexts.append("BrcmFirmwareData") + if pci_data.BluetoothIDs[-1] == usb_id: + selected_kexts.append("BlueToolFixup") else: - kexts.append("IntelBluetoothFirmware") + selected_kexts.append("IntelBluetoothFirmware") - if "Laptop" in platform: - if "SURFACE" in motherboard_name: - kexts.append("BigSurface") + if "Laptop" in hardware_report.get("Motherboard").get("Platform"): + if "SURFACE" in hardware_report.get("Motherboard").get("Motherboard Name"): + selected_kexts.append("BigSurface") else: - if "ASUS" in motherboard_name: - kexts.append("AsusSMC") - kexts.append("BrightnessKeys") + if "ASUS" in hardware_report.get("Motherboard").get("Motherboard Name"): + selected_kexts.append("AsusSMC") + selected_kexts.append("BrightnessKeys") - for device_name, device_props in input.items(): + for device_name, device_props in hardware_report.get("Input").items(): if not device_props.get("Bus Type", "").startswith("ACPI"): continue @@ -672,107 +198,238 @@ class KextMaestro: idx = pci_data.InputIDs.index(device_id) if "PS/2" in device_name: - kexts.extend(["VoodooInput", "VoodooPS2"]) + selected_kexts.append("VoodooPS2Controller") if device_id.startswith("SYN"): - kexts.append("VoodooRMI") + selected_kexts.append("VoodooRMI") elif idx and 76 < idx < 80: - kexts.append("VoodooSMBus") + selected_kexts.append("VoodooSMBus") if "I2C" in device_name: - kexts.extend(["VoodooInput", "VoodooI2C"]) + selected_kexts.append("VoodooI2CHID") if idx: if idx < 77: - kexts.append("AlpsHID") + selected_kexts.append("AlpsHID") elif 79 < idx: - kexts.append("VoodooRMI") + selected_kexts.append("VoodooRMI") if any(patch.checked for patch in acpi_patches if patch.name == "BATP"): - kexts.append("ECEnabler") + selected_kexts.append("ECEnabler") - if sd_controller and sd_controller.get("Device ID") in pci_data.RealtekCardReaderIDs: - kexts.extend(["RealtekCardReader", "RealtekCardReaderFriend"]) + if hardware_report.get("SD Controller", {}).get("Device ID") in pci_data.RealtekCardReaderIDs: + selected_kexts.append("RealtekCardReader") - for controller_name, controller_props in storage_controllers.items(): + for controller_name, controller_props in hardware_report.get("Storage Controllers").items(): if "NVMe" in controller_name or "NVM Express" in controller_name: - kexts.append("NVMeFix") + selected_kexts.append("NVMeFix") else: if controller_props.get("Device ID") in pci_data.UnsupportedSATAControllerIDs and not "AHCI" in controller_name: - kexts.append("CtlnaAHCIPort") + selected_kexts.append("CtlnaAHCIPort") - for controller_name, controller_props in usb_controllers.items(): + for controller_name, controller_props in hardware_report.get("USB Controllers").items(): device_id = controller_props.get("Device ID") if device_id in pci_data.UnsupportedUSBControllerIDs: idx = pci_data.UnsupportedUSBControllerIDs.index(device_id) if idx == 0: - kexts.append("GenericUSBXHCI") + selected_kexts.append("GenericUSBXHCI") else: - kexts.append("XHCI-unsupported") + selected_kexts.append("XHCI-unsupported") - return sorted(list(set(kexts)))[::-1] - - 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[:2]) - elif "BlueToolFixup" in kext_name or "BrcmPatchRAM" in kext_name: - kext_name = "BrcmPatchRAM" + for name in selected_kexts: + self.check_kext(self.get_kext_index(name), macos_version) - source_kext_dir = os.path.join(self.ock_files_dir, kext_name) - if os.path.exists(source_kext_dir): - shutil.copytree(source_kext_dir, kexts_directory, dirs_exist_ok=True) + def install_kexts_to_efi(self, macos_version, kexts_directory): + for kext in self.kexts: + if kext.checked: + try: + source_kext_path = destination_kext_path = None + + kext_paths = self.utils.find_matching_paths(self.ock_files_dir, extension_filter=".kext", name_filter=kext.name) + for kext_path, type in kext_paths: + if "AirportItlwm" == kext.name: + version = macos_version[:2] + if self.utils.parse_darwin_version("23.4.0") <= self.utils.parse_darwin_version(macos_version): + version = "23.4" + elif self.utils.parse_darwin_version("23.0.0") <= self.utils.parse_darwin_version(macos_version): + version = "23.0" + + if version in kext_path: + source_kext_path = os.path.join(self.ock_files_dir, kext_path) + destination_kext_path = os.path.join(kexts_directory, os.path.basename(kext_path)) + break + else: + main_kext = kext_path.split("/")[0] + main_kext_index = self.get_kext_index(main_kext) + if not main_kext_index or self.kexts[main_kext_index].checked: + if os.path.splitext(os.path.basename(kext_path))[0] in kext.name: + source_kext_path = os.path.join(self.ock_files_dir, kext_path) + destination_kext_path = os.path.join(kexts_directory, os.path.basename(kext_path)) + break + + if os.path.exists(source_kext_path): + shutil.copytree(source_kext_path, destination_kext_path, dirs_exist_ok=True) + except: + continue - def load_kexts(self, kexts, motherboard_name, platform, cpu_manufacturer, discrete_gpu_codename, macos_version): + def load_kexts(self, macos_version, kexts_directory): kernel_add = [] unload_kext = [] - if not "DELL" in motherboard_name: - unload_kext.append("SMCDellSensors") - if "Desktop" in platform: - unload_kext.extend([ - "SMCBatteryManager", - "SMCLightSensor" - ]) - if "AMD" in cpu_manufacturer: - unload_kext.extend(["SMCProcessor", "SMCSuperIO"]) - if "Navi 2" in discrete_gpu_codename: - unload_kext.append("SMCSuperIO") - elif "Laptop" in platform and not "SURFACE" in motherboard_name: - if "AMD" in cpu_manufacturer: - unload_kext.extend([ - "SMCProcessor", - "SMCSuperIO" - ]) + if self.kexts[self.get_kext_index("AirportBrcmFixup")].checked and self.utils.parse_darwin_version(macos_version) > self.utils.parse_darwin_version("20.0.0"): + unload_kext.append("AirPortBrcm4360_Injector") + + if self.kexts[self.get_kext_index("VoodooSMBus")].checked: + unload_kext.append("VoodooPS2Mouse") + elif self.kexts[self.get_kext_index("VoodooRMI")].checked: + if not self.kexts[self.get_kext_index("VoodooI2C")].checked: + unload_kext.append("RMII2C") + else: + unload_kext.extend(( + "VoodooSMBus", + "RMISMBus", + "VoodooI2CServices", + "VoodooGPIO", + "VoodooI2CHID" + )) + + kext_paths = self.utils.find_matching_paths(kexts_directory, extension_filter=".kext") + bundle_list = [] + + for kext_path, type in kext_paths: + try: + plist_path = self.utils.find_matching_paths(os.path.join(kexts_directory, kext_path), extension_filter=".plist", name_filter="Info")[0][0] + bundle_info = self.utils.read_file(os.path.join(kexts_directory, kext_path, plist_path)) + except: + bundle_info = {} + + if not isinstance(bundle_info.get("CFBundleIdentifier", None), (str, unicode)): + continue + + executable_path = os.path.join("Contents", "MacOS", bundle_info.get("CFBundleExecutable", "None")).replace("\\", "/").lstrip("/") + if not os.path.exists(os.path.join(kexts_directory, kexts_directory, executable_path)): + executable_path = "" - if "VoodooSMBus" in kexts: - unload_kext.append("VoodooPS2Mouse") - elif "VoodooRMI" in kexts: - if not "VoodooI2C" in kexts: - unload_kext.append("RMII2C") - else: - unload_kext.extend([ - "VoodooSMBus", - "RMISMBus", - "VoodooI2CServices", - "VoodooGPIO", - "VoodooI2CHID" - ]) - - 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_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 <= self.utils.parse_darwin_version(macos_version) <= max_kernel: - continue - - kernel_add.append({ - "Arch": "x86_64", - "BundlePath": kext.get("BundlePath"), - "Comment": "", + bundle_list.append({ + "BundlePath": kext_path.replace("\\", "/").lstrip("/"), "Enabled": True, - "ExecutablePath": kext.get("ExecutablePath") or "", - "MaxKernel": "", - "MinKernel": "", - "PlistPath": "Contents/Info.plist" + "ExecutablePath": executable_path, + "PlistPath": plist_path.replace("\\", "/").lstrip("/"), + "BundleIdentifier": bundle_info.get("CFBundleIdentifier"), + "BundleVersion": bundle_info.get("CFBundleVersion"), + "BundleLibraries": { + bundle_identifier: bundle_version + for bundle_identifier, bundle_version in bundle_info.get("OSBundleLibraries", {}).items() + if not bundle_identifier.startswith("com.apple") + } }) - return kernel_add \ No newline at end of file + bundle_dict = {bundle["BundleIdentifier"]: bundle for bundle in bundle_list} + + sorted_bundles = [] + + visited = set() + seen_identifier = set() + + def visit(bundle): + if os.path.splitext(os.path.basename(bundle.get("BundlePath")))[0] in unload_kext or (bundle.get("BundlePath"), bundle.get("BundleIdentifier")) in visited: + return + + for dep_identifier in bundle.get("BundleLibraries"): + if dep_identifier in bundle_dict: + visit(bundle_dict[dep_identifier]) + + visited.add((bundle.get("BundlePath"), bundle.get("BundleIdentifier"))) + + if bundle.get("BundleIdentifier") in seen_identifier: + bundle["Enabled"] = False + else: + seen_identifier.add(bundle.get("BundleIdentifier")) + + sorted_bundles.append(bundle) + + for bundle in bundle_list: + visit(bundle) + + for bundle in sorted_bundles: + kernel_add.append({ + "Arch": "x86_64", + "BundlePath": bundle.get("BundlePath"), + "Comment": "", + "Enabled": bundle.get("Enabled"), + "ExecutablePath": bundle.get("ExecutablePath"), + "MaxKernel": "", + "MinKernel": "", + "PlistPath": bundle.get("PlistPath") + }) + + kernel_add.append({ + "Arch": "x86_64", + "BundlePath": "USBMap.kext", + "Comment": "", + "Enabled": True, + "ExecutablePath": "", + "MaxKernel": "", + "MinKernel": "", + "PlistPath": "Contents/Info.plist" + }) + + return kernel_add + + def uncheck_kext(self, index): + kext = self.kexts[index] + kext.checked = False + + for other_kext in self.kexts: + if other_kext.name in kext.requires_kexts and not other_kext.required: + other_kext.checked = False + + def kext_configuration_menu(self, hardware_report, smbios_model, macos_version, acpi_patches): + current_category = None + + while True: + contents = [] + contents.append("") + contents.append("List of available kexts:") + for index, kext in enumerate(self.kexts, start=1): + if kext.category != current_category: + current_category = kext.category + category_header = "Category: {}".format(current_category if current_category else "Uncategorized") + contents.append(f"\n{category_header}\n" + "=" * len(category_header)) + checkbox = "[*]" if kext.checked else "[ ]" + + line = "{} {:2}. {:25} - {:60}".format(checkbox, index, kext.name, kext.description) + if not self.utils.parse_darwin_version(kext.min_darwin_version) <= self.utils.parse_darwin_version(macos_version) <= self.utils.parse_darwin_version(kext.max_darwin_version): + line = "\033[90m{}\033[0m".format(line) + elif kext.checked: + line = "\033[1;32m{}\033[0m".format(line) + contents.append(line) + contents.append("\033[1;36m") + contents.append("Note:") + contents.append("- Lines in gray indicate kexts that are not supported by the current macOS version ({}).".format(macos_version)) + contents.append("- When a plugin of a kext is selected, the entire kext will be automatically selected.") + contents.append("- You can select multiple kexts by entering their indices separated by commas (e.g., '1, 2, 3').") + contents.append("\033[0m") + contents.append("R. Restore defaults") + contents.append("") + contents.append("B. Back") + contents.append("Q. Quit") + contents.append("") + content = "\n".join(contents) + + self.utils.adjust_window_size(content) + self.utils.head("Configure Kernel Extensions", resize=False) + print(content) + option = self.utils.request_input("Select your option: ") + if option.lower() == "r": + self.select_required_kexts(hardware_report, smbios_model, macos_version, acpi_patches) + if option.lower() == "b": + return + if option.lower() == "q": + self.utils.exit_program() + indices = [int(i.strip()) -1 for i in option.split(",") if i.strip().isdigit()] + + for index in indices: + if index >= 0 and index < len(self.kexts): + kext = self.kexts[index] + if kext.checked: + self.uncheck_kext(index) + else: + self.check_kext(index, macos_version) \ No newline at end of file