1 /* 2 * PROJECT: Registry manipulation library 3 * LICENSE: GPL - See COPYING in the top level directory 4 * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org> 5 * Copyright 2001 - 2005 Eric Kohl 6 */ 7 8 #pragma once 9 10 // 11 // Hive operations 12 // 13 #define HINIT_CREATE 0 14 #define HINIT_MEMORY 1 15 #define HINIT_FILE 2 16 #define HINIT_MEMORY_INPLACE 3 17 #define HINIT_FLAT 4 18 #define HINIT_MAPFILE 5 19 20 // 21 // Hive flags 22 // 23 #define HIVE_VOLATILE 1 24 #define HIVE_NOLAZYFLUSH 2 25 #define HIVE_HAS_BEEN_REPLACED 4 26 #define HIVE_HAS_BEEN_FREED 8 27 #define HIVE_UNKNOWN 0x10 28 #define HIVE_IS_UNLOADING 0x20 29 30 // 31 // Hive types 32 // 33 #define HFILE_TYPE_PRIMARY 0 34 #define HFILE_TYPE_LOG 1 35 #define HFILE_TYPE_EXTERNAL 2 36 #define HFILE_TYPE_MAX 3 37 38 // 39 // Hive sizes 40 // 41 #define HBLOCK_SIZE 0x1000 42 #define HSECTOR_SIZE 0x200 43 #define HSECTOR_COUNT 8 44 45 #define HV_LOG_HEADER_SIZE FIELD_OFFSET(HBASE_BLOCK, Reserved2) 46 47 // 48 // Hive structure identifiers 49 // 50 #define HV_HHIVE_SIGNATURE 0xbee0bee0 51 #define HV_HBLOCK_SIGNATURE 0x66676572 // "regf" 52 #define HV_HBIN_SIGNATURE 0x6e696268 // "hbin" 53 54 // 55 // Hive versions 56 // 57 #define HSYS_MAJOR 1 58 #define HSYS_MINOR 3 59 #define HSYS_WHISTLER_BETA1 4 60 #define HSYS_WHISTLER 5 61 #define HSYS_MINOR_SUPPORTED HSYS_WHISTLER 62 63 // 64 // Hive formats 65 // 66 #define HBASE_FORMAT_MEMORY 1 67 68 // 69 // Hive storage 70 // 71 #define HTYPE_COUNT 2 72 73 /** 74 * @name HCELL_INDEX 75 * 76 * A handle to cell index. The highest bit specifies the cell storage and 77 * the other bits specify index into the hive file. The value HCELL_NULL 78 * (-1) is reserved for marking invalid cells. 79 */ 80 typedef ULONG HCELL_INDEX, *PHCELL_INDEX; 81 82 // 83 // Cell Magic Values 84 // 85 #define HCELL_NIL MAXULONG 86 #define HCELL_CACHED 1 87 88 #define HCELL_TYPE_MASK 0x80000000 89 #define HCELL_BLOCK_MASK 0x7ffff000 90 #define HCELL_OFFSET_MASK 0x00000fff 91 #define HCELL_TYPE_SHIFT 31 92 #define HCELL_BLOCK_SHIFT 12 93 #define HCELL_OFFSET_SHIFT 0 94 95 #define HvGetCellType(Cell) \ 96 ((ULONG)(((Cell) & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT)) 97 #define HvGetCellBlock(Cell) \ 98 ((ULONG)(((Cell) & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT)) 99 100 typedef enum 101 { 102 Stable = 0, 103 Volatile = 1 104 } HSTORAGE_TYPE; 105 106 #include <pshpack1.h> 107 108 /** 109 * @name HBASE_BLOCK 110 * 111 * On-disk header for registry hive file. 112 */ 113 114 #define HIVE_FILENAME_MAXLEN 31 115 116 typedef struct _HBASE_BLOCK 117 { 118 /* Hive base block identifier "regf" (0x66676572) */ 119 ULONG Signature; 120 121 /* Update counters */ 122 ULONG Sequence1; 123 ULONG Sequence2; 124 125 /* When this hive file was last modified */ 126 LARGE_INTEGER TimeStamp; 127 128 /* Registry format major version (1) */ 129 ULONG Major; 130 131 /* Registry format minor version (3) 132 Version 3 added fast indexes, version 5 has large value optimizations */ 133 ULONG Minor; 134 135 /* Registry file type (0 - Primary, 1 - Log) */ 136 ULONG Type; 137 138 /* Registry format (1 is the only defined value so far) */ 139 ULONG Format; 140 141 /* Offset into file from the byte after the end of the base block. 142 If the hive is volatile, this is the actual pointer to the CM_KEY_NODE */ 143 HCELL_INDEX RootCell; 144 145 /* Size in bytes of the full hive, minus the header, multiple of the block size (4KB) */ 146 ULONG Length; 147 148 /* (1?) */ 149 ULONG Cluster; 150 151 /* Last 31 UNICODE characters, plus terminating NULL character, 152 of the full name of the hive file */ 153 WCHAR FileName[HIVE_FILENAME_MAXLEN + 1]; 154 155 ULONG Reserved1[99]; 156 157 /* Checksum of first 0x200 bytes */ 158 ULONG CheckSum; 159 160 ULONG Reserved2[0x37E]; 161 ULONG BootType; 162 ULONG BootRecover; 163 } HBASE_BLOCK, *PHBASE_BLOCK; 164 165 C_ASSERT(sizeof(HBASE_BLOCK) == HBLOCK_SIZE); 166 167 typedef struct _HBIN 168 { 169 /* Hive bin identifier "hbin" (0x6E696268) */ 170 ULONG Signature; 171 172 /* Block offset of this bin */ 173 HCELL_INDEX FileOffset; 174 175 /* Size in bytes of this bin, multiple of the block size (4KB) */ 176 ULONG Size; 177 178 ULONG Reserved1[2]; 179 180 /* When this bin was last modified */ 181 LARGE_INTEGER TimeStamp; 182 183 /* Unused (In-memory only) */ 184 ULONG Spare; 185 } HBIN, *PHBIN; 186 187 typedef struct _HCELL 188 { 189 /* <0 if used, >0 if free */ 190 LONG Size; 191 } HCELL, *PHCELL; 192 193 #include <poppack.h> 194 195 struct _HHIVE; 196 197 typedef struct _CELL_DATA* 198 (CMAPI *PGET_CELL_ROUTINE)( 199 struct _HHIVE *Hive, 200 HCELL_INDEX Cell 201 ); 202 203 typedef VOID 204 (CMAPI *PRELEASE_CELL_ROUTINE)( 205 struct _HHIVE *Hive, 206 HCELL_INDEX Cell 207 ); 208 209 typedef PVOID 210 (CMAPI *PALLOCATE_ROUTINE)( 211 SIZE_T Size, 212 BOOLEAN Paged, 213 ULONG Tag 214 ); 215 216 typedef VOID 217 (CMAPI *PFREE_ROUTINE)( 218 PVOID Ptr, 219 ULONG Quota 220 ); 221 222 typedef BOOLEAN 223 (CMAPI *PFILE_READ_ROUTINE)( 224 struct _HHIVE *RegistryHive, 225 ULONG FileType, 226 PULONG FileOffset, 227 PVOID Buffer, 228 SIZE_T BufferLength 229 ); 230 231 typedef BOOLEAN 232 (CMAPI *PFILE_WRITE_ROUTINE)( 233 struct _HHIVE *RegistryHive, 234 ULONG FileType, 235 PULONG FileOffset, 236 PVOID Buffer, 237 SIZE_T BufferLength 238 ); 239 240 typedef BOOLEAN 241 (CMAPI *PFILE_SET_SIZE_ROUTINE)( 242 struct _HHIVE *RegistryHive, 243 ULONG FileType, 244 ULONG FileSize, 245 ULONG OldfileSize 246 ); 247 248 typedef BOOLEAN 249 (CMAPI *PFILE_FLUSH_ROUTINE)( 250 struct _HHIVE *RegistryHive, 251 ULONG FileType, 252 PLARGE_INTEGER FileOffset, 253 ULONG Length 254 ); 255 256 typedef struct _HMAP_ENTRY 257 { 258 ULONG_PTR BlockAddress; 259 ULONG_PTR BinAddress; 260 struct _CM_VIEW_OF_FILE *CmView; 261 ULONG MemAlloc; 262 } HMAP_ENTRY, *PHMAP_ENTRY; 263 264 typedef struct _HMAP_TABLE 265 { 266 HMAP_ENTRY Table[512]; 267 } HMAP_TABLE, *PHMAP_TABLE; 268 269 typedef struct _HMAP_DIRECTORY 270 { 271 PHMAP_TABLE Directory[2048]; 272 } HMAP_DIRECTORY, *PHMAP_DIRECTORY; 273 274 typedef struct _DUAL 275 { 276 ULONG Length; 277 PHMAP_DIRECTORY Map; 278 PHMAP_ENTRY BlockList; // PHMAP_TABLE SmallDir; 279 ULONG Guard; 280 HCELL_INDEX FreeDisplay[24]; // FREE_DISPLAY FreeDisplay[24]; 281 ULONG FreeSummary; 282 LIST_ENTRY FreeBins; 283 } DUAL, *PDUAL; 284 285 typedef struct _HHIVE 286 { 287 /* Hive identifier (0xBEE0BEE0) */ 288 ULONG Signature; 289 290 /* Callbacks */ 291 PGET_CELL_ROUTINE GetCellRoutine; 292 PRELEASE_CELL_ROUTINE ReleaseCellRoutine; 293 PALLOCATE_ROUTINE Allocate; 294 PFREE_ROUTINE Free; 295 PFILE_SET_SIZE_ROUTINE FileSetSize; 296 PFILE_WRITE_ROUTINE FileWrite; 297 PFILE_READ_ROUTINE FileRead; 298 PFILE_FLUSH_ROUTINE FileFlush; 299 300 #if (NTDDI_VERSION >= NTDDI_WIN7) 301 PVOID HiveLoadFailure; // PHIVE_LOAD_FAILURE 302 #endif 303 PHBASE_BLOCK BaseBlock; 304 RTL_BITMAP DirtyVector; 305 ULONG DirtyCount; 306 ULONG DirtyAlloc; 307 ULONG BaseBlockAlloc; 308 ULONG Cluster; 309 BOOLEAN Flat; 310 BOOLEAN ReadOnly; 311 #if (NTDDI_VERSION < NTDDI_VISTA) // NTDDI_LONGHORN 312 BOOLEAN Log; 313 #endif 314 BOOLEAN DirtyFlag; 315 #if (NTDDI_VERSION >= NTDDI_VISTA) // NTDDI_LONGHORN 316 ULONG HvBinHeadersUse; 317 ULONG HvFreeCellsUse; 318 ULONG HvUsedCellsUse; 319 ULONG CmUsedCellsUse; 320 #endif 321 ULONG HiveFlags; 322 #if (NTDDI_VERSION < NTDDI_VISTA) // NTDDI_LONGHORN 323 ULONG LogSize; 324 #else 325 ULONG CurrentLog; 326 ULONG LogSize[2]; 327 #endif 328 ULONG RefreshCount; 329 ULONG StorageTypeCount; 330 ULONG Version; 331 DUAL Storage[HTYPE_COUNT]; 332 } HHIVE, *PHHIVE; 333 334 #define IsFreeCell(Cell) ((Cell)->Size >= 0) 335 #define IsUsedCell(Cell) ((Cell)->Size < 0) 336