File Coverage

lib/Win32/PEFile/PEBase.pm
Criterion Covered Total %
statement 41 50 82.0
branch 5 14 35.7
condition 2 6 33.3
subroutine 11 12 91.6
pod 0 3 0.0
total 59 85 69.4


line stmt bran cond sub pod time code
1             package Win32::PEFile::PEBase;
2 1     1   6 use strict;
  1         2  
  1         40  
3 1     1   6 use warnings;
  1         2  
  1         26  
4 1     1   6 use Encode;
  1         2  
  1         80  
5 1     1   6 use Carp;
  1         2  
  1         56  
6 1     1   559 use Win32::PEFile::SectionHandlers;
  1         3  
  1         33  
7 1     1   6 use Win32::PEFile::PEConstants;
  1         2  
  1         4225  
8            
9            
10             sub new {
11 3     3 0 11 my ($class, %params) = @_;
12            
13 3         13 return bless \%params, $class;
14             }
15            
16            
17             sub AUTOLOAD {
18 3     3   10 my ($self, @args) = @_;
19 3         7 my $myClass = ref $self;
20 3         5 my $fullMethod = $Win32::PEFile::PEBase::AUTOLOAD;
21 3         25 (my $method = $fullMethod) =~ s/^([\w:]*):://;
22 3         9 my $package = $1;
23 3         10 my $class = $Win32::PEFile::SectionHandlers::_EntryPoints{$method};
24            
25 3 50       12 Carp::confess "No such method '$fullMethod' defined for $myClass"
26             if !defined $class;
27            
28 3         770 push @Win32::PEFile::PEBase::ISA, $class;
29 3         45 return $self->$method(@args);
30             }
31            
32            
33             sub isOk {
34 3     3 0 24 my ($self) = @_;
35 3         1277 return $self->{ok};
36             }
37            
38            
39             sub lastError {
40 1     1 0 3 my ($self) = @_;
41 1         9 return $self->{err};
42             }
43            
44            
45             sub _dispatch {
46 0     0   0 my ($self, $method, $sectionCode, @args) = @_;
47            
48 0 0 0     0 Carp::confess "Not a recognised section code: $sectionCode"
49             if !defined $sectionCode || !exists $kStdSectionCodeLu{$sectionCode};
50            
51 0 0       0 return if ! exists $Win32::PEFile::SectionHandlers::_SectionNames{$sectionCode};
52            
53 0         0 my $class = "$Win32::PEFile::SectionHandlers::_SectionNames{$sectionCode}";
54            
55 0         0 $method = "${class}::$method";
56 0 0       0 return $self->$method(@args) if $self->can($method);
57            
58 0         0 $method = "${method}_$kStdSectionCodeLu{$sectionCode}";
59 0 0       0 return $self->$method(@args) if $self->can($method);
60 0         0 return '';
61             }
62            
63            
64             sub _readNameStr {
65 43     43   61 my ($self, $fh, $nameFileAddr) = @_;
66 43         50 my $nameStr = '';
67 43         42 my $strEnd = 0;
68 43         54 my $oldLoc = tell $fh;
69            
70 43 100       384 seek $fh, $nameFileAddr, 0 if defined $nameFileAddr;
71 43   66     2422 read $fh, $nameStr, 256, length $nameStr
72             while !eof ($fh)
73             and ($strEnd = index $nameStr, "\0") < 0;
74 43 100       102 seek $fh, $oldLoc, 0 if defined $nameFileAddr;
75 43         154 return substr $nameStr, 0, $strEnd;
76             }
77            
78            
79             1;
80            
81