Skip to content

Commit 7fdb8b5

Browse files
committed
[FREELDR] Change the DTE path prefix to \SystemRoot\ for NT6.1+ compatibility
1 parent e0f25b3 commit 7fdb8b5

File tree

4 files changed

+61
-29
lines changed

4 files changed

+61
-29
lines changed

boot/freeldr/freeldr/disk/scsiport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ LoadBootDeviceDriver(VOID)
16881688
}
16891689

16901690
/* Fix imports */
1691-
Success = PeLdrScanImportDescriptorTable(&ModuleListHead, "", BootDdDTE);
1691+
Success = PeLdrScanImportDescriptorTable(&ModuleListHead, "", "", BootDdDTE);
16921692
if (!Success)
16931693
{
16941694
/* Cleanup and bail out */

boot/freeldr/freeldr/include/peloader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ BOOLEAN
4949
PeLdrScanImportDescriptorTable(
5050
IN OUT PLIST_ENTRY ModuleListHead,
5151
IN PCCH DirectoryPath,
52+
IN PCCH ArcPath,
5253
IN PLDR_DATA_TABLE_ENTRY ScanDTE);
5354

5455
BOOLEAN

boot/freeldr/freeldr/lib/peloader.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static BOOLEAN
128128
PeLdrpLoadAndScanReferencedDll(
129129
IN OUT PLIST_ENTRY ModuleListHead,
130130
IN PCCH DirectoryPath,
131+
IN PCCH ArcPath,
131132
IN PCH ImportName,
132133
IN PLIST_ENTRY Parent OPTIONAL,
133134
OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry);
@@ -142,6 +143,7 @@ PeLdrpBindImportName(
142143
IN ULONG ExportSize,
143144
IN BOOLEAN ProcessForwards,
144145
IN PCSTR DirectoryPath,
146+
IN PCSTR ArcPath,
145147
IN PLIST_ENTRY Parent)
146148
{
147149
ULONG Ordinal;
@@ -317,6 +319,7 @@ PeLdrpBindImportName(
317319
/* Now let's try to load it! */
318320
Success = PeLdrpLoadAndScanReferencedDll(ModuleListHead,
319321
DirectoryPath,
322+
ArcPath,
320323
ForwardDllName,
321324
Parent,
322325
&DataTableEntry);
@@ -366,6 +369,7 @@ PeLdrpBindImportName(
366369
RefExportSize,
367370
TRUE,
368371
DirectoryPath,
372+
ArcPath,
369373
Parent);
370374

371375
/* Fill out the ThunkData with data from RefThunkData */
@@ -389,28 +393,33 @@ static BOOLEAN
389393
PeLdrpLoadAndScanReferencedDll(
390394
IN OUT PLIST_ENTRY ModuleListHead,
391395
IN PCCH DirectoryPath,
396+
IN PCCH ArcPath,
392397
IN PCH ImportName,
393398
IN PLIST_ENTRY Parent OPTIONAL,
394399
OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry)
395400
{
396401
CHAR FullDllName[256];
402+
CHAR ArcFullDllName[256];
397403
BOOLEAN Success;
398404
PVOID BasePA = NULL;
399405

400406
/* Prepare the full path to the file to be loaded */
401407
RtlStringCbCopyA(FullDllName, sizeof(FullDllName), DirectoryPath);
402408
RtlStringCbCatA(FullDllName, sizeof(FullDllName), ImportName);
403409

410+
RtlStringCbCopyA(ArcFullDllName, sizeof(ArcFullDllName), ArcPath);
411+
RtlStringCbCatA(ArcFullDllName, sizeof(ArcFullDllName), ImportName);
412+
404413
TRACE("Loading referenced DLL: %s\n", FullDllName);
405414

406415
if (PeLdrImportDllLoadCallback)
407-
PeLdrImportDllLoadCallback(FullDllName);
416+
PeLdrImportDllLoadCallback(ArcFullDllName);
408417

409418
/* Load the image */
410-
Success = PeLdrLoadImage(FullDllName, LoaderBootDriver, &BasePA);
419+
Success = PeLdrLoadImage(ArcFullDllName, LoaderBootDriver, &BasePA);
411420
if (!Success)
412421
{
413-
ERR("PeLdrLoadImage('%s') failed\n", FullDllName);
422+
ERR("PeLdrLoadImage('%s') failed\n", ArcFullDllName);
414423
return Success;
415424
}
416425

@@ -436,7 +445,7 @@ PeLdrpLoadAndScanReferencedDll(
436445
/* Scan its dependencies too */
437446
TRACE("PeLdrScanImportDescriptorTable() calling ourselves for %S\n",
438447
VaToPa((*DataTableEntry)->BaseDllName.Buffer));
439-
Success = PeLdrScanImportDescriptorTable(ModuleListHead, DirectoryPath, *DataTableEntry);
448+
Success = PeLdrScanImportDescriptorTable(ModuleListHead, DirectoryPath, ArcPath, *DataTableEntry);
440449
if (!Success)
441450
{
442451
/* Cleanup and bail out */
@@ -451,12 +460,13 @@ PeLdrpLoadAndScanReferencedDll(
451460

452461
static BOOLEAN
453462
PeLdrpScanImportAddressTable(
454-
IN OUT PLIST_ENTRY ModuleListHead,
455-
IN PVOID DllBase,
456-
IN PVOID ImageBase,
457-
IN PIMAGE_THUNK_DATA ThunkData,
458-
IN PCSTR DirectoryPath,
459-
IN PLIST_ENTRY Parent)
463+
_Inout_ PLIST_ENTRY ModuleListHead,
464+
_In_ PVOID DllBase,
465+
_In_ PVOID ImageBase,
466+
_Inout_ PIMAGE_THUNK_DATA ThunkData,
467+
_In_ PCSTR DirectoryPath,
468+
_In_ PCSTR ArcPath,
469+
_In_ PLIST_ENTRY Parent)
460470
{
461471
PIMAGE_EXPORT_DIRECTORY ExportDirectory = NULL;
462472
BOOLEAN Success;
@@ -501,6 +511,7 @@ PeLdrpScanImportAddressTable(
501511
ExportSize,
502512
FALSE,
503513
DirectoryPath,
514+
ArcPath,
504515
Parent);
505516

506517
/* Move to the next entry */
@@ -605,6 +616,7 @@ BOOLEAN
605616
PeLdrScanImportDescriptorTable(
606617
IN OUT PLIST_ENTRY ModuleListHead,
607618
IN PCCH DirectoryPath,
619+
IN PCCH ArcPath,
608620
IN PLDR_DATA_TABLE_ENTRY ScanDTE)
609621
{
610622
PLDR_DATA_TABLE_ENTRY DataTableEntry;
@@ -648,6 +660,7 @@ PeLdrScanImportDescriptorTable(
648660
{
649661
Success = PeLdrpLoadAndScanReferencedDll(ModuleListHead,
650662
DirectoryPath,
663+
ArcPath,
651664
ImportName,
652665
&ScanDTE->InLoadOrderLinks,
653666
&DataTableEntry);
@@ -664,6 +677,7 @@ PeLdrScanImportDescriptorTable(
664677
ScanDTE->DllBase,
665678
(PIMAGE_THUNK_DATA)RVA(ScanDTE->DllBase, ImportTable->FirstThunk),
666679
DirectoryPath,
680+
ArcPath,
667681
&ScanDTE->InLoadOrderLinks);
668682

669683
if (!Success)

boot/freeldr/freeldr/ntldr/winldr.c

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
296296
PLDR_DATA_TABLE_ENTRY *DriverDTE)
297297
{
298298
CHAR FullPath[1024];
299+
CHAR FullFileName[1024];
300+
CHAR ArcPath[1024];
299301
CHAR DriverPath[1024];
300302
CHAR DllName[1024];
301303
PCHAR DriverNamePos;
@@ -331,18 +333,23 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
331333
}
332334

333335
// It's not loaded, we have to load it
334-
RtlStringCbPrintfA(FullPath, sizeof(FullPath), "%s%wZ", BootPath, FilePath);
336+
RtlStringCbPrintfA(ArcPath, sizeof(ArcPath), "%s%wZ", BootPath, FilePath);
335337

336-
NtLdrOutputLoadMsg(FullPath, NULL);
337-
Success = PeLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase);
338+
NtLdrOutputLoadMsg(ArcPath, NULL);
339+
Success = PeLdrLoadImage(ArcPath, LoaderBootDriver, &DriverBase);
338340
if (!Success)
339341
{
340342
ERR("PeLdrLoadImage('%s') failed\n", DllName);
341343
return FALSE;
342344
}
343345

344346
// Allocate a DTE for it
345-
Success = PeLdrAllocateDataTableEntry(LoadOrderListHead, DllName, DllName, DriverBase, DriverDTE);
347+
RtlStringCbPrintfA(FullFileName, sizeof(FullFileName), "\\SystemRoot\\%s%s", DriverPath, DllName);
348+
Success = PeLdrAllocateDataTableEntry(LoadOrderListHead,
349+
DllName,
350+
FullFileName,
351+
DriverBase,
352+
DriverDTE);
346353
if (!Success)
347354
{
348355
/* Cleanup and bail out */
@@ -358,8 +365,9 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
358365
(*DriverDTE)->Flags |= Flags;
359366

360367
// Look for any dependencies it may have, and load them too
361-
RtlStringCbPrintfA(FullPath, sizeof(FullPath), "%s%s", BootPath, DriverPath);
362-
Success = PeLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, *DriverDTE);
368+
RtlStringCbPrintfA(ArcPath, sizeof(ArcPath), "%s%s", BootPath, DriverPath);
369+
RtlStringCbPrintfA(FullPath, sizeof(FullPath), "\\SystemRoot\\%s", DriverPath);
370+
Success = PeLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, ArcPath, *DriverDTE);
363371
if (!Success)
364372
{
365373
/* Cleanup and bail out */
@@ -513,6 +521,7 @@ PVOID
513521
LoadModule(
514522
IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
515523
IN PCCH Path,
524+
IN PCCH ArcPath,
516525
IN PCCH File,
517526
IN PCCH ImportName, // BaseDllName
518527
IN TYPE_OF_MEMORY MemoryType,
@@ -521,6 +530,7 @@ LoadModule(
521530
{
522531
BOOLEAN Success;
523532
CHAR FullFileName[MAX_PATH];
533+
CHAR ArcFileName[MAX_PATH];
524534
CHAR ProgressString[256];
525535
PVOID BaseAddress;
526536

@@ -530,8 +540,11 @@ LoadModule(
530540
RtlStringCbCopyA(FullFileName, sizeof(FullFileName), Path);
531541
RtlStringCbCatA(FullFileName, sizeof(FullFileName), File);
532542

533-
NtLdrOutputLoadMsg(FullFileName, NULL);
534-
Success = PeLdrLoadImage(FullFileName, MemoryType, &BaseAddress);
543+
RtlStringCbCopyA(ArcFileName, sizeof(ArcFileName), ArcPath);
544+
RtlStringCbCatA(ArcFileName, sizeof(ArcFileName), File);
545+
546+
NtLdrOutputLoadMsg(ArcFileName, NULL);
547+
Success = PeLdrLoadImage(ArcFileName, MemoryType, &BaseAddress);
535548
if (!Success)
536549
{
537550
ERR("PeLdrLoadImage('%s') failed\n", File);
@@ -547,7 +560,7 @@ LoadModule(
547560
if (!Success)
548561
{
549562
/* Cleanup and bail out */
550-
ERR("PeLdrAllocateDataTableEntry('%s') failed\n", FullFileName);
563+
ERR("PeLdrAllocateDataTableEntry('%s') failed\n", ArcFileName);
551564
MmFreeMemory(BaseAddress);
552565
return NULL;
553566
}
@@ -626,6 +639,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
626639
ULONG OptionLength;
627640
PVOID KernelBase, HalBase, KdDllBase = NULL;
628641
PLDR_DATA_TABLE_ENTRY HalDTE, KdDllDTE = NULL;
642+
CHAR ArcPath[MAX_PATH];
629643
CHAR DirPath[MAX_PATH];
630644
CHAR HalFileName[MAX_PATH];
631645
CHAR KernelFileName[MAX_PATH];
@@ -634,8 +648,11 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
634648
if (!KernelDTE) return FALSE;
635649

636650
/* Initialize SystemRoot\System32 path */
637-
RtlStringCbCopyA(DirPath, sizeof(DirPath), BootPath);
638-
RtlStringCbCatA(DirPath, sizeof(DirPath), "system32\\");
651+
RtlStringCbCopyA(DirPath, sizeof(DirPath), "\\SystemRoot\\system32\\");
652+
653+
/* Initialize SystemRoot\System32 arc path */
654+
RtlStringCbCopyA(ArcPath, sizeof(ArcPath), BootPath);
655+
RtlStringCbCatA(ArcPath, sizeof(ArcPath), "system32\\");
639656

640657
/* Parse the boot options */
641658
TRACE("LoadWindowsCore: BootOptions '%s'\n", BootOptions);
@@ -758,7 +775,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
758775
*/
759776

760777
/* Load the Kernel */
761-
KernelBase = LoadModule(LoaderBlock, DirPath, KernelFileName,
778+
KernelBase = LoadModule(LoaderBlock, DirPath, ArcPath, KernelFileName,
762779
"ntoskrnl.exe", LoaderSystemCode, KernelDTE, 30);
763780
if (!KernelBase)
764781
{
@@ -768,7 +785,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
768785
}
769786

770787
/* Load the HAL */
771-
HalBase = LoadModule(LoaderBlock, DirPath, HalFileName,
788+
HalBase = LoadModule(LoaderBlock, DirPath, ArcPath, HalFileName,
772789
"hal.dll", LoaderHalCode, &HalDTE, 35);
773790
if (!HalBase)
774791
{
@@ -843,7 +860,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
843860
_strlwr(KdDllName);
844861

845862
/* Load the KD DLL. Override its base DLL name to the default "KDCOM.DLL". */
846-
KdDllBase = LoadModule(LoaderBlock, DirPath, KdDllName,
863+
KdDllBase = LoadModule(LoaderBlock, DirPath, ArcPath, KdDllName,
847864
"kdcom.dll", LoaderSystemCode, &KdDllDTE, 40);
848865
if (!KdDllBase)
849866
{
@@ -856,7 +873,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
856873
IsCustomKdDll = FALSE;
857874
RtlStringCbCopyA(KdDllName, sizeof(KdDllName), "kdcom.dll");
858875

859-
KdDllBase = LoadModule(LoaderBlock, DirPath, KdDllName,
876+
KdDllBase = LoadModule(LoaderBlock, DirPath, ArcPath, KdDllName,
860877
"kdcom.dll", LoaderSystemCode, &KdDllDTE, 40);
861878
}
862879

@@ -870,21 +887,21 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
870887
}
871888

872889
/* Load all referenced DLLs for Kernel, HAL and Kernel Debugger Transport DLL */
873-
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, *KernelDTE);
890+
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, ArcPath, *KernelDTE);
874891
if (!Success)
875892
{
876893
UiMessageBox("Could not load %s", KernelFileName);
877894
goto Quit;
878895
}
879-
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, HalDTE);
896+
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, ArcPath, HalDTE);
880897
if (!Success)
881898
{
882899
UiMessageBox("Could not load %s", HalFileName);
883900
goto Quit;
884901
}
885902
if (KdDllDTE)
886903
{
887-
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, KdDllDTE);
904+
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, ArcPath, KdDllDTE);
888905
if (!Success)
889906
{
890907
UiMessageBox("Could not load %s", KdDllName);

0 commit comments

Comments
 (0)