from Scripts.datasets import chipset_data from Scripts.datasets import cpu_data from Scripts.datasets import mac_model_data from Scripts.datasets import os_data from Scripts import codec_layouts from Scripts import gathering_files from Scripts import smbios from Scripts import utils import random class ConfigProdigy: def __init__(self): self.g = gathering_files.gatheringFiles() self.smbios = smbios.SMBIOS() self.utils = utils.Utils() self.cpuids = { "Ivy Bridge": "A9060300", "Haswell": "C3060300", "Broadwell": "D4060300", "Coffee Lake": "EB060800", "Comet Lake": "55060A00" } def mmio_whitelist(self, motherboard_chipset): booter_mmiowhitelist = [] if "Ice Lake" in motherboard_chipset: booter_mmiowhitelist.append({ "Address": 4284481536, "Comment": "MMIO 0xFF600000", "Enable": True }) elif "B650" in motherboard_chipset or "X670" in motherboard_chipset: booter_mmiowhitelist.append({ "Address": 4244635648, "Comment": "MMIO 0xFD000000", "Enable": True }) return booter_mmiowhitelist def add_booter_patch(self, smbios_model, macos_version): booter_patch = [] mac_device = mac_model_data.get_mac_device_by_name(smbios_model) if not self.utils.parse_darwin_version(mac_device.initial_support) <= self.utils.parse_darwin_version(macos_version) <= self.utils.parse_darwin_version(mac_device.last_supported_version): booter_patch.append({ "Arch": "x86_64", "Comment": "Skip Board ID check", "Count": 0, "Enabled": True, "Find": self.utils.hex_to_bytes("0050006C006100740066006F0072006D0053007500700070006F00720074002E0070006C006900730074"), "Identifier": "Apple", "Limit": 0, "Mask": self.utils.hex_to_bytes(""), "Replace": self.utils.hex_to_bytes("002E002E002E002E002E002E002E002E002E002E002E002E002E002E002E002E002E002E002E002E002E"), "ReplaceMask": self.utils.hex_to_bytes(""), "Skip": 0 }) return booter_patch def check_mats_support(self, cpu_manufacturer, motherboard_chipset): return "AMD" in cpu_manufacturer or \ not self.utils.contains_any(chipset_data.IntelChipsets, motherboard_chipset, start=101) is None or \ not self.utils.contains_any(chipset_data.IntelChipsets, motherboard_chipset, start=79, end=89) is None def check_resizable_bar_support(self, motherboard_chipset): return not self.utils.contains_any(chipset_data.AMDChipsets, motherboard_chipset, start=11) is None or \ not "Ice Lake" in motherboard_chipset and not self.utils.contains_any(chipset_data.IntelChipsets, motherboard_chipset, start=101) is None def is_low_end_intel_cpu(self, processor_name): return any(cpu_branding in processor_name for cpu_branding in ["Celeron", "Pentium"]) def deviceproperties(self, cpu_codename, intel_mei, igpu_properties): deviceproperties_add = {} if igpu_properties: deviceproperties_add["PciRoot(0x0)/Pci(0x2,0x0)"] = igpu_properties if intel_mei: if "Sandy Bridge" in cpu_codename and intel_mei.get("Device ID") in "8086-1E3A": deviceproperties_add["PciRoot(0x0)/Pci(0x16,0x0)"] = { "device-id": "3A1C0000" } elif "Ivy Bridge" in cpu_codename and intel_mei.get("Device ID") in "8086-1C3A": deviceproperties_add["PciRoot(0x0)/Pci(0x16,0x0)"] = { "device-id": "3A1E0000" } for key, value in deviceproperties_add.items(): for key_child, value_child in value.items(): if isinstance(value_child, str): deviceproperties_add[key][key_child] = self.utils.hex_to_bytes(deviceproperties_add[key][key_child]) return deviceproperties_add def block_kext_bundle(self, network, macos_version): kernel_block = [] if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("23.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({ "Arch": "x86_64", "Comment": "Allow IOSkywalk Downgrade", "Enabled": True, "Identifier": "com.apple.iokit.IOSkywalkFamily", "MaxKernel": "", "MinKernel": "", "Strategy": "Exclude" }) return kernel_block def is_low_end_haswell_plus(self, processor_name, cpu_codename): return self.is_low_end_intel_cpu(processor_name) and not self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, end=38) is None def is_intel_hedt_cpu(self, cpu_codename): return not self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, start=21) is None and cpu_codename.endswith(("-X", "-P", "-W", "-E", "-EP", "-EX")) def spoof_cpuid(self, processor_name, cpu_codename, macos_version): if self.is_low_end_haswell_plus(processor_name, cpu_codename): return self.cpuids.get("Ivy Bridge") elif "Haswell" in cpu_codename and self.is_intel_hedt_cpu(cpu_codename): return self.cpuids.get("Haswell") elif "Broadwell" in cpu_codename and self.is_intel_hedt_cpu(cpu_codename): return self.cpuids.get("Broadwell") elif "Ice Lake" not in cpu_codename and self.utils.contains_any(cpu_data.IntelCPUGenerations, cpu_codename, end=10): if not "Comet Lake" in cpu_codename: return self.cpuids.get("Comet Lake") if self.utils.parse_darwin_version(macos_version) < self.utils.parse_darwin_version("19.0.0"): return self.cpuids.get("Coffee Lake") return None 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()) 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"]: patch["Replace"] = patch["Replace"].hex() patch["Replace"] = self.utils.hex_to_bytes(patch["Replace"][:2] + self.utils.int_to_hex(int(cpu_cores)) + patch["Replace"][4:]) elif "IOPCIIsHotplugPort" in patch["Comment"]: if self.utils.contains_any(chipset_data.AMDChipsets, motherboard_chipset, start=17): patch["Enabled"] = True if "_mtrr_update_action" in patch["Comment"]: if "TRX" in motherboard_chipset.upper(): patch["Enabled"] = False elif "AMD" in gpu_manufacturer: if "algrey" in patch["Comment"].lower(): patch["Enabled"] = False elif "shaneee" in patch["Comment"].lower(): patch["Enabled"] = True return kernel_patch def boot_args(self, hardware_report, unsupported_devices, macos_version): boot_args = [ "-v", "debug=0x100", "keepsyms=1" ] codec_id = list(hardware_report.get("Sound").items())[0][-1].get("Device ID") if codec_id in codec_layouts.data: boot_args.append("alcid={}".format(random.choice(codec_layouts.data.get(codec_id)))) if "AMD" in hardware_report.get("CPU").get("Manufacturer") or self.is_intel_hedt_cpu(hardware_report.get("CPU").get("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 not (" Core" in hardware_report.get("CPU").get("Processor Name") and \ self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("Codename"), end=3)) else "")) if self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("Codename"), end=2) and int(hardware_report.get("CPU").get("Core Count")) > 6: boot_args.append("-ctrsmt") if "Intel" in hardware_report.get("CPU").get("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 list(hardware_report.get("GPU").items())[0][-1].get("Codename"): boot_args.extend(["-noDC9", "-igfxcdc", "-igfxdvmt", "-igfxdbeo"]) if "Laptop" in hardware_report.get("Motherboard").get("Platform"): if self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("Codename"), end=21): 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 1" in list(hardware_report.get("GPU").items())[-1][-1].get("Codename"): boot_args.append("agdpmod=pikera") if not "SURFACE" in hardware_report.get("Motherboard").get("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 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 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): if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("20.0.0"): return "03080000" elif self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("18.0.0"): return "FF070000" else: return "FF030000" def load_drivers(self): uefi_drivers = [] for driver_path in ["OpenCanopy.efi", "OpenHfsPlus.efi", "OpenRuntime.efi", "ResetNvramEntry.efi"]: uefi_drivers.append({ "Arguments": "", "Comment": "", "Enabled": True, "LoadEarly": False, "Path": driver_path }) return uefi_drivers 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_report.get("Motherboard").get("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("Manufacturer"), hardware_report.get("Motherboard").get("Chipset")) if "AMD" in hardware_report.get("CPU").get("Manufacturer") and not "TRX40" in hardware_report.get("Motherboard").get("Chipset"): config["Booter"]["Quirks"]["DevirtualiseMmio"] = False config["Booter"]["Quirks"]["EnableWriteUnprotector"] = False if "AMD" in hardware_report.get("CPU").get("Manufacturer") else not config["Booter"]["Quirks"]["DevirtualiseMmio"] config["Booter"]["Quirks"]["ProtectUefiServices"] = "Z390" in hardware_report.get("Motherboard").get("Chipset") or \ not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("Codename"), end=14) is None config["Booter"]["Quirks"]["RebuildAppleMemoryMap"] = not config["Booter"]["Quirks"]["EnableWriteUnprotector"] config["Booter"]["Quirks"]["ResizeAppleGpuBars"] = 0 if self.check_resizable_bar_support(hardware_report.get("Motherboard").get("Chipset")) else -1 config["Booter"]["Quirks"]["SetupVirtualMap"] = not (not self.utils.contains_any(chipset_data.AMDChipsets, hardware_report.get("Motherboard").get("Chipset"), start=11, end=17) is None or \ "ASUS" in hardware_report.get("Motherboard").get("Name") and self.is_intel_hedt_cpu(hardware_report.get("CPU").get("Codename")) and config["Booter"]["Quirks"]["DevirtualiseMmio"]) config["Booter"]["Quirks"]["SyncRuntimePermissions"] = config["Booter"]["Quirks"]["RebuildAppleMemoryMap"] config["DeviceProperties"]["Add"] = self.deviceproperties( hardware_report.get("CPU").get("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_report.get("Network"), macos_version) spoof_cpuid = self.spoof_cpuid( hardware_report.get("CPU").get("Processor Name"), hardware_report.get("CPU").get("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_report.get("CPU").get("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_report.get("Motherboard").get("Chipset"), hardware_report.get("CPU").get("Manufacturer"), hardware_report.get("CPU").get("Core Count"), list(hardware_report.get("GPU").items())[-1][-1].get("Manufacturer"), kexts ) config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"] = not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("Codename"), start=38) is None config["Kernel"]["Quirks"]["AppleXcpmCfgLock"] = False if "AMD" in hardware_report.get("CPU").get("Manufacturer") else not config["Kernel"]["Quirks"]["AppleCpuPmCfgLock"] config["Kernel"]["Quirks"]["AppleXcpmExtraMsrs"] = "-E" in hardware_report.get("CPU").get("Codename") and not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("Codename"), start=26) is None config["Kernel"]["Quirks"]["CustomSMBIOSGuid"] = True config["Kernel"]["Quirks"]["DisableIoMapper"] = not "AMD" in hardware_report.get("CPU").get("Manufacturer") config["Kernel"]["Quirks"]["DisableRtcChecksum"] = "ASUS" in hardware_report.get("Motherboard").get("Name") or "HP" in hardware_report.get("Motherboard").get("Name") config["Kernel"]["Quirks"]["LapicKernelPanic"] = "HP" in hardware_report.get("Motherboard").get("Name") config["Kernel"]["Quirks"]["PanicNoKextDump"] = config["Kernel"]["Quirks"]["PowerTimeoutKernelPanic"] = True config["Kernel"]["Quirks"]["ProvideCurrentCpuInfo"] = "AMD" in hardware_report.get("CPU").get("Manufacturer") or \ not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware_report.get("CPU").get("Codename"), end=2) is None config["Misc"]["BlessOverride"] = [] config["Misc"]["Boot"]["HideAuxiliary"] = False config["Misc"]["Boot"]["LauncherOption"] = "Full" config["Misc"]["Boot"]["PickerMode"] = "External" config["Misc"]["Boot"]["Timeout"] = 10 config["Misc"]["Debug"]["AppleDebug"] = config["Misc"]["Debug"]["ApplePanic"] = False config["Misc"]["Debug"]["DisableWatchDog"] = True config["Misc"]["Debug"]["Target"] = 0 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(macos_version) < self.utils.parse_darwin_version("23.0.0") else "Disabled" config["Misc"]["Security"]["Vault"] = "Optional" config["Misc"]["Tools"] = [] 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_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" config["NVRAM"]["Delete"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"].append("csr-active-config") 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_report.get("CPU").get("Codename"), start=26) is None config["UEFI"]["Quirks"]["ReleaseUsbOwnership"] = True config["UEFI"]["Quirks"]["UnblockFsConnect"] = "HP" in hardware_report.get("Motherboard").get("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("Codename"), end=3)): 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("Core Count")) < 8 else 3841 return config