source: trunk/include/regfi.h @ 232

Last change on this file since 232 was 232, checked in by tim, 13 years ago

added a convenience openHive function in pyregfi
standardized static function names
improvements to scons release script and library versioning

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