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