mirror of
https://github.com/outbackdingo/OpCore-Simplify.git
synced 2026-01-27 10:19:49 +00:00
Add valid kext check before saving
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user