[169] | 1 | /* |
---|
[168] | 2 | * Copyright (C) 2005-2010 Timothy D. Morgan |
---|
[30] | 3 | * Copyright (C) 2005 Gerald (Jerry) Carter |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
[134] | 7 | * the Free Software Foundation; version 3 of the License. |
---|
[30] | 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | * GNU General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program; if not, write to the Free Software |
---|
| 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 17 | * |
---|
| 18 | * $Id: regfi.h 182 2010-03-17 06:41:17Z tim $ |
---|
| 19 | */ |
---|
| 20 | |
---|
[169] | 21 | /** |
---|
| 22 | * @file |
---|
| 23 | * Windows NT (and later) read-only registry library |
---|
| 24 | * |
---|
| 25 | * This library is intended for use in digital forensics investigations, but |
---|
| 26 | * is likely useful in other applications. |
---|
| 27 | * |
---|
| 28 | * Branched from Samba project Subversion repository, version #6903: |
---|
| 29 | * http://viewcvs.samba.org/cgi-bin/viewcvs.cgi/trunk/source/include/regfio.h?rev=6903&view=auto |
---|
| 30 | * |
---|
| 31 | * Since then, it has been heavily rewritten, simplified, and improved. |
---|
| 32 | */ |
---|
[30] | 33 | |
---|
[168] | 34 | /** |
---|
| 35 | * @mainpage Home |
---|
| 36 | * |
---|
[169] | 37 | * The regfi library is a read-only NT registry library which serves as the main |
---|
| 38 | * engine behind the reglookup tool. It is designed with digital forensic |
---|
| 39 | * analysis in mind, but it should also be useful in other tools which need to |
---|
| 40 | * efficiently traverse and query registry data structures. |
---|
| 41 | * |
---|
| 42 | * The library is broken down into four main parts, the |
---|
| 43 | * @ref regfiBase "Base Layer", which any code dependent on the library will |
---|
| 44 | * likely need to rely on, as well as three main functional layers: |
---|
| 45 | * @li @ref regfiIteratorLayer |
---|
| 46 | * @li @ref regfiGlueLayer |
---|
| 47 | * @li @ref regfiParseLayer |
---|
| 48 | * |
---|
| 49 | * Most users will find that a combination of the Base Layer and the Iterator Layer |
---|
| 50 | * will be sufficient for accessing registry hive files. Those who are wiling |
---|
| 51 | * to dive deep into registry data structures, for instance to recover deleted |
---|
| 52 | * data structures or to research Windows registry behavior in detail, will |
---|
| 53 | * find the Parse Layer to be quite useful. |
---|
[168] | 54 | */ |
---|
| 55 | |
---|
[169] | 56 | |
---|
[78] | 57 | #ifndef _REGFI_H |
---|
| 58 | #define _REGFI_H |
---|
[30] | 59 | |
---|
[31] | 60 | #include <stdlib.h> |
---|
| 61 | #include <stdio.h> |
---|
[30] | 62 | #include <stdbool.h> |
---|
[31] | 63 | #include <string.h> |
---|
[30] | 64 | #include <errno.h> |
---|
[31] | 65 | #include <time.h> |
---|
[30] | 66 | #include <fcntl.h> |
---|
| 67 | #include <sys/stat.h> |
---|
| 68 | #include <sys/types.h> |
---|
| 69 | #include <unistd.h> |
---|
[159] | 70 | #include <iconv.h> |
---|
[180] | 71 | #include <pthread.h> |
---|
[30] | 72 | |
---|
[168] | 73 | #include "byteorder.h" |
---|
[147] | 74 | #include "talloc.h" |
---|
[132] | 75 | #include "winsec.h" |
---|
[78] | 76 | #include "void_stack.h" |
---|
[99] | 77 | #include "range_list.h" |
---|
[108] | 78 | #include "lru_cache.h" |
---|
[30] | 79 | |
---|
| 80 | /******************************************************************************/ |
---|
[138] | 81 | |
---|
| 82 | /* regfi library error message types */ |
---|
[182] | 83 | #define REGFI_LOG_INFO 0x0001 |
---|
| 84 | #define REGFI_LOG_WARN 0x0004 |
---|
| 85 | #define REGFI_LOG_ERROR 0x0010 |
---|
[138] | 86 | |
---|
[182] | 87 | /* For internal use */ |
---|
| 88 | pthread_key_t REGFI_LOG_KEY; |
---|
| 89 | |
---|
[168] | 90 | typedef uint8_t REGFI_ENCODING; |
---|
[161] | 91 | /* regfi library supported character encodings */ |
---|
| 92 | #define REGFI_ENCODING_ASCII 0 |
---|
| 93 | #define REGFI_ENCODING_UTF8 1 |
---|
| 94 | #define REGFI_ENCODING_DEFAULT REGFI_ENCODING_ASCII |
---|
| 95 | /* UTF16LE is not supported for output */ |
---|
| 96 | #define REGFI_ENCODING_UTF16LE 2 |
---|
| 97 | |
---|
| 98 | #define REGFI_NUM_ENCODINGS 3 |
---|
| 99 | |
---|
[32] | 100 | /* Registry data types */ |
---|
| 101 | #define REG_NONE 0 |
---|
| 102 | #define REG_SZ 1 |
---|
| 103 | #define REG_EXPAND_SZ 2 |
---|
| 104 | #define REG_BINARY 3 |
---|
| 105 | #define REG_DWORD 4 |
---|
[54] | 106 | #define REG_DWORD_LE 4 /* DWORD, little endian */ |
---|
| 107 | #define REG_DWORD_BE 5 /* DWORD, big endian */ |
---|
[32] | 108 | #define REG_LINK 6 |
---|
| 109 | #define REG_MULTI_SZ 7 |
---|
| 110 | #define REG_RESOURCE_LIST 8 |
---|
| 111 | #define REG_FULL_RESOURCE_DESCRIPTOR 9 |
---|
| 112 | #define REG_RESOURCE_REQUIREMENTS_LIST 10 |
---|
[72] | 113 | #define REG_QWORD 11 /* 64-bit little endian */ |
---|
| 114 | /* XXX: Has MS defined a REG_QWORD_BE? */ |
---|
[32] | 115 | /* Not a real type in the registry */ |
---|
[136] | 116 | #define REG_KEY 0x7FFFFFFF |
---|
[32] | 117 | |
---|
[135] | 118 | #define REGFI_OFFSET_NONE 0xffffffff |
---|
[30] | 119 | |
---|
[165] | 120 | |
---|
| 121 | /* This maximum depth is described here: |
---|
| 122 | * http://msdn.microsoft.com/en-us/library/ms724872%28VS.85%29.aspx |
---|
| 123 | */ |
---|
| 124 | #define REGFI_MAX_DEPTH 512 |
---|
| 125 | |
---|
| 126 | /* This limit defines the maximum number of levels deep that ri subkey list |
---|
| 127 | * trees can go. |
---|
| 128 | */ |
---|
| 129 | /* XXX: This is totally arbitrary right now. |
---|
| 130 | * The actual limit may need to be discovered by experimentation. |
---|
| 131 | */ |
---|
[149] | 132 | #define REGFI_MAX_SUBKEY_DEPTH 255 |
---|
[139] | 133 | |
---|
[165] | 134 | |
---|
[135] | 135 | /* Header sizes and magic number lengths for various records */ |
---|
[147] | 136 | #define REGFI_HBIN_ALLOC 0x1000 /* Minimum allocation unit for HBINs */ |
---|
| 137 | #define REGFI_REGF_SIZE 0x1000 /* "regf" header block size */ |
---|
[135] | 138 | #define REGFI_REGF_MAGIC_SIZE 4 |
---|
[151] | 139 | #define REGFI_REGF_NAME_SIZE 64 |
---|
| 140 | #define REGFI_REGF_RESERVED1_SIZE 340 |
---|
| 141 | #define REGFI_REGF_RESERVED2_SIZE 3528 |
---|
[135] | 142 | #define REGFI_HBIN_MAGIC_SIZE 4 |
---|
| 143 | #define REGFI_CELL_MAGIC_SIZE 2 |
---|
| 144 | #define REGFI_HBIN_HEADER_SIZE 0x20 |
---|
[116] | 145 | #define REGFI_NK_MIN_LENGTH 0x4C |
---|
| 146 | #define REGFI_VK_MIN_LENGTH 0x14 |
---|
| 147 | #define REGFI_SK_MIN_LENGTH 0x14 |
---|
[127] | 148 | #define REGFI_SUBKEY_LIST_MIN_LEN 0x4 |
---|
[157] | 149 | #define REGFI_BIG_DATA_MIN_LENGTH 0xC |
---|
[30] | 150 | |
---|
[135] | 151 | |
---|
[116] | 152 | /* Constants used for validation */ |
---|
[125] | 153 | /* XXX: Can we add clock resolution validation as well as range? It has |
---|
| 154 | * been reported that Windows timestamps are never more than a |
---|
| 155 | * certain granularity (250ms?), which could be used to help |
---|
[147] | 156 | * eliminate false positives. Would need to verify this and |
---|
[125] | 157 | * perhaps conservatively implement a check. |
---|
| 158 | */ |
---|
[116] | 159 | /* Minimum time is Jan 1, 1990 00:00:00 */ |
---|
| 160 | #define REGFI_MTIME_MIN_HIGH 0x01B41E6D |
---|
[178] | 161 | |
---|
[116] | 162 | /* Maximum time is Jan 1, 2290 00:00:00 |
---|
| 163 | * (We hope no one is using Windows by then...) |
---|
| 164 | */ |
---|
| 165 | #define REGFI_MTIME_MAX_HIGH 0x03047543 |
---|
[30] | 166 | |
---|
[116] | 167 | |
---|
[30] | 168 | /* Flags for the vk records */ |
---|
[162] | 169 | #define REGFI_VK_FLAG_ASCIINAME 0x0001 |
---|
[135] | 170 | #define REGFI_VK_DATA_IN_OFFSET 0x80000000 |
---|
[152] | 171 | #define REGFI_VK_MAX_DATA_LENGTH 1024*1024 /* XXX: This is arbitrary */ |
---|
[30] | 172 | |
---|
[137] | 173 | |
---|
[152] | 174 | /* Known key flags */ |
---|
| 175 | /*******************/ |
---|
[137] | 176 | /* These next two show up on normal-seeming keys in Vista and W2K3 registries */ |
---|
| 177 | #define REGFI_NK_FLAG_UNKNOWN1 0x4000 |
---|
| 178 | #define REGFI_NK_FLAG_UNKNOWN2 0x1000 |
---|
[152] | 179 | |
---|
[167] | 180 | /* This next one shows up in some Vista "software" registries */ |
---|
| 181 | /* XXX: This shows up in the following two SOFTWARE keys in Vista: |
---|
| 182 | * /Wow6432Node/Microsoft |
---|
| 183 | * /Wow6432Node/Microsoft/Cryptography |
---|
| 184 | * |
---|
| 185 | * It comes along with UNKNOWN2 and ASCIINAME for a total flags value of 0x10A0 |
---|
| 186 | */ |
---|
[137] | 187 | #define REGFI_NK_FLAG_UNKNOWN3 0x0080 |
---|
[30] | 188 | |
---|
[152] | 189 | /* Predefined handle. Rumor has it that the valuelist count for this key is |
---|
| 190 | * where the handle is stored. |
---|
| 191 | * http://msdn.microsoft.com/en-us/library/ms724836(VS.85).aspx |
---|
| 192 | */ |
---|
| 193 | #define REGFI_NK_FLAG_PREDEF_KEY 0x0040 |
---|
[137] | 194 | |
---|
[152] | 195 | /* The name will be in ASCII if this next bit is set, otherwise UTF-16LE */ |
---|
| 196 | #define REGFI_NK_FLAG_ASCIINAME 0x0020 |
---|
| 197 | |
---|
| 198 | /* Symlink key. |
---|
| 199 | * See: http://www.codeproject.com/KB/system/regsymlink.aspx |
---|
| 200 | */ |
---|
| 201 | #define REGFI_NK_FLAG_LINK 0x0010 |
---|
| 202 | |
---|
| 203 | /* This key cannot be deleted */ |
---|
| 204 | #define REGFI_NK_FLAG_NO_RM 0x0008 |
---|
| 205 | |
---|
| 206 | /* Root of a hive */ |
---|
| 207 | #define REGFI_NK_FLAG_ROOT 0x0004 |
---|
| 208 | |
---|
| 209 | /* Mount point of another hive. NULL/(default) value indicates which hive |
---|
| 210 | * and where in the hive it points to. |
---|
| 211 | */ |
---|
| 212 | #define REGFI_NK_FLAG_HIVE_LINK 0x0002 |
---|
| 213 | |
---|
| 214 | /* These keys shouldn't be stored on disk, according to: |
---|
| 215 | * http://geekswithblogs.net/sdorman/archive/2007/12/24/volatile-registry-keys.aspx |
---|
| 216 | */ |
---|
| 217 | #define REGFI_NK_FLAG_VOLATILE 0x0001 |
---|
| 218 | |
---|
| 219 | /* Useful for identifying unknown flag types */ |
---|
| 220 | #define REGFI_NK_KNOWN_FLAGS (REGFI_NK_FLAG_PREDEF_KEY\ |
---|
| 221 | | REGFI_NK_FLAG_ASCIINAME\ |
---|
| 222 | | REGFI_NK_FLAG_LINK\ |
---|
| 223 | | REGFI_NK_FLAG_NO_RM\ |
---|
| 224 | | REGFI_NK_FLAG_ROOT\ |
---|
| 225 | | REGFI_NK_FLAG_HIVE_LINK\ |
---|
| 226 | | REGFI_NK_FLAG_VOLATILE\ |
---|
| 227 | | REGFI_NK_FLAG_UNKNOWN1\ |
---|
[167] | 228 | | REGFI_NK_FLAG_UNKNOWN2\ |
---|
| 229 | | REGFI_NK_FLAG_UNKNOWN3) |
---|
[152] | 230 | |
---|
[168] | 231 | |
---|
| 232 | #define CHAR_BIT 8 |
---|
| 233 | #define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \ |
---|
| 234 | : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1)) |
---|
| 235 | #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) |
---|
| 236 | #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) |
---|
| 237 | |
---|
| 238 | typedef struct _regfi_nttime |
---|
| 239 | { |
---|
| 240 | uint32_t low; |
---|
| 241 | uint32_t high; |
---|
| 242 | } REGFI_NTTIME; |
---|
| 243 | |
---|
| 244 | |
---|
[182] | 245 | typedef struct _regfi_log |
---|
| 246 | { |
---|
| 247 | /* Error/warning/info messages returned by lower layer functions */ |
---|
| 248 | char* messages; |
---|
| 249 | |
---|
| 250 | /* Mask for error message types that will be stored. */ |
---|
| 251 | uint16_t msg_mask; |
---|
| 252 | |
---|
| 253 | } REGFI_LOG; |
---|
| 254 | |
---|
| 255 | |
---|
[169] | 256 | /** HBIN block information |
---|
| 257 | * @ingroup regfiMiddleLayer |
---|
| 258 | */ |
---|
[135] | 259 | typedef struct _regfi_hbin |
---|
[97] | 260 | { |
---|
[169] | 261 | /** Offset of this HBIN in the registry file */ |
---|
| 262 | uint32_t file_off; |
---|
[97] | 263 | |
---|
[169] | 264 | /** Number of active records pointing to this block (not used currently) */ |
---|
| 265 | uint32_t ref_count; |
---|
| 266 | |
---|
| 267 | /** Offset from first hbin block */ |
---|
| 268 | uint32_t first_hbin_off; |
---|
| 269 | |
---|
| 270 | /** Block size of this block Should be a multiple of 4096 (0x1000) */ |
---|
| 271 | uint32_t block_size; |
---|
| 272 | |
---|
| 273 | /** Relative offset to next block. |
---|
| 274 | * |
---|
| 275 | * @note This value may be unreliable! |
---|
| 276 | */ |
---|
| 277 | uint32_t next_block; |
---|
| 278 | |
---|
| 279 | /** Magic number for the HBIN (should be "hbin"). */ |
---|
| 280 | uint8_t magic[REGFI_HBIN_MAGIC_SIZE]; |
---|
[135] | 281 | } REGFI_HBIN; |
---|
[30] | 282 | |
---|
[97] | 283 | |
---|
[127] | 284 | /* Subkey List -- list of key offsets and hashed names for consistency */ |
---|
[97] | 285 | typedef struct |
---|
| 286 | { |
---|
[139] | 287 | /* Virtual offset of NK record or additional subkey list, |
---|
| 288 | * depending on this list's type. |
---|
| 289 | */ |
---|
[168] | 290 | uint32_t offset; |
---|
[139] | 291 | |
---|
[168] | 292 | uint32_t hash; |
---|
[135] | 293 | } REGFI_SUBKEY_LIST_ELEM; |
---|
[30] | 294 | |
---|
[97] | 295 | |
---|
[169] | 296 | /** Subkey-list structure |
---|
| 297 | * @ingroup regfiMiddleLayer |
---|
| 298 | */ |
---|
[145] | 299 | typedef struct _regfi_subkey_list |
---|
[97] | 300 | { |
---|
[139] | 301 | /* Real offset of this record's cell in the file */ |
---|
[168] | 302 | uint32_t offset; |
---|
[139] | 303 | |
---|
[168] | 304 | uint32_t cell_size; |
---|
[139] | 305 | |
---|
| 306 | /* Number of immediate children */ |
---|
[168] | 307 | uint32_t num_children; |
---|
[139] | 308 | |
---|
| 309 | /* Total number of keys referenced by this list and it's children */ |
---|
[168] | 310 | uint32_t num_keys; |
---|
[139] | 311 | |
---|
[135] | 312 | REGFI_SUBKEY_LIST_ELEM* elements; |
---|
[168] | 313 | uint8_t magic[REGFI_CELL_MAGIC_SIZE]; |
---|
[139] | 314 | |
---|
| 315 | /* Set if the magic indicates this subkey list points to child subkey lists */ |
---|
| 316 | bool recursive_type; |
---|
[135] | 317 | } REGFI_SUBKEY_LIST; |
---|
[30] | 318 | |
---|
[97] | 319 | |
---|
[168] | 320 | typedef uint32_t REGFI_VALUE_LIST_ELEM; |
---|
[169] | 321 | /** Value-list structure |
---|
| 322 | * @ingroup regfiMiddleLayer |
---|
| 323 | */ |
---|
[145] | 324 | typedef struct _regfi_value_list |
---|
| 325 | { |
---|
| 326 | /* Actual number of values referenced by this list. |
---|
| 327 | * May differ from parent key's num_values if there were parsing errors. |
---|
| 328 | */ |
---|
[168] | 329 | uint32_t num_values; |
---|
[145] | 330 | |
---|
| 331 | REGFI_VALUE_LIST_ELEM* elements; |
---|
| 332 | } REGFI_VALUE_LIST; |
---|
| 333 | |
---|
| 334 | |
---|
[169] | 335 | /** Class name structure (used in storing SysKeys) |
---|
| 336 | * @ingroup regfiBase |
---|
| 337 | */ |
---|
[160] | 338 | typedef struct _regfi_classname |
---|
| 339 | { |
---|
[169] | 340 | /** As converted to requested REGFI_ENCODING */ |
---|
[160] | 341 | char* interpreted; |
---|
| 342 | |
---|
[169] | 343 | /** Represents raw buffer read from classname cell. |
---|
| 344 | * |
---|
| 345 | * Length of this item is specified in the size field. |
---|
| 346 | */ |
---|
[168] | 347 | uint8_t* raw; |
---|
[160] | 348 | |
---|
[169] | 349 | /** Length of the raw data. |
---|
| 350 | * |
---|
| 351 | * May be shorter than that indicated by parent key. |
---|
| 352 | */ |
---|
[168] | 353 | uint16_t size; |
---|
[160] | 354 | } REGFI_CLASSNAME; |
---|
| 355 | |
---|
| 356 | |
---|
[169] | 357 | /** Data record structure |
---|
| 358 | * @ingroup regfiBase |
---|
| 359 | */ |
---|
[159] | 360 | typedef struct _regfi_data |
---|
| 361 | { |
---|
[169] | 362 | /** Data type of this data, as indicated by the referencing VK record. */ |
---|
[168] | 363 | uint32_t type; |
---|
[159] | 364 | |
---|
[169] | 365 | /** Length of the raw data. */ |
---|
[168] | 366 | uint32_t size; |
---|
[159] | 367 | |
---|
[169] | 368 | /** This is always present, representing the raw data cell contents. */ |
---|
[168] | 369 | uint8_t* raw; |
---|
[159] | 370 | |
---|
[169] | 371 | /** Represents the length of the interpreted value. Meaning is type-specific. */ |
---|
[168] | 372 | uint32_t interpreted_size; |
---|
[159] | 373 | |
---|
[169] | 374 | /** These items represent interpreted versions of the REGFI_DATA::raw field. |
---|
| 375 | * |
---|
| 376 | * Only use the appropriate member according to the REGFI_DATA::type field. |
---|
| 377 | * In the event of an unknown type, use only the REGFI_DATA::raw field. |
---|
[159] | 378 | */ |
---|
| 379 | union _regfi_data_interpreted |
---|
| 380 | { |
---|
[169] | 381 | /** REG_NONE |
---|
| 382 | * |
---|
| 383 | * Stored as a raw buffer. Use REGFI_DATA::interpreted_size to determine |
---|
| 384 | * length. |
---|
| 385 | */ |
---|
| 386 | uint8_t* none; |
---|
| 387 | |
---|
| 388 | /** REG_SZ |
---|
| 389 | * |
---|
| 390 | * Stored as a NUL terminated string. Converted to the specified |
---|
| 391 | * REGFI_ENCODING. |
---|
| 392 | */ |
---|
[168] | 393 | uint8_t* string; |
---|
[169] | 394 | |
---|
| 395 | /** REG_EXPAND_SZ |
---|
| 396 | * |
---|
| 397 | * Stored as a NUL terminated string. Converted to the specified |
---|
| 398 | * REGFI_ENCODING. |
---|
| 399 | */ |
---|
[168] | 400 | uint8_t* expand_string; |
---|
[169] | 401 | |
---|
| 402 | /** REG_BINARY |
---|
| 403 | * |
---|
| 404 | * Stored as a raw buffer. Use REGFI_DATA::interpreted_size to determine |
---|
| 405 | * length. |
---|
| 406 | */ |
---|
| 407 | uint8_t* binary; |
---|
| 408 | |
---|
| 409 | /** REG_DWORD */ |
---|
[168] | 410 | uint32_t dword; |
---|
[169] | 411 | |
---|
| 412 | /** REG_DWORD_BE */ |
---|
[168] | 413 | uint32_t dword_be; |
---|
[169] | 414 | |
---|
| 415 | /** REG_LINK |
---|
| 416 | * |
---|
| 417 | * Stored as a NUL terminated string. Converted to the specified |
---|
| 418 | * REGFI_ENCODING. |
---|
| 419 | */ |
---|
[168] | 420 | uint8_t* link; |
---|
[169] | 421 | |
---|
| 422 | /** REG_MULTI_SZ |
---|
| 423 | * |
---|
| 424 | * Stored as a list of uint8_t* pointers, terminated with a NULL pointer. |
---|
| 425 | * Each string element in the list is NUL terminated, and the character set |
---|
| 426 | * is determined by the specified REGFI_ENCODING. |
---|
| 427 | */ |
---|
[168] | 428 | uint8_t** multiple_string; |
---|
[169] | 429 | |
---|
| 430 | /** REG_QWORD */ |
---|
[168] | 431 | uint64_t qword; |
---|
[159] | 432 | |
---|
| 433 | /* The following are treated as binary currently, but this may change in |
---|
| 434 | * the future as the formats become better understood. |
---|
| 435 | */ |
---|
[169] | 436 | |
---|
| 437 | /** REG_RESOURCE_LIST |
---|
| 438 | * |
---|
| 439 | * Stored as a raw buffer. Use REGFI_DATA::interpreted_size to determine |
---|
| 440 | * length. |
---|
| 441 | */ |
---|
[168] | 442 | uint8_t* resource_list; |
---|
[169] | 443 | |
---|
| 444 | /** REG_FULL_RESOURCE_DESCRIPTOR |
---|
| 445 | * |
---|
| 446 | * Stored as a raw buffer. Use REGFI_DATA::interpreted_size to determine |
---|
| 447 | * length. |
---|
| 448 | */ |
---|
[168] | 449 | uint8_t* full_resource_descriptor; |
---|
[169] | 450 | |
---|
| 451 | /** REG_RESOURCE_REQUIREMENTS_LIST |
---|
| 452 | * |
---|
| 453 | * Stored as a raw buffer. Use REGFI_DATA::interpreted_size to determine |
---|
| 454 | * length. |
---|
| 455 | */ |
---|
[168] | 456 | uint8_t* resource_requirements_list; |
---|
[159] | 457 | } interpreted; |
---|
| 458 | } REGFI_DATA; |
---|
| 459 | |
---|
| 460 | |
---|
[169] | 461 | /** Value structure |
---|
| 462 | * @ingroup regfiBase |
---|
| 463 | */ |
---|
| 464 | typedef struct |
---|
[97] | 465 | { |
---|
[169] | 466 | /** Real offset of this record's cell in the file */ |
---|
| 467 | uint32_t offset; |
---|
[101] | 468 | |
---|
[169] | 469 | /** ((start_offset - end_offset) & 0xfffffff8) */ |
---|
| 470 | uint32_t cell_size; |
---|
[159] | 471 | |
---|
[169] | 472 | /* XXX: deprecated */ |
---|
| 473 | REGFI_DATA* data; |
---|
| 474 | |
---|
| 475 | /** The name of this value converted to desired REGFI_ENCODING. |
---|
| 476 | * |
---|
| 477 | * This conversion typically occurs automatically through REGFI_ITERATOR |
---|
| 478 | * settings. String is NUL terminated. |
---|
| 479 | */ |
---|
| 480 | char* valuename; |
---|
| 481 | |
---|
| 482 | /** The raw value name |
---|
| 483 | * |
---|
| 484 | * Length of the buffer is stored in name_length. |
---|
| 485 | */ |
---|
[168] | 486 | uint8_t* valuename_raw; |
---|
[169] | 487 | |
---|
| 488 | /** Length of valuename_raw */ |
---|
[168] | 489 | uint16_t name_length; |
---|
[169] | 490 | |
---|
| 491 | /** Offset from beginning of this hbin block */ |
---|
| 492 | uint32_t hbin_off; |
---|
[53] | 493 | |
---|
[169] | 494 | /** Size of the value's data as reported in the VK record. |
---|
| 495 | * |
---|
| 496 | * May be different than that obtained while parsing the data cell itself. |
---|
| 497 | */ |
---|
| 498 | uint32_t data_size; |
---|
| 499 | |
---|
| 500 | /** Virtual offset of data cell */ |
---|
| 501 | uint32_t data_off; |
---|
| 502 | |
---|
| 503 | /** Value's data type */ |
---|
[168] | 504 | uint32_t type; |
---|
[169] | 505 | |
---|
| 506 | /** VK record's magic number (should be "vk") */ |
---|
[168] | 507 | uint8_t magic[REGFI_CELL_MAGIC_SIZE]; |
---|
[169] | 508 | |
---|
| 509 | /** VK record flags */ |
---|
[168] | 510 | uint16_t flags; |
---|
[169] | 511 | |
---|
| 512 | /* XXX: A 2-byte field of unknown purpose stored in the VK record */ |
---|
[168] | 513 | uint16_t unknown1; |
---|
[169] | 514 | |
---|
| 515 | /** Whether or not the data record is stored in the VK record's data_off field. |
---|
| 516 | * |
---|
| 517 | * This information is derived from the high bit of the raw data size field. |
---|
| 518 | */ |
---|
| 519 | bool data_in_offset; |
---|
[135] | 520 | } REGFI_VK_REC; |
---|
[30] | 521 | |
---|
| 522 | |
---|
| 523 | /* Key Security */ |
---|
[135] | 524 | struct _regfi_sk_rec; |
---|
[30] | 525 | |
---|
[169] | 526 | /** Security structure |
---|
| 527 | * @ingroup regfiBase |
---|
| 528 | */ |
---|
[135] | 529 | typedef struct _regfi_sk_rec |
---|
[97] | 530 | { |
---|
[169] | 531 | /** Real file offset of this record */ |
---|
| 532 | uint32_t offset; |
---|
[111] | 533 | |
---|
[169] | 534 | /** ((start_offset - end_offset) & 0xfffffff8) */ |
---|
| 535 | uint32_t cell_size; |
---|
| 536 | |
---|
| 537 | /** The stored Windows security descriptor for this SK record */ |
---|
[134] | 538 | WINSEC_DESC* sec_desc; |
---|
[169] | 539 | |
---|
| 540 | /** Offset of this record from beginning of this hbin block */ |
---|
| 541 | uint32_t hbin_off; |
---|
[53] | 542 | |
---|
[169] | 543 | /** Offset of the previous SK record in the linked list of SK records */ |
---|
[168] | 544 | uint32_t prev_sk_off; |
---|
[169] | 545 | |
---|
| 546 | /** Offset of the next SK record in the linked list of SK records */ |
---|
[168] | 547 | uint32_t next_sk_off; |
---|
[169] | 548 | |
---|
| 549 | /** Number of keys referencing this SK record */ |
---|
[168] | 550 | uint32_t ref_count; |
---|
[169] | 551 | |
---|
| 552 | /** Size of security descriptor (sec_desc) */ |
---|
| 553 | uint32_t desc_size; |
---|
| 554 | |
---|
| 555 | /* XXX: A 2-byte field of unknown purpose */ |
---|
[168] | 556 | uint16_t unknown_tag; |
---|
[169] | 557 | |
---|
| 558 | /** The magic number for this record (should be "sk") */ |
---|
[168] | 559 | uint8_t magic[REGFI_CELL_MAGIC_SIZE]; |
---|
[135] | 560 | } REGFI_SK_REC; |
---|
[30] | 561 | |
---|
[81] | 562 | |
---|
[169] | 563 | /** Key structure |
---|
| 564 | * @ingroup regfiBase |
---|
| 565 | */ |
---|
[104] | 566 | typedef struct |
---|
[97] | 567 | { |
---|
[169] | 568 | /** Real offset of this record's cell in the file */ |
---|
| 569 | uint32_t offset; |
---|
[84] | 570 | |
---|
[169] | 571 | /** Actual or estimated length of the cell. |
---|
| 572 | * Always in multiples of 8. |
---|
| 573 | */ |
---|
| 574 | uint32_t cell_size; |
---|
| 575 | |
---|
| 576 | /** Preloaded value-list for this key. |
---|
| 577 | * This element is loaded automatically when using the iterator interface and |
---|
| 578 | * possibly some lower layer interfaces. |
---|
| 579 | */ |
---|
[145] | 580 | REGFI_VALUE_LIST* values; |
---|
[169] | 581 | |
---|
| 582 | |
---|
| 583 | /** Preloaded subkey-list for this key. |
---|
| 584 | * This element is loaded automatically when using the iterator interface and |
---|
| 585 | * possibly some lower layer interfaces. |
---|
| 586 | */ |
---|
[135] | 587 | REGFI_SUBKEY_LIST* subkeys; |
---|
[53] | 588 | |
---|
[169] | 589 | /** Key flags */ |
---|
[168] | 590 | uint16_t flags; |
---|
[169] | 591 | |
---|
| 592 | /** Magic number of key (should be "nk") */ |
---|
[168] | 593 | uint8_t magic[REGFI_CELL_MAGIC_SIZE]; |
---|
[169] | 594 | |
---|
| 595 | /** Key's last modification time */ |
---|
[168] | 596 | REGFI_NTTIME mtime; |
---|
[169] | 597 | |
---|
| 598 | /** Length of keyname_raw */ |
---|
[168] | 599 | uint16_t name_length; |
---|
[169] | 600 | |
---|
| 601 | /** Length of referenced classname */ |
---|
[168] | 602 | uint16_t classname_length; |
---|
[169] | 603 | |
---|
| 604 | /** The name of this key converted to desired REGFI_ENCODING. |
---|
| 605 | * |
---|
| 606 | * This conversion typically occurs automatically through REGFI_ITERATOR |
---|
| 607 | * settings. String is NUL terminated. |
---|
| 608 | */ |
---|
[84] | 609 | char* keyname; |
---|
[169] | 610 | |
---|
| 611 | /** The raw key name |
---|
| 612 | * |
---|
| 613 | * Length of the buffer is stored in name_length. |
---|
| 614 | */ |
---|
[168] | 615 | uint8_t* keyname_raw; |
---|
[169] | 616 | |
---|
| 617 | /** Virutal offset of parent key */ |
---|
| 618 | uint32_t parent_off; |
---|
| 619 | |
---|
| 620 | /** Virutal offset of classname key */ |
---|
[168] | 621 | uint32_t classname_off; |
---|
[53] | 622 | |
---|
[169] | 623 | /* XXX: max subkey name * 2 */ |
---|
| 624 | uint32_t max_bytes_subkeyname; |
---|
| 625 | |
---|
| 626 | /* XXX: max subkey classname length (as if) */ |
---|
| 627 | uint32_t max_bytes_subkeyclassname; |
---|
| 628 | |
---|
| 629 | /* XXX: max valuename * 2 */ |
---|
| 630 | uint32_t max_bytes_valuename; |
---|
| 631 | |
---|
| 632 | /* XXX: max value data size */ |
---|
| 633 | uint32_t max_bytes_value; |
---|
[53] | 634 | |
---|
[169] | 635 | /* XXX: Fields of unknown purpose */ |
---|
[168] | 636 | uint32_t unknown1; |
---|
| 637 | uint32_t unknown2; |
---|
| 638 | uint32_t unknown3; |
---|
| 639 | uint32_t unk_index; /* nigel says run time index ? */ |
---|
[53] | 640 | |
---|
[169] | 641 | /** Number of subkeys */ |
---|
[168] | 642 | uint32_t num_subkeys; |
---|
[169] | 643 | |
---|
| 644 | /** Virtual offset of subkey-list */ |
---|
| 645 | uint32_t subkeys_off; |
---|
| 646 | |
---|
| 647 | /** Number of values for this key */ |
---|
[168] | 648 | uint32_t num_values; |
---|
[169] | 649 | |
---|
| 650 | /** Virtual offset of value-list */ |
---|
| 651 | uint32_t values_off; |
---|
| 652 | |
---|
| 653 | /** Virtual offset of SK record */ |
---|
| 654 | uint32_t sk_off; |
---|
[135] | 655 | } REGFI_NK_REC; |
---|
[30] | 656 | |
---|
[81] | 657 | |
---|
[178] | 658 | typedef struct _regfi_raw_file |
---|
| 659 | { |
---|
| 660 | off_t (* seek)(); /* (REGFI_RAW_FILE* self, off_t offset, int whence) */ |
---|
| 661 | ssize_t (* read)(); /* (REGFI_RAW_FILE* self, void* buf, size_t count) */ |
---|
[97] | 662 | |
---|
[178] | 663 | uint64_t cur_off; |
---|
| 664 | uint64_t size; |
---|
| 665 | void* state; |
---|
| 666 | } REGFI_RAW_FILE; |
---|
| 667 | |
---|
| 668 | |
---|
[169] | 669 | /** Registry hive file data structure |
---|
| 670 | * |
---|
| 671 | * This essential structure stores run-time information about a single open |
---|
| 672 | * registry hive as well as file header (REGF block) data. This structure |
---|
| 673 | * also stores a list of warnings and error messages generated while parsing |
---|
| 674 | * the registry hive. These can be tuned using @ref regfi_set_message_mask. |
---|
| 675 | * Messages may be retrieved using @ref regfi_get_messages. |
---|
| 676 | * |
---|
| 677 | * @note If the message mask is set to record any messages, dependent code |
---|
| 678 | * must use @ref regfi_get_messages periodically to clear the message |
---|
| 679 | * queue. Otherwise, this structure will grow in size over time as |
---|
| 680 | * messages queue up. |
---|
| 681 | * |
---|
| 682 | * @ingroup regfiBase |
---|
| 683 | */ |
---|
[178] | 684 | typedef struct _regfi_file |
---|
[97] | 685 | { |
---|
[135] | 686 | /* Run-time information */ |
---|
| 687 | /************************/ |
---|
[178] | 688 | /* Functions for accessing the file */ |
---|
| 689 | REGFI_RAW_FILE* cb; |
---|
[99] | 690 | |
---|
[180] | 691 | /* Mutex for all cb access. This is done to prevent one thread from moving |
---|
| 692 | * the file offset while another thread is in the middle of a multi-read |
---|
| 693 | * parsing transaction */ |
---|
| 694 | pthread_mutex_t* cb_lock; |
---|
| 695 | |
---|
[138] | 696 | /* For sanity checking (not part of the registry header) */ |
---|
[168] | 697 | uint32_t file_length; |
---|
[138] | 698 | |
---|
| 699 | /* Metadata about hbins */ |
---|
[99] | 700 | range_list* hbins; |
---|
| 701 | |
---|
[180] | 702 | /* Multiple read access allowed, write access is exclusive */ |
---|
| 703 | pthread_rwlock_t* hbins_lock; |
---|
| 704 | |
---|
[146] | 705 | /* SK record cached since they're repeatedly reused */ |
---|
| 706 | lru_cache* sk_cache; |
---|
| 707 | |
---|
[180] | 708 | /* Need exclusive access for LRUs, since lookups make changes */ |
---|
| 709 | pthread_mutex_t* sk_lock; |
---|
| 710 | |
---|
[135] | 711 | /* Data parsed from file header */ |
---|
| 712 | /********************************/ |
---|
[168] | 713 | uint8_t magic[REGFI_REGF_MAGIC_SIZE];/* "regf" */ |
---|
[151] | 714 | |
---|
| 715 | /* These sequence numbers should match if |
---|
| 716 | * the hive was properly synced to disk. |
---|
| 717 | */ |
---|
[168] | 718 | uint32_t sequence1; |
---|
| 719 | uint32_t sequence2; |
---|
[151] | 720 | |
---|
[168] | 721 | REGFI_NTTIME mtime; |
---|
| 722 | uint32_t major_version; /* Set to 1 in all known hives */ |
---|
| 723 | uint32_t minor_version; /* Set to 3 or 5 in all known hives */ |
---|
| 724 | uint32_t type; /* XXX: Unverified. Set to 0 in all known hives */ |
---|
| 725 | uint32_t format; /* XXX: Unverified. Set to 1 in all known hives */ |
---|
[97] | 726 | |
---|
[168] | 727 | uint32_t root_cell; /* Offset to root cell in the first (or any?) hbin block */ |
---|
| 728 | uint32_t last_block; /* Offset to last hbin block in file */ |
---|
[151] | 729 | |
---|
[168] | 730 | uint32_t cluster; /* XXX: Unverified. Set to 1 in all known hives */ |
---|
[151] | 731 | |
---|
| 732 | /* Matches hive's base file name. Stored in UTF-16LE */ |
---|
[168] | 733 | uint8_t file_name[REGFI_REGF_NAME_SIZE]; |
---|
[151] | 734 | |
---|
| 735 | WINSEC_UUID* rm_id; /* XXX: Unverified. */ |
---|
| 736 | WINSEC_UUID* log_id; /* XXX: Unverified. */ |
---|
| 737 | WINSEC_UUID* tm_id; /* XXX: Unverified. */ |
---|
[168] | 738 | uint32_t flags; /* XXX: Unverified. */ |
---|
| 739 | uint32_t guid_signature; /* XXX: Unverified. */ |
---|
[151] | 740 | |
---|
[168] | 741 | uint32_t checksum; /* Stored checksum from file */ |
---|
| 742 | uint32_t computed_checksum; /* Our own calculation of the checksum. |
---|
[151] | 743 | * (XOR of bytes 0x0000 - 0x01FB) */ |
---|
| 744 | |
---|
| 745 | WINSEC_UUID* thaw_tm_id; /* XXX: Unverified. */ |
---|
| 746 | WINSEC_UUID* thaw_rm_id; /* XXX: Unverified. */ |
---|
| 747 | WINSEC_UUID* thaw_log_id; /* XXX: Unverified. */ |
---|
[168] | 748 | uint32_t boot_type; /* XXX: Unverified. */ |
---|
| 749 | uint32_t boot_recover; /* XXX: Unverified. */ |
---|
[151] | 750 | |
---|
| 751 | /* This seems to include random junk. Possibly unsanitized memory left over |
---|
| 752 | * from when header block was written. For instance, chunks of nk records |
---|
| 753 | * can be found, though often it's all 0s. */ |
---|
[168] | 754 | uint8_t reserved1[REGFI_REGF_RESERVED1_SIZE]; |
---|
[151] | 755 | |
---|
| 756 | /* This is likely reserved and unusued currently. (Should be all 0s.) |
---|
| 757 | * Included here for easier access in looking for hidden data |
---|
| 758 | * or doing research. */ |
---|
[168] | 759 | uint8_t reserved2[REGFI_REGF_RESERVED2_SIZE]; |
---|
[151] | 760 | |
---|
[135] | 761 | } REGFI_FILE; |
---|
[30] | 762 | |
---|
| 763 | |
---|
[169] | 764 | /** Registry hive iterator |
---|
| 765 | * @ingroup regfiIteratorLayer |
---|
| 766 | */ |
---|
[151] | 767 | typedef struct _regfi_iterator |
---|
[97] | 768 | { |
---|
[169] | 769 | /** The registry hive this iterator is associated with */ |
---|
[135] | 770 | REGFI_FILE* f; |
---|
[169] | 771 | |
---|
| 772 | /** All current parent keys and associated iterator positions */ |
---|
[80] | 773 | void_stack* key_positions; |
---|
[169] | 774 | |
---|
| 775 | /** The current key */ |
---|
[135] | 776 | REGFI_NK_REC* cur_key; |
---|
[169] | 777 | |
---|
| 778 | /** The encoding that all strings are converted to as set during iterator |
---|
| 779 | * creation. |
---|
| 780 | */ |
---|
[161] | 781 | REGFI_ENCODING string_encoding; |
---|
[169] | 782 | |
---|
| 783 | /** Index of the current subkey */ |
---|
[168] | 784 | uint32_t cur_subkey; |
---|
[169] | 785 | |
---|
| 786 | /** Index of the current value */ |
---|
[168] | 787 | uint32_t cur_value; |
---|
[78] | 788 | } REGFI_ITERATOR; |
---|
| 789 | |
---|
[80] | 790 | |
---|
[151] | 791 | typedef struct _regfi_iter_position |
---|
[97] | 792 | { |
---|
[135] | 793 | REGFI_NK_REC* nk; |
---|
[168] | 794 | uint32_t cur_subkey; |
---|
[80] | 795 | /* We could store a cur_value here as well, but didn't see |
---|
| 796 | * the use in it right now. |
---|
| 797 | */ |
---|
| 798 | } REGFI_ITER_POSITION; |
---|
| 799 | |
---|
| 800 | |
---|
[169] | 801 | /** General purpose buffer with stored length |
---|
| 802 | * @ingroup regfiBottomLayer |
---|
| 803 | */ |
---|
[151] | 804 | typedef struct _regfi_buffer |
---|
| 805 | { |
---|
[168] | 806 | uint8_t* buf; |
---|
[151] | 807 | uint32_t len; |
---|
| 808 | } REGFI_BUFFER; |
---|
| 809 | |
---|
| 810 | |
---|
[169] | 811 | |
---|
[54] | 812 | /******************************************************************************/ |
---|
[168] | 813 | /** |
---|
[169] | 814 | * @defgroup regfiBase Base Layer: Essential Functions and Data Structures |
---|
[168] | 815 | * |
---|
[169] | 816 | * These functions are either necessary for normal use of the regfi API or just |
---|
| 817 | * don't fit particularly well in any of the other layers. |
---|
[168] | 818 | */ |
---|
[135] | 819 | /******************************************************************************/ |
---|
[166] | 820 | |
---|
[168] | 821 | /** Parses file headers of an already open registry hive file and |
---|
| 822 | * allocates related structures for further parsing. |
---|
[166] | 823 | * |
---|
[168] | 824 | * @param fd A file descriptor of an already open file. Must be seekable. |
---|
[166] | 825 | * |
---|
[168] | 826 | * @return A reference to a newly allocated REGFI_FILE structure, if successful; |
---|
| 827 | * NULL on error. |
---|
| 828 | * |
---|
| 829 | * @ingroup regfiBase |
---|
[166] | 830 | */ |
---|
| 831 | REGFI_FILE* regfi_alloc(int fd); |
---|
| 832 | |
---|
| 833 | |
---|
[178] | 834 | /** Parses file headers returned by supplied callback functions. |
---|
[166] | 835 | * |
---|
[178] | 836 | * This interface is useful if you have a registry hive in memory |
---|
| 837 | * or have some other reason to emulate a real file. |
---|
[166] | 838 | * |
---|
[178] | 839 | * @param file_cb A structure defining the callback functions needed to access the file. |
---|
[168] | 840 | * |
---|
[178] | 841 | * @return A reference to a newly allocated REGFI_FILE structure, if successful; |
---|
| 842 | * NULL on error. |
---|
| 843 | * |
---|
[168] | 844 | * @ingroup regfiBase |
---|
[166] | 845 | */ |
---|
[178] | 846 | REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb); |
---|
[166] | 847 | |
---|
| 848 | |
---|
[168] | 849 | /** Frees a hive's data structures without closing the underlying file. |
---|
[166] | 850 | * |
---|
[168] | 851 | * @param file The registry structure to free. |
---|
| 852 | * |
---|
| 853 | * @ingroup regfiBase |
---|
[166] | 854 | */ |
---|
| 855 | void regfi_free(REGFI_FILE* file); |
---|
| 856 | |
---|
| 857 | |
---|
[182] | 858 | /** Enables regfi library logging for the current thread. |
---|
| 859 | * |
---|
| 860 | * XXX: finish documenting |
---|
| 861 | * |
---|
| 862 | * @ingroup regfiBase |
---|
| 863 | */ |
---|
| 864 | void regfi_log_start(uint16_t mask); |
---|
| 865 | |
---|
| 866 | |
---|
[168] | 867 | /** Get errors, warnings, and/or verbose information relating to processing of |
---|
| 868 | * the given registry file. |
---|
[135] | 869 | * |
---|
[168] | 870 | * @return A newly allocated char* which must be free()d by the caller. |
---|
| 871 | * |
---|
| 872 | * @ingroup regfiBase |
---|
[135] | 873 | */ |
---|
[182] | 874 | char* regfi_log_get_str(); |
---|
[159] | 875 | |
---|
[166] | 876 | |
---|
[168] | 877 | /** Set the verbosity level of errors and warnings generated by the library |
---|
| 878 | * (as accessible via regfi_get_messages). |
---|
[166] | 879 | * |
---|
[168] | 880 | * This may be called at any time and will take effect immediately. |
---|
| 881 | * |
---|
| 882 | * @param mask an integer representing the types of messages desired. |
---|
[166] | 883 | * Acceptable values are created through bitwise ORs of |
---|
| 884 | * REGFI_MSG_* values. For instance, if only errors and |
---|
| 885 | * informational messages were desired (but not warnings), |
---|
| 886 | * then one would specify: REGFI_MSG_ERROR|REGFI_MSG_INFO |
---|
| 887 | * New REGFI_FILE structures are created with: |
---|
| 888 | * REGFI_MSG_ERROR|REGFI_MSG_WARN |
---|
| 889 | * Note that error and warning messages will continue to |
---|
| 890 | * accumulate in memory if they are not fetched using |
---|
| 891 | * regfi_get_messages and then freed by the caller. |
---|
| 892 | * To disable error messages entirely, supply 0, which |
---|
| 893 | * will prevent message accumulation. |
---|
| 894 | * |
---|
[168] | 895 | * @ingroup regfiBase |
---|
[166] | 896 | */ |
---|
[182] | 897 | void regfi_log_set_mask(uint16_t mask); |
---|
[53] | 898 | |
---|
[159] | 899 | |
---|
[182] | 900 | /** Disables regfi library logging for the current thread. |
---|
| 901 | * |
---|
| 902 | * XXX: finish documenting |
---|
| 903 | * |
---|
| 904 | * @ingroup regfiBase |
---|
| 905 | */ |
---|
| 906 | void regfi_log_stop(); |
---|
| 907 | |
---|
| 908 | |
---|
[168] | 909 | /* Dispose of previously parsed records */ |
---|
| 910 | |
---|
| 911 | /** Frees a key structure previously returned by one of the API functions |
---|
[159] | 912 | * |
---|
[168] | 913 | * XXX: finish documenting |
---|
[159] | 914 | * |
---|
[168] | 915 | * @ingroup regfiBase |
---|
[159] | 916 | */ |
---|
[168] | 917 | void regfi_free_key(REGFI_NK_REC* nk); |
---|
| 918 | |
---|
| 919 | |
---|
| 920 | /** Frees a value structure previously returned by one of the API functions |
---|
| 921 | * |
---|
| 922 | * XXX: finish documenting |
---|
| 923 | * |
---|
| 924 | * @ingroup regfiBase |
---|
| 925 | */ |
---|
| 926 | void regfi_free_value(REGFI_VK_REC* vk); |
---|
| 927 | |
---|
| 928 | |
---|
| 929 | |
---|
| 930 | /******************************************************************************/ |
---|
| 931 | /** |
---|
[169] | 932 | * @defgroup regfiIteratorLayer Iterator Layer: Primary regfi Library Interface |
---|
[168] | 933 | * |
---|
| 934 | * This top layer of API functions provides an iterator interface which makes |
---|
| 935 | * traversing registry data structures easy in both single-threaded and |
---|
| 936 | * multi-threaded scenarios. |
---|
| 937 | */ |
---|
| 938 | /******************************************************************************/ |
---|
| 939 | |
---|
| 940 | /** Creates a new iterator for the provided registry file. |
---|
| 941 | * |
---|
| 942 | * @param file The opened registry file the iterator should be created for. |
---|
| 943 | * |
---|
| 944 | * @param output_encoding Character encoding that strings should be returned in. |
---|
| 945 | * Only supply the REGFI_ENCODING_* constants, as others |
---|
| 946 | * will be rejected. |
---|
| 947 | * The following values are currently accepted: |
---|
| 948 | * REGFI_ENCODING_DEFAULT (currently REGFI_ENCODING_ASCII) |
---|
| 949 | * REGFI_ENCODING_ASCII |
---|
| 950 | * REGFI_ENCODING_UTF8 |
---|
| 951 | * |
---|
| 952 | * @return A newly allocated REGFI_ITERATOR. |
---|
| 953 | * Must be free()d with regfi_iterator_free. |
---|
| 954 | * |
---|
[169] | 955 | * @ingroup regfiIteratorLayer |
---|
[168] | 956 | */ |
---|
[159] | 957 | REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file, |
---|
[161] | 958 | REGFI_ENCODING output_encoding); |
---|
[166] | 959 | |
---|
| 960 | |
---|
[168] | 961 | /** Frees a registry file iterator previously created by regfi_iterator_new. |
---|
[166] | 962 | * |
---|
| 963 | * This does not affect the underlying registry file's allocation status. |
---|
| 964 | * |
---|
[168] | 965 | * @param i the iterator to be freed |
---|
| 966 | * |
---|
[169] | 967 | * @ingroup regfiIteratorLayer |
---|
[166] | 968 | */ |
---|
[84] | 969 | void regfi_iterator_free(REGFI_ITERATOR* i); |
---|
[166] | 970 | |
---|
| 971 | |
---|
[168] | 972 | /** Traverse deeper into the registry tree at the current subkey. |
---|
[166] | 973 | * |
---|
[168] | 974 | * @param i the iterator |
---|
[166] | 975 | * |
---|
[168] | 976 | * @return true on success, false on failure. |
---|
| 977 | * Note that subkey and value indexes are preserved. That is, if a |
---|
| 978 | * regfi_iterator_up call occurs later (reversing the effect of this |
---|
| 979 | * call) then the subkey and value referenced prior to the |
---|
| 980 | * regfi_iterator_down call will still be referenced. This makes |
---|
| 981 | * depth-first iteration particularly easy. |
---|
| 982 | * |
---|
[169] | 983 | * @ingroup regfiIteratorLayer |
---|
[166] | 984 | */ |
---|
[84] | 985 | bool regfi_iterator_down(REGFI_ITERATOR* i); |
---|
[166] | 986 | |
---|
| 987 | |
---|
[168] | 988 | /** Traverse up to the current key's parent key. |
---|
[166] | 989 | * |
---|
[168] | 990 | * @param i the iterator |
---|
[166] | 991 | * |
---|
[168] | 992 | * @return true on success, false on failure. Any subkey or value state |
---|
| 993 | * associated with the current key is lost. |
---|
| 994 | * |
---|
[169] | 995 | * @ingroup regfiIteratorLayer |
---|
[166] | 996 | */ |
---|
[84] | 997 | bool regfi_iterator_up(REGFI_ITERATOR* i); |
---|
[166] | 998 | |
---|
| 999 | |
---|
[168] | 1000 | /** Traverse up to the root key of the hive. |
---|
[166] | 1001 | * |
---|
[168] | 1002 | * @param i the iterator |
---|
[166] | 1003 | * |
---|
[168] | 1004 | * @return true on success, false on failure. |
---|
| 1005 | * |
---|
[169] | 1006 | * @ingroup regfiIteratorLayer |
---|
[166] | 1007 | */ |
---|
[84] | 1008 | bool regfi_iterator_to_root(REGFI_ITERATOR* i); |
---|
[30] | 1009 | |
---|
[166] | 1010 | |
---|
[168] | 1011 | /** Traverse down multiple levels in the registry hive. |
---|
[166] | 1012 | * |
---|
| 1013 | * XXX: This currently only accepts ASCII key names. Need to look into |
---|
| 1014 | * accepting other encodings. |
---|
| 1015 | * |
---|
[168] | 1016 | * @param i the iterator |
---|
| 1017 | * @param path a list of key names representing the path. This list must |
---|
| 1018 | * contain NUL terminated strings. The list itself is |
---|
| 1019 | * terminated with a NULL pointer. All path elements must be |
---|
| 1020 | * keys; value names are not accepted (even as the last |
---|
| 1021 | * element). |
---|
| 1022 | * |
---|
| 1023 | * @return true on success, false on failure. If any element of path is not |
---|
| 1024 | * found, false will be returned and the iterator will remain |
---|
| 1025 | * in its original position. |
---|
| 1026 | * |
---|
[169] | 1027 | * @ingroup regfiIteratorLayer |
---|
[166] | 1028 | */ |
---|
[168] | 1029 | bool regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path); |
---|
[166] | 1030 | |
---|
| 1031 | |
---|
[168] | 1032 | /** Returns the currently referenced key. |
---|
[166] | 1033 | * |
---|
[168] | 1034 | * @param i the iterator |
---|
[166] | 1035 | * |
---|
[168] | 1036 | * @return A read-only key structure for the current key, or NULL on failure. |
---|
| 1037 | * |
---|
[169] | 1038 | * @ingroup regfiIteratorLayer |
---|
[166] | 1039 | */ |
---|
[135] | 1040 | const REGFI_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i); |
---|
[166] | 1041 | |
---|
| 1042 | |
---|
[168] | 1043 | /** Returns the SK (security) record referenced by the current key. |
---|
[166] | 1044 | * |
---|
[168] | 1045 | * @param i the iterator |
---|
[166] | 1046 | * |
---|
[168] | 1047 | * @return A read-only SK structure, or NULL on failure. |
---|
| 1048 | * |
---|
[169] | 1049 | * @ingroup regfiIteratorLayer |
---|
[166] | 1050 | */ |
---|
[135] | 1051 | const REGFI_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i); |
---|
[80] | 1052 | |
---|
[166] | 1053 | |
---|
[168] | 1054 | /** Sets the internal subkey index to the first subkey referenced by the current |
---|
| 1055 | * key and returns that key. |
---|
[166] | 1056 | * |
---|
[168] | 1057 | * @param i the iterator |
---|
[166] | 1058 | * |
---|
[168] | 1059 | * @return A newly allocated key structure for the newly referenced first |
---|
| 1060 | * subkey, or NULL on failure. Failure may be due to a lack of any |
---|
| 1061 | * subkeys or other errors. Newly allocated keys must be freed with |
---|
| 1062 | * regfi_free_key. |
---|
| 1063 | * |
---|
[169] | 1064 | * @ingroup regfiIteratorLayer |
---|
[166] | 1065 | */ |
---|
[150] | 1066 | REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i); |
---|
[166] | 1067 | |
---|
| 1068 | |
---|
[168] | 1069 | /** Returns the currently indexed subkey. |
---|
[166] | 1070 | * |
---|
[168] | 1071 | * @param i the iterator |
---|
[166] | 1072 | * |
---|
[168] | 1073 | * @return A newly allocated key structure for the currently referenced subkey, |
---|
| 1074 | * or NULL on failure. Newly allocated keys must be freed with |
---|
| 1075 | * regfi_free_key. |
---|
| 1076 | * |
---|
[169] | 1077 | * @ingroup regfiIteratorLayer |
---|
[166] | 1078 | */ |
---|
[150] | 1079 | REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i); |
---|
[167] | 1080 | |
---|
| 1081 | |
---|
[168] | 1082 | /** Increments the internal subkey index to the next key in the subkey-list and |
---|
| 1083 | * returns the subkey for that index. |
---|
[167] | 1084 | * |
---|
[168] | 1085 | * @param i the iterator |
---|
[167] | 1086 | * |
---|
[168] | 1087 | * @return A newly allocated key structure for the next subkey or NULL on |
---|
| 1088 | * failure. Newly allocated keys must be freed with regfi_free_key. |
---|
| 1089 | * |
---|
[169] | 1090 | * @ingroup regfiIteratorLayer |
---|
[167] | 1091 | */ |
---|
[150] | 1092 | REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i); |
---|
[167] | 1093 | |
---|
| 1094 | |
---|
[168] | 1095 | /** Searches for a subkey with a given name under the current key. |
---|
[167] | 1096 | * |
---|
[168] | 1097 | * @param i the iterator |
---|
| 1098 | * @param subkey_name subkey name to search for |
---|
[167] | 1099 | * |
---|
[168] | 1100 | * @return True if such a subkey was found, false otherwise. If a subkey is |
---|
| 1101 | * found, the current subkey index is set to that subkey. Otherwise, |
---|
| 1102 | * the subkey index remains at the same location as before the call. |
---|
| 1103 | * |
---|
[169] | 1104 | * @ingroup regfiIteratorLayer |
---|
[167] | 1105 | */ |
---|
[157] | 1106 | bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, |
---|
| 1107 | const char* subkey_name); |
---|
[150] | 1108 | |
---|
[168] | 1109 | /** Sets the internal value index to the first value referenced by the current |
---|
| 1110 | * key and returns that value. |
---|
[167] | 1111 | * |
---|
[168] | 1112 | * @param i the iterator |
---|
[167] | 1113 | * |
---|
[168] | 1114 | * @return A newly allocated value structure for the newly referenced first |
---|
| 1115 | * value, or NULL on failure. Failure may be due to a lack of any |
---|
| 1116 | * values or other errors. Newly allocated keys must be freed with |
---|
| 1117 | * regfi_free_value. |
---|
| 1118 | * |
---|
[169] | 1119 | * @ingroup regfiIteratorLayer |
---|
[167] | 1120 | */ |
---|
[150] | 1121 | REGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i); |
---|
[167] | 1122 | |
---|
| 1123 | |
---|
[168] | 1124 | /** Returns the currently indexed value. |
---|
[167] | 1125 | * |
---|
[168] | 1126 | * @param i the iterator |
---|
[167] | 1127 | * |
---|
[168] | 1128 | * @return A newly allocated value structure for the currently referenced value, |
---|
| 1129 | * or NULL on failure. Newly allocated values must be freed with |
---|
| 1130 | * regfi_free_value. |
---|
| 1131 | * |
---|
[169] | 1132 | * @ingroup regfiIteratorLayer |
---|
[167] | 1133 | */ |
---|
[150] | 1134 | REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i); |
---|
[167] | 1135 | |
---|
| 1136 | |
---|
[168] | 1137 | /** Increments the internal value index to the next value in the value-list and |
---|
| 1138 | * returns the value for that index. |
---|
[167] | 1139 | * |
---|
[168] | 1140 | * @param i the iterator |
---|
[167] | 1141 | * |
---|
[168] | 1142 | * @return A newly allocated key structure for the next value or NULL on |
---|
| 1143 | * failure. Newly allocated keys must be freed with regfi_free_value. |
---|
| 1144 | * |
---|
[169] | 1145 | * @ingroup regfiIteratorLayer |
---|
[167] | 1146 | */ |
---|
[150] | 1147 | REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i); |
---|
[167] | 1148 | |
---|
| 1149 | |
---|
[168] | 1150 | /** Searches for a value with a given name under the current key. |
---|
[167] | 1151 | * |
---|
[168] | 1152 | * @param i the iterator |
---|
| 1153 | * @param value_name value name to search for |
---|
[167] | 1154 | * |
---|
[168] | 1155 | * @return True if such a value was found, false otherwise. If a value is |
---|
| 1156 | * found, the current value index is set to that value. Otherwise, |
---|
| 1157 | * the value index remains at the same location as before the call. |
---|
| 1158 | * |
---|
[169] | 1159 | * @ingroup regfiIteratorLayer |
---|
[167] | 1160 | */ |
---|
[157] | 1161 | bool regfi_iterator_find_value(REGFI_ITERATOR* i, |
---|
| 1162 | const char* value_name); |
---|
[80] | 1163 | |
---|
[168] | 1164 | /** Retrieves classname for a given key. |
---|
[167] | 1165 | * |
---|
[168] | 1166 | * @param i the iterator |
---|
| 1167 | * @param key the key whose classname is desired |
---|
[167] | 1168 | * |
---|
[168] | 1169 | * @return Returns a newly allocated classname structure, or NULL on failure. |
---|
| 1170 | * Classname structures must be freed with regfi_free_classname. |
---|
| 1171 | * |
---|
[169] | 1172 | * @ingroup regfiIteratorLayer |
---|
[167] | 1173 | */ |
---|
[160] | 1174 | REGFI_CLASSNAME* regfi_iterator_fetch_classname(REGFI_ITERATOR* i, |
---|
| 1175 | const REGFI_NK_REC* key); |
---|
[167] | 1176 | |
---|
| 1177 | |
---|
[168] | 1178 | /** Retrieves data for a given value. |
---|
[167] | 1179 | * |
---|
[168] | 1180 | * @param i the iterator |
---|
| 1181 | * @param value the value whose data is desired |
---|
[167] | 1182 | * |
---|
[168] | 1183 | * @return Returns a newly allocated data structure, or NULL on failure. |
---|
| 1184 | * Data structures must be freed with regfi_free_data. |
---|
| 1185 | * |
---|
[169] | 1186 | * @ingroup regfiIteratorLayer |
---|
[167] | 1187 | */ |
---|
[159] | 1188 | REGFI_DATA* regfi_iterator_fetch_data(REGFI_ITERATOR* i, |
---|
| 1189 | const REGFI_VK_REC* value); |
---|
[127] | 1190 | |
---|
[157] | 1191 | |
---|
[168] | 1192 | |
---|
| 1193 | /******************************************************************************/ |
---|
| 1194 | /** |
---|
[169] | 1195 | * @defgroup regfiGlueLayer Glue Layer: Logical Data Structure Loading |
---|
[168] | 1196 | */ |
---|
| 1197 | /******************************************************************************/ |
---|
| 1198 | |
---|
| 1199 | /** Loads a key at a given file offset along with associated data structures. |
---|
| 1200 | * |
---|
| 1201 | * XXX: finish documenting |
---|
| 1202 | * |
---|
[169] | 1203 | * @ingroup regfiGlueLayer |
---|
[168] | 1204 | */ |
---|
| 1205 | REGFI_NK_REC* regfi_load_key(REGFI_FILE* file, uint32_t offset, |
---|
[161] | 1206 | REGFI_ENCODING output_encoding, |
---|
[135] | 1207 | bool strict); |
---|
[168] | 1208 | |
---|
| 1209 | |
---|
| 1210 | /** Loads a value at a given file offset alng with associated data structures. |
---|
| 1211 | * |
---|
| 1212 | * XXX: finish documenting |
---|
| 1213 | * |
---|
[169] | 1214 | * @ingroup regfiGlueLayer |
---|
[168] | 1215 | */ |
---|
| 1216 | REGFI_VK_REC* regfi_load_value(REGFI_FILE* file, uint32_t offset, |
---|
[162] | 1217 | REGFI_ENCODING output_encoding, |
---|
[145] | 1218 | bool strict); |
---|
[168] | 1219 | |
---|
| 1220 | |
---|
| 1221 | /** Loads a logical subkey list in its entirety which may span multiple records. |
---|
| 1222 | * |
---|
| 1223 | * XXX: finish documenting |
---|
| 1224 | * |
---|
[169] | 1225 | * @ingroup regfiGlueLayer |
---|
[168] | 1226 | */ |
---|
| 1227 | REGFI_SUBKEY_LIST* regfi_load_subkeylist(REGFI_FILE* file, uint32_t offset, |
---|
| 1228 | uint32_t num_keys, uint32_t max_size, |
---|
[146] | 1229 | bool strict); |
---|
[168] | 1230 | |
---|
| 1231 | |
---|
| 1232 | /** Loads a valuelist. |
---|
| 1233 | * |
---|
| 1234 | * XXX: finish documenting |
---|
| 1235 | * |
---|
[169] | 1236 | * @ingroup regfiGlueLayer |
---|
[168] | 1237 | */ |
---|
| 1238 | REGFI_VALUE_LIST* regfi_load_valuelist(REGFI_FILE* file, uint32_t offset, |
---|
| 1239 | uint32_t num_values, uint32_t max_size, |
---|
[135] | 1240 | bool strict); |
---|
[127] | 1241 | |
---|
[168] | 1242 | |
---|
| 1243 | /** Loads a data record which may be contained in the virtual offset, in a |
---|
| 1244 | * single cell, or in multiple cells through big data records. |
---|
| 1245 | * |
---|
| 1246 | * XXX: finish documenting |
---|
| 1247 | * |
---|
[169] | 1248 | * @ingroup regfiGlueLayer |
---|
[168] | 1249 | */ |
---|
| 1250 | REGFI_BUFFER regfi_load_data(REGFI_FILE* file, uint32_t voffset, |
---|
| 1251 | uint32_t length, bool data_in_offset, |
---|
[157] | 1252 | bool strict); |
---|
| 1253 | |
---|
[168] | 1254 | |
---|
| 1255 | /** Loads the data associated with a big data record at the specified offset. |
---|
| 1256 | * |
---|
| 1257 | * XXX: finish documenting |
---|
| 1258 | * |
---|
[169] | 1259 | * @ingroup regfiGlueLayer |
---|
[168] | 1260 | */ |
---|
| 1261 | REGFI_BUFFER regfi_load_big_data(REGFI_FILE* file, uint32_t offset, |
---|
| 1262 | uint32_t data_length,uint32_t cell_length, |
---|
[157] | 1263 | range_list* used_ranges, |
---|
| 1264 | bool strict); |
---|
[168] | 1265 | |
---|
| 1266 | |
---|
| 1267 | /** Given raw data, attempts to interpret the data based on a specified registry |
---|
| 1268 | * data type. |
---|
| 1269 | * |
---|
| 1270 | * XXX: finish documenting |
---|
| 1271 | * |
---|
[169] | 1272 | * @ingroup regfiGlueLayer |
---|
[168] | 1273 | */ |
---|
[159] | 1274 | bool regfi_interpret_data(REGFI_FILE* file, |
---|
[161] | 1275 | REGFI_ENCODING string_encoding, |
---|
[168] | 1276 | uint32_t type, REGFI_DATA* data); |
---|
| 1277 | |
---|
| 1278 | |
---|
| 1279 | /** Frees the memory associated with a REGFI_CLASSNAME data structure. |
---|
| 1280 | * |
---|
| 1281 | * XXX: finish documenting |
---|
| 1282 | * |
---|
[169] | 1283 | * @ingroup regfiGlueLayer |
---|
[168] | 1284 | */ |
---|
[160] | 1285 | void regfi_free_classname(REGFI_CLASSNAME* classname); |
---|
[168] | 1286 | |
---|
| 1287 | |
---|
| 1288 | /** Frees the memory associated with a REGFI_DATA data structure. |
---|
| 1289 | * |
---|
| 1290 | * XXX: finish documenting |
---|
| 1291 | * |
---|
[169] | 1292 | * @ingroup regfiGlueLayer |
---|
[168] | 1293 | */ |
---|
[159] | 1294 | void regfi_free_data(REGFI_DATA* data); |
---|
[157] | 1295 | |
---|
[160] | 1296 | |
---|
[146] | 1297 | /* These are cached so return values don't need to be freed. */ |
---|
[168] | 1298 | |
---|
| 1299 | /** Loads an "sk" security record at the specified offset. |
---|
| 1300 | * |
---|
| 1301 | * XXX: finish documenting |
---|
| 1302 | * |
---|
[169] | 1303 | * @ingroup regfiGlueLayer |
---|
[168] | 1304 | */ |
---|
| 1305 | const REGFI_SK_REC* regfi_load_sk(REGFI_FILE* file, uint32_t offset, |
---|
[146] | 1306 | bool strict); |
---|
| 1307 | |
---|
| 1308 | |
---|
[168] | 1309 | /** Retrieves the HBIN data structure stored at the specified offset. |
---|
| 1310 | * |
---|
| 1311 | * XXX: finish documenting |
---|
| 1312 | * |
---|
[169] | 1313 | * @ingroup regfiGlueLayer |
---|
[168] | 1314 | */ |
---|
| 1315 | const REGFI_HBIN* regfi_lookup_hbin(REGFI_FILE* file, uint32_t offset); |
---|
| 1316 | |
---|
| 1317 | |
---|
| 1318 | |
---|
| 1319 | /******************************************************************************/ |
---|
| 1320 | /** |
---|
[169] | 1321 | * @defgroup regfiParseLayer Parsing Layer: Direct Data Structure Access |
---|
[168] | 1322 | */ |
---|
| 1323 | /******************************************************************************/ |
---|
| 1324 | |
---|
[178] | 1325 | REGFI_FILE* regfi_parse_regf(REGFI_RAW_FILE* file_cb, bool strict); |
---|
[168] | 1326 | REGFI_HBIN* regfi_parse_hbin(REGFI_FILE* file, uint32_t offset, |
---|
[110] | 1327 | bool strict); |
---|
[80] | 1328 | |
---|
[99] | 1329 | |
---|
[168] | 1330 | /** Parses an NK record at the specified offset |
---|
[99] | 1331 | * |
---|
[168] | 1332 | * @param file the registry file structure |
---|
| 1333 | * @param offset the offset of the cell (not the record) to be parsed. |
---|
| 1334 | * @param max_size the maximum size the NK cell could be. (for validation) |
---|
| 1335 | * @param strict if true, rejects any malformed records. Otherwise, |
---|
| 1336 | * tries to minimally validate integrity. |
---|
| 1337 | * |
---|
| 1338 | * @return A newly allocated NK record structure, or NULL on failure. |
---|
| 1339 | * |
---|
[169] | 1340 | * @ingroup regfiParseLayer |
---|
[99] | 1341 | */ |
---|
[168] | 1342 | REGFI_NK_REC* regfi_parse_nk(REGFI_FILE* file, uint32_t offset, |
---|
| 1343 | uint32_t max_size, bool strict); |
---|
[99] | 1344 | |
---|
[139] | 1345 | |
---|
[168] | 1346 | /** Parses a single cell containing a subkey-list record. |
---|
| 1347 | * |
---|
| 1348 | * XXX: finish documenting |
---|
| 1349 | * |
---|
[169] | 1350 | * @ingroup regfiParseLayer |
---|
[168] | 1351 | */ |
---|
| 1352 | REGFI_SUBKEY_LIST* regfi_parse_subkeylist(REGFI_FILE* file, uint32_t offset, |
---|
| 1353 | uint32_t max_size, bool strict); |
---|
[103] | 1354 | |
---|
[111] | 1355 | |
---|
[168] | 1356 | /** Parses a VK (value) record at the specified offset |
---|
| 1357 | * |
---|
| 1358 | * XXX: finish documenting |
---|
| 1359 | * |
---|
[169] | 1360 | * @ingroup regfiParseLayer |
---|
[168] | 1361 | */ |
---|
| 1362 | REGFI_VK_REC* regfi_parse_vk(REGFI_FILE* file, uint32_t offset, |
---|
| 1363 | uint32_t max_size, bool strict); |
---|
| 1364 | |
---|
| 1365 | |
---|
| 1366 | /** Parses an SK (security) record at the specified offset |
---|
| 1367 | * |
---|
| 1368 | * XXX: finish documenting |
---|
| 1369 | * |
---|
[169] | 1370 | * @ingroup regfiParseLayer |
---|
[168] | 1371 | */ |
---|
| 1372 | REGFI_SK_REC* regfi_parse_sk(REGFI_FILE* file, uint32_t offset, |
---|
| 1373 | uint32_t max_size, bool strict); |
---|
| 1374 | |
---|
| 1375 | |
---|
| 1376 | /** Retrieves information on all cells in the registry hive which are |
---|
| 1377 | * currently in the unallocated status. |
---|
| 1378 | * |
---|
| 1379 | * The unallocated status is determined based soley on the cell length sign. |
---|
| 1380 | * |
---|
| 1381 | * XXX: finish documenting |
---|
| 1382 | * |
---|
[169] | 1383 | * @ingroup regfiParseLayer |
---|
[168] | 1384 | */ |
---|
[135] | 1385 | range_list* regfi_parse_unalloc_cells(REGFI_FILE* file); |
---|
[101] | 1386 | |
---|
[111] | 1387 | |
---|
[168] | 1388 | /** Helper function to parse a cell |
---|
| 1389 | * |
---|
| 1390 | * XXX: finish documenting |
---|
| 1391 | * |
---|
[169] | 1392 | * @ingroup regfiParseLayer |
---|
[168] | 1393 | */ |
---|
[178] | 1394 | bool regfi_parse_cell(REGFI_RAW_FILE* file_cb, uint32_t offset, |
---|
[168] | 1395 | uint8_t* hdr, uint32_t hdr_len, |
---|
| 1396 | uint32_t* cell_length, bool* unalloc); |
---|
[126] | 1397 | |
---|
[157] | 1398 | |
---|
[168] | 1399 | /** Parses a classname cell |
---|
| 1400 | * |
---|
| 1401 | * XXX: finish documenting |
---|
| 1402 | * |
---|
[169] | 1403 | * @ingroup regfiParseLayer |
---|
[168] | 1404 | */ |
---|
| 1405 | uint8_t* regfi_parse_classname(REGFI_FILE* file, uint32_t offset, |
---|
| 1406 | uint16_t* name_length, |
---|
| 1407 | uint32_t max_size, bool strict); |
---|
[157] | 1408 | |
---|
| 1409 | |
---|
[168] | 1410 | /** Parses a single-cell data record |
---|
| 1411 | * |
---|
| 1412 | * XXX: finish documenting |
---|
| 1413 | * |
---|
[169] | 1414 | * @ingroup regfiParseLayer |
---|
[168] | 1415 | */ |
---|
| 1416 | REGFI_BUFFER regfi_parse_data(REGFI_FILE* file, uint32_t offset, |
---|
| 1417 | uint32_t length, bool strict); |
---|
[127] | 1418 | |
---|
[150] | 1419 | |
---|
[168] | 1420 | /** Parses a "little data" record which is stored entirely within the |
---|
| 1421 | * provided virtual offset. |
---|
| 1422 | * |
---|
| 1423 | * XXX: finish documenting |
---|
| 1424 | * |
---|
[169] | 1425 | * @ingroup regfiParseLayer |
---|
[168] | 1426 | */ |
---|
| 1427 | REGFI_BUFFER regfi_parse_little_data(REGFI_FILE* file, uint32_t voffset, |
---|
| 1428 | uint32_t length, bool strict); |
---|
[150] | 1429 | |
---|
[168] | 1430 | |
---|
| 1431 | /******************************************************************************/ |
---|
| 1432 | /* Private Functions */ |
---|
| 1433 | /******************************************************************************/ |
---|
[161] | 1434 | REGFI_NK_REC* regfi_rootkey(REGFI_FILE* file, |
---|
| 1435 | REGFI_ENCODING output_encoding); |
---|
[135] | 1436 | void regfi_subkeylist_free(REGFI_SUBKEY_LIST* list); |
---|
[127] | 1437 | |
---|
[178] | 1438 | off_t regfi_raw_seek(REGFI_RAW_FILE* self, |
---|
| 1439 | off_t offset, int whence); |
---|
| 1440 | ssize_t regfi_raw_read(REGFI_RAW_FILE* self, |
---|
| 1441 | void* buf, size_t count); |
---|
| 1442 | off_t regfi_seek(REGFI_RAW_FILE* file_cb, |
---|
| 1443 | off_t offset, int whence); |
---|
| 1444 | uint32_t regfi_read(REGFI_RAW_FILE* file_cb, |
---|
| 1445 | uint8_t* buf, uint32_t* length); |
---|
| 1446 | |
---|
[135] | 1447 | const char* regfi_type_val2str(unsigned int val); |
---|
| 1448 | int regfi_type_str2val(const char* str); |
---|
[127] | 1449 | |
---|
[135] | 1450 | char* regfi_get_sacl(WINSEC_DESC* sec_desc); |
---|
| 1451 | char* regfi_get_dacl(WINSEC_DESC* sec_desc); |
---|
| 1452 | char* regfi_get_owner(WINSEC_DESC* sec_desc); |
---|
| 1453 | char* regfi_get_group(WINSEC_DESC* sec_desc); |
---|
| 1454 | |
---|
[168] | 1455 | REGFI_SUBKEY_LIST* regfi_merge_subkeylists(uint16_t num_lists, |
---|
[135] | 1456 | REGFI_SUBKEY_LIST** lists, |
---|
| 1457 | bool strict); |
---|
[168] | 1458 | REGFI_SUBKEY_LIST* regfi_load_subkeylist_aux(REGFI_FILE* file, uint32_t offset, |
---|
| 1459 | uint32_t max_size, bool strict, |
---|
| 1460 | uint8_t depth_left); |
---|
| 1461 | void regfi_add_message(REGFI_FILE* file, uint16_t msg_type, |
---|
[138] | 1462 | const char* fmt, ...); |
---|
[146] | 1463 | REGFI_NK_REC* regfi_copy_nk(const REGFI_NK_REC* nk); |
---|
| 1464 | REGFI_VK_REC* regfi_copy_vk(const REGFI_VK_REC* vk); |
---|
[168] | 1465 | int32_t regfi_calc_maxsize(REGFI_FILE* file, uint32_t offset); |
---|
| 1466 | int32_t regfi_conv_charset(const char* input_charset, |
---|
[161] | 1467 | const char* output_charset, |
---|
[168] | 1468 | uint8_t* input, char* output, |
---|
| 1469 | uint32_t input_len, uint32_t output_max); |
---|
[159] | 1470 | REGFI_DATA* regfi_buffer_to_data(REGFI_BUFFER raw_data); |
---|
[146] | 1471 | |
---|
[168] | 1472 | /* XXX: move to base API and document */ |
---|
| 1473 | void regfi_unix2nt_time(REGFI_NTTIME* nt, time_t t); |
---|
| 1474 | time_t regfi_nt2unix_time(const REGFI_NTTIME* nt); |
---|
| 1475 | |
---|
| 1476 | |
---|
[172] | 1477 | void regfi_interpret_keyname(REGFI_FILE* file, REGFI_NK_REC* nk, |
---|
| 1478 | REGFI_ENCODING output_encoding, bool strict); |
---|
| 1479 | void regfi_interpret_valuename(REGFI_FILE* file, REGFI_VK_REC* vk, |
---|
| 1480 | REGFI_ENCODING output_encoding, bool strict); |
---|
| 1481 | |
---|
| 1482 | |
---|
[78] | 1483 | #endif /* _REGFI_H */ |
---|