prepare for kext injecting, step 2

Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
SergeySlice 2022-03-06 13:42:12 +03:00
parent af0fb92a75
commit d69a944398
3 changed files with 44 additions and 26 deletions

View File

@ -135,19 +135,25 @@ XBool LOADER_ENTRY::checkOSBundleRequired(const TagDict* dict)
//extern void KernelAndKextPatcherInit(IN LOADER_ENTRY *Entry);
//extern void AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize, INT32 N, LOADER_ENTRY *Entry);
//XStringW infoPlistPath = getKextPlist(dir, KextEntry, &NoContents);
XStringW LOADER_ENTRY::getKextPlist(const XStringW& dirPath, const SIDELOAD_KEXT& KextEntry, XBool* NoContents)
//XStringW infoPlistPath = getKextPlist(&self.getCloverDir(), dir, KextEntry, &NoContents);
XStringW LOADER_ENTRY::getKextPlist(const EFI_FILE& Root, const XStringW& dirPath, const XStringW& FileName, XBool* NoContents)
{
XStringW TempName;
XStringW FullName;
if (dirPath.isEmpty()) { //dirPath.isEmpty()
FullName = FileName;
} else {
FullName = SWPrintf("%ls\\%ls", dirPath.wc_str(), FileName.wc_str());
}
TempName = SWPrintf("%ls\\%ls\\%ls", dirPath.wc_str(), KextEntry.FileName.wc_str(), L"Contents\\Info.plist");
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(&self.getCloverDir(), TempName)) {
if (!FileExists(&Root, TempName)) {
//try to find a planar kext, without Contents
TempName = SWPrintf("%ls\\%ls\\%ls", dirPath.wc_str(), KextEntry.FileName.wc_str(), L"Info.plist");
if (!FileExists(&self.getCloverDir(), TempName)) {
TempName = SWPrintf("%ls\\%ls", FullName.wc_str(), L"Info.plist");
if (!FileExists(&Root, TempName)) {
MsgLog("Failed to load extra kext : %ls \n", TempName.wc_str());
return L""_XSW;
}
@ -159,14 +165,14 @@ XStringW LOADER_ENTRY::getKextPlist(const XStringW& dirPath, const SIDELOAD_KEXT
}
//TagDict* dict = getInfoPlist(infoPlistPath);
TagDict* LOADER_ENTRY::getInfoPlist(const XStringW& infoPlistPath)
TagDict* LOADER_ENTRY::getInfoPlist(const EFI_FILE& Root, const XStringW& infoPlistPath)
{
EFI_STATUS Status;
UINT8* infoDictBuffer = NULL;
UINTN infoDictBufferLength = 0;
TagDict* dict = NULL;
Status = egLoadFile(&self.getCloverDir(), infoPlistPath.wc_str(), &infoDictBuffer, &infoDictBufferLength);
Status = egLoadFile(&Root, infoPlistPath.wc_str(), &infoDictBuffer, &infoDictBufferLength);
if (!EFI_ERROR(Status)) { //double check
if( ParseXML((CHAR8*)infoDictBuffer, &dict, infoDictBufferLength)!=0 ) {
MsgLog("Failed to parse Info.plist: %ls\n", infoPlistPath.wc_str());
@ -178,8 +184,8 @@ TagDict* LOADER_ENTRY::getInfoPlist(const XStringW& infoPlistPath)
return NULL;
}
//XString8 execpath = getKextExecPath(dir, KextEntry, dict, NoContents);
XString8 LOADER_ENTRY::getKextExecPath(const XStringW& dirPath, const SIDELOAD_KEXT& KextEntry, TagDict* dict, XBool NoContents)
//XString8 execpath = getKextExecPath(dir, KextEntry.FileName, dict, NoContents);
XString8 LOADER_ENTRY::getKextExecPath(const EFI_FILE& Root, const XStringW& dirPath, const XStringW& FileName, TagDict* dict, XBool NoContents)
{
const TagStruct* prop = NULL;
XString8 TempName;
@ -192,9 +198,9 @@ XString8 LOADER_ENTRY::getKextExecPath(const XStringW& dirPath, const SIDELOAD_
} else {
TempName = S8Printf("Contents\\MacOS\\%s", Executable.c_str());
}
const XStringW& fullPath = SWPrintf("%ls\\%ls\\%s", dirPath.wc_str(), KextEntry.FileName.wc_str(), TempName.c_str());
if (!FileExists(&self.getCloverDir(), fullPath)) {
MsgLog("Failed to load kext executable: %ls\n", KextEntry.FileName.wc_str());
const XStringW& fullPath = SWPrintf("%ls\\%ls\\%s", 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
}
}
@ -489,6 +495,7 @@ void LOADER_ENTRY::AddKextsInArray(XObjArray<SIDELOAD_KEXT>* kextArray)
}
// Force kexts to load
/*
if ( KernelAndKextPatches.ForceKextsToLoad.notEmpty() ) {
for (size_t i = 0; i < KernelAndKextPatches.ForceKextsToLoad.size(); ++i) {

View File

@ -360,7 +360,7 @@ class REFIT_ABSTRACT_MENU_ENTRY
UINT8 LoaderType;
MacOsVersion macOSVersion;
XString8 BuildVersion;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL BootBgColor;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL BootBgColor;
UINT8 CustomBoot;
XImage CustomLogo;
@ -489,9 +489,9 @@ class REFIT_ABSTRACT_MENU_ENTRY
void DelegateKernelPatches();
XBool checkOSBundleRequired(const TagDict* dict);
XStringW getKextPlist(const XStringW& dirPath, const SIDELOAD_KEXT& KextEntry, XBool* NoContents);
TagDict* getInfoPlist(const XStringW& infoPlistPath);
XString8 getKextExecPath(const XStringW& dirPath, const SIDELOAD_KEXT& KextEntry, TagDict* dict, XBool NoContents);
XStringW getKextPlist(const EFI_FILE& Root, const XStringW& dirPath, const XStringW& FileName, XBool* NoContents);
TagDict* getInfoPlist(const EFI_FILE& Root, const XStringW& infoPlistPath);
XString8 getKextExecPath(const EFI_FILE& Root, const XStringW& dirPath, const XStringW& FileName, TagDict* dict, XBool NoContents);
} ;

View File

@ -1129,8 +1129,8 @@ void LOADER_ENTRY::StartLoader()
#if 1
//CFBundleExecutable
XBool NoContents = false;
XStringW infoPlistPath = getKextPlist(dirPath, KextEntry, &NoContents); //it will be fullPath, including dir
TagDict* dict = getInfoPlist(infoPlistPath);
XStringW infoPlistPath = getKextPlist(self.getCloverDir(), dirPath, KextEntry.FileName, &NoContents); //it will be fullPath, including dir
TagDict* dict = getInfoPlist(self.getCloverDir(), infoPlistPath);
// XBool inject = checkOSBundleRequired(dict);
XBool inject = true;
if (inject) {
@ -1143,7 +1143,7 @@ void LOADER_ENTRY::StartLoader()
}else{
DBG("Cannot find kext info.plist at '%ls'\n", KextEntry.FileName.wc_str());
}
XString8 execpath = getKextExecPath(dirPath, KextEntry, dict, NoContents);
XString8 execpath = getKextExecPath(self.getCloverDir(), dirPath, 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());
@ -1179,7 +1179,7 @@ void LOADER_ENTRY::StartLoader()
mOpenCoreConfiguration.Kernel.Force.Values = (OC_KERNEL_ADD_ENTRY**)malloc(mOpenCoreConfiguration.Kernel.Force.AllocCount*sizeof(*mOpenCoreConfiguration.Kernel.Force.Values)); // sizeof(OC_KERNEL_FORCE_ENTRY*) == sizeof(ptr)
memset(mOpenCoreConfiguration.Kernel.Force.Values, 0, mOpenCoreConfiguration.Kernel.Force.AllocCount*sizeof(*mOpenCoreConfiguration.Kernel.Force.Values));
const XStringW& empty = ""_XSW;
for (size_t kextIdx = 0 ; kextIdx < KernelAndKextPatches.ForceKextsToLoad.size() ; kextIdx++ )
{
const XStringW& forceKext = KernelAndKextPatches.ForceKextsToLoad[kextIdx];
@ -1199,17 +1199,28 @@ void LOADER_ENTRY::StartLoader()
mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->PlistData = NULL;
mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->PlistDataSize = 0;
// XString8 execpath = getKextExecPath(dirPath, KextEntry, dict, NoContents);
// for kext IOAudioFamily BundlePath = System\Library\Extensions\IOAudioFamily.kext
// ExecutablePath = Contents/MacOS/IOAudioFamily
if ( FileExists(Volume->VoduleDir, bundlePath) ) {
XStringW infoPlistPath = getKextPlist(Volume->RootDir, dirPath, forceKext, &NoContents); //it will be fullPath, including dir
// XString8 execpath = getKextExecPath(Volume->RootDir, dirPath, forceKext, dict, NoContents);
// for kext IOAudioFamily BundlePath = System\Library\Extensions\IOAudioFamily.kext
// ExecutablePath = Contents/MacOS/IOAudioFamily
// XStringW plist = SWPrintf("%s\\System\\Library\\CoreServices\\SystemVersion.plist", uuidPrefix.c_str());
// if ( !FileExists(Volume->RootDir, plist) ) {
// plist = SWPrintf("%s\\System\\Library\\CoreServices\\ServerVersion.plist", uuidPrefix.c_str());
// if ( !FileExists(Volume->RootDir, plist) ) {
// plist.setEmpty();
// }
// }
if ( FileExists(Volume->RootDir, forceKext.wc_str()) ) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath, S8Printf("%ls",forceKext.wc_str()).c_str());
}else{
DBG("Cannot find kext bundlePath at '%s'\n", S8Printf("%ls",forceKext.wc_str()).c_str());
}
//then we have to find executablePath and plistPath
if (forceKext.notEmpty()) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->ExecutablePath, S8Printf("%ls",forceKext.wc_str()).c_str());
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->ExecutablePath, executablePath.c_str());
DBG("assign executable as '%s'\n", mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->ExecutablePath.Value);
}
}