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   4 use strict;
  1         1  
  1         27  
3 1     1   4 use warnings;
  1         1  
  1         17  
4 1     1   3 use Encode;
  1         1  
  1         49  
5 1     1   3 use Carp;
  1         1  
  1         40  
6 1     1   384 use Win32::PEFile::SectionHandlers;
  1         2  
  1         29  
7 1     1   4 use Win32::PEFile::PEConstants;
  1         1  
  1         928  
8            
9            
10             sub new {
11 3     3 0 7 my ($class, %params) = @_;
12            
13 3         10 return bless \%params, $class;
14             }
15            
16            
17             sub AUTOLOAD {
18 3     3   6 my ($self, @args) = @_;
19 3         4 my $myClass = ref $self;
20 3         3 my $fullMethod = $Win32::PEFile::PEBase::AUTOLOAD;
21 3         16 (my $method = $fullMethod) =~ s/^([\w:]*):://;
22 3         7 my $package = $1;
23 3         5 my $class = $Win32::PEFile::SectionHandlers::_EntryPoints{$method};
24            
25 3 50       8 Carp::confess "No such method '$fullMethod' defined for $myClass"
26             if !defined $class;
27            
28 3         94 push @Win32::PEFile::PEBase::ISA, $class;
29 3         26 return $self->$method(@args);
30             }
31            
32            
33             sub isOk {
34 3     3 0 16 my ($self) = @_;
35 3         15 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   36 my ($self, $fh, $nameFileAddr) = @_;
66 43         34 my $nameStr = '';
67 43         28 my $strEnd = 0;
68 43         36 my $oldLoc = tell $fh;
69            
70 43 100       55 seek $fh, $nameFileAddr, 0 if defined $nameFileAddr;
71 43   66     255 read $fh, $nameStr, 256, length $nameStr
72             while !eof ($fh)
73             and ($strEnd = index $nameStr, "\0") < 0;
74 43 100       73 seek $fh, $oldLoc, 0 if defined $nameFileAddr;
75 43         78 return substr $nameStr, 0, $strEnd;
76             }
77            
78            
79             1;
80            
81