source: trunk/include/regfi.h @ 184

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

redesigned memory management to allow for multiple references to talloc-ed objects

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