lib/Win32/Exe/Section.pm

filter: Statementstmt 84.6% 83 / 98 Branchbran 53.1% 17 / 32 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 6 totaltotal 70.9% 117 / 165 CC 23 SCAR 18.8
CC
23
Cov
75%
update_offset
20.0
pad_data
9.5
Data
5.5
CRAP 6.5
« lib/Win32/Exe/Manifest/Parser.pm ↑ Summary lib/Win32/Exe/Resource/Manifest.pm »
1 # Copyright 2004 by Audrey Tang <cpan@audreyt.org>
2  
3 package Win32::Exe::Section;
4  
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use base 'Win32::Exe::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use constant FORMAT => (
Subroutine BEGIN: called CC=1 SCAR=0.0
8 Name => 'Z8',
9 VirtualSize => 'V',
10 VirtualAddress => 'V',
11 FileSize => 'V',
12 FileOffset => 'V',
13 RelocOffset => 'V',
14 LineNumOffset => 'V',
15 NumReloc => 'v',
16 NumLineNum => 'v',
17 Flags => 'V',
18 5 );
19 5 ▶use constant DISPATCH_FIELD => 'Name';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use constant DISPATCH_TABLE => (
Subroutine BEGIN: called CC=1 SCAR=0.0
21 '.text' => 'Section::Code',
22 '.debug' => 'Section::Debug',
23 '.data' => 'Section::Data',
24 '.rdata' => 'Section::Data',
25 '.bss' => 'Section::Data',
26 '.edata' => 'Section::Exports',
27 '.idata' => 'Section::Imports',
28 '.rsrc' => 'Section::Resources',
29 5 );
30  
31 5 ▶use constant CONTAINS_CODE => 0x20;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use constant CONTAINS_IDATA => 0x40;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶use constant CONTAINS_UDATA => 0x80;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 280 ▶sub Data {
Subroutine Data: called CC=5 SCAR=17.1
Pod undocumented
36 280 my ($self) = @_;
37 280 ▶ $self->{data} ||= do {
Condition66%2/3
$self->{"data"} ||= do { my $v_size = $self->VirtualSize; my $f_size = $self->FileSize or return "\0" x $v_size; $f_size = $v_size if $v_size and $v_size < $f_size; my $data = $self->parent->substr($self->FileOffset, $f_size); $data .= "\0" x ($v_size - length($data)); $data }
l!l&&r!l&&!r
27280
MC/DC0%0/2
$self->{"data"} ||= do { my $v_size = $self->VirtualSize; my $f_size = $self->FileSize or return "\0" x $v_size; $f_size = $v_size if $v_size and $v_size < $f_size; my $data = $self->parent->substr($self->FileOffset, $f_size); $data .= "\0" x ($v_size - length($data)); $data }
$self->{"data"} do { my $v_size = $self->VirtualSize; my $f_size = $self->FileSize or return "\0" x $v_size; $f_size = $v_size if $v_size and $v_size < $f_size; my $data = $self->parent->substr($self->FileOffset, $f_size); $data .= "\0" x ($v_size - length($data)); $data }
Truth table66%2/3
A ||= B
A= $self->{"data"}B= do { my $v_size = $self->VirtualSize; my $f_size = $self->FileSize or return "\0" x $v_size; $f_size = $v_size if $v_size and $v_size < $f_size; my $data = $self->parent->substr($self->FileOffset, $f_size); $data .= "\0" x ($v_size - length($data)); $data }
ABresult
1X1
011
000
38 8 my $v_size = $self->VirtualSize;
39 8 ▶ my $f_size = $self->FileSize or return("\0" x $v_size);
Branch: 1 branch
BranchTrueFalseTotal
my $f_size = $self->FileSize or return "\0" x $v_size 8 0 8
40  
41 8 ▶ $f_size = $v_size if ($v_size && ( $v_size < $f_size));
Branch: 1 branch
BranchTrueFalseTotal
if $v_size and $v_size < $f_size 8 0 8
Condition33%1/3
$v_size and $v_size < $f_size
!ll&&!rl&&r
008
MC/DC0%0/2
$v_size and $v_size < $f_size
$v_size $v_size < $f_size
Truth table33%1/3
A and B
A= $v_sizeB= $v_size < $f_size
ABresult
0X0
100
111
42  
43 8 my $data = $self->parent->substr($self->FileOffset, $f_size);
44 8 $data .= ("\x0" x ($v_size - length($data)));
45 8 $data;
46 }
47 }
48  
49 9 ▶sub SetData {
Subroutine SetData: called CC=5 SCAR=16.3
Pod undocumented
50 9 my ($self, $data) = @_;
51 9 ▶ my $pad_size = length($1) if $data =~ s/(\0*)\z//;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ s/(\0*)\z// 9 0 9
52  
53 9 my $exe = $self->parent;
54 9 my $act_headersize = $exe->OptHeaderSize;
55 9 my $exp_headersize = $exe->ExpectedOptHeaderSize;
56
57 9 ▶ ($act_headersize && ( $act_headersize == $exp_headersize )) or die "Unsupported binary format: headersize $act_headersize ne $exp_headersize";
Branch: 1 branch
BranchTrueFalseTotal
$act_headersize and $act_headersize == $exp_headersize or die "Unsupported binary format: headersize $act_headersize ne $exp_headersize" 9 0 9
Condition33%1/3
$act_headersize and $act_headersize == $exp_headersize
!ll&&!rl&&r
009
MC/DC0%0/2
$act_headersize and $act_headersize == $exp_headersize
$act_headersize $act_headersize == $exp_headersize
Truth table33%1/3
A and B
A= $act_headersizeB= $act_headersize == $exp_headersize
ABresult
0X0
100
111
58
59 9 my $index = $self->sibling_index;
60 9 my $data_size = length($data);
61  
62 9 my $f_size = $self->align($data_size, $exe->FileAlign);
63 9 my $v_size = $self->align($data_size, $exe->SectionAlign);
64 9 my $f_extra = $f_size - $self->FileSize;
65 9 my $v_extra = $v_size - $self->align($self->VirtualSize, $exe->SectionAlign);
66  
67 9 ▶ $self->pad_data($f_extra, $v_extra) if $f_extra;
Branch: 1 branch
BranchTrueFalseTotal
if $f_extra 2 7 9
68  
69 9 $self->SetVirtualSize($data_size + $pad_size);
70 9 $data .= ("\0" x ($self->FileSize - $data_size));
71  
72 9 $exe->substr($self->FileOffset, length($data), $data);
73 9 $self->update_size;
74 }
75  
76 9 ▶sub update_size {
Subroutine update_size: called CC=3 SCAR=11.0
Pod undocumented
77 9 my ($self) = @_;
78  
79 9 my $exe = $self->parent;
80 9 my $v_addr = $self->VirtualAddress;
81 9 my $v_size = $self->VirtualSize;
82  
83 9 foreach my $dir ($exe->data_directories) {
84 144 ▶ next unless $dir->VirtualAddress == $v_addr;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir->VirtualAddress == $v_addr 135 9 144
85 9 $dir->SetSize($v_size);
86 9 $dir->refresh;
87 }
88 }
89  
90 2 ▶sub pad_data {
Subroutine pad_data: called CC=8 SCAR=22.5
Pod undocumented
91 2 my ($self, $f_extra, $v_extra) = @_;
92  
93 2 my $exe = $self->parent;
94 2 my $offset = $self->FileOffset + $self->FileSize;
95  
96 2 $exe->update_debug_directory($offset, $f_extra);
97  
98 2 my $exe_size = $exe->size;
99 2 ▶ if ($exe_size > $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exe_size > $offset) 0 2 2
100 0 my $buf = $exe->substr($offset, ($exe_size - $offset));
101 0 $exe->substr($offset + $f_extra, length($buf), $buf);
102 }
103  
104 2 $exe->set_size($exe_size + $f_extra);
105 2 ▶ if ($f_extra > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f_extra > 0) { } 2 0 2
106 2 $exe->SetData($exe->Data . ("\0" x $f_extra));
107 }
108 else {
109 0 $exe->SetData(substr($exe->Data, 0, $f_extra));
110 }
111  
112 2 my $index = $self->sibling_index;
113 2 foreach my $section (@{$self->siblings}) {
114 14 ▶ next if $section->sibling_index <= $index;
Branch: 1 branch
BranchTrueFalseTotal
if $section->sibling_index <= $index 14 0 14
115 0 $section->update_offset($f_extra, $v_extra);
116 }
117  
118 2 $self->SetFileSize($self->FileSize + $f_extra);
119 2 $exe->SetImageSize($exe->ImageSize + $v_extra);
120  
121 2 my $flags = $self->Flags;
122 2 ▶ $exe->SetCodeSize($exe->CodeSize + $f_extra) if $flags & CONTAINS_CODE;
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 32 0 2 2
123 2 ▶ $exe->SetIDataSize($exe->IDataSize + $f_extra) if $flags & CONTAINS_IDATA;
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 64 2 0 2
124 2 ▶ $exe->SetUDataSize($exe->UDataSize + $f_extra) if $flags & CONTAINS_UDATA;
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 128 0 2 2
125 }
126  
127 0 ▶sub update_offset {
Subroutine update_offset: not called CC=4 SCAR=30.0
Pod undocumented
128 0 my ($self, $f_extra, $v_extra) = @_;
129 0 ▶ return unless $f_extra > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $f_extra > 0 0 0 0
130  
131 0 my $exe = $self->parent;
132 0 my $v_addr = $self->VirtualAddress;
133  
134 0 $self->SetVirtualAddress( $v_addr + $v_extra );
135 0 $self->SetFileOffset( $self->FileOffset + $f_extra );
136  
137 0 foreach my $dir ($exe->data_directories) {
138 0 ▶ next unless $dir->VirtualAddress == $v_addr;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir->VirtualAddress == $v_addr 0 0 0
139 0 $dir->SetVirtualAddress($self->VirtualAddress);
140 }
141 }
142  
143 280 ▶sub substr {
Subroutine substr: called CC=3 SCAR=11.4
Pod undocumented
144 280 my $self = shift;
145 280 my $data = $self->Data;
146 280 my $offset = shift;
147 280 ▶ my $length = @_ ? shift(@_) : (length($data) - $offset);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 200 80 280
148 280 my $replace = shift;
149  
150 280 ▶ return substr($data, $offset, $length) if !defined $replace;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $replace 280 0 280
151  
152 0 substr($data, $offset, $length, $replace);
153 0 $self->SetData($data);
154 }
155  
156 5 1;
« lib/Win32/Exe/Manifest/Parser.pm ↑ Summary lib/Win32/Exe/Resource/Manifest.pm »