[FREELDR] Implement PeLdrLoadBootImage

This commit is contained in:
Timo Kreuzer 2024-10-05 12:18:00 +02:00
parent f9849f7cc4
commit 393b1f8998
2 changed files with 55 additions and 0 deletions

View file

@ -70,3 +70,10 @@ PeLdrCheckForLoadedDll(
PVOID PVOID
PeLdrInitSecurityCookie( PeLdrInitSecurityCookie(
_In_ PLDR_DATA_TABLE_ENTRY LdrEntry); _In_ PLDR_DATA_TABLE_ENTRY LdrEntry);
BOOLEAN
PeLdrLoadBootImage(
_In_ PCSTR FilePath,
_In_ PCSTR BaseDllName,
_Out_ PVOID* ImageBase,
_Out_ PLDR_DATA_TABLE_ENTRY* DataTableEntry);

View file

@ -1044,3 +1044,51 @@ PeLdrLoadImage(
{ {
return PeLdrLoadImageEx(FilePath, MemoryType, ImageBasePA, TRUE); 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;
}