https://git.reactos.org/?p=reactos.git;a=commitdiff;h=393b1f89982804b2bd307…
commit 393b1f89982804b2bd3074d773096ebbcf2fcd6d
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sat Oct 5 12:18:00 2024 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sat Nov 2 17:31:57 2024 +0200
[FREELDR] Implement PeLdrLoadBootImage
---
boot/freeldr/freeldr/include/peloader.h | 7 +++++
boot/freeldr/freeldr/lib/peloader.c | 48 +++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/boot/freeldr/freeldr/include/peloader.h
b/boot/freeldr/freeldr/include/peloader.h
index a2bf617463d..b2374f74ceb 100644
--- a/boot/freeldr/freeldr/include/peloader.h
+++ b/boot/freeldr/freeldr/include/peloader.h
@@ -70,3 +70,10 @@ PeLdrCheckForLoadedDll(
PVOID
PeLdrInitSecurityCookie(
_In_ PLDR_DATA_TABLE_ENTRY LdrEntry);
+
+BOOLEAN
+PeLdrLoadBootImage(
+ _In_ PCSTR FilePath,
+ _In_ PCSTR BaseDllName,
+ _Out_ PVOID* ImageBase,
+ _Out_ PLDR_DATA_TABLE_ENTRY* DataTableEntry);
diff --git a/boot/freeldr/freeldr/lib/peloader.c b/boot/freeldr/freeldr/lib/peloader.c
index 0511738164c..b2477c7e1a2 100644
--- a/boot/freeldr/freeldr/lib/peloader.c
+++ b/boot/freeldr/freeldr/lib/peloader.c
@@ -1044,3 +1044,51 @@ PeLdrLoadImage(
{
return PeLdrLoadImageEx(FilePath, MemoryType, ImageBasePA, TRUE);
}
+
+BOOLEAN
+PeLdrLoadBootImage(
+ _In_ PCSTR FilePath,
+ _In_ PCSTR BaseDllName,
+ _Out_ PVOID* ImageBase,
+ _Out_ PLDR_DATA_TABLE_ENTRY* DataTableEntry)
+{
+ BOOLEAN Success;
+
+ /* Load the image as a bootloader image */
+ Success = PeLdrLoadImageEx(FilePath,
+ LoaderLoadedProgram,
+ ImageBase,
+ FALSE);
+ if (!Success)
+ {
+ WARN("Failed to load boot image '%s'\n", FilePath);
+ return FALSE;
+ }
+
+ /* Allocate a DTE */
+ Success = PeLdrAllocateDataTableEntry(&FrLdrModuleList,
+ BaseDllName,
+ FilePath,
+ *ImageBase,
+ DataTableEntry);
+ if (!Success)
+ {
+ /* Cleanup and bail out */
+ ERR("Failed to allocate DTE for '%s'\n", FilePath);
+ MmFreeMemory(*ImageBase);
+ return FALSE;
+ }
+
+ /* Resolve imports */
+ Success = PeLdrScanImportDescriptorTable(&FrLdrModuleList, "",
*DataTableEntry);
+ if (!Success)
+ {
+ /* Cleanup and bail out */
+ ERR("Failed to resolve imports for '%s'\n", FilePath);
+ PeLdrFreeDataTableEntry(*DataTableEntry);
+ MmFreeMemory(*ImageBase);
+ return FALSE;
+ }
+
+ return TRUE;
+}