Pull translations from Transifex.
[hivex.git] / images / mklarge.c
1 /* mklarge - Make a large hive for testing purposes.
2  * Copyright (C) 2010 Red Hat Inc.
3  *
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.
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 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.
17  */
18
19 #include <config.h>
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <hivex.h>
26
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 */
31   { "giant" },
32   { "mongoose", "goat", "zebra", "elephant" },
33   { "was" },
34   { "found in", "seen in", "spotted over", "sent to", "fired at" },
35   { "Paris", "London", "Rome", "Oslo", "Madrid", "Nicosia", "Amsterdam",
36     "Moscow", "Riga" },
37   { "today", "yesterday" } /* level 6 */
38 };
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" }
48 };
49
50 static void
51 iter (hive_h *h, int depth, int posn, hive_node_h parent, char *name)
52 {
53   if (depth < nr_degrees) {
54     int degree = degrees[depth];
55     int i, len;
56     hive_node_h node;
57
58     len = strlen (name);
59     if (len > 0) name[len++] = ' ';
60
61     for (i = 0; i < degree; ++i) {
62       strcpy (&name[len], strings[depth][i]);
63       node = hivex_node_add_child (h, parent, name);
64       if (node == 0) {
65         perror ("mklarge: hivex_node_add_child");
66         exit (1);
67       }
68       iter (h, depth+1, i, node, name);
69     }
70
71     if (hivex_node_set_values (h, parent, depth, values, 0) == -1) {
72       perror ("mklarge: hivex_node_set_values");
73       exit (1);
74     }
75   }
76 }
77
78 int
79 main (int argc, char *argv[])
80 {
81   hive_h *h;
82   char name[4096] = { '\0' };
83
84   h = hivex_open (argv[1], HIVEX_OPEN_WRITE);
85   if (h == NULL) {
86     perror (argv[1]);
87     exit (1);
88   }
89
90   iter (h, 0, 0, hivex_root (h), name);
91
92   if (hivex_commit (h, argv[2], 0) == -1) {
93     perror (argv[2]);
94     exit (1);
95   }
96
97   if (hivex_close (h) == -1) {
98     perror ("mklarge: close");
99     exit (1);
100   }
101
102   exit (0);
103 }