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