From 563d9f26c4ab04145ae5cf9054e125d9c40b5c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Wed, 31 May 2017 01:11:05 +0000 Subject: [PATCH] [SETUPLIB] Adjustments in the code. - Call OpenAndMapFile() with its new ReadWrite parameter; - Add informative comments in osdetect.c; - In partlist.c, check whether a disk has a valid MBR by also checking for its 0xAA55 signature. svn path=/branches/setup_improvements/; revision=74712 --- base/setup/lib/bldrsup.c | 4 ++-- base/setup/lib/osdetect.c | 13 ++++++++++++- base/setup/lib/partlist.c | 9 ++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/base/setup/lib/bldrsup.c b/base/setup/lib/bldrsup.c index 493c52237e7..13a1ed34e87 100644 --- a/base/setup/lib/bldrsup.c +++ b/base/setup/lib/bldrsup.c @@ -89,7 +89,7 @@ FindNTOSBootLoader( // By handle #if 0 /* Check whether the loader configuration file exists */ Status = OpenAndMapFile(PartitionHandle, NtosBootLoaders[Type].LoaderConfigurationFile, - &FileHandle, &SectionHandle, &ViewBase, &FileSize); + &FileHandle, &SectionHandle, &ViewBase, &FileSize, FALSE); if (!NT_SUCCESS(Status)) { /* The loader does not exist, continue with another one */ @@ -314,7 +314,7 @@ EnumerateNTOSBootEntries( /* Check whether the loader configuration file exists */ Status = OpenAndMapFile(PartitionHandle, NtosBootLoaders[Type].LoaderConfigurationFile, - &FileHandle, &SectionHandle, &ViewBase, &FileSize); + &FileHandle, &SectionHandle, &ViewBase, &FileSize, FALSE); if (!NT_SUCCESS(Status)) { /* The loader does not exist, continue with another one */ diff --git a/base/setup/lib/osdetect.c b/base/setup/lib/osdetect.c index 20611bdc02e..6b16e5624d3 100644 --- a/base/setup/lib/osdetect.c +++ b/base/setup/lib/osdetect.c @@ -150,6 +150,8 @@ EnumerateInstallations( { /* This is not a ReactOS entry */ /* Certainly not a ReactOS installation */ + DPRINT1(" A Win2k3 install '%wZ' without an ARC path?!\n", &InstallName); + /* Continue the enumeration */ return STATUS_SUCCESS; } } @@ -171,6 +173,7 @@ EnumerateInstallations( { DPRINT1(" An NTOS installation with name \"%S\" already exists in SystemRoot '%wZ'\n", NtOsInstall->InstallationName, &NtOsInstall->SystemArcPath); + /* Continue the enumeration */ return STATUS_SUCCESS; } @@ -183,6 +186,7 @@ EnumerateInstallations( if (!ArcPathToNtPath(&SystemRootPath, BootEntry->OsLoadPath, Data->PartList)) { DPRINT1("ArcPathToNtPath(%S) failed, skip the installation.\n", BootEntry->OsLoadPath); + /* Continue the enumeration */ return STATUS_SUCCESS; } @@ -198,6 +202,7 @@ EnumerateInstallations( { DPRINT1(" An NTOS installation with name \"%S\" already exists in SystemRoot '%wZ'\n", NtOsInstall->InstallationName, &NtOsInstall->SystemNtPath); + /* Continue the enumeration */ return STATUS_SUCCESS; } @@ -205,7 +210,10 @@ EnumerateInstallations( /* Check if this is a valid NTOS installation; stop there if it isn't one */ if (!IsValidNTOSInstallation_UStr(&SystemRootPath)) + { + /* Continue the enumeration */ return STATUS_SUCCESS; + } DPRINT1("Found a valid NTOS installation in SystemRoot ARC path '%S', NT path '%wZ'\n", BootEntry->OsLoadPath, &SystemRootPath); @@ -228,6 +236,7 @@ EnumerateInstallations( DPRINT1("NtPathToDiskPartComponents(%wZ) failed\n", &SystemRootPath); } + /* Add the discovered NTOS installation into the list */ if (PartEntry && PartEntry->DriveLetter) { /* We have retrieved a partition that is mounted */ @@ -245,6 +254,7 @@ EnumerateInstallations( DiskNumber, PartitionNumber, PartEntry, InstallNameW); + /* Continue the enumeration */ return STATUS_SUCCESS; } @@ -301,7 +311,8 @@ CheckForValidPEAndVendor( VendorName->Length = 0; Status = OpenAndMapFile(RootDirectory, PathNameToFile, - &FileHandle, &SectionHandle, &ViewBase, NULL); + &FileHandle, &SectionHandle, &ViewBase, + NULL, FALSE); if (!NT_SUCCESS(Status)) { DPRINT1("Failed to open and map file '%S', Status 0x%08lx\n", PathNameToFile, Status); diff --git a/base/setup/lib/partlist.c b/base/setup/lib/partlist.c index 7b74cda8f0f..f29b2859a6a 100644 --- a/base/setup/lib/partlist.c +++ b/base/setup/lib/partlist.c @@ -989,9 +989,12 @@ AddDiskToList( // DiskEntry->Signature = Signature; DiskEntry->BiosFound = FALSE; - /* Check if this disk has a valid MBR */ - // FIXME: Check for the MBR signature as well, etc... - if (Mbr->BootCode[0] == 0 && Mbr->BootCode[1] == 0) + /* + * Check if this disk has a valid MBR: verify its signature, + * and whether its two first bytes are a valid instruction + * (related to this, see IsThereAValidBootSector() in partlist.c). + */ + if (Mbr->Magic != 0xaa55 || (*(PUSHORT)Mbr->BootCode) == 0x0000) DiskEntry->NoMbr = TRUE; else DiskEntry->NoMbr = FALSE;