MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / PatchLoadedKexts

Method PatchLoadedKexts

rEFIt_UEFI/Platform/kext_patcher.cpp:1589–1644  ·  view source on GitHub ↗

Iterates over kexts loaded by booter and calls PatchKext() for each.

Source from the content-addressed store, hash-verified

1587// and calls PatchKext() for each.
1588//
1589VOID LOADER_ENTRY::PatchLoadedKexts()
1590{
1591 DTEntry MMEntry;
1592 _BooterKextFileInfo *KextFileInfo;
1593 CHAR8 *PropName;
1594 _DeviceTreeBuffer *PropEntry;
1595 CHAR8 SavedValue;
1596 CHAR8 *InfoPlist;
1597 OpaqueDTPropertyIterator OPropIter;
1598 DTPropertyIterator PropIter = &OPropIter;
1599 //UINTN DbgCount = 0;
1600
1601
1602 DBG("\nPatchLoadedKexts ... dtRoot = %llx\n", (UINTN)dtRoot);
1603
1604 if (!dtRoot || !dtLength) {
1605 return;
1606 }
1607
1608 DTInit(dtRoot, dtLength);
1609
1610 if (!EFI_ERROR(DTLookupEntry(NULL,"/chosen/memory-map", &MMEntry))) {
1611 if (!EFI_ERROR(DTCreatePropertyIterator(MMEntry, PropIter))) {
1612 while (!EFI_ERROR(DTIterateProperties(PropIter, &PropName))) {
1613 //DBG(L"Prop: %s\n", PropName);
1614 if (AsciiStrStr(PropName,"Driver-")) {
1615 // PropEntry _DeviceTreeBuffer is the value of Driver-XXXXXX property
1616 PropEntry = (_DeviceTreeBuffer*)(((UINT8*)PropIter->CurrentProperty) + sizeof(DeviceTreeNodeProperty));
1617 //if (DbgCount < 3) DBG(L"%s: paddr = %hhX, length = %hhX\n", PropName, PropEntry->paddr, PropEntry->length);
1618
1619 // PropEntry->paddr points to _BooterKextFileInfo
1620 KextFileInfo = (_BooterKextFileInfo *)(UINTN)PropEntry->paddr;
1621
1622 // Info.plist should be terminated with 0, but will also do it just in case
1623 InfoPlist = (CHAR8*)(UINTN)KextFileInfo->infoDictPhysAddr;
1624 SavedValue = InfoPlist[KextFileInfo->infoDictLength];
1625 InfoPlist[KextFileInfo->infoDictLength] = '\0';
1626
1627 PatchKext(
1628 (UINT8*)(UINTN)KextFileInfo->executablePhysAddr,
1629 KextFileInfo->executableLength,
1630 InfoPlist,
1631 KextFileInfo->infoDictLength
1632 );
1633
1634 InfoPlist[KextFileInfo->infoDictLength] = SavedValue;
1635 }
1636 //if(AsciiStrStr(PropName,"DriversPackage-")!=0)
1637 //{
1638 // DBG(L"Found %s\n", PropName);
1639 // break;
1640 //}
1641 }
1642 }
1643 }
1644}
1645
1646//

Callers

nothing calls this directly

Calls 4

DTInitFunction · 0.50
DTLookupEntryFunction · 0.50
DTCreatePropertyIteratorFunction · 0.50
DTIteratePropertiesFunction · 0.50

Tested by

no test coverage detected