Skip to content

Commit bc86131

Browse files
committed
[FREELDR] Change the DTE path prefix to \SystemRoot\ for NT6.1+ compatibility
1 parent 70732b0 commit bc86131

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed

boot/freeldr/freeldr/include/peloader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ BOOLEAN
5959
PeLdrScanImportDescriptorTable(
6060
IN OUT PLIST_ENTRY ModuleListHead,
6161
IN PCCH DirectoryPath,
62+
IN PCCH ArcPath,
6263
IN PLDR_DATA_TABLE_ENTRY ScanDTE);
6364

6465
BOOLEAN

boot/freeldr/freeldr/lib/peloader.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static BOOLEAN
130130
PeLdrpLoadAndScanReferencedDll(
131131
IN OUT PLIST_ENTRY ModuleListHead,
132132
IN PCCH DirectoryPath,
133+
IN PCCH ArcPath,
133134
IN PCH ImportName,
134135
IN PLIST_ENTRY Parent OPTIONAL,
135136
OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry);
@@ -145,6 +146,7 @@ PeLdrpBindImportName(
145146
_In_ ULONG ExportSize,
146147
_In_ BOOLEAN ProcessForwards,
147148
_In_ PCSTR DirectoryPath,
149+
_In_ PCSTR ArcPath,
148150
_In_ PLIST_ENTRY Parent)
149151
{
150152
ULONG Ordinal;
@@ -316,6 +318,7 @@ PeLdrpBindImportName(
316318
/* Now let's try to load it! */
317319
Success = PeLdrpLoadAndScanReferencedDll(ModuleListHead,
318320
DirectoryPath,
321+
ArcPath,
319322
ForwardDllName,
320323
Parent,
321324
&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

@@ -437,7 +446,7 @@ PeLdrpLoadAndScanReferencedDll(
437446
TRACE("PeLdrScanImportDescriptorTable() calling ourselves for '%.*S'\n",
438447
(*DataTableEntry)->BaseDllName.Length / sizeof(WCHAR),
439448
VaToPa((*DataTableEntry)->BaseDllName.Buffer));
440-
Success = PeLdrScanImportDescriptorTable(ModuleListHead, DirectoryPath, *DataTableEntry);
449+
Success = PeLdrScanImportDescriptorTable(ModuleListHead, DirectoryPath, ArcPath, *DataTableEntry);
441450
if (!Success)
442451
{
443452
/* Cleanup and bail out */
@@ -458,6 +467,7 @@ PeLdrpScanImportAddressTable(
458467
_In_ PIMAGE_THUNK_DATA ThunkName,
459468
_Inout_ PIMAGE_THUNK_DATA ThunkData,
460469
_In_ PCSTR DirectoryPath,
470+
_In_ PCSTR ArcPath,
461471
_In_ PLIST_ENTRY Parent)
462472
{
463473
PIMAGE_EXPORT_DIRECTORY ExportDirectory = NULL;
@@ -504,6 +514,7 @@ PeLdrpScanImportAddressTable(
504514
ExportSize,
505515
FALSE,
506516
DirectoryPath,
517+
ArcPath,
507518
Parent);
508519
/* Fail if binding was unsuccessful */
509520
if (!Success)
@@ -629,6 +640,7 @@ BOOLEAN
629640
PeLdrScanImportDescriptorTable(
630641
IN OUT PLIST_ENTRY ModuleListHead,
631642
IN PCCH DirectoryPath,
643+
IN PCCH ArcPath,
632644
IN PLDR_DATA_TABLE_ENTRY ScanDTE)
633645
{
634646
PLDR_DATA_TABLE_ENTRY DataTableEntry;
@@ -675,6 +687,7 @@ PeLdrScanImportDescriptorTable(
675687
{
676688
Success = PeLdrpLoadAndScanReferencedDll(ModuleListHead,
677689
DirectoryPath,
690+
ArcPath,
678691
ImportName,
679692
&ScanDTE->InLoadOrderLinks,
680693
&DataTableEntry);
@@ -692,6 +705,7 @@ PeLdrScanImportDescriptorTable(
692705
ThunkName,
693706
ThunkData,
694707
DirectoryPath,
708+
ArcPath,
695709
&ScanDTE->InLoadOrderLinks);
696710

697711
if (!Success)
@@ -1083,7 +1097,7 @@ PeLdrLoadBootImage(
10831097
}
10841098

10851099
/* Resolve imports */
1086-
Success = PeLdrScanImportDescriptorTable(&FrLdrModuleList, "", *DataTableEntry);
1100+
Success = PeLdrScanImportDescriptorTable(&FrLdrModuleList, "", "", *DataTableEntry);
10871101
if (!Success)
10881102
{
10891103
/* Cleanup and bail out */

boot/freeldr/freeldr/ntldr/winldr.c

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
295295
PLDR_DATA_TABLE_ENTRY *DriverDTE)
296296
{
297297
CHAR FullPath[1024];
298+
CHAR FullFileName[1024];
299+
CHAR ArcPath[1024];
298300
CHAR DriverPath[1024];
299301
CHAR DllName[1024];
300302
PCHAR DriverNamePos;
@@ -330,20 +332,21 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
330332
}
331333

332334
// It's not loaded, we have to load it
333-
RtlStringCbPrintfA(FullPath, sizeof(FullPath), "%s%wZ", BootPath, FilePath);
335+
RtlStringCbPrintfA(ArcPath, sizeof(ArcPath), "%s%wZ", BootPath, FilePath);
334336

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

343345
// Allocate a DTE for it
346+
RtlStringCbPrintfA(FullFileName, sizeof(FullFileName), "\\SystemRoot\\%s%s", DriverPath, DllName);
344347
Success = PeLdrAllocateDataTableEntry(LoadOrderListHead,
345348
DllName,
346-
DllName,
349+
FullFileName,
347350
PaToVa(DriverBase),
348351
DriverDTE);
349352
if (!Success)
@@ -361,8 +364,9 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
361364
(*DriverDTE)->Flags |= Flags;
362365

363366
// Look for any dependencies it may have, and load them too
364-
RtlStringCbPrintfA(FullPath, sizeof(FullPath), "%s%s", BootPath, DriverPath);
365-
Success = PeLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, *DriverDTE);
367+
RtlStringCbPrintfA(ArcPath, sizeof(ArcPath), "%s%s", BootPath, DriverPath);
368+
RtlStringCbPrintfA(FullPath, sizeof(FullPath), "\\SystemRoot\\%s", DriverPath);
369+
Success = PeLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, ArcPath, *DriverDTE);
366370
if (!Success)
367371
{
368372
/* Cleanup and bail out */
@@ -516,6 +520,7 @@ PVOID
516520
LoadModule(
517521
IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
518522
IN PCCH Path,
523+
IN PCCH ArcPath,
519524
IN PCCH File,
520525
IN PCCH ImportName, // BaseDllName
521526
IN TYPE_OF_MEMORY MemoryType,
@@ -524,6 +529,7 @@ LoadModule(
524529
{
525530
BOOLEAN Success;
526531
CHAR FullFileName[MAX_PATH];
532+
CHAR ArcFileName[MAX_PATH];
527533
CHAR ProgressString[256];
528534
PVOID BaseAddress;
529535

@@ -533,8 +539,11 @@ LoadModule(
533539
RtlStringCbCopyA(FullFileName, sizeof(FullFileName), Path);
534540
RtlStringCbCatA(FullFileName, sizeof(FullFileName), File);
535541

536-
NtLdrOutputLoadMsg(FullFileName, NULL);
537-
Success = PeLdrLoadImage(FullFileName, MemoryType, &BaseAddress);
542+
RtlStringCbCopyA(ArcFileName, sizeof(ArcFileName), ArcPath);
543+
RtlStringCbCatA(ArcFileName, sizeof(ArcFileName), File);
544+
545+
NtLdrOutputLoadMsg(ArcFileName, NULL);
546+
Success = PeLdrLoadImage(ArcFileName, MemoryType, &BaseAddress);
538547
if (!Success)
539548
{
540549
ERR("PeLdrLoadImage('%s') failed\n", File);
@@ -550,7 +559,7 @@ LoadModule(
550559
if (!Success)
551560
{
552561
/* Cleanup and bail out */
553-
ERR("PeLdrAllocateDataTableEntry('%s') failed\n", FullFileName);
562+
ERR("PeLdrAllocateDataTableEntry('%s') failed\n", ArcFileName);
554563
MmFreeMemory(BaseAddress);
555564
return NULL;
556565
}
@@ -629,6 +638,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
629638
ULONG OptionLength;
630639
PVOID KernelBase, HalBase, KdDllBase = NULL;
631640
PLDR_DATA_TABLE_ENTRY HalDTE, KdDllDTE = NULL;
641+
CHAR ArcPath[MAX_PATH];
632642
CHAR DirPath[MAX_PATH];
633643
CHAR HalFileName[MAX_PATH];
634644
CHAR KernelFileName[MAX_PATH];
@@ -637,8 +647,11 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
637647
if (!KernelDTE) return FALSE;
638648

639649
/* Initialize SystemRoot\System32 path */
640-
RtlStringCbCopyA(DirPath, sizeof(DirPath), BootPath);
641-
RtlStringCbCatA(DirPath, sizeof(DirPath), "system32\\");
650+
RtlStringCbCopyA(DirPath, sizeof(DirPath), "\\SystemRoot\\system32\\");
651+
652+
/* Initialize SystemRoot\System32 arc path */
653+
RtlStringCbCopyA(ArcPath, sizeof(ArcPath), BootPath);
654+
RtlStringCbCatA(ArcPath, sizeof(ArcPath), "system32\\");
642655

643656
/* Parse the boot options */
644657
TRACE("LoadWindowsCore: BootOptions '%s'\n", BootOptions);
@@ -761,7 +774,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
761774
*/
762775

763776
/* Load the Kernel */
764-
KernelBase = LoadModule(LoaderBlock, DirPath, KernelFileName,
777+
KernelBase = LoadModule(LoaderBlock, DirPath, ArcPath, KernelFileName,
765778
"ntoskrnl.exe", LoaderSystemCode, KernelDTE, 30);
766779
if (!KernelBase)
767780
{
@@ -771,7 +784,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
771784
}
772785

773786
/* Load the HAL */
774-
HalBase = LoadModule(LoaderBlock, DirPath, HalFileName,
787+
HalBase = LoadModule(LoaderBlock, DirPath, ArcPath, HalFileName,
775788
"hal.dll", LoaderHalCode, &HalDTE, 35);
776789
if (!HalBase)
777790
{
@@ -846,7 +859,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
846859
_strlwr(KdDllName);
847860

848861
/* Load the KD DLL. Override its base DLL name to the default "KDCOM.DLL". */
849-
KdDllBase = LoadModule(LoaderBlock, DirPath, KdDllName,
862+
KdDllBase = LoadModule(LoaderBlock, DirPath, ArcPath, KdDllName,
850863
"kdcom.dll", LoaderSystemCode, &KdDllDTE, 40);
851864
if (!KdDllBase)
852865
{
@@ -859,7 +872,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
859872
IsCustomKdDll = FALSE;
860873
RtlStringCbCopyA(KdDllName, sizeof(KdDllName), "kdcom.dll");
861874

862-
KdDllBase = LoadModule(LoaderBlock, DirPath, KdDllName,
875+
KdDllBase = LoadModule(LoaderBlock, DirPath, ArcPath, KdDllName,
863876
"kdcom.dll", LoaderSystemCode, &KdDllDTE, 40);
864877
}
865878

@@ -873,21 +886,21 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
873886
}
874887

875888
/* Load all referenced DLLs for Kernel, HAL and Kernel Debugger Transport DLL */
876-
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, *KernelDTE);
889+
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, ArcPath, *KernelDTE);
877890
if (!Success)
878891
{
879892
UiMessageBox("Could not load %s", KernelFileName);
880893
goto Quit;
881894
}
882-
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, HalDTE);
895+
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, ArcPath, HalDTE);
883896
if (!Success)
884897
{
885898
UiMessageBox("Could not load %s", HalFileName);
886899
goto Quit;
887900
}
888901
if (KdDllDTE)
889902
{
890-
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, KdDllDTE);
903+
Success = PeLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, ArcPath, KdDllDTE);
891904
if (!Success)
892905
{
893906
UiMessageBox("Could not load %s", KdDllName);

0 commit comments

Comments
 (0)