Do not store the kext dir in the SIDELOAD_KEXT object.

This commit is contained in:
jief666 2024-01-02 19:54:23 +01:00
parent 19fd19200d
commit 956cfc1ad4
4 changed files with 29 additions and 28 deletions

View File

@ -12,7 +12,7 @@
#ifndef DEBUG_ALL
#define DEBUG_KEXTLIST 1
#define DEBUG_SET 1
#else
#define DEBUG_KEXTLIST DEBUG_ALL
#endif
@ -20,7 +20,7 @@
#if DEBUG_SET == 0
#define DBG(...)
#else
#define DBG(...) DebugLog (DEBUG_KEXTLIST, __VA_ARGS__)
#define DBG(...) DebugLog (DEBUG_SET, __VA_ARGS__)
#endif
@ -31,7 +31,7 @@ XObjArray<SIDELOAD_KEXT> InjectKextList;
/*
* Relative path to SelfDir (the efi dir)
*/
XStringW GetBundleVersion(const XStringW& pathUnderSelf)
XStringW GetBundleVersion(const XStringW& pathUnderKextdDir)
{
EFI_STATUS Status;
XStringW CFBundleVersion;
@ -40,10 +40,10 @@ XStringW GetBundleVersion(const XStringW& pathUnderSelf)
TagDict* InfoPlistDict = NULL;
const TagStruct* Prop = NULL;
UINTN Size;
InfoPlistPath = SWPrintf("%ls\\%ls", pathUnderSelf.wc_str(), L"Contents\\Info.plist");
InfoPlistPath = SWPrintf("%ls\\%ls\\%ls", selfOem.getKextsDirPathRelToSelfDir().wc_str(), pathUnderKextdDir.wc_str(), L"Contents\\Info.plist");
Status = egLoadFile(&self.getCloverDir(), InfoPlistPath.wc_str(), &InfoPlistPtr, &Size);
if (EFI_ERROR(Status)) {
InfoPlistPath = SWPrintf("%ls\\%ls", pathUnderSelf.wc_str(), L"Info.plist");
InfoPlistPath = SWPrintf("%ls\\%ls\\%ls", selfOem.getKextsDirPathRelToSelfDir().wc_str(), pathUnderKextdDir.wc_str(), L"Info.plist");
Status = egLoadFile(&self.getCloverDir(), InfoPlistPath.wc_str(), &InfoPlistPtr, &Size);
}
if(!EFI_ERROR(Status)) {
@ -94,19 +94,19 @@ void GetListOfInjectKext(CHAR16 *KextDirNameUnderOEMPath)
<string>8.8.8</string>
*/
// FullName = SWPrintf("%ls\\%ls", FullPath.wc_str(), DirEntry->FileName);
XStringW pathRelToSelfDir = SWPrintf("%ls\\%ls\\%ls", selfOem.getKextsDirPathRelToSelfDir().wc_str(), KextDirNameUnderOEMPath, DirEntry->FileName);
XStringW pathUnderKextsDir = SWPrintf("%ls\\%ls", KextDirNameUnderOEMPath, DirEntry->FileName);
mKext = new SIDELOAD_KEXT;
mKext->FileName.SWPrintf("%ls", DirEntry->FileName);
mKext->MenuItem.BValue = Blocked;
mKext->KextDirNameUnderOEMPath.SWPrintf("%ls", KextDirNameUnderOEMPath);
mKext->Version = GetBundleVersion(pathRelToSelfDir);
mKext->Version = GetBundleVersion(pathUnderKextsDir);
InjectKextList.AddReference(mKext, true);
DBG("Added Kext=%ls\\%ls\n", mKext->KextDirNameUnderOEMPath.wc_str(), mKext->FileName.wc_str());
// Obtain PlugInList
// Iterate over PlugIns directory
PlugInsPath = SWPrintf("%ls\\Contents\\PlugIns", pathRelToSelfDir.wc_str());
PlugInsPath = SWPrintf("%ls\\%ls\\Contents\\PlugIns", selfOem.getKextsDirPathRelToSelfDir().wc_str(), pathUnderKextsDir.wc_str());
DirIterOpen(&self.getCloverDir(), PlugInsPath.wc_str(), &PlugInsIter);
while (DirIterNext(&PlugInsIter, 1, L"*.kext", &PlugInEntry)) {

View File

@ -147,9 +147,7 @@ XStringW LOADER_ENTRY::getKextPlist(const EFI_FILE* Root, const XStringW& dirPat
}
TempName = SWPrintf("%ls\\%ls", FullName.wc_str(), L"Contents\\Info.plist");
//#ifndef LESS_DEBUG
MsgLog("info plist path: %ls\n", TempName.wc_str());
//#endif
if (!FileExists(Root, TempName)) {
//try to find a planar kext, without Contents
TempName = SWPrintf("%ls\\%ls", FullName.wc_str(), L"Info.plist");
@ -198,7 +196,7 @@ 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\\%s", dirPath.wc_str(), FileName.wc_str(), TempName.c_str());
const 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

View File

@ -63,7 +63,7 @@ public:
XBool isKextsDirFound() { return m_KextsDir != NULL; }
const EFI_FILE& getKextsDir() { assert(m_KextsDir != NULL); return *m_KextsDir; }
const XStringW& getKextsDirPathRelToSelfDir() { assert(m_KextsPathRelToSelfDir.notEmpty()); return m_KextsPathRelToSelfDir; }
const XStringW& getKextsDirPathRelToSelfDir() { assert(m_KextsPathRelToSelfDir.notEmpty()); return m_KextsPathRelToSelfDir; } // Usually "Kexts". Init from KEXTS_DIRNAME
const XStringW& getKextsFullPath() { assert(m_KextsFullPath.notEmpty()); return m_KextsFullPath; }
};

View File

@ -1220,7 +1220,7 @@ void LOADER_ENTRY::StartLoader()
for (size_t kextIdx = 0 ; kextIdx < kextArray.size() ; kextIdx++ ) {
const SIDELOAD_KEXT& KextEntry = kextArray[kextIdx];
DBG("Bridge kext to OC : Path=%ls\n", 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;
@ -1233,34 +1233,37 @@ void LOADER_ENTRY::StartLoader()
assert( selfOem.isKextsDirFound() ); // be sure before calling getKextsPathRelToSelfDir()
XStringW dirPath = SWPrintf("%ls\\%ls", selfOem.getKextsDirPathRelToSelfDir().wc_str(), KextEntry.KextDirNameUnderOEMPath.wc_str());
XString8 bundlePath = S8Printf("%ls\\%ls", dirPath.wc_str(), KextEntry.FileName.wc_str());
if ( FileExists(&self.getCloverDir(), bundlePath) ) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath, bundlePath.c_str());
XString8 bundleFullPath = S8Printf("%ls\\%ls", dirPath.wc_str(), KextEntry.FileName.wc_str());
if ( FileExists(&self.getCloverDir(), bundleFullPath) ) {
XString8 bundlePathUnderKextsDir = S8Printf("%ls\\%ls", KextEntry.KextDirNameUnderOEMPath.wc_str(), KextEntry.FileName.wc_str());
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath, bundlePathUnderKextsDir.c_str());
DBG("OC BundlePath = '%s'\n", OC_BLOB_GET(&mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath));
} else {
DBG("Cannot find kext bundlePath at '%s'\n", bundlePath.c_str());
DBG("Cannot find kext bundlePath at '%s'\n", bundleFullPath.c_str());
}
#if 1
//CFBundleExecutable
XBool NoContents = false;
XStringW infoPlistPath = getKextPlist(&self.getCloverDir(), dirPath, KextEntry.FileName, &NoContents); //it will be fullPath, including dir
DBG("InfoPlistPath=%ls\n", infoPlistPath.wc_str());
XStringW infoPlistPathRelToSelf = getKextPlist(&self.getCloverDir(), dirPath, KextEntry.FileName, &NoContents); //it will be fullPath, including dir
// XBool inject = checkOSBundleRequired(dict);
XBool inject = true;
if (inject) {
if ( infoPlistPath.notEmpty()) {
if ( infoPlistPathRelToSelf.notEmpty()) {
if (NoContents) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->PlistPath, "Info.plist");
} else {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->PlistPath, "Contents/Info.plist");
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->PlistPath, "Contents\\Info.plist");
}
DBG("OC PlistPath = '%s'\n", OC_BLOB_GET(&mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->PlistPath));
} else {
DBG("Cannot find kext info.plist at '%ls'\n", KextEntry.FileName.wc_str());
}
TagDict* dict = getInfoPlist(&self.getCloverDir(), infoPlistPath);
XString8 execpath = getKextExecPath(&self.getCloverDir(), dirPath, KextEntry.FileName, dict, NoContents);
TagDict* dict = getInfoPlist(&self.getCloverDir(), infoPlistPathRelToSelf);
XString8 execpath = getKextExecPath(&self.getCloverDir(), KextEntry.KextDirNameUnderOEMPath, KextEntry.FileName, dict, NoContents);
if (execpath.notEmpty()) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->ExecutablePath, execpath.c_str());
DBG("assign executable as '%s'\n", execpath.c_str());
DBG("OC ExecutablePath = '%s'\n", execpath.c_str());
}
if ( dict ) dict->ReleaseTag();
}
@ -1271,11 +1274,11 @@ void LOADER_ENTRY::StartLoader()
if ( FileExists(&self.getCloverDir(), fullPath) ) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->ExecutablePath, S8Printf("Contents\\MacOS\\%ls", KextEntry.FileName.subString(0, KextEntry.FileName.rindexOf(".")).wc_str()).c_str());
}
XStringW infoPlistPath = SWPrintf("%s\\Contents\\Info.plist", OC_BLOB_GET(&mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath));
if (FileExists(&self.getCloverDir(), infoPlistPath)) {
XStringW infoPlistPathRelToSelf = SWPrintf("%s\\Contents\\Info.plist", OC_BLOB_GET(&mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath));
if (FileExists(&self.getCloverDir(), infoPlistPathRelToSelf)) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->PlistPath, "Contents/Info.plist"); // TODO : is always Contents/Info.plist ?
} else {
DBG("Cannot find kext info.plist at '%ls'\n", infoPlistPath.wc_str());
DBG("Cannot find kext info.plist at '%ls'\n", infoPlistPathRelToSelf.wc_str());
}
#endif
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->ImageData = NULL;