Skip to content

Commit 393b1f8

Browse files
committed
[FREELDR] Implement PeLdrLoadBootImage
1 parent f9849f7 commit 393b1f8

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

boot/freeldr/freeldr/include/peloader.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,10 @@ PeLdrCheckForLoadedDll(
7070
PVOID
7171
PeLdrInitSecurityCookie(
7272
_In_ PLDR_DATA_TABLE_ENTRY LdrEntry);
73+
74+
BOOLEAN
75+
PeLdrLoadBootImage(
76+
_In_ PCSTR FilePath,
77+
_In_ PCSTR BaseDllName,
78+
_Out_ PVOID* ImageBase,
79+
_Out_ PLDR_DATA_TABLE_ENTRY* DataTableEntry);

boot/freeldr/freeldr/lib/peloader.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,3 +1044,51 @@ PeLdrLoadImage(
10441044
{
10451045
return PeLdrLoadImageEx(FilePath, MemoryType, ImageBasePA, TRUE);
10461046
}
1047+
1048+
BOOLEAN
1049+
PeLdrLoadBootImage(
1050+
_In_ PCSTR FilePath,
1051+
_In_ PCSTR BaseDllName,
1052+
_Out_ PVOID* ImageBase,
1053+
_Out_ PLDR_DATA_TABLE_ENTRY* DataTableEntry)
1054+
{
1055+
BOOLEAN Success;
1056+
1057+
/* Load the image as a bootloader image */
1058+
Success = PeLdrLoadImageEx(FilePath,
1059+
LoaderLoadedProgram,
1060+
ImageBase,
1061+
FALSE);
1062+
if (!Success)
1063+
{
1064+
WARN("Failed to load boot image '%s'\n", FilePath);
1065+
return FALSE;
1066+
}
1067+
1068+
/* Allocate a DTE */
1069+
Success = PeLdrAllocateDataTableEntry(&FrLdrModuleList,
1070+
BaseDllName,
1071+
FilePath,
1072+
*ImageBase,
1073+
DataTableEntry);
1074+
if (!Success)
1075+
{
1076+
/* Cleanup and bail out */
1077+
ERR("Failed to allocate DTE for '%s'\n", FilePath);
1078+
MmFreeMemory(*ImageBase);
1079+
return FALSE;
1080+
}
1081+
1082+
/* Resolve imports */
1083+
Success = PeLdrScanImportDescriptorTable(&FrLdrModuleList, "", *DataTableEntry);
1084+
if (!Success)
1085+
{
1086+
/* Cleanup and bail out */
1087+
ERR("Failed to resolve imports for '%s'\n", FilePath);
1088+
PeLdrFreeDataTableEntry(*DataTableEntry);
1089+
MmFreeMemory(*ImageBase);
1090+
return FALSE;
1091+
}
1092+
1093+
return TRUE;
1094+
}

0 commit comments

Comments
 (0)