| 1 | package Parse::Win32Registry::WinNT::Key; | ||||||||||||||||||||||||||||||||
| 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::Key); | ||||||||||||||||||||||||||||||
|
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 | 13 | ▶ | use Parse::Win32Registry::WinNT::Value; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Parse::Win32Registry::WinNT::Security; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 13 | ▶ | use constant NK_HEADER_LENGTH => 0x50; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use constant OFFSET_TO_FIRST_HBIN => 0x1000; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 452 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=17 SCAR=28.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 18 | 452 | my $class = shift; | |||||||||||||||||||||||||||||||
| 19 | 452 | my $regfile = shift; | |||||||||||||||||||||||||||||||
| 20 | 452 | my $offset = shift; # offset to nk record relative to start of file | |||||||||||||||||||||||||||||||
| 21 | 452 | my $parent_key_path = shift; # parent key path (optional) | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 452 | ▶ | croak 'Missing registry file' if !defined $regfile; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | 452 | ▶ | croak 'Missing offset' if !defined $offset; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 452 | my $fh = $regfile->get_filehandle; | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | # 0x00 dword = key length (negative = allocated) | ||||||||||||||||||||||||||||||||
| 29 | # 0x04 word = 'nk' signature | ||||||||||||||||||||||||||||||||
| 30 | # 0x06 word = flags | ||||||||||||||||||||||||||||||||
| 31 | # 0x08 qword = timestamp | ||||||||||||||||||||||||||||||||
| 32 | # 0x10 | ||||||||||||||||||||||||||||||||
| 33 | # 0x14 dword = offset to parent | ||||||||||||||||||||||||||||||||
| 34 | # 0x18 dword = number of subkeys | ||||||||||||||||||||||||||||||||
| 35 | # 0x1c | ||||||||||||||||||||||||||||||||
| 36 | # 0x20 dword = offset to subkey list (lf, lh, ri, li) | ||||||||||||||||||||||||||||||||
| 37 | # 0x24 | ||||||||||||||||||||||||||||||||
| 38 | # 0x28 dword = number of values | ||||||||||||||||||||||||||||||||
| 39 | # 0x2c dword = offset to value list | ||||||||||||||||||||||||||||||||
| 40 | # 0x30 dword = offset to security | ||||||||||||||||||||||||||||||||
| 41 | # 0x34 dword = offset to class name | ||||||||||||||||||||||||||||||||
| 42 | # 0x38 dword = max subkey name length | ||||||||||||||||||||||||||||||||
| 43 | # 0x3c dword = max class name length | ||||||||||||||||||||||||||||||||
| 44 | # 0x40 dword = max value name length | ||||||||||||||||||||||||||||||||
| 45 | # 0x44 dword = max value data length | ||||||||||||||||||||||||||||||||
| 46 | # 0x48 | ||||||||||||||||||||||||||||||||
| 47 | # 0x4c word = key name length | ||||||||||||||||||||||||||||||||
| 48 | # 0x4e word = class name length | ||||||||||||||||||||||||||||||||
| 49 | # 0x50 = key name [for key name length bytes] | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | # Extracted offsets are always relative to first hbin | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 452 | sysseek($fh, $offset, 0); | |||||||||||||||||||||||||||||||
| 54 | 452 | my $bytes_read = sysread($fh, my $nk_header, NK_HEADER_LENGTH); | |||||||||||||||||||||||||||||||
| 55 | 452 | ▶ | if ($bytes_read != NK_HEADER_LENGTH) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | 1 | warnf('Could not read key at 0x%x', $offset); | |||||||||||||||||||||||||||||||
| 57 | 1 | return; | |||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 451 | my ($length, | |||||||||||||||||||||||||||||||
| 61 | $sig, | ||||||||||||||||||||||||||||||||
| 62 | $flags, | ||||||||||||||||||||||||||||||||
| 63 | $timestamp, | ||||||||||||||||||||||||||||||||
| 64 | $offset_to_parent, | ||||||||||||||||||||||||||||||||
| 65 | $num_subkeys, | ||||||||||||||||||||||||||||||||
| 66 | $offset_to_subkey_list, | ||||||||||||||||||||||||||||||||
| 67 | $num_values, | ||||||||||||||||||||||||||||||||
| 68 | $offset_to_value_list, | ||||||||||||||||||||||||||||||||
| 69 | $offset_to_security, | ||||||||||||||||||||||||||||||||
| 70 | $offset_to_class_name, | ||||||||||||||||||||||||||||||||
| 71 | $name_length, | ||||||||||||||||||||||||||||||||
| 72 | $class_name_length, | ||||||||||||||||||||||||||||||||
| 73 | ) = unpack('Va2va8x4VVx4Vx4VVVVx20vv', $nk_header); | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 451 | ▶ | $offset_to_parent += OFFSET_TO_FIRST_HBIN | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 76 | if $offset_to_parent != 0xffffffff; | ||||||||||||||||||||||||||||||||
| 77 | 451 | ▶ | $offset_to_subkey_list += OFFSET_TO_FIRST_HBIN | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | if $offset_to_subkey_list != 0xffffffff; | ||||||||||||||||||||||||||||||||
| 79 | 451 | ▶ | $offset_to_value_list += OFFSET_TO_FIRST_HBIN | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | if $offset_to_value_list != 0xffffffff; | ||||||||||||||||||||||||||||||||
| 81 | 451 | ▶ | $offset_to_security += OFFSET_TO_FIRST_HBIN | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | if $offset_to_security != 0xffffffff; | ||||||||||||||||||||||||||||||||
| 83 | 451 | ▶ | $offset_to_class_name += OFFSET_TO_FIRST_HBIN | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | if $offset_to_class_name != 0xffffffff; | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 451 | my $allocated = 0; | |||||||||||||||||||||||||||||||
| 87 | 451 | ▶ | if ($length > 0x7fffffff) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 88 | 451 | $allocated = 1; | |||||||||||||||||||||||||||||||
| 89 | 451 | $length = (0xffffffff - $length) + 1; | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | # allocated should be true | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 451 | ▶ | if ($length < NK_HEADER_LENGTH) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 0 | warnf('Invalid value entry length at 0x%x', $offset); | |||||||||||||||||||||||||||||||
| 95 | 0 | return; | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 451 | ▶ | if ($sig ne 'nk') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | 1 | warnf('Invalid signature for key at 0x%x', $offset); | |||||||||||||||||||||||||||||||
| 100 | 1 | return; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 450 | $bytes_read = sysread($fh, my $name, $name_length); | |||||||||||||||||||||||||||||||
| 104 | 450 | ▶ | if ($bytes_read != $name_length) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | 1 | warnf('Could not read name for key at 0x%x', $offset); | |||||||||||||||||||||||||||||||
| 106 | 1 | return; | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 449 | ▶ | if ($flags & 0x20) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 110 | 436 | $name = decode($Parse::Win32Registry::Base::CODEPAGE, $name); | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | else { | ||||||||||||||||||||||||||||||||
| 113 | 13 | $name = decode('UCS-2LE', $name); | |||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 449 | ▶ | my $key_path = (defined $parent_key_path) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 117 | ? "$parent_key_path\\$name" | ||||||||||||||||||||||||||||||||
| 118 | : "$name"; | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 449 | my $class_name; | |||||||||||||||||||||||||||||||
| 121 | 449 | ▶ | if ($offset_to_class_name != 0xffffffff) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | 231 | sysseek($fh, $offset_to_class_name + 4, 0); | |||||||||||||||||||||||||||||||
| 123 | 231 | $bytes_read = sysread($fh, $class_name, $class_name_length); | |||||||||||||||||||||||||||||||
| 124 | 231 | ▶ | if ($bytes_read != $class_name_length) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 125 | 1 | warnf('Could not read class name at 0x%x', $offset_to_class_name); | |||||||||||||||||||||||||||||||
| 126 | 1 | $class_name = undef; | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | else { | ||||||||||||||||||||||||||||||||
| 129 | 230 | $class_name = decode('UCS-2LE', $class_name); | |||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 449 | my $self = {}; | |||||||||||||||||||||||||||||||
| 134 | 449 | $self->{_regfile} = $regfile; | |||||||||||||||||||||||||||||||
| 135 | 449 | $self->{_offset} = $offset; | |||||||||||||||||||||||||||||||
| 136 | 449 | $self->{_length} = $length; | |||||||||||||||||||||||||||||||
| 137 | 449 | $self->{_allocated} = $allocated; | |||||||||||||||||||||||||||||||
| 138 | 449 | $self->{_tag} = $sig; | |||||||||||||||||||||||||||||||
| 139 | 449 | $self->{_name} = $name; | |||||||||||||||||||||||||||||||
| 140 | 449 | $self->{_name_length} = $name_length; | |||||||||||||||||||||||||||||||
| 141 | 449 | $self->{_key_path} = $key_path; | |||||||||||||||||||||||||||||||
| 142 | 449 | $self->{_flags} = $flags; | |||||||||||||||||||||||||||||||
| 143 | 449 | $self->{_offset_to_parent} = $offset_to_parent; | |||||||||||||||||||||||||||||||
| 144 | 449 | $self->{_num_subkeys} = $num_subkeys; | |||||||||||||||||||||||||||||||
| 145 | 449 | $self->{_offset_to_subkey_list} = $offset_to_subkey_list; | |||||||||||||||||||||||||||||||
| 146 | 449 | $self->{_num_values} = $num_values; | |||||||||||||||||||||||||||||||
| 147 | 449 | $self->{_offset_to_value_list} = $offset_to_value_list; | |||||||||||||||||||||||||||||||
| 148 | 449 | $self->{_timestamp} = unpack_windows_time($timestamp); | |||||||||||||||||||||||||||||||
| 149 | 449 | $self->{_offset_to_security} = $offset_to_security; | |||||||||||||||||||||||||||||||
| 150 | 449 | $self->{_offset_to_class_name} = $offset_to_class_name; | |||||||||||||||||||||||||||||||
| 151 | 449 | $self->{_class_name_length} = $class_name_length; | |||||||||||||||||||||||||||||||
| 152 | 449 | $self->{_class_name} = $class_name; | |||||||||||||||||||||||||||||||
| 153 | 449 | bless $self, $class; | |||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 449 | return $self; | |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | 112 | ▶ | sub get_timestamp { | ||||||||||||||||||||||||||||||
|
Subroutine
get_timestamp: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 159 | 112 | my $self = shift; | |||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 112 | return $self->{_timestamp}; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | 78 | ▶ | sub get_timestamp_as_string { | ||||||||||||||||||||||||||||||
|
Subroutine
get_timestamp_as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 165 | 78 | my $self = shift; | |||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | 78 | return iso8601($self->get_timestamp); | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 19 | ▶ | sub get_class_name { | ||||||||||||||||||||||||||||||
|
Subroutine
get_class_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 171 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | 19 | return $self->{_class_name}; | |||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | 225 | ▶ | sub is_root { | ||||||||||||||||||||||||||||||
|
Subroutine
is_root: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 177 | 225 | my $self = shift; | |||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | 225 | my $flags = $self->{_flags}; | |||||||||||||||||||||||||||||||
| 180 | 225 | ▶ | return $flags & 4 || $flags & 8; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$flags & 4 || $flags & 8
MC/DC50%1/2
$flags & 4 || $flags & 8
$flags & 4
$flags & 8
Truth table66%2/3
A || B
A= $flags & 4B= $flags & 8
| |||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | 91 | ▶ | sub get_parent { | ||||||||||||||||||||||||||||||
|
Subroutine
get_parent: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 184 | 91 | my $self = shift; | |||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | 91 | my $regfile = $self->{_regfile}; | |||||||||||||||||||||||||||||||
| 187 | 91 | my $offset_to_parent = $self->{_offset_to_parent}; | |||||||||||||||||||||||||||||||
| 188 | 91 | my $key_path = $self->{_key_path}; | |||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | 91 | ▶ | return if $self->is_root; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 91 | my $grandparent_key_path; | |||||||||||||||||||||||||||||||
| 193 | 91 | my @keys = split /\\/, $key_path, -1; | |||||||||||||||||||||||||||||||
| 194 | 91 | ▶ | if (@keys > 2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 195 | 30 | $grandparent_key_path = join('\\', @keys[0..$#keys-2]); | |||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | 91 | return Parse::Win32Registry::WinNT::Key->new($regfile, | |||||||||||||||||||||||||||||||
| 199 | $offset_to_parent, | ||||||||||||||||||||||||||||||||
| 200 | $grandparent_key_path); | ||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | sub get_security { | ||||||||||||||||||||||||||||||
|
Subroutine
get_security: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 204 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 1 | my $regfile = $self->{_regfile}; | |||||||||||||||||||||||||||||||
| 207 | 1 | my $offset_to_security = $self->{_offset_to_security}; | |||||||||||||||||||||||||||||||
| 208 | 1 | my $key_path = $self->{_key_path}; | |||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 1 | ▶ | if ($offset_to_security == 0xffffffff) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 211 | 0 | return; | |||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | 1 | return Parse::Win32Registry::WinNT::Security->new($regfile, | |||||||||||||||||||||||||||||||
| 215 | $offset_to_security, | ||||||||||||||||||||||||||||||||
| 216 | $key_path); | ||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | 42 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 220 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||
| 222 | 42 | my $string = $self->get_path . ' [' . $self->get_timestamp_as_string . ']'; | |||||||||||||||||||||||||||||||
| 223 | 42 | return $string; | |||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | sub parse_info { | ||||||||||||||||||||||||||||||
|
Subroutine
parse_info: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 227 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | my $info = sprintf '0x%x nk len=0x%x alloc=%d "%s" par=0x%x keys=%d,0x%x vals=%d,0x%x sec=0x%x class=0x%x', | ||||||||||||||||||||||||||||||||
| 230 | $self->{_offset}, | ||||||||||||||||||||||||||||||||
| 231 | $self->{_length}, | ||||||||||||||||||||||||||||||||
| 232 | $self->{_allocated}, | ||||||||||||||||||||||||||||||||
| 233 | $self->{_name}, | ||||||||||||||||||||||||||||||||
| 234 | $self->{_offset_to_parent}, | ||||||||||||||||||||||||||||||||
| 235 | $self->{_num_subkeys}, $self->{_offset_to_subkey_list}, | ||||||||||||||||||||||||||||||||
| 236 | $self->{_num_values}, $self->{_offset_to_value_list}, | ||||||||||||||||||||||||||||||||
| 237 | $self->{_offset_to_security}, | ||||||||||||||||||||||||||||||||
| 238 | 0 | $self->{_offset_to_class_name}; | |||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if (defined $self->{_class_name}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 240 | 0 | $info .= sprintf ',len=0x%x', $self->{_class_name_length}; | |||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||
| 242 | 0 | return $info; | |||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | 233 | ▶ | sub _get_offsets_to_subkeys { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_offsets_to_subkeys: called CC=20 SCAR=30.3
| |||||||||||||||||||||||||||||||||
| 246 | 233 | my $self = shift; | |||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | # Offset is passed as a parameter for recursive lists such as 'ri' | ||||||||||||||||||||||||||||||||
| 249 | 233 | ▶ | my $offset_to_subkey_list = shift || $self->{_offset_to_subkey_list}; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self->{'_offset_to_subkey_list'}
MC/DC0%0/2
shift() || $self->{'_offset_to_subkey_list'}
shift()
$self->{'_offset_to_subkey_list'}
Truth table66%2/3
A || B
A= shift()B= $self->{'_offset_to_subkey_list'}
| |||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | 233 | my $regfile = $self->{_regfile}; | |||||||||||||||||||||||||||||||
| 252 | 233 | my $fh = $regfile->get_filehandle; | |||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | return if $offset_to_subkey_list == 0xffffffff | ||||||||||||||||||||||||||||||||
| 255 | 233 | ▶ | || $self->{_num_subkeys} == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$offset_to_subkey_list == 4294967295 or $self->{"_num_subkeys"} == 0
MC/DC0%0/2
$offset_to_subkey_list == 4294967295 or $self->{"_num_subkeys"} == 0
$offset_to_subkey_list == 4294967295
$self->{"_num_subkeys"} == 0
Truth table33%1/3
A or B
A= $offset_to_subkey_list == 4294967295B= $self->{"_num_subkeys"} == 0
| |||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||
| 257 | 233 | sysseek($fh, $offset_to_subkey_list, 0); | |||||||||||||||||||||||||||||||
| 258 | 233 | my $bytes_read = sysread($fh, my $subkey_list_header, 8); | |||||||||||||||||||||||||||||||
| 259 | 233 | ▶ | if ($bytes_read != 8) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 260 | 1 | warnf('Could not read subkey list header at 0x%x', | |||||||||||||||||||||||||||||||
| 261 | $offset_to_subkey_list); | ||||||||||||||||||||||||||||||||
| 262 | 1 | return; | |||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | # 0x00 dword = subkey list length (negative = allocated) | ||||||||||||||||||||||||||||||||
| 266 | # 0x04 word = 'lf' signature | ||||||||||||||||||||||||||||||||
| 267 | # 0x06 word = number of entries | ||||||||||||||||||||||||||||||||
| 268 | # 0x08 dword = offset to 1st subkey | ||||||||||||||||||||||||||||||||
| 269 | # 0x0c dword = first four characters of the key name | ||||||||||||||||||||||||||||||||
| 270 | # 0x10 dword = offset to 2nd subkey | ||||||||||||||||||||||||||||||||
| 271 | # 0x14 dword = first four characters of the key name | ||||||||||||||||||||||||||||||||
| 272 | # ... | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | # 0x00 dword = subkey list length (negative = allocated) | ||||||||||||||||||||||||||||||||
| 275 | # 0x04 word = 'lh' signature | ||||||||||||||||||||||||||||||||
| 276 | # 0x06 word = number of entries | ||||||||||||||||||||||||||||||||
| 277 | # 0x08 dword = offset to 1st subkey | ||||||||||||||||||||||||||||||||
| 278 | # 0x0c dword = hash of the key name | ||||||||||||||||||||||||||||||||
| 279 | # 0x10 dword = offset to 2nd subkey | ||||||||||||||||||||||||||||||||
| 280 | # 0x14 dword = hash of the key name | ||||||||||||||||||||||||||||||||
| 281 | # ... | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | # 0x00 dword = subkey list length (negative = allocated) | ||||||||||||||||||||||||||||||||
| 284 | # 0x04 word = 'ri' signature | ||||||||||||||||||||||||||||||||
| 285 | # 0x06 word = number of entries in ri list | ||||||||||||||||||||||||||||||||
| 286 | # 0x08 dword = offset to 1st lf/lh/li list | ||||||||||||||||||||||||||||||||
| 287 | # 0x0c dword = offset to 2nd lf/lh/li list | ||||||||||||||||||||||||||||||||
| 288 | # 0x10 dword = offset to 3rd lf/lh/li list | ||||||||||||||||||||||||||||||||
| 289 | # ... | ||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | # 0x00 dword = subkey list length (negative = allocated) | ||||||||||||||||||||||||||||||||
| 292 | # 0x04 word = 'li' signature | ||||||||||||||||||||||||||||||||
| 293 | # 0x06 word = number of entries in li list | ||||||||||||||||||||||||||||||||
| 294 | # 0x08 dword = offset to 1st subkey | ||||||||||||||||||||||||||||||||
| 295 | # 0x0c dword = offset to 2nd subkey | ||||||||||||||||||||||||||||||||
| 296 | # ... | ||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||
| 298 | # Extracted offsets are always relative to first hbin | ||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | 232 | my @offsets_to_subkeys = (); | |||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | 232 | my ($length, | |||||||||||||||||||||||||||||||
| 303 | $sig, | ||||||||||||||||||||||||||||||||
| 304 | $num_entries, | ||||||||||||||||||||||||||||||||
| 305 | ) = unpack('Va2v', $subkey_list_header); | ||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||
| 307 | 232 | my $subkey_list_length; | |||||||||||||||||||||||||||||||
| 308 | 232 | ▶ | if ($sig eq 'lf' || $sig eq 'lh') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$sig eq "lf" or $sig eq "lh"
MC/DC100%2/2
$sig eq "lf" or $sig eq "lh"
$sig eq "lf"
$sig eq "lh"
Truth table100%3/3
A or B
A= $sig eq "lf"B= $sig eq "lh"
| |||||||||||||||||||||||||||||||||
| 309 | 143 | $subkey_list_length = 2 * 4 * $num_entries; | |||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||
| 311 | ▶ | elsif ($sig eq 'ri' || $sig eq 'li') { | |||||||||||||||||||||||||||||||
|
Condition100%3/3
$sig eq "ri" or $sig eq "li"
MC/DC100%2/2
$sig eq "ri" or $sig eq "li"
$sig eq "ri"
$sig eq "li"
Truth table100%3/3
A or B
A= $sig eq "ri"B= $sig eq "li"
| |||||||||||||||||||||||||||||||||
| 312 | 88 | $subkey_list_length = 4 * $num_entries; | |||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||
| 314 | else { | ||||||||||||||||||||||||||||||||
| 315 | 1 | warnf('Invalid signature for subkey list at 0x%x', | |||||||||||||||||||||||||||||||
| 316 | $offset_to_subkey_list); | ||||||||||||||||||||||||||||||||
| 317 | 1 | return; | |||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | 231 | $bytes_read = sysread($fh, my $subkey_list, $subkey_list_length); | |||||||||||||||||||||||||||||||
| 321 | 231 | ▶ | if ($bytes_read != $subkey_list_length) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 322 | 1 | warnf('Could not read subkey list at 0x%x', | |||||||||||||||||||||||||||||||
| 323 | $offset_to_subkey_list); | ||||||||||||||||||||||||||||||||
| 324 | 1 | return; | |||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||
| 327 | 230 | ▶ | if ($sig eq 'lf') { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 328 | 112 | foreach my $offset (unpack("(Vx4)$num_entries", $subkey_list)) { | |||||||||||||||||||||||||||||||
| 329 | 378 | push @offsets_to_subkeys, OFFSET_TO_FIRST_HBIN + $offset; | |||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||
| 332 | elsif ($sig eq 'lh') { | ||||||||||||||||||||||||||||||||
| 333 | 30 | foreach my $offset (unpack("(Vx4)$num_entries", $subkey_list)) { | |||||||||||||||||||||||||||||||
| 334 | 72 | push @offsets_to_subkeys, OFFSET_TO_FIRST_HBIN + $offset; | |||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||
| 337 | elsif ($sig eq 'ri') { | ||||||||||||||||||||||||||||||||
| 338 | 26 | foreach my $offset (unpack("V$num_entries", $subkey_list)) { | |||||||||||||||||||||||||||||||
| 339 | 52 | my $offsets_ref = | |||||||||||||||||||||||||||||||
| 340 | $self->_get_offsets_to_subkeys(OFFSET_TO_FIRST_HBIN + $offset); | ||||||||||||||||||||||||||||||||
| 341 | 52 | ▶ | if (defined $offsets_ref && ref $offsets_ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $offsets_ref and ref $offsets_ref eq "ARRAY"
MC/DC0%0/2
defined $offsets_ref and ref $offsets_ref eq "ARRAY"
defined $offsets_ref
ref $offsets_ref eq "ARRAY"
Truth table33%1/3
A and B
A= defined $offsets_refB= ref $offsets_ref eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 342 | 52 | push @offsets_to_subkeys, @{ $offsets_ref }; | |||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||
| 346 | elsif ($sig eq 'li') { | ||||||||||||||||||||||||||||||||
| 347 | 62 | foreach my $offset (unpack("V$num_entries", $subkey_list)) { | |||||||||||||||||||||||||||||||
| 348 | 176 | push @offsets_to_subkeys, OFFSET_TO_FIRST_HBIN + $offset; | |||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | 230 | return \@offsets_to_subkeys; | |||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | 135 | ▶ | sub get_subkey_iterator { | ||||||||||||||||||||||||||||||
|
Subroutine
get_subkey_iterator: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 356 | 135 | my $self = shift; | |||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||
| 358 | 135 | my $regfile = $self->{_regfile}; | |||||||||||||||||||||||||||||||
| 359 | 135 | my $key_path = $self->{_key_path}; | |||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||
| 361 | 135 | my @offsets_to_subkeys = (); | |||||||||||||||||||||||||||||||
| 362 | 135 | ▶ | if ($self->{_num_subkeys} > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 363 | 92 | my $offsets_to_subkeys_ref = $self->_get_offsets_to_subkeys; | |||||||||||||||||||||||||||||||
| 364 | 92 | ▶ | if (defined $offsets_to_subkeys_ref) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 365 | 89 | @offsets_to_subkeys = @{$self->_get_offsets_to_subkeys}; | |||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | 448 | ▶ | return Parse::Win32Registry::Iterator->new(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 370 | 448 | ▶ | while (defined(my $offset_to_subkey = shift @offsets_to_subkeys)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 371 | 313 | my $subkey = Parse::Win32Registry::WinNT::Key->new($regfile, | |||||||||||||||||||||||||||||||
| 372 | $offset_to_subkey, $key_path); | ||||||||||||||||||||||||||||||||
| 373 | 313 | ▶ | if (defined $subkey) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 374 | 313 | return $subkey; | |||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||
| 377 | 135 | return; # no more offsets to subkeys | |||||||||||||||||||||||||||||||
| 378 | 135 | }); | |||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||
| 381 | 289 | ▶ | sub _get_offsets_to_values { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_offsets_to_values: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 382 | 289 | my $self = shift; | |||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||
| 384 | 289 | my $regfile = $self->{_regfile}; | |||||||||||||||||||||||||||||||
| 385 | 289 | my $fh = $regfile->get_filehandle; | |||||||||||||||||||||||||||||||
| 386 | 289 | my $offset_to_value_list = $self->{_offset_to_value_list}; | |||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||
| 388 | 289 | my $num_values = $self->{_num_values}; | |||||||||||||||||||||||||||||||
| 389 | 289 | ▶ | return if $num_values == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 390 | # Actually, this could probably just fall through | ||||||||||||||||||||||||||||||||
| 391 | # as unpack("x4V0", ...) would return an empty array. | ||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||
| 393 | 289 | my @offsets_to_values = (); | |||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | # 0x00 dword = value list length (negative = allocated) | ||||||||||||||||||||||||||||||||
| 396 | # 0x04 dword = 1st offset | ||||||||||||||||||||||||||||||||
| 397 | # 0x08 dword = 2nd offset | ||||||||||||||||||||||||||||||||
| 398 | # ... | ||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||
| 400 | # Extracted offsets are always relative to first hbin | ||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||
| 402 | 289 | sysseek($fh, $offset_to_value_list, 0); | |||||||||||||||||||||||||||||||
| 403 | 289 | my $value_list_length = 0x4 + $num_values * 4; | |||||||||||||||||||||||||||||||
| 404 | 289 | my $bytes_read = sysread($fh, my $value_list, $value_list_length); | |||||||||||||||||||||||||||||||
| 405 | 289 | ▶ | if ($bytes_read != $value_list_length) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 406 | 1 | warnf("Could not read value list at 0x%x", | |||||||||||||||||||||||||||||||
| 407 | $offset_to_value_list); | ||||||||||||||||||||||||||||||||
| 408 | 1 | return; | |||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||
| 411 | 288 | foreach my $offset (unpack("x4V$num_values", $value_list)) { | |||||||||||||||||||||||||||||||
| 412 | 12246 | push @offsets_to_values, OFFSET_TO_FIRST_HBIN + $offset; | |||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||
| 415 | 288 | return \@offsets_to_values; | |||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||
| 418 | 174 | ▶ | sub get_value_iterator { | ||||||||||||||||||||||||||||||
|
Subroutine
get_value_iterator: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 419 | 174 | my $self = shift; | |||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||
| 421 | 174 | my $regfile = $self->{_regfile}; | |||||||||||||||||||||||||||||||
| 422 | 174 | my $key_path = $self->{_key_path}; | |||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||
| 424 | 174 | my @offsets_to_values = (); | |||||||||||||||||||||||||||||||
| 425 | 174 | ▶ | if ($self->{_num_values} > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 426 | 145 | my $offsets_to_values_ref = $self->_get_offsets_to_values; | |||||||||||||||||||||||||||||||
| 427 | 145 | ▶ | if (defined $offsets_to_values_ref) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 428 | 144 | @offsets_to_values = @{$self->_get_offsets_to_values}; | |||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||
| 432 | 6276 | ▶ | return Parse::Win32Registry::Iterator->new(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 433 | 6276 | ▶ | while (defined(my $offset_to_value = shift @offsets_to_values)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 434 | 6109 | my $value = Parse::Win32Registry::WinNT::Value->new($regfile, | |||||||||||||||||||||||||||||||
| 435 | $offset_to_value); | ||||||||||||||||||||||||||||||||
| 436 | 6109 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 437 | 6109 | return $value; | |||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||
| 440 | 167 | return; # no more offsets to values | |||||||||||||||||||||||||||||||
| 441 | 174 | }); | |||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||
| 444 | 13 | 1; | |||||||||||||||||||||||||||||||