104 DPRINT(
" An installation '%S' of unsupported type %lu\n",
105 BootEntry->FriendlyName, BootEntry->OsOptionsLength);
114 DPRINT1(
" A Win2k3 install '%S' without an ARC path?!\n", BootEntry->FriendlyName);
119 DPRINT(
" Found a candidate Win2k3 install '%S' with ARC path '%S'\n",
120 BootEntry->FriendlyName,
Options->OsLoadPath);
133 DPRINT(
" An NTOS installation with name \"%S\" from vendor \"%S\" already exists in SystemRoot '%wZ'\n",
134 NtOsInstall->InstallationName, NtOsInstall->VendorName, &NtOsInstall->SystemArcPath);
147 DPRINT1(
"ArcPathToNtPath(%S) failed, skip the installation.\n",
Options->OsLoadPath);
152 DPRINT(
"ArcPathToNtPath() succeeded: '%S' --> '%wZ'\n",
153 Options->OsLoadPath, &SystemRootPath);
162 DPRINT1(
" An NTOS installation with name \"%S\" from vendor \"%S\" already exists in SystemRoot '%wZ'\n",
163 NtOsInstall->InstallationName, NtOsInstall->VendorName, &NtOsInstall->SystemNtPath);
168 DPRINT(
"EnumerateInstallations: SystemRootPath: '%wZ'\n", &SystemRootPath);
171 RtlInitEmptyUnicodeString(&
VendorName, VendorNameBuffer,
sizeof(VendorNameBuffer));
178 DPRINT(
"Found a valid NTOS installation in SystemRoot ARC path '%S', NT path '%wZ'\n",
179 Options->OsLoadPath, &SystemRootPath);
184 DPRINT(
"SystemRootPath = '%wZ' points to disk #%d, partition #%d, path '%S'\n",
190 DPRINT1(
"GetDiskOrPartition(disk #%d, partition #%d) failed\n",
196 DPRINT1(
"NtPathToDiskPartComponents(%wZ) failed\n", &SystemRootPath);
201 BootEntry->FriendlyName,
270 DPRINT1(
"Failed to open and map file '%S', Status 0x%08lx\n", PathNameToFile,
Status);
278 DPRINT1(
"File '%S' does not seem to be a valid NT PE file, bail out\n", PathNameToFile);
293 DPRINT1(
"Failed to get version resource for file '%S', Status 0x%08lx\n", PathNameToFile,
Status);
300 USHORT wCodePage = 0, wLangID = 0;
307 L"StringFileInfo\\%04X%04X\\CompanyName",
319 DPRINT(
"Found version vendor: \"%S\" for file '%S'\n",
pvData, PathNameToFile);
330 DPRINT(
"No version vendor found for file '%S'\n", PathNameToFile);
372 PathName =
L"System32\\";
380 PathName =
L"System32\\drivers\\";
388 PathName =
L"System32\\config\\";
400 PathName =
L"System32\\config\\SYSTEM";
406 PathName =
L"System32\\config\\SOFTWARE";
414 RtlInitEmptyUnicodeString(&LocalVendorName, VendorNameBuffer,
sizeof(VendorNameBuffer));
417 PathName =
L"System32\\ntoskrnl.exe";
420 DPRINT1(
"Kernel executable '%S' is either not a PE file, or does not have any vendor?\n", PathName);
437 DPRINT(
"IsValidNTOSInstallation: We've got an NTOS installation from %S !\n",
KnownVendors[
i]);
446 *Machine = LocalMachine;
462 PathName =
L"System32\\ntdll.dll";
465 DPRINT1(
"User-mode DLL '%S' is either not a PE file, or does not have any vendor?\n", PathName);
474 DPRINT(
"IsValidNTOSInstallation: The user-mode DLL '%S' is from %S\n", PathName,
KnownVendors[
i]);
483 *Machine = LocalMachine;
508 HANDLE SystemRootDirectory;
525 DPRINT1(
"Failed to open SystemRoot '%wZ', Status 0x%08lx\n", SystemRootPath,
Status);
546 DPRINT(
"There %s %d installation%s detected:\n",
547 NtOsInstallsCount >= 2 ?
"are" :
"is",
549 NtOsInstallsCount >= 2 ?
"s" :
"");
555 DPRINT(
" On disk #%d, partition #%d: Installation \"%S\" in SystemRoot '%wZ'\n",
579 if (!SystemRootArcPath && !SystemRootNtPath)
593 if ( (SystemRootArcPath &&
595 &SystemArcPath,
TRUE)) ||
598 SystemRootNtPath,
TRUE)) )
622 SIZE_T ArcPathLength, NtPathLength;
628 DPRINT1(
"An NTOS installation with name \"%S\" from vendor \"%S\" already exists on disk #%d, partition #%d, in SystemRoot '%wZ'\n",
638 ArcPathLength = (
wcslen(SystemRootArcPath) + 1) *
sizeof(
WCHAR);
640 NtPathLength = SystemRootNtPath->Length +
sizeof(
UNICODE_NULL);
644 sizeof(*NtOsInstall) +
645 ArcPathLength + NtPathLength);
653 NtOsInstall->
Machine = Machine;
656 (
PWCHAR)(NtOsInstall + 1),
688 ULONG DiskNumber = PartEntry->DiskEntry->DiskNumber;
690 HANDLE PartitionDirectoryHandle;
695 PVOID BootStoreHandle;
700 ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
704 L"\\Device\\Harddisk%lu\\Partition%lu\\",
707 DPRINT(
"FindNTOSInstallations: PartitionRootPath: '%wZ'\n", &PartitionRootPath);
723 DPRINT1(
"Failed to open partition '%wZ', Status 0x%08lx\n", &PartitionRootPath,
Status);
728 Data.PartList = PartList;
737 DPRINT(
"Loader type '%d' does not exist, or an error happened (Status 0x%08lx), continue with another one...\n",
743 DPRINT(
"Analyze the OS installations for loader type '%d' in disk #%d, partition #%d\n",
749 DPRINT1(
"Could not open the NTOS boot store of type '%d' (Status 0x%08lx), continue with another one...\n",
758 NtClose(PartitionDirectoryHandle);
769 return PartEntry->IsPartitioned &&
790 Entry = PartList->DiskListHead.Flink;
791 while (
Entry != &PartList->DiskListHead)
805 Entry2 = Entry2->
Flink;
809 DPRINT(
" Primary Partition #%d, index %d - Type 0x%02x, IsLogical = %s, IsPartitioned = %s, IsNew = %s, AutoCreate = %s, FormatState = %lu -- Should I check it? %s\n",
813 PartEntry->
New ?
"Yes" :
"No",
827 Entry2 = Entry2->
Flink;
831 DPRINT(
" Logical Partition #%d, index %d - Type 0x%02x, IsLogical = %s, IsPartitioned = %s, IsNew = %s, AutoCreate = %s, FormatState = %lu -- Should I check it? %s\n",
835 PartEntry->
New ?
"Yes" :
"No",
847 DumpNTOSInstalls(
List);
static const char VendorName[]
#define FILE_DIRECTORY_FILE
BOOLEAN ArcPathToNtPath(OUT PUNICODE_STRING NtPath, IN PCWSTR ArcPath, IN PPARTLIST PartList OPTIONAL)
NTSTATUS OpenBootStoreByHandle(OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
NTSTATUS EnumerateBootStoreEntries(IN PVOID Handle, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
NTSTATUS FindBootStore(IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, OUT PULONG VersionNumber OPTIONAL)
NTSTATUS CloseBootStore(IN PVOID Handle)
struct _NTOS_OPTIONS * PNTOS_OPTIONS
#define NTOS_OPTIONS_SIGNATURE
enum _BOOT_STORE_TYPE BOOT_STORE_TYPE
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
static const WCHAR SystemRoot[]
static const WCHAR Signature[]
#define RtlCompareMemory(s1, s2, l)
BOOLEAN NtPathToDiskPartComponents(IN PCWSTR NtPath, OUT PULONG pDiskNumber, OUT PULONG pPartNumber, OUT PCWSTR *PathComponent OPTIONAL)
NTSTATUS OpenAndMapFile(IN HANDLE RootDirectory OPTIONAL, IN PCWSTR PathNameToFile, OUT PHANDLE FileHandle, OUT PHANDLE SectionHandle, OUT PVOID *BaseAddress, OUT PULONG FileSize OPTIONAL, IN BOOLEAN ReadWriteAccess)
#define UnMapAndCloseFile(FileHandle, SectionHandle, BaseAddress)
#define DoesDirExist(RootDirectory, DirName)
#define DoesFileExist(RootDirectory, FileName)
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
#define FILE_SYNCHRONOUS_IO_NONALERT
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_CASE_INSENSITIVE
#define RTL_FIELD_SIZE(type, field)
PGENERIC_LIST CreateGenericList(VOID)
PGENERIC_LIST_ENTRY GetFirstListEntry(IN PGENERIC_LIST List)
BOOLEAN AppendGenericListEntry(IN OUT PGENERIC_LIST List, IN PVOID Data, IN BOOLEAN Current)
ULONG GetNumberOfListEntries(IN PGENERIC_LIST List)
PVOID GetListEntryData(IN PGENERIC_LIST_ENTRY Entry)
PGENERIC_LIST_ENTRY GetNextListEntry(IN PGENERIC_LIST_ENTRY Entry)
static OUT PIO_STATUS_BLOCK IoStatusBlock
#define InitializeObjectAttributes(p, n, a, r, s)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
#define FILE_LIST_DIRECTORY
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
#define IsContainerPartition(PartitionType)
#define STATUS_INVALID_IMAGE_FORMAT
NTSTRSAFEAPI RtlStringCchCopyW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
NTSTRSAFEAPI RtlStringCbCopyNW(_Out_writes_bytes_(cbDest) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_reads_bytes_(cbToCopy) STRSAFE_LPCWSTR pszSrc, _In_ size_t cbToCopy)
NTSTATUS NtGetVersionResource(IN PVOID BaseAddress, OUT PVOID *Resource, OUT PULONG ResourceSize OPTIONAL)
NTSTATUS NtVerQueryValue(IN const VOID *pBlock, IN PCWSTR lpSubBlock, OUT PVOID *lplpBuffer, OUT PUINT puLen)
struct _ENUM_INSTALLS_DATA ENUM_INSTALLS_DATA
FORCEINLINE BOOLEAN ShouldICheckThisPartition(IN PPARTENTRY PartEntry)
static PNTOS_INSTALLATION FindExistingNTOSInstall(IN PGENERIC_LIST List, IN PCWSTR SystemRootArcPath OPTIONAL, IN PUNICODE_STRING SystemRootNtPath OPTIONAL)
static VOID FindNTOSInstallations(IN OUT PGENERIC_LIST List, IN PPARTLIST PartList, IN PPARTENTRY PartEntry)
static PNTOS_INSTALLATION AddNTOSInstallation(IN PGENERIC_LIST List, IN PCWSTR InstallationName, IN USHORT Machine, IN PCWSTR VendorName, IN PCWSTR SystemRootArcPath, IN PUNICODE_STRING SystemRootNtPath, IN PCWSTR PathComponent, IN ULONG DiskNumber, IN ULONG PartitionNumber, IN PPARTENTRY PartEntry OPTIONAL)
static const PCWSTR KnownVendors[]
struct _ENUM_INSTALLS_DATA * PENUM_INSTALLS_DATA
PGENERIC_LIST CreateNTOSInstallationsList(IN PPARTLIST PartList)
static BOOLEAN IsValidNTOSInstallationByHandle(IN HANDLE SystemRootDirectory, OUT PUSHORT Machine OPTIONAL, OUT PUNICODE_STRING VendorName OPTIONAL)
static BOOLEAN IsValidNTOSInstallation(IN PUNICODE_STRING SystemRootPath, OUT PUSHORT Machine OPTIONAL, OUT PUNICODE_STRING VendorName OPTIONAL)
static BOOLEAN CheckForValidPEAndVendor(IN HANDLE RootDirectory OPTIONAL, IN PCWSTR PathNameToFile, OUT PUSHORT Machine, OUT PUNICODE_STRING VendorName)
static NTSTATUS NTAPI EnumerateInstallations(IN BOOT_STORE_TYPE Type, IN PBOOT_STORE_ENTRY BootEntry, IN PVOID Parameter OPTIONAL)
PCWSTR FindSubStrI(PCWSTR str, PCWSTR strSearch)
struct _NTOS_INSTALLATION * PNTOS_INSTALLATION
BOOLEAN GetDiskOrPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber OPTIONAL, OUT PDISKENTRY *pDiskEntry, OUT PPARTENTRY *pPartEntry OPTIONAL)
PULONG MinorVersion OPTIONAL
base of all file and directory entries
LIST_ENTRY LogicalPartListHead
LIST_ENTRY PrimaryPartListHead
IN OUT PGENERIC_LIST List
struct _LIST_ENTRY * Flink
WCHAR InstallationName[MAX_PATH]
UNICODE_STRING SystemNtPath
WCHAR VendorName[MAX_PATH]
UNICODE_STRING SystemArcPath
struct _DISKENTRY * DiskEntry
#define RtlCopyMemory(Destination, Source, Length)
#define CONTAINING_RECORD(address, type, field)
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
_Must_inspect_result_ _In_ WDFCMRESLIST List
_In_ ULONG _In_opt_ PVOID pvData
_In_ ULONG _In_ ULONG PartitionNumber