| 1 | 2 | ▶ | use 5.010; # $+{} | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package ELF::Extract::Sections::Scanner::Objdump; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # ABSTRACT: An objdump based section scanner. | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '1.001004'; # TRIAL | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Moose qw( with has ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | with 'ELF::Extract::Sections::Meta::Scanner'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use MooseX::Has::Sugar 0.0300; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use MooseX::Types::Moose (qw( Bool HashRef RegexpRef FileHandle Undef Str Int)); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use MooseX::Types::Path::Tiny ('File'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use MooseX::Params::Validate (qw( validated_list )); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 4 | ▶ | sub open_file { | ||||||||||||||||||||||||||
|
Subroutine
open_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 4 | my ( $self, $file ) = validated_list( \@_, file => { isa => File, }, ); | |||||||||||||||||||||||||||
| 35 | 4 | $self->log->debug("Opening $file"); | |||||||||||||||||||||||||||
| 36 | 4 | $self->_file($file); | |||||||||||||||||||||||||||
| 37 | 4 | $self->_filehandle( $self->_objdump ); | |||||||||||||||||||||||||||
| 38 | 4 | return 1; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3987 | ▶ | sub next_section { | ||||||||||||||||||||||||||
|
Subroutine
next_section: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 3987 | my ($self) = @_; | |||||||||||||||||||||||||||
| 53 | 3987 | my $re = $self->_section_header_identifier; | |||||||||||||||||||||||||||
| 54 | 3987 | my $fh = $self->_filehandle; | |||||||||||||||||||||||||||
| 55 | 3987 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 472625 | ▶ | next if $line !~ $re; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 3983 | my ( $header, $offset ) = ( $+{header}, $+{offset} ); | |||||||||||||||||||||||||||
| 58 | 3983 | $self->_state( { header => $header, offset => $offset } ); | |||||||||||||||||||||||||||
| 59 | 3983 | $self->log->info("objdump -D -F : Section $header at $offset"); | |||||||||||||||||||||||||||
| 60 | 3983 | return 1; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 4 | $self->_clear_file; | |||||||||||||||||||||||||||
| 63 | 4 | $self->_clear_filehandle; | |||||||||||||||||||||||||||
| 64 | 4 | $self->_clear_state; | |||||||||||||||||||||||||||
| 65 | 4 | return 0; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 3983 | ▶ | sub section_offset { | ||||||||||||||||||||||||||
|
Subroutine
section_offset: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 3983 | my ($self) = @_; | |||||||||||||||||||||||||||
| 80 | 3983 | ▶ | if ( not $self->_has_state ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | $self->log->logcroak('Invalid call to section_offset outside of file scan'); | |||||||||||||||||||||||||||
| 82 | 0 | return; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 3983 | return hex( $self->_state->{offset} ); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub section_size { | ||||||||||||||||||||||||||
|
Subroutine
section_size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 99 | 0 | $self->log->logcroak('Can\'t perform section_size on this type of object.'); | |||||||||||||||||||||||||||
| 100 | 0 | return; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 3983 | ▶ | sub section_name { | ||||||||||||||||||||||||||
|
Subroutine
section_name: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | 3983 | my ($self) = @_; | |||||||||||||||||||||||||||
| 115 | 3983 | ▶ | if ( not $self->_has_state ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $self->log->logcroak('Invalid call to section_name outside of file scan'); | |||||||||||||||||||||||||||
| 117 | 0 | return; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 3983 | return $self->_state->{header}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 4 | ▶ | sub can_compute_size { | ||||||||||||||||||||||||||
|
Subroutine
can_compute_size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 4 | return 0; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | has _header_regex => ( | ||||||||||||||||||||||||||||
| 137 | isa => RegexpRef, | ||||||||||||||||||||||||||||
| 138 | ro, | ||||||||||||||||||||||||||||
| 139 | 4 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 140 | 4 | return qr/<(?<header>[^>]+)>/; | |||||||||||||||||||||||||||
| 141 | }, | ||||||||||||||||||||||||||||
| 142 | 2 | ); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | has _offset_regex => ( | ||||||||||||||||||||||||||||
| 145 | isa => RegexpRef, | ||||||||||||||||||||||||||||
| 146 | ro, | ||||||||||||||||||||||||||||
| 147 | 4 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 148 | ## no critic (RegularExpressions::ProhibitEnumeratedClasses) | ||||||||||||||||||||||||||||
| 149 | 4 | return qr/[(]File Offset:\s*(?<offset>0x[0-9a-f]+)[)]/; | |||||||||||||||||||||||||||
| 150 | }, | ||||||||||||||||||||||||||||
| 151 | 2 | ); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 2 | has _section_header_identifier => ( isa => RegexpRef, ro, lazy_build, ); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 2 | has _file => ( isa => File, rw, clearer => '_clear_file', ); | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 2 | has _filehandle => ( isa => FileHandle, rw, clearer => '_clear_filehandle', ); | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 2 | has _state => ( | |||||||||||||||||||||||||||
| 160 | isa => HashRef, | ||||||||||||||||||||||||||||
| 161 | rw, | ||||||||||||||||||||||||||||
| 162 | predicate => '_has_state', | ||||||||||||||||||||||||||||
| 163 | clearer => '_clear_state', | ||||||||||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||||||||||
| 165 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 166 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 4 | ▶ | sub _build__section_header_identifier { | ||||||||||||||||||||||||||
|
Subroutine
_build__section_header_identifier: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 169 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 170 | 4 | my $header = $self->_header_regex; | |||||||||||||||||||||||||||
| 171 | 4 | my $offset = $self->_offset_regex; | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 4 | return qr/${header}\s*${offset}:/; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub _objdump_win32 { | ||||||||||||||||||||||||||
|
Subroutine
_objdump_win32: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 177 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 178 | 0 | require Capture::Tiny; | |||||||||||||||||||||||||||
| 179 | ## no critic (Subroutines::ProhibitCallsToUnexportedSubs) | ||||||||||||||||||||||||||||
| 180 | my ( $stdout, $result ) = Capture::Tiny::capture_stdout( | ||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 182 | 0 | system 'objdump', qw( -D -F ), $self->_file->realpath->absolute; | |||||||||||||||||||||||||||
| 183 | }, | ||||||||||||||||||||||||||||
| 184 | 0 | ); | |||||||||||||||||||||||||||
| 185 | 0 | ▶ | if ( $result != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | $self->log->logconfess(qq{An error occured requesting section data from objdump $^E $@ }); | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | 0 | ▶ | open my $fh, '<', \$stdout or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 0 | $self->log->logconfess(qq{An error occured making a string IO filehandle $! $@ }); | |||||||||||||||||||||||||||
| 190 | }; | ||||||||||||||||||||||||||||
| 191 | 0 | return $fh; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 4 | ▶ | sub _objdump { | ||||||||||||||||||||||||||
|
Subroutine
_objdump: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||
| 195 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 196 | 4 | ▶ | if ( 'MSWin32' eq $^O or $ENV{OBJDUMP_SLURP} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
"MSWin32" eq $^O or $ENV{"OBJDUMP_SLURP"}
MC/DC0%0/2
"MSWin32" eq $^O or $ENV{"OBJDUMP_SLURP"}
"MSWin32" eq $^O
$ENV{"OBJDUMP_SLURP"}
Truth table33%1/3
A or B
A= "MSWin32" eq $^OB= $ENV{"OBJDUMP_SLURP"}
| |||||||||||||||||||||||||||||
| 197 | 0 | return $self->_objdump_win32; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 4 | ▶ | if ( open my $fh, q{-|}, q{objdump}, qw( -D -F ), $self->_file->realpath->absolute ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 4 | return $fh; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 0 | $self->log->logconfess(qq{An error occured requesting section data from objdump $! $@ }); | |||||||||||||||||||||||||||
| 203 | 0 | return; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 2 | 1; | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | __END__ | ||||||||||||||||||||||||||||