source: trunk/include/regfi.h @ 199

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

reworked part of regfi C API to make python wrappers simpler
continued work on python wrappers
fixed some issues in pyregfi-smoketest. WIP

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