mirror of
https://github.com/reactos/reactos.git
synced 2025-06-20 07:36:05 +00:00
[USETUP]: Improve the bootsector validity check performed in IsThereAValidBootSector:
- Check for the first 3 bytes (and not 4) of the bootsector to not be zero (that's our criterium for a "valid instruction"). Therefore, a bootsector starting with "00 00 00 xx" (with xx the first byte of a volume identifier) is detected as invalid (because the BIOS won't be able to run it anyways) and therefore, needs to be overwritten. - Check that its last 2 bytes are the valid 0xAA55 signature. These improvements were suggested by Serge Gautherie and Peter Hater. CORE-4870 CORE-12672 CORE-13188 - Move a DPRINT1 around. svn path=/trunk/; revision=74512
This commit is contained in:
parent
16e06b89aa
commit
f06734e55d
2 changed files with 22 additions and 18 deletions
|
@ -630,12 +630,14 @@ BOOLEAN
|
||||||
IsThereAValidBootSector(PWSTR RootPath)
|
IsThereAValidBootSector(PWSTR RootPath)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Check the first DWORD (4 bytes) of the bootsector for a potential
|
* We first demand that the bootsector has a valid signature at its end.
|
||||||
* "valid" instruction (the BIOS starts execution of the bootsector
|
* We then check the first 3 bytes (as a ULONG) of the bootsector for a
|
||||||
* at its beginning). Currently the criterium is that this DWORD must
|
* potential "valid" instruction (the BIOS starts execution of the bootsector
|
||||||
* be non-zero.
|
* at its beginning). Currently this criterium is that this ULONG must be
|
||||||
|
* non-zero. If both these tests pass, then the bootsector is valid; otherwise
|
||||||
|
* it is invalid and certainly needs to be overwritten.
|
||||||
*/
|
*/
|
||||||
|
BOOLEAN IsValid = FALSE;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
UNICODE_STRING Name;
|
UNICODE_STRING Name;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
@ -666,10 +668,9 @@ IsThereAValidBootSector(PWSTR RootPath)
|
||||||
0,
|
0,
|
||||||
FILE_SYNCHRONOUS_IO_NONALERT);
|
FILE_SYNCHRONOUS_IO_NONALERT);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
goto Quit;
|
||||||
RtlFreeHeap(ProcessHeap, 0, BootSector);
|
|
||||||
return FALSE; // Status;
|
RtlZeroMemory(BootSector, SECTORSIZE);
|
||||||
}
|
|
||||||
|
|
||||||
FileOffset.QuadPart = 0ULL;
|
FileOffset.QuadPart = 0ULL;
|
||||||
Status = NtReadFile(FileHandle,
|
Status = NtReadFile(FileHandle,
|
||||||
|
@ -682,16 +683,20 @@ IsThereAValidBootSector(PWSTR RootPath)
|
||||||
&FileOffset,
|
&FileOffset,
|
||||||
NULL);
|
NULL);
|
||||||
NtClose(FileHandle);
|
NtClose(FileHandle);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
goto Quit;
|
||||||
|
|
||||||
Instruction = *(PULONG)BootSector;
|
/* Check the instruction; we use a ULONG to read three bytes */
|
||||||
|
Instruction = (*(PULONG)BootSector) & 0x00FFFFFF;
|
||||||
|
IsValid = (Instruction != 0x00000000);
|
||||||
|
|
||||||
|
/* Check the bootsector signature */
|
||||||
|
IsValid &= (*(PUSHORT)(BootSector + 0x1fe) == 0xaa55);
|
||||||
|
|
||||||
|
Quit:
|
||||||
/* Free the boot sector */
|
/* Free the boot sector */
|
||||||
RtlFreeHeap(ProcessHeap, 0, BootSector);
|
RtlFreeHeap(ProcessHeap, 0, BootSector);
|
||||||
|
return IsValid; // Status;
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
return FALSE; // Status;
|
|
||||||
|
|
||||||
return (Instruction != 0x00000000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
|
|
@ -4442,9 +4442,6 @@ BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir)
|
||||||
wcscpy(SourceMbrPathBuffer, SourceRootPath.Buffer);
|
wcscpy(SourceMbrPathBuffer, SourceRootPath.Buffer);
|
||||||
wcscat(SourceMbrPathBuffer, L"\\loader\\dosmbr.bin");
|
wcscat(SourceMbrPathBuffer, L"\\loader\\dosmbr.bin");
|
||||||
|
|
||||||
DPRINT1("Install MBR bootcode: %S ==> %S\n",
|
|
||||||
SourceMbrPathBuffer, DestinationDevicePathBuffer);
|
|
||||||
|
|
||||||
if (IsThereAValidBootSector(DestinationDevicePathBuffer))
|
if (IsThereAValidBootSector(DestinationDevicePathBuffer))
|
||||||
{
|
{
|
||||||
/* Save current MBR */
|
/* Save current MBR */
|
||||||
|
@ -4460,6 +4457,8 @@ BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DPRINT1("Install MBR bootcode: %S ==> %S\n",
|
||||||
|
SourceMbrPathBuffer, DestinationDevicePathBuffer);
|
||||||
Status = InstallMbrBootCodeToDisk(SourceMbrPathBuffer,
|
Status = InstallMbrBootCodeToDisk(SourceMbrPathBuffer,
|
||||||
DestinationDevicePathBuffer);
|
DestinationDevicePathBuffer);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue