From 22a7676b9b5cfaf88b8fa2e2675c7230877c5628 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Mon, 22 Jan 2024 15:11:56 +0100 Subject: [PATCH] Store boot loader image information and close EFI_LOADED_IMAGE_PROTOCOL afterwards --- sdk/xtdk/bltypes.h | 2 ++ xtldr/xtldr.c | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sdk/xtdk/bltypes.h b/sdk/xtdk/bltypes.h index d4a5513..89b56a9 100644 --- a/sdk/xtdk/bltypes.h +++ b/sdk/xtdk/bltypes.h @@ -195,6 +195,8 @@ typedef struct _XTBL_STATUS PBL_XT_BOOT_MENU BootMenu; BOOLEAN BootServices; ULONG DebugPort; + PVOID LoaderBase; + ULONGLONG LoaderSize; INT_PTR SecureBoot; CPPORT SerialPort; } XTBL_STATUS, *PXTBL_STATUS; diff --git a/xtldr/xtldr.c b/xtldr/xtldr.c index 7d82681..6df5ce7 100644 --- a/xtldr/xtldr.c +++ b/xtldr/xtldr.c @@ -42,12 +42,16 @@ BlInitializeBootLoader() /* Store SecureBoot status */ BlpStatus.SecureBoot = BlGetSecureBootStatus(); - /* Check if debug is enabled */ - if(DEBUG) + /* Attempt to open EFI LoadedImage protocol */ + Status = BlOpenProtocol(&Handle, (PVOID *)&LoadedImage, &LipGuid); + if(Status == STATUS_EFI_SUCCESS) { - /* Attempt to open EFI LoadedImage protocol */ - Status = BlOpenProtocol(&Handle, (PVOID *)&LoadedImage, &LipGuid); - if(Status == STATUS_EFI_SUCCESS) + /* Store boot loader image base and size */ + BlpStatus.LoaderBase = LoadedImage->ImageBase; + BlpStatus.LoaderSize = LoadedImage->ImageSize; + + /* Check if debug is enabled */ + if(DEBUG) { /* Protocol opened successfully, print useful debug information */ BlConsolePrint(L"\n---------- BOOTLOADER DEBUG ----------\n" @@ -62,6 +66,9 @@ BlInitializeBootLoader() LoadedImage->Revision); BlSleepExecution(3000); } + + /* Close EFI LoadedImage protocol */ + BlCloseProtocol(&Handle, &LipGuid); } }