10 #define REG_ROOT_KEY_NAME L"\\Registry"
11 #define REG_MACHINE_KEY_NAME L"\\Registry\\Machine"
12 #define REG_HARDWARE_KEY_NAME L"\\Registry\\Machine\\HARDWARE"
13 #define REG_DESCRIPTION_KEY_NAME L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION"
14 #define REG_DEVICEMAP_KEY_NAME L"\\Registry\\Machine\\HARDWARE\\DEVICEMAP"
15 #define REG_RESOURCEMAP_KEY_NAME L"\\Registry\\Machine\\HARDWARE\\RESOURCEMAP"
16 #define REG_CLASSES_KEY_NAME L"\\Registry\\Machine\\Software\\Classes"
17 #define REG_SYSTEM_KEY_NAME L"\\Registry\\Machine\\System"
18 #define REG_SOFTWARE_KEY_NAME L"\\Registry\\Machine\\Software"
19 #define REG_SAM_KEY_NAME L"\\Registry\\Machine\\Sam"
20 #define REG_SEC_KEY_NAME L"\\Registry\\Machine\\Security"
21 #define REG_USER_KEY_NAME L"\\Registry\\User"
22 #define REG_DEFAULT_USER_KEY_NAME L"\\Registry\\User\\.Default"
23 #define REG_CURRENT_USER_KEY_NAME L"\\Registry\\User\\CurrentUser"
25 #define SYSTEM_REG_FILE L"\\SystemRoot\\System32\\Config\\SYSTEM"
26 #define SYSTEM_LOG_FILE L"\\SystemRoot\\System32\\Config\\SYSTEM.log"
27 #define SOFTWARE_REG_FILE L"\\SystemRoot\\System32\\Config\\SOFTWARE"
28 #define DEFAULT_USER_REG_FILE L"\\SystemRoot\\System32\\Config\\DEFAULT"
29 #define SAM_REG_FILE L"\\SystemRoot\\System32\\Config\\SAM"
30 #define SEC_REG_FILE L"\\SystemRoot\\System32\\Config\\SECURITY"
32 #define REG_SYSTEM_FILE_NAME L"\\SYSTEM"
33 #define REG_SOFTWARE_FILE_NAME L"\\SOFTWARE"
34 #define REG_DEFAULT_USER_FILE_NAME L"\\DEFAULT"
35 #define REG_SAM_FILE_NAME L"\\SAM"
36 #define REG_SEC_FILE_NAME L"\\SECURITY"
38 #define REG_BLOCK_SIZE 4096
39 #define REG_HBIN_DATA_OFFSET 32
40 #define REG_INIT_BLOCK_LIST_SIZE 32
41 #define REG_INIT_HASH_TABLE_SIZE 3
42 #define REG_EXTEND_HASH_TABLE_SIZE 4
43 #define REG_VALUE_LIST_CELL_MULTIPLE 4
45 #define REG_HIVE_ID 0x66676572
46 #define REG_BIN_ID 0x6e696268
47 #define REG_KEY_CELL_ID 0x6b6e
48 #define REG_HASH_TABLE_CELL_ID 0x666c
49 #define REG_VALUE_CELL_ID 0x6b76
52 // BLOCK_OFFSET = offset in file after header block
53 typedef ULONG BLOCK_OFFSET
, *PBLOCK_OFFSET
;
57 /* header for registry hive file : */
58 typedef struct _HIVE_HEADER
60 /* Hive identifier "regf" (0x66676572) */
69 /* When this hive file was last modified */
70 LARGE_INTEGER DateModified
;
72 /* Registry format version ? (1?) */
75 /* Registry format version ? (3?) */
78 /* Registry format version ? (0?) */
81 /* Registry format version ? (1?) */
84 /* Offset into file from the byte after the end of the base block.
85 If the hive is volatile, this is the actual pointer to the KEY_CELL */
86 BLOCK_OFFSET RootKeyOffset
;
88 /* Size of each hive block ? */
94 /* Name of hive file */
100 /* Checksum of first 0x200 bytes */
102 } HIVE_HEADER
, *PHIVE_HEADER
;
106 /* Bin identifier "hbin" (0x6E696268) */
109 /* Block offset of this bin */
110 BLOCK_OFFSET BlockOffset
;
112 /* Size in bytes, multiple of the block size (4KB) */
118 /* When this bin was last modified */
119 LARGE_INTEGER DateModified
;
125 typedef struct _CELL_HEADER
127 /* <0 if used, >0 if free */
129 } CELL_HEADER
, *PCELL_HEADER
;
131 typedef struct _KEY_CELL
133 /* Size of this cell */
136 /* Key cell identifier "kn" (0x6b6e) */
142 /* Time of last flush */
143 LARGE_INTEGER LastWriteTime
;
148 /* Block offset of parent key cell */
149 BLOCK_OFFSET ParentKeyOffset
;
151 /* Count of sub keys for the key in this key cell */
152 ULONG NumberOfSubKeys
;
157 /* Block offset of has table for FIXME: subkeys/values? */
158 BLOCK_OFFSET HashTableOffset
;
163 /* Count of values contained in this key cell */
164 ULONG NumberOfValues
;
166 /* Block offset of VALUE_LIST_CELL */
167 BLOCK_OFFSET ValueListOffset
;
169 /* Block offset of security cell */
170 BLOCK_OFFSET SecurityKeyOffset
;
172 /* Block offset of registry key class */
173 BLOCK_OFFSET ClassNameOffset
;
178 /* Size in bytes of key name */
181 /* Size of class name in bytes */
184 /* Name of key (not zero terminated) */
186 } KEY_CELL
, *PKEY_CELL
;
188 /* KEY_CELL.Flags constants */
189 #define REG_KEY_ROOT_CELL 0x0C
190 #define REG_KEY_LINK_CELL 0x10
191 #define REG_KEY_NAME_PACKED 0x20
197 * packed name: four letters of value's name
200 typedef struct _HASH_RECORD
202 BLOCK_OFFSET KeyOffset
;
204 } HASH_RECORD
, *PHASH_RECORD
;
206 typedef struct _HASH_TABLE_CELL
210 USHORT HashTableSize
;
211 HASH_RECORD Table
[0];
212 } HASH_TABLE_CELL
, *PHASH_TABLE_CELL
;
215 typedef struct _VALUE_LIST_CELL
218 BLOCK_OFFSET ValueOffset
[0];
219 } VALUE_LIST_CELL
, *PVALUE_LIST_CELL
;
221 typedef struct _VALUE_CELL
225 USHORT NameSize
; // length of Name
226 ULONG DataSize
; // length of datas in the cell pointed by DataOffset
227 BLOCK_OFFSET DataOffset
;// datas are here if high bit of DataSize is set
231 UCHAR Name
[0]; /* warning : not zero terminated */
232 } VALUE_CELL
, *PVALUE_CELL
;
234 /* VALUE_CELL.Flags constants */
235 #define REG_VALUE_NAME_PACKED 0x0001
237 /* VALUE_CELL.DataSize mask constants */
238 #define REG_DATA_SIZE_MASK 0x7FFFFFFF
239 #define REG_DATA_IN_OFFSET 0x80000000
242 typedef struct _DATA_CELL
246 } DATA_CELL
, *PDATA_CELL
;
251 typedef struct _REGISTRY_HIVE
255 UNICODE_STRING HiveFileName
;
256 UNICODE_STRING LogFileName
;
258 PHIVE_HEADER HiveHeader
;
264 PCELL_HEADER
*FreeList
;
265 BLOCK_OFFSET
*FreeListOffset
;
266 ERESOURCE HiveResource
;
269 RTL_BITMAP DirtyBitMap
;
271 } REGISTRY_HIVE
, *PREGISTRY_HIVE
;
273 /* REGISTRY_HIVE.Flags constants */
274 /* When set, the hive uses pointers instead of offsets. */
275 #define HIVE_POINTER 0x00000001
277 /* When set, the hive is not backed by a file.
278 Therefore, it can not be flushed to disk. */
279 #define HIVE_NO_FILE 0x00000002
281 /* When set, a modified (dirty) hive is not synchronized automatically.
282 Explicit synchronization (save/flush) works. */
283 #define HIVE_NO_SYNCH 0x00000004
285 #define IsPointerHive(Hive) ((Hive)->Flags & HIVE_POINTER)
286 #define IsNoFileHive(Hive) ((Hive)->Flags & HIVE_NO_FILE)
287 #define IsNoSynchHive(Hive) ((Hive)->Flags & HIVE_NO_SYNCH)
290 #define IsFreeCell(Cell)(Cell->CellSize >= 0)
291 #define IsUsedCell(Cell)(Cell->CellSize < 0)
294 /* KEY_OBJECT.Flags */
296 /* When set, the key is scheduled for deletion, and all
297 attempts to access the key must not succeed */
298 #define KO_MARKED_FOR_DELETE 0x00000001
301 /* Type defining the Object Manager Key Object */
302 typedef struct _KEY_OBJECT
304 /* Fields used by the Object Manager */
314 /* Registry hive the key belongs to */
315 PREGISTRY_HIVE RegistryHive
;
317 /* Block offset of the key cell this key belongs in */
318 BLOCK_OFFSET KeyCellOffset
;
320 /* KEY_CELL this key belong in */
323 /* Link to the parent KEY_OBJECT for this key */
324 struct _KEY_OBJECT
*ParentKey
;
326 /* Subkeys loaded in SubKeys */
327 ULONG NumberOfSubKeys
;
329 /* Space allocated in SubKeys */
332 /* List of subkeys loaded */
333 struct _KEY_OBJECT
**SubKeys
;
334 } KEY_OBJECT
, *PKEY_OBJECT
;
336 /* Bits 31-22 (top 10 bits) of the cell index is the directory index */
337 #define CmiDirectoryIndex(CellIndex)(CellIndex & 0xffc000000)
338 /* Bits 21-12 (middle 10 bits) of the cell index is the table index */
339 #define CmiTableIndex(Cellndex)(CellIndex & 0x003ff000)
340 /* Bits 11-0 (bottom 12 bits) of the cell index is the byte offset */
341 #define CmiByteOffset(Cellndex)(CellIndex & 0x00000fff)
344 extern BOOLEAN CmiDoVerify
;
345 extern PREGISTRY_HIVE CmiVolatileHive
;
346 extern POBJECT_TYPE CmiKeyType
;
347 extern KSPIN_LOCK CmiKeyListLock
;
349 extern LIST_ENTRY CmiHiveListHead
;
350 extern ERESOURCE CmiHiveListLock
;
354 CmiVerifyBinCell(PHBIN BinCell
);
356 CmiVerifyKeyCell(PKEY_CELL KeyCell
);
358 CmiVerifyRootKeyCell(PKEY_CELL RootKeyCell
);
360 CmiVerifyKeyObject(PKEY_OBJECT KeyObject
);
362 CmiVerifyRegistryHive(PREGISTRY_HIVE RegistryHive
);
365 #define VERIFY_BIN_CELL CmiVerifyBinCell
366 #define VERIFY_KEY_CELL CmiVerifyKeyCell
367 #define VERIFY_ROOT_KEY_CELL CmiVerifyRootKeyCell
368 #define VERIFY_VALUE_CELL CmiVerifyValueCell
369 #define VERIFY_VALUE_LIST_CELL CmiVerifyValueListCell
370 #define VERIFY_KEY_OBJECT CmiVerifyKeyObject
371 #define VERIFY_REGISTRY_HIVE CmiVerifyRegistryHive
373 #define VERIFY_BIN_CELL(x)
374 #define VERIFY_KEY_CELL(x)
375 #define VERIFY_ROOT_KEY_CELL(x)
376 #define VERIFY_VALUE_CELL(x)
377 #define VERIFY_VALUE_LIST_CELL(x)
378 #define VERIFY_KEY_OBJECT(x)
379 #define VERIFY_REGISTRY_HIVE(x)
383 CmiObjectParse(IN PVOID ParsedObject
,
384 OUT PVOID
*NextObject
,
385 IN PUNICODE_STRING FullPath
,
390 CmiObjectCreate(PVOID ObjectBody
,
393 POBJECT_ATTRIBUTES ObjectAttributes
);
396 CmiObjectDelete(PVOID DeletedObject
);
399 CmiObjectSecurity(PVOID ObjectBody
,
400 SECURITY_OPERATION_CODE OperationCode
,
401 SECURITY_INFORMATION SecurityInformation
,
402 PSECURITY_DESCRIPTOR SecurityDescriptor
,
403 PULONG BufferLength
);
406 CmiObjectQueryName (PVOID ObjectBody
,
407 POBJECT_NAME_INFORMATION ObjectNameInfo
,
409 PULONG ReturnLength
);
412 CmiImportHiveBins(PREGISTRY_HIVE Hive
,
416 CmiFreeHiveBins(PREGISTRY_HIVE Hive
);
419 CmiCreateHiveFreeCellList(PREGISTRY_HIVE Hive
);
422 CmiFreeHiveFreeCellList(PREGISTRY_HIVE Hive
);
425 CmiCreateHiveBitmap(PREGISTRY_HIVE Hive
);
429 CmiAddKeyToList(IN PKEY_OBJECT ParentKey
,
430 IN PKEY_OBJECT NewKey
);
433 CmiRemoveKeyFromList(IN PKEY_OBJECT NewKey
);
436 CmiScanKeyList(IN PKEY_OBJECT Parent
,
437 IN PUNICODE_STRING KeyName
,
438 IN ULONG Attributes
);
441 CmiCreateVolatileHive(PREGISTRY_HIVE
*RegistryHive
);
444 CmiLoadHive(POBJECT_ATTRIBUTES KeyObjectAttributes
,
445 PUNICODE_STRING FileName
,
449 CmiRemoveRegistryHive(PREGISTRY_HIVE RegistryHive
);
452 CmiFlushRegistryHive(PREGISTRY_HIVE RegistryHive
);
455 CmiGetMaxNameLength(IN PKEY_OBJECT KeyObject
);
458 CmiGetMaxClassLength(IN PKEY_OBJECT KeyObject
);
461 CmiGetMaxValueNameLength(IN PREGISTRY_HIVE RegistryHive
,
462 IN PKEY_CELL KeyCell
);
465 CmiGetMaxValueDataLength(IN PREGISTRY_HIVE RegistryHive
,
466 IN PKEY_CELL KeyCell
);
469 CmiScanForSubKey(IN PREGISTRY_HIVE RegistryHive
,
470 IN PKEY_CELL KeyCell
,
471 OUT PKEY_CELL
*SubKeyCell
,
472 OUT BLOCK_OFFSET
*BlockOffset
,
473 IN PUNICODE_STRING KeyName
,
474 IN ACCESS_MASK DesiredAccess
,
475 IN ULONG Attributes
);
478 CmiAddSubKey(IN PREGISTRY_HIVE RegistryHive
,
479 IN PKEY_OBJECT ParentKey
,
480 OUT PKEY_OBJECT SubKey
,
481 IN PUNICODE_STRING SubKeyName
,
483 IN PUNICODE_STRING Class
,
484 IN ULONG CreateOptions
);
487 CmiRemoveSubKey(IN PREGISTRY_HIVE RegistryHive
,
488 IN PKEY_OBJECT Parent
,
489 IN PKEY_OBJECT SubKey
);
492 CmiScanKeyForValue(IN PREGISTRY_HIVE RegistryHive
,
493 IN PKEY_CELL KeyCell
,
494 IN PUNICODE_STRING ValueName
,
495 OUT PVALUE_CELL
*ValueCell
,
496 OUT BLOCK_OFFSET
*VBOffset
);
499 CmiGetValueFromKeyByIndex(IN PREGISTRY_HIVE RegistryHive
,
500 IN PKEY_CELL KeyCell
,
502 OUT PVALUE_CELL
*ValueCell
);
505 CmiAddValueToKey(IN PREGISTRY_HIVE RegistryHive
,
506 IN PKEY_CELL KeyCell
,
507 IN BLOCK_OFFSET KeyCellOffset
,
508 IN PUNICODE_STRING ValueName
,
509 OUT PVALUE_CELL
*pValueCell
,
510 OUT BLOCK_OFFSET
*pValueCellOffset
);
513 CmiDeleteValueFromKey(IN PREGISTRY_HIVE RegistryHive
,
514 IN PKEY_CELL KeyCell
,
515 IN BLOCK_OFFSET KeyCellOffset
,
516 IN PUNICODE_STRING ValueName
);
519 CmiAllocateHashTableCell(IN PREGISTRY_HIVE RegistryHive
,
520 OUT PHASH_TABLE_CELL
*HashBlock
,
521 OUT BLOCK_OFFSET
*HBOffset
,
522 IN ULONG HashTableSize
);
525 CmiGetKeyFromHashByIndex(PREGISTRY_HIVE RegistryHive
,
526 PHASH_TABLE_CELL HashBlock
,
530 CmiAddKeyToHashTable(PREGISTRY_HIVE RegistryHive
,
531 PHASH_TABLE_CELL HashCell
,
532 BLOCK_OFFSET HashCellOffset
,
533 PKEY_CELL NewKeyCell
,
534 BLOCK_OFFSET NKBOffset
);
537 CmiRemoveKeyFromHashTable(PREGISTRY_HIVE RegistryHive
,
538 PHASH_TABLE_CELL HashBlock
,
539 BLOCK_OFFSET NKBOffset
);
542 CmiAllocateValueCell(IN PREGISTRY_HIVE RegistryHive
,
543 OUT PVALUE_CELL
*ValueCell
,
544 OUT BLOCK_OFFSET
*VBOffset
,
545 IN PUNICODE_STRING ValueName
);
548 CmiDestroyValueCell(PREGISTRY_HIVE RegistryHive
,
549 PVALUE_CELL ValueCell
,
550 BLOCK_OFFSET VBOffset
);
553 CmiAllocateCell(PREGISTRY_HIVE RegistryHive
,
556 BLOCK_OFFSET
*CellOffset
);
559 CmiDestroyCell(PREGISTRY_HIVE RegistryHive
,
561 BLOCK_OFFSET CellOffset
);
564 CmiGetCell (PREGISTRY_HIVE RegistryHive
,
565 BLOCK_OFFSET CellOffset
,
569 CmiMarkBlockDirty(PREGISTRY_HIVE RegistryHive
,
570 BLOCK_OFFSET BlockOffset
);
573 CmiMarkBinDirty(PREGISTRY_HIVE RegistryHive
,
574 BLOCK_OFFSET BinOffset
);
577 CmiAddFree(PREGISTRY_HIVE RegistryHive
,
578 PCELL_HEADER FreeBlock
,
579 BLOCK_OFFSET FreeOffset
,
580 BOOLEAN MergeFreeBlocks
);
583 CmiConnectHive(POBJECT_ATTRIBUTES KeyObjectAttributes
,
584 PREGISTRY_HIVE RegistryHive
);
587 CmiDisconnectHive (POBJECT_ATTRIBUTES KeyObjectAttributes
,
588 PREGISTRY_HIVE
*RegistryHive
);
591 CmiInitHives(BOOLEAN SetupBoot
);
594 CmiGetPackedNameLength(IN PUNICODE_STRING Name
,
595 OUT PBOOLEAN Packable
);
598 CmiComparePackedNames(IN PUNICODE_STRING Name
,
600 IN USHORT NameBufferSize
,
601 IN BOOLEAN NamePacked
);
604 CmiCopyPackedName(PWCHAR NameBuffer
,
605 PCHAR PackedNameBuffer
,
606 ULONG PackedNameSize
);
609 CmiCompareHash(PUNICODE_STRING KeyName
,
613 CmiCompareHashI(PUNICODE_STRING KeyName
,
617 CmiCompareKeyNames(PUNICODE_STRING KeyName
,
621 CmiCompareKeyNamesI(PUNICODE_STRING KeyName
,
630 CmiCreateTempHive(PREGISTRY_HIVE
*RegistryHive
);
633 CmiCopyKey (PREGISTRY_HIVE DstHive
,
634 PKEY_CELL DstKeyCell
,
635 PREGISTRY_HIVE SrcHive
,
636 PKEY_CELL SrcKeyCell
);
639 CmiSaveTempHive (PREGISTRY_HIVE Hive
,
642 #endif /*__INCLUDE_CM_H*/