lib/Parse/Win32Registry/WinNT/Security.pm

filter: Statementstmt 89.5% 77 / 86 Branchbran 70.8% 17 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 78.5% 11 / 14 Podpod 0.0% 0 / 7 totaltotal 80.1% 105 / 131 CC 13 SCAR 19.7
CC
13
Cov
85%
new
13.2
get_previous
2.0
get_reference_count
2.0
CRAP 7.2
« lib/Parse/Win32Registry/WinNT/Entry.pm ↑ Summary script/regtimeline.pl »
1 package Parse::Win32Registry::WinNT::Security;
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::Entry);
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  
11 13 ▶use constant SK_HEADER_LENGTH => 0x18;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use constant OFFSET_TO_FIRST_HBIN => 0x1000;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 14 ▶sub new {
Subroutine new: called CC=13 SCAR=25.8
Pod undocumented
15 14 my $class = shift;
16 14 my $regfile = shift;
17 14 my $offset = shift; # offset to sk record relative to start of file
18  
19 14 ▶ croak 'Missing registry file' if !defined $regfile;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $regfile 0 14 14
20 14 ▶ croak 'Missing offset' if !defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 14 14
21  
22 14 ▶ if (defined(my $cache = $regfile->{_security_cache})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $cache = $regfile->{"_security_cache"})) 14 0 14
23 14 ▶ if (exists $cache->{$offset}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cache->{$offset}) 2 12 14
24 2 return $cache->{$offset};
25 }
26 }
27  
28 12 my $fh = $regfile->get_filehandle;
29  
30 # 0x00 dword = security length (negative = allocated)
31 # 0x04 word = 'sk' signature
32 # 0x08 dword = offset to previous sk
33 # 0x0c dword = offset to next sk
34 # 0x10 dword = ref count
35 # 0x14 dword = length of security descriptor
36 # 0x18 = start of security descriptor
37  
38 # Extracted offsets are always relative to first hbin
39  
40 12 sysseek($fh, $offset, 0);
41 12 my $bytes_read = sysread($fh, my $sk_header, SK_HEADER_LENGTH);
42 12 ▶ if ($bytes_read != SK_HEADER_LENGTH) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes_read != 24) 1 11 12
43 1 warnf('Could not read security at 0x%x', $offset);
44 1 return;
45 }
46  
47 11 my ($length,
48 $sig,
49 $offset_to_previous,
50 $offset_to_next,
51 $ref_count,
52 $sd_length,
53 ) = unpack('Va2x2VVVV', $sk_header);
54  
55 11 ▶ $offset_to_previous += OFFSET_TO_FIRST_HBIN
Branch: 1 branch
BranchTrueFalseTotal
if $offset_to_previous != 4294967295 11 0 11
56 if $offset_to_previous != 0xffffffff;
57 11 ▶ $offset_to_next += OFFSET_TO_FIRST_HBIN
Branch: 1 branch
BranchTrueFalseTotal
if $offset_to_next != 4294967295 11 0 11
58 if $offset_to_next != 0xffffffff;
59  
60 11 my $allocated = 0;
61 11 ▶ if ($length > 0x7fffffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 2147483647) 11 0 11
62 11 $allocated = 1;
63 11 $length = (0xffffffff - $length) + 1;
64 }
65 # allocated should be true
66  
67 11 ▶ if ($sig ne 'sk') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig ne "sk") 1 10 11
68 1 warnf('Invalid signature for security at 0x%x', $offset);
69 1 return;
70 }
71  
72 10 $bytes_read = sysread($fh, my $sd_data, $sd_length);
73 10 ▶ if ($bytes_read != $sd_length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes_read != $sd_length) 1 9 10
74 1 warnf('Could not read security descriptor for security at 0x%x',
75 $offset);
76 1 return;
77 }
78  
79 9 my $sd = unpack_security_descriptor($sd_data);
80 9 ▶ if (!defined $sd) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sd) 1 8 9
81 1 warnf('Invalid security descriptor for security at 0x%x',
82 $offset);
83 # Abandon security object if security descriptor is invalid
84 1 return;
85 }
86  
87 8 my $self = {};
88 8 $self->{_regfile} = $regfile;
89 8 $self->{_offset} = $offset;
90 8 $self->{_length} = $length;
91 8 $self->{_allocated} = $allocated;
92 8 $self->{_tag} = $sig;
93 8 $self->{_offset_to_previous} = $offset_to_previous;
94 8 $self->{_offset_to_next} = $offset_to_next;
95 8 $self->{_ref_count} = $ref_count;
96 8 $self->{_security_descriptor_length} = $sd_length;
97 8 $self->{_security_descriptor} = $sd;
98 8 bless $self, $class;
99  
100 8 ▶ if (defined(my $cache = $regfile->{_security_cache})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $cache = $regfile->{"_security_cache"})) 8 0 8
101 8 $cache->{$offset} = $self;
102 }
103  
104 8 return $self;
105 }
106  
107 0 ▶sub get_previous {
Subroutine get_previous: not called CC=1 SCAR=6.9
Pod undocumented
108 0 my $self = shift;
109 0 my $regfile = $self->{_regfile};
110 0 my $offset_to_previous = $self->{_offset_to_previous};
111  
112 0 return Parse::Win32Registry::WinNT::Security->new($regfile,
113 $offset_to_previous);
114 }
115  
116 7 ▶sub get_next {
Subroutine get_next: called CC=1 SCAR=0.0
Pod undocumented
117 7 my $self = shift;
118 7 my $regfile = $self->{_regfile};
119 7 my $offset_to_next = $self->{_offset_to_next};
120  
121 7 return Parse::Win32Registry::WinNT::Security->new($regfile,
122 $offset_to_next);
123 }
124  
125 0 ▶sub get_reference_count {
Subroutine get_reference_count: not called CC=1 SCAR=6.9
Pod undocumented
126 0 my $self = shift;
127  
128 0 return $self->{_ref_count};
129 }
130  
131 7 ▶sub get_security_descriptor {
Subroutine get_security_descriptor: called CC=1 SCAR=0.0
Pod undocumented
132 7 my $self = shift;
133  
134 7 return $self->{_security_descriptor};
135 }
136  
137 2 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
138 2 my $self = shift;
139  
140 2 return '(security entry)';
141 }
142  
143 0 ▶sub parse_info {
Subroutine parse_info: not called CC=1 SCAR=6.9
Pod undocumented
144 0 my $self = shift;
145  
146 my $info = sprintf '0x%x sk len=0x%x alloc=%d prev=0x%x,next=0x%x refs=%d',
147 $self->{_offset},
148 $self->{_length},
149 $self->{_allocated},
150 $self->{_offset_to_previous},
151 $self->{_offset_to_next},
152 0 $self->{_ref_count};
153  
154 0 return $info;
155 }
156  
157 13 1;
« lib/Parse/Win32Registry/WinNT/Entry.pm ↑ Summary script/regtimeline.pl »