Skip to content

Commit 937011e

Browse files
committed
[FREELDR] Fix tcpip.sys issue
1 parent 9eb2d61 commit 937011e

File tree

4 files changed

+54
-25
lines changed

4 files changed

+54
-25
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: 18 additions & 4 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)
407416
PeLdrImportDllLoadCallback(FullDllName);
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: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ NtLdrOutputLoadMsg(
7575
VOID WinLdrSetOperatingSystemVersion(
7676
IN ULONG VersionToBoot)
7777
{
78+
WinLdrSystemBlock->OsVersion = VersionToBoot;
79+
7880
if (VersionToBoot >= _WIN32_WINNT_WIN7)
7981
{
8082
WinLdrSystemBlock->LoaderBlockWin7.OsMajorVersion = (VersionToBoot & 0xFF00) >> 8;
@@ -124,7 +126,7 @@ AllocateAndInitLPB(
124126
RtlZeroMemory(WinLdrSystemBlock, sizeof(LOADER_SYSTEM_BLOCK));
125127

126128
LoaderBlock = (PCHAR)&WinLdrSystemBlock->LoaderBlockVista;
127-
*(PULONG)LoaderBlock = VersionToBoot;
129+
WinLdrSystemBlock->OsVersion = VersionToBoot;
128130

129131
if (VersionToBoot >= _WIN32_WINNT_WIN7)
130132
{
@@ -375,6 +377,8 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
375377
PLDR_DATA_TABLE_ENTRY *DriverDTE)
376378
{
377379
CHAR FullPath[1024];
380+
CHAR FullFileName[1024];
381+
CHAR ArcPath[1024];
378382
CHAR DriverPath[1024];
379383
CHAR DllName[1024];
380384
PCHAR DriverNamePos;
@@ -410,20 +414,21 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
410414
}
411415

412416
// It's not loaded, we have to load it
413-
RtlStringCbPrintfA(FullPath, sizeof(FullPath), "%s%wZ", BootPath, FilePath);
417+
RtlStringCbPrintfA(ArcPath, sizeof(ArcPath), "%s%wZ", BootPath, FilePath);
414418

415-
NtLdrOutputLoadMsg(FullPath, NULL);
416-
Success = PeLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase);
419+
NtLdrOutputLoadMsg(ArcPath, NULL);
420+
Success = PeLdrLoadImage(ArcPath, LoaderBootDriver, &DriverBase);
417421
if (!Success)
418422
{
419423
ERR("PeLdrLoadImage('%s') failed\n", DllName);
420424
return FALSE;
421425
}
422426

423427
// Allocate a DTE for it
428+
RtlStringCbPrintfA(FullFileName, sizeof(FullFileName), "\\SystemRoot\\%s%s", DriverPath, DllName);
424429
Success = PeLdrAllocateDataTableEntry(LoadOrderListHead,
425430
DllName,
426-
DllName,
431+
FullFileName,
427432
PaToVa(DriverBase),
428433
DriverDTE);
429434
if (!Success)
@@ -441,8 +446,9 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
441446
(*DriverDTE)->Flags |= Flags;
442447

443448
// Look for any dependencies it may have, and load them too
444-
RtlStringCbPrintfA(FullPath, sizeof(FullPath), "%s%s", BootPath, DriverPath);
445-
Success = PeLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, *DriverDTE);
449+
RtlStringCbPrintfA(ArcPath, sizeof(ArcPath), "%s%s", BootPath, DriverPath);
450+
RtlStringCbPrintfA(FullPath, sizeof(FullPath), "\\SystemRoot\\%s", DriverPath);
451+
Success = PeLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, ArcPath, *DriverDTE);
446452
if (!Success)
447453
{
448454
/* Cleanup and bail out */
@@ -596,6 +602,7 @@ PVOID
596602
LoadModule(
597603
IN OUT PLOADER_PARAMETER_BLOCK1 LoaderBlock1,
598604
IN PCCH Path,
605+
IN PCCH ArcPath,
599606
IN PCCH File,
600607
IN PCCH ImportName, // BaseDllName
601608
IN TYPE_OF_MEMORY MemoryType,
@@ -604,6 +611,7 @@ LoadModule(
604611
{
605612
BOOLEAN Success;
606613
CHAR FullFileName[MAX_PATH];
614+
CHAR ArcFileName[MAX_PATH];
607615
CHAR ProgressString[256];
608616
PVOID BaseAddress;
609617

@@ -613,8 +621,11 @@ LoadModule(
613621
RtlStringCbCopyA(FullFileName, sizeof(FullFileName), Path);
614622
RtlStringCbCatA(FullFileName, sizeof(FullFileName), File);
615623

616-
NtLdrOutputLoadMsg(FullFileName, NULL);
617-
Success = PeLdrLoadImage(FullFileName, MemoryType, &BaseAddress);
624+
RtlStringCbCopyA(ArcFileName, sizeof(ArcFileName), ArcPath);
625+
RtlStringCbCatA(ArcFileName, sizeof(ArcFileName), File);
626+
627+
NtLdrOutputLoadMsg(ArcFileName, NULL);
628+
Success = PeLdrLoadImage(ArcFileName, MemoryType, &BaseAddress);
618629
if (!Success)
619630
{
620631
ERR("PeLdrLoadImage('%s') failed\n", File);
@@ -630,7 +641,7 @@ LoadModule(
630641
if (!Success)
631642
{
632643
/* Cleanup and bail out */
633-
ERR("PeLdrAllocateDataTableEntry('%s') failed\n", FullFileName);
644+
ERR("PeLdrAllocateDataTableEntry('%s') failed\n", ArcFileName);
634645
MmFreeMemory(BaseAddress);
635646
return NULL;
636647
}
@@ -709,6 +720,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
709720
ULONG OptionLength;
710721
PVOID KernelBase, HalBase, KdDllBase = NULL;
711722
PLDR_DATA_TABLE_ENTRY HalDTE, KdDllDTE = NULL;
723+
CHAR ArcPath[MAX_PATH];
712724
CHAR DirPath[MAX_PATH];
713725
CHAR HalFileName[MAX_PATH];
714726
CHAR KernelFileName[MAX_PATH];
@@ -717,8 +729,11 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
717729
if (!KernelDTE) return FALSE;
718730

719731
/* Initialize SystemRoot\System32 path */
720-
RtlStringCbCopyA(DirPath, sizeof(DirPath), BootPath);
721-
RtlStringCbCatA(DirPath, sizeof(DirPath), "system32\\");
732+
RtlStringCbCopyA(DirPath, sizeof(DirPath), "\\SystemRoot\\system32\\");
733+
734+
/* Initialize SystemRoot\System32 arc path */
735+
RtlStringCbCopyA(ArcPath, sizeof(ArcPath), BootPath);
736+
RtlStringCbCatA(ArcPath, sizeof(ArcPath), "system32\\");
722737

723738
/* Parse the boot options */
724739
TRACE("LoadWindowsCore: BootOptions '%s'\n", BootOptions);
@@ -841,7 +856,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
841856
*/
842857

843858
/* Load the Kernel */
844-
KernelBase = LoadModule(LoaderBlock1, DirPath, KernelFileName,
859+
KernelBase = LoadModule(LoaderBlock1, DirPath, ArcPath, KernelFileName,
845860
"ntoskrnl.exe", LoaderSystemCode, KernelDTE, 30);
846861
if (!KernelBase)
847862
{
@@ -851,7 +866,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
851866
}
852867

853868
/* Load the HAL */
854-
HalBase = LoadModule(LoaderBlock1, DirPath, HalFileName,
869+
HalBase = LoadModule(LoaderBlock1, DirPath, ArcPath, HalFileName,
855870
"hal.dll", LoaderHalCode, &HalDTE, 35);
856871
if (!HalBase)
857872
{
@@ -926,7 +941,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
926941
_strlwr(KdDllName);
927942

928943
/* Load the KD DLL. Override its base DLL name to the default "KDCOM.DLL". */
929-
KdDllBase = LoadModule(LoaderBlock1, DirPath, KdDllName,
944+
KdDllBase = LoadModule(LoaderBlock1, DirPath, ArcPath, KdDllName,
930945
"kdcom.dll", LoaderSystemCode, &KdDllDTE, 40);
931946
if (!KdDllBase)
932947
{
@@ -939,7 +954,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
939954
IsCustomKdDll = FALSE;
940955
RtlStringCbCopyA(KdDllName, sizeof(KdDllName), "kdcom.dll");
941956

942-
KdDllBase = LoadModule(LoaderBlock1, DirPath, KdDllName,
957+
KdDllBase = LoadModule(LoaderBlock1, DirPath, ArcPath, KdDllName,
943958
"kdcom.dll", LoaderSystemCode, &KdDllDTE, 40);
944959
}
945960

@@ -953,21 +968,21 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
953968
}
954969

955970
/* Load all referenced DLLs for Kernel, HAL and Kernel Debugger Transport DLL */
956-
Success = PeLdrScanImportDescriptorTable(&LoaderBlock1->LoadOrderListHead, DirPath, *KernelDTE);
971+
Success = PeLdrScanImportDescriptorTable(&LoaderBlock1->LoadOrderListHead, DirPath, ArcPath, *KernelDTE);
957972
if (!Success)
958973
{
959974
UiMessageBox("Could not load %s", KernelFileName);
960975
goto Quit;
961976
}
962-
Success = PeLdrScanImportDescriptorTable(&LoaderBlock1->LoadOrderListHead, DirPath, HalDTE);
977+
Success = PeLdrScanImportDescriptorTable(&LoaderBlock1->LoadOrderListHead, DirPath, ArcPath, HalDTE);
963978
if (!Success)
964979
{
965980
UiMessageBox("Could not load %s", HalFileName);
966981
goto Quit;
967982
}
968983
if (KdDllDTE)
969984
{
970-
Success = PeLdrScanImportDescriptorTable(&LoaderBlock1->LoadOrderListHead, DirPath, KdDllDTE);
985+
Success = PeLdrScanImportDescriptorTable(&LoaderBlock1->LoadOrderListHead, DirPath, ArcPath, KdDllDTE);
971986
if (!Success)
972987
{
973988
UiMessageBox("Could not load %s", KdDllName);

boot/freeldr/freeldr/ntldr/winldr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ typedef struct _LOADER_PARAMETER_BLOCK2
8181

8282
typedef struct _LOADER_PARAMETER_BLOCK_VISTA
8383
{
84-
ULONG OsVersion;
8584
LOADER_PARAMETER_BLOCK1 Block1;
8685
PSETUP_LOADER_BLOCK SetupLdrBlock;
8786
LOADER_PARAMETER_BLOCK2 Block2;
8887
} LOADER_PARAMETER_BLOCK_VISTA, *PLOADER_PARAMETER_BLOCK_VISTA;
8988

9089
typedef struct _LOADER_PARAMETER_BLOCK_WIN7
9190
{
92-
ULONG OsVersion;
9391
ULONG OsMajorVersion;
9492
ULONG OsMinorVersion;
9593
ULONG Size;
@@ -183,6 +181,7 @@ typedef struct _LOADER_SYSTEM_BLOCK
183181
LOADER_PARAMETER_EXTENSION_VISTA ExtensionVista;
184182
LOADER_PARAMETER_EXTENSION_WIN7 ExtensionWin7;
185183
};
184+
ULONG OsVersion;
186185
PLOADER_PARAMETER_BLOCK1 LoaderBlock1;
187186
PLOADER_PARAMETER_BLOCK2 LoaderBlock2;
188187
PLOADER_PARAMETER_EXTENSION1 Extension1;

0 commit comments

Comments
 (0)