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