From 5135d1a3579104b4c69994135c424c5a524c11f9 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 23 Sep 2019 15:38:14 +0200 Subject: Ensure that the correct Windows bootloader is executed when the user press ESCAPE --- DcsBoot/DcsBoot.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/DcsBoot/DcsBoot.c b/DcsBoot/DcsBoot.c index 18fb005..080b052 100644 --- a/DcsBoot/DcsBoot.c +++ b/DcsBoot/DcsBoot.c @@ -29,6 +29,7 @@ CHAR16 *gEfiExecCmdDefault = L"\\EFI\\Microsoft\\Boot\\Bootmgfw_ms.vc CHAR16 *gEfiExecCmdMS = L"\\EFI\\Microsoft\\Boot\\Bootmgfw.efi"; CHAR16 *gEfiExecCmd = NULL; CHAR8 gDoExecCmdMsg[256]; +CONST CHAR8* g_szMsBootString = "bootmgfw.pdb"; EFI_STATUS DoExecCmd() @@ -58,6 +59,39 @@ DoExecCmd() return res; } +EFI_STATUS +ExecMSWindowsLoader() { + + if (!EFI_ERROR(FileExist(NULL, gEfiExecCmdDefault))) + return EfiExec(NULL, gEfiExecCmdDefault); + else + { + if (!EFI_ERROR(FileExist(NULL, gEfiExecCmdMS))) + { + /* check if it is Microsoft one */ + UINT8* fileData = NULL; + UINTN fileSize = 0; + BOOLEAN bFound = FALSE; + if (!EFI_ERROR(FileLoad(NULL, gEfiExecCmdMS, &fileData, &fileSize))) + { + if ((fileSize > 32768) && !EFI_ERROR(MemoryHasPattern(fileData, fileSize, g_szMsBootString, AsciiStrLen(g_szMsBootString)))) + { + bFound = TRUE; + } + } + + MEM_FREE(fileData); + + if (bFound) + return EfiExec(NULL, gEfiExecCmdMS); + } + + ERR_PRINT(L"Could not find the original Windows loader\r\n"); + + return EFI_NOT_READY; + } +} + ////////////////////////////////////////////////////////////////////////// // BML ////////////////////////////////////////////////////////////////////////// @@ -186,7 +220,7 @@ DcsBootMain( else if (res == EFI_DCS_USER_CANCELED) { /* If user cancels password prompt, call original Windows loader */ - res = EfiExec(NULL, gEfiExecCmdDefault); + res = ExecMSWindowsLoader (); } return res; } -- cgit v1.2.3