| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Script::isAperlScript; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22127
|
use warnings; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
34
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use base 'Error::Helper'; |
|
|
1
|
|
|
|
|
15
|
|
|
|
1
|
|
|
|
|
871
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Script::isAperlScript - This does a basic check if something is a perl script or not. |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 1.0.0 |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.0.0'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This module does a basic check to see if something is a perl script. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
By default it checks for the paths below. |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
/^\#\!\/usr\/bin\/perl/ |
|
26
|
|
|
|
|
|
|
/^\#\!\/usr\/bin\/suidperl/ |
|
27
|
|
|
|
|
|
|
/^\#\!\/usr\/local\/bin\/perl/ |
|
28
|
|
|
|
|
|
|
/^\#\!\/usr\/local\/bin\/suidperl/ |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This will also match stuff like "#!/usr/local/bin/perl5.8.9". |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
If {env=>1} is given to the new method, the checks below are done. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
/^\#!\/usr\/bin\/env.*perl/ |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
If {any=>1} is given to the new method, the checks below are done. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
/^\#!\/.*perl/ |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 new |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This initiates the object. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head3 args hash |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head4 env |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Allow env based scripts. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
By default this is false as it can't be trusted. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head4 any |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This does very loose matching. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
By default this is false as it can't be trusted. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $checker=Script::isAperlScript->new( \%args ); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new{ |
|
65
|
0
|
|
|
0
|
1
|
|
my %args; |
|
66
|
0
|
0
|
|
|
|
|
if ( defined( $_[1] ) ){ |
|
67
|
0
|
|
|
|
|
|
%args=%{$_[1]}; |
|
|
0
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $self={ |
|
71
|
|
|
|
|
|
|
error=>0, |
|
72
|
|
|
|
|
|
|
errorString=>0, |
|
73
|
|
|
|
|
|
|
env=>0, |
|
74
|
|
|
|
|
|
|
any=>0, |
|
75
|
|
|
|
|
|
|
errorExtra=>{ |
|
76
|
|
|
|
|
|
|
flags=>{ |
|
77
|
|
|
|
|
|
|
2=>'noString', |
|
78
|
|
|
|
|
|
|
3=>'doesNotExist', |
|
79
|
|
|
|
|
|
|
4=>'notReadable', |
|
80
|
|
|
|
|
|
|
5=>'fileNotSpecified', |
|
81
|
|
|
|
|
|
|
6=>'noFile', |
|
82
|
|
|
|
|
|
|
7=>'notAfile', |
|
83
|
|
|
|
|
|
|
}, |
|
84
|
|
|
|
|
|
|
}, |
|
85
|
|
|
|
|
|
|
}; |
|
86
|
0
|
|
|
|
|
|
bless $self; |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if ( $args{env} ){ |
|
89
|
0
|
|
|
|
|
|
$self->{env}=1; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if ( $args{any} ){ |
|
93
|
0
|
|
|
|
|
|
$self->{any}=1; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return $self; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 isAperlScript |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This checks if a file is a Perl script. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Only one arguement is taken and it is the string in question. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
In regards to the returned value, see the section "RETURN" for more information. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $returned=isAperlScript($file); |
|
108
|
|
|
|
|
|
|
if(!$returned){ |
|
109
|
|
|
|
|
|
|
print "It returned false so there for it is a perl script.\n"; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub isAperlScript{ |
|
115
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
116
|
0
|
|
|
|
|
|
my $file=$_[1]; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if ( ! $self->errorblank ){ |
|
119
|
0
|
|
|
|
|
|
return undef; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#make sure a file is specified |
|
123
|
0
|
0
|
|
|
|
|
if (!defined($file)) { |
|
124
|
0
|
|
|
|
|
|
$self->{error}=5; |
|
125
|
0
|
|
|
|
|
|
$self->{errorString}='No file defined'; |
|
126
|
0
|
|
|
|
|
|
return undef; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
#make sure it exists |
|
129
|
0
|
0
|
|
|
|
|
if (! -e $file) { |
|
130
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
131
|
0
|
|
|
|
|
|
$self->{errorString}='The file, "'.$file.'", does not exist'; |
|
132
|
0
|
|
|
|
|
|
return undef; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#it is not a file |
|
136
|
0
|
0
|
|
|
|
|
if (! -f $file) { |
|
137
|
0
|
|
|
|
|
|
$self->{error}=7; |
|
138
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$file.'" is not a file'; |
|
139
|
0
|
|
|
|
|
|
return undef; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
#make sure it is readable |
|
143
|
0
|
0
|
|
|
|
|
if (! -r $file) { |
|
144
|
0
|
|
|
|
|
|
$self->{error}=4; |
|
145
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$file.'" is not readable'; |
|
146
|
0
|
|
|
|
|
|
return undef; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#try to open it |
|
150
|
0
|
0
|
|
|
|
|
if (open(THEFILE, '<', $file )) { |
|
151
|
0
|
|
|
|
|
|
my $string=join("", ); |
|
152
|
0
|
|
|
|
|
|
close(THEFILE); |
|
153
|
0
|
|
|
|
|
|
return $self->stringIsAperlScript($string); |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
#it could not be opened |
|
157
|
0
|
|
|
|
|
|
$self->{error}=6; |
|
158
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$file.'" could not be opened'; |
|
159
|
0
|
|
|
|
|
|
return undef; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 stringIsAperlScript |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This checks if a string is a Perl script. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Only one arguement is taken and it is the string in question. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
In regards to the returned value, see the section "RETURN" for more information. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
my $returned=stringIsAperlScript($string); |
|
171
|
|
|
|
|
|
|
if(!$returned){ |
|
172
|
|
|
|
|
|
|
print "It returned false so there for it is a perl script.\n"; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub stringIsAperlScript{ |
|
178
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
179
|
0
|
|
|
|
|
|
my $string=$_[1]; |
|
180
|
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
if ( ! $self->errorblank ){ |
|
182
|
0
|
|
|
|
|
|
return undef; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#make sure a string is specified |
|
186
|
0
|
0
|
|
|
|
|
if (!defined( $string )) { |
|
187
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
188
|
0
|
|
|
|
|
|
$self->{errorString}='No string defined'; |
|
189
|
0
|
|
|
|
|
|
return undef; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
#check if it should possibly do the any check |
|
193
|
0
|
0
|
|
|
|
|
if ( $self->{any} ){ |
|
194
|
0
|
0
|
|
|
|
|
if ($string =~ /^\#\!\/.*perl/) { |
|
195
|
0
|
|
|
|
|
|
return 1; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
#checks if it makes #!/usr/bin/perl |
|
200
|
0
|
0
|
|
|
|
|
if ($string =~ /^\#\!\/usr\/bin\/perl/) { |
|
201
|
0
|
|
|
|
|
|
return 1; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
#checks if it makes #!/usr/bin/suidperl |
|
205
|
0
|
0
|
|
|
|
|
if ($string =~ /^\#\!\/usr\/bin\/suidperl/) { |
|
206
|
0
|
|
|
|
|
|
return 1; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
#checks if it makes #!/usr/local/bin/perl |
|
210
|
0
|
0
|
|
|
|
|
if ($string =~ /^\#\!\/usr\/local\/bin\/perl/) { |
|
211
|
0
|
|
|
|
|
|
return 1; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
#checks if it makes #!/usr/local/bin/suidperl |
|
215
|
0
|
0
|
|
|
|
|
if ($string =~ /^\#\!\/usr\/local\/bin\/suidperl/) { |
|
216
|
0
|
|
|
|
|
|
return 1; |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
#check if it should possibly do the env check |
|
220
|
0
|
0
|
|
|
|
|
if ( $self->{env} ){ |
|
221
|
0
|
0
|
|
|
|
|
if ( $string =~ /^\#!\/usr\/bin\/env.*perl/ ) { |
|
222
|
0
|
|
|
|
|
|
return 1; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
#not a perl script |
|
227
|
0
|
|
|
|
|
|
return undef; |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 ERROR CODES/FLAGS/HANDLING |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
The easiest way to check is to verify the returned value is false. |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Error handling is provided by L. |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 2, noString |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
The string is not defined. |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 3, doesNotExist |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
The file does not exist. |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 4, notReadable |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
The file is not readable. |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head2 5, fileNotSpecified |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
No file specified. |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 6, noFile |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
The file could not be opened. |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 7, notAfile |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
The specified file is not a file. |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 AUTHOR |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Zane C. Bowers-Hadley, C<< >> |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head1 BUGS |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
267
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
268
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 SUPPORT |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
perldoc Script::isAperlScript |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
You can also look for information at: |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=over 4 |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
L |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
L |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
L |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=item * Search CPAN |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
L |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=back |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Copyright 2012 Zane C. Bowers-Hadley, all rights reserved. |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
311
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=cut |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
1; # End of Script::isAperlScript |