Hilko Bengen
2014-Jan-10 23:12 UTC
[Libguestfs] [PATCH 1/7] Add a minimal hive with "special" keys and values
--- images/README | 14 ++++++++++++ images/mkzero/Makefile | 9 ++++++++ images/mkzero/mkzero.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ images/special | Bin 0 -> 8192 bytes 4 files changed, 82 insertions(+) create mode 100644 images/mkzero/Makefile create mode 100644 images/mkzero/mkzero.c create mode 100644 images/special diff --git a/images/README b/images/README index 2131885..b01e5a2 100644 --- a/images/README +++ b/images/README @@ -11,3 +11,17 @@ hand-crafted binary blob. tests. - Richard W.M. Jones 2010-02-24. + +'special' was created by importing 'minimal' into a VM running Windows +XP, loading it into HKEY_LOCAL_MACHINE\minimal using regedit.exe +(File/Load Hive...), and running 'mkzero.exe'. + +'mkzero.exe' creates the following keys and values: + +- A key 'zero\0key' containing a REG_DWORD value 'zero\0val' (\0 = zero + character) +- A key 'asdf_äöüß' containing a REG_DWORD value 'asdf_äöüß' +- A key 'weird™' containing a REG_DWORD value 'symbols $£₤₧€' (SMALL + DOLLAR SIGN, FULLWIDTH POUND SIGN, PESETA SIGN, EURO SIGN) + +- Hilko Bengen 2014-01-10. diff --git a/images/mkzero/Makefile b/images/mkzero/Makefile new file mode 100644 index 0000000..affe52b --- /dev/null +++ b/images/mkzero/Makefile @@ -0,0 +1,9 @@ +CROSS=i686-w64-mingw32- +CFLAGS=--std=c99 +all: mkzero.exe +clean: + rm -f *.exe *.o +mkzero.exe: mkzero.o + $(CROSS)gcc -o $@ $< -lntdll +%.o: %.c + $(CROSS)gcc $(CFLAGS) -Wpedantic -Wall -o $@ -c $< diff --git a/images/mkzero/mkzero.c b/images/mkzero/mkzero.c new file mode 100644 index 0000000..a95794a --- /dev/null +++ b/images/mkzero/mkzero.c @@ -0,0 +1,59 @@ +/* use the NT native API to create registry key and value that contain + a zero character */ + +#include <ntdef.h> +#include <stdio.h> +#include <ddk/wdm.h> +#include <windef.h> + +void create_key_value (PHANDLE handle, WCHAR* key, int key_len, WCHAR* val, int val_len) +{ + UNICODE_STRING key_name = { key_len, key_len, key }; + UNICODE_STRING value_name = { val_len, val_len, val }; + OBJECT_ATTRIBUTES key_obj; + InitializeObjectAttributes (&key_obj, &key_name, + OBJ_OPENIF | OBJ_CASE_INSENSITIVE, + *handle, NULL); + HANDLE key_handle; + NTSTATUS rc; + rc = ZwCreateKey (&key_handle, KEY_ALL_ACCESS, &key_obj, + 0, NULL, REG_OPTION_NON_VOLATILE, NULL); + if (!NT_SUCCESS (rc)) { + wprintf(L"error: CreateKey %s: 0x%08x\n", key, rc); + exit(1); + } + DWORD value = 0; + rc = ZwSetValueKey (key_handle, &value_name, 0, + REG_DWORD, &value, sizeof(value)); + if (!NT_SUCCESS (rc)) { + wprintf(L"error: SetValueKey %s: 0x%08x\n", val, rc); + exit(1); + } +} + +int main (int argc, char **argv) +{ + UNICODE_STRING root_key_name; + RtlInitUnicodeString(&root_key_name, L"\\Registry\\Machine\\minimal"); + OBJECT_ATTRIBUTES root_key_obj; + InitializeObjectAttributes (&root_key_obj, &root_key_name, + OBJ_OPENIF | OBJ_CASE_INSENSITIVE, + NULL, NULL); + HANDLE minimal_key_handle; + NTSTATUS rc = ZwCreateKey (&minimal_key_handle, KEY_ALL_ACCESS, &root_key_obj, + 0, NULL, REG_OPTION_NON_VOLATILE, NULL); + if (!NT_SUCCESS (rc)) { + wprintf(L"error: CreateKey <HKLM\\minimal>: 0x%08x\n", rc); + exit(1); + } + WCHAR k1[] = L"zero\0key"; + WCHAR v1[] = L"zero\0val"; + create_key_value (&minimal_key_handle, k1, sizeof (k1)-2, v1, sizeof (v1)-2); + WCHAR k2[] = L"abcd_äöüß"; + WCHAR v2[] = L"abcd_äöüß"; + create_key_value (&minimal_key_handle, k2, sizeof (k2)-2, v2, sizeof (v2)-2); + WCHAR k3[] = L"weird™"; + WCHAR v3[] = L"symbols $£₤₧€"; + create_key_value (&minimal_key_handle, k3, sizeof (k3)-2, v3, sizeof (v3)-2); + return 0; +} diff --git a/images/special b/images/special new file mode 100644 index 0000000000000000000000000000000000000000..8a5ff5f34f32f0e56c1e1e9abf49bd3a8857c5e7 GIT binary patch literal 8192 zcmeHLziU%b6h28CZ9~<EDAeHa+P=XdxC$;R6s%K4L=cN5X`%@)O-drwio+ZH@elY1 z1T2`rMJE?Ghc2Q^L|k-m(@8`sh|ll4H&6SLm(oQjat_>k?mh3^bH4X|uYulX`TDgz zDG`p7(@(o+_rFeIDH#kJ*De>1UAJUG&PYj?r7CrdmfVo06fig77i3n-i1}u}f_;>? zjGP+lsO=gC@|UkX+cjVmh%%rIC<DrXGN2471ImChpbRJj%D_Kmpi->XO#}RYA6aw{ zz<oOm!@8fB{JkG9c{jk=>AfN&T);Y`B1j3jrVo1lAOn3ifxYK>=P%4(oIgHy?h+qw z{0hUCkL!iB9c*wEQ%Xi3^76qk9Yqcyo|Z3?<sq4rBiN;I29|L#O>v!_#3aE$JRyH( zNWO_9|CAhv)p!5qJ6r3UIMA7Vi#223Jxj!Zzcn_rZY<YO+utKz2fTypy6?txaoMqF z)PlzLZB!(`+(*wTH>5K*hWU26*$}_H*6!&MAjUy3vnT>R?oPlTv+vW>W7F#44ACPu zM301g!+S!$i6cKz51T)zhm)X3F2=Fd$nk7ld)bvajCbvvcw4^n+1od>xa5E1yT;F1 zZMMlz4SCknQ#PT23*zbDz<-2a^~b11fNu2s?5!TFg&Ok$bZx`$RPU7pz4=YDHf<cE zP+Tf4e)|6NgNg7jN~BgvO9yAKb|1WY4iGQCdhg#EeB%T7`p;W@vZL?uRsy~p`bYTq zJ8={Dh*jJumSlR05Q(E!8To^64$0m1`;7=Eb7&g|Z!U(H@s_ONF0zPQ${N<Lc=AZr k-N)_|mrtRG{b8{ios|J)Kp9X5lmTTx8Bhk4f&Y|&-#+)~(*OVf literal 0 HcmV?d00001 -- 1.8.5.2
Hilko Bengen
2014-Jan-10 23:12 UTC
[Libguestfs] [PATCH 2/7] lib: Use vk->len for string conversion
--- lib/value.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/value.c b/lib/value.c index 65404d7..e700c84 100644 --- a/lib/value.c +++ b/lib/value.c @@ -207,14 +207,8 @@ hivex_value_key (hive_h *h, hive_value_h value) struct ntreg_vk_record *vk (struct ntreg_vk_record *) ((char *) h->addr + value); - /* AFAIK the key is always plain ASCII, so no conversion to UTF-8 is - * necessary. However we do need to nul-terminate the string. - */ - errno = 0; - size_t len = hivex_value_key_len (h, value); - if (len == 0 && errno != 0) - return NULL; size_t flags = le16toh (vk->flags); + size_t len = le16toh (vk->name_len); if (flags & 0x01) { return _hivex_windows_latin1_to_utf8 (vk->name, len); } else { -- 1.8.5.2
Hilko Bengen
2014-Jan-10 23:12 UTC
[Libguestfs] [PATCH 3/7] perl: Add test for "special" keys and values
--- perl/t/130-special.t | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 perl/t/130-special.t diff --git a/perl/t/130-special.t b/perl/t/130-special.t new file mode 100644 index 0000000..c25af7e --- /dev/null +++ b/perl/t/130-special.t @@ -0,0 +1,34 @@ +# hivex Perl bindings -*- perl -*- + +use strict; +use warnings; +use utf8::all; # so the strings in this file are interpreted correctly. +use Test::More; + +use Win::Hivex; + +my $srcdir = $ENV{srcdir} || "."; +my $h = Win::Hivex->open ("$srcdir/../images/special"); +ok $h, 'hive opened correctly'; +my $root = $h->root; +ok $root, 'root node found'; +my ($node, $value); + +my @nodes = $h->node_children( $root ); + +($node) = grep { $h->node_name($_) eq 'abcd_äöüß' } @nodes; +ok $node, q<'abcd_äöüß' (node) has been found>; +($value) = grep { $h->value_key($_) eq 'abcd_äöüß' } $h->node_values($node); +ok $value, q<'abcd_äöüß\abcd_äöüß' (value) has been found>; + +($node) = grep { $h->node_name($_) eq "zero\0key" } @nodes; +ok $node, 'key has been found'; +($value) = grep { $h->value_key($_) eq "zero\0val" } $h->node_values($node); +ok $value, 'value has been found'; + +($node) = grep { $h->node_name($_) eq 'weird™' } @nodes; +ok $node, q<'weird™' (node) has been found>; +($value) = grep { $h->value_key($_) eq 'symbols $£₤₧€' } $h->node_values($node); +ok $value, q<'weird™\symbols $£₤₧€' (value) has been found>; + +done_testing; -- 1.8.5.2
Hilko Bengen
2014-Jan-10 23:12 UTC
[Libguestfs] [PATCH 4/7] python: Add test for "special" keys and values
--- python/t/130-special.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 python/t/130-special.py diff --git a/python/t/130-special.py b/python/t/130-special.py new file mode 100755 index 0000000..7adb9d5 --- /dev/null +++ b/python/t/130-special.py @@ -0,0 +1,28 @@ +# coding: utf-8 + +import os +import hivex + +srcdir = os.environ["srcdir"] +if not srcdir: + srcdir = "." + +h = hivex.Hivex ("%s/../images/special" % srcdir) +assert h + +root = h.root () +assert root + +ns = [ n for n in h.node_children (root) if h.node_name(n) == u"abcd_äöüß" ] +assert len (ns) == 1 +vs = [ v for v in h.node_values (ns[0]) if h.value_key(v) == u"abcd_äöüß" ] +assert len (vs) == 1 +ns = [ n for n in h.node_children (root) if h.node_name(n) == u"zero\0key" ] +assert len (ns) == 1 +vs = [ v for v in h.node_values (ns[0]) if h.value_key(v) == u"zero\0val" ] +assert len (vs) == 1 +ns = [ n for n in h.node_children (root) if h.node_name(n) == u"weird™" ] +assert len (ns) == 1 +vs = [ v for v in h.node_values (ns[0]) if h.value_key(v) == u"symbols $£₤₧€" ] +assert len (vs) == 1 + -- 1.8.5.2
Hilko Bengen
2014-Jan-10 23:12 UTC
[Libguestfs] [PATCH 5/7] perl: Properly decode node names, value keys from UTF-8
--- generator/generator.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/generator.ml b/generator/generator.ml index 6b1eef7..4119b04 100755 --- a/generator/generator.ml +++ b/generator/generator.ml @@ -2648,7 +2648,7 @@ DESTROY (h) pr " croak (\"%%s: %%s\", \"%s\", strerror (errno));\n" name; if f_len_exists name then - pr " RETVAL = newSVpvn (r, hivex_%s_len (%s));\n" + pr " RETVAL = newSVpvn_utf8 (r, hivex_%s_len (%s), 1);\n" name (String.concat ", " c_params) else pr " RETVAL = newSVpv (r, 0);\n"; -- 1.8.5.2
Hilko Bengen
2014-Jan-10 23:12 UTC
[Libguestfs] [PATCH 6/7] python: Python 3 no longer recognizes long integers
--- python/t/120-rlenvalue.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/t/120-rlenvalue.py b/python/t/120-rlenvalue.py index ebc48f5..a9b2129 100644 --- a/python/t/120-rlenvalue.py +++ b/python/t/120-rlenvalue.py @@ -38,5 +38,5 @@ moderate_value_node = h.node_get_child (root, "ModerateValueParent") moderate_value_value = h.node_get_value (moderate_value_node, "33Bytes") r = h.value_data_cell_offset (moderate_value_value) -assert r[0] == 37L -assert r[1] == 8712L +assert r[0] == 37 +assert r[1] == 8712 -- 1.8.5.2
Hilko Bengen
2014-Jan-10 23:12 UTC
[Libguestfs] [PATCH 7/7] python: fix test runner so scripts are found when building out-of-tree
--- python/run-python-tests.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/run-python-tests.in b/python/run-python-tests.in index 90aee03..0df646b 100755 --- a/python/run-python-tests.in +++ b/python/run-python-tests.in @@ -19,7 +19,7 @@ set -e shopt -s nullglob -for f in @srcdir@t/*.py; do +for f in @srcdir@/t/*.py; do basename "$f" $PYTHON "$f" done -- 1.8.5.2
Richard W.M. Jones
2014-Jan-13 13:17 UTC
Re: [Libguestfs] [PATCH 2/7] lib: Use vk->len for string conversion
On Sat, Jan 11, 2014 at 12:12:47AM +0100, Hilko Bengen wrote:> --- > lib/value.c | 8 +------- > 1 file changed, 1 insertion(+), 7 deletions(-) > > diff --git a/lib/value.c b/lib/value.c > index 65404d7..e700c84 100644 > --- a/lib/value.c > +++ b/lib/value.c > @@ -207,14 +207,8 @@ hivex_value_key (hive_h *h, hive_value_h value) > struct ntreg_vk_record *vk > (struct ntreg_vk_record *) ((char *) h->addr + value); > > - /* AFAIK the key is always plain ASCII, so no conversion to UTF-8 is > - * necessary. However we do need to nul-terminate the string. > - */ > - errno = 0; > - size_t len = hivex_value_key_len (h, value); > - if (len == 0 && errno != 0) > - return NULL; > size_t flags = le16toh (vk->flags); > + size_t len = le16toh (vk->name_len);I think this effectively removes a check. hivex_value_key_len contains this code: size_t seg_len = block_len (h, value, NULL); if (sizeof (struct ntreg_vk_record) + len - 1 > seg_len) { SET_ERRNO (EFAULT, "key length is too long (%zu, %zu)", len, seg_len); return 0; } but after this change, this would no longer be run, so it would be possible to overrun the registry, or at least overrun the end of a block. Is there a reason for this patch? It seems like just an optimization. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Richard W.M. Jones
2014-Jan-13 13:18 UTC
Re: [Libguestfs] [PATCH 1/7] Add a minimal hive with "special" keys and values
On Sat, Jan 11, 2014 at 12:12:46AM +0100, Hilko Bengen wrote:> --- > images/README | 14 ++++++++++++ > images/mkzero/Makefile | 9 ++++++++ > images/mkzero/mkzero.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ > images/special | Bin 0 -> 8192 bytes > 4 files changed, 82 insertions(+) > create mode 100644 images/mkzero/Makefile > create mode 100644 images/mkzero/mkzero.c > create mode 100644 images/special > > diff --git a/images/README b/images/README > index 2131885..b01e5a2 100644 > --- a/images/README > +++ b/images/README > @@ -11,3 +11,17 @@ hand-crafted binary blob. > tests. > > - Richard W.M. Jones 2010-02-24. > + > +'special' was created by importing 'minimal' into a VM running Windows > +XP, loading it into HKEY_LOCAL_MACHINE\minimal using regedit.exe > +(File/Load Hive...), and running 'mkzero.exe'. > + > +'mkzero.exe' creates the following keys and values: > + > +- A key 'zero\0key' containing a REG_DWORD value 'zero\0val' (\0 = zero > + character) > +- A key 'asdf_äöüß' containing a REG_DWORD value 'asdf_äöüß' > +- A key 'weird™' containing a REG_DWORD value 'symbols $£₤₧€' (SMALL > + DOLLAR SIGN, FULLWIDTH POUND SIGN, PESETA SIGN, EURO SIGN) > + > +- Hilko Bengen 2014-01-10. > diff --git a/images/mkzero/Makefile b/images/mkzero/Makefile > new file mode 100644 > index 0000000..affe52b > --- /dev/null > +++ b/images/mkzero/Makefile > @@ -0,0 +1,9 @@ > +CROSS=i686-w64-mingw32- > +CFLAGS=--std=c99 > +all: mkzero.exe > +clean: > + rm -f *.exe *.o > +mkzero.exe: mkzero.o > + $(CROSS)gcc -o $@ $< -lntdll > +%.o: %.c > + $(CROSS)gcc $(CFLAGS) -Wpedantic -Wall -o $@ -c $< > diff --git a/images/mkzero/mkzero.c b/images/mkzero/mkzero.c > new file mode 100644 > index 0000000..a95794a > --- /dev/null > +++ b/images/mkzero/mkzero.c > @@ -0,0 +1,59 @@ > +/* use the NT native API to create registry key and value that contain > + a zero character */ > + > +#include <ntdef.h> > +#include <stdio.h> > +#include <ddk/wdm.h> > +#include <windef.h> > + > +void create_key_value (PHANDLE handle, WCHAR* key, int key_len, WCHAR* val, int val_len) > +{ > + UNICODE_STRING key_name = { key_len, key_len, key }; > + UNICODE_STRING value_name = { val_len, val_len, val }; > + OBJECT_ATTRIBUTES key_obj; > + InitializeObjectAttributes (&key_obj, &key_name, > + OBJ_OPENIF | OBJ_CASE_INSENSITIVE, > + *handle, NULL); > + HANDLE key_handle; > + NTSTATUS rc; > + rc = ZwCreateKey (&key_handle, KEY_ALL_ACCESS, &key_obj, > + 0, NULL, REG_OPTION_NON_VOLATILE, NULL); > + if (!NT_SUCCESS (rc)) { > + wprintf(L"error: CreateKey %s: 0x%08x\n", key, rc); > + exit(1); > + } > + DWORD value = 0; > + rc = ZwSetValueKey (key_handle, &value_name, 0, > + REG_DWORD, &value, sizeof(value)); > + if (!NT_SUCCESS (rc)) { > + wprintf(L"error: SetValueKey %s: 0x%08x\n", val, rc); > + exit(1); > + } > +} > + > +int main (int argc, char **argv) > +{ > + UNICODE_STRING root_key_name; > + RtlInitUnicodeString(&root_key_name, L"\\Registry\\Machine\\minimal"); > + OBJECT_ATTRIBUTES root_key_obj; > + InitializeObjectAttributes (&root_key_obj, &root_key_name, > + OBJ_OPENIF | OBJ_CASE_INSENSITIVE, > + NULL, NULL); > + HANDLE minimal_key_handle; > + NTSTATUS rc = ZwCreateKey (&minimal_key_handle, KEY_ALL_ACCESS, &root_key_obj, > + 0, NULL, REG_OPTION_NON_VOLATILE, NULL); > + if (!NT_SUCCESS (rc)) { > + wprintf(L"error: CreateKey <HKLM\\minimal>: 0x%08x\n", rc); > + exit(1); > + } > + WCHAR k1[] = L"zero\0key"; > + WCHAR v1[] = L"zero\0val"; > + create_key_value (&minimal_key_handle, k1, sizeof (k1)-2, v1, sizeof (v1)-2); > + WCHAR k2[] = L"abcd_äöüß"; > + WCHAR v2[] = L"abcd_äöüß"; > + create_key_value (&minimal_key_handle, k2, sizeof (k2)-2, v2, sizeof (v2)-2); > + WCHAR k3[] = L"weird™"; > + WCHAR v3[] = L"symbols $£₤₧€"; > + create_key_value (&minimal_key_handle, k3, sizeof (k3)-2, v3, sizeof (v3)-2); > + return 0; > +} > diff --git a/images/special b/images/special > new file mode 100644 > index 0000000000000000000000000000000000000000..8a5ff5f34f32f0e56c1e1e9abf49bd3a8857c5e7 > GIT binary patch > literal 8192 > zcmeHLziU%b6h28CZ9~<EDAeHa+P=XdxC$;R6s%K4L=cN5X`%@)O-drwio+ZH@elY1 > z1T2`rMJE?Ghc2Q^L|k-m(@8`sh|ll4H&6SLm(oQjat_>k?mh3^bH4X|uYulX`TDgz > zDG`p7(@(o+_rFeIDH#kJ*De>1UAJUG&PYj?r7CrdmfVo06fig77i3n-i1}u}f_;>? > zjGP+lsO=gC@|UkX+cjVmh%%rIC<DrXGN2471ImChpbRJj%D_Kmpi->XO#}RYA6aw{ > zz<oOm!@8fB{JkG9c{jk=>AfN&T);Y`B1j3jrVo1lAOn3ifxYK>=P%4(oIgHy?h+qw > z{0hUCkL!iB9c*wEQ%Xi3^76qk9Yqcyo|Z3?<sq4rBiN;I29|L#O>v!_#3aE$JRyH( > zNWO_9|CAhv)p!5qJ6r3UIMA7Vi#223Jxj!Zzcn_rZY<YO+utKz2fTypy6?txaoMqF > z)PlzLZB!(`+(*wTH>5K*hWU26*$}_H*6!&MAjUy3vnT>R?oPlTv+vW>W7F#44ACPu > zM301g!+S!$i6cKz51T)zhm)X3F2=Fd$nk7ld)bvajCbvvcw4^n+1od>xa5E1yT;F1 > zZMMlz4SCknQ#PT23*zbDz<-2a^~b11fNu2s?5!TFg&Ok$bZx`$RPU7pz4=YDHf<cE > zP+Tf4e)|6NgNg7jN~BgvO9yAKb|1WY4iGQCdhg#EeB%T7`p;W@vZL?uRsy~p`bYTq > zJ8={Dh*jJumSlR05Q(E!8To^64$0m1`;7=Eb7&g|Z!U(H@s_ONF0zPQ${N<Lc=AZr > k-N)_|mrtRG{b8{ios|J)Kp9X5lmTTx8Bhk4f&Y|&-#+)~(*OVf > > literal 0 > HcmV?d00001ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Richard W.M. Jones
2014-Jan-13 13:18 UTC
Re: [Libguestfs] [PATCH 3/7] perl: Add test for "special" keys and values
On Sat, Jan 11, 2014 at 12:12:48AM +0100, Hilko Bengen wrote:> --- > perl/t/130-special.t | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > create mode 100644 perl/t/130-special.t > > diff --git a/perl/t/130-special.t b/perl/t/130-special.t > new file mode 100644 > index 0000000..c25af7e > --- /dev/null > +++ b/perl/t/130-special.t > @@ -0,0 +1,34 @@ > +# hivex Perl bindings -*- perl -*- > + > +use strict; > +use warnings; > +use utf8::all; # so the strings in this file are interpreted correctly. > +use Test::More; > + > +use Win::Hivex; > + > +my $srcdir = $ENV{srcdir} || "."; > +my $h = Win::Hivex->open ("$srcdir/../images/special"); > +ok $h, 'hive opened correctly'; > +my $root = $h->root; > +ok $root, 'root node found'; > +my ($node, $value); > + > +my @nodes = $h->node_children( $root ); > + > +($node) = grep { $h->node_name($_) eq 'abcd_äöüß' } @nodes; > +ok $node, q<'abcd_äöüß' (node) has been found>; > +($value) = grep { $h->value_key($_) eq 'abcd_äöüß' } $h->node_values($node); > +ok $value, q<'abcd_äöüß\abcd_äöüß' (value) has been found>; > + > +($node) = grep { $h->node_name($_) eq "zero\0key" } @nodes; > +ok $node, 'key has been found'; > +($value) = grep { $h->value_key($_) eq "zero\0val" } $h->node_values($node); > +ok $value, 'value has been found'; > + > +($node) = grep { $h->node_name($_) eq 'weird™' } @nodes; > +ok $node, q<'weird™' (node) has been found>; > +($value) = grep { $h->value_key($_) eq 'symbols $£₤₧€' } $h->node_values($node); > +ok $value, q<'weird™\symbols $£₤₧€' (value) has been found>; > + > +done_testing;ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
Richard W.M. Jones
2014-Jan-13 13:20 UTC
Re: [Libguestfs] [PATCH 4/7] python: Add test for "special" keys and values
On Sat, Jan 11, 2014 at 12:12:49AM +0100, Hilko Bengen wrote:> --- > python/t/130-special.py | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > create mode 100755 python/t/130-special.py > > diff --git a/python/t/130-special.py b/python/t/130-special.py > new file mode 100755 > index 0000000..7adb9d5 > --- /dev/null > +++ b/python/t/130-special.py > @@ -0,0 +1,28 @@ > +# coding: utf-8 > + > +import os > +import hivex > + > +srcdir = os.environ["srcdir"] > +if not srcdir: > + srcdir = "." > + > +h = hivex.Hivex ("%s/../images/special" % srcdir) > +assert h > + > +root = h.root () > +assert root > + > +ns = [ n for n in h.node_children (root) if h.node_name(n) == u"abcd_äöüß" ] > +assert len (ns) == 1 > +vs = [ v for v in h.node_values (ns[0]) if h.value_key(v) == u"abcd_äöüß" ] > +assert len (vs) == 1 > +ns = [ n for n in h.node_children (root) if h.node_name(n) == u"zero\0key" ] > +assert len (ns) == 1 > +vs = [ v for v in h.node_values (ns[0]) if h.value_key(v) == u"zero\0val" ] > +assert len (vs) == 1 > +ns = [ n for n in h.node_children (root) if h.node_name(n) == u"weird™" ] > +assert len (ns) == 1 > +vs = [ v for v in h.node_values (ns[0]) if h.value_key(v) == u"symbols $£₤₧€" ] > +assert len (vs) == 1 > + > -- > 1.8.5.2ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
Richard W.M. Jones
2014-Jan-13 13:23 UTC
Re: [Libguestfs] [PATCH 5/7] perl: Properly decode node names, value keys from UTF-8
On Sat, Jan 11, 2014 at 12:12:50AM +0100, Hilko Bengen wrote:> --- > generator/generator.ml | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/generator/generator.ml b/generator/generator.ml > index 6b1eef7..4119b04 100755 > --- a/generator/generator.ml > +++ b/generator/generator.ml > @@ -2648,7 +2648,7 @@ DESTROY (h) > pr " croak (\"%%s: %%s\", \"%s\", strerror (errno));\n" > name; > if f_len_exists name then > - pr " RETVAL = newSVpvn (r, hivex_%s_len (%s));\n" > + pr " RETVAL = newSVpvn_utf8 (r, hivex_%s_len (%s), 1);\n" > name (String.concat ", " c_params) > else > pr " RETVAL = newSVpv (r, 0);\n"; > -- > 1.8.5.2 > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfsACK. I wonder what happens if the registry contains a garbage string (one which is not valid utf-8)? It looks from the source as if newSVpvn_utf8 just sets a flag in the SV, so that would be OK in the sense that Perl programs wouldn't start crashing. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Richard W.M. Jones
2014-Jan-13 13:23 UTC
Re: [Libguestfs] [PATCH 6/7] python: Python 3 no longer recognizes long integers
On Sat, Jan 11, 2014 at 12:12:51AM +0100, Hilko Bengen wrote:> --- > python/t/120-rlenvalue.py | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/python/t/120-rlenvalue.py b/python/t/120-rlenvalue.py > index ebc48f5..a9b2129 100644 > --- a/python/t/120-rlenvalue.py > +++ b/python/t/120-rlenvalue.py > @@ -38,5 +38,5 @@ moderate_value_node = h.node_get_child (root, "ModerateValueParent") > moderate_value_value = h.node_get_value (moderate_value_node, "33Bytes") > > r = h.value_data_cell_offset (moderate_value_value) > -assert r[0] == 37L > -assert r[1] == 8712L > +assert r[0] == 37 > +assert r[1] == 8712As long as this still works on Python 2, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Richard W.M. Jones
2014-Jan-13 13:24 UTC
Re: [Libguestfs] [PATCH 7/7] python: fix test runner so scripts are found when building out-of-tree
On Sat, Jan 11, 2014 at 12:12:52AM +0100, Hilko Bengen wrote:> --- > python/run-python-tests.in | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/python/run-python-tests.in b/python/run-python-tests.in > index 90aee03..0df646b 100755 > --- a/python/run-python-tests.in > +++ b/python/run-python-tests.in > @@ -19,7 +19,7 @@ > set -e > shopt -s nullglob > > -for f in @srcdir@t/*.py; do > +for f in @srcdir@/t/*.py; do > basename "$f" > $PYTHON "$f" > done > -- > 1.8.5.2ACK (because @srcdir@ always expands to something, usually '.'). Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Alex Nelson
2014-Jan-14 17:10 UTC
Re: [Libguestfs] [PATCH 1/7] Add a minimal hive with "special" keys and values
Hi Hilko, Thanks a lot for creating this test hive! I think another thing that will trip up Registry programs is value names that include back slashes. For example, under the System hive, the key "\MountedDevices" has child values with names like "\DosDevices\C:" (the leading backslash is a part of the value name). There are many other values that include backslashes. I don't think I have any keys that have backslash-carrying names, but I haven't tested that extensively. Have these values caused enough troubles to warrant another test hive? --Alex On Mon, Jan 13, 2014 at 8:18 AM, Richard W.M. Jones <rjones@redhat.com>wrote:> On Sat, Jan 11, 2014 at 12:12:46AM +0100, Hilko Bengen wrote: > > --- > > images/README | 14 ++++++++++++ > > images/mkzero/Makefile | 9 ++++++++ > > images/mkzero/mkzero.c | 59 > +++++++++++++++++++++++++++++++++++++++++++++++++ > > images/special | Bin 0 -> 8192 bytes > > 4 files changed, 82 insertions(+) > > create mode 100644 images/mkzero/Makefile > > create mode 100644 images/mkzero/mkzero.c > > create mode 100644 images/special > > > > diff --git a/images/README b/images/README > > index 2131885..b01e5a2 100644 > > --- a/images/README > > +++ b/images/README > > @@ -11,3 +11,17 @@ hand-crafted binary blob. > > tests. > > > > - Richard W.M. Jones 2010-02-24. > > + > > +'special' was created by importing 'minimal' into a VM running Windows > > +XP, loading it into HKEY_LOCAL_MACHINE\minimal using regedit.exe > > +(File/Load Hive...), and running 'mkzero.exe'. > > + > > +'mkzero.exe' creates the following keys and values: > > + > > +- A key 'zero\0key' containing a REG_DWORD value 'zero\0val' (\0 = zero > > + character) > > +- A key 'asdf_äöüß' containing a REG_DWORD value 'asdf_äöüß' > > +- A key 'weird™' containing a REG_DWORD value 'symbols $£₤₧€' (SMALL > > + DOLLAR SIGN, FULLWIDTH POUND SIGN, PESETA SIGN, EURO SIGN) > > + > > +- Hilko Bengen 2014-01-10. > > diff --git a/images/mkzero/Makefile b/images/mkzero/Makefile > > new file mode 100644 > > index 0000000..affe52b > > --- /dev/null > > +++ b/images/mkzero/Makefile > > @@ -0,0 +1,9 @@ > > +CROSS=i686-w64-mingw32- > > +CFLAGS=--std=c99 > > +all: mkzero.exe > > +clean: > > + rm -f *.exe *.o > > +mkzero.exe: mkzero.o > > + $(CROSS)gcc -o $@ $< -lntdll > > +%.o: %.c > > + $(CROSS)gcc $(CFLAGS) -Wpedantic -Wall -o $@ -c $< > > diff --git a/images/mkzero/mkzero.c b/images/mkzero/mkzero.c > > new file mode 100644 > > index 0000000..a95794a > > --- /dev/null > > +++ b/images/mkzero/mkzero.c > > @@ -0,0 +1,59 @@ > > +/* use the NT native API to create registry key and value that contain > > + a zero character */ > > + > > +#include <ntdef.h> > > +#include <stdio.h> > > +#include <ddk/wdm.h> > > +#include <windef.h> > > + > > +void create_key_value (PHANDLE handle, WCHAR* key, int key_len, WCHAR* > val, int val_len) > > +{ > > + UNICODE_STRING key_name = { key_len, key_len, key }; > > + UNICODE_STRING value_name = { val_len, val_len, val }; > > + OBJECT_ATTRIBUTES key_obj; > > + InitializeObjectAttributes (&key_obj, &key_name, > > + OBJ_OPENIF | OBJ_CASE_INSENSITIVE, > > + *handle, NULL); > > + HANDLE key_handle; > > + NTSTATUS rc; > > + rc = ZwCreateKey (&key_handle, KEY_ALL_ACCESS, &key_obj, > > + 0, NULL, REG_OPTION_NON_VOLATILE, NULL); > > + if (!NT_SUCCESS (rc)) { > > + wprintf(L"error: CreateKey %s: 0x%08x\n", key, rc); > > + exit(1); > > + } > > + DWORD value = 0; > > + rc = ZwSetValueKey (key_handle, &value_name, 0, > > + REG_DWORD, &value, sizeof(value)); > > + if (!NT_SUCCESS (rc)) { > > + wprintf(L"error: SetValueKey %s: 0x%08x\n", val, rc); > > + exit(1); > > + } > > +} > > + > > +int main (int argc, char **argv) > > +{ > > + UNICODE_STRING root_key_name; > > + RtlInitUnicodeString(&root_key_name, L"\\Registry\\Machine\\minimal"); > > + OBJECT_ATTRIBUTES root_key_obj; > > + InitializeObjectAttributes (&root_key_obj, &root_key_name, > > + OBJ_OPENIF | OBJ_CASE_INSENSITIVE, > > + NULL, NULL); > > + HANDLE minimal_key_handle; > > + NTSTATUS rc = ZwCreateKey (&minimal_key_handle, KEY_ALL_ACCESS, > &root_key_obj, > > + 0, NULL, REG_OPTION_NON_VOLATILE, NULL); > > + if (!NT_SUCCESS (rc)) { > > + wprintf(L"error: CreateKey <HKLM\\minimal>: 0x%08x\n", rc); > > + exit(1); > > + } > > + WCHAR k1[] = L"zero\0key"; > > + WCHAR v1[] = L"zero\0val"; > > + create_key_value (&minimal_key_handle, k1, sizeof (k1)-2, v1, sizeof > (v1)-2); > > + WCHAR k2[] = L"abcd_äöüß"; > > + WCHAR v2[] = L"abcd_äöüß"; > > + create_key_value (&minimal_key_handle, k2, sizeof (k2)-2, v2, sizeof > (v2)-2); > > + WCHAR k3[] = L"weird™"; > > + WCHAR v3[] = L"symbols $£₤₧€"; > > + create_key_value (&minimal_key_handle, k3, sizeof (k3)-2, v3, sizeof > (v3)-2); > > + return 0; > > +} > > diff --git a/images/special b/images/special > > new file mode 100644 > > index > 0000000000000000000000000000000000000000..8a5ff5f34f32f0e56c1e1e9abf49bd3a8857c5e7 > > GIT binary patch > > literal 8192 > > zcmeHLziU%b6h28CZ9~<EDAeHa+P=XdxC$;R6s%K4L=cN5X`%@)O-drwio+ZH@elY1 > > z1T2`rMJE?Ghc2Q^L|k-m(@8`sh|ll4H&6SLm(oQjat_>k?mh3^bH4X|uYulX`TDgz > > zDG`p7(@(o+_rFeIDH#kJ*De>1UAJUG&PYj?r7CrdmfVo06fig77i3n-i1}u}f_;>? > > zjGP+lsO=gC@|UkX+cjVmh%%rIC<DrXGN2471ImChpbRJj%D_Kmpi->XO#}RYA6aw{ > > zz<oOm!@8fB{JkG9c{jk=>AfN&T);Y`B1j3jrVo1lAOn3ifxYK>=P%4(oIgHy?h+qw > > z{0hUCkL!iB9c*wEQ%Xi3^76qk9Yqcyo|Z3?<sq4rBiN;I29|L#O>v!_#3aE$JRyH( > > zNWO_9|CAhv)p!5qJ6r3UIMA7Vi#223Jxj!Zzcn_rZY<YO+utKz2fTypy6?txaoMqF > > z)PlzLZB!(`+(*wTH>5K*hWU26*$}_H*6!&MAjUy3vnT>R?oPlTv+vW>W7F#44ACPu > > zM301g!+S!$i6cKz51T)zhm)X3F2=Fd$nk7ld)bvajCbvvcw4^n+1od>xa5E1yT;F1 > > zZMMlz4SCknQ#PT23*zbDz<-2a^~b11fNu2s?5!TFg&Ok$bZx`$RPU7pz4=YDHf<cE > > zP+Tf4e)|6NgNg7jN~BgvO9yAKb|1WY4iGQCdhg#EeB%T7`p;W@vZL?uRsy~p`bYTq > > zJ8={Dh*jJumSlR05Q(E!8To^64$0m1`;7=Eb7&g|Z!U(H@s_ONF0zPQ${N<Lc=AZr > > k-N)_|mrtRG{b8{ios|J)Kp9X5lmTTx8Bhk4f&Y|&-#+)~(*OVf > > > > literal 0 > > HcmV?d00001 > > ACK. > > Rich. > > -- > Richard Jones, Virtualization Group, Red Hat > http://people.redhat.com/~rjones > virt-df lists disk usage of guests without needing to install any > software inside the virtual machine. Supports Linux and Windows. > http://people.redhat.com/~rjones/virt-df/ > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfs >
Possibly Parallel Threads
- [PATCH v3 02/11] appliance: Move /proc/cmdline checks earlier.
- Re: [PATCH v3 02/11] appliance: Move /proc/cmdline checks earlier.
- [PATCH] hivex: A few tweaks to enable building in a separate directory
- [PATCH 1/7] Add a minimal hive with "special" keys and values
- [PATCH 1/3] out of tree build: erlang