ReactOS  0.4.15-dev-3440-g915569a
registry.c File Reference
#include <freeldr.h>
#include <cmlib.h>
#include "registry.h"
#include <debug.h>
Include dependency graph for registry.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (REGISTRY)
 
PVOID NTAPI CmpAllocate (IN SIZE_T Size, IN BOOLEAN Paged, IN ULONG Tag)
 
VOID NTAPI CmpFree (IN PVOID Ptr, IN ULONG Quota)
 
BOOLEAN RegImportBinaryHive (_In_ PVOID ChunkBase, _In_ ULONG ChunkSize)
 
LONG RegInitCurrentControlSet (_In_ BOOLEAN LastKnownGood)
 
static BOOLEAN GetNextPathElement (_Out_ PUNICODE_STRING NextElement, _Inout_ PUNICODE_STRING RemainingPath)
 
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)
 
static VOID RepGetValueData (_In_ PHHIVE Hive, _In_ PCM_KEY_VALUE ValueCell, _Out_opt_ PULONG Type, _Out_opt_ PUCHAR Data, _Inout_opt_ PULONG DataSize)
 
LONG RegQueryValue (_In_ HKEY Key, _In_z_ PCWSTR ValueName, _Out_opt_ PULONG Type, _Out_opt_ PUCHAR Data, _Inout_opt_ PULONG DataSize)
 

Variables

static PCMHIVE CmHive
 
static PCM_KEY_NODE RootKeyNode
 
static HKEY CurrentControlSetKey
 

Function Documentation

◆ CmpAllocate()

PVOID NTAPI CmpAllocate ( IN SIZE_T  Size,
IN BOOLEAN  Paged,
IN ULONG  Tag 
)

Definition at line 34 of file registry.c.

38 {
41 
42  return FrLdrTempAlloc(Size, Tag);
43 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061

Referenced by RegImportBinaryHive().

◆ CmpFree()

VOID NTAPI CmpFree ( IN PVOID  Ptr,
IN ULONG  Quota 
)

Definition at line 47 of file registry.c.

50 {
52  FrLdrTempFree(Ptr, 0);
53 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197

Referenced by RegImportBinaryHive().

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( REGISTRY  )

◆ GetNextPathElement()

static BOOLEAN GetNextPathElement ( _Out_ PUNICODE_STRING  NextElement,
_Inout_ PUNICODE_STRING  RemainingPath 
)
static

Definition at line 193 of file registry.c.

196 {
197  /* Check if there are any characters left */
198  if (RemainingPath->Length < sizeof(WCHAR))
199  {
200  /* Nothing left, bail out early */
201  return FALSE;
202  }
203 
204  /* The next path elements starts with the remaining path */
205  NextElement->Buffer = RemainingPath->Buffer;
206 
207  /* Loop until the path element ends */
208  while ((RemainingPath->Length >= sizeof(WCHAR)) &&
209  (RemainingPath->Buffer[0] != '\\'))
210  {
211  /* Skip this character */
212  RemainingPath->Buffer++;
213  RemainingPath->Length -= sizeof(WCHAR);
214  }
215 
216  NextElement->Length = (USHORT)(RemainingPath->Buffer - NextElement->Buffer) * sizeof(WCHAR);
217  NextElement->MaximumLength = NextElement->Length;
218 
219  /* Check if the path element ended with a path separator */
220  if (RemainingPath->Length >= sizeof(WCHAR))
221  {
222  /* Skip the path separator */
223  ASSERT(RemainingPath->Buffer[0] == '\\');
224  RemainingPath->Buffer++;
225  RemainingPath->Length -= sizeof(WCHAR);
226  }
227 
228  /* Return whether we got any characters */
229  return TRUE;
230 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned short USHORT
Definition: pedump.c:61

Referenced by RegOpenKey().

◆ RegEnumKey()

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

Definition at line 233 of file registry.c.

239 {
240  PHHIVE Hive = &CmHive->Hive;
241  PCM_KEY_NODE KeyNode, SubKeyNode;
242  HCELL_INDEX CellIndex;
243  USHORT NameLength;
244 
245  TRACE("RegEnumKey(%p, %lu, %p, %p->%u)\n",
246  Key, Index, Name, NameSize, NameSize ? *NameSize : 0);
247 
248  /* Get the key node */
249  KeyNode = (PCM_KEY_NODE)Key;
251 
252  CellIndex = CmpFindSubKeyByNumber(Hive, KeyNode, Index);
253  if (CellIndex == HCELL_NIL)
254  {
255  TRACE("RegEnumKey index out of bounds (%d) in key (%.*s)\n",
256  Index, KeyNode->NameLength, KeyNode->Name);
257  return ERROR_NO_MORE_ITEMS;
258  }
259 
260  /* Get the value cell */
261  SubKeyNode = (PCM_KEY_NODE)HvGetCell(Hive, CellIndex);
262  ASSERT(SubKeyNode != NULL);
263  ASSERT(SubKeyNode->Signature == CM_KEY_NODE_SIGNATURE);
264 
265  if (SubKeyNode->Flags & KEY_COMP_NAME)
266  {
267  NameLength = CmpCompressedNameSize(SubKeyNode->Name, SubKeyNode->NameLength);
268 
269  /* Compressed name */
271  *NameSize,
272  SubKeyNode->Name,
273  SubKeyNode->NameLength);
274  }
275  else
276  {
277  NameLength = SubKeyNode->NameLength;
278 
279  /* Normal name */
280  RtlCopyMemory(Name, SubKeyNode->Name,
281  min(*NameSize, SubKeyNode->NameLength));
282  }
283 
284  if (*NameSize >= NameLength + sizeof(WCHAR))
285  {
286  Name[NameLength / sizeof(WCHAR)] = UNICODE_NULL;
287  }
288 
289  *NameSize = NameLength + sizeof(WCHAR);
290 
291  HvReleaseCell(Hive, CellIndex);
292 
293  if (SubKey != NULL)
294  *SubKey = (HKEY)SubKeyNode;
295  // else
296  // RegCloseKey((HKEY)SubKeyNode);
297 
298  TRACE("RegEnumKey done -> %u, '%.*S'\n", *NameSize, *NameSize, Name);
299  return ERROR_SUCCESS;
300 }
#define KEY_COMP_NAME
Definition: cmdata.h:35
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:116
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:392
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
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:394
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG HCELL_INDEX
Definition: hivedata.h:80
_In_ WDFCOLLECTION _In_ ULONG Index
USHORT Signature
Definition: cmdata.h:92
unsigned short USHORT
Definition: pedump.c:61
static PCMHIVE CmHive
Definition: registry.c:28
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
static const char HKEY
Definition: registry.c:45
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
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 
62  TRACE("RegImportBinaryHive(%p, 0x%lx)\n", ChunkBase, ChunkSize);
63 
64  /* Allocate and initialize the hive */
65  CmHive = CmpAllocate(sizeof(CMHIVE), FALSE, 'eviH');
67  HINIT_FLAT, // HINIT_MEMORY_INPLACE
68  0,
69  0,
70  ChunkBase,
72  CmpFree,
73  NULL,
74  NULL,
75  NULL,
76  NULL,
77  1,
78  NULL);
79  if (!NT_SUCCESS(Status))
80  {
81  ERR("Corrupted hive %p!\n", ChunkBase);
82  CmpFree(CmHive, 0);
83  return FALSE;
84  }
85 
86  /* Save the root key node */
88 
89  TRACE("RegImportBinaryHive done\n");
90  return TRUE;
91 }
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
#define FALSE
Definition: types.h:117
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2274
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:394
#define HINIT_FLAT
Definition: hivedata.h:17
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HCELL_INDEX RootCell
Definition: hivedata.h:143
#define ERR(fmt,...)
Definition: debug.h:110
static PCMHIVE CmHive
Definition: registry.c:28
#define NULL
Definition: types.h:112
Definition: cm.h:392

Referenced by WinLdrInitSystemHive().

◆ RegInitCurrentControlSet()

LONG RegInitCurrentControlSet ( _In_ BOOLEAN  LastKnownGood)

Definition at line 94 of file registry.c.

96 {
97  WCHAR ControlSetKeyName[80];
98  HKEY SelectKey;
99  HKEY SystemKey;
100  ULONG CurrentSet = 0;
101  ULONG DefaultSet = 0;
102  ULONG LastKnownGoodSet = 0;
103  ULONG DataSize;
104  LONG Error;
105 
106  TRACE("RegInitCurrentControlSet\n");
107 
109  L"\\Registry\\Machine\\SYSTEM\\Select",
110  &SelectKey);
111  if (Error != ERROR_SUCCESS)
112  {
113  ERR("RegOpenKey() failed (Error %u)\n", (int)Error);
114  return Error;
115  }
116 
117  DataSize = sizeof(ULONG);
118  Error = RegQueryValue(SelectKey,
119  L"Default",
120  NULL,
121  (PUCHAR)&DefaultSet,
122  &DataSize);
123  if (Error != ERROR_SUCCESS)
124  {
125  ERR("RegQueryValue('Default') failed (Error %u)\n", (int)Error);
126  RegCloseKey(SelectKey);
127  return Error;
128  }
129 
130  DataSize = sizeof(ULONG);
131  Error = RegQueryValue(SelectKey,
132  L"LastKnownGood",
133  NULL,
134  (PUCHAR)&LastKnownGoodSet,
135  &DataSize);
136  if (Error != ERROR_SUCCESS)
137  {
138  ERR("RegQueryValue('LastKnownGood') failed (Error %u)\n", (int)Error);
139  RegCloseKey(SelectKey);
140  return Error;
141  }
142 
143  RegCloseKey(SelectKey);
144 
145  CurrentSet = (LastKnownGood) ? LastKnownGoodSet : DefaultSet;
146  wcscpy(ControlSetKeyName, L"ControlSet");
147  switch(CurrentSet)
148  {
149  case 1:
150  wcscat(ControlSetKeyName, L"001");
151  break;
152  case 2:
153  wcscat(ControlSetKeyName, L"002");
154  break;
155  case 3:
156  wcscat(ControlSetKeyName, L"003");
157  break;
158  case 4:
159  wcscat(ControlSetKeyName, L"004");
160  break;
161  case 5:
162  wcscat(ControlSetKeyName, L"005");
163  break;
164  }
165 
167  L"\\Registry\\Machine\\SYSTEM",
168  &SystemKey);
169  if (Error != ERROR_SUCCESS)
170  {
171  ERR("RegOpenKey(SystemKey) failed (Error %lu)\n", Error);
172  return Error;
173  }
174 
175  Error = RegOpenKey(SystemKey,
176  ControlSetKeyName,
178 
179  RegCloseKey(SystemKey);
180 
181  if (Error != ERROR_SUCCESS)
182  {
183  ERR("RegOpenKey(CurrentControlSetKey) failed (Error %lu)\n", Error);
184  return Error;
185  }
186 
187  TRACE("RegInitCurrentControlSet done\n");
188  return ERROR_SUCCESS;
189 }
LONG WINAPI RegCloseKey(IN HKEY hKey)
Definition: registry.c:512
#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:448
#define L(x)
Definition: ntvdm.h:50
static HKEY CurrentControlSetKey
Definition: registry.c:30
long LONG
Definition: pedump.c:60
#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)
#define ERR(fmt,...)
Definition: debug.h:110
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define NULL
Definition: types.h:112
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:303

Referenced by WinLdrInitSystemHive().

◆ RegOpenKey()

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

Definition at line 303 of file registry.c.

307 {
308  UNICODE_STRING RemainingPath, SubKeyName;
309  UNICODE_STRING CurrentControlSet = RTL_CONSTANT_STRING(L"CurrentControlSet");
310  PHHIVE Hive = &CmHive->Hive;
311  PCM_KEY_NODE KeyNode;
312  HCELL_INDEX CellIndex;
313 
314  TRACE("RegOpenKey(%p, '%S', %p)\n", ParentKey, KeyName, Key);
315 
316  /* Initialize the remaining path name */
317  RtlInitUnicodeString(&RemainingPath, KeyName);
318 
319  /* Get the parent key node */
320  KeyNode = (PCM_KEY_NODE)ParentKey;
321 
322  /* Check if we have a parent key */
323  if (KeyNode == NULL)
324  {
325  UNICODE_STRING SubKeyName1, SubKeyName2, SubKeyName3;
327  UNICODE_STRING MachinePath = RTL_CONSTANT_STRING(L"MACHINE");
328  UNICODE_STRING SystemPath = RTL_CONSTANT_STRING(L"SYSTEM");
329 
330  TRACE("RegOpenKey: absolute path\n");
331 
332  if ((RemainingPath.Length < sizeof(WCHAR)) ||
333  RemainingPath.Buffer[0] != '\\')
334  {
335  /* The key path is not absolute */
336  ERR("RegOpenKey: invalid path '%S' (%wZ)\n", KeyName, &RemainingPath);
337  return ERROR_PATH_NOT_FOUND;
338  }
339 
340  /* Skip initial path separator */
341  RemainingPath.Buffer++;
342  RemainingPath.Length -= sizeof(WCHAR);
343 
344  /* Get the first 3 path elements */
345  GetNextPathElement(&SubKeyName1, &RemainingPath);
346  GetNextPathElement(&SubKeyName2, &RemainingPath);
347  GetNextPathElement(&SubKeyName3, &RemainingPath);
348  TRACE("RegOpenKey: %wZ / %wZ / %wZ\n", &SubKeyName1, &SubKeyName2, &SubKeyName3);
349 
350  /* Check if we have the correct path */
351  if (!RtlEqualUnicodeString(&SubKeyName1, &RegistryPath, TRUE) ||
352  !RtlEqualUnicodeString(&SubKeyName2, &MachinePath, TRUE) ||
353  !RtlEqualUnicodeString(&SubKeyName3, &SystemPath, TRUE))
354  {
355  /* The key path is not inside HKLM\Machine\System */
356  ERR("RegOpenKey: invalid path '%S' (%wZ)\n", KeyName, &RemainingPath);
357  return ERROR_PATH_NOT_FOUND;
358  }
359 
360  /* Use the root key */
361  KeyNode = RootKeyNode;
362  }
363 
365 
366  /* Check if this is the root key */
367  if (KeyNode == RootKeyNode)
368  {
369  UNICODE_STRING TempPath = RemainingPath;
370 
371  /* Get the first path element */
372  GetNextPathElement(&SubKeyName, &TempPath);
373 
374  /* Check if this is CurrentControlSet */
375  if (RtlEqualUnicodeString(&SubKeyName, &CurrentControlSet, TRUE))
376  {
377  /* Use the CurrentControlSetKey and update the remaining path */
379  RemainingPath = TempPath;
380  }
381  }
382 
383  TRACE("RegOpenKey: RemainingPath '%wZ'\n", &RemainingPath);
384 
385  /* Loop while there are path elements */
386  while (GetNextPathElement(&SubKeyName, &RemainingPath))
387  {
388  TRACE("RegOpenKey: next element '%wZ'\n", &SubKeyName);
389 
390  /* Get the next sub key */
391  CellIndex = CmpFindSubKeyByName(Hive, KeyNode, &SubKeyName);
392  if (CellIndex == HCELL_NIL)
393  {
394  ERR("Did not find sub key '%wZ' (full %S)\n", &SubKeyName, KeyName);
395  return ERROR_PATH_NOT_FOUND;
396  }
397 
398  /* Get the found key */
399  KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, CellIndex);
400  ASSERT(KeyNode);
401  }
402 
403  *Key = (HKEY)KeyNode;
404 
405  TRACE("RegOpenKey done\n");
406  return ERROR_SUCCESS;
407 }
static PCM_KEY_NODE RootKeyNode
Definition: registry.c:29
#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 TRUE
Definition: types.h:120
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
#define HCELL_NIL
Definition: hivedata.h:85
#define L(x)
Definition: ntvdm.h:50
static HKEY CurrentControlSetKey
Definition: registry.c:30
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:394
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
#define ERR(fmt,...)
Definition: debug.h:110
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69
static PCMHIVE CmHive
Definition: registry.c:28
#define NULL
Definition: types.h:112
static const char HKEY
Definition: registry.c:45
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#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:193
#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 448 of file registry.c.

454 {
455  PHHIVE Hive = &CmHive->Hive;
456  PCM_KEY_NODE KeyNode;
457  PCM_KEY_VALUE ValueCell;
458  HCELL_INDEX CellIndex;
459  UNICODE_STRING ValueNameString;
460 
461  TRACE("RegQueryValue(%p, '%S', %p, %p, %p)\n",
463 
464  /* Get the key node */
465  KeyNode = (PCM_KEY_NODE)Key;
467 
468  /* Initialize value name string */
469  RtlInitUnicodeString(&ValueNameString, ValueName);
470  CellIndex = CmpFindValueByName(Hive, KeyNode, &ValueNameString);
471  if (CellIndex == HCELL_NIL)
472  {
473  TRACE("RegQueryValue value not found in key (%.*s)\n",
474  KeyNode->NameLength, KeyNode->Name);
475  return ERROR_FILE_NOT_FOUND;
476  }
477 
478  /* Get the value cell */
479  ValueCell = (PCM_KEY_VALUE)HvGetCell(Hive, CellIndex);
480  ASSERT(ValueCell != NULL);
481 
482  RepGetValueData(Hive, ValueCell, Type, Data, DataSize);
483 
484  HvReleaseCell(Hive, CellIndex);
485 
486  TRACE("RegQueryValue success\n");
487  return ERROR_SUCCESS;
488 }
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:116
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:392
#define HCELL_NIL
Definition: hivedata.h:85
USHORT NameLength
Definition: cmdata.h:114
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:394
#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
#define ASSERT(a)
Definition: mode.c:44
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
Type
Definition: Type.h:6
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:411
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
struct _CM_KEY_VALUE * PCM_KEY_VALUE
static PCMHIVE CmHive
Definition: registry.c:28
#define NULL
Definition: types.h:112
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().

◆ RepGetValueData()

static VOID RepGetValueData ( _In_ PHHIVE  Hive,
_In_ PCM_KEY_VALUE  ValueCell,
_Out_opt_ PULONG  Type,
_Out_opt_ PUCHAR  Data,
_Inout_opt_ PULONG  DataSize 
)
static

Definition at line 411 of file registry.c.

417 {
419  PVOID DataCell;
420 
421  /* Does the caller want the type? */
422  if (Type != NULL)
423  *Type = ValueCell->Type;
424 
425  /* Does the caller provide DataSize? */
426  if (DataSize != NULL)
427  {
428  // NOTE: CmpValueToData doesn't support big data (the function will
429  // bugcheck if so), FreeLdr is not supposed to read such data.
430  // If big data is needed, use instead CmpGetValueData.
431  // CmpGetValueData(Hive, ValueCell, DataSize, &DataCell, ...);
432  DataCell = CmpValueToData(Hive, ValueCell, &DataLength);
433 
434  /* Does the caller want the data? */
435  if ((Data != NULL) && (*DataSize != 0))
436  {
438  DataCell,
439  min(*DataSize, DataLength));
440  }
441 
442  /* Return the actual data length */
443  *DataSize = DataLength;
444  }
445 }
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1437
PCELL_DATA NTAPI CmpValueToData(IN PHHIVE Hive, IN PCM_KEY_VALUE Value, OUT PULONG Length)
Definition: cmvalue.c:167
Type
Definition: Type.h:6
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by RegQueryValue().

Variable Documentation

◆ CmHive

◆ CurrentControlSetKey

HKEY CurrentControlSetKey
static

Definition at line 30 of file registry.c.

Referenced by RegInitCurrentControlSet(), and RegOpenKey().

◆ RootKeyNode

PCM_KEY_NODE RootKeyNode
static

Definition at line 29 of file registry.c.

Referenced by RegImportBinaryHive(), and RegOpenKey().