source: releases/0.12.0/include/regfi.h @ 191

Last change on this file since 191 was 179, checked in by tim, 15 years ago

fixed a bug in time validation that improves recovery rates

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