ReactOS 0.4.15-dev-6055-g36cdd34
registry.h File Reference
#include <cmlib.h>
Include dependency graph for registry.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HKEY_TO_HCI(hKey)   ((HCELL_INDEX)(ULONG_PTR)(hKey))
 
#define RegCloseKey(hKey)   (ERROR_SUCCESS)
 

Typedefs

typedef HANDLE HKEY
 
typedef HANDLEPHKEY
 

Functions

BOOLEAN RegImportBinaryHive (_In_ PVOID ChunkBase, _In_ ULONG ChunkSize)
 
BOOLEAN RegInitCurrentControlSet (_In_ BOOLEAN LastKnownGood)
 
LONG RegOpenKey (_In_ HKEY ParentKey, _In_z_ PCWSTR KeyName, _Out_ PHKEY Key)
 
LONG RegQueryValue (_In_ HKEY Key, _In_z_ PCWSTR ValueName, _Out_opt_ PULONG Type, _Out_opt_ PUCHAR Data, _Inout_opt_ PULONG DataSize)
 

Variables

PHHIVE SystemHive
 
HKEY CurrentControlSetKey
 

Macro Definition Documentation

◆ HKEY_TO_HCI

#define HKEY_TO_HCI (   hKey)    ((HCELL_INDEX)(ULONG_PTR)(hKey))

Definition at line 28 of file registry.h.

◆ RegCloseKey

#define RegCloseKey (   hKey)    (ERROR_SUCCESS)

Definition at line 47 of file registry.h.

Typedef Documentation

◆ HKEY

typedef HANDLE HKEY

Definition at line 26 of file registry.h.

◆ PHKEY

typedef HANDLE * PHKEY

Definition at line 26 of file registry.h.

Function Documentation

◆ RegImportBinaryHive()

BOOLEAN RegImportBinaryHive ( _In_ PVOID  ChunkBase,
_In_ ULONG  ChunkSize 
)

Definition at line 66 of file registry.c.

69{
71 PCM_KEY_NODE KeyNode;
72
73 TRACE("RegImportBinaryHive(%p, 0x%lx)\n", ChunkBase, ChunkSize);
74
75 /* Allocate and initialize the hive */
76 CmSystemHive = FrLdrTempAlloc(sizeof(CMHIVE), 'eviH');
78 HINIT_FLAT, // HINIT_MEMORY_INPLACE
79 0,
80 0,
81 ChunkBase,
83 CmpFree,
84 NULL,
85 NULL,
86 NULL,
87 NULL,
88 1,
89 NULL);
90 if (!NT_SUCCESS(Status))
91 {
92 ERR("Corrupted hive %p!\n", ChunkBase);
94 return FALSE;
95 }
96
97 /* Save the root key node */
101
102 /* Verify it is accessible */
104 ASSERT(KeyNode);
107
108 return TRUE;
109}
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: debug.h:110
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197
VOID NTAPI CmpFree(IN PVOID Ptr, IN ULONG Quota)
Definition: registry.c:57
#define GET_HHIVE(CmHive)
Definition: registry.c:40
static PCMHIVE CmSystemHive
Definition: registry.c:29
PHHIVE SystemHive
Definition: registry.c:32
static HCELL_INDEX SystemRootCell
Definition: registry.c:30
PVOID NTAPI CmpAllocate(IN SIZE_T Size, IN BOOLEAN Paged, IN ULONG Tag)
Definition: registry.c:46
struct _CM_KEY_NODE * PCM_KEY_NODE
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(Hive, Cell)
Definition: cmlib.h:384
NTSTATUS CMAPI HvInitialize(PHHIVE RegistryHive, ULONG OperationType, ULONG HiveFlags, ULONG FileType, PVOID HiveData OPTIONAL, PALLOCATE_ROUTINE Allocate, PFREE_ROUTINE Free, PFILE_SET_SIZE_ROUTINE FileSetSize, PFILE_WRITE_ROUTINE FileWrite, PFILE_READ_ROUTINE FileRead, PFILE_FLUSH_ROUTINE FileFlush, ULONG Cluster OPTIONAL, PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:522
#define HvGetCell(Hive, Cell)
Definition: cmlib.h:381
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
#define HINIT_FLAT
Definition: hivedata.h:17
#define HCELL_NIL
Definition: hivedata.h:85
#define ASSERT(a)
Definition: mode.c:44
#define TRACE(s)
Definition: solgame.cpp:4
Definition: cmlib.h:245
USHORT Signature
Definition: cmdata.h:92
HCELL_INDEX RootCell
Definition: hivedata.h:143
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2277

Referenced by WinLdrInitSystemHive().

◆ RegInitCurrentControlSet()

BOOLEAN RegInitCurrentControlSet ( _In_ BOOLEAN  LastKnownGood)

Definition at line 112 of file registry.c.

114{
115 UNICODE_STRING ControlSetName;
116 HCELL_INDEX ControlCell;
117 PCM_KEY_NODE KeyNode;
118 BOOLEAN AutoSelect;
119
120 TRACE("RegInitCurrentControlSet\n");
121
122 /* Choose which control set to open and set it as the new "Current" */
123 RtlInitUnicodeString(&ControlSetName,
124 LastKnownGood ? L"LastKnownGood"
125 : L"Default");
126
127 ControlCell = CmpFindControlSet(SystemHive,
129 &ControlSetName,
130 &AutoSelect);
131 if (ControlCell == HCELL_NIL)
132 {
133 ERR("CmpFindControlSet('%wZ') failed\n", &ControlSetName);
134 return FALSE;
135 }
136
137 CurrentControlSetKey = HCI_TO_HKEY(ControlCell);
138
139 /* Verify it is accessible */
140 KeyNode = (PCM_KEY_NODE)HvGetCell(SystemHive, ControlCell);
141 ASSERT(KeyNode);
143 HvReleaseCell(SystemHive, ControlCell);
144
145 return TRUE;
146}
unsigned char BOOLEAN
HKEY CurrentControlSetKey
Definition: registry.c:33
#define HCI_TO_HKEY(CellIndex)
Definition: registry.c:35
HCELL_INDEX NTAPI CmpFindControlSet(_In_ PHHIVE SystemHive, _In_ HCELL_INDEX RootCell, _In_ PCUNICODE_STRING SelectKeyName, _Out_ PBOOLEAN AutoSelect)
Finds the corresponding "HKLM\SYSTEM\ControlSetXXX" system control set registry key,...
Definition: cmboot.c:84
ULONG HCELL_INDEX
Definition: hivedata.h:80
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define L(x)
Definition: ntvdm.h:50

Referenced by WinLdrInitSystemHive().

◆ RegOpenKey()

LONG RegOpenKey ( _In_ HKEY  ParentKey,
_In_z_ PCWSTR  KeyName,
_Out_ PHKEY  Key 
)

Definition at line 263 of file registry.c.

267{
268 UNICODE_STRING RemainingPath, SubKeyName;
269 UNICODE_STRING CurrentControlSet = RTL_CONSTANT_STRING(L"CurrentControlSet");
271 PCM_KEY_NODE KeyNode;
272 HCELL_INDEX CellIndex;
273
274 TRACE("RegOpenKey(%p, '%S', %p)\n", ParentKey, KeyName, Key);
275
276 /* Initialize the remaining path name */
277 RtlInitUnicodeString(&RemainingPath, KeyName);
278
279 /* Check if we have a parent key */
280 if (ParentKey == NULL)
281 {
282 UNICODE_STRING SubKeyName1, SubKeyName2, SubKeyName3;
284 UNICODE_STRING MachinePath = RTL_CONSTANT_STRING(L"MACHINE");
285 UNICODE_STRING SystemPath = RTL_CONSTANT_STRING(L"SYSTEM");
286
287 TRACE("RegOpenKey: absolute path\n");
288
289 if ((RemainingPath.Length < sizeof(WCHAR)) ||
290 RemainingPath.Buffer[0] != '\\')
291 {
292 /* The key path is not absolute */
293 ERR("RegOpenKey: invalid path '%S' (%wZ)\n", KeyName, &RemainingPath);
295 }
296
297 /* Skip initial path separator */
298 RemainingPath.Buffer++;
299 RemainingPath.Length -= sizeof(WCHAR);
300
301 /* Get the first 3 path elements */
302 GetNextPathElement(&SubKeyName1, &RemainingPath);
303 GetNextPathElement(&SubKeyName2, &RemainingPath);
304 GetNextPathElement(&SubKeyName3, &RemainingPath);
305 TRACE("RegOpenKey: %wZ / %wZ / %wZ\n", &SubKeyName1, &SubKeyName2, &SubKeyName3);
306
307 /* Check if we have the correct path */
308 if (!RtlEqualUnicodeString(&SubKeyName1, &RegistryPath, TRUE) ||
309 !RtlEqualUnicodeString(&SubKeyName2, &MachinePath, TRUE) ||
310 !RtlEqualUnicodeString(&SubKeyName3, &SystemPath, TRUE))
311 {
312 /* The key path is not inside HKLM\Machine\System */
313 ERR("RegOpenKey: invalid path '%S' (%wZ)\n", KeyName, &RemainingPath);
315 }
316
317 /* Use the root key */
318 CellIndex = SystemRootCell;
319 }
320 else
321 {
322 /* Use the parent key */
323 CellIndex = HKEY_TO_HCI(ParentKey);
324 }
325
326 /* Check if this is the root key */
327 if (CellIndex == SystemRootCell)
328 {
329 UNICODE_STRING TempPath = RemainingPath;
330
331 /* Get the first path element */
332 GetNextPathElement(&SubKeyName, &TempPath);
333
334 /* Check if this is CurrentControlSet */
335 if (RtlEqualUnicodeString(&SubKeyName, &CurrentControlSet, TRUE))
336 {
337 /* Use the CurrentControlSetKey and update the remaining path */
339 RemainingPath = TempPath;
340 }
341 }
342
343 /* Get the key node */
344 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, CellIndex);
345 ASSERT(KeyNode);
347
348 TRACE("RegOpenKey: RemainingPath '%wZ'\n", &RemainingPath);
349
350 /* Loop while there are path elements */
351 while (GetNextPathElement(&SubKeyName, &RemainingPath))
352 {
353 HCELL_INDEX NextCellIndex;
354
355 TRACE("RegOpenKey: next element '%wZ'\n", &SubKeyName);
356
357 /* Get the next sub key */
358 NextCellIndex = CmpFindSubKeyByName(Hive, KeyNode, &SubKeyName);
359 HvReleaseCell(Hive, CellIndex);
360 CellIndex = NextCellIndex;
361 if (CellIndex == HCELL_NIL)
362 {
363 WARN("Did not find sub key '%wZ' (full: %S)\n", &SubKeyName, KeyName);
365 }
366
367 /* Get the found key */
368 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, CellIndex);
369 ASSERT(KeyNode);
371 }
372
373 HvReleaseCell(Hive, CellIndex);
374 *Key = HCI_TO_HKEY(CellIndex);
375
376 return ERROR_SUCCESS;
377}
#define WARN(fmt,...)
Definition: debug.h:112
static BOOLEAN GetNextPathElement(_Out_ PUNICODE_STRING NextElement, _Inout_ PUNICODE_STRING RemainingPath)
Definition: registry.c:150
#define GET_HHIVE_FROM_HKEY(hKey)
Definition: registry.c:41
#define HKEY_TO_HCI(hKey)
Definition: registry.h:28
HCELL_INDEX NTAPI CmpFindSubKeyByName(IN PHHIVE Hive, IN PCM_KEY_NODE Parent, IN PCUNICODE_STRING SearchName)
Definition: cmindex.c:683
#define ERROR_SUCCESS
Definition: deptool.c:10
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING SubKeyName
Definition: ndis.h:4725
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ RegQueryValue()

LONG RegQueryValue ( _In_ HKEY  Key,
_In_z_ PCWSTR  ValueName,
_Out_opt_ PULONG  Type,
_Out_opt_ PUCHAR  Data,
_Inout_opt_ PULONG  DataSize 
)

Definition at line 418 of file registry.c.

424{
426 PCM_KEY_NODE KeyNode;
427 PCM_KEY_VALUE ValueCell;
428 HCELL_INDEX CellIndex;
429 UNICODE_STRING ValueNameString;
430
431 TRACE("RegQueryValue(%p, '%S', %p, %p, %p)\n",
433
434 /* Get the key node */
435 KeyNode = GET_CM_KEY_NODE(Hive, Key);
436 ASSERT(KeyNode);
438
439 /* Initialize value name string */
440 RtlInitUnicodeString(&ValueNameString, ValueName);
441 CellIndex = CmpFindValueByName(Hive, KeyNode, &ValueNameString);
442 if (CellIndex == HCELL_NIL)
443 {
444 TRACE("RegQueryValue value not found in key (%.*s)\n",
445 KeyNode->NameLength, KeyNode->Name);
448 }
450
451 /* Get the value cell */
452 ValueCell = (PCM_KEY_VALUE)HvGetCell(Hive, CellIndex);
453 ASSERT(ValueCell != NULL);
454
455 RepGetValueData(Hive, ValueCell, Type, Data, DataSize);
456
457 HvReleaseCell(Hive, CellIndex);
458
459 return ERROR_SUCCESS;
460}
Type
Definition: Type.h:7
#define GET_CM_KEY_NODE(hHive, hKey)
Definition: registry.c:42
struct _CM_KEY_VALUE * PCM_KEY_VALUE
HCELL_INDEX NTAPI CmpFindValueByName(IN PHHIVE Hive, IN PCM_KEY_NODE KeyNode, IN PCUNICODE_STRING Name)
Definition: cmvalue.c:99
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
static VOID RepGetValueData(IN PHHIVE Hive, IN PCM_KEY_VALUE ValueCell, OUT PULONG Type OPTIONAL, OUT PUCHAR Data OPTIONAL, IN OUT PULONG DataSize OPTIONAL)
Definition: registry.c:824
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:116
USHORT NameLength
Definition: cmdata.h:114
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243

Variable Documentation

◆ CurrentControlSetKey

◆ SystemHive