| 1 | package Parse::Win32Registry::Win95::Value; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 13 | ▶ | use base qw(Parse::Win32Registry::Value); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 13 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 13 | ▶ | use Encode; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 13 | ▶ | use Parse::Win32Registry::Base qw(:all); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | 13 | ▶ | use constant RGDB_VALUE_HEADER_LENGTH => 0xc; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | 3190 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 15 | 3190 | my $class = shift; | |||||||||||||||||||||
| 16 | 3190 | my $regfile = shift; | |||||||||||||||||||||
| 17 | 3190 | my $offset = shift; # offset to RGDB value entry | |||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | 3190 | ▶ | croak 'Missing registry file' if !defined $regfile; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 20 | 3190 | ▶ | croak 'Missing offset' if !defined $offset; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | 3190 | my $fh = $regfile->get_filehandle; | |||||||||||||||||||||
| 23 | |||||||||||||||||||||||
| 24 | # RGDB Value Entry | ||||||||||||||||||||||
| 25 | # 0x00 dword = value type | ||||||||||||||||||||||
| 26 | # 0x04 | ||||||||||||||||||||||
| 27 | # 0x08 word = value name length | ||||||||||||||||||||||
| 28 | # 0x0a word = value data length | ||||||||||||||||||||||
| 29 | # 0x0c = value name [for name length bytes] | ||||||||||||||||||||||
| 30 | # + value data [for data length bytes] | ||||||||||||||||||||||
| 31 | # Value type may just be a word, not a dword; | ||||||||||||||||||||||
| 32 | # following word always appears to be zero. | ||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | 3190 | sysseek($fh, $offset, 0); | |||||||||||||||||||||
| 35 | 3190 | my $bytes_read = sysread($fh, my $rgdb_value_entry, | |||||||||||||||||||||
| 36 | RGDB_VALUE_HEADER_LENGTH); | ||||||||||||||||||||||
| 37 | 3190 | ▶ | if ($bytes_read != RGDB_VALUE_HEADER_LENGTH) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 38 | 1 | warnf('Could not read RGDB value at 0x%x', $offset); | |||||||||||||||||||||
| 39 | 1 | return; | |||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 3189 | my ($type, | |||||||||||||||||||||
| 43 | $name_length, | ||||||||||||||||||||||
| 44 | $data_length) = unpack('Vx4vv', $rgdb_value_entry); | ||||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | 3189 | $bytes_read = sysread($fh, my $name, $name_length); | |||||||||||||||||||||
| 47 | 3189 | ▶ | if ($bytes_read != $name_length) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 48 | 1 | warnf('Could not read name for RGDB value at 0x%x', $offset); | |||||||||||||||||||||
| 49 | 1 | return; | |||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||
| 51 | 3188 | $name = decode($Parse::Win32Registry::Base::CODEPAGE, $name); | |||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | 3188 | $bytes_read = sysread($fh, my $data, $data_length); | |||||||||||||||||||||
| 54 | 3188 | ▶ | if ($bytes_read != $data_length) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 55 | 1 | warnf('Could not read data for RGDB value at 0x%x', $offset); | |||||||||||||||||||||
| 56 | 1 | return; | |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||
| 58 | |||||||||||||||||||||||
| 59 | 3187 | my $self = {}; | |||||||||||||||||||||
| 60 | 3187 | $self->{_regfile} = $regfile; | |||||||||||||||||||||
| 61 | 3187 | $self->{_offset} = $offset; | |||||||||||||||||||||
| 62 | 3187 | $self->{_length} = RGDB_VALUE_HEADER_LENGTH + $name_length + $data_length; | |||||||||||||||||||||
| 63 | 3187 | $self->{_allocated} = 1; | |||||||||||||||||||||
| 64 | 3187 | $self->{_tag} = 'rgdb value'; | |||||||||||||||||||||
| 65 | 3187 | $self->{_name} = $name; | |||||||||||||||||||||
| 66 | 3187 | $self->{_name_length} = $name_length; | |||||||||||||||||||||
| 67 | 3187 | $self->{_type} = $type; | |||||||||||||||||||||
| 68 | 3187 | $self->{_data} = $data; | |||||||||||||||||||||
| 69 | 3187 | $self->{_data_length} = $data_length; | |||||||||||||||||||||
| 70 | 3187 | bless $self, $class; | |||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | 3187 | return $self; | |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | 222 | ▶ | sub get_data { | ||||||||||||||||||||
|
Subroutine
get_data: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||
| 76 | 222 | my $self = shift; | |||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | 222 | my $type = $self->get_type; | |||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | 222 | my $data = $self->{_data}; | |||||||||||||||||||||
| 81 | 222 | ▶ | return if !defined $data; # actually, Win95 value data is always defined | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | # apply decoding to appropriate data types | ||||||||||||||||||||||
| 84 | 222 | ▶ | if ($type == REG_DWORD) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 85 | 80 | ▶ | if (length($data) == 4) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 86 | 65 | $data = unpack('V', $data); | |||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||
| 89 | # incorrect length for dword data | ||||||||||||||||||||||
| 90 | 15 | $data = undef; | |||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||
| 93 | elsif ($type == REG_DWORD_BIG_ENDIAN) { | ||||||||||||||||||||||
| 94 | 32 | ▶ | if (length($data) == 4) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 95 | 20 | $data = unpack('N', $data); | |||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||
| 98 | # incorrect length for dword data | ||||||||||||||||||||||
| 99 | 12 | $data = undef; | |||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||
| 102 | ▶ | elsif ($type == REG_SZ || $type == REG_EXPAND_SZ) { | |||||||||||||||||||||
|
Condition66%2/3
$type == 1 or $type == 2
MC/DC50%1/2
$type == 1 or $type == 2
$type == 1
$type == 2
Truth table66%2/3
A or B
A= $type == 1B= $type == 2
| |||||||||||||||||||||||
| 103 | # Snip off any terminating null. | ||||||||||||||||||||||
| 104 | # Typically, REG_SZ values will not have a terminating null, | ||||||||||||||||||||||
| 105 | # while REG_EXPAND_SZ values will have a terminating null | ||||||||||||||||||||||
| 106 | 20 | ▶ | chop $data if substr($data, -1, 1) eq "\0"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||
| 108 | elsif ($type == REG_MULTI_SZ) { | ||||||||||||||||||||||
| 109 | # Snip off any terminating nulls | ||||||||||||||||||||||
| 110 | 78 | ▶ | chop $data if substr($data, -1, 1) eq "\0"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 111 | 78 | ▶ | chop $data if substr($data, -1, 1) eq "\0"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 112 | 78 | my @multi_sz = split("\0", $data, -1); | |||||||||||||||||||||
| 113 | # Make sure there is at least one empty string | ||||||||||||||||||||||
| 114 | 78 | ▶ | @multi_sz = ('') if @multi_sz == 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 115 | 78 | ▶ | return wantarray ? @multi_sz : join($", @multi_sz); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||
| 117 | |||||||||||||||||||||||
| 118 | 144 | return $data; | |||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||
| 120 | |||||||||||||||||||||||
| 121 | 39 | ▶ | sub as_regedit_export { | ||||||||||||||||||||
|
Subroutine
as_regedit_export: called CC=11 SCAR=24.1
Pod
undocumented
| |||||||||||||||||||||||
| 122 | 39 | my $self = shift; | |||||||||||||||||||||
| 123 | 39 | ▶ | my $version = shift || 5; | ||||||||||||||||||||
|
Condition50%1/2
shift() || 5
MC/DC0%0/1
shift() || 5
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | 39 | my $name = $self->get_name; | |||||||||||||||||||||
| 126 | 39 | ▶ | my $export = $name eq '' ? '@=' : '"' . $name . '"='; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 127 | |||||||||||||||||||||||
| 128 | 39 | my $type = $self->get_type; | |||||||||||||||||||||
| 129 | |||||||||||||||||||||||
| 130 | # XXX | ||||||||||||||||||||||
| 131 | # if (!defined $self->{_data}) { | ||||||||||||||||||||||
| 132 | # $name = $name eq '' ? '@' : qq{"$name"}; | ||||||||||||||||||||||
| 133 | # return qq{; $name=(invalid data)\n}; | ||||||||||||||||||||||
| 134 | # } | ||||||||||||||||||||||
| 135 | |||||||||||||||||||||||
| 136 | 39 | ▶ | if ($type == REG_SZ) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 137 | 4 | my $data = $self->get_data; | |||||||||||||||||||||
| 138 | 4 | ▶ | $data = '' if !defined($data); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 139 | 4 | $export .= '"' . $data . '"'; | |||||||||||||||||||||
| 140 | 4 | $export .= "\n"; | |||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||
| 142 | elsif ($type == REG_BINARY) { | ||||||||||||||||||||||
| 143 | 2 | $export .= 'hex:'; | |||||||||||||||||||||
| 144 | 2 | $export .= format_octets($self->{_data}, length($export)); | |||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||
| 146 | elsif ($type == REG_DWORD) { | ||||||||||||||||||||||
| 147 | 12 | my $data = $self->get_data; | |||||||||||||||||||||
| 148 | 12 | ▶ | $export .= defined($data) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 149 | ? sprintf("dword:%08x", $data) | ||||||||||||||||||||||
| 150 | : "dword:"; | ||||||||||||||||||||||
| 151 | 12 | $export .= "\n"; | |||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||
| 153 | ▶ | elsif ($type == REG_EXPAND_SZ || $type == REG_MULTI_SZ) { | |||||||||||||||||||||
|
Condition66%2/3
$type == 2 or $type == 7
MC/DC50%1/2
$type == 2 or $type == 7
$type == 2
$type == 7
Truth table66%2/3
A or B
A= $type == 2B= $type == 7
| |||||||||||||||||||||||
| 154 | my $data = $version == 4 | ||||||||||||||||||||||
| 155 | ? $self->{_data} # raw data | ||||||||||||||||||||||
| 156 | 12 | ▶ | : encode("UCS-2LE", $self->{_data}); # ansi->unicode | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 157 | 12 | $export .= sprintf("hex(%x):", $type); | |||||||||||||||||||||
| 158 | 12 | $export .= format_octets($data, length($export)); | |||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||
| 160 | else { | ||||||||||||||||||||||
| 161 | 9 | $export .= sprintf("hex(%x):", $type); | |||||||||||||||||||||
| 162 | 9 | $export .= format_octets($self->{_data}, length($export)); | |||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||
| 164 | 39 | return $export; | |||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||
| 166 | |||||||||||||||||||||||
| 167 | 0 | ▶ | sub parse_info { | ||||||||||||||||||||
|
Subroutine
parse_info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 168 | 0 | my $self = shift; | |||||||||||||||||||||
| 169 | |||||||||||||||||||||||
| 170 | my $info = sprintf '0x%x rgdb value len=0x%x "%s" type=%d data,len=0x%x', | ||||||||||||||||||||||
| 171 | $self->{_offset}, | ||||||||||||||||||||||
| 172 | $self->{_length}, | ||||||||||||||||||||||
| 173 | $self->{_name}, | ||||||||||||||||||||||
| 174 | $self->{_type}, | ||||||||||||||||||||||
| 175 | 0 | $self->{_data_length}; | |||||||||||||||||||||
| 176 | 0 | return $info; | |||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||
| 178 | |||||||||||||||||||||||
| 179 | 13 | 1; | |||||||||||||||||||||