From 381e65075e019f751c9c140e10a221a983ec4f94 Mon Sep 17 00:00:00 2001 From: Hoang Hong Quan Date: Sun, 4 Aug 2024 16:23:27 +0700 Subject: [PATCH] Remove unnecessary hard disk information --- OpCore-Simplify.py | 2 +- Scripts/aida64.py | 67 ++++++++++++-------------------- Scripts/compatibility_checker.py | 2 +- Scripts/efi_builder.py | 2 +- Scripts/kext_maestro.py | 2 +- 5 files changed, 28 insertions(+), 47 deletions(-) mode change 100755 => 100644 Scripts/aida64.py diff --git a/OpCore-Simplify.py b/OpCore-Simplify.py index 7a7e15c..62adaaa 100644 --- a/OpCore-Simplify.py +++ b/OpCore-Simplify.py @@ -84,7 +84,7 @@ class OCPE: pass else: for device_name, device_props in self.hardware.get(device_type).items(): - if "Controllers" in device_name or "Devices" in device_name or "Drives" in device_name: + if "Controllers" in device_name or "Devices" in device_name: contents.append("{}* {}:".format(" "*4, device_name)) for device_name_child, device_props_child in device_props.items(): contents.append("{}- {}".format(" "*8, device_name_child)) diff --git a/Scripts/aida64.py b/Scripts/aida64.py old mode 100755 new mode 100644 index 78fb89c..2c5b8b6 --- a/Scripts/aida64.py +++ b/Scripts/aida64.py @@ -4,7 +4,6 @@ from bs4 import BeautifulSoup class AIDA64: def __init__(self): - self.aida64_download_url = "https://www.aida64.com/downloads" self.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"} self.encodings = ['utf-8', 'latin-1', 'ISO-8859-1'] self.utils = utils.Utils() @@ -18,6 +17,19 @@ class AIDA64: continue raise UnicodeDecodeError("Unable to decode file {} with given encodings".format(file_path)) + def get_unique_key(self, base_key, dictionary): + if base_key not in dictionary: + return base_key + + counter = 1 + unique_key = f"{base_key}_#{counter}" + + while unique_key in dictionary: + counter += 1 + unique_key = f"{base_key}_#{counter}" + + return unique_key + def hardware_id(self, hardware_id): if "VEN" in hardware_id: return { @@ -119,11 +131,8 @@ class AIDA64: ] } - def storage(self, ata_controllers, storage_controllers, ata_devices): - storage_info = { - "Storage Controllers": {}, - "Disk Drives": {} - } + def storage_controllers(self, ata_controllers, storage_controllers): + storage_controllers_info = {} storage_controllers.update(ata_controllers) for controller_name, controller_props in storage_controllers.items(): @@ -133,28 +142,12 @@ class AIDA64: if " SD " in pci_device or "MMC" in pci_device: continue - storage_info["Storage Controllers"][controller_name] = { + storage_controllers_info[self.get_unique_key(controller_props.get("PCI Device", controller_name), storage_controllers_info)] = { "Bus Type": controller_props.get("Bus Type", "Unknown"), - "Device ID": controller_props.get("Device ID", "Unknown"), - "Device Description": controller_props.get("PCI Device", "Unknown") + "Device ID": controller_props.get("Device ID", "Unknown") } - device_categories = ["NVMe Device Properties", "SSD Physical Info", "ATA Device Properties", "Disk Device Physical Info", "Device Properties"] - - for device_name, device_props in ata_devices.items(): - disk_props = {} - relevant_categories = [key for key in list(device_props.keys()) if key in device_categories] - for category in relevant_categories: - category_props = device_props[category] - - disk_props["Controller"] = category_props.get("Controller Type", "Unknown") - disk_props["Interface"] = category_props.get("Interface", "Unknown") - if category_props.get("Device Type", None): - disk_props["Interface"] = category_props.get("Device Type") - - storage_info["Disk Drives"][device_name] = disk_props - - return storage_info + return storage_controllers_info def monitor(self, monitor): return { @@ -211,9 +204,7 @@ class AIDA64: bus_type = device_props.get("Bus Type", "") if bus_type.endswith("AUDIO") or bus_type.endswith("USB"): if device_props.get("Device ID", "Unknown") not in audio_device_ids: - occurrences = self.count_keys(audio_devices_info, device_name) - unique_device_name = "{}_#{}".format(device_name, occurrences) if occurrences > 0 else device_name - audio_devices_info[unique_device_name] = { + audio_devices_info[self.get_unique_key(device_name, audio_devices_info)] = { "Bus Type": bus_type, "{} ID".format("USB" if bus_type.endswith("USB") else "Codec"): device_props.get("Device ID", "Unknown") } @@ -313,8 +304,7 @@ class AIDA64: if not device_description: device_description = self.utils.search_dict_iter(windows_devices, hardware_id).get("Driver Description", device_name) - occurrences = self.count_keys(usb_info["USB Devices"], device_description) - device_description = "{}_#{}".format(device_description, occurrences) if occurrences > 0 else device_description + device_description = self.get_unique_key(device_description, usb_info["USB Devices"]) if "Hub" not in device_description and "Billboard" not in device_description and not "0000-0000" in device_props.get("Device ID"): usb_info["USB Devices"][device_description] = { @@ -481,18 +471,11 @@ class AIDA64: # Extract device name from device properties device_name = device_props.get("Driver Description") - # Count occurrences of device name within category - occurrences = self.count_keys(parsed_windows_devices[category_name], device_name) - device_name = "{}_#{}".format(device_name, occurrences) if occurrences > 0 else device_name - # Add device to category dictionary - parsed_windows_devices[category_name][device_name] = device_props + parsed_windows_devices[category_name][self.get_unique_key(device_name, parsed_windows_devices[category_name])] = device_props return parsed_windows_devices - def count_keys(self, dictionary, target_key): - return sum(1 for key in dictionary if target_key in key) - def html_to_dict(self, html_content): soup = BeautifulSoup(html_content, "html.parser") tables = soup.find_all('table') @@ -507,7 +490,6 @@ class AIDA64: "CPU", "GPU", "Vulkan", - "ATA", "Windows Devices", "PCI Devices", "USB Devices" @@ -559,8 +541,7 @@ class AIDA64: # Add the new key-value pair current_dict = stack[-1][0] - occurrences = self.count_keys(current_dict, key) - key = "{}_#{}".format(key, occurrences) if occurrences > 0 else key + key = self.get_unique_key(key, current_dict) if value is None: new_dict = {} @@ -593,7 +574,7 @@ class AIDA64: hardware["CPU"] = self.cpu(report_dict.get("CPU", {})) hardware["GPU"] = self.gpu(report_dict.get("GPU", {}), report_dict.get("Vulkan", {}), windows_devices) hardware["Network"] = self.network(windows_devices, report_dict.get("PCI Devices", {})) - hardware["Storage"] = self.storage(windows_devices.get("IDE ATA/ATAPI controllers", {}), windows_devices.get("Storage controllers", {}), report_dict.get("ATA", {})) + hardware["Storage Controllers"] = self.storage_controllers(windows_devices.get("IDE ATA/ATAPI controllers", {}), windows_devices.get("Storage controllers", {})) hardware["Audio"] = self.audio(windows_devices) hardware["USB"] = self.usb(windows_devices.get("Universal Serial Bus controllers", {}), report_dict.get("USB Devices", {}), windows_devices) hardware["Input"] = self.input(windows_devices.get("Human Interface Devices", {}), windows_devices.get("Keyboards", {}), windows_devices.get("Mice and other pointing devices", {}), hardware["USB"].get("USB Devices", {})) @@ -603,4 +584,4 @@ class AIDA64: hardware = self.sd_controller(report_dict.get("PCI Devices", {}), hardware["USB"].get("USB Devices", {}), hardware) hardware = self.intel_mei(hardware["CPU"].get("CPU Codename"), report_dict.get("PCI Devices", {}), hardware) - return hardware + return hardware \ No newline at end of file diff --git a/Scripts/compatibility_checker.py b/Scripts/compatibility_checker.py index 5cbae3a..d2fe61f 100755 --- a/Scripts/compatibility_checker.py +++ b/Scripts/compatibility_checker.py @@ -198,7 +198,7 @@ class CompatibilityChecker: hardware["Audio"] = self.check_audio_compatibility(hardware.get("Audio")) self.check_biometric_compatibility(hardware) hardware["Network"] = self.check_network_compatibility(hardware.get("Network")) - hardware["Storage"]["Storage Controllers"] = self.check_storage_compatibility(hardware.get("Storage").get("Storage Controllers")) + hardware["Storage Controllers"] = self.check_storage_compatibility(hardware.get("Storage Controllers")) self.check_sd_controller_compatibility(hardware) hardware["Compatibility"] = { diff --git a/Scripts/efi_builder.py b/Scripts/efi_builder.py index 53f23d9..b582169 100755 --- a/Scripts/efi_builder.py +++ b/Scripts/efi_builder.py @@ -411,7 +411,7 @@ class builder: 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") - hardware_shorc["Storage Controllers"] = hardware.get("Storage").get("Storage Controllers") + hardware_shorc["Storage Controllers"] = hardware.get("Storage Controllers") hardware_shorc["USB Controllers"] = [controller_props.get("Device ID") for controller_name, controller_props in hardware.get("USB").get("USB Controllers").items()] hardware_shorc["Intel MEI"] = hardware.get("Intel MEI") hardware_shorc["Unsupported Devices"] = hardware.get("Compatibility").get("Unsupported Devices") diff --git a/Scripts/kext_maestro.py b/Scripts/kext_maestro.py index 73458a8..96d8857 100755 --- a/Scripts/kext_maestro.py +++ b/Scripts/kext_maestro.py @@ -696,7 +696,7 @@ class KextMaestro: kexts.extend(["RealtekCardReader", "RealtekCardReaderFriend"]) for controller_name, controller_props in storage_controllers.items(): - if "NVMe" in controller_name + controller_props.get("Device Description") or "NVM Express" in controller_name + controller_props.get("Device Description"): + if "NVMe" in controller_name or "NVM Express" in controller_name: kexts.append("NVMeFix") else: if controller_props.get("Device ID") in pci_data.UnsupportedSATAControllerIDs and not "AHCI" in controller_name: