From: Richard Jones Date: Wed, 24 Feb 2010 17:30:37 +0000 (+0000) Subject: Move test images to images/ and add a large, generated test image. X-Git-Tag: 1.2.0~15 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=aef7470a0492d3fea1a00ef2de8381417fb23b83;p=hivex.git Move test images to images/ and add a large, generated test image. Previously we had one minimal test image. This was located in hivex/t (a subdirectory of the main library). This adds a large, procedurally generated test image. Because this needs to be built using hivex code, and because subdirectories are built before the parent directory by automake, we have to also move the directory location to a top-level directory called images/. --- diff --git a/.gitignore b/.gitignore index 6fb5f37..6918ed2 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,8 @@ html/hivex.3.html html/hivexget.1.html html/hivexml.1.html html/hivexsh.1.html +images/large +images/mklarge install-sh *.la .libs diff --git a/Makefile.am b/Makefile.am index 2ebc015..fc57ef4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,7 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = gnulib/lib hivex gnulib/tests po +SUBDIRS = gnulib/lib hivex images gnulib/tests po EXTRA_DIST = hivex.pc hivex.pc.in README LICENSE diff --git a/configure.ac b/configure.ac index e5f402f..0bd511f 100644 --- a/configure.ac +++ b/configure.ac @@ -399,8 +399,8 @@ AC_CONFIG_FILES([Makefile gnulib/tests/Makefile hivex.pc hivex/Makefile - hivex/t/Makefile hivex/tools/Makefile + images/Makefile po/Makefile.in]) AC_OUTPUT diff --git a/hivex/Makefile.am b/hivex/Makefile.am index e17f5a3..acd41cf 100644 --- a/hivex/Makefile.am +++ b/hivex/Makefile.am @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -SUBDIRS = t tools +SUBDIRS = tools EXTRA_DIST = \ hivex.pod \ diff --git a/hivex/t/Makefile.am b/images/Makefile.am similarity index 61% rename from hivex/t/Makefile.am rename to images/Makefile.am index 217d7ca..9a32c87 100644 --- a/hivex/t/Makefile.am +++ b/images/Makefile.am @@ -1,5 +1,5 @@ -# libguestfs -# Copyright (C) 2009 Red Hat Inc. +# hivex +# Copyright (C) 2009-2010 Red Hat Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,3 +16,18 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. EXTRA_DIST = minimal + +# 'large' is a large hive used for testing purposes. It is generated +# by the mklarge C program, to avoid having to distribute this large +# binary blob. +noinst_PROGRAMS = mklarge +mklarge_SOURCES = mklarge.c +mklarge_CFLAGS = \ + -I$(srcdir)/../hivex \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) +mklarge_LDADD = ../hivex/libhivex.la + +noinst_DATA = large + +large: mklarge + ./mklarge $(srcdir)/minimal large diff --git a/hivex/t/README b/images/README similarity index 55% rename from hivex/t/README rename to images/README index b7e297a..2131885 100644 --- a/hivex/t/README +++ b/images/README @@ -1,4 +1,4 @@ -This directory contains tests for the hivex library. +This directory contains test images for the hivex library. 'minimal' is a valid registry containing a single root nk (with associated sk) which was created by chopping out everything possible @@ -6,4 +6,8 @@ from a Windows 2003 software hive and then doing lots of hand edits on the result. There is no "source" for it as such, it is just a hand-crafted binary blob. -- Richard W.M. Jones 2010-01-23. +'large' is a procedurally generated, large hive. The program +'mklarge.c' is used to make this during the build. It is used during +tests. + +- Richard W.M. Jones 2010-02-24. diff --git a/hivex/t/minimal b/images/minimal similarity index 100% rename from hivex/t/minimal rename to images/minimal diff --git a/images/mklarge.c b/images/mklarge.c new file mode 100644 index 0000000..c818df8 --- /dev/null +++ b/images/mklarge.c @@ -0,0 +1,103 @@ +/* mklarge - Make a large hive for testing purposes. + * Copyright (C) 2010 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +#include +#include +#include + +#include + +static int degrees[] = { 3, 1, 4, 1, 5, 9, 2 }; /* ~1000 nodes */ +static const int nr_degrees = sizeof degrees / sizeof degrees[0]; +static const char *strings[][10] = { + { "The", "A", "Another" }, /* level 0 */ + { "giant" }, + { "mongoose", "goat", "zebra", "elephant" }, + { "was" }, + { "found in", "seen in", "spotted over", "sent to", "fired at" }, + { "Paris", "London", "Rome", "Oslo", "Madrid", "Nicosia", "Amsterdam", + "Moscow", "Riga" }, + { "today", "yesterday" } /* level 6 */ +}; +static hive_set_value values[] = { + /* char* casts are needed to work around a stupidity of C */ + { (char *) "A", hive_t_REG_SZ, 4, (char *) "a\0\0\0" }, + { (char *) "B", hive_t_REG_DWORD, 4, (char *) "\x78\x56\x34\x12" }, + { (char *) "C", hive_t_REG_EXPAND_SZ, 6, (char *) "c\0c\0\0\0" }, + { (char *) "D", hive_t_REG_SZ, 8, (char *) "d\0d\0d\0\0\0" }, + { (char *) "E", hive_t_REG_QWORD, 8, (char *) "\xf0\xde\xbc\x9a\x78\x56\x34\x12" }, + { (char *) "F", hive_t_REG_SZ, 4, (char *) "f\0\0\0" }, + { (char *) "G", hive_t_REG_EXPAND_SZ, 4, (char *) "g\0\0\0" } +}; + +static void +iter (hive_h *h, int depth, int posn, hive_node_h parent, char *name) +{ + if (depth < nr_degrees) { + int degree = degrees[depth]; + int i, len; + hive_node_h node; + + len = strlen (name); + if (len > 0) name[len++] = ' '; + + for (i = 0; i < degree; ++i) { + strcpy (&name[len], strings[depth][i]); + node = hivex_node_add_child (h, parent, name); + if (node == 0) { + perror ("mklarge: hivex_node_add_child"); + exit (1); + } + iter (h, depth+1, i, node, name); + } + + if (hivex_node_set_values (h, parent, depth, values, 0) == -1) { + perror ("mklarge: hivex_node_set_values"); + exit (1); + } + } +} + +int +main (int argc, char *argv[]) +{ + hive_h *h; + char name[4096] = { '\0' }; + + h = hivex_open (argv[1], HIVEX_OPEN_WRITE); + if (h == NULL) { + perror (argv[1]); + exit (1); + } + + iter (h, 0, 0, hivex_root (h), name); + + if (hivex_commit (h, argv[2], 0) == -1) { + perror (argv[2]); + exit (1); + } + + if (hivex_close (h) == -1) { + perror ("mklarge: close"); + exit (1); + } + + exit (0); +} diff --git a/po/POTFILES.in b/po/POTFILES.in index 7d8a085..306da64 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,3 +1,4 @@ hivex/hivex.c hivex/hivexml.c hivex/hivexsh.c +images/mklarge.c