2 * PROJECT: EFI Windows Loader
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: boot/freeldr/freeldr/windows/wlregistry.c
5 * PURPOSE: Registry support functions
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
9 /* INCLUDES ***************************************************************/
15 DBG_DEFAULT_CHANNEL(WINDOWS
);
17 // The only global var here, used to mark mem pages as NLS in WinLdrSetupMemoryLayout()
18 ULONG TotalNLSSize
= 0;
21 WinLdrGetNLSNames(LPSTR AnsiName
,
26 WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead
,
27 IN LPCSTR DirectoryPath
);
30 /* FUNCTIONS **************************************************************/
33 WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock
,
34 IN LPCSTR DirectoryPath
,
38 CHAR FullHiveName
[256];
40 FILEINFORMATION FileInfo
;
42 ULONG_PTR HiveDataPhysical
;
43 PVOID HiveDataVirtual
;
47 /* Concatenate path and filename to get the full name */
48 strcpy(FullHiveName
, DirectoryPath
);
49 strcat(FullHiveName
, HiveName
);
50 //Print(L"Loading %s...\n", FullHiveName);
51 Status
= ArcOpen(FullHiveName
, OpenReadOnly
, &FileId
);
52 if (Status
!= ESUCCESS
)
54 UiMessageBox("Opening hive file failed!");
58 /* Get the file length */
59 Status
= ArcGetFileInformation(FileId
, &FileInfo
);
60 if (Status
!= ESUCCESS
)
63 UiMessageBox("Hive file has 0 size!");
66 HiveFileSize
= FileInfo
.EndingAddress
.LowPart
;
68 /* Round up the size to page boundary and alloc memory */
69 HiveDataPhysical
= (ULONG_PTR
)MmAllocateMemoryWithType(
70 MM_SIZE_TO_PAGES(HiveFileSize
+ MM_PAGE_SIZE
- 1) << MM_PAGE_SHIFT
,
73 if (HiveDataPhysical
== 0)
76 UiMessageBox("Unable to alloc memory for a hive!");
80 /* Convert address to virtual */
81 HiveDataVirtual
= PaToVa((PVOID
)HiveDataPhysical
);
83 /* Fill LoaderBlock's entries */
84 LoaderBlock
->RegistryLength
= HiveFileSize
;
85 LoaderBlock
->RegistryBase
= HiveDataVirtual
;
87 /* Finally read from file to the memory */
88 Status
= ArcRead(FileId
, (PVOID
)HiveDataPhysical
, HiveFileSize
, &BytesRead
);
89 if (Status
!= ESUCCESS
)
92 UiMessageBox("Unable to read from hive file!");
96 // Add boot filesystem driver to the list
97 FsService
= FsGetServiceName(FileId
);
101 TRACE(" Adding filesystem service %S\n", FsService
);
102 Success
= WinLdrAddDriverToList(&LoaderBlock
->BootDriverListHead
,
103 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
107 TRACE(" Failed to add filesystem service\n");
111 TRACE(" No required filesystem service\n");
118 BOOLEAN
WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock
,
119 IN LPCSTR DirectoryPath
)
121 CHAR SearchPath
[1024];
124 // There is a simple logic here: try to load usual hive (system), if it
125 // fails, then give system.alt a try, and finally try a system.sav
127 // FIXME: For now we only try system
128 strcpy(SearchPath
, DirectoryPath
);
129 strcat(SearchPath
, "SYSTEM32\\CONFIG\\");
130 Success
= WinLdrLoadSystemHive(LoaderBlock
, SearchPath
, "SYSTEM");
136 // Initialize in-memory registry
137 RegInitializeRegistry();
139 // Import what was loaded
140 Success
= RegImportBinaryHive((PCHAR
)VaToPa(LoaderBlock
->RegistryBase
), LoaderBlock
->RegistryLength
);
143 UiMessageBox("Importing binary hive failed!");
147 // Initialize the 'CurrentControlSet' link
148 if (RegInitCurrentControlSet(FALSE
) != ERROR_SUCCESS
)
150 UiMessageBox("Initializing CurrentControlSet link failed!");
157 BOOLEAN
WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock
,
158 IN LPCSTR DirectoryPath
)
160 CHAR SearchPath
[1024];
161 CHAR AnsiName
[256], OemName
[256], LangName
[256];
164 // Scan registry and prepare boot drivers list
165 WinLdrScanRegistry(&LoaderBlock
->BootDriverListHead
, DirectoryPath
);
167 // Get names of NLS files
168 Success
= WinLdrGetNLSNames(AnsiName
, OemName
, LangName
);
171 UiMessageBox("Getting NLS names from registry failed!");
175 TRACE("NLS data %s %s %s\n", AnsiName
, OemName
, LangName
);
178 strcpy(SearchPath
, DirectoryPath
);
179 strcat(SearchPath
, "SYSTEM32\\");
180 Success
= WinLdrLoadNLSData(LoaderBlock
, SearchPath
, AnsiName
, OemName
, LangName
);
181 TRACE("NLS data loading %s\n", Success
? "successful" : "failed");
183 /* TODO: Load OEM HAL font */
190 /* PRIVATE FUNCTIONS ******************************************************/
192 // Queries registry for those three file names
194 WinLdrGetNLSNames(LPSTR AnsiName
,
198 LONG rc
= ERROR_SUCCESS
;
200 WCHAR szIdBuffer
[80];
201 WCHAR NameBuffer
[80];
204 /* open the codepage key */
205 rc
= RegOpenKey(NULL
,
206 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
208 if (rc
!= ERROR_SUCCESS
)
210 //strcpy(szErrorOut, "Couldn't open CodePage registry key");
214 /* get ANSI codepage */
215 BufferSize
= sizeof(szIdBuffer
);
216 rc
= RegQueryValue(hKey
, L
"ACP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
217 if (rc
!= ERROR_SUCCESS
)
219 //strcpy(szErrorOut, "Couldn't get ACP NLS setting");
223 BufferSize
= sizeof(NameBuffer
);
224 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)NameBuffer
, &BufferSize
);
225 if (rc
!= ERROR_SUCCESS
)
227 //strcpy(szErrorOut, "ACP NLS Setting exists, but isn't readable");
229 wcscpy(NameBuffer
, L
"c_1252.nls"); // HACK: ReactOS bug #6727
231 sprintf(AnsiName
, "%S", NameBuffer
);
233 /* get OEM codepage */
234 BufferSize
= sizeof(szIdBuffer
);
235 rc
= RegQueryValue(hKey
, L
"OEMCP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
236 if (rc
!= ERROR_SUCCESS
)
238 //strcpy(szErrorOut, "Couldn't get OEMCP NLS setting");
242 BufferSize
= sizeof(NameBuffer
);
243 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)NameBuffer
, &BufferSize
);
244 if (rc
!= ERROR_SUCCESS
)
246 //strcpy(szErrorOut, "OEMCP NLS setting exists, but isn't readable");
248 wcscpy(NameBuffer
, L
"c_437.nls"); // HACK: ReactOS bug #6727
250 sprintf(OemName
, "%S", NameBuffer
);
252 /* open the language key */
253 rc
= RegOpenKey(NULL
,
254 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
256 if (rc
!= ERROR_SUCCESS
)
258 //strcpy(szErrorOut, "Couldn't open Language registry key");
262 /* get the Unicode case table */
263 BufferSize
= sizeof(szIdBuffer
);
264 rc
= RegQueryValue(hKey
, L
"Default", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
265 if (rc
!= ERROR_SUCCESS
)
267 //strcpy(szErrorOut, "Couldn't get Language Default setting");
271 BufferSize
= sizeof(NameBuffer
);
272 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)NameBuffer
, &BufferSize
);
273 if (rc
!= ERROR_SUCCESS
)
275 //strcpy(szErrorOut, "Language Default setting exists, but isn't readable");
278 sprintf(LangName
, "%S", NameBuffer
);
284 WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock
,
285 IN LPCSTR DirectoryPath
,
286 IN LPCSTR AnsiFileName
,
287 IN LPCSTR OemFileName
,
288 IN LPCSTR LanguageFileName
)
293 ULONG LanguageFileId
;
294 ULONG AnsiFileSize
, OemFileSize
, LanguageFileSize
;
296 ULONG_PTR NlsDataBase
;
298 BOOLEAN AnsiEqualsOem
= FALSE
;
299 FILEINFORMATION FileInfo
;
303 /* There may be a case, when OEM and ANSI page coincide */
304 if (!strcmp(AnsiFileName
, OemFileName
))
305 AnsiEqualsOem
= TRUE
;
307 /* Open file with ANSI and store its size */
308 //Print(L"Loading %s...\n", Filename);
309 strcpy(FileName
, DirectoryPath
);
310 strcat(FileName
, AnsiFileName
);
311 Status
= ArcOpen(FileName
, OpenReadOnly
, &AnsiFileId
);
312 if (Status
!= ESUCCESS
)
315 Status
= ArcGetFileInformation(AnsiFileId
, &FileInfo
);
316 if (Status
!= ESUCCESS
)
318 AnsiFileSize
= FileInfo
.EndingAddress
.LowPart
;
319 TRACE("AnsiFileSize: %d\n", AnsiFileSize
);
320 ArcClose(AnsiFileId
);
322 /* Open OEM file and store its length */
329 //Print(L"Loading %s...\n", Filename);
330 strcpy(FileName
, DirectoryPath
);
331 strcat(FileName
, OemFileName
);
332 Status
= ArcOpen(FileName
, OpenReadOnly
, &OemFileId
);
333 if (Status
!= ESUCCESS
)
336 Status
= ArcGetFileInformation(OemFileId
, &FileInfo
);
337 if (Status
!= ESUCCESS
)
339 OemFileSize
= FileInfo
.EndingAddress
.LowPart
;
342 TRACE("OemFileSize: %d\n", OemFileSize
);
344 /* And finally open the language codepage file and store its length */
345 //Print(L"Loading %s...\n", Filename);
346 strcpy(FileName
, DirectoryPath
);
347 strcat(FileName
, LanguageFileName
);
348 Status
= ArcOpen(FileName
, OpenReadOnly
, &LanguageFileId
);
349 if (Status
!= ESUCCESS
)
352 Status
= ArcGetFileInformation(LanguageFileId
, &FileInfo
);
353 if (Status
!= ESUCCESS
)
355 LanguageFileSize
= FileInfo
.EndingAddress
.LowPart
;
356 ArcClose(LanguageFileId
);
357 TRACE("LanguageFileSize: %d\n", LanguageFileSize
);
359 /* Sum up all three length, having in mind that every one of them
360 must start at a page boundary => thus round up each file to a page */
361 TotalSize
= MM_SIZE_TO_PAGES(AnsiFileSize
) +
362 MM_SIZE_TO_PAGES(OemFileSize
) +
363 MM_SIZE_TO_PAGES(LanguageFileSize
);
365 /* Store it for later marking the pages as NlsData type */
366 TotalNLSSize
= TotalSize
;
368 NlsDataBase
= (ULONG_PTR
)MmAllocateMemoryWithType(TotalSize
*MM_PAGE_SIZE
, LoaderNlsData
);
370 if (NlsDataBase
== 0)
373 NlsVirtual
= PaToVa((PVOID
)NlsDataBase
);
374 LoaderBlock
->NlsData
->AnsiCodePageData
= NlsVirtual
;
375 LoaderBlock
->NlsData
->OemCodePageData
= (PVOID
)((PUCHAR
)NlsVirtual
+
376 (MM_SIZE_TO_PAGES(AnsiFileSize
) << MM_PAGE_SHIFT
));
377 LoaderBlock
->NlsData
->UnicodeCodePageData
= (PVOID
)((PUCHAR
)NlsVirtual
+
378 (MM_SIZE_TO_PAGES(AnsiFileSize
) << MM_PAGE_SHIFT
) +
379 (MM_SIZE_TO_PAGES(OemFileSize
) << MM_PAGE_SHIFT
));
381 /* Ansi and OEM data are the same - just set pointers to the same area */
383 LoaderBlock
->NlsData
->OemCodePageData
= LoaderBlock
->NlsData
->AnsiCodePageData
;
386 /* Now actually read the data into memory, starting with Ansi file */
387 strcpy(FileName
, DirectoryPath
);
388 strcat(FileName
, AnsiFileName
);
389 Status
= ArcOpen(FileName
, OpenReadOnly
, &AnsiFileId
);
390 if (Status
!= ESUCCESS
)
393 Status
= ArcRead(AnsiFileId
, VaToPa(LoaderBlock
->NlsData
->AnsiCodePageData
), AnsiFileSize
, &BytesRead
);
394 if (Status
!= ESUCCESS
)
397 ArcClose(AnsiFileId
);
399 /* OEM now, if it doesn't equal Ansi of course */
402 strcpy(FileName
, DirectoryPath
);
403 strcat(FileName
, OemFileName
);
404 Status
= ArcOpen(FileName
, OpenReadOnly
, &OemFileId
);
405 if (Status
!= ESUCCESS
)
408 Status
= ArcRead(OemFileId
, VaToPa(LoaderBlock
->NlsData
->OemCodePageData
), OemFileSize
, &BytesRead
);
409 if (Status
!= ESUCCESS
)
415 /* finally the language file */
416 strcpy(FileName
, DirectoryPath
);
417 strcat(FileName
, LanguageFileName
);
418 Status
= ArcOpen(FileName
, OpenReadOnly
, &LanguageFileId
);
419 if (Status
!= ESUCCESS
)
422 Status
= ArcRead(LanguageFileId
, VaToPa(LoaderBlock
->NlsData
->UnicodeCodePageData
), LanguageFileSize
, &BytesRead
);
423 if (Status
!= ESUCCESS
)
426 ArcClose(LanguageFileId
);
429 // THIS IS HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACK
430 // Should go to WinLdrLoadOemHalFont(), when it will be implemented
432 LoaderBlock
->OemFontFile
= VaToPa(LoaderBlock
->NlsData
->UnicodeCodePageData
);
434 /* Convert NlsTables address to VA */
435 LoaderBlock
->NlsData
= PaToVa(LoaderBlock
->NlsData
);
440 UiMessageBox("Error reading NLS file %s", FileName
);
445 WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead
,
446 IN LPCSTR DirectoryPath
)
449 HKEY hGroupKey
, hOrderKey
, hServiceKey
, hDriverKey
;
450 LPWSTR GroupNameBuffer
;
451 WCHAR ServiceName
[256];
452 ULONG OrderList
[128];
462 WCHAR DriverGroup
[256];
463 ULONG DriverGroupSize
;
466 WCHAR TempImagePath
[256];
470 /* get 'service group order' key */
471 rc
= RegOpenKey(NULL
,
472 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
474 if (rc
!= ERROR_SUCCESS
) {
476 TRACE_CH(REACTOS
, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc
);
480 /* get 'group order list' key */
481 rc
= RegOpenKey(NULL
,
482 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
484 if (rc
!= ERROR_SUCCESS
) {
486 TRACE_CH(REACTOS
, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc
);
490 /* enumerate drivers */
491 rc
= RegOpenKey(NULL
,
492 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
494 if (rc
!= ERROR_SUCCESS
) {
496 TRACE_CH(REACTOS
, "Failed to open the 'Services' key (rc %d)\n", (int)rc
);
500 /* Get the Name Group */
502 GroupNameBuffer
= FrLdrHeapAlloc(BufferSize
, TAG_WLDR_NAME
);
503 rc
= RegQueryValue(hGroupKey
, L
"List", NULL
, (PUCHAR
)GroupNameBuffer
, &BufferSize
);
504 TRACE_CH(REACTOS
, "RegQueryValue(): rc %d\n", (int)rc
);
505 if (rc
!= ERROR_SUCCESS
)
507 TRACE_CH(REACTOS
, "BufferSize: %d \n", (int)BufferSize
);
508 TRACE_CH(REACTOS
, "GroupNameBuffer: '%S' \n", GroupNameBuffer
);
510 /* Loop through each group */
511 GroupName
= GroupNameBuffer
;
514 TRACE("Driver group: '%S'\n", GroupName
);
516 /* Query the Order */
517 BufferSize
= sizeof(OrderList
);
518 rc
= RegQueryValue(hOrderKey
, GroupName
, NULL
, (PUCHAR
)OrderList
, &BufferSize
);
519 if (rc
!= ERROR_SUCCESS
) OrderList
[0] = 0;
521 /* enumerate all drivers */
522 for (TagIndex
= 1; TagIndex
<= OrderList
[0]; TagIndex
++)
528 /* Get the Driver's Name */
529 ValueSize
= sizeof(ServiceName
);
530 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
, &hDriverKey
);
531 TRACE("RegEnumKey(): rc %d\n", (int)rc
);
533 /* Make sure it's valid, and check if we're done */
534 if (rc
== ERROR_NO_MORE_ITEMS
)
536 if (rc
!= ERROR_SUCCESS
)
538 FrLdrHeapFree(GroupNameBuffer
, TAG_WLDR_NAME
);
541 //TRACE_CH(REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName);
543 /* Read the Start Value */
544 ValueSize
= sizeof(ULONG
);
545 rc
= RegQueryValue(hDriverKey
, L
"Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
546 if (rc
!= ERROR_SUCCESS
) StartValue
= (ULONG
)-1;
547 //TRACE_CH(REACTOS, " Start: %x \n", (int)StartValue);
550 ValueSize
= sizeof(ULONG
);
551 rc
= RegQueryValue(hDriverKey
, L
"Tag", &ValueType
, (PUCHAR
)&TagValue
, &ValueSize
);
552 if (rc
!= ERROR_SUCCESS
) TagValue
= (ULONG
)-1;
553 //TRACE_CH(REACTOS, " Tag: %x \n", (int)TagValue);
555 /* Read the driver's group */
556 DriverGroupSize
= sizeof(DriverGroup
);
557 rc
= RegQueryValue(hDriverKey
, L
"Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
558 //TRACE_CH(REACTOS, " Group: '%S' \n", DriverGroup);
560 /* Make sure it should be started */
561 if ((StartValue
== 0) &&
562 (TagValue
== OrderList
[TagIndex
]) &&
563 (_wcsicmp(DriverGroup
, GroupName
) == 0))
565 /* Get the Driver's Location */
566 ValueSize
= sizeof(TempImagePath
);
567 rc
= RegQueryValue(hDriverKey
, L
"ImagePath", NULL
, (PUCHAR
)TempImagePath
, &ValueSize
);
569 /* Write the whole path if it suceeded, else prepare to fail */
570 if (rc
!= ERROR_SUCCESS
)
572 TRACE_CH(REACTOS
, "ImagePath: not found\n");
573 TempImagePath
[0] = 0;
574 sprintf(ImagePath
, "%s\\system32\\drivers\\%S.sys", DirectoryPath
, ServiceName
);
576 else if (TempImagePath
[0] != L
'\\')
578 sprintf(ImagePath
, "%s%S", DirectoryPath
, TempImagePath
);
582 sprintf(ImagePath
, "%S", TempImagePath
);
583 TRACE_CH(REACTOS
, "ImagePath: '%s'\n", ImagePath
);
586 TRACE("Adding boot driver: '%s'\n", ImagePath
);
588 Success
= WinLdrAddDriverToList(BootDriverListHead
,
589 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
593 ERR("Failed to add boot driver\n");
597 //TRACE(" Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
598 // ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName);
608 /* Get the Driver's Name */
609 ValueSize
= sizeof(ServiceName
);
610 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
, &hDriverKey
);
612 //TRACE_CH(REACTOS, "RegEnumKey(): rc %d\n", (int)rc);
613 if (rc
== ERROR_NO_MORE_ITEMS
)
615 if (rc
!= ERROR_SUCCESS
)
617 FrLdrHeapFree(GroupNameBuffer
, TAG_WLDR_NAME
);
620 TRACE("Service %d: '%S'\n", (int)Index
, ServiceName
);
622 /* Read the Start Value */
623 ValueSize
= sizeof(ULONG
);
624 rc
= RegQueryValue(hDriverKey
, L
"Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
625 if (rc
!= ERROR_SUCCESS
) StartValue
= (ULONG
)-1;
626 //TRACE_CH(REACTOS, " Start: %x \n", (int)StartValue);
629 ValueSize
= sizeof(ULONG
);
630 rc
= RegQueryValue(hDriverKey
, L
"Tag", &ValueType
, (PUCHAR
)&TagValue
, &ValueSize
);
631 if (rc
!= ERROR_SUCCESS
) TagValue
= (ULONG
)-1;
632 //TRACE_CH(REACTOS, " Tag: %x \n", (int)TagValue);
634 /* Read the driver's group */
635 DriverGroupSize
= sizeof(DriverGroup
);
636 rc
= RegQueryValue(hDriverKey
, L
"Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
637 //TRACE_CH(REACTOS, " Group: '%S' \n", DriverGroup);
639 for (TagIndex
= 1; TagIndex
<= OrderList
[0]; TagIndex
++)
641 if (TagValue
== OrderList
[TagIndex
]) break;
644 if ((StartValue
== 0) &&
645 (TagIndex
> OrderList
[0]) &&
646 (_wcsicmp(DriverGroup
, GroupName
) == 0))
648 ValueSize
= sizeof(TempImagePath
);
649 rc
= RegQueryValue(hDriverKey
, L
"ImagePath", NULL
, (PUCHAR
)TempImagePath
, &ValueSize
);
650 if (rc
!= ERROR_SUCCESS
)
652 TRACE_CH(REACTOS
, "ImagePath: not found\n");
653 TempImagePath
[0] = 0;
654 sprintf(ImagePath
, "%ssystem32\\drivers\\%S.sys", DirectoryPath
, ServiceName
);
656 else if (TempImagePath
[0] != L
'\\')
658 sprintf(ImagePath
, "%s%S", DirectoryPath
, TempImagePath
);
662 sprintf(ImagePath
, "%S", TempImagePath
);
663 TRACE_CH(REACTOS
, "ImagePath: '%s'\n", ImagePath
);
665 TRACE(" Adding boot driver: '%s'\n", ImagePath
);
667 Success
= WinLdrAddDriverToList(BootDriverListHead
,
668 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
672 ERR(" Failed to add boot driver\n");
676 //TRACE(" Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
677 // ServiceName, StartValue, TagValue, DriverGroup, GroupName);
683 /* Move to the next group name */
684 GroupName
= GroupName
+ wcslen(GroupName
) + 1;
687 /* Free allocated memory */
688 FrLdrHeapFree(GroupNameBuffer
, TAG_WLDR_NAME
);
692 WinLdrAddDriverToList(LIST_ENTRY
*BootDriverListHead
,
697 PBOOT_DRIVER_LIST_ENTRY BootDriverEntry
;
701 BootDriverEntry
= FrLdrHeapAlloc(sizeof(BOOT_DRIVER_LIST_ENTRY
), TAG_WLDR_BDE
);
703 if (!BootDriverEntry
)
706 // DTE will be filled during actual load of the driver
707 BootDriverEntry
->LdrEntry
= NULL
;
709 // Check - if we have a valid ImagePath, if not - we need to build it
710 // like "System32\\Drivers\\blah.sys"
711 if (ImagePath
&& (wcslen(ImagePath
) > 0))
713 // Just copy ImagePath to the corresponding field in the structure
714 PathLength
= (USHORT
)wcslen(ImagePath
) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
);
716 BootDriverEntry
->FilePath
.Length
= 0;
717 BootDriverEntry
->FilePath
.MaximumLength
= PathLength
;
718 BootDriverEntry
->FilePath
.Buffer
= FrLdrHeapAlloc(PathLength
, TAG_WLDR_NAME
);
720 if (!BootDriverEntry
->FilePath
.Buffer
)
722 FrLdrHeapFree(BootDriverEntry
, TAG_WLDR_BDE
);
726 Status
= RtlAppendUnicodeToString(&BootDriverEntry
->FilePath
, ImagePath
);
727 if (!NT_SUCCESS(Status
))
729 FrLdrHeapFree(BootDriverEntry
->FilePath
.Buffer
, TAG_WLDR_NAME
);
730 FrLdrHeapFree(BootDriverEntry
, TAG_WLDR_BDE
);
736 // we have to construct ImagePath ourselves
737 PathLength
= (USHORT
)wcslen(ServiceName
)*sizeof(WCHAR
) + sizeof(L
"system32\\drivers\\.sys");
738 BootDriverEntry
->FilePath
.Length
= 0;
739 BootDriverEntry
->FilePath
.MaximumLength
= PathLength
;
740 BootDriverEntry
->FilePath
.Buffer
= FrLdrHeapAlloc(PathLength
, TAG_WLDR_NAME
);
742 if (!BootDriverEntry
->FilePath
.Buffer
)
744 FrLdrHeapFree(BootDriverEntry
, TAG_WLDR_NAME
);
748 Status
= RtlAppendUnicodeToString(&BootDriverEntry
->FilePath
, L
"system32\\drivers\\");
749 if (!NT_SUCCESS(Status
))
751 FrLdrHeapFree(BootDriverEntry
->FilePath
.Buffer
, TAG_WLDR_NAME
);
752 FrLdrHeapFree(BootDriverEntry
, TAG_WLDR_NAME
);
756 Status
= RtlAppendUnicodeToString(&BootDriverEntry
->FilePath
, ServiceName
);
757 if (!NT_SUCCESS(Status
))
759 FrLdrHeapFree(BootDriverEntry
->FilePath
.Buffer
, TAG_WLDR_NAME
);
760 FrLdrHeapFree(BootDriverEntry
, TAG_WLDR_NAME
);
764 Status
= RtlAppendUnicodeToString(&BootDriverEntry
->FilePath
, L
".sys");
765 if (!NT_SUCCESS(Status
))
767 FrLdrHeapFree(BootDriverEntry
->FilePath
.Buffer
, TAG_WLDR_NAME
);
768 FrLdrHeapFree(BootDriverEntry
, TAG_WLDR_NAME
);
774 PathLength
= (USHORT
)(wcslen(RegistryPath
) + wcslen(ServiceName
))*sizeof(WCHAR
) + sizeof(UNICODE_NULL
);
775 BootDriverEntry
->RegistryPath
.Length
= 0;
776 BootDriverEntry
->RegistryPath
.MaximumLength
= PathLength
;
777 BootDriverEntry
->RegistryPath
.Buffer
= FrLdrHeapAlloc(PathLength
, TAG_WLDR_NAME
);
778 if (!BootDriverEntry
->RegistryPath
.Buffer
)
781 Status
= RtlAppendUnicodeToString(&BootDriverEntry
->RegistryPath
, RegistryPath
);
782 if (!NT_SUCCESS(Status
))
785 Status
= RtlAppendUnicodeToString(&BootDriverEntry
->RegistryPath
, ServiceName
);
786 if (!NT_SUCCESS(Status
))
789 // Insert entry at top of the list
790 InsertTailList(BootDriverListHead
, &BootDriverEntry
->Link
);