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

Method AnyKextPatch

rEFIt_UEFI/Platform/kext_patcher.cpp:1111–1211  ·  view source on GitHub ↗

/////////////////////////////// Generic kext patch functions

Source from the content-addressed store, hash-verified

1109//
1110//
1111VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize, size_t N)
1112{
1113 UINTN Num = 0;
1114
1115 // if we modify value directly at KernelAndKextPatches->KextPatches[N].SearchLen, it will be wrong for next driver
1116 const KEXT_PATCH& kextpatch = KernelAndKextPatches.KextPatches[N];
1117 UINTN SearchLen = kextpatch.SearchLen;
1118
1119 DBG_RT("\nAnyKextPatch %zu: driverAddr = %llx, driverSize = %x\n Label = %s\n",
1120 N, (UINTN)Driver, DriverSize, kextpatch.Label.c_str());
1121 DBG("\nAnyKextPatch %zu: driverAddr = %llx, driverSize = %x\n Label = %s\n",
1122 N, (UINTN)Driver, DriverSize, kextpatch.Label.c_str());
1123
1124 if (!kextpatch.MenuItem.BValue) {
1125 return;
1126 }
1127
1128
1129 if (!SearchLen ||
1130 (SearchLen > DriverSize)) {
1131 SearchLen = DriverSize;
1132 }
1133
1134 if (KernelAndKextPatches.KPDebug) {
1135 ExtractKextBundleIdentifier(InfoPlist);
1136 }
1137
1138 DBG_RT("Kext: %s\n", gKextBundleIdentifier);
1139
1140 if (!kextpatch.IsPlistPatch) {
1141 // kext binary patch
1142 DBG_RT("Binary patch\n");
1143 bool once = false;
1144 UINTN procLen = 0;
1145 UINTN procAddr = searchProcInDriver(Driver, DriverSize, kextpatch.ProcedureName);
1146
1147 if (SearchLen == DriverSize) {
1148 procLen = DriverSize - procAddr;
1149 once = true;
1150 } else {
1151 procLen = SearchLen;
1152 }
1153 UINT8 * curs = &Driver[procAddr];
1154 UINTN j = 0;
1155 while (j < DriverSize) {
1156 if (kextpatch.StartPattern.isEmpty() || //old behavior
1157 CompareMemMask((const UINT8*)curs,
1158 kextpatch.StartPattern.data(),
1159 kextpatch.StartPattern.size(),
1160 kextpatch.StartMask.data(),
1161 kextpatch.StartPattern.size())) {
1162 DBG_RT(" StartPattern found\n");
1163
1164 Num = SearchAndReplaceMask(curs,
1165 procLen,
1166 kextpatch.Data.data(),
1167 kextpatch.MaskFind.data(),
1168 kextpatch.Data.size(),

Callers

nothing calls this directly

Calls 9

CompareMemMaskFunction · 0.85
SearchAndReplaceMaskFunction · 0.85
SearchAndReplaceTxtFunction · 0.85
StallMethod · 0.80
c_strMethod · 0.45
isEmptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected