mirror of
https://github.com/reactos/reactos.git
synced 2025-05-16 15:50:24 +00:00
[SETUPLIB][USETUP] Refactor the DoesFileExist() function so that it now looks closer to DoesPathExist() and use it almost everywhere.
- Adjust also its callers, adjust OpenAndMapFile() parameters. - Related to that, simplify IsValidNTOSInstallation() parameters & introduce a IsValidNTOSInstallation_UStr() that does the same, but takes a UNICODE_STRING instead. - Simplify CheckForValidPEAndVendor(). Now only exactly 5 calls use the "old" 'DoesFileExist' syntax, using a temporarily auxiliary function "DoesFileExist_2"... svn path=/branches/setup_improvements/; revision=74641
This commit is contained in:
parent
d27ef70aab
commit
b53b7b11e3
5 changed files with 110 additions and 119 deletions
base/setup
|
@ -154,7 +154,7 @@ DoesPathExist(
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status))
|
||||||
NtClose(FileHandle);
|
NtClose(FileHandle);
|
||||||
else
|
else
|
||||||
DPRINT1("Failed to open directory %wZ, Status 0x%08lx\n", &Name, Status);
|
DPRINT1("Failed to open directory '%wZ', Status 0x%08lx\n", &Name, Status);
|
||||||
|
|
||||||
return NT_SUCCESS(Status);
|
return NT_SUCCESS(Status);
|
||||||
}
|
}
|
||||||
|
@ -162,21 +162,18 @@ DoesPathExist(
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
DoesFileExist(
|
DoesFileExist(
|
||||||
IN HANDLE RootDirectory OPTIONAL,
|
IN HANDLE RootDirectory OPTIONAL,
|
||||||
IN PCWSTR PathName OPTIONAL,
|
IN PCWSTR PathNameToFile)
|
||||||
IN PCWSTR FileName)
|
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
UNICODE_STRING FileName;
|
||||||
HANDLE FileHandle;
|
HANDLE FileHandle;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
UNICODE_STRING Name;
|
|
||||||
WCHAR FullName[MAX_PATH];
|
|
||||||
|
|
||||||
CombinePaths(FullName, ARRAYSIZE(FullName), 2, PathName, FileName);
|
RtlInitUnicodeString(&FileName, PathNameToFile);
|
||||||
RtlInitUnicodeString(&Name, FullName);
|
|
||||||
|
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&Name,
|
&FileName,
|
||||||
OBJ_CASE_INSENSITIVE,
|
OBJ_CASE_INSENSITIVE,
|
||||||
RootDirectory,
|
RootDirectory,
|
||||||
NULL);
|
NULL);
|
||||||
|
@ -190,11 +187,22 @@ DoesFileExist(
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status))
|
||||||
NtClose(FileHandle);
|
NtClose(FileHandle);
|
||||||
else
|
else
|
||||||
DPRINT1("Failed to open file %wZ, Status 0x%08lx\n", &Name, Status);
|
DPRINT1("Failed to open file '%wZ', Status 0x%08lx\n", &FileName, Status);
|
||||||
|
|
||||||
return NT_SUCCESS(Status);
|
return NT_SUCCESS(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: DEPRECATED! HACKish function that needs to be deprecated!
|
||||||
|
BOOLEAN
|
||||||
|
DoesFileExist_2(
|
||||||
|
IN PCWSTR PathName OPTIONAL,
|
||||||
|
IN PCWSTR FileName)
|
||||||
|
{
|
||||||
|
WCHAR FullName[MAX_PATH];
|
||||||
|
CombinePaths(FullName, ARRAYSIZE(FullName), 2, PathName, FileName);
|
||||||
|
return DoesFileExist(NULL, FullName);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The format of NtPath should be:
|
* The format of NtPath should be:
|
||||||
* \Device\HarddiskXXX\PartitionYYY[\path] ,
|
* \Device\HarddiskXXX\PartitionYYY[\path] ,
|
||||||
|
@ -298,26 +306,23 @@ Quit:
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
OpenAndMapFile(
|
OpenAndMapFile(
|
||||||
IN HANDLE RootDirectory OPTIONAL,
|
IN HANDLE RootDirectory OPTIONAL,
|
||||||
IN PCWSTR PathName OPTIONAL,
|
IN PCWSTR PathNameToFile,
|
||||||
IN PCWSTR FileName, // OPTIONAL
|
|
||||||
OUT PHANDLE FileHandle, // IN OUT PHANDLE OPTIONAL
|
OUT PHANDLE FileHandle, // IN OUT PHANDLE OPTIONAL
|
||||||
OUT PHANDLE SectionHandle,
|
OUT PHANDLE SectionHandle,
|
||||||
OUT PVOID* BaseAddress,
|
OUT PVOID* BaseAddress,
|
||||||
OUT PULONG FileSize OPTIONAL)
|
OUT PULONG FileSize OPTIONAL)
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
UNICODE_STRING FileName;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
SIZE_T ViewSize;
|
SIZE_T ViewSize;
|
||||||
PVOID ViewBase;
|
PVOID ViewBase;
|
||||||
UNICODE_STRING Name;
|
|
||||||
WCHAR FullName[MAX_PATH];
|
|
||||||
|
|
||||||
CombinePaths(FullName, ARRAYSIZE(FullName), 2, PathName, FileName);
|
RtlInitUnicodeString(&FileName, PathNameToFile);
|
||||||
RtlInitUnicodeString(&Name, FullName);
|
|
||||||
|
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&Name,
|
&FileName,
|
||||||
OBJ_CASE_INSENSITIVE,
|
OBJ_CASE_INSENSITIVE,
|
||||||
RootDirectory,
|
RootDirectory,
|
||||||
NULL);
|
NULL);
|
||||||
|
@ -333,7 +338,7 @@ OpenAndMapFile(
|
||||||
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
|
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to open file '%wZ', Status 0x%08lx\n", &Name, Status);
|
DPRINT1("Failed to open file '%wZ', Status 0x%08lx\n", &FileName, Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +360,7 @@ OpenAndMapFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileInfo.EndOfFile.HighPart != 0)
|
if (FileInfo.EndOfFile.HighPart != 0)
|
||||||
DPRINT1("WARNING!! The file '%wZ' is too large!\n", &Name);
|
DPRINT1("WARNING!! The file '%wZ' is too large!\n", &FileName);
|
||||||
|
|
||||||
*FileSize = FileInfo.EndOfFile.LowPart;
|
*FileSize = FileInfo.EndOfFile.LowPart;
|
||||||
|
|
||||||
|
@ -374,7 +379,7 @@ OpenAndMapFile(
|
||||||
*FileHandle);
|
*FileHandle);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to create a memory section for file '%wZ', Status 0x%08lx\n", &Name, Status);
|
DPRINT1("Failed to create a memory section for file '%wZ', Status 0x%08lx\n", &FileName, Status);
|
||||||
NtClose(*FileHandle);
|
NtClose(*FileHandle);
|
||||||
*FileHandle = NULL;
|
*FileHandle = NULL;
|
||||||
return Status;
|
return Status;
|
||||||
|
@ -394,7 +399,7 @@ OpenAndMapFile(
|
||||||
PAGE_READONLY);
|
PAGE_READONLY);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to map a view for file %wZ, Status 0x%08lx\n", &Name, Status);
|
DPRINT1("Failed to map a view for file '%wZ', Status 0x%08lx\n", &FileName, Status);
|
||||||
NtClose(*SectionHandle);
|
NtClose(*SectionHandle);
|
||||||
*SectionHandle = NULL;
|
*SectionHandle = NULL;
|
||||||
NtClose(*FileHandle);
|
NtClose(*FileHandle);
|
||||||
|
|
|
@ -51,6 +51,11 @@ DoesPathExist(
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
DoesFileExist(
|
DoesFileExist(
|
||||||
IN HANDLE RootDirectory OPTIONAL,
|
IN HANDLE RootDirectory OPTIONAL,
|
||||||
|
IN PCWSTR PathNameToFile);
|
||||||
|
|
||||||
|
// FIXME: DEPRECATED! HACKish function that needs to be deprecated!
|
||||||
|
BOOLEAN
|
||||||
|
DoesFileExist_2(
|
||||||
IN PCWSTR PathName OPTIONAL,
|
IN PCWSTR PathName OPTIONAL,
|
||||||
IN PCWSTR FileName);
|
IN PCWSTR FileName);
|
||||||
|
|
||||||
|
@ -64,8 +69,7 @@ NtPathToDiskPartComponents(
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
OpenAndMapFile(
|
OpenAndMapFile(
|
||||||
IN HANDLE RootDirectory OPTIONAL,
|
IN HANDLE RootDirectory OPTIONAL,
|
||||||
IN PCWSTR PathName OPTIONAL,
|
IN PCWSTR PathNameToFile,
|
||||||
IN PCWSTR FileName, // OPTIONAL
|
|
||||||
OUT PHANDLE FileHandle, // IN OUT PHANDLE OPTIONAL
|
OUT PHANDLE FileHandle, // IN OUT PHANDLE OPTIONAL
|
||||||
OUT PHANDLE SectionHandle,
|
OUT PHANDLE SectionHandle,
|
||||||
OUT PVOID* BaseAddress,
|
OUT PVOID* BaseAddress,
|
||||||
|
|
|
@ -105,9 +105,12 @@ NTOS_BOOT_LOADER_FILES NtosBootLoaders[] =
|
||||||
|
|
||||||
|
|
||||||
static BOOLEAN
|
static BOOLEAN
|
||||||
|
IsValidNTOSInstallation_UStr(
|
||||||
|
IN PUNICODE_STRING SystemRootPath);
|
||||||
|
|
||||||
|
/*static*/ BOOLEAN
|
||||||
IsValidNTOSInstallation(
|
IsValidNTOSInstallation(
|
||||||
IN HANDLE SystemRootDirectory OPTIONAL,
|
IN PCWSTR SystemRoot);
|
||||||
IN PCWSTR SystemRoot OPTIONAL);
|
|
||||||
|
|
||||||
static PNTOS_INSTALLATION
|
static PNTOS_INSTALLATION
|
||||||
FindExistingNTOSInstall(
|
FindExistingNTOSInstall(
|
||||||
|
@ -142,9 +145,6 @@ FreeLdrEnumerateInstallations(
|
||||||
PWCHAR SectionName, KeyData;
|
PWCHAR SectionName, KeyData;
|
||||||
UNICODE_STRING InstallName;
|
UNICODE_STRING InstallName;
|
||||||
|
|
||||||
HANDLE SystemRootDirectory;
|
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
|
||||||
PNTOS_INSTALLATION NtOsInstall;
|
PNTOS_INSTALLATION NtOsInstall;
|
||||||
UNICODE_STRING SystemRootPath;
|
UNICODE_STRING SystemRootPath;
|
||||||
WCHAR SystemRoot[MAX_PATH];
|
WCHAR SystemRoot[MAX_PATH];
|
||||||
|
@ -264,25 +264,7 @@ FreeLdrEnumerateInstallations(
|
||||||
/* Set SystemRootPath */
|
/* Set SystemRootPath */
|
||||||
DPRINT1("FreeLdrEnumerateInstallations: SystemRootPath: '%wZ'\n", &SystemRootPath);
|
DPRINT1("FreeLdrEnumerateInstallations: SystemRootPath: '%wZ'\n", &SystemRootPath);
|
||||||
|
|
||||||
/* Open SystemRootPath */
|
if (IsValidNTOSInstallation_UStr(&SystemRootPath))
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
|
||||||
&SystemRootPath,
|
|
||||||
OBJ_CASE_INSENSITIVE,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
Status = NtOpenFile(&SystemRootDirectory,
|
|
||||||
FILE_LIST_DIRECTORY | SYNCHRONIZE,
|
|
||||||
&ObjectAttributes,
|
|
||||||
&IoStatusBlock,
|
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
||||||
FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT1("Failed to open SystemRoot '%wZ', Status 0x%08lx\n", &SystemRootPath, Status);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsValidNTOSInstallation(SystemRootDirectory, NULL))
|
|
||||||
{
|
{
|
||||||
ULONG DiskNumber = 0, PartitionNumber = 0;
|
ULONG DiskNumber = 0, PartitionNumber = 0;
|
||||||
PCWSTR PathComponent = NULL;
|
PCWSTR PathComponent = NULL;
|
||||||
|
@ -322,8 +304,6 @@ FreeLdrEnumerateInstallations(
|
||||||
DiskNumber, PartitionNumber, PartEntry,
|
DiskNumber, PartitionNumber, PartEntry,
|
||||||
InstallNameW);
|
InstallNameW);
|
||||||
}
|
}
|
||||||
|
|
||||||
NtClose(SystemRootDirectory);
|
|
||||||
}
|
}
|
||||||
while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData));
|
while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData));
|
||||||
|
|
||||||
|
@ -349,9 +329,6 @@ NtLdrEnumerateInstallations(
|
||||||
PWCHAR SectionName, KeyData;
|
PWCHAR SectionName, KeyData;
|
||||||
UNICODE_STRING InstallName;
|
UNICODE_STRING InstallName;
|
||||||
|
|
||||||
HANDLE SystemRootDirectory;
|
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
|
||||||
PNTOS_INSTALLATION NtOsInstall;
|
PNTOS_INSTALLATION NtOsInstall;
|
||||||
UNICODE_STRING SystemRootPath;
|
UNICODE_STRING SystemRootPath;
|
||||||
WCHAR SystemRoot[MAX_PATH];
|
WCHAR SystemRoot[MAX_PATH];
|
||||||
|
@ -439,25 +416,7 @@ NtLdrEnumerateInstallations(
|
||||||
/* Set SystemRootPath */
|
/* Set SystemRootPath */
|
||||||
DPRINT1("NtLdrEnumerateInstallations: SystemRootPath: '%wZ'\n", &SystemRootPath);
|
DPRINT1("NtLdrEnumerateInstallations: SystemRootPath: '%wZ'\n", &SystemRootPath);
|
||||||
|
|
||||||
/* Open SystemRootPath */
|
if (IsValidNTOSInstallation_UStr(&SystemRootPath))
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
|
||||||
&SystemRootPath,
|
|
||||||
OBJ_CASE_INSENSITIVE,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
Status = NtOpenFile(&SystemRootDirectory,
|
|
||||||
FILE_LIST_DIRECTORY | SYNCHRONIZE,
|
|
||||||
&ObjectAttributes,
|
|
||||||
&IoStatusBlock,
|
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
||||||
FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT1("Failed to open SystemRoot '%wZ', Status 0x%08lx\n", &SystemRootPath, Status);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsValidNTOSInstallation(SystemRootDirectory, NULL))
|
|
||||||
{
|
{
|
||||||
ULONG DiskNumber = 0, PartitionNumber = 0;
|
ULONG DiskNumber = 0, PartitionNumber = 0;
|
||||||
PCWSTR PathComponent = NULL;
|
PCWSTR PathComponent = NULL;
|
||||||
|
@ -497,8 +456,6 @@ NtLdrEnumerateInstallations(
|
||||||
DiskNumber, PartitionNumber, PartEntry,
|
DiskNumber, PartitionNumber, PartEntry,
|
||||||
InstallNameW);
|
InstallNameW);
|
||||||
}
|
}
|
||||||
|
|
||||||
NtClose(SystemRootDirectory);
|
|
||||||
}
|
}
|
||||||
while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData));
|
while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData));
|
||||||
|
|
||||||
|
@ -542,8 +499,7 @@ PCWSTR FindSubStrI(PCWSTR str, PCWSTR strSearch)
|
||||||
static BOOLEAN
|
static BOOLEAN
|
||||||
CheckForValidPEAndVendor(
|
CheckForValidPEAndVendor(
|
||||||
IN HANDLE RootDirectory OPTIONAL,
|
IN HANDLE RootDirectory OPTIONAL,
|
||||||
IN PCWSTR PathName OPTIONAL,
|
IN PCWSTR PathNameToFile,
|
||||||
IN PCWSTR FileName, // OPTIONAL
|
|
||||||
OUT PUNICODE_STRING VendorName
|
OUT PUNICODE_STRING VendorName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -562,18 +518,18 @@ CheckForValidPEAndVendor(
|
||||||
*VendorName->Buffer = UNICODE_NULL;
|
*VendorName->Buffer = UNICODE_NULL;
|
||||||
VendorName->Length = 0;
|
VendorName->Length = 0;
|
||||||
|
|
||||||
Status = OpenAndMapFile(RootDirectory, PathName, FileName,
|
Status = OpenAndMapFile(RootDirectory, PathNameToFile,
|
||||||
&FileHandle, &SectionHandle, &ViewBase, NULL);
|
&FileHandle, &SectionHandle, &ViewBase, NULL);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to open and map file '%S', Status 0x%08lx\n", FileName, Status);
|
DPRINT1("Failed to open and map file '%S', Status 0x%08lx\n", PathNameToFile, Status);
|
||||||
return FALSE; // Status;
|
return FALSE; // Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure it's a valid PE file */
|
/* Make sure it's a valid PE file */
|
||||||
if (!RtlImageNtHeader(ViewBase))
|
if (!RtlImageNtHeader(ViewBase))
|
||||||
{
|
{
|
||||||
DPRINT1("File '%S' does not seem to be a valid PE, bail out\n", FileName);
|
DPRINT1("File '%S' does not seem to be a valid PE, bail out\n", PathNameToFile);
|
||||||
Status = STATUS_INVALID_IMAGE_FORMAT;
|
Status = STATUS_INVALID_IMAGE_FORMAT;
|
||||||
goto UnmapFile;
|
goto UnmapFile;
|
||||||
}
|
}
|
||||||
|
@ -585,7 +541,7 @@ CheckForValidPEAndVendor(
|
||||||
Status = NtGetVersionResource((PVOID)((ULONG_PTR)ViewBase | 1), &VersionBuffer, NULL);
|
Status = NtGetVersionResource((PVOID)((ULONG_PTR)ViewBase | 1), &VersionBuffer, NULL);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to get version resource for file '%S', Status 0x%08lx\n", FileName, Status);
|
DPRINT1("Failed to get version resource for file '%S', Status 0x%08lx\n", PathNameToFile, Status);
|
||||||
goto UnmapFile;
|
goto UnmapFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -611,7 +567,7 @@ CheckForValidPEAndVendor(
|
||||||
if (NT_SUCCESS(Status) /*&& pvData*/)
|
if (NT_SUCCESS(Status) /*&& pvData*/)
|
||||||
{
|
{
|
||||||
/* BufLen includes the NULL terminator count */
|
/* BufLen includes the NULL terminator count */
|
||||||
DPRINT1("Found version vendor: \"%S\" for file '%S'\n", pvData, FileName);
|
DPRINT1("Found version vendor: \"%S\" for file '%S'\n", pvData, PathNameToFile);
|
||||||
|
|
||||||
StringCbCopyNW(VendorName->Buffer, VendorName->MaximumLength,
|
StringCbCopyNW(VendorName->Buffer, VendorName->MaximumLength,
|
||||||
pvData, BufLen * sizeof(WCHAR));
|
pvData, BufLen * sizeof(WCHAR));
|
||||||
|
@ -622,7 +578,7 @@ CheckForValidPEAndVendor(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
DPRINT1("No version vendor found for file '%S'\n", FileName);
|
DPRINT1("No version vendor found for file '%S'\n", PathNameToFile);
|
||||||
|
|
||||||
UnmapFile:
|
UnmapFile:
|
||||||
/* Finally, unmap and close the file */
|
/* Finally, unmap and close the file */
|
||||||
|
@ -639,48 +595,30 @@ UnmapFile:
|
||||||
// - if it's broken or not (aka. needs for repair, or just upgrading).
|
// - if it's broken or not (aka. needs for repair, or just upgrading).
|
||||||
//
|
//
|
||||||
static BOOLEAN
|
static BOOLEAN
|
||||||
IsValidNTOSInstallation(
|
IsValidNTOSInstallationByHandle(
|
||||||
IN HANDLE SystemRootDirectory OPTIONAL,
|
IN HANDLE SystemRootDirectory)
|
||||||
IN PCWSTR SystemRoot OPTIONAL)
|
|
||||||
{
|
{
|
||||||
BOOLEAN Success = FALSE;
|
BOOLEAN Success = FALSE;
|
||||||
USHORT i;
|
USHORT i;
|
||||||
UNICODE_STRING VendorName;
|
UNICODE_STRING VendorName;
|
||||||
WCHAR PathBuffer[MAX_PATH];
|
WCHAR VendorNameBuffer[MAX_PATH];
|
||||||
|
|
||||||
/*
|
|
||||||
* Use either the 'SystemRootDirectory' handle or the 'SystemRoot' string,
|
|
||||||
* depending on what the user gave to us in entry.
|
|
||||||
*/
|
|
||||||
if (SystemRootDirectory)
|
|
||||||
SystemRoot = NULL;
|
|
||||||
// else SystemRootDirectory == NULL and SystemRoot is what it is.
|
|
||||||
|
|
||||||
/* If both the parameters are NULL we cannot do anything else more */
|
|
||||||
if (!SystemRootDirectory && !SystemRoot)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
// DoesPathExist(SystemRootDirectory, SystemRoot, L"System32\\"); etc...
|
|
||||||
|
|
||||||
/* Check for the existence of \SystemRoot\System32 */
|
/* Check for the existence of \SystemRoot\System32 */
|
||||||
StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), L"%s%s", SystemRoot ? SystemRoot : L"", L"System32\\");
|
if (!DoesPathExist(SystemRootDirectory, L"System32\\"))
|
||||||
if (!DoesPathExist(SystemRootDirectory, PathBuffer))
|
|
||||||
{
|
{
|
||||||
// DPRINT1("Failed to open directory '%wZ', Status 0x%08lx\n", &FileName, Status);
|
// DPRINT1("Failed to open directory '%wZ', Status 0x%08lx\n", &FileName, Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for the existence of \SystemRoot\System32\drivers */
|
/* Check for the existence of \SystemRoot\System32\drivers */
|
||||||
StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), L"%s%s", SystemRoot ? SystemRoot : L"", L"System32\\drivers\\");
|
if (!DoesPathExist(SystemRootDirectory, L"System32\\drivers\\"))
|
||||||
if (!DoesPathExist(SystemRootDirectory, PathBuffer))
|
|
||||||
{
|
{
|
||||||
// DPRINT1("Failed to open directory '%wZ', Status 0x%08lx\n", &FileName, Status);
|
// DPRINT1("Failed to open directory '%wZ', Status 0x%08lx\n", &FileName, Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for the existence of \SystemRoot\System32\config */
|
/* Check for the existence of \SystemRoot\System32\config */
|
||||||
StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), L"%s%s", SystemRoot ? SystemRoot : L"", L"System32\\config\\");
|
if (!DoesPathExist(SystemRootDirectory, L"System32\\config\\"))
|
||||||
if (!DoesPathExist(SystemRootDirectory, PathBuffer))
|
|
||||||
{
|
{
|
||||||
// DPRINT1("Failed to open directory '%wZ', Status 0x%08lx\n", &FileName, Status);
|
// DPRINT1("Failed to open directory '%wZ', Status 0x%08lx\n", &FileName, Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -691,22 +629,22 @@ IsValidNTOSInstallation(
|
||||||
* Check for the existence of SYSTEM and SOFTWARE hives in \SystemRoot\System32\config
|
* Check for the existence of SYSTEM and SOFTWARE hives in \SystemRoot\System32\config
|
||||||
* (but we don't check here whether they are actually valid).
|
* (but we don't check here whether they are actually valid).
|
||||||
*/
|
*/
|
||||||
if (!DoesFileExist(SystemRootDirectory, SystemRoot, L"System32\\config\\SYSTEM"))
|
if (!DoesFileExist(SystemRootDirectory, L"System32\\config\\SYSTEM"))
|
||||||
{
|
{
|
||||||
// DPRINT1("Failed to open file '%wZ', Status 0x%08lx\n", &FileName, Status);
|
// DPRINT1("Failed to open file '%wZ', Status 0x%08lx\n", &FileName, Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!DoesFileExist(SystemRootDirectory, SystemRoot, L"System32\\config\\SOFTWARE"))
|
if (!DoesFileExist(SystemRootDirectory, L"System32\\config\\SOFTWARE"))
|
||||||
{
|
{
|
||||||
// DPRINT1("Failed to open file '%wZ', Status 0x%08lx\n", &FileName, Status);
|
// DPRINT1("Failed to open file '%wZ', Status 0x%08lx\n", &FileName, Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RtlInitEmptyUnicodeString(&VendorName, PathBuffer, sizeof(PathBuffer));
|
RtlInitEmptyUnicodeString(&VendorName, VendorNameBuffer, sizeof(VendorNameBuffer));
|
||||||
|
|
||||||
/* Check for the existence of \SystemRoot\System32\ntoskrnl.exe and retrieves its vendor name */
|
/* Check for the existence of \SystemRoot\System32\ntoskrnl.exe and retrieves its vendor name */
|
||||||
Success = CheckForValidPEAndVendor(SystemRootDirectory, SystemRoot, L"System32\\ntoskrnl.exe", &VendorName);
|
Success = CheckForValidPEAndVendor(SystemRootDirectory, L"System32\\ntoskrnl.exe", &VendorName);
|
||||||
if (!Success)
|
if (!Success)
|
||||||
DPRINT1("Kernel file ntoskrnl.exe is either not a PE file, or does not have any vendor?\n");
|
DPRINT1("Kernel file ntoskrnl.exe is either not a PE file, or does not have any vendor?\n");
|
||||||
|
|
||||||
|
@ -728,7 +666,7 @@ IsValidNTOSInstallation(
|
||||||
/* OPTIONAL: Check for the existence of \SystemRoot\System32\ntkrnlpa.exe */
|
/* OPTIONAL: Check for the existence of \SystemRoot\System32\ntkrnlpa.exe */
|
||||||
|
|
||||||
/* Check for the existence of \SystemRoot\System32\ntdll.dll and retrieves its vendor name */
|
/* Check for the existence of \SystemRoot\System32\ntdll.dll and retrieves its vendor name */
|
||||||
Success = CheckForValidPEAndVendor(SystemRootDirectory, SystemRoot, L"System32\\ntdll.dll", &VendorName);
|
Success = CheckForValidPEAndVendor(SystemRootDirectory, L"System32\\ntdll.dll", &VendorName);
|
||||||
if (!Success)
|
if (!Success)
|
||||||
DPRINT1("User-mode file ntdll.dll is either not a PE file, or does not have any vendor?\n");
|
DPRINT1("User-mode file ntdll.dll is either not a PE file, or does not have any vendor?\n");
|
||||||
if (Success)
|
if (Success)
|
||||||
|
@ -747,6 +685,50 @@ IsValidNTOSInstallation(
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOLEAN
|
||||||
|
IsValidNTOSInstallation_UStr(
|
||||||
|
IN PUNICODE_STRING SystemRootPath)
|
||||||
|
{
|
||||||
|
NTSTATUS Status;
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
|
HANDLE SystemRootDirectory;
|
||||||
|
BOOLEAN Success;
|
||||||
|
|
||||||
|
/* Open SystemRootPath */
|
||||||
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
|
SystemRootPath,
|
||||||
|
OBJ_CASE_INSENSITIVE,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
Status = NtOpenFile(&SystemRootDirectory,
|
||||||
|
FILE_LIST_DIRECTORY | SYNCHRONIZE,
|
||||||
|
&ObjectAttributes,
|
||||||
|
&IoStatusBlock,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("Failed to open SystemRoot '%wZ', Status 0x%08lx\n", SystemRootPath, Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Success = IsValidNTOSInstallationByHandle(SystemRootDirectory);
|
||||||
|
|
||||||
|
/* Done! */
|
||||||
|
NtClose(SystemRootDirectory);
|
||||||
|
return Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*static*/ BOOLEAN
|
||||||
|
IsValidNTOSInstallation(
|
||||||
|
IN PCWSTR SystemRoot)
|
||||||
|
{
|
||||||
|
UNICODE_STRING SystemRootPath;
|
||||||
|
RtlInitUnicodeString(&SystemRootPath, SystemRoot);
|
||||||
|
return IsValidNTOSInstallationByHandle(&SystemRootPath);
|
||||||
|
}
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
DumpNTOSInstalls(
|
DumpNTOSInstalls(
|
||||||
IN PGENERIC_LIST List)
|
IN PGENERIC_LIST List)
|
||||||
|
@ -934,7 +916,7 @@ FindNTOSInstallations(
|
||||||
for (i = 0; i < ARRAYSIZE(NtosBootLoaders); ++i)
|
for (i = 0; i < ARRAYSIZE(NtosBootLoaders); ++i)
|
||||||
{
|
{
|
||||||
/* Check whether the loader executable exists */
|
/* Check whether the loader executable exists */
|
||||||
if (!DoesFileExist(PartitionHandle, NULL, NtosBootLoaders[i].LoaderExecutable))
|
if (!DoesFileExist(PartitionHandle, NtosBootLoaders[i].LoaderExecutable))
|
||||||
{
|
{
|
||||||
/* The loader does not exist, continue with another one */
|
/* The loader does not exist, continue with another one */
|
||||||
DPRINT1("Loader executable '%S' does not exist, continue with another one...\n", NtosBootLoaders[i].LoaderExecutable);
|
DPRINT1("Loader executable '%S' does not exist, continue with another one...\n", NtosBootLoaders[i].LoaderExecutable);
|
||||||
|
@ -942,7 +924,7 @@ FindNTOSInstallations(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether the loader configuration file exists */
|
/* Check whether the loader configuration file exists */
|
||||||
Status = OpenAndMapFile(PartitionHandle, NULL, NtosBootLoaders[i].LoaderConfigurationFile,
|
Status = OpenAndMapFile(PartitionHandle, NtosBootLoaders[i].LoaderConfigurationFile,
|
||||||
&FileHandle, &SectionHandle, &ViewBase, &FileSize);
|
&FileHandle, &SectionHandle, &ViewBase, &FileSize);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
|
|
@ -2275,7 +2275,7 @@ InstallFatBootcodeToPartition(
|
||||||
/* Prepare for possibly copying 'freeldr.ini' */
|
/* Prepare for possibly copying 'freeldr.ini' */
|
||||||
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
|
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
|
||||||
|
|
||||||
DoesFreeLdrExist = DoesFileExist(NULL, NULL, DstPath);
|
DoesFreeLdrExist = DoesFileExist(NULL, DstPath);
|
||||||
if (DoesFreeLdrExist)
|
if (DoesFreeLdrExist)
|
||||||
{
|
{
|
||||||
/* Update existing 'freeldr.ini' */
|
/* Update existing 'freeldr.ini' */
|
||||||
|
@ -2292,8 +2292,8 @@ InstallFatBootcodeToPartition(
|
||||||
/* Check for NT and other bootloaders */
|
/* Check for NT and other bootloaders */
|
||||||
|
|
||||||
// FIXME: Check for Vista+ bootloader!
|
// FIXME: Check for Vista+ bootloader!
|
||||||
if (DoesFileExist(NULL, SystemRootPath->Buffer, L"ntldr") == TRUE ||
|
if (DoesFileExist_2(SystemRootPath->Buffer, L"ntldr") == TRUE ||
|
||||||
DoesFileExist(NULL, SystemRootPath->Buffer, L"boot.ini") == TRUE)
|
DoesFileExist_2(SystemRootPath->Buffer, L"boot.ini") == TRUE)
|
||||||
{
|
{
|
||||||
/* Search root directory for 'ntldr' and 'boot.ini' */
|
/* Search root directory for 'ntldr' and 'boot.ini' */
|
||||||
DPRINT1("Found Microsoft Windows NT/2000/XP boot loader\n");
|
DPRINT1("Found Microsoft Windows NT/2000/XP boot loader\n");
|
||||||
|
@ -2370,8 +2370,8 @@ InstallFatBootcodeToPartition(
|
||||||
PWCHAR BootSector;
|
PWCHAR BootSector;
|
||||||
PWCHAR BootSectorFileName;
|
PWCHAR BootSectorFileName;
|
||||||
|
|
||||||
if (DoesFileExist(NULL, SystemRootPath->Buffer, L"io.sys") == TRUE ||
|
if (DoesFileExist_2(SystemRootPath->Buffer, L"io.sys") == TRUE ||
|
||||||
DoesFileExist(NULL, SystemRootPath->Buffer, L"msdos.sys") == TRUE)
|
DoesFileExist_2(SystemRootPath->Buffer, L"msdos.sys") == TRUE)
|
||||||
{
|
{
|
||||||
/* Search for root directory for 'io.sys' and 'msdos.sys' */
|
/* Search for root directory for 'io.sys' and 'msdos.sys' */
|
||||||
DPRINT1("Found Microsoft DOS or Windows 9x boot loader\n");
|
DPRINT1("Found Microsoft DOS or Windows 9x boot loader\n");
|
||||||
|
@ -2385,7 +2385,7 @@ InstallFatBootcodeToPartition(
|
||||||
BootSectorFileName = L"\\bootsect.dos";
|
BootSectorFileName = L"\\bootsect.dos";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (DoesFileExist(NULL, SystemRootPath->Buffer, L"kernel.sys") == TRUE)
|
if (DoesFileExist_2(SystemRootPath->Buffer, L"kernel.sys") == TRUE)
|
||||||
{
|
{
|
||||||
/* Search for root directory for 'kernel.sys' */
|
/* Search for root directory for 'kernel.sys' */
|
||||||
DPRINT1("Found FreeDOS boot loader\n");
|
DPRINT1("Found FreeDOS boot loader\n");
|
||||||
|
@ -2517,7 +2517,7 @@ InstallExt2BootcodeToPartition(
|
||||||
/* Prepare for possibly copying 'freeldr.ini' */
|
/* Prepare for possibly copying 'freeldr.ini' */
|
||||||
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
|
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
|
||||||
|
|
||||||
DoesFreeLdrExist = DoesFileExist(NULL, NULL, DstPath);
|
DoesFreeLdrExist = DoesFileExist(NULL, DstPath);
|
||||||
if (DoesFreeLdrExist)
|
if (DoesFreeLdrExist)
|
||||||
{
|
{
|
||||||
/* Update existing 'freeldr.ini' */
|
/* Update existing 'freeldr.ini' */
|
||||||
|
|
|
@ -429,7 +429,7 @@ CheckUnattendedSetup(VOID)
|
||||||
|
|
||||||
CombinePaths(UnattendInfPath, ARRAYSIZE(UnattendInfPath), 2, SourcePath.Buffer, L"\\unattend.inf");
|
CombinePaths(UnattendInfPath, ARRAYSIZE(UnattendInfPath), 2, SourcePath.Buffer, L"\\unattend.inf");
|
||||||
|
|
||||||
if (DoesFileExist(NULL, NULL, UnattendInfPath) == FALSE)
|
if (DoesFileExist(NULL, UnattendInfPath) == FALSE)
|
||||||
{
|
{
|
||||||
DPRINT("Does not exist: %S\n", UnattendInfPath);
|
DPRINT("Does not exist: %S\n", UnattendInfPath);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue