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