2 * PROJECT: EFI Windows Loader
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: freeldr/winldr/wlregistry.c
5 * PURPOSE: Registry support functions
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
9 /* INCLUDES ***************************************************************/
16 /* FUNCTIONS **************************************************************/
19 WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock
,
20 IN LPCSTR DirectoryPath
,
24 CHAR FullHiveName
[256];
27 ULONG_PTR HiveDataPhysical
;
28 PVOID HiveDataVirtual
;
30 /* Concatenate path and filename to get the full name */
31 strcpy(FullHiveName
, DirectoryPath
);
32 strcat(FullHiveName
, HiveName
);
33 //Print(L"Loading %s...\n", FullHiveName);
34 FileHandle
= FsOpenFile(FullHiveName
);
36 if (FileHandle
== NULL
)
38 UiMessageBox("Opening hive file failed!");
42 /* Get the file length */
43 HiveFileSize
= FsGetFileSize(FileHandle
);
45 if (HiveFileSize
== 0)
47 FsCloseFile(FileHandle
);
48 UiMessageBox("Hive file has 0 size!");
52 /* Round up the size to page boundary and alloc memory */
53 HiveDataPhysical
= (ULONG_PTR
)MmAllocateMemory(
54 MM_SIZE_TO_PAGES(HiveFileSize
+ MM_PAGE_SIZE
- 1) << MM_PAGE_SHIFT
);
56 if (HiveDataPhysical
== 0)
58 FsCloseFile(FileHandle
);
59 UiMessageBox("Unable to alloc memory for a hive!");
63 /* Convert address to virtual */
64 HiveDataVirtual
= (PVOID
)(KSEG0_BASE
| HiveDataPhysical
);
66 /* Fill LoaderBlock's entries */
67 LoaderBlock
->RegistryLength
= HiveFileSize
;
68 LoaderBlock
->RegistryBase
= HiveDataVirtual
;
70 /* Finally read from file to the memory */
71 Status
= FsReadFile(FileHandle
, HiveFileSize
, NULL
, (PVOID
)HiveDataPhysical
);
72 FsCloseFile(FileHandle
);
75 UiMessageBox("Unable to read from hive file!");
83 BOOLEAN
WinLdrLoadAndScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock
,
84 IN LPCSTR DirectoryPath
)
86 CHAR SearchPath
[1024];
89 // There is a simple logic here: try to load usual hive (system), if it
90 // fails, then give system.alt a try, and finally try a system.sav
92 // FIXME: For now we only try system
93 strcpy(SearchPath
, DirectoryPath
);
94 strcat(SearchPath
, "SYSTEM32\\CONFIG\\");
95 Status
= WinLdrLoadSystemHive(LoaderBlock
, SearchPath
, "SYSTEM");