| 125 | //extern VOID AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize, INT32 N, LOADER_ENTRY *Entry); |
| 126 | |
| 127 | EFI_STATUS LOADER_ENTRY::LoadKext(IN EFI_FILE *RootDir, IN CONST CHAR16 *FileName, IN cpu_type_t archCpuType, IN OUT VOID *kext_v) |
| 128 | { |
| 129 | EFI_STATUS Status; |
| 130 | UINT8* infoDictBuffer = NULL; |
| 131 | UINTN infoDictBufferLength = 0; |
| 132 | UINT8* executableFatBuffer = NULL; |
| 133 | UINT8* executableBuffer = NULL; |
| 134 | UINTN executableBufferLength = 0; |
| 135 | CHAR8* bundlePathBuffer = NULL; |
| 136 | UINTN bundlePathBufferLength = 0; |
| 137 | XStringW TempName; |
| 138 | XStringW Executable; |
| 139 | TagDict* dict = NULL; |
| 140 | const TagStruct* prop = NULL; |
| 141 | BOOLEAN NoContents = FALSE; |
| 142 | BOOLEAN inject = FALSE; |
| 143 | _BooterKextFileInfo *infoAddr = NULL; |
| 144 | _DeviceTreeBuffer *kext = (_DeviceTreeBuffer *)kext_v; |
| 145 | |
| 146 | TempName = SWPrintf("%ls\\%ls", FileName, L"Contents\\Info.plist"); |
| 147 | // snwprintf(TempName, 512, L"%s\\%s", FileName, "Contents\\Info.plist"); |
| 148 | Status = egLoadFile(RootDir, TempName.wc_str(), &infoDictBuffer, &infoDictBufferLength); |
| 149 | if (EFI_ERROR(Status)) { |
| 150 | //try to find a planar kext, without Contents |
| 151 | TempName = SWPrintf("%ls\\%ls", FileName, L"Info.plist"); |
| 152 | // snwprintf(TempName, 512, L"%s\\%s", FileName, "Info.plist"); |
| 153 | infoDictBufferLength = 0; |
| 154 | Status = egLoadFile(RootDir, TempName.wc_str(), &infoDictBuffer, &infoDictBufferLength); |
| 155 | if (EFI_ERROR(Status)) { |
| 156 | MsgLog("Failed to load extra kext : %ls status=%s\n", TempName.wc_str(), efiStrError(Status)); |
| 157 | return EFI_NOT_FOUND; |
| 158 | } |
| 159 | NoContents = TRUE; |
| 160 | } |
| 161 | if( ParseXML((CHAR8*)infoDictBuffer, &dict,infoDictBufferLength)!=0 ) { |
| 162 | FreePool(infoDictBuffer); |
| 163 | MsgLog("Failed to load extra kext (failed to parse Info.plist): %ls\n", FileName); |
| 164 | return EFI_NOT_FOUND; |
| 165 | } |
| 166 | |
| 167 | inject = checkOSBundleRequired(LoaderType, dict); |
| 168 | if(!inject) { |
| 169 | MsgLog("Skipping kext injection by OSBundleRequired : %ls\n", FileName); |
| 170 | return EFI_UNSUPPORTED; |
| 171 | } |
| 172 | |
| 173 | prop = dict->propertyForKey("CFBundleExecutable"); |
| 174 | if( prop != NULL && prop->isString() && prop->getString()->stringValue().notEmpty() ) { |
| 175 | Executable.takeValueFrom(prop->getString()->stringValue()); |
| 176 | // AsciiStrToUnicodeStrS(prop->getString()->stringValue(), Executable, 256); |
| 177 | if (NoContents) { |
| 178 | TempName = SWPrintf("%ls\\%ls", FileName, Executable.wc_str()); |
| 179 | // snwprintf(TempName, 512, "%s\\%s", FileName, Executable); |
| 180 | } else { |
| 181 | TempName = SWPrintf("%ls\\%ls\\%ls", FileName, L"Contents\\MacOS", Executable.wc_str()); |
| 182 | // snwprintf(TempName, 512, L"%s\\%s\\%s", FileName, "Contents\\MacOS",Executable); |
| 183 | } |
| 184 | Status = egLoadFile(RootDir, TempName.wc_str(), &executableFatBuffer, &executableBufferLength); |
nothing calls this directly
no test coverage detected