be7feee477eafd8c3efedf6014c4c0b6446f9ff7
[libguestfs.git] / hivex / hivex.h
1 /* hivex - Windows Registry "hive" extraction library.
2  * Copyright (C) 2009 Red Hat Inc.
3  * Derived from code by Petter Nordahl-Hagen under a compatible license:
4  *   Copyright (c) 1997-2007 Petter Nordahl-Hagen.
5  * Derived from code by Markus Stephany under a compatible license:
6  *   Copyright (c)2000-2004, Markus Stephany.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation;
11  * version 2.1 of the License.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * See file LICENSE for the full license.
19  */
20
21 #ifndef HIVEX_H_
22 #define HIVEX_H_
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /* NOTE: This API is documented in the man page hivex(3). */
29
30 typedef struct hive_h hive_h;
31 typedef size_t hive_node_h;
32 typedef size_t hive_value_h;
33
34 enum hive_type {
35   /* Just a key without a value. */
36   hive_t_none = 0,
37
38   /* A UTF-16 Windows string. */
39   hive_t_string = 1,
40
41   /* A UTF-16 Windows string that contains %env% (environment variable
42    * substitutions).
43    */
44   hive_t_expand_string = 2,
45
46   /* A blob of binary. */
47   hive_t_binary = 3,
48
49   /* Two ways to encode DWORDs (32 bit words).  The first is little-endian. */
50   hive_t_dword = 4,
51   hive_t_dword_be = 5,
52
53   /* Symbolic link, we think to another part of the registry tree. */
54   hive_t_link = 6,
55
56   /* Multiple UTF-16 Windows strings, each separated by zero byte.  See:
57    * http://blogs.msdn.com/oldnewthing/archive/2009/10/08/9904646.aspx
58    */
59   hive_t_multiple_strings = 7,
60
61   /* These three are unknown. */
62   hive_t_resource_list = 8,
63   hive_t_full_resource_description = 9,
64   hive_t_resource_requirements_list = 10,
65
66   /* A QWORD (64 bit word).  This is stored in the file little-endian. */
67   hive_t_qword = 11
68 };
69
70 typedef enum hive_type hive_type;
71
72 #define HIVEX_OPEN_VERBOSE      1
73 #define HIVEX_OPEN_DEBUG        2
74 #define HIVEX_OPEN_MSGLVL_MASK  3
75
76 #define STREQ(a,b) (strcmp((a),(b)) == 0)
77 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
78 #define STRNEQ(a,b) (strcmp((a),(b)) != 0)
79 #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
80 #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
81 #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
82 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
83 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
84 #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
85
86 extern hive_h *hivex_open (const char *filename, int flags);
87 extern int hivex_close (hive_h *h);
88 extern hive_node_h hivex_root (hive_h *h);
89 extern char *hivex_node_name (hive_h *h, hive_node_h node);
90 extern hive_node_h *hivex_node_children (hive_h *h, hive_node_h node);
91 extern hive_node_h hivex_node_get_child (hive_h *h, hive_node_h node, const char *name);
92 extern hive_node_h hivex_node_parent (hive_h *h, hive_node_h node);
93 extern hive_value_h *hivex_node_values (hive_h *h, hive_node_h node);
94 extern hive_value_h hivex_node_get_value (hive_h *h, hive_node_h node, const char *key);
95 extern char *hivex_value_key (hive_h *h, hive_value_h value);
96 extern int hivex_value_type (hive_h *h, hive_value_h value, hive_type *t, size_t *len);
97 extern char *hivex_value_value (hive_h *h, hive_value_h value, hive_type *t, size_t *len);
98 extern char *hivex_value_string (hive_h *h, hive_value_h value);
99 extern char **hivex_value_multiple_strings (hive_h *h, hive_value_h value);
100 extern int32_t hivex_value_dword (hive_h *h, hive_value_h value);
101 extern int64_t hivex_value_qword (hive_h *h, hive_value_h value);
102 struct hivex_visitor {
103   int (*node_start) (hive_h *, void *opaque, hive_node_h, const char *name);
104   int (*node_end) (hive_h *, void *opaque, hive_node_h, const char *name);
105   int (*value_string) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, const char *str);
106   int (*value_multiple_strings) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, char **argv);
107   int (*value_string_invalid_utf16) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, const char *str);
108   int (*value_dword) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, int32_t);
109   int (*value_qword) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, int64_t);
110   int (*value_binary) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, const char *value);
111   int (*value_none) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, const char *value);
112   int (*value_other) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, const char *value);
113 };
114
115 #define HIVEX_VISIT_SKIP_BAD 1
116
117 extern int hivex_visit (hive_h *h, const struct hivex_visitor *visitor, size_t len, void *opaque, int flags);
118 extern int hivex_visit_node (hive_h *h, hive_node_h node, const struct hivex_visitor *visitor, size_t len, void *opaque, int flags);
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif /* HIVEX_H_ */