Skip to content

Commit

Permalink
Clean Detection Code
Browse files Browse the repository at this point in the history
  • Loading branch information
khronokernel committed Jun 15, 2021
1 parent 88b660e commit 178c604
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 356 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# OpenCore Legacy Patcher changelog

## 0.1.8
- Fix Kernel Panic in Big Sur and Monterey
- Increment binaries:
- Lilu (1.5.4 rolling - 06-15-2021)

## 0.1.7
- Add FireWire Boot Support for Catalina and newer
- Add NVMe firmware support for older models (ie. MacPro3,1)
Expand Down
68 changes: 32 additions & 36 deletions OpenCore-Patcher.command
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,47 @@ class OpenCoreLegacyPatcher():
self.current_model: str = None
self.current_model = DeviceProbe.smbios_probe().model_detect(False)
self.constants.detected_os = int(platform.uname().release.partition(".")[0])
if self.current_model in ModelArray.LegacyGPU:
dgpu_vendor,dgpu_device,dgpu_acpi = DeviceProbe.pci_probe().gpu_probe("GFX0")

if (dgpu_vendor == self.constants.pci_amd_ati and (dgpu_device in PCIIDArray.amd_ids().polaris_ids or dgpu_device in PCIIDArray.amd_ids().vega_ids or dgpu_device in PCIIDArray.amd_ids().navi_ids or dgpu_device in PCIIDArray.amd_ids().legacy_gcn_ids)) or (dgpu_vendor == self.constants.pci_nvidia and dgpu_device in PCIIDArray.nvidia_ids().kepler_ids):
self.constants.sip_status = True
self.constants.secure_status = False
self.constants.disable_amfi = False
else:
self.constants.sip_status = False
self.constants.secure_status = False
self.constants.disable_amfi = True
if self.current_model in ModelArray.ModernGPU:
if self.current_model in ["iMac13,1", "iMac13,3"]:
dgpu_vendor,dgpu_device,dgpu_acpi = DeviceProbe.pci_probe().gpu_probe("GFX0")
if not dgpu_vendor:
self.constants.sip_status = False
self.constants.secure_status = False
else:
self.constants.sip_status = False
self.constants.secure_status = False

# Logic for when user runs custom OpenCore build and do not expose it
# Note: This logic currently only applies for iMacPro1,1 users, see below threads on the culprits:
# - https://forums.macrumors.com/threads/2011-imac-graphics-card-upgrade.1596614/post-17425857
# - https://forums.macrumors.com/threads/opencore-on-the-mac-pro.2207814/
# PLEASE FOR THE LOVE OF GOD JUST SET ExposeSensitiveData CORRECTLY!!!
if self.current_model == "iMacPro1,1":
serial: str = subprocess.run("system_profiler SPHardwareDataType | grep Serial".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()
serial = [line.strip().split("Number (system): ", 1)[1] for line in serial.split("\n") if line.strip().startswith("Serial")][0]
true_model = subprocess.run([str(self.constants.macserial_path), "--info", str(serial)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
true_model = [i.partition(" - ")[2] for i in true_model.stdout.decode().split("\n") if "Model: " in i][0]
print(f"True Model: {true_model}")
if not true_model.startswith("Unknown"):
self.current_model = true_model
self.check_default_settings(self.current_model, False)

custom_cpu_model_value: str = subprocess.run("nvram 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:revcpuname".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()

if not custom_cpu_model_value.startswith("nvram: Error getting variable"):
custom_cpu_model_value = [line.strip().split(":revcpuname ", 1)[1] for line in custom_cpu_model_value.split("\n") if line.strip().startswith("4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:")][0]
if custom_cpu_model_value.split("%00")[0] != "":
self.constants.custom_cpu_model = 1
self.constants.custom_cpu_model_value = custom_cpu_model_value.split("%00")[0]

if "-v" in Utilities.get_nvram("boot-args", decode=False):
self.constants.verbose_debug = True

# Check if running in RecoveryOS
self.check_recovery()

def check_default_settings(self, model, custom):
self.constants.sip_status = True
self.constants.disable_amfi = False
if model in ModelArray.LegacyGPU:
if custom is False:
dgpu_vendor,dgpu_device,dgpu_acpi = DeviceProbe.pci_probe().gpu_probe("GFX0")
if (dgpu_vendor == self.constants.pci_amd_ati and (dgpu_device in PCIIDArray.amd_ids().polaris_ids or dgpu_device in PCIIDArray.amd_ids().vega_ids or dgpu_device in PCIIDArray.amd_ids().navi_ids or dgpu_device in PCIIDArray.amd_ids().legacy_gcn_ids)) or (dgpu_vendor == self.constants.pci_nvidia and dgpu_device in PCIIDArray.nvidia_ids().kepler_ids):
self.constants.sip_status = True
self.constants.secure_status = False
self.constants.disable_amfi = False
else:
self.constants.sip_status = False
self.constants.secure_status = False
self.constants.disable_amfi = True
if model in ModelArray.ModernGPU:
if model in ["iMac13,1", "iMac13,3"]:

if custom is False:
dgpu_vendor,dgpu_device,dgpu_acpi = DeviceProbe.pci_probe().gpu_probe("GFX0")
if not dgpu_vendor:
self.constants.sip_status = False
self.constants.secure_status = False
else:
self.constants.sip_status = False
self.constants.secure_status = False

def check_recovery(self):
root_partition_info = plistlib.loads(subprocess.run("diskutil info -plist /".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
if root_partition_info["VolumeName"] == "macOS Base System" and \
Expand Down Expand Up @@ -95,6 +90,8 @@ system_profiler SPHardwareDataType | grep 'Model Identifier'
if print_models in {"y", "Y", "yes", "Yes"}:
print("\n".join(ModelArray.SupportedSMBIOS))
input("\nPress [ENTER] to continue")
else:
self.check_default_settings(self.constants.custom_model, True)

def patcher_settings(self):
response = None
Expand Down Expand Up @@ -230,7 +227,6 @@ B. Exit

def main_menu(self):
response = None
ModelArray.SupportedSMBIOS = ModelArray.SupportedSMBIOS12
while not (response and response == -1):
title = [
f"OpenCore Legacy Patcher v{self.constants.patcher_version}",
Expand Down
18 changes: 0 additions & 18 deletions Resources/CliMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ def __init__(self, model, versions):
self.model = model
self.constants: Constants.Constants = versions

def change_os(self):
Utilities.cls()
Utilities.header(["Select Patcher's Target OS"])
print(f"""
Minimum Target:\t{self.constants.min_os_support}
Maximum Target:\t{self.constants.max_os_support}
Current target:\t{self.constants.os_support}
""")
temp_os_support = float(input("Please enter OS target: "))
if (self.constants.max_os_support < temp_os_support) or (temp_os_support < self.constants.min_os_support):
print("Unsupported entry")
else:
self.constants.os_support = temp_os_support
if temp_os_support == 11.0:
ModelArray.SupportedSMBIOS = ModelArray.SupportedSMBIOS11
elif temp_os_support == 12.0:
ModelArray.SupportedSMBIOS = ModelArray.SupportedSMBIOS12

def change_verbose(self):
Utilities.cls()
Utilities.header(["Set Verbose mode"])
Expand Down
2 changes: 1 addition & 1 deletion Resources/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class Constants:
def __init__(self):
self.patcher_version = "0.1.7"
self.patcher_version = "0.1.8"
self.opencore_commit = "4e0ff2d - 05-23-2021"
self.opencore_version = "0.7.0"
self.lilu_version = "1.5.4"
Expand Down
Loading

0 comments on commit 178c604

Please sign in to comment.