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

Method BooterPatch

rEFIt_UEFI/Platform/kernel_patcher.cpp:2423–2481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2421}
2422
2423BOOLEAN
2424LOADER_ENTRY::BooterPatch(IN UINT8 *BooterData, IN UINT64 BooterSize)
2425{
2426 INTN Num, y = 0;
2427
2428
2429 for (size_t i = 0 ; i < KernelAndKextPatches.BootPatches.size(); ++i)
2430 {
2431 // if we modify directly KernelAndKextPatches.BootPatches[i].SearchLen, it will wrong for next driver
2432 UINTN SearchLen = KernelAndKextPatches.BootPatches[i].SearchLen;
2433 if (!SearchLen) {
2434 SearchLen = BooterSize;
2435 }
2436
2437 DBG( "Patch[%zu]: %s\n", i, KernelAndKextPatches.BootPatches[i].Label.c_str());
2438 if (!KernelAndKextPatches.BootPatches[i].MenuItem.BValue) {
2439 DBG( "==> disabled\n");
2440 continue;
2441 }
2442 UINT8 * curs = BooterData;
2443 UINTN j = 0;
2444 while (j < BooterSize) {
2445 if (KernelAndKextPatches.BootPatches[i].StartPattern.isEmpty() || //old behavior
2446 CompareMemMask((const UINT8*)curs,
2447 (const UINT8*)KernelAndKextPatches.BootPatches[i].StartPattern.data(),
2448 KernelAndKextPatches.BootPatches[i].StartPattern.size(),
2449 (const UINT8*)KernelAndKextPatches.BootPatches[i].StartMask.data(),
2450 KernelAndKextPatches.BootPatches[i].StartPattern.size())) {
2451 DBG( " StartPattern found\n");
2452
2453 Num = SearchAndReplaceMask(curs,
2454 SearchLen,
2455 (const UINT8*)KernelAndKextPatches.BootPatches[i].Data.data(),
2456 (const UINT8*)KernelAndKextPatches.BootPatches[i].MaskFind.data(),
2457 KernelAndKextPatches.BootPatches[i].Data.size(),
2458 (const UINT8*)KernelAndKextPatches.BootPatches[i].Patch.data(),
2459 (const UINT8*)KernelAndKextPatches.BootPatches[i].MaskReplace.data(),
2460 KernelAndKextPatches.BootPatches[i].Count
2461 );
2462 if (Num) {
2463 y++;
2464 curs += SearchLen - 1;
2465 j += SearchLen - 1;
2466 }
2467
2468 DBG( "==> %s : %lld replaces done\n", Num ? "Success" : "Error", Num);
2469 if ( KernelAndKextPatches.BootPatches[i].StartPattern.isEmpty() ) {
2470 break;
2471 }
2472 }
2473 j++; curs++;
2474 }
2475 }
2476// if (KernelAndKextPatches.KPDebug) {
2477// gBS->Stall(2000000);
2478// }
2479 Stall(2000000);
2480 return (y != 0);

Callers

nothing calls this directly

Calls 6

CompareMemMaskFunction · 0.85
SearchAndReplaceMaskFunction · 0.85
sizeMethod · 0.45
c_strMethod · 0.45
isEmptyMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected