From 17c8480280cbb64cb0273c2fe4b9f0671266b180 Mon Sep 17 00:00:00 2001 From: jief666 Date: Sun, 7 Jan 2024 18:14:33 +0100 Subject: [PATCH] Search kext executable by name if CFBundleExecutable leads to a non existant file. Add corecaptureElCap.kext, IO80211ElCap and IO80211ElCap/Plugins/AirPortAtheros40.kext in oredered list. --- rEFIt_UEFI/Platform/kext_inject.cpp | 25 ++++++++++++++++++++++--- rEFIt_UEFI/refit/main.cpp | 6 +++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/rEFIt_UEFI/Platform/kext_inject.cpp b/rEFIt_UEFI/Platform/kext_inject.cpp index 9ba3e4675..5809773e4 100644 --- a/rEFIt_UEFI/Platform/kext_inject.cpp +++ b/rEFIt_UEFI/Platform/kext_inject.cpp @@ -196,10 +196,29 @@ XString8 LOADER_ENTRY::getKextExecPath(const EFI_FILE* Root, const XStringW& di } else { TempName = S8Printf("Contents\\MacOS\\%s", Executable.c_str()); } - const XStringW& fullPath = SWPrintf("%ls\\%ls\\%ls\\%s", selfOem.getKextsDirPathRelToSelfDir().wc_str(), dirPath.wc_str(), FileName.wc_str(), TempName.c_str()); + XStringW fullPath = SWPrintf("%ls\\%ls\\%ls\\%s", selfOem.getKextsDirPathRelToSelfDir().wc_str(), dirPath.wc_str(), FileName.wc_str(), TempName.c_str()); if (!FileExists(Root, fullPath)) { - MsgLog("Failed to load kext executable: %ls\n", FileName.wc_str()); - return ""_XS8; //no executable + + // kext from OpenCoreLegacyPatcher renamed the executable without updating CFBundleExecutable + // let's see if there is an executable that has the same name as the kext. + XString8 TempName2; + XStringW FileNameWithoutExt; + if ( FileName.indexOf('.') != MAX_XSIZE ) FileNameWithoutExt = FileName.subString(0, FileName.indexOf('.')); + else FileNameWithoutExt = FileName; + if (NoContents) { + TempName2 = S8Printf("%ls", FileNameWithoutExt.wc_str()); + } else { + TempName2 = S8Printf("Contents\\MacOS\\%ls", FileNameWithoutExt.wc_str()); + } + fullPath = SWPrintf("%ls\\%ls\\%ls\\%s", selfOem.getKextsDirPathRelToSelfDir().wc_str(), dirPath.wc_str(), FileName.wc_str(), TempName2.c_str()); + + if (!FileExists(Root, fullPath)) { + MsgLog("Failed to load kext executable: %ls\n", FileName.wc_str()); + return ""_XS8; //no executable + }else{ + MsgLog("Warning : wrong value for CFBundleExecutable for kext %ls. It's %s and should be %ls\n", FileName.wc_str(), Executable.c_str(), FileName.wc_str()); + return TempName2; + } } } return TempName; diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index dfe464160..dfd06f15e 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -1217,11 +1217,14 @@ void LOADER_ENTRY::StartLoader() pos = setKextAtPos(&kextArray, "BrcmPatchRAM3.kext"_XS8, pos); pos = setKextAtPos(&kextArray, "IO80211FamilyLegacy.kext"_XS8, pos); pos = setKextAtPos(&kextArray, "HS80211Family.kext"_XS8, pos); + pos = setKextAtPos(&kextArray, "corecaptureElCap.kext"_XS8, pos); + pos = setKextAtPos(&kextArray, "IO80211ElCap.kext"_XS8, pos); + pos = setKextAtPos(&kextArray, "IO80211ElCap\\Contents\\Plugins\\AirPortAtheros40.kext"_XS8, pos); pos = setKextAtPos(&kextArray, "AirPortAtheros40.kext"_XS8, pos); for (size_t kextIdx = 0 ; kextIdx < kextArray.size() ; kextIdx++ ) { const SIDELOAD_KEXT& KextEntry = kextArray[kextIdx]; - DBG("Bridge kext to OC : Path=%ls\%ls\n", KextEntry.KextDirNameUnderOEMPath.wc_str(), KextEntry.FileName.wc_str()); + DBG("Bridge kext to OC : Path=%ls\\%ls\n", KextEntry.KextDirNameUnderOEMPath.wc_str(), KextEntry.FileName.wc_str()); mOpenCoreConfiguration.Kernel.Add.Values[kextIdx] = (__typeof_am__(*mOpenCoreConfiguration.Kernel.Add.Values))malloc(mOpenCoreConfiguration.Kernel.Add.ValueSize); memset(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx], 0, mOpenCoreConfiguration.Kernel.Add.ValueSize); mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->Enabled = 1; @@ -3696,6 +3699,7 @@ RefitMain (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) { MemoryTrackerInit(); + //MemoryTrackerInstallHook(); can't install hook before construct_globals_objects()... yet EFI_STATUS Status = RefitMainMain(ImageHandle, SystemTable);