ReactOS 0.4.15-dev-7674-gc0b4db1
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, _In_ PCSTR SearchPath, _In_ BOOLEAN LoadAlternate)
 Imports the SYSTEM binary hive from the registry base chunk that's been provided by the loader block.
 
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 49 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,
_In_ PCSTR  SearchPath,
_In_ BOOLEAN  LoadAlternate 
)

Imports the SYSTEM binary hive from the registry base chunk that's been provided by the loader block.

Parameters
[in]ChunkBaseA pointer to the registry base chunk that serves for SYSTEM hive initialization.
[in]ChunkSizeThe size of the registry base chunk. This parameter refers to the actual size of the SYSTEM hive. This parameter is currently unused.
[in]LoadAlternateIf set to TRUE, the function will initialize the hive as an alternate hive, otherwise FALSE to initialize it as primary.
Returns
Returns TRUE if hive importing and initialization have succeeded, FALSE otherwise.

Definition at line 449 of file registry.c.

454{
456 PCM_KEY_NODE KeyNode;
457
458 TRACE("RegImportBinaryHive(%p, 0x%lx)\n", ChunkBase, ChunkSize);
459
460 /* Assume that we don't need boot recover, unless we have to */
461 ((PHBASE_BLOCK)ChunkBase)->BootRecover = HBOOT_NO_BOOT_RECOVER;
462
463 /* Allocate and initialize the hive */
464 CmSystemHive = FrLdrTempAlloc(sizeof(CMHIVE), 'eviH');
465 Success = RegInitializeHive(CmSystemHive, ChunkBase, LoadAlternate);
466 if (!Success)
467/* FIXME: See the comment above */
468#if defined(_M_AMD64)
469 {
470 ERR("Corrupted hive %p!\n", ChunkBase);
472 return FALSE;
473 }
474#else
475 {
476 /* Free the buffer and retry again */
479
480 if (!RegRecoverHeaderHive(ChunkBase, SearchPath, "SYSTEM"))
481 {
482 ERR("Failed to recover the hive header block\n");
483 return FALSE;
484 }
485
486 if (!RegRecoverDataHive(ChunkBase, SearchPath, "SYSTEM"))
487 {
488 ERR("Failed to recover the hive data\n");
489 return FALSE;
490 }
491
492 /* Now retry initializing the hive again */
493 CmSystemHive = FrLdrTempAlloc(sizeof(CMHIVE), 'eviH');
494 Success = RegInitializeHive(CmSystemHive, ChunkBase, LoadAlternate);
495 if (!Success)
496 {
497 ERR("Corrupted hive (despite recovery) %p\n", ChunkBase);
499 return FALSE;
500 }
501
502 /*
503 * Acknowledge the kernel we recovered the SYSTEM hive
504 * on our side by applying log data.
505 */
506 ((PHBASE_BLOCK)ChunkBase)->BootRecover = HBOOT_BOOT_RECOVERED_BY_HIVE_LOG;
507 }
508#endif
509
510 /* Save the root key node */
514
515 /* Verify it is accessible */
517 ASSERT(KeyNode);
520
521 return TRUE;
522}
unsigned char BOOLEAN
#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
static BOOLEAN RegRecoverHeaderHive(_Inout_ PVOID ChunkBase, _In_ PCSTR DirectoryPath, _In_ PCSTR LogName)
Recovers the header base block of a flat registry hive.
Definition: registry.c:289
#define GET_HHIVE(CmHive)
Definition: registry.c:41
static PCMHIVE CmSystemHive
Definition: registry.c:30
PHHIVE SystemHive
Definition: registry.c:33
static HCELL_INDEX SystemRootCell
Definition: registry.c:31
static BOOLEAN RegInitializeHive(_In_ PCMHIVE CmHive, _In_ PVOID ChunkBase, _In_ BOOLEAN LoadAlternate)
Initializes a flat hive descriptor for the hive and validates the registry hive. Volatile data is pur...
Definition: registry.c:96
static BOOLEAN RegRecoverDataHive(_Inout_ PVOID ChunkBase, _In_ PCSTR DirectoryPath, _In_ PCSTR LogName)
Recovers the corrupt data of a primary flat registry hive.
Definition: registry.c:362
struct _CM_KEY_NODE * PCM_KEY_NODE
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(Hive, Cell)
Definition: cmlib.h:455
#define HvGetCell(Hive, Cell)
Definition: cmlib.h:452
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
@ Success
Definition: eventcreate.c:712
#define HCELL_NIL
Definition: hivedata.h:110
#define HBOOT_BOOT_RECOVERED_BY_HIVE_LOG
Definition: hivedata.h:95
#define HBOOT_NO_BOOT_RECOVER
Definition: hivedata.h:94
struct _HBASE_BLOCK * PHBASE_BLOCK
#define ASSERT(a)
Definition: mode.c:44
#define TRACE(s)
Definition: solgame.cpp:4
Definition: cmlib.h:316
USHORT Signature
Definition: cmdata.h:92
HCELL_INDEX RootCell
Definition: hivedata.h:168
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:328
#define SearchPath
Definition: winbase.h:3835
_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 525 of file registry.c.

527{
528 UNICODE_STRING ControlSetName;
529 HCELL_INDEX ControlCell;
530 PCM_KEY_NODE KeyNode;
531 BOOLEAN AutoSelect;
532
533 TRACE("RegInitCurrentControlSet\n");
534
535 /* Choose which control set to open and set it as the new "Current" */
536 RtlInitUnicodeString(&ControlSetName,
537 LastKnownGood ? L"LastKnownGood"
538 : L"Default");
539
540 ControlCell = CmpFindControlSet(SystemHive,
542 &ControlSetName,
543 &AutoSelect);
544 if (ControlCell == HCELL_NIL)
545 {
546 ERR("CmpFindControlSet('%wZ') failed\n", &ControlSetName);
547 return FALSE;
548 }
549
550 CurrentControlSetKey = HCI_TO_HKEY(ControlCell);
551
552 /* Verify it is accessible */
553 KeyNode = (PCM_KEY_NODE)HvGetCell(SystemHive, ControlCell);
554 ASSERT(KeyNode);
556 HvReleaseCell(SystemHive, ControlCell);
557
558 return TRUE;
559}
HKEY CurrentControlSetKey
Definition: registry.c:34
#define HCI_TO_HKEY(CellIndex)
Definition: registry.c:36
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:105
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 676 of file registry.c.

680{
681 UNICODE_STRING RemainingPath, SubKeyName;
682 UNICODE_STRING CurrentControlSet = RTL_CONSTANT_STRING(L"CurrentControlSet");
684 PCM_KEY_NODE KeyNode;
685 HCELL_INDEX CellIndex;
686
687 TRACE("RegOpenKey(%p, '%S', %p)\n", ParentKey, KeyName, Key);
688
689 /* Initialize the remaining path name */
690 RtlInitUnicodeString(&RemainingPath, KeyName);
691
692 /* Check if we have a parent key */
693 if (ParentKey == NULL)
694 {
695 UNICODE_STRING SubKeyName1, SubKeyName2, SubKeyName3;
697 UNICODE_STRING MachinePath = RTL_CONSTANT_STRING(L"MACHINE");
698 UNICODE_STRING SystemPath = RTL_CONSTANT_STRING(L"SYSTEM");
699
700 TRACE("RegOpenKey: absolute path\n");
701
702 if ((RemainingPath.Length < sizeof(WCHAR)) ||
703 RemainingPath.Buffer[0] != '\\')
704 {
705 /* The key path is not absolute */
706 ERR("RegOpenKey: invalid path '%S' (%wZ)\n", KeyName, &RemainingPath);
708 }
709
710 /* Skip initial path separator */
711 RemainingPath.Buffer++;
712 RemainingPath.Length -= sizeof(WCHAR);
713
714 /* Get the first 3 path elements */
715 GetNextPathElement(&SubKeyName1, &RemainingPath);
716 GetNextPathElement(&SubKeyName2, &RemainingPath);
717 GetNextPathElement(&SubKeyName3, &RemainingPath);
718 TRACE("RegOpenKey: %wZ / %wZ / %wZ\n", &SubKeyName1, &SubKeyName2, &SubKeyName3);
719
720 /* Check if we have the correct path */
721 if (!RtlEqualUnicodeString(&SubKeyName1, &RegistryPath, TRUE) ||
722 !RtlEqualUnicodeString(&SubKeyName2, &MachinePath, TRUE) ||
723 !RtlEqualUnicodeString(&SubKeyName3, &SystemPath, TRUE))
724 {
725 /* The key path is not inside HKLM\Machine\System */
726 ERR("RegOpenKey: invalid path '%S' (%wZ)\n", KeyName, &RemainingPath);
728 }
729
730 /* Use the root key */
731 CellIndex = SystemRootCell;
732 }
733 else
734 {
735 /* Use the parent key */
736 CellIndex = HKEY_TO_HCI(ParentKey);
737 }
738
739 /* Check if this is the root key */
740 if (CellIndex == SystemRootCell)
741 {
742 UNICODE_STRING TempPath = RemainingPath;
743
744 /* Get the first path element */
745 GetNextPathElement(&SubKeyName, &TempPath);
746
747 /* Check if this is CurrentControlSet */
748 if (RtlEqualUnicodeString(&SubKeyName, &CurrentControlSet, TRUE))
749 {
750 /* Use the CurrentControlSetKey and update the remaining path */
752 RemainingPath = TempPath;
753 }
754 }
755
756 /* Get the key node */
757 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, CellIndex);
758 ASSERT(KeyNode);
760
761 TRACE("RegOpenKey: RemainingPath '%wZ'\n", &RemainingPath);
762
763 /* Loop while there are path elements */
764 while (GetNextPathElement(&SubKeyName, &RemainingPath))
765 {
766 HCELL_INDEX NextCellIndex;
767
768 TRACE("RegOpenKey: next element '%wZ'\n", &SubKeyName);
769
770 /* Get the next sub key */
771 NextCellIndex = CmpFindSubKeyByName(Hive, KeyNode, &SubKeyName);
772 HvReleaseCell(Hive, CellIndex);
773 CellIndex = NextCellIndex;
774 if (CellIndex == HCELL_NIL)
775 {
776 WARN("Did not find sub key '%wZ' (full: %S)\n", &SubKeyName, KeyName);
778 }
779
780 /* Get the found key */
781 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, CellIndex);
782 ASSERT(KeyNode);
784 }
785
786 HvReleaseCell(Hive, CellIndex);
787 *Key = HCI_TO_HKEY(CellIndex);
788
789 return ERROR_SUCCESS;
790}
#define WARN(fmt,...)
Definition: debug.h:112
static BOOLEAN GetNextPathElement(_Out_ PUNICODE_STRING NextElement, _Inout_ PUNICODE_STRING RemainingPath)
Definition: registry.c:563
#define GET_HHIVE_FROM_HKEY(hKey)
Definition: registry.c:42
#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 831 of file registry.c.

837{
839 PCM_KEY_NODE KeyNode;
840 PCM_KEY_VALUE ValueCell;
841 HCELL_INDEX CellIndex;
842 UNICODE_STRING ValueNameString;
843
844 TRACE("RegQueryValue(%p, '%S', %p, %p, %p)\n",
846
847 /* Get the key node */
848 KeyNode = GET_CM_KEY_NODE(Hive, Key);
849 ASSERT(KeyNode);
851
852 /* Initialize value name string */
853 RtlInitUnicodeString(&ValueNameString, ValueName);
854 CellIndex = CmpFindValueByName(Hive, KeyNode, &ValueNameString);
855 if (CellIndex == HCELL_NIL)
856 {
857 TRACE("RegQueryValue value not found in key (%.*s)\n",
858 KeyNode->NameLength, KeyNode->Name);
861 }
863
864 /* Get the value cell */
865 ValueCell = (PCM_KEY_VALUE)HvGetCell(Hive, CellIndex);
866 ASSERT(ValueCell != NULL);
867
868 RepGetValueData(Hive, ValueCell, Type, Data, DataSize);
869
870 HvReleaseCell(Hive, CellIndex);
871
872 return ERROR_SUCCESS;
873}
Type
Definition: Type.h:7
#define GET_CM_KEY_NODE(hHive, hKey)
Definition: registry.c:43
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