ReactOS  0.4.11-dev-195-gef016bf
osdetect.c File Reference
#include "precomp.h"
#include "ntverrsrc.h"
#include "bldrsup.h"
#include "filesup.h"
#include "genlist.h"
#include "partlist.h"
#include "arcname.h"
#include "osdetect.h"
#include <strsafe.h>
#include <debug.h>
Include dependency graph for osdetect.c:

Go to the source code of this file.

Classes

struct  _ENUM_INSTALLS_DATA
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _ENUM_INSTALLS_DATA ENUM_INSTALLS_DATA
 
typedef struct
_ENUM_INSTALLS_DATA
PENUM_INSTALLS_DATA
 

Functions

static BOOLEAN IsValidNTOSInstallation_UStr (IN PUNICODE_STRING SystemRootPath)
 
BOOLEAN IsValidNTOSInstallation (IN PCWSTR SystemRoot)
 
static PNTOS_INSTALLATION FindExistingNTOSInstall (IN PGENERIC_LIST List, IN PCWSTR SystemRootArcPath OPTIONAL, IN PUNICODE_STRING SystemRootNtPath OPTIONAL)
 
static PNTOS_INSTALLATION AddNTOSInstallation (IN PGENERIC_LIST List, IN PCWSTR SystemRootArcPath, IN PUNICODE_STRING SystemRootNtPath, IN PCWSTR PathComponent, IN ULONG DiskNumber, IN ULONG PartitionNumber, IN PPARTENTRY PartEntry OPTIONAL, IN PCWSTR InstallationName)
 
static NTSTATUS NTAPI EnumerateInstallations (IN NTOS_BOOT_LOADER_TYPE Type, IN PNTOS_BOOT_ENTRY BootEntry, IN PVOID Parameter OPTIONAL)
 
PCWSTR FindSubStrI (PCWSTR str, PCWSTR strSearch)
 
static BOOLEAN CheckForValidPEAndVendor (IN HANDLE RootDirectory OPTIONAL, IN PCWSTR PathNameToFile, OUT PUNICODE_STRING VendorName)
 
static BOOLEAN IsValidNTOSInstallationByHandle (IN HANDLE SystemRootDirectory)
 
static VOID DumpNTOSInstalls (IN PGENERIC_LIST List)
 
static VOID FindNTOSInstallations (IN OUT PGENERIC_LIST List, IN PPARTLIST PartList, IN PPARTENTRY PartEntry)
 
FORCEINLINE BOOLEAN ShouldICheckThisPartition (IN PPARTENTRY PartEntry)
 
PGENERIC_LIST CreateNTOSInstallationsList (IN PPARTLIST PartList)
 

Variables

static const PCWSTR KnownVendors [] = { L"ReactOS", L"Microsoft" }
 

Macro Definition Documentation

#define NDEBUG

Definition at line 25 of file osdetect.c.

Typedef Documentation

Function Documentation

static PNTOS_INSTALLATION AddNTOSInstallation ( IN PGENERIC_LIST  List,
IN PCWSTR  SystemRootArcPath,
IN PUNICODE_STRING  SystemRootNtPath,
IN PCWSTR  PathComponent,
IN ULONG  DiskNumber,
IN ULONG  PartitionNumber,
IN PPARTENTRY PartEntry  OPTIONAL,
IN PCWSTR  InstallationName 
)
static

Definition at line 607 of file osdetect.c.

Referenced by EnumerateInstallations().

616 {
617  PNTOS_INSTALLATION NtOsInstall;
618  SIZE_T ArcPathLength, NtPathLength;
619  CHAR InstallNameA[MAX_PATH];
620 
621  /* Is there already any installation with these settings? */
622  NtOsInstall = FindExistingNTOSInstall(List, SystemRootArcPath, SystemRootNtPath);
623  if (NtOsInstall)
624  {
625  DPRINT1("An NTOS installation with name \"%S\" already exists on disk #%d, partition #%d, in SystemRoot '%wZ'\n",
626  NtOsInstall->InstallationName, NtOsInstall->DiskNumber, NtOsInstall->PartitionNumber, &NtOsInstall->SystemNtPath);
627  //
628  // NOTE: We may use its "IsDefault" attribute, and only keep the entries that have IsDefault == TRUE...
629  // Setting IsDefault to TRUE would imply searching for the "Default" entry in the loader configuration file.
630  //
631  return NtOsInstall;
632  }
633 
634  ArcPathLength = (wcslen(SystemRootArcPath) + 1) * sizeof(WCHAR);
635  // NtPathLength = ROUND_UP(SystemRootNtPath->Length + sizeof(UNICODE_NULL), sizeof(WCHAR));
636  NtPathLength = SystemRootNtPath->Length + sizeof(UNICODE_NULL);
637 
638  /* None was found, so add a new one */
640  sizeof(*NtOsInstall) +
641  ArcPathLength + NtPathLength);
642  if (!NtOsInstall)
643  return NULL;
644 
645  NtOsInstall->DiskNumber = DiskNumber;
646  NtOsInstall->PartitionNumber = PartitionNumber;
647  NtOsInstall->PartEntry = PartEntry;
648 
649  RtlInitEmptyUnicodeString(&NtOsInstall->SystemArcPath,
650  (PWCHAR)(NtOsInstall + 1),
651  ArcPathLength);
652  RtlCopyMemory(NtOsInstall->SystemArcPath.Buffer, SystemRootArcPath, ArcPathLength);
653  NtOsInstall->SystemArcPath.Length = ArcPathLength - sizeof(UNICODE_NULL);
654 
655  RtlInitEmptyUnicodeString(&NtOsInstall->SystemNtPath,
656  (PWCHAR)((ULONG_PTR)(NtOsInstall + 1) + ArcPathLength),
657  NtPathLength);
658  RtlCopyUnicodeString(&NtOsInstall->SystemNtPath, SystemRootNtPath);
659  NtOsInstall->PathComponent = NtOsInstall->SystemNtPath.Buffer +
660  (PathComponent - SystemRootNtPath->Buffer);
661 
662  StringCchCopyW(NtOsInstall->InstallationName, ARRAYSIZE(NtOsInstall->InstallationName), InstallationName);
663 
664  // Having the GENERIC_LIST storing the display item string plainly sucks...
665  StringCchPrintfA(InstallNameA, ARRAYSIZE(InstallNameA), "%S", InstallationName);
666  AppendGenericListEntry(List, InstallNameA, NtOsInstall, FALSE);
667 
668  return NtOsInstall;
669 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
uint16_t * PWCHAR
Definition: typedefs.h:54
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
PPARTENTRY PartEntry
Definition: osdetect.h:21
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
STRSAFEAPI StringCchPrintfA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:520
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
LIST_ENTRY List
Definition: psmgr.c:57
#define MAX_PATH
Definition: compat.h:26
WCHAR InstallationName[MAX_PATH]
Definition: osdetect.h:22
static PNTOS_INSTALLATION FindExistingNTOSInstall(IN PGENERIC_LIST List, IN PCWSTR SystemRootArcPath OPTIONAL, IN PUNICODE_STRING SystemRootNtPath OPTIONAL)
Definition: osdetect.c:561
BOOLEAN AppendGenericListEntry(IN OUT PGENERIC_LIST List, IN PCHAR Text, IN PVOID UserData, IN BOOLEAN Current)
Definition: genlist.c:66
HANDLE ProcessHeap
Definition: servman.c:15
ULONG_PTR SIZE_T
Definition: typedefs.h:78
PCWSTR PathComponent
Definition: osdetect.h:18
UNICODE_STRING SystemArcPath
Definition: osdetect.h:16
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
ULONG PartitionNumber
Definition: osdetect.h:20
#define DPRINT1
Definition: precomp.h:8
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
UNICODE_STRING SystemNtPath
Definition: osdetect.h:17
static BOOLEAN CheckForValidPEAndVendor ( IN HANDLE RootDirectory  OPTIONAL,
IN PCWSTR  PathNameToFile,
OUT PUNICODE_STRING  VendorName 
)
static

Definition at line 292 of file osdetect.c.

Referenced by IsValidNTOSInstallationByHandle().

297 {
300  HANDLE FileHandle, SectionHandle;
301  // SIZE_T ViewSize;
302  PVOID ViewBase;
303  PVOID VersionBuffer = NULL; // Read-only
304  PVOID pvData = NULL;
305  UINT BufLen = 0;
306 
307  if (VendorName->MaximumLength < sizeof(UNICODE_NULL))
308  return FALSE;
309 
310  *VendorName->Buffer = UNICODE_NULL;
311  VendorName->Length = 0;
312 
313  Status = OpenAndMapFile(RootDirectory, PathNameToFile,
314  &FileHandle, &SectionHandle, &ViewBase,
315  NULL, FALSE);
316  if (!NT_SUCCESS(Status))
317  {
318  DPRINT1("Failed to open and map file '%S', Status 0x%08lx\n", PathNameToFile, Status);
319  return FALSE; // Status;
320  }
321 
322  /* Make sure it's a valid PE file */
323  if (!RtlImageNtHeader(ViewBase))
324  {
325  DPRINT1("File '%S' does not seem to be a valid PE, bail out\n", PathNameToFile);
327  goto UnmapFile;
328  }
329 
330  /*
331  * Search for a valid executable version and vendor.
332  * NOTE: The module is loaded as a data file, it should be marked as such.
333  */
334  Status = NtGetVersionResource((PVOID)((ULONG_PTR)ViewBase | 1), &VersionBuffer, NULL);
335  if (!NT_SUCCESS(Status))
336  {
337  DPRINT1("Failed to get version resource for file '%S', Status 0x%08lx\n", PathNameToFile, Status);
338  goto UnmapFile;
339  }
340 
341  Status = NtVerQueryValue(VersionBuffer, L"\\VarFileInfo\\Translation", &pvData, &BufLen);
342  if (NT_SUCCESS(Status))
343  {
344  USHORT wCodePage = 0, wLangID = 0;
346 
347  wCodePage = LOWORD(*(ULONG*)pvData);
348  wLangID = HIWORD(*(ULONG*)pvData);
349 
350  StringCchPrintfW(FileInfo, ARRAYSIZE(FileInfo),
351  L"StringFileInfo\\%04X%04X\\CompanyName",
352  wCodePage, wLangID);
353 
354  Status = NtVerQueryValue(VersionBuffer, FileInfo, &pvData, &BufLen);
355 
356  /* Fixup the Status in case pvData is NULL */
357  if (NT_SUCCESS(Status) && !pvData)
358  Status = STATUS_NOT_FOUND;
359 
360  if (NT_SUCCESS(Status) /*&& pvData*/)
361  {
362  /* BufLen includes the NULL terminator count */
363  DPRINT1("Found version vendor: \"%S\" for file '%S'\n", pvData, PathNameToFile);
364 
365  StringCbCopyNW(VendorName->Buffer, VendorName->MaximumLength,
366  pvData, BufLen * sizeof(WCHAR));
367  VendorName->Length = wcslen(VendorName->Buffer) * sizeof(WCHAR);
368 
369  Success = TRUE;
370  }
371  }
372 
373  if (!NT_SUCCESS(Status))
374  DPRINT1("No version vendor found for file '%S'\n", PathNameToFile);
375 
376 UnmapFile:
377  /* Finally, unmap and close the file */
378  UnMapFile(SectionHandle, ViewBase);
379  NtClose(FileHandle);
380 
381  return Success;
382 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TRUE
Definition: types.h:120
WCHAR RootDirectory[MAX_PATH]
Definition: format.c:74
STRSAFEAPI StringCbCopyNW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, size_t cbToCopy)
Definition: strsafe.h:255
#define BufLen
Definition: fatfs.h:167
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define WCHAR
Definition: msvc.h:43
NTSTATUS NtVerQueryValue(IN const VOID *pBlock, IN PCWSTR lpSubBlock, OUT PVOID *lplpBuffer, OUT PUINT puLen)
Definition: ntverrsrc.c:174
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS NtGetVersionResource(IN PVOID BaseAddress, OUT PVOID *Resource, OUT PULONG ResourceSize OPTIONAL)
Definition: ntverrsrc.c:26
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3748
smooth NULL
Definition: ftsmooth.c:416
unsigned char BOOLEAN
#define STATUS_NOT_FOUND
Definition: shellext.h:55
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define MAX_PATH
Definition: compat.h:26
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)
Definition: filesup.c:307
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3393
static const WCHAR L[]
Definition: oid.c:1087
Status
Definition: gdiplustypes.h:24
static HANDLE FileHandle
Definition: cabinet.c:48
DWORD *typedef HANDLE
Definition: winlogon.h:61
unsigned short USHORT
Definition: pedump.c:61
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
BOOLEAN UnMapFile(IN HANDLE SectionHandle, IN PVOID BaseAddress)
Definition: filesup.c:424
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
#define RtlImageNtHeader
Definition: compat.h:457
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PGENERIC_LIST CreateNTOSInstallationsList ( IN PPARTLIST  PartList)

Definition at line 756 of file osdetect.c.

758 {
760  PLIST_ENTRY Entry, Entry2;
761  PDISKENTRY DiskEntry;
762  PPARTENTRY PartEntry;
763 
764  List = CreateGenericList();
765  if (List == NULL)
766  return NULL;
767 
768  /* Loop each available disk ... */
769  Entry = PartList->DiskListHead.Flink;
770  while (Entry != &PartList->DiskListHead)
771  {
772  DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
773  Entry = Entry->Flink;
774 
775  DPRINT1("Disk #%d\n", DiskEntry->DiskNumber);
776 
777  /* ... and for each disk, loop each available partition */
778 
779  /* First, the primary partitions */
780  Entry2 = DiskEntry->PrimaryPartListHead.Flink;
781  while (Entry2 != &DiskEntry->PrimaryPartListHead)
782  {
783  PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
784  Entry2 = Entry2->Flink;
785 
786  ASSERT(PartEntry->DiskEntry == DiskEntry);
787 
788  DPRINT1(" Primary Partition #%d, index %d - Type 0x%02x, IsLogical = %s, IsPartitioned = %s, IsNew = %s, AutoCreate = %s, FormatState = %lu -- Should I check it? %s\n",
789  PartEntry->PartitionNumber, PartEntry->PartitionIndex,
790  PartEntry->PartitionType, PartEntry->LogicalPartition ? "TRUE" : "FALSE",
791  PartEntry->IsPartitioned ? "TRUE" : "FALSE",
792  PartEntry->New ? "Yes" : "No",
793  PartEntry->AutoCreate ? "Yes" : "No",
794  PartEntry->FormatState,
795  ShouldICheckThisPartition(PartEntry) ? "YES!" : "NO!");
796 
797  if (ShouldICheckThisPartition(PartEntry))
798  FindNTOSInstallations(List, PartList, PartEntry);
799  }
800 
801  /* Then, the logical partitions (present in the extended partition) */
802  Entry2 = DiskEntry->LogicalPartListHead.Flink;
803  while (Entry2 != &DiskEntry->LogicalPartListHead)
804  {
805  PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
806  Entry2 = Entry2->Flink;
807 
808  ASSERT(PartEntry->DiskEntry == DiskEntry);
809 
810  DPRINT1(" Logical Partition #%d, index %d - Type 0x%02x, IsLogical = %s, IsPartitioned = %s, IsNew = %s, AutoCreate = %s, FormatState = %lu -- Should I check it? %s\n",
811  PartEntry->PartitionNumber, PartEntry->PartitionIndex,
812  PartEntry->PartitionType, PartEntry->LogicalPartition ? "TRUE" : "FALSE",
813  PartEntry->IsPartitioned ? "TRUE" : "FALSE",
814  PartEntry->New ? "Yes" : "No",
815  PartEntry->AutoCreate ? "Yes" : "No",
816  PartEntry->FormatState,
817  ShouldICheckThisPartition(PartEntry) ? "YES!" : "NO!");
818 
819  if (ShouldICheckThisPartition(PartEntry))
820  FindNTOSInstallations(List, PartList, PartEntry);
821  }
822  }
823 
824  /**** Debugging: List all the collected installations ****/
825  DumpNTOSInstalls(List);
826 
827  return List;
828 }
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:117
ULONG PartitionNumber
Definition: partlist.h:35
struct _Entry Entry
Definition: kefuncs.h:640
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
ULONG DiskNumber
Definition: partlist.h:94
static VOID FindNTOSInstallations(IN OUT PGENERIC_LIST List, IN PPARTLIST PartList, IN PPARTENTRY PartEntry)
Definition: osdetect.c:672
BOOLEAN LogicalPartition
Definition: partlist.h:40
FORMATSTATE FormatState
Definition: partlist.h:54
PGENERIC_LIST CreateGenericList(VOID)
Definition: genlist.c:20
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
BOOLEAN AutoCreate
Definition: partlist.h:49
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
UCHAR PartitionType
Definition: partlist.h:33
struct _DISKENTRY * DiskEntry
Definition: partlist.h:26
LIST_ENTRY List
Definition: psmgr.c:57
Definition: typedefs.h:117
BOOLEAN New
Definition: partlist.h:46
static VOID DumpNTOSInstalls(IN PGENERIC_LIST List)
Definition: osdetect.c:534
FORCEINLINE BOOLEAN ShouldICheckThisPartition(IN PPARTENTRY PartEntry)
Definition: osdetect.c:742
#define DPRINT1
Definition: precomp.h:8
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:118
BOOLEAN IsPartitioned
Definition: partlist.h:43
ULONG PartitionIndex
Definition: partlist.h:36
static VOID DumpNTOSInstalls ( IN PGENERIC_LIST  List)
static

Definition at line 534 of file osdetect.c.

Referenced by CreateNTOSInstallationsList().

536 {
538  PNTOS_INSTALLATION NtOsInstall;
539  ULONG NtOsInstallsCount = GetNumberOfListEntries(List);
540 
541  DPRINT1("There %s %d installation%s detected:\n",
542  NtOsInstallsCount >= 2 ? "are" : "is",
543  NtOsInstallsCount,
544  NtOsInstallsCount >= 2 ? "s" : "");
545 
546  Entry = GetFirstListEntry(List);
547  while (Entry)
548  {
549  NtOsInstall = (PNTOS_INSTALLATION)GetListEntryUserData(Entry);
550  Entry = GetNextListEntry(Entry);
551 
552  DPRINT1(" On disk #%d, partition #%d: Installation \"%S\" in SystemRoot '%wZ'\n",
553  NtOsInstall->DiskNumber, NtOsInstall->PartitionNumber,
554  NtOsInstall->InstallationName, &NtOsInstall->SystemNtPath);
555  }
556 
557  DPRINT1("Done.\n");
558 }
Definition: genlist.h:10
struct _Entry Entry
Definition: kefuncs.h:640
ULONG GetNumberOfListEntries(IN PGENERIC_LIST List)
Definition: genlist.c:149
LIST_ENTRY List
Definition: psmgr.c:57
PGENERIC_LIST_ENTRY GetNextListEntry(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:124
WCHAR InstallationName[MAX_PATH]
Definition: osdetect.h:22
struct _NTOS_INSTALLATION * PNTOS_INSTALLATION
PVOID GetListEntryUserData(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:135
ULONG PartitionNumber
Definition: osdetect.h:20
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
PGENERIC_LIST_ENTRY GetFirstListEntry(IN PGENERIC_LIST List)
Definition: genlist.c:113
UNICODE_STRING SystemNtPath
Definition: osdetect.h:17
static NTSTATUS NTAPI EnumerateInstallations ( IN NTOS_BOOT_LOADER_TYPE  Type,
IN PNTOS_BOOT_ENTRY  BootEntry,
IN PVOID Parameter  OPTIONAL 
)
static

Definition at line 118 of file osdetect.c.

Referenced by FindNTOSInstallations().

122 {
124 
125  PNTOS_INSTALLATION NtOsInstall;
128  WCHAR InstallNameW[MAX_PATH];
129 
130  ULONG DiskNumber = 0, PartitionNumber = 0;
132  PDISKENTRY DiskEntry = NULL;
133  PPARTENTRY PartEntry = NULL;
134 
135  /* We have a boot entry */
136 
137  UNICODE_STRING InstallName;
138  // /**/RtlInitUnicodeString(&InstallName, BootEntry->FriendlyName);/**/
139  InstallName = *BootEntry->FriendlyName;
140 
141 #if 0
142  if (Type == FreeLdr)
143  {
144  /* Check for supported boot type "Windows2003" */
145 
146  // TODO: What to do with "Windows" ; "WindowsNT40" ; "ReactOSSetup" ?
147  if ((BootType == NULL) ||
148  ( (_wcsicmp(BootType, L"Windows2003") != 0) &&
149  (_wcsicmp(BootType, L"\"Windows2003\"") != 0) ))
150  {
151  /* This is not a ReactOS entry */
152  /* Certainly not a ReactOS installation */
153  DPRINT1(" A Win2k3 install '%wZ' without an ARC path?!\n", &InstallName);
154  /* Continue the enumeration */
155  return STATUS_SUCCESS;
156  }
157  }
158 #endif
159 
160  DPRINT1(" Found a candidate Win2k3 install '%wZ' with ARC path '%S'\n",
161  &InstallName, BootEntry->OsLoadPath);
162  // DPRINT1(" Found a Win2k3 install '%wZ' with ARC path '%S'\n",
163  // &InstallName, BootEntry->OsLoadPath);
164 
165  // TODO: Normalize the ARC path.
166 
167  /*
168  * Check whether we already have an installation with this ARC path.
169  * If this is the case, stop there.
170  */
171  NtOsInstall = FindExistingNTOSInstall(Data->List, BootEntry->OsLoadPath, NULL);
172  if (NtOsInstall)
173  {
174  DPRINT1(" An NTOS installation with name \"%S\" already exists in SystemRoot '%wZ'\n",
175  NtOsInstall->InstallationName, &NtOsInstall->SystemArcPath);
176  /* Continue the enumeration */
177  return STATUS_SUCCESS;
178  }
179 
180  /*
181  * Convert the ARC path into an NT path, from which we will deduce
182  * the real disk drive & partition on which the candidate installation
183  * resides, as well verifying whether it is indeed an NTOS installation.
184  */
185  RtlInitEmptyUnicodeString(&SystemRootPath, SystemRoot, sizeof(SystemRoot));
186  if (!ArcPathToNtPath(&SystemRootPath, BootEntry->OsLoadPath, Data->PartList))
187  {
188  DPRINT1("ArcPathToNtPath(%S) failed, skip the installation.\n", BootEntry->OsLoadPath);
189  /* Continue the enumeration */
190  return STATUS_SUCCESS;
191  }
192 
193  DPRINT1("ArcPathToNtPath() succeeded: '%S' --> '%wZ'\n",
194  BootEntry->OsLoadPath, &SystemRootPath);
195 
196  /*
197  * Check whether we already have an installation with this NT path.
198  * If this is the case, stop there.
199  */
200  NtOsInstall = FindExistingNTOSInstall(Data->List, NULL /*BootEntry->OsLoadPath*/, &SystemRootPath);
201  if (NtOsInstall)
202  {
203  DPRINT1(" An NTOS installation with name \"%S\" already exists in SystemRoot '%wZ'\n",
204  NtOsInstall->InstallationName, &NtOsInstall->SystemNtPath);
205  /* Continue the enumeration */
206  return STATUS_SUCCESS;
207  }
208 
209  DPRINT1("EnumerateInstallations: SystemRootPath: '%wZ'\n", &SystemRootPath);
210 
211  /* Check if this is a valid NTOS installation; stop there if it isn't one */
212  if (!IsValidNTOSInstallation_UStr(&SystemRootPath))
213  {
214  /* Continue the enumeration */
215  return STATUS_SUCCESS;
216  }
217 
218  DPRINT1("Found a valid NTOS installation in SystemRoot ARC path '%S', NT path '%wZ'\n",
219  BootEntry->OsLoadPath, &SystemRootPath);
220 
221  /* From the NT path, compute the disk, partition and path components */
222  if (NtPathToDiskPartComponents(SystemRootPath.Buffer, &DiskNumber, &PartitionNumber, &PathComponent))
223  {
224  DPRINT1("SystemRootPath = '%wZ' points to disk #%d, partition #%d, path '%S'\n",
225  &SystemRootPath, DiskNumber, PartitionNumber, PathComponent);
226 
227  /* Retrieve the corresponding disk and partition */
228  if (!GetDiskOrPartition(Data->PartList, DiskNumber, PartitionNumber, &DiskEntry, &PartEntry))
229  {
230  DPRINT1("GetDiskOrPartition(disk #%d, partition #%d) failed\n",
231  DiskNumber, PartitionNumber);
232  }
233  }
234  else
235  {
236  DPRINT1("NtPathToDiskPartComponents(%wZ) failed\n", &SystemRootPath);
237  }
238 
239  /* Add the discovered NTOS installation into the list */
240  if (PartEntry && PartEntry->DriveLetter)
241  {
242  /* We have retrieved a partition that is mounted */
243  StringCchPrintfW(InstallNameW, ARRAYSIZE(InstallNameW), L"%C:%s \"%wZ\"",
244  PartEntry->DriveLetter, PathComponent, &InstallName);
245  }
246  else
247  {
248  /* We failed somewhere, just show the NT path */
249  StringCchPrintfW(InstallNameW, ARRAYSIZE(InstallNameW), L"%wZ \"%wZ\"",
250  &SystemRootPath, &InstallName);
251  }
252  AddNTOSInstallation(Data->List, BootEntry->OsLoadPath,
253  &SystemRootPath, PathComponent,
254  DiskNumber, PartitionNumber, PartEntry,
255  InstallNameW);
256 
257  /* Continue the enumeration */
258  return STATUS_SUCCESS;
259 }
Type
Definition: Type.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
_In_ PVOID Parameter
Definition: ldrtypes.h:239
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
BOOLEAN NtPathToDiskPartComponents(IN PCWSTR NtPath, OUT PULONG pDiskNumber, OUT PULONG pPartNumber, OUT PCWSTR *PathComponent OPTIONAL)
Definition: filesup.c:220
BOOLEAN ArcPathToNtPath(OUT PUNICODE_STRING NtPath, IN PCWSTR ArcPath, IN PPARTLIST PartList OPTIONAL)
Definition: arcname.c:725
static UNICODE_STRING SystemRootPath
Definition: usetup.c:86
CHAR BootType[80]
Definition: bootmgr.c:34
IN PPARTLIST PartList
Definition: osdetect.c:111
BOOLEAN GetDiskOrPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber OPTIONAL, OUT PDISKENTRY *pDiskEntry, OUT PPARTENTRY *pPartEntry OPTIONAL)
Definition: partlist.c:1510
static PNTOS_INSTALLATION AddNTOSInstallation(IN PGENERIC_LIST List, IN PCWSTR SystemRootArcPath, IN PUNICODE_STRING SystemRootNtPath, IN PCWSTR PathComponent, IN ULONG DiskNumber, IN ULONG PartitionNumber, IN PPARTENTRY PartEntry OPTIONAL, IN PCWSTR InstallationName)
Definition: osdetect.c:607
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR SystemRoot[]
Definition: reg.c:38
static BOOLEAN IsValidNTOSInstallation_UStr(IN PUNICODE_STRING SystemRootPath)
Definition: osdetect.c:490
#define MAX_PATH
Definition: compat.h:26
CHAR DriveLetter
Definition: partlist.h:38
WCHAR InstallationName[MAX_PATH]
Definition: osdetect.h:22
static PNTOS_INSTALLATION FindExistingNTOSInstall(IN PGENERIC_LIST List, IN PCWSTR SystemRootArcPath OPTIONAL, IN PUNICODE_STRING SystemRootNtPath OPTIONAL)
Definition: osdetect.c:561
static const WCHAR L[]
Definition: oid.c:1087
UNICODE_STRING SystemArcPath
Definition: osdetect.h:16
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
const uint16_t * PCWSTR
Definition: typedefs.h:55
IN OUT PGENERIC_LIST List
Definition: osdetect.c:110
return STATUS_SUCCESS
Definition: btrfs.c:2710
struct _ENUM_INSTALLS_DATA * PENUM_INSTALLS_DATA
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
UNICODE_STRING SystemNtPath
Definition: osdetect.h:17
static PNTOS_INSTALLATION FindExistingNTOSInstall ( IN PGENERIC_LIST  List,
IN PCWSTR SystemRootArcPath  OPTIONAL,
IN PUNICODE_STRING SystemRootNtPath  OPTIONAL 
)
static

Definition at line 561 of file osdetect.c.

Referenced by AddNTOSInstallation(), and EnumerateInstallations().

566 {
568  PNTOS_INSTALLATION NtOsInstall;
569  UNICODE_STRING SystemArcPath;
570 
571  /*
572  * We search either via ARC path or NT path.
573  * If both pointers are NULL then we fail straight away.
574  */
575  if (!SystemRootArcPath && !SystemRootNtPath)
576  return NULL;
577 
578  RtlInitUnicodeString(&SystemArcPath, SystemRootArcPath);
579 
580  Entry = GetFirstListEntry(List);
581  while (Entry)
582  {
583  NtOsInstall = (PNTOS_INSTALLATION)GetListEntryUserData(Entry);
584  Entry = GetNextListEntry(Entry);
585 
586  /*
587  * Note that if both ARC paths are equal, then the corresponding
588  * NT paths must be the same. However, two ARC paths may be different
589  * but resolve into the same NT path.
590  */
591  if ( (SystemRootArcPath &&
592  RtlEqualUnicodeString(&NtOsInstall->SystemArcPath,
593  &SystemArcPath, TRUE)) ||
594  (SystemRootNtPath &&
595  RtlEqualUnicodeString(&NtOsInstall->SystemNtPath,
596  SystemRootNtPath, TRUE)) )
597  {
598  /* Found it! */
599  return NtOsInstall;
600  }
601  }
602 
603  return NULL;
604 }
Definition: genlist.h:10
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY List
Definition: psmgr.c:57
PGENERIC_LIST_ENTRY GetNextListEntry(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:124
struct _NTOS_INSTALLATION * PNTOS_INSTALLATION
PVOID GetListEntryUserData(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:135
UNICODE_STRING SystemArcPath
Definition: osdetect.h:16
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
PGENERIC_LIST_ENTRY GetFirstListEntry(IN PGENERIC_LIST List)
Definition: genlist.c:113
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
UNICODE_STRING SystemNtPath
Definition: osdetect.h:17
static VOID FindNTOSInstallations ( IN OUT PGENERIC_LIST  List,
IN PPARTLIST  PartList,
IN PPARTENTRY  PartEntry 
)
static

Definition at line 672 of file osdetect.c.

Referenced by CreateNTOSInstallationsList().

676 {
678  ULONG DiskNumber = PartEntry->DiskEntry->DiskNumber;
679  ULONG PartitionNumber = PartEntry->PartitionNumber;
680  HANDLE PartitionHandle;
683  UNICODE_STRING PartitionRootPath;
686  ULONG Version;
687  WCHAR PathBuffer[MAX_PATH];
688 
689  /* Set PartitionRootPath */
690  StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
691  L"\\Device\\Harddisk%lu\\Partition%lu\\",
692  DiskNumber, PartitionNumber);
693  RtlInitUnicodeString(&PartitionRootPath, PathBuffer);
694  DPRINT1("FindNTOSInstallations: PartitionRootPath: '%wZ'\n", &PartitionRootPath);
695 
696  /* Open the partition */
697  InitializeObjectAttributes(&ObjectAttributes,
698  &PartitionRootPath,
700  NULL,
701  NULL);
702  Status = NtOpenFile(&PartitionHandle,
704  &ObjectAttributes,
705  &IoStatusBlock,
708  if (!NT_SUCCESS(Status))
709  {
710  DPRINT1("Failed to open partition '%wZ', Status 0x%08lx\n", &PartitionRootPath, Status);
711  return;
712  }
713 
714  Data.List = List;
715  Data.PartList = PartList;
716 
717  /* Try to see whether we recognize some NT boot loaders */
718  for (Type = FreeLdr; Type < BldrTypeMax; ++Type)
719  {
720  Status = FindNTOSBootLoader(PartitionHandle, Type, &Version);
721  if (!NT_SUCCESS(Status))
722  {
723  /* The loader does not exist, continue with another one */
724  DPRINT1("Loader type '%d' does not exist, or an error happened (Status 0x%08lx), continue with another one...\n",
725  Type, Status);
726  continue;
727  }
728 
729  /* The loader exists, try to enumerate its boot entries */
730  DPRINT1("Analyse the OS installations for loader type '%d' in disk #%d, partition #%d\n",
731  Type, DiskNumber, PartitionNumber);
732 
733  EnumerateNTOSBootEntries(PartitionHandle, Type, EnumerateInstallations, &Data);
734  }
735 
736  /* Close the partition */
737  NtClose(PartitionHandle);
738 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:359
Type
Definition: Type.h:6
NTSTATUS FindNTOSBootLoader(IN HANDLE PartitionHandle, IN NTOS_BOOT_LOADER_TYPE Type, OUT PULONG Version OPTIONAL)
Definition: bldrsup.c:55
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
NTSTATUS EnumerateNTOSBootEntries(IN HANDLE PartitionHandle, IN NTOS_BOOT_LOADER_TYPE Type, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.c:293
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
PVOID ULONG ULONG PULONG Data
Definition: oprghdlr.h:14
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
enum _NTOS_BOOT_LOADER_TYPE NTOS_BOOT_LOADER_TYPE
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
#define FILE_SHARE_READ
Definition: compat.h:125
IN PPARTLIST PartList
Definition: osdetect.c:111
smooth NULL
Definition: ftsmooth.c:416
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)
Definition: file.c:3508
#define FILE_LIST_DIRECTORY
Definition: nt_native.h:629
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY List
Definition: psmgr.c:57
static NTSTATUS NTAPI EnumerateInstallations(IN NTOS_BOOT_LOADER_TYPE Type, IN PNTOS_BOOT_ENTRY BootEntry, IN PVOID Parameter OPTIONAL)
Definition: osdetect.c:118
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define MAX_PATH
Definition: compat.h:26
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3393
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1087
#define SYNCHRONIZE
Definition: nt_native.h:61
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
IN OUT PGENERIC_LIST List
Definition: osdetect.c:110
PCWSTR FindSubStrI ( PCWSTR  str,
PCWSTR  strSearch 
)

Definition at line 266 of file osdetect.c.

Referenced by IsValidNTOSInstallationByHandle().

267 {
268  PCWSTR cp = str;
269  PCWSTR s1, s2;
270 
271  if (!*strSearch)
272  return str;
273 
274  while (*cp)
275  {
276  s1 = cp;
277  s2 = strSearch;
278 
279  while (*s1 && *s2 && (towupper(*s1) == towupper(*s2)))
280  ++s1, ++s2;
281 
282  if (!*s2)
283  return cp;
284 
285  ++cp;
286  }
287 
288  return NULL;
289 }
struct S2 s2
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
struct S1 s1
POINT cp
Definition: magnifier.c:60
#define towupper(c)
Definition: wctype.h:99
const uint16_t * PCWSTR
Definition: typedefs.h:55
BOOLEAN IsValidNTOSInstallation ( IN PCWSTR  SystemRoot)

Definition at line 525 of file osdetect.c.

527 {
529  RtlInitUnicodeString(&SystemRootPath, SystemRoot);
530  return IsValidNTOSInstallationByHandle(&SystemRootPath);
531 }
static UNICODE_STRING SystemRootPath
Definition: usetup.c:86
static const WCHAR SystemRoot[]
Definition: reg.c:38
static BOOLEAN IsValidNTOSInstallationByHandle(IN HANDLE SystemRootDirectory)
Definition: osdetect.c:391
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static BOOLEAN IsValidNTOSInstallation_UStr ( IN PUNICODE_STRING  SystemRootPath)
static

Definition at line 490 of file osdetect.c.

Referenced by EnumerateInstallations().

492 {
496  HANDLE SystemRootDirectory;
498 
499  /* Open SystemRootPath */
500  InitializeObjectAttributes(&ObjectAttributes,
503  NULL,
504  NULL);
505  Status = NtOpenFile(&SystemRootDirectory,
507  &ObjectAttributes,
508  &IoStatusBlock,
511  if (!NT_SUCCESS(Status))
512  {
513  DPRINT1("Failed to open SystemRoot '%wZ', Status 0x%08lx\n", SystemRootPath, Status);
514  return FALSE;
515  }
516 
517  Success = IsValidNTOSInstallationByHandle(SystemRootDirectory);
518 
519  /* Done! */
520  NtClose(SystemRootDirectory);
521  return Success;
522 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
static UNICODE_STRING SystemRootPath
Definition: usetup.c:86
#define FILE_SHARE_READ
Definition: compat.h:125
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
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)
Definition: file.c:3508
unsigned char BOOLEAN
#define FILE_LIST_DIRECTORY
Definition: nt_native.h:629
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3393
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define SYNCHRONIZE
Definition: nt_native.h:61
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
static BOOLEAN IsValidNTOSInstallationByHandle(IN HANDLE SystemRootDirectory)
Definition: osdetect.c:391
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static BOOLEAN IsValidNTOSInstallationByHandle ( IN HANDLE  SystemRootDirectory)
static

Definition at line 391 of file osdetect.c.

Referenced by IsValidNTOSInstallation(), and IsValidNTOSInstallation_UStr().

393 {
395  PCWSTR PathName;
396  USHORT i;
397  UNICODE_STRING VendorName;
398  WCHAR VendorNameBuffer[MAX_PATH];
399 
400  /* Check for the existence of \SystemRoot\System32 */
401  PathName = L"System32\\";
402  if (!DoesPathExist(SystemRootDirectory, PathName))
403  {
404  // DPRINT1("Failed to open directory '%S', Status 0x%08lx\n", PathName, Status);
405  return FALSE;
406  }
407 
408  /* Check for the existence of \SystemRoot\System32\drivers */
409  PathName = L"System32\\drivers\\";
410  if (!DoesPathExist(SystemRootDirectory, PathName))
411  {
412  // DPRINT1("Failed to open directory '%S', Status 0x%08lx\n", PathName, Status);
413  return FALSE;
414  }
415 
416  /* Check for the existence of \SystemRoot\System32\config */
417  PathName = L"System32\\config\\";
418  if (!DoesPathExist(SystemRootDirectory, PathName))
419  {
420  // DPRINT1("Failed to open directory '%S', Status 0x%08lx\n", PathName, Status);
421  return FALSE;
422  }
423 
424 #if 0
425  /*
426  * Check for the existence of SYSTEM and SOFTWARE hives in \SystemRoot\System32\config
427  * (but we don't check here whether they are actually valid).
428  */
429  PathName = L"System32\\config\\SYSTEM";
430  if (!DoesFileExist(SystemRootDirectory, PathName))
431  {
432  // DPRINT1("Failed to open file '%S', Status 0x%08lx\n", PathName, Status);
433  return FALSE;
434  }
435  PathName = L"System32\\config\\SOFTWARE";
436  if (!DoesFileExist(SystemRootDirectory, PathName))
437  {
438  // DPRINT1("Failed to open file '%S', Status 0x%08lx\n", PathName, Status);
439  return FALSE;
440  }
441 #endif
442 
443  RtlInitEmptyUnicodeString(&VendorName, VendorNameBuffer, sizeof(VendorNameBuffer));
444 
445  /* Check for the existence of \SystemRoot\System32\ntoskrnl.exe and retrieves its vendor name */
446  PathName = L"System32\\ntoskrnl.exe";
447  Success = CheckForValidPEAndVendor(SystemRootDirectory, PathName, &VendorName);
448  if (!Success)
449  DPRINT1("Kernel executable '%S' is either not a PE file, or does not have any vendor?\n", PathName);
450 
451  /* The kernel gives the OS its flavour */
452  if (Success)
453  {
454  for (i = 0; i < ARRAYSIZE(KnownVendors); ++i)
455  {
456  Success = !!FindSubStrI(VendorName.Buffer, KnownVendors[i]);
457  if (Success)
458  {
459  /* We have found a correct vendor combination */
460  DPRINT1("IsValidNTOSInstallation: We've got an NTOS installation from %S !\n", KnownVendors[i]);
461  break;
462  }
463  }
464  }
465 
466  /* OPTIONAL: Check for the existence of \SystemRoot\System32\ntkrnlpa.exe */
467 
468  /* Check for the existence of \SystemRoot\System32\ntdll.dll and retrieves its vendor name */
469  PathName = L"System32\\ntdll.dll";
470  Success = CheckForValidPEAndVendor(SystemRootDirectory, PathName, &VendorName);
471  if (!Success)
472  DPRINT1("User-mode DLL '%S' is either not a PE file, or does not have any vendor?\n", PathName);
473  if (Success)
474  {
475  for (i = 0; i < ARRAYSIZE(KnownVendors); ++i)
476  {
477  if (!!FindSubStrI(VendorName.Buffer, KnownVendors[i]))
478  {
479  /* We have found a correct vendor combination */
480  DPRINT1("IsValidNTOSInstallation: The user-mode DLL '%S' is from %S\n", PathName, KnownVendors[i]);
481  break;
482  }
483  }
484  }
485 
486  return Success;
487 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
PCWSTR FindSubStrI(PCWSTR str, PCWSTR strSearch)
Definition: osdetect.c:266
#define MAX_PATH
Definition: compat.h:26
static const WCHAR L[]
Definition: oid.c:1087
unsigned short USHORT
Definition: pedump.c:61
BOOLEAN DoesFileExist(IN HANDLE RootDirectory OPTIONAL, IN PCWSTR PathNameToFile)
Definition: filesup.c:163
static BOOLEAN CheckForValidPEAndVendor(IN HANDLE RootDirectory OPTIONAL, IN PCWSTR PathNameToFile, OUT PUNICODE_STRING VendorName)
Definition: osdetect.c:292
static const PCWSTR KnownVendors[]
Definition: osdetect.c:32
BOOLEAN DoesPathExist(IN HANDLE RootDirectory OPTIONAL, IN PCWSTR PathName)
Definition: filesup.c:130
#define DPRINT1
Definition: precomp.h:8
const uint16_t * PCWSTR
Definition: typedefs.h:55
FORCEINLINE BOOLEAN ShouldICheckThisPartition ( IN PPARTENTRY  PartEntry)

Definition at line 742 of file osdetect.c.

Referenced by CreateNTOSInstallationsList().

744 {
745  if (!PartEntry)
746  return FALSE;
747 
748  return PartEntry->IsPartitioned &&
749  !IsContainerPartition(PartEntry->PartitionType) /* alternatively: PartEntry->PartitionNumber != 0 */ &&
750  !PartEntry->New &&
751  (PartEntry->FormatState == Preformatted /* || PartEntry->FormatState == Formatted */);
752 }
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:245
#define FALSE
Definition: types.h:117

Variable Documentation

const PCWSTR KnownVendors[] = { L"ReactOS", L"Microsoft" }
static

Definition at line 32 of file osdetect.c.

Referenced by IsValidNTOSInstallationByHandle().