From 43e5065bfa3439d70968b29cb0a2a81179ba90ed Mon Sep 17 00:00:00 2001 From: Hoang Hong Quan Date: Tue, 10 Dec 2024 10:45:18 +0700 Subject: [PATCH] Add valid kext check before saving --- Scripts/gathering_files.py | 6 ++-- Scripts/kext_maestro.py | 60 ++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Scripts/gathering_files.py b/Scripts/gathering_files.py index 8b2bea0..245991e 100644 --- a/Scripts/gathering_files.py +++ b/Scripts/gathering_files.py @@ -1,4 +1,5 @@ from Scripts import github +from Scripts import kext_maestro from Scripts import resource_fetcher from Scripts import utils import os @@ -10,6 +11,7 @@ class gatheringFiles: def __init__(self): self.utils = utils.Utils() self.github = github.Github() + self.kext = kext_maestro.KextMaestro() self.fetcher = resource_fetcher.ResourceFetcher() self.dortania_builds_url = "https://raw.githubusercontent.com/dortania/build-repo/builds/latest.json" self.ocbinarydata_url = "https://github.com/acidanthera/OcBinaryData/archive/refs/heads/master.zip" @@ -90,7 +92,7 @@ class gatheringFiles: source_kext_path = os.path.join(self.temporary_dir, product_name, kext_path) destination_kext_path = os.path.join(self.ock_files_dir, product_name, os.path.basename(kext_path)) - if "Contents" in kext_path or "Debug".lower() in kext_path.lower(): + if "debug" in kext_path.lower() or "Contents" in kext_path or not self.kext.process_kext(os.path.join(self.temporary_dir, product_name), kext_path): continue shutil.move(source_kext_path, destination_kext_path) @@ -124,8 +126,6 @@ class gatheringFiles: shutil.move(source_macserial_path, destination_macserial_path) if os.name != "nt": subprocess.run(["chmod", "+x", destination_macserial_path]) - else: - raise FileNotFoundError("No bootloader or kexts files found in the product directory.") return True diff --git a/Scripts/kext_maestro.py b/Scripts/kext_maestro.py index e682896..24bacd9 100644 --- a/Scripts/kext_maestro.py +++ b/Scripts/kext_maestro.py @@ -293,6 +293,33 @@ class KextMaestro: shutil.copytree(source_kext_path, destination_kext_path, dirs_exist_ok=True) except: continue + + def process_kext(self, kexts_directory, kext_path): + 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)) + + if isinstance(bundle_info.get("CFBundleIdentifier", None), (str, unicode)): + pass + except: + return None + + executable_path = os.path.join("Contents", "MacOS", bundle_info.get("CFBundleExecutable", "None")) + if not os.path.exists(os.path.join(kexts_directory, kext_path, executable_path)): + executable_path = "" + + return { + "BundlePath": kext_path.replace("\\", "/").lstrip("/"), + "Enabled": True, + "ExecutablePath": executable_path.replace("\\", "/").lstrip("/"), + "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() + } + } def load_kexts(self, macos_version, kexts_directory): kernel_add = [] @@ -315,36 +342,11 @@ class KextMaestro: 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 = {} + for kext_path, type in kext_paths: + bundle_info = self.process_kext(kexts_directory, kext_path) - if not isinstance(bundle_info.get("CFBundleIdentifier", None), (str, unicode)): - continue - - executable_path = os.path.join("Contents", "MacOS", bundle_info.get("CFBundleExecutable", "None")) - if not os.path.exists(os.path.join(kexts_directory, kext_path, executable_path)): - executable_path = "" - - if bundle_info.get("CFBundleExecutable", "None") == "AirportItlwm" and self.utils.parse_darwin_version("24.0.0") <= self.utils.parse_darwin_version(macos_version): - bundle_info["IOKitPersonalities"]["itlwm"]["IOPCIMatch"] += " 0x43A014E4" - self.utils.write_file(os.path.join(kexts_directory, kext_path, plist_path), bundle_info) - - bundle_list.append({ - "BundlePath": kext_path.replace("\\", "/").lstrip("/"), - "Enabled": True, - "ExecutablePath": executable_path.replace("\\", "/").lstrip("/"), - "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 bundle_info: + bundle_list.append(bundle_info) bundle_dict = {bundle["BundleIdentifier"]: bundle for bundle in bundle_list}