Richard W.M. Jones
2010-Apr-28 13:32 UTC
[Libguestfs] [PATCH hivex] regedit: Add implicit nul-termination when importing strings.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html -------------- next part -------------->From 81cc08b749bde37f364400c2b983d1e73e8dde21 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Wed, 28 Apr 2010 14:28:27 +0100 Subject: [PATCH] regedit: Add implicit nul-termination when importing strings. When you import a string value like: "Foo"="Bar" using Windows regedit program, implicit nul-termination is added to the value (not the key), so what is stored in the value would be something like: hex(1):42,00,61,00,72,00,00,00 where two of the trailing zero bytes come from the implicit terminator. This corrects the reg_import function so it works the same way. --- perl/lib/Win/Hivex/Regedit.pm | 3 +++ perl/t/560-regedit-import.t | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/perl/lib/Win/Hivex/Regedit.pm b/perl/lib/Win/Hivex/Regedit.pm index 871e5ba..c69fda8 100644 --- a/perl/lib/Win/Hivex/Regedit.pm +++ b/perl/lib/Win/Hivex/Regedit.pm @@ -285,16 +285,19 @@ sub _parse_value $type = 1; $data = _parse_quoted_string ($1); return undef unless defined $data; + $data .= "\0"; # Value strings are implicitly ASCIIZ. $data = encode ($encoding, $data); } elsif (m/^str\(([[:xdigit:]]+)\):(".*")$/) { $type = hex ($1); $data = _parse_quoted_string ($2); return undef unless defined $data; + $data .= "\0"; # Value strings are implicitly ASCIIZ. $data = encode ($encoding, $data); } elsif (m/^(".*")$/) { $type = 1; $data = _parse_quoted_string ($1); return undef unless defined $data; + $data .= "\0"; # Value strings are implicitly ASCIIZ. $data = encode ($encoding, $data); } else { return undef; diff --git a/perl/t/560-regedit-import.t b/perl/t/560-regedit-import.t index b0c5254..163a46e 100644 --- a/perl/t/560-regedit-import.t +++ b/perl/t/560-regedit-import.t @@ -55,7 +55,7 @@ $expected = '[\] [\C] "Key1"=hex(2):48,00,65,00,6c,00,6c,00,6f,00 -"Key2"=hex(2):48,00,65,00,6c,00,6c,00,6f,00 +"Key2"=hex(2):48,00,65,00,6c,00,6c,00,6f,00,00,00 "Key3"=hex(3):48,00,65,00,6c,00,6c,00,6f,00,48,00,65,00,6c,00,6c,00,6f,00 "Key4"=dword:ff123456 @@ -72,11 +72,11 @@ $data = ' $expected = '[\] [\A] -@=hex(1):48,00,65,00,6c,00,6c,00,6f,00 +@=hex(1):48,00,65,00,6c,00,6c,00,6f,00,00,00 [\C] "Key1"=hex(2):48,00,65,00,6c,00,6c,00,6f,00 -"Key2"=hex(2):48,00,65,00,6c,00,6c,00,6f,00 +"Key2"=hex(2):48,00,65,00,6c,00,6c,00,6f,00,00,00 "Key3"=hex(3):48,00,65,00,6c,00,6c,00,6f,00,48,00,65,00,6c,00,6c,00,6f,00 "Key4"=dword:ff123456 -- 1.6.6.1
Matthew Booth
2010-Apr-28 13:58 UTC
[Libguestfs] [PATCH hivex] regedit: Add implicit nul-termination when importing strings.
On 28/04/10 14:32, Richard W.M. Jones wrote:>>From 81cc08b749bde37f364400c2b983d1e73e8dde21 Mon Sep 17 00:00:00 2001 > From: Richard Jones <rjones at redhat.com> > Date: Wed, 28 Apr 2010 14:28:27 +0100 > Subject: [PATCH] regedit: Add implicit nul-termination when importing strings. > > When you import a string value like: > "Foo"="Bar" > using Windows regedit program, implicit nul-termination is added > to the value (not the key), so what is stored in the value would > be something like: > hex(1):42,00,61,00,72,00,00,00 > where two of the trailing zero bytes come from the implicit > terminator. This corrects the reg_import function so it works > the same way. > --- > perl/lib/Win/Hivex/Regedit.pm | 3 +++ > perl/t/560-regedit-import.t | 6 +++--- > 2 files changed, 6 insertions(+), 3 deletions(-)Tested this against both win2k3 and win2k8. Worked fine. ACK. Matt -- Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team M: +44 (0)7977 267231 GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
Richard W.M. Jones
2010-Apr-28 14:03 UTC
[Libguestfs] [PATCH hivex] regedit: Add implicit nul-termination when importing strings.
ACKed by Matt on IRC. I'm going to push this now and make a new upstream release of hivex. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
Reasonably Related Threads
- [PATCH v4 0/5] hivex: handle corrupted hives better.
- [PATCH hivex 02/14] maint: remove unnecessary test-before-free
- [PATCH 0/3] Export and merge into Windows Registry
- [PATCH 0/1] hivexregedit: add --max-depth option for exports
- [PATCH 2/2] Win::Hivex::Regedit: Ignore comments