| 1 | package Parse::Win32Registry::Win95::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 Parse::Win32Registry::Base qw(:all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 13 | ▶ | use Parse::Win32Registry::Win95::Value; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 13 | ▶ | use constant RGKN_ENTRY_LENGTH => 0x1c; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 13 | ▶ | use constant OFFSET_TO_RGKN_BLOCK => 0x20; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 332 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||
| 16 | 332 | my $class = shift; | |||||||||
| 17 | 332 | my $regfile = shift; | |||||||||
| 18 | 332 | my $offset = shift; # offset to RGKN key entry relative to start of RGKN | |||||||||
| 19 | 332 | my $parent_key_path = shift; # parent key path (optional) | |||||||||
| 20 | |||||||||||
| 21 | 332 | ▶ | croak 'Missing registry file' if !defined $regfile; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 332 | ▶ | croak 'Missing offset' if !defined $offset; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | |||||||||||
| 24 | 332 | my $fh = $regfile->get_filehandle; | |||||||||
| 25 | |||||||||||
| 26 | # RGKN Key Entry | ||||||||||
| 27 | # 0x00 dword | ||||||||||
| 28 | # 0x04 dword | ||||||||||
| 29 | # 0x08 dword | ||||||||||
| 30 | # 0x0c dword = offset to parent RGKN entry | ||||||||||
| 31 | # 0x10 dword = offset to first child RGKN entry | ||||||||||
| 32 | # 0x14 dword = offset to next sibling RGKN entry | ||||||||||
| 33 | # 0x18 dword = entry id of RGDB entry | ||||||||||
| 34 | |||||||||||
| 35 | # Extracted offsets are relative to the start of the RGKN block | ||||||||||
| 36 | |||||||||||
| 37 | # Any offset of 0xffffffff marks the end of a list. | ||||||||||
| 38 | # An entry id of 0xffffffff means the RGKN entry has no RGDB entry. | ||||||||||
| 39 | # This occurs for the root key of the registry file. | ||||||||||
| 40 | |||||||||||
| 41 | 332 | sysseek($fh, $offset, 0); | |||||||||
| 42 | 332 | my $bytes_read = sysread($fh, my $rgkn_entry, RGKN_ENTRY_LENGTH); | |||||||||
| 43 | 332 | ▶ | if ($bytes_read != RGKN_ENTRY_LENGTH) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 1 | warnf('Could not read RGKN key at 0x%x', $offset); | |||||||||
| 45 | 1 | return; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 331 | my ($offset_to_parent, | |||||||||
| 49 | $offset_to_first_child, | ||||||||||
| 50 | $offset_to_next_sibling, | ||||||||||
| 51 | $key_id) = unpack('x12VVVV', $rgkn_entry); | ||||||||||
| 52 | |||||||||||
| 53 | 331 | ▶ | $offset_to_parent += OFFSET_TO_RGKN_BLOCK | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | if $offset_to_parent != 0xffffffff; | ||||||||||
| 55 | 331 | ▶ | $offset_to_first_child += OFFSET_TO_RGKN_BLOCK | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | if $offset_to_first_child != 0xffffffff; | ||||||||||
| 57 | 331 | ▶ | $offset_to_next_sibling += OFFSET_TO_RGKN_BLOCK | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | if $offset_to_next_sibling != 0xffffffff; | ||||||||||
| 59 | |||||||||||
| 60 | 331 | my $self = {}; | |||||||||
| 61 | 331 | $self->{_regfile} = $regfile; | |||||||||
| 62 | 331 | $self->{_offset} = $offset; | |||||||||
| 63 | 331 | $self->{_length} = RGKN_ENTRY_LENGTH; | |||||||||
| 64 | 331 | $self->{_allocated} = 1; | |||||||||
| 65 | 331 | $self->{_tag} = 'rgkn key'; | |||||||||
| 66 | 331 | $self->{_offset_to_parent} = $offset_to_parent; | |||||||||
| 67 | 331 | $self->{_offset_to_first_child} = $offset_to_first_child; | |||||||||
| 68 | 331 | $self->{_offset_to_next_sibling} = $offset_to_next_sibling; | |||||||||
| 69 | 331 | $self->{_id} = $key_id; | |||||||||
| 70 | 331 | bless $self, $class; | |||||||||
| 71 | |||||||||||
| 72 | # Look up corresponding rgdb entry | ||||||||||
| 73 | 331 | my $index = $regfile->{_rgdb_index}; | |||||||||
| 74 | 331 | ▶ | croak 'Missing rgdb index' if !defined $index; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 331 | ▶ | if (exists $index->{$key_id}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 299 | my $rgdb_key = $index->{$key_id}; | |||||||||
| 77 | 299 | $self->{_rgdb_key} = $rgdb_key; | |||||||||
| 78 | 299 | $self->{_name} = $rgdb_key->get_name; | |||||||||
| 79 | } | ||||||||||
| 80 | else { | ||||||||||
| 81 | 32 | $self->{_name} = ''; | |||||||||
| 82 | # Only the root key should have no matching RGDB entry | ||||||||||
| 83 | 32 | ▶ | if (!$self->is_root) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 1 | warnf('Could not find RGDB entry for RGKN key at 0x%x', $offset); | |||||||||
| 85 | } | ||||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 331 | my $name = $self->{_name}; | |||||||||
| 89 | 331 | ▶ | $self->{_key_path} = defined($parent_key_path) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | ? "$parent_key_path\\$name" | ||||||||||
| 91 | : $name; | ||||||||||
| 92 | |||||||||||
| 93 | 331 | return $self; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 33 | ▶ | sub get_timestamp { | ||||||||
|
Subroutine
get_timestamp: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 97 | 33 | return undef; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 34 | ▶ | sub get_timestamp_as_string { | ||||||||
|
Subroutine
get_timestamp_as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 101 | 34 | return iso8601(undef); | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 17 | ▶ | sub get_class_name { | ||||||||
|
Subroutine
get_class_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 105 | 17 | return undef; | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 146 | ▶ | sub is_root { | ||||||||
|
Subroutine
is_root: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 109 | 146 | my $self = shift; | |||||||||
| 110 | |||||||||||
| 111 | 146 | my $offset = $self->{_offset}; | |||||||||
| 112 | 146 | my $regfile = $self->{_regfile}; | |||||||||
| 113 | |||||||||||
| 114 | 146 | my $rgkn_block = $regfile->get_rgkn; | |||||||||
| 115 | 146 | my $offset_to_root_key = $rgkn_block->{_offset_to_root_key}; | |||||||||
| 116 | |||||||||||
| 117 | # This gives better results than checking id == 0xffffffff | ||||||||||
| 118 | 146 | return $offset == $offset_to_root_key; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 48 | ▶ | sub get_parent { | ||||||||
|
Subroutine
get_parent: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 122 | 48 | my $self = shift; | |||||||||
| 123 | |||||||||||
| 124 | 48 | my $regfile = $self->{_regfile}; | |||||||||
| 125 | 48 | my $offset_to_parent = $self->{_offset_to_parent}; | |||||||||
| 126 | 48 | my $key_path = $self->{_key_path}; | |||||||||
| 127 | |||||||||||
| 128 | 48 | ▶ | return if $self->is_root; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | |||||||||||
| 130 | 48 | my $grandparent_key_path; | |||||||||
| 131 | 48 | my @keys = split(/\\/, $key_path, -1); | |||||||||
| 132 | 48 | ▶ | if (@keys > 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 133 | 28 | $grandparent_key_path = join("\\", @keys[0..$#keys-2]); | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | 48 | return Parse::Win32Registry::Win95::Key->new($regfile, | |||||||||
| 137 | $offset_to_parent, | ||||||||||
| 138 | $grandparent_key_path); | ||||||||||
| 139 | } | ||||||||||
| 140 | |||||||||||
| 141 | 0 | ▶ | sub get_security { | ||||||||
|
Subroutine
get_security: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 142 | 0 | return undef; | |||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | 23 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 146 | 23 | my $self = shift; | |||||||||
| 147 | |||||||||||
| 148 | 23 | return $self->get_path; | |||||||||
| 149 | } | ||||||||||
| 150 | |||||||||||
| 151 | 0 | ▶ | sub parse_info { | ||||||||
|
Subroutine
parse_info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 152 | 0 | my $self = shift; | |||||||||
| 153 | |||||||||||
| 154 | my $info = sprintf '0x%x rgkn key len=0x%x par=0x%x,child=0x%x,next=0x%x id=0x%x', | ||||||||||
| 155 | $self->{_offset}, | ||||||||||
| 156 | $self->{_length}, | ||||||||||
| 157 | $self->{_offset_to_parent}, | ||||||||||
| 158 | $self->{_offset_to_first_child}, | ||||||||||
| 159 | $self->{_offset_to_next_sibling}, | ||||||||||
| 160 | 0 | $self->{_id}; | |||||||||
| 161 | 0 | return $info; | |||||||||
| 162 | } | ||||||||||
| 163 | |||||||||||
| 164 | 126 | ▶ | sub get_subkey_iterator { | ||||||||
|
Subroutine
get_subkey_iterator: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||
| 165 | 126 | my $self = shift; | |||||||||
| 166 | |||||||||||
| 167 | 126 | my $regfile = $self->{_regfile}; | |||||||||
| 168 | 126 | my $key_path = $self->{_key_path}; | |||||||||
| 169 | |||||||||||
| 170 | 126 | my $offset_to_next_key = $self->{_offset_to_first_child}; | |||||||||
| 171 | |||||||||||
| 172 | 126 | my $end_of_file = $regfile->get_length; | |||||||||
| 173 | 126 | my $rgkn_block = $regfile->get_rgkn; | |||||||||
| 174 | 126 | my $end_of_rgkn_block = $rgkn_block->get_offset + $rgkn_block->get_length; | |||||||||
| 175 | |||||||||||
| 176 | 397 | ▶ | return Parse::Win32Registry::Iterator->new(sub { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.8
| |||||||||||
| 177 | 397 | ▶ | if ($offset_to_next_key == 0xffffffff) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 178 | 126 | return; # no more subkeys | |||||||||
| 179 | } | ||||||||||
| 180 | 271 | ▶ | if ($offset_to_next_key > $end_of_rgkn_block) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 181 | 0 | return; | |||||||||
| 182 | } | ||||||||||
| 183 | 271 | ▶ | if (my $key = Parse::Win32Registry::Win95::Key->new($regfile, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 184 | $offset_to_next_key, $key_path)) | ||||||||||
| 185 | { | ||||||||||
| 186 | 271 | $offset_to_next_key = $key->{_offset_to_next_sibling}; | |||||||||
| 187 | 271 | return $key; | |||||||||
| 188 | } | ||||||||||
| 189 | else { | ||||||||||
| 190 | 0 | return; # no more subkeys | |||||||||
| 191 | } | ||||||||||
| 192 | 126 | }); | |||||||||
| 193 | } | ||||||||||
| 194 | |||||||||||
| 195 | 151 | ▶ | sub get_value_iterator { | ||||||||
|
Subroutine
get_value_iterator: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 196 | 151 | my $self = shift; | |||||||||
| 197 | |||||||||||
| 198 | 151 | my $rgdb_key = $self->{_rgdb_key}; | |||||||||
| 199 | 151 | ▶ | if (defined $rgdb_key) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 200 | 140 | return $rgdb_key->get_value_iterator; | |||||||||
| 201 | } | ||||||||||
| 202 | else { | ||||||||||
| 203 | 11 | ▶ | return Parse::Win32Registry::Iterator->new(sub {}); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 204 | } | ||||||||||
| 205 | } | ||||||||||
| 206 | |||||||||||
| 207 | 13 | 1; | |||||||||