1 /* mklarge - Make a large hive for testing purposes.
2 * Copyright (C) 2010 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 static int degrees[] = { 3, 1, 4, 1, 5, 9, 2 }; /* ~1000 nodes */
28 static const int nr_degrees = sizeof degrees / sizeof degrees[0];
29 static const char *strings[][10] = {
30 { "The", "A", "Another" }, /* level 0 */
32 { "mongoose", "goat", "zebra", "elephant" },
34 { "found in", "seen in", "spotted over", "sent to", "fired at" },
35 { "Paris", "London", "Rome", "Oslo", "Madrid", "Nicosia", "Amsterdam",
37 { "today", "yesterday" } /* level 6 */
39 static hive_set_value values[] = {
40 /* char* casts are needed to work around a stupidity of C */
41 { (char *) "A", hive_t_REG_SZ, 4, (char *) "a\0\0\0" },
42 { (char *) "B", hive_t_REG_DWORD, 4, (char *) "\x78\x56\x34\x12" },
43 { (char *) "C", hive_t_REG_EXPAND_SZ, 6, (char *) "c\0c\0\0\0" },
44 { (char *) "D", hive_t_REG_SZ, 8, (char *) "d\0d\0d\0\0\0" },
45 { (char *) "E", hive_t_REG_QWORD, 8, (char *) "\xf0\xde\xbc\x9a\x78\x56\x34\x12" },
46 { (char *) "F", hive_t_REG_SZ, 4, (char *) "f\0\0\0" },
47 { (char *) "G", hive_t_REG_EXPAND_SZ, 4, (char *) "g\0\0\0" }
51 iter (hive_h *h, int depth, int posn, hive_node_h parent, char *name)
53 if (depth < nr_degrees) {
54 int degree = degrees[depth];
59 if (len > 0) name[len++] = ' ';
61 for (i = 0; i < degree; ++i) {
62 strcpy (&name[len], strings[depth][i]);
63 node = hivex_node_add_child (h, parent, name);
65 perror ("mklarge: hivex_node_add_child");
68 iter (h, depth+1, i, node, name);
71 if (hivex_node_set_values (h, parent, depth, values, 0) == -1) {
72 perror ("mklarge: hivex_node_set_values");
79 main (int argc, char *argv[])
82 char name[4096] = { '\0' };
84 h = hivex_open (argv[1], HIVEX_OPEN_WRITE);
90 iter (h, 0, 0, hivex_root (h), name);
92 if (hivex_commit (h, argv[2], 0) == -1) {
97 if (hivex_close (h) == -1) {
98 perror ("mklarge: close");