ReactOS  0.4.14-dev-55-g2da92ac
registry.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef HANDLE HKEY
 
typedef HANDLEPHKEY
 

Functions

BOOLEAN RegImportBinaryHive (_In_ PVOID ChunkBase, _In_ ULONG ChunkSize)
 
LONG RegInitCurrentControlSet (_In_ BOOLEAN LastKnownGood)
 
LONG RegEnumKey (_In_ HKEY Key, _In_ ULONG Index, _Out_ PWCHAR Name, _Inout_ PULONG NameSize, _Out_opt_ PHKEY SubKey)
 
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)
 

Typedef Documentation

◆ HKEY

typedef HANDLE HKEY

Definition at line 24 of file registry.h.

◆ PHKEY

typedef HANDLE * PHKEY

Definition at line 24 of file registry.h.

Function Documentation

◆ RegEnumKey()

LONG RegEnumKey ( _In_ HKEY  Key,
_In_ ULONG  Index,
_Out_ PWCHAR  Name,
_Inout_ PULONG  NameSize,
_Out_opt_ PHKEY  SubKey 
)

Definition at line 224 of file registry.c.

230 {
231  PHHIVE Hive = &CmHive->Hive;
232  PCM_KEY_NODE KeyNode, SubKeyNode;
233  HCELL_INDEX CellIndex;
234  USHORT NameLength;
235 
236  TRACE("RegEnumKey(%p, %lu, %p, %p->%u)\n",
237  Key, Index, Name, NameSize, NameSize ? *NameSize : 0);
238 
239  /* Get the key node */
240  KeyNode = (PCM_KEY_NODE)Key;
242 
243  CellIndex = CmpFindSubKeyByNumber(Hive, KeyNode, Index);
244  if (CellIndex == HCELL_NIL)
245  {
246  TRACE("RegEnumKey index out of bounds (%d) in key (%.*s)\n",
247  Index, KeyNode->NameLength, KeyNode->Name);
248  return ERROR_NO_MORE_ITEMS;
249  }
250 
251  /* Get the value cell */
252  SubKeyNode = (PCM_KEY_NODE)HvGetCell(Hive, CellIndex);
253  ASSERT(SubKeyNode != NULL);
254  ASSERT(SubKeyNode->Signature == CM_KEY_NODE_SIGNATURE);
255 
256  if (SubKeyNode->Flags & KEY_COMP_NAME)
257  {
258  NameLength = CmpCompressedNameSize(SubKeyNode->Name, SubKeyNode->NameLength);
259 
260  /* Compressed name */
262  *NameSize,
263  SubKeyNode->Name,
264  SubKeyNode->NameLength);
265  }
266  else
267  {
268  NameLength = SubKeyNode->NameLength;
269 
270  /* Normal name */
271  RtlCopyMemory(Name, SubKeyNode->Name,
272  min(*NameSize, SubKeyNode->NameLength));
273  }
274 
275  if (*NameSize >= NameLength + sizeof(WCHAR))
276  {
277  Name[NameLength / sizeof(WCHAR)] = UNICODE_NULL;
278  }
279 
280  *NameSize = NameLength + sizeof(WCHAR);
281 
282  HvReleaseCell(Hive, CellIndex);
283 
284  if (SubKey != NULL)
285  *SubKey = (HKEY)SubKeyNode;
286 
287  TRACE("RegEnumKey done -> %u, '%.*S'\n", *NameSize, *NameSize, Name);
288  return ERROR_SUCCESS;
289 }
#define KEY_COMP_NAME
Definition: cmdata.h:35
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:116
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
HCELL_INDEX NTAPI CmpFindSubKeyByNumber(IN PHHIVE Hive, IN PCM_KEY_NODE Node, IN ULONG Number)
Definition: cmindex.c:600
#define HCELL_NIL
Definition: hivedata.h:85
USHORT NameLength
Definition: cmdata.h:114
#define UNICODE_NULL
VOID NTAPI CmpCopyCompressedName(OUT PWCHAR Destination, IN ULONG DestinationLength, IN PWCHAR Source, IN ULONG SourceLength)
Definition: cmname.c:56
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:393
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
static const UCHAR Index[8]
Definition: usbohci.c:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned short USHORT
Definition: pedump.c:61
static PCMHIVE CmHive
Definition: registry.c:28
#define min(a, b)
Definition: monoChain.cc:55
static const char HKEY
Definition: registry.c:45
USHORT NTAPI CmpCompressedNameSize(IN PWCHAR Name, IN ULONG Length)
Definition: cmname.c:95
USHORT Flags
Definition: cmdata.h:93

◆ RegImportBinaryHive()

BOOLEAN RegImportBinaryHive ( _In_ PVOID  ChunkBase,
_In_ ULONG  ChunkSize 
)

Definition at line 56 of file registry.c.

59 {
61  TRACE("RegImportBinaryHive(%p, 0x%lx)\n", ChunkBase, ChunkSize);
62 
63  /* Allocate and initialize the hive */
64  CmHive = CmpAllocate(sizeof(CMHIVE), FALSE, 'eviH');
66  HINIT_FLAT, // HINIT_MEMORY_INPLACE
67  0,
68  0,
69  ChunkBase,
71  CmpFree,
72  NULL,
73  NULL,
74  NULL,
75  NULL,
76  1,
77  NULL);
78  if (!NT_SUCCESS(Status))
79  {
80  CmpFree(CmHive, 0);
81  ERR("Corrupted hive %p!\n", ChunkBase);
82  return FALSE;
83  }
84 
85  /* Save the root key node */
87 
88  TRACE("RegImportBinaryHive done\n");
89  return TRUE;
90 }
static PCM_KEY_NODE RootKeyNode
Definition: registry.c:29
#define TRUE
Definition: types.h:120
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
VOID NTAPI CmpFree(IN PVOID Ptr, IN ULONG Quota)
Definition: registry.c:47
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
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI CmpAllocate(IN SIZE_T Size, IN BOOLEAN Paged, IN ULONG Tag)
Definition: registry.c:34
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:393
#define HINIT_FLAT
Definition: hivedata.h:17
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HCELL_INDEX RootCell
Definition: hivedata.h:143
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
static PCMHIVE CmHive
Definition: registry.c:28
Definition: cm.h:391

Referenced by WinLdrInitSystemHive().

◆ RegInitCurrentControlSet()

LONG RegInitCurrentControlSet ( _In_ BOOLEAN  LastKnownGood)

Definition at line 93 of file registry.c.

95 {
96  WCHAR ControlSetKeyName[80];
97  HKEY SelectKey;
98  HKEY SystemKey;
99  ULONG CurrentSet = 0;
100  ULONG DefaultSet = 0;
101  ULONG LastKnownGoodSet = 0;
102  ULONG DataSize;
103  LONG Error;
104  TRACE("RegInitCurrentControlSet\n");
105 
107  L"\\Registry\\Machine\\SYSTEM\\Select",
108  &SelectKey);
109  if (Error != ERROR_SUCCESS)
110  {
111  ERR("RegOpenKey() failed (Error %u)\n", (int)Error);
112  return Error;
113  }
114 
115  DataSize = sizeof(ULONG);
116  Error = RegQueryValue(SelectKey,
117  L"Default",
118  NULL,
119  (PUCHAR)&DefaultSet,
120  &DataSize);
121  if (Error != ERROR_SUCCESS)
122  {
123  ERR("RegQueryValue('Default') failed (Error %u)\n", (int)Error);
124  return Error;
125  }
126 
127  DataSize = sizeof(ULONG);
128  Error = RegQueryValue(SelectKey,
129  L"LastKnownGood",
130  NULL,
131  (PUCHAR)&LastKnownGoodSet,
132  &DataSize);
133  if (Error != ERROR_SUCCESS)
134  {
135  ERR("RegQueryValue('LastKnownGood') failed (Error %u)\n", (int)Error);
136  return Error;
137  }
138 
139  CurrentSet = (LastKnownGood) ? LastKnownGoodSet : DefaultSet;
140  wcscpy(ControlSetKeyName, L"ControlSet");
141  switch(CurrentSet)
142  {
143  case 1:
144  wcscat(ControlSetKeyName, L"001");
145  break;
146  case 2:
147  wcscat(ControlSetKeyName, L"002");
148  break;
149  case 3:
150  wcscat(ControlSetKeyName, L"003");
151  break;
152  case 4:
153  wcscat(ControlSetKeyName, L"004");
154  break;
155  case 5:
156  wcscat(ControlSetKeyName, L"005");
157  break;
158  }
159 
161  L"\\Registry\\Machine\\SYSTEM",
162  &SystemKey);
163  if (Error != ERROR_SUCCESS)
164  {
165  ERR("RegOpenKey(SystemKey) failed (Error %lu)\n", Error);
166  return Error;
167  }
168 
169  Error = RegOpenKey(SystemKey,
170  ControlSetKeyName,
172  if (Error != ERROR_SUCCESS)
173  {
174  ERR("RegOpenKey(CurrentControlSetKey) failed (Error %lu)\n", Error);
175  return Error;
176  }
177 
178  TRACE("RegInitCurrentControlSet done\n");
179  return ERROR_SUCCESS;
180 }
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned char * PUCHAR
Definition: retypes.h:3
LONG RegQueryValue(_In_ HKEY Key, _In_z_ PCWSTR ValueName, _Out_opt_ PULONG Type, _Out_opt_ PUCHAR Data, _Inout_opt_ PULONG DataSize)
Definition: registry.c:435
static HKEY CurrentControlSetKey
Definition: registry.c:30
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL Error
Definition: chkdsk.c:66
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:109
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
unsigned int ULONG
Definition: retypes.h:1
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
LONG RegOpenKey(_In_ HKEY ParentKey, _In_z_ PCWSTR KeyName, _Out_ PHKEY Key)
Definition: registry.c:292

Referenced by WinLdrInitSystemHive().

◆ RegOpenKey()

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

Definition at line 292 of file registry.c.

296 {
297  UNICODE_STRING RemainingPath, SubKeyName;
298  UNICODE_STRING CurrentControlSet = RTL_CONSTANT_STRING(L"CurrentControlSet");
299  PHHIVE Hive = &CmHive->Hive;
300  PCM_KEY_NODE KeyNode;
301  HCELL_INDEX CellIndex;
302  TRACE("RegOpenKey(%p, '%S', %p)\n", ParentKey, KeyName, Key);
303 
304  /* Initialize the remaining path name */
305  RtlInitUnicodeString(&RemainingPath, KeyName);
306 
307  /* Get the parent key node */
308  KeyNode = (PCM_KEY_NODE)ParentKey;
309 
310  /* Check if we have a parent key */
311  if (KeyNode == NULL)
312  {
313  UNICODE_STRING SubKeyName1, SubKeyName2, SubKeyName3;
315  UNICODE_STRING MachinePath = RTL_CONSTANT_STRING(L"MACHINE");
316  UNICODE_STRING SystemPath = RTL_CONSTANT_STRING(L"SYSTEM");
317  TRACE("RegOpenKey: absolute path\n");
318 
319  if ((RemainingPath.Length < sizeof(WCHAR)) ||
320  RemainingPath.Buffer[0] != '\\')
321  {
322  /* The key path is not absolute */
323  ERR("RegOpenKey: invalid path '%S' (%wZ)\n", KeyName, &RemainingPath);
324  return ERROR_PATH_NOT_FOUND;
325  }
326 
327  /* Skip initial path separator */
328  RemainingPath.Buffer++;
329  RemainingPath.Length -= sizeof(WCHAR);
330 
331  /* Get the first 3 path elements */
332  GetNextPathElement(&SubKeyName1, &RemainingPath);
333  GetNextPathElement(&SubKeyName2, &RemainingPath);
334  GetNextPathElement(&SubKeyName3, &RemainingPath);
335  TRACE("RegOpenKey: %wZ / %wZ / %wZ\n", &SubKeyName1, &SubKeyName2, &SubKeyName3);
336 
337  /* Check if we have the correct path */
338  if (!RtlEqualUnicodeString(&SubKeyName1, &RegistryPath, TRUE) ||
339  !RtlEqualUnicodeString(&SubKeyName2, &MachinePath, TRUE) ||
340  !RtlEqualUnicodeString(&SubKeyName3, &SystemPath, TRUE))
341  {
342  /* The key path is not inside HKLM\Machine\System */
343  ERR("RegOpenKey: invalid path '%S' (%wZ)\n", KeyName, &RemainingPath);
344  return ERROR_PATH_NOT_FOUND;
345  }
346 
347  /* Use the root key */
348  KeyNode = RootKeyNode;
349  }
350 
352 
353  /* Check if this is the root key */
354  if (KeyNode == RootKeyNode)
355  {
356  UNICODE_STRING TempPath = RemainingPath;
357 
358  /* Get the first path element */
359  GetNextPathElement(&SubKeyName, &TempPath);
360 
361  /* Check if this is CurrentControlSet */
362  if (RtlEqualUnicodeString(&SubKeyName, &CurrentControlSet, TRUE))
363  {
364  /* Use the CurrentControlSetKey and update the remaining path */
366  RemainingPath = TempPath;
367  }
368  }
369 
370  TRACE("RegOpenKey: RemainingPath '%wZ'\n", &RemainingPath);
371 
372  /* Loop while there are path elements */
373  while (GetNextPathElement(&SubKeyName, &RemainingPath))
374  {
375  TRACE("RegOpenKey: next element '%wZ'\n", &SubKeyName);
376 
377  /* Get the next sub key */
378  CellIndex = CmpFindSubKeyByName(Hive, KeyNode, &SubKeyName);
379  if (CellIndex == HCELL_NIL)
380  {
381  ERR("Did not find sub key '%wZ' (full %S)\n", &SubKeyName, KeyName);
382  return ERROR_PATH_NOT_FOUND;
383  }
384 
385  /* Get the found key */
386  KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, CellIndex);
387  ASSERT(KeyNode);
388  }
389 
390  *Key = (HKEY)KeyNode;
391 
392  TRACE("RegOpenKey done\n");
393  return ERROR_SUCCESS;
394 }
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
static PCM_KEY_NODE RootKeyNode
Definition: registry.c:29
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING SubKeyName
Definition: ndis.h:4723
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HCELL_NIL
Definition: hivedata.h:85
static HKEY CurrentControlSetKey
Definition: registry.c:30
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:393
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:109
static PCMHIVE CmHive
Definition: registry.c:28
static const char HKEY
Definition: registry.c:45
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
HCELL_INDEX NTAPI CmpFindSubKeyByName(IN PHHIVE Hive, IN PCM_KEY_NODE Parent, IN PCUNICODE_STRING SearchName)
Definition: cmindex.c:683
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
static BOOLEAN GetNextPathElement(_Out_ PUNICODE_STRING NextElement, _Inout_ PUNICODE_STRING RemainingPath)
Definition: registry.c:184
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by RegInitCurrentControlSet().

◆ 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 435 of file registry.c.

441 {
442  PHHIVE Hive = &CmHive->Hive;
443  PCM_KEY_NODE KeyNode;
444  PCM_KEY_VALUE ValueCell;
445  HCELL_INDEX CellIndex;
446  UNICODE_STRING ValueNameString;
447 
448  TRACE("RegQueryValue(%p, '%S', %p, %p, %p)\n",
450 
451  /* Get the key node */
452  KeyNode = (PCM_KEY_NODE)Key;
454 
455  /* Initialize value name string */
456  RtlInitUnicodeString(&ValueNameString, ValueName);
457  CellIndex = CmpFindValueByName(Hive, KeyNode, &ValueNameString);
458  if (CellIndex == HCELL_NIL)
459  {
460  TRACE("RegQueryValue value not found in key (%.*s)\n",
461  KeyNode->NameLength, KeyNode->Name);
462  return ERROR_FILE_NOT_FOUND;
463  }
464 
465  /* Get the value cell */
466  ValueCell = (PCM_KEY_VALUE)HvGetCell(Hive, CellIndex);
467  ASSERT(ValueCell != NULL);
468 
469  RepGetValueData(Hive, ValueCell, Type, Data, DataSize);
470 
471  HvReleaseCell(Hive, CellIndex);
472 
473  TRACE("RegQueryValue success\n");
474  return ERROR_SUCCESS;
475 }
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:116
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
USHORT NameLength
Definition: cmdata.h:114
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:393
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define TRACE(s)
Definition: solgame.cpp:4
HCELL_INDEX NTAPI CmpFindValueByName(IN PHHIVE Hive, IN PCM_KEY_NODE KeyNode, IN PUNICODE_STRING Name)
Definition: cmvalue.c:99
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static VOID RepGetValueData(_In_ PHHIVE Hive, _In_ PCM_KEY_VALUE ValueCell, _Out_opt_ PULONG Type, _Out_opt_ PUCHAR Data, _Inout_opt_ PULONG DataSize)
Definition: registry.c:398
struct _CM_KEY_VALUE * PCM_KEY_VALUE
static PCMHIVE CmHive
Definition: registry.c:28
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by RegInitCurrentControlSet(), and RegReadDWORD().