f4ce83401aa90592f6929f05650d1bc0db9fdf99
[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 /* Bitmask of flags passed to hivex_open. */
73 #define HIVEX_OPEN_VERBOSE      1
74 #define HIVEX_OPEN_DEBUG        2
75 #define HIVEX_OPEN_MSGLVL_MASK  (HIVEX_OPEN_VERBOSE|HIVEX_OPEN_DEBUG)
76 #define HIVEX_OPEN_WRITE        4
77
78 extern hive_h *hivex_open (const char *filename, int flags);
79 extern int hivex_close (hive_h *h);
80 extern hive_node_h hivex_root (hive_h *h);
81 extern char *hivex_node_name (hive_h *h, hive_node_h node);
82 extern hive_node_h *hivex_node_children (hive_h *h, hive_node_h node);
83 extern hive_node_h hivex_node_get_child (hive_h *h, hive_node_h node, const char *name);
84 extern hive_node_h hivex_node_parent (hive_h *h, hive_node_h node);
85 extern hive_value_h *hivex_node_values (hive_h *h, hive_node_h node);
86 extern hive_value_h hivex_node_get_value (hive_h *h, hive_node_h node, const char *key);
87 extern char *hivex_value_key (hive_h *h, hive_value_h value);
88 extern int hivex_value_type (hive_h *h, hive_value_h value, hive_type *t, size_t *len);
89 extern char *hivex_value_value (hive_h *h, hive_value_h value, hive_type *t, size_t *len);
90 extern char *hivex_value_string (hive_h *h, hive_value_h value);
91 extern char **hivex_value_multiple_strings (hive_h *h, hive_value_h value);
92 extern int32_t hivex_value_dword (hive_h *h, hive_value_h value);
93 extern int64_t hivex_value_qword (hive_h *h, hive_value_h value);
94 struct hivex_visitor {
95   int (*node_start) (hive_h *, void *opaque, hive_node_h, const char *name);
96   int (*node_end) (hive_h *, void *opaque, hive_node_h, const char *name);
97   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);
98   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);
99   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);
100   int (*value_dword) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, int32_t);
101   int (*value_qword) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, int64_t);
102   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);
103   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);
104   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);
105   int (*value_any) (hive_h *, void *opaque, hive_node_h, hive_value_h, hive_type t, size_t len, const char *key, const char *value);
106 };
107
108 #define HIVEX_VISIT_SKIP_BAD 1
109
110 extern int hivex_visit (hive_h *h, const struct hivex_visitor *visitor, size_t len, void *opaque, int flags);
111 extern int hivex_visit_node (hive_h *h, hive_node_h node, const struct hivex_visitor *visitor, size_t len, void *opaque, int flags);
112
113 extern int hivex_commit (hive_h *h, const char *filename, int flags);
114 extern hive_node_h hivex_node_add_child (hive_h *h, hive_node_h parent, const char *name);
115 extern int hivex_node_delete_child (hive_h *h, hive_node_h node);
116
117 struct hive_set_value {
118   char *key;
119   hive_type t;
120   size_t len;
121   char *value;
122 };
123 typedef struct hive_set_value hive_set_value;
124
125 extern int hivex_node_set_values (hive_h *h, hive_node_h node, size_t nr_values, const hive_set_value *values, int flags);
126
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif /* HIVEX_H_ */