1 # Win::Hivex::Regedit test -*- perl -*-
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
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 use Encode qw(from_to);
24 use Test::More tests => 8;
27 use Win::Hivex::Regedit qw(reg_export);
29 my $srcdir = $ENV{srcdir} || ".";
31 my $h = Win::Hivex->open ("$srcdir/../images/minimal", write => 1);
34 my $root = $h->root ();
37 $h->node_add_child ($root, "B");
40 $h->node_add_child ($root, "A");
43 my $b = $h->node_get_child ($root, "B");
46 # Encode a string as UTF16-LE.
50 from_to ($s, "ascii", "utf-16le");
54 # Convert a 32 bit integer to a little endian 4 byte data field.
61 # Values are entered in a random order here, but they should be
63 { key => "Key2", t => 2, value => utf16le ("DEF") },
64 { key => "", t => 1, value => "Default" },
65 { key => "Key3", t => 4, value => dwordle (0xff876543) },
66 { key => "Key1", t => 1, value => "ABC" },
68 $h->node_set_values ($b, \@values);
71 my $fh = new IO::Scalar;
72 reg_export ($h, "\\", $fh, prefix => "HKEY_LOCAL_MACHINE\\SOFTWARE\\");
74 my $expected = '[HKEY_LOCAL_MACHINE\\SOFTWARE\\]
76 [HKEY_LOCAL_MACHINE\\SOFTWARE\\A]
78 [HKEY_LOCAL_MACHINE\\SOFTWARE\\B]
79 @=hex(1):44,65,66,61,75,6c,74
80 "Key1"=hex(1):41,42,43
81 "Key2"=hex(2):44,00,45,00,46,00
86 ok (${$fh->sref} eq $expected);
89 reg_export ($h, "\\B", $fh);
92 @=hex(1):44,65,66,61,75,6c,74
93 "Key1"=hex(1):41,42,43
94 "Key2"=hex(2):44,00,45,00,46,00
99 ok (${$fh->sref} eq $expected);
101 # don't commit because that would overwrite the original file