ReactOS  0.4.13-dev-656-g74bcf30
hiveinit.c File Reference
#include "cmlib.h"
#include <debug.h>
Include dependency graph for hiveinit.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

HvpVerifyHiveHeader

Internal function to verify that a hive header has valid format.

BOOLEAN CMAPI HvpVerifyHiveHeader (IN PHBASE_BLOCK BaseBlock)
 
HvpFreeHiveBins

Internal function to free all bin storage associated with a hive descriptor.

VOID CMAPI HvpFreeHiveBins (PHHIVE Hive)
 
HvpAllocBaseBlockAligned

Internal helper function to allocate cluster-aligned hive base blocks.

static __inline PHBASE_BLOCK HvpAllocBaseBlockAligned (IN PHHIVE Hive, IN BOOLEAN Paged, IN ULONG Tag)
 
HvpInitFileName

Internal function to initialize the UNICODE NULL-terminated hive file name member of a hive header by copying the last 31 characters of the file name. Mainly used for debugging purposes.

static VOID HvpInitFileName (IN OUT PHBASE_BLOCK BaseBlock, IN PCUNICODE_STRING FileName OPTIONAL)
 
HvpCreateHive

Internal helper function to initialize a hive descriptor structure for a newly created hive in memory.

See also
HvInitialize
NTSTATUS CMAPI HvpCreateHive (IN OUT PHHIVE RegistryHive, IN PCUNICODE_STRING FileName OPTIONAL)
 
HvpInitializeMemoryHive

Internal helper function to initialize hive descriptor structure for an existing hive stored in memory. The data of the hive is copied and it is prepared for read/write access.

See also
HvInitialize
NTSTATUS CMAPI HvpInitializeMemoryHive (PHHIVE Hive, PHBASE_BLOCK ChunkBase, IN PCUNICODE_STRING FileName OPTIONAL)
 
HvInitialize

Allocate a new hive descriptor structure and intialize it.

Parameters
RegistryHiveOutput variable to store pointer to the hive descriptor.
OperationType
  • HV_OPERATION_CREATE_HIVE Create a new hive for read/write access.
  • HV_OPERATION_MEMORY Load and copy in-memory hive for read/write access. The pointer to data passed to this routine can be freed after the function is executed.
  • HV_OPERATION_MEMORY_INPLACE Load an in-memory hive for read-only access. The pointer to data passed to this routine MUSTN'T be freed until HvFree is called.
ChunkBasePointer to hive data.
ChunkSizeSize of passed hive data.
Returns
STATUS_NO_MEMORY - A memory allocation failed. STATUS_REGISTRY_CORRUPT - Registry corruption was detected. STATUS_SUCCESS
See also
HvFree
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)
 
HvFree

Free all stroage and handles associated with hive descriptor. But do not free the hive descriptor itself.

VOID CMAPI HvFree (PHHIVE RegistryHive)
 

HvpInitializeFlatHive

Internal helper function to initialize hive descriptor structure for a hive stored in memory. The in-memory data of the hive are directly used and it is read-only accessible.

See also
HvInitialize
enum  _RESULT {
  NotHive, Fail, NoMemory, HiveSuccess,
  RecoverHeader, RecoverData, SelfHeal
}
 
typedef enum _RESULT RESULT
 
NTSTATUS CMAPI HvpInitializeFlatHive (PHHIVE Hive, PHBASE_BLOCK ChunkBase)
 
RESULT CMAPI HvpGetHiveHeader (IN PHHIVE Hive, IN PHBASE_BLOCK *HiveBaseBlock, IN PLARGE_INTEGER TimeStamp)
 
NTSTATUS CMAPI HvLoadHive (IN PHHIVE Hive, IN PCUNICODE_STRING FileName OPTIONAL)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 9 of file hiveinit.c.

Typedef Documentation

◆ RESULT

typedef enum _RESULT RESULT

Enumeration Type Documentation

◆ _RESULT

Enumerator
NotHive 
Fail 
NoMemory 
HiveSuccess 
RecoverHeader 
RecoverData 
SelfHeal 

Definition at line 365 of file hiveinit.c.

366 {
367  NotHive,
368  Fail,
369  NoMemory,
370  HiveSuccess,
372  RecoverData,
373  SelfHeal
374 } RESULT;
Definition: hiveinit.c:368
enum _RESULT RESULT

Function Documentation

◆ HvFree()

VOID CMAPI HvFree ( PHHIVE  RegistryHive)

Definition at line 623 of file hiveinit.c.

625 {
626  if (!RegistryHive->ReadOnly)
627  {
628  /* Release hive bitmap */
629  if (RegistryHive->DirtyVector.Buffer)
630  {
631  RegistryHive->Free(RegistryHive->DirtyVector.Buffer, 0);
632  }
633 
634  HvpFreeHiveBins(RegistryHive);
635 
636  /* Free the BaseBlock */
637  if (RegistryHive->BaseBlock)
638  {
639  RegistryHive->Free(RegistryHive->BaseBlock, RegistryHive->BaseBlockAlloc);
640  RegistryHive->BaseBlock = NULL;
641  }
642  }
643 }
PULONG Buffer
Definition: typedefs.h:89
RTL_BITMAP DirtyVector
Definition: hivedata.h:304
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
BOOLEAN ReadOnly
Definition: hivedata.h:310
PFREE_ROUTINE Free
Definition: hivedata.h:294
smooth NULL
Definition: ftsmooth.c:416
ULONG BaseBlockAlloc
Definition: hivedata.h:307
VOID CMAPI HvpFreeHiveBins(PHHIVE Hive)
Definition: hiveinit.c:53

Referenced by CmiInitializeHive(), CmpDestroyHive(), and CmUnloadKey().

◆ HvInitialize()

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 at line 522 of file hiveinit.c.

536 {
538  PHHIVE Hive = RegistryHive;
539 
540  /*
541  * Create a new hive structure that will hold all the maintenance data.
542  */
543 
544  RtlZeroMemory(Hive, sizeof(HHIVE));
546 
547  Hive->Allocate = Allocate;
548  Hive->Free = Free;
549  Hive->FileSetSize = FileSetSize;
550  Hive->FileWrite = FileWrite;
551  Hive->FileRead = FileRead;
552  Hive->FileFlush = FileFlush;
553 
554  Hive->RefreshCount = 0;
556  Hive->Cluster = Cluster;
557  Hive->BaseBlockAlloc = sizeof(HBASE_BLOCK); // == HBLOCK_SIZE
558 
559  Hive->Version = HSYS_MINOR;
560 #if (NTDDI_VERSION < NTDDI_VISTA)
561  Hive->Log = (FileType == HFILE_TYPE_LOG);
562 #endif
563  Hive->HiveFlags = HiveFlags & ~HIVE_NOLAZYFLUSH;
564 
565  switch (OperationType)
566  {
567  case HINIT_CREATE:
568  Status = HvpCreateHive(Hive, FileName);
569  break;
570 
571  case HINIT_MEMORY:
572  Status = HvpInitializeMemoryHive(Hive, HiveData, FileName);
573  break;
574 
575  case HINIT_FLAT:
576  Status = HvpInitializeFlatHive(Hive, HiveData);
577  break;
578 
579  case HINIT_FILE:
580  {
581  Status = HvLoadHive(Hive, FileName);
582  if ((Status != STATUS_SUCCESS) &&
584  {
585  /* Unrecoverable failure */
586  return Status;
587  }
588 
589  /* Check for previous damage */
591  break;
592  }
593 
595  // Status = HvpInitializeMemoryInplaceHive(Hive, HiveData);
596  // break;
597 
598  case HINIT_MAPFILE:
599 
600  default:
601  /* FIXME: A better return status value is needed */
603  ASSERT(FALSE);
604  }
605 
606  if (!NT_SUCCESS(Status)) return Status;
607 
608  /* HACK: ROS: Init root key cell and prepare the hive */
609  // r31253
610  // if (OperationType == HINIT_CREATE) CmCreateRootNode(Hive, L"");
611  if (OperationType != HINIT_CREATE) CmPrepareHive(Hive);
612 
613  return Status;
614 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define HSYS_MINOR
Definition: hivedata.h:58
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_REGISTRY_RECOVERED
Definition: ntstatus.h:123
NTSTATUS CMAPI HvpInitializeMemoryHive(PHHIVE Hive, PHBASE_BLOCK ChunkBase, IN PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:221
#define HTYPE_COUNT
Definition: hivedata.h:71
#define HV_HHIVE_SIGNATURE
Definition: hivedata.h:50
PFREE_ROUTINE Free
Definition: hivedata.h:294
#define HINIT_MAPFILE
Definition: hivedata.h:18
#define HINIT_MEMORY_INPLACE
Definition: hivedata.h:16
PALLOCATE_ROUTINE Allocate
Definition: hivedata.h:293
_In_opt_ PALLOCATE_FUNCTION Allocate
Definition: exfuncs.h:656
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION Free
Definition: exfuncs.h:656
ULONG StorageTypeCount
Definition: hivedata.h:329
ULONG RefreshCount
Definition: hivedata.h:328
#define HINIT_FILE
Definition: hivedata.h:15
#define HINIT_FLAT
Definition: hivedata.h:17
NTSTATUS CMAPI HvpCreateHive(IN OUT PHHIVE RegistryHive, IN PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:160
PFILE_SET_SIZE_ROUTINE FileSetSize
Definition: hivedata.h:295
ULONG Signature
Definition: hivedata.h:288
ULONG Version
Definition: hivedata.h:330
#define HINIT_CREATE
Definition: hivedata.h:13
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define HFILE_TYPE_LOG
Definition: hivedata.h:34
ULONG Cluster
Definition: hivedata.h:308
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS CMAPI HvpInitializeFlatHive(PHHIVE Hive, PHBASE_BLOCK ChunkBase)
Definition: hiveinit.c:344
PFILE_WRITE_ROUTINE FileWrite
Definition: hivedata.h:296
VOID CMAPI CmPrepareHive(PHHIVE RegistryHive)
Definition: cminit.c:135
#define HINIT_MEMORY
Definition: hivedata.h:14
Status
Definition: gdiplustypes.h:24
ULONG HiveFlags
Definition: hivedata.h:321
PFILE_FLUSH_ROUTINE FileFlush
Definition: hivedata.h:298
ULONG BaseBlockAlloc
Definition: hivedata.h:307
#define HIVE_NOLAZYFLUSH
Definition: hivedata.h:24
NTSTATUS CMAPI HvLoadHive(IN PHHIVE Hive, IN PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:415
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _HBASE_BLOCK HBASE_BLOCK
return STATUS_SUCCESS
Definition: btrfs.c:2777
PFILE_READ_ROUTINE FileRead
Definition: hivedata.h:297

Referenced by BiInitializeAndValidateHive(), CmGetSystemControlValues(), CmiInitializeHive(), CmpInitializeHive(), and RegImportBinaryHive().

◆ HvLoadHive()

NTSTATUS CMAPI HvLoadHive ( IN PHHIVE  Hive,
IN PCUNICODE_STRING FileName  OPTIONAL 
)

Definition at line 415 of file hiveinit.c.

417 {
419  PHBASE_BLOCK BaseBlock = NULL;
420  ULONG Result;
422  ULONG Offset = 0;
423  PVOID HiveData;
424  ULONG FileSize;
425 
426  /* Get the hive header */
427  Result = HvpGetHiveHeader(Hive, &BaseBlock, &TimeStamp);
428  switch (Result)
429  {
430  /* Out of memory */
431  case NoMemory:
432 
433  /* Fail */
435 
436  /* Not a hive */
437  case NotHive:
438 
439  /* Fail */
441 
442  /* Has recovery data */
443  case RecoverData:
444  case RecoverHeader:
445 
446  /* Fail */
448  }
449 
450  /* Set default boot type */
451  BaseBlock->BootType = 0;
452 
453  /* Setup hive data */
454  Hive->BaseBlock = BaseBlock;
455  Hive->Version = BaseBlock->Minor;
456 
457  /* Allocate a buffer large enough to hold the hive */
458  FileSize = HBLOCK_SIZE + BaseBlock->Length; // == sizeof(HBASE_BLOCK) + BaseBlock->Length;
459  HiveData = Hive->Allocate(FileSize, TRUE, TAG_CM);
460  if (!HiveData)
461  {
462  Hive->Free(BaseBlock, Hive->BaseBlockAlloc);
464  }
465 
466  /* Now read the whole hive */
467  Result = Hive->FileRead(Hive,
469  &Offset,
470  HiveData,
471  FileSize);
472  if (!Result)
473  {
474  Hive->Free(HiveData, FileSize);
475  Hive->Free(BaseBlock, Hive->BaseBlockAlloc);
477  }
478 
479  // This is a HACK!
480  /* Free our base block... it's usless in this implementation */
481  Hive->Free(BaseBlock, Hive->BaseBlockAlloc);
482 
483  /* Initialize the hive directly from memory */
484  Status = HvpInitializeMemoryHive(Hive, HiveData, FileName);
485  if (!NT_SUCCESS(Status))
486  Hive->Free(HiveData, FileSize);
487 
488  return Status;
489 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define HBLOCK_SIZE
Definition: hivedata.h:41
ULONG BootType
Definition: hivedata.h:161
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS CMAPI HvpInitializeMemoryHive(PHHIVE Hive, PHBASE_BLOCK ChunkBase, IN PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:221
ULONG Length
Definition: hivedata.h:146
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define STATUS_REGISTRY_CORRUPT
Definition: ntstatus.h:554
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TAG_CM
Definition: cmlib.h:203
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
SECURITY_INTEGER TimeStamp
Definition: sspi.h:78
Status
Definition: gdiplustypes.h:24
#define HFILE_TYPE_PRIMARY
Definition: hivedata.h:33
unsigned int ULONG
Definition: retypes.h:1
ULONG Minor
Definition: hivedata.h:133
RESULT CMAPI HvpGetHiveHeader(IN PHHIVE Hive, IN PHBASE_BLOCK *HiveBaseBlock, IN PLARGE_INTEGER TimeStamp)
Definition: hiveinit.c:377
#define STATUS_NOT_REGISTRY_FILE
Definition: ntstatus.h:570

Referenced by HvInitialize().

◆ HvpAllocBaseBlockAligned()

static __inline PHBASE_BLOCK HvpAllocBaseBlockAligned ( IN PHHIVE  Hive,
IN BOOLEAN  Paged,
IN ULONG  Tag 
)
static

Definition at line 87 of file hiveinit.c.

91 {
92  PHBASE_BLOCK BaseBlock;
94 
95  ASSERT(sizeof(HBASE_BLOCK) >= (HSECTOR_SIZE * Hive->Cluster));
96 
97  /* Allocate the buffer */
98  BaseBlock = Hive->Allocate(Hive->BaseBlockAlloc, Paged, Tag);
99  if (!BaseBlock) return NULL;
100 
101  /* Check for, and enforce, alignment */
102  Alignment = Hive->Cluster * HSECTOR_SIZE -1;
103  if ((ULONG_PTR)BaseBlock & Alignment)
104  {
105  /* Free the old header and reallocate a new one, always paged */
106  Hive->Free(BaseBlock, Hive->BaseBlockAlloc);
107  BaseBlock = Hive->Allocate(PAGE_SIZE, TRUE, Tag);
108  if (!BaseBlock) return NULL;
109 
110  Hive->BaseBlockAlloc = PAGE_SIZE;
111  }
112 
113  return BaseBlock;
114 }
#define TRUE
Definition: types.h:120
#define HSECTOR_SIZE
Definition: hivedata.h:42
uint32_t ULONG_PTR
Definition: typedefs.h:63
union Alignment_ Alignment
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
unsigned int ULONG
Definition: retypes.h:1

Referenced by HvpCreateHive(), HvpGetHiveHeader(), and HvpInitializeMemoryHive().

◆ HvpCreateHive()

NTSTATUS CMAPI HvpCreateHive ( IN OUT PHHIVE  RegistryHive,
IN PCUNICODE_STRING FileName  OPTIONAL 
)

Definition at line 160 of file hiveinit.c.

163 {
164  PHBASE_BLOCK BaseBlock;
165  ULONG Index;
166 
167  /* Allocate the base block */
168  BaseBlock = HvpAllocBaseBlockAligned(RegistryHive, FALSE, TAG_CM);
169  if (BaseBlock == NULL)
170  return STATUS_NO_MEMORY;
171 
172  /* Clear it */
173  RtlZeroMemory(BaseBlock, RegistryHive->BaseBlockAlloc);
174 
175  BaseBlock->Signature = HV_HBLOCK_SIGNATURE;
176  BaseBlock->Major = HSYS_MAJOR;
177  BaseBlock->Minor = HSYS_MINOR;
178  BaseBlock->Type = HFILE_TYPE_PRIMARY;
179  BaseBlock->Format = HBASE_FORMAT_MEMORY;
180  BaseBlock->Cluster = 1;
181  BaseBlock->RootCell = HCELL_NIL;
182  BaseBlock->Length = 0;
183  BaseBlock->Sequence1 = 1;
184  BaseBlock->Sequence2 = 1;
185  BaseBlock->TimeStamp.QuadPart = 0ULL;
186 
187  /*
188  * No need to compute the checksum since
189  * the hive resides only in memory so far.
190  */
191  BaseBlock->CheckSum = 0;
192 
193  /* Set default boot type */
194  BaseBlock->BootType = 0;
195 
196  /* Setup hive data */
197  RegistryHive->BaseBlock = BaseBlock;
198  RegistryHive->Version = BaseBlock->Minor; // == HSYS_MINOR
199 
200  for (Index = 0; Index < 24; Index++)
201  {
202  RegistryHive->Storage[Stable].FreeDisplay[Index] = HCELL_NIL;
203  RegistryHive->Storage[Volatile].FreeDisplay[Index] = HCELL_NIL;
204  }
205 
206  HvpInitFileName(BaseBlock, FileName);
207 
208  return STATUS_SUCCESS;
209 }
ULONG Sequence2
Definition: hivedata.h:123
ULONG Cluster
Definition: hivedata.h:149
ULONG BootType
Definition: hivedata.h:161
#define HSYS_MINOR
Definition: hivedata.h:58
ULONG Signature
Definition: hivedata.h:119
#define HCELL_NIL
Definition: hivedata.h:85
ULONG Length
Definition: hivedata.h:146
LARGE_INTEGER TimeStamp
Definition: hivedata.h:126
ULONG Sequence1
Definition: hivedata.h:122
static __inline PHBASE_BLOCK HvpAllocBaseBlockAligned(IN PHHIVE Hive, IN BOOLEAN Paged, IN ULONG Tag)
Definition: hiveinit.c:87
ULONG Major
Definition: hivedata.h:129
ULONG CheckSum
Definition: hivedata.h:158
#define HSYS_MAJOR
Definition: hivedata.h:57
smooth NULL
Definition: ftsmooth.c:416
#define ULL(a, b)
Definition: format_msg.c:27
static const UCHAR Index[8]
Definition: usbohci.c:18
#define TAG_CM
Definition: cmlib.h:203
static VOID HvpInitFileName(IN OUT PHBASE_BLOCK BaseBlock, IN PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:124
HCELL_INDEX RootCell
Definition: hivedata.h:143
#define HBASE_FORMAT_MEMORY
Definition: hivedata.h:66
#define HFILE_TYPE_PRIMARY
Definition: hivedata.h:33
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HV_HBLOCK_SIGNATURE
Definition: hivedata.h:51
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
ULONG Minor
Definition: hivedata.h:133
return STATUS_SUCCESS
Definition: btrfs.c:2777
ULONG Type
Definition: hivedata.h:136
LONGLONG QuadPart
Definition: typedefs.h:112
ULONG Format
Definition: hivedata.h:139

Referenced by HvInitialize().

◆ HvpFreeHiveBins()

VOID CMAPI HvpFreeHiveBins ( PHHIVE  Hive)

Definition at line 53 of file hiveinit.c.

55 {
56  ULONG i;
57  PHBIN Bin;
58  ULONG Storage;
59 
60  for (Storage = 0; Storage < Hive->StorageTypeCount; Storage++)
61  {
62  Bin = NULL;
63  for (i = 0; i < Hive->Storage[Storage].Length; i++)
64  {
66  continue;
68  {
70  Hive->Free((PHBIN)Hive->Storage[Storage].BlockList[i].BinAddress, 0);
71  }
74  }
75 
76  if (Hive->Storage[Storage].Length)
77  Hive->Free(Hive->Storage[Storage].BlockList, 0);
78  }
79 }
ULONG_PTR BlockAddress
Definition: hivedata.h:258
PFREE_ROUTINE Free
Definition: hivedata.h:294
struct _HBIN * PHBIN
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG StorageTypeCount
Definition: hivedata.h:329
smooth NULL
Definition: ftsmooth.c:416
Definition: bin.h:43
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
PHMAP_ENTRY BlockList
Definition: hivedata.h:278
ULONG_PTR BinAddress
Definition: hivedata.h:259
ULONG Length
Definition: hivedata.h:276
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvFree(), and HvpInitializeMemoryHive().

◆ HvpGetHiveHeader()

RESULT CMAPI HvpGetHiveHeader ( IN PHHIVE  Hive,
IN PHBASE_BLOCK HiveBaseBlock,
IN PLARGE_INTEGER  TimeStamp 
)

Definition at line 377 of file hiveinit.c.

380 {
381  PHBASE_BLOCK BaseBlock;
382  ULONG Result;
383  ULONG Offset = 0;
384 
385  ASSERT(sizeof(HBASE_BLOCK) >= (HSECTOR_SIZE * Hive->Cluster));
386 
387  /* Assume failure and allocate the base block */
388  *HiveBaseBlock = NULL;
389  BaseBlock = HvpAllocBaseBlockAligned(Hive, TRUE, TAG_CM);
390  if (!BaseBlock) return NoMemory;
391 
392  /* Clear it */
393  RtlZeroMemory(BaseBlock, sizeof(HBASE_BLOCK));
394 
395  /* Now read it from disk */
396  Result = Hive->FileRead(Hive,
398  &Offset,
399  BaseBlock,
400  Hive->Cluster * HSECTOR_SIZE);
401 
402  /* Couldn't read: assume it's not a hive */
403  if (!Result) return NotHive;
404 
405  /* Do validation */
406  if (!HvpVerifyHiveHeader(BaseBlock)) return NotHive;
407 
408  /* Return information */
409  *HiveBaseBlock = BaseBlock;
410  *TimeStamp = BaseBlock->TimeStamp;
411  return HiveSuccess;
412 }
#define TRUE
Definition: types.h:120
#define HSECTOR_SIZE
Definition: hivedata.h:42
LARGE_INTEGER TimeStamp
Definition: hivedata.h:126
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
static __inline PHBASE_BLOCK HvpAllocBaseBlockAligned(IN PHHIVE Hive, IN BOOLEAN Paged, IN ULONG Tag)
Definition: hiveinit.c:87
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
BOOLEAN CMAPI HvpVerifyHiveHeader(IN PHBASE_BLOCK BaseBlock)
Definition: hiveinit.c:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define TAG_CM
Definition: cmlib.h:203
#define HFILE_TYPE_PRIMARY
Definition: hivedata.h:33
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by HvLoadHive().

◆ HvpInitFileName()

static VOID HvpInitFileName ( IN OUT PHBASE_BLOCK  BaseBlock,
IN PCUNICODE_STRING FileName  OPTIONAL 
)
static

Definition at line 124 of file hiveinit.c.

127 {
129  SIZE_T Length;
130 
131  /* Always NULL-initialize */
132  RtlZeroMemory(BaseBlock->FileName, (HIVE_FILENAME_MAXLEN + 1) * sizeof(WCHAR));
133 
134  /* Copy the 31 last characters of the hive file name if any */
135  if (!FileName) return;
136 
137  if (FileName->Length / sizeof(WCHAR) <= HIVE_FILENAME_MAXLEN)
138  {
139  Offset = 0;
140  Length = FileName->Length;
141  }
142  else
143  {
144  Offset = FileName->Length / sizeof(WCHAR) - HIVE_FILENAME_MAXLEN;
145  Length = HIVE_FILENAME_MAXLEN * sizeof(WCHAR);
146  }
147 
148  RtlCopyMemory(BaseBlock->FileName, FileName->Buffer + Offset, Length);
149 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define HIVE_FILENAME_MAXLEN
Definition: hivedata.h:114
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by HvpCreateHive(), and HvpInitializeMemoryHive().

◆ HvpInitializeFlatHive()

NTSTATUS CMAPI HvpInitializeFlatHive ( PHHIVE  Hive,
PHBASE_BLOCK  ChunkBase 
)

Definition at line 344 of file hiveinit.c.

347 {
348  if (!HvpVerifyHiveHeader(ChunkBase))
350 
351  /* Setup hive data */
352  Hive->BaseBlock = ChunkBase;
353  Hive->Version = ChunkBase->Minor;
354  Hive->Flat = TRUE;
355  Hive->ReadOnly = TRUE;
356 
357  Hive->StorageTypeCount = 1;
358 
359  /* Set default boot type */
360  ChunkBase->BootType = 0;
361 
362  return STATUS_SUCCESS;
363 }
#define TRUE
Definition: types.h:120
ULONG BootType
Definition: hivedata.h:161
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
BOOLEAN ReadOnly
Definition: hivedata.h:310
ULONG StorageTypeCount
Definition: hivedata.h:329
#define STATUS_REGISTRY_CORRUPT
Definition: ntstatus.h:554
BOOLEAN CMAPI HvpVerifyHiveHeader(IN PHBASE_BLOCK BaseBlock)
Definition: hiveinit.c:18
ULONG Version
Definition: hivedata.h:330
ULONG Minor
Definition: hivedata.h:133
return STATUS_SUCCESS
Definition: btrfs.c:2777
BOOLEAN Flat
Definition: hivedata.h:309

Referenced by HvInitialize().

◆ HvpInitializeMemoryHive()

NTSTATUS CMAPI HvpInitializeMemoryHive ( PHHIVE  Hive,
PHBASE_BLOCK  ChunkBase,
IN PCUNICODE_STRING FileName  OPTIONAL 
)

Definition at line 221 of file hiveinit.c.

225 {
226  SIZE_T BlockIndex;
227  PHBIN Bin, NewBin;
228  ULONG i;
229  ULONG BitmapSize;
232 
233  ChunkSize = ChunkBase->Length;
234  DPRINT("ChunkSize: %zx\n", ChunkSize);
235 
236  if (ChunkSize < sizeof(HBASE_BLOCK) ||
237  !HvpVerifyHiveHeader(ChunkBase))
238  {
239  DPRINT1("Registry is corrupt: ChunkSize 0x%zx < sizeof(HBASE_BLOCK) 0x%zx, "
240  "or HvpVerifyHiveHeader() failed\n", ChunkSize, sizeof(HBASE_BLOCK));
242  }
243 
244  /* Allocate the base block */
246  if (Hive->BaseBlock == NULL)
247  return STATUS_NO_MEMORY;
248 
249  RtlCopyMemory(Hive->BaseBlock, ChunkBase, sizeof(HBASE_BLOCK));
250 
251  /* Setup hive data */
252  Hive->Version = ChunkBase->Minor;
253 
254  /*
255  * Build a block list from the in-memory chunk and copy the data as
256  * we go.
257  */
258 
260  Hive->Storage[Stable].BlockList =
261  Hive->Allocate(Hive->Storage[Stable].Length *
262  sizeof(HMAP_ENTRY), FALSE, TAG_CM);
263  if (Hive->Storage[Stable].BlockList == NULL)
264  {
265  DPRINT1("Allocating block list failed\n");
266  Hive->Free(Hive->BaseBlock, Hive->BaseBlockAlloc);
267  return STATUS_NO_MEMORY;
268  }
269 
270  for (BlockIndex = 0; BlockIndex < Hive->Storage[Stable].Length; )
271  {
272  Bin = (PHBIN)((ULONG_PTR)ChunkBase + (BlockIndex + 1) * HBLOCK_SIZE);
273  if (Bin->Signature != HV_HBIN_SIGNATURE ||
274  (Bin->Size % HBLOCK_SIZE) != 0)
275  {
276  DPRINT1("Invalid bin at BlockIndex %lu, Signature 0x%x, Size 0x%x\n",
277  (unsigned long)BlockIndex, (unsigned)Bin->Signature, (unsigned)Bin->Size);
278  Hive->Free(Hive->Storage[Stable].BlockList, 0);
279  Hive->Free(Hive->BaseBlock, Hive->BaseBlockAlloc);
281  }
282 
283  NewBin = Hive->Allocate(Bin->Size, TRUE, TAG_CM);
284  if (NewBin == NULL)
285  {
286  Hive->Free(Hive->Storage[Stable].BlockList, 0);
287  Hive->Free(Hive->BaseBlock, Hive->BaseBlockAlloc);
288  return STATUS_NO_MEMORY;
289  }
290 
291  Hive->Storage[Stable].BlockList[BlockIndex].BinAddress = (ULONG_PTR)NewBin;
292  Hive->Storage[Stable].BlockList[BlockIndex].BlockAddress = (ULONG_PTR)NewBin;
293 
294  RtlCopyMemory(NewBin, Bin, Bin->Size);
295 
296  if (Bin->Size > HBLOCK_SIZE)
297  {
298  for (i = 1; i < Bin->Size / HBLOCK_SIZE; i++)
299  {
300  Hive->Storage[Stable].BlockList[BlockIndex + i].BinAddress = (ULONG_PTR)NewBin;
301  Hive->Storage[Stable].BlockList[BlockIndex + i].BlockAddress =
302  ((ULONG_PTR)NewBin + (i * HBLOCK_SIZE));
303  }
304  }
305 
306  BlockIndex += Bin->Size / HBLOCK_SIZE;
307  }
308 
309  if (HvpCreateHiveFreeCellList(Hive))
310  {
311  HvpFreeHiveBins(Hive);
312  Hive->Free(Hive->BaseBlock, Hive->BaseBlockAlloc);
313  return STATUS_NO_MEMORY;
314  }
315 
316  BitmapSize = ROUND_UP(Hive->Storage[Stable].Length,
317  sizeof(ULONG) * 8) / 8;
318  BitmapBuffer = (PULONG)Hive->Allocate(BitmapSize, TRUE, TAG_CM);
319  if (BitmapBuffer == NULL)
320  {
321  HvpFreeHiveBins(Hive);
322  Hive->Free(Hive->BaseBlock, Hive->BaseBlockAlloc);
323  return STATUS_NO_MEMORY;
324  }
325 
326  RtlInitializeBitMap(&Hive->DirtyVector, BitmapBuffer, BitmapSize * 8);
328 
330 
331  return STATUS_SUCCESS;
332 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
#define HBLOCK_SIZE
Definition: hivedata.h:41
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
RTL_BITMAP DirtyVector
Definition: hivedata.h:304
Definition: hivedata.h:256
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
ULONG_PTR BlockAddress
Definition: hivedata.h:258
PFREE_ROUTINE Free
Definition: hivedata.h:294
struct _HBIN * PHBIN
PALLOCATE_ROUTINE Allocate
Definition: hivedata.h:293
NTSTATUS CMAPI HvpCreateHiveFreeCellList(PHHIVE Hive)
Definition: hivecell.c:279
ULONG Length
Definition: hivedata.h:146
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
static __inline PHBASE_BLOCK HvpAllocBaseBlockAligned(IN PHHIVE Hive, IN BOOLEAN Paged, IN ULONG Tag)
Definition: hiveinit.c:87
smooth NULL
Definition: ftsmooth.c:416
Definition: bin.h:43
void DPRINT(...)
Definition: polytest.cpp:61
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
#define STATUS_REGISTRY_CORRUPT
Definition: ntstatus.h:554
NTSYSAPI void WINAPI RtlClearAllBits(PRTL_BITMAP)
BOOLEAN CMAPI HvpVerifyHiveHeader(IN PHBASE_BLOCK BaseBlock)
Definition: hiveinit.c:18
ULONG Version
Definition: hivedata.h:330
#define HV_HBIN_SIGNATURE
Definition: hivedata.h:52
static ULONG BitmapBuffer[(XMS_BLOCKS+31)/32]
Definition: himem.c:86
#define TAG_CM
Definition: cmlib.h:203
static VOID HvpInitFileName(IN OUT PHBASE_BLOCK BaseBlock, IN PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:124
ULONG_PTR SIZE_T
Definition: typedefs.h:78
PHMAP_ENTRY BlockList
Definition: hivedata.h:278
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG_PTR BinAddress
Definition: hivedata.h:259
ULONG BaseBlockAlloc
Definition: hivedata.h:307
VOID CMAPI HvpFreeHiveBins(PHHIVE Hive)
Definition: hiveinit.c:53
unsigned int * PULONG
Definition: retypes.h:1
ULONG Length
Definition: hivedata.h:276
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
ULONG Minor
Definition: hivedata.h:133
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by HvInitialize(), and HvLoadHive().

◆ HvpVerifyHiveHeader()

BOOLEAN CMAPI HvpVerifyHiveHeader ( IN PHBASE_BLOCK  BaseBlock)

Definition at line 18 of file hiveinit.c.

20 {
21  if (BaseBlock->Signature != HV_HBLOCK_SIGNATURE ||
22  BaseBlock->Major != HSYS_MAJOR ||
23  BaseBlock->Minor < HSYS_MINOR ||
24  BaseBlock->Type != HFILE_TYPE_PRIMARY ||
25  BaseBlock->Format != HBASE_FORMAT_MEMORY ||
26  BaseBlock->Cluster != 1 ||
27  BaseBlock->Sequence1 != BaseBlock->Sequence2 ||
28  HvpHiveHeaderChecksum(BaseBlock) != BaseBlock->CheckSum)
29  {
30  DPRINT1("Verify Hive Header failed:\n");
31  DPRINT1(" Signature: 0x%x, expected 0x%x; Major: 0x%x, expected 0x%x\n",
32  BaseBlock->Signature, HV_HBLOCK_SIGNATURE, BaseBlock->Major, HSYS_MAJOR);
33  DPRINT1(" Minor: 0x%x expected to be >= 0x%x; Type: 0x%x, expected 0x%x\n",
34  BaseBlock->Minor, HSYS_MINOR, BaseBlock->Type, HFILE_TYPE_PRIMARY);
35  DPRINT1(" Format: 0x%x, expected 0x%x; Cluster: 0x%x, expected 1\n",
36  BaseBlock->Format, HBASE_FORMAT_MEMORY, BaseBlock->Cluster);
37  DPRINT1(" Sequence: 0x%x, expected 0x%x; Checksum: 0x%x, expected 0x%x\n",
38  BaseBlock->Sequence1, BaseBlock->Sequence2,
39  HvpHiveHeaderChecksum(BaseBlock), BaseBlock->CheckSum);
40 
41  return FALSE;
42  }
43 
44  return TRUE;
45 }
#define TRUE
Definition: types.h:120
ULONG CMAPI HvpHiveHeaderChecksum(PHBASE_BLOCK HiveHeader)
Definition: hivesum.c:17
#define HSYS_MINOR
Definition: hivedata.h:58
#define HSYS_MAJOR
Definition: hivedata.h:57
#define HBASE_FORMAT_MEMORY
Definition: hivedata.h:66
#define HFILE_TYPE_PRIMARY
Definition: hivedata.h:33
#define DPRINT1
Definition: precomp.h:8
#define HV_HBLOCK_SIGNATURE
Definition: hivedata.h:51

Referenced by HvpGetHiveHeader(), HvpInitializeFlatHive(), and HvpInitializeMemoryHive().