Skip to content

Commit 8a5ef4c

Browse files
committed
[FREELDR] Implement PeLdrLoadImageEx
This allows to load an image as freeldr extension code. TODO: - Add global bootloader DTE list - Add wrapper function that also processes imports - Use this for scsiport
1 parent bee8e81 commit 8a5ef4c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

boot/freeldr/freeldr/include/peloader.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ PeLdrLoadImage(
3232
_In_ TYPE_OF_MEMORY MemoryType,
3333
_Out_ PVOID* ImageBasePA);
3434

35+
BOOLEAN
36+
PeLdrLoadImageEx(
37+
_In_ PCSTR FilePath,
38+
_In_ TYPE_OF_MEMORY MemoryType,
39+
_Out_ PVOID* ImageBasePA,
40+
_In_ BOOLEAN KernelMapping);
41+
3542
BOOLEAN
3643
PeLdrAllocateDataTableEntry(
3744
IN OUT PLIST_ENTRY ModuleListHead,

boot/freeldr/freeldr/lib/peloader.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,11 @@ PeLdrFreeDataTableEntry(
820820
* Addressing mode: physical.
821821
**/
822822
BOOLEAN
823-
PeLdrLoadImage(
823+
PeLdrLoadImageEx(
824824
_In_ PCSTR FilePath,
825825
_In_ TYPE_OF_MEMORY MemoryType,
826-
_Out_ PVOID* ImageBasePA)
826+
_Out_ PVOID* ImageBasePA,
827+
_In_ BOOLEAN KernelMapping)
827828
{
828829
ULONG FileId;
829830
PVOID PhysicalBase;
@@ -895,7 +896,7 @@ PeLdrLoadImage(
895896
}
896897

897898
/* This is the real image base, in form of a virtual address */
898-
VirtualBase = PaToVa(PhysicalBase);
899+
VirtualBase = KernelMapping ? PaToVa(PhysicalBase) : PhysicalBase;
899900

900901
TRACE("Base PA: 0x%p, VA: 0x%p\n", PhysicalBase, VirtualBase);
901902

@@ -1009,3 +1010,12 @@ PeLdrLoadImage(
10091010
MmFreeMemory(PhysicalBase);
10101011
return FALSE;
10111012
}
1013+
1014+
BOOLEAN
1015+
PeLdrLoadImage(
1016+
_In_ PCSTR FilePath,
1017+
_In_ TYPE_OF_MEMORY MemoryType,
1018+
_Out_ PVOID* ImageBasePA)
1019+
{
1020+
return PeLdrLoadImageEx(FilePath, MemoryType, ImageBasePA, TRUE);
1021+
}

0 commit comments

Comments
 (0)