source: trunk/include/regfi.h @ 207

Last change on this file since 207 was 207, checked in by tim, 14 years ago

reworked regfi API to accomodate more convenient subkey/value searches without an iterator.

continued implementation on pyregfi

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