| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# Scan.pm |
|
3
|
|
|
|
|
|
|
# Last Modification: Wed May 4 16:31:36 WEST 2005 |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# Copyright (c) 2005 Henrique Dias . All rights reserved. |
|
6
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or modify |
|
7
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
package File::Scan; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require 5; |
|
13
|
1
|
|
|
1
|
|
1501
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
require Exporter; |
|
16
|
1
|
|
|
1
|
|
894
|
use File::Copy; |
|
|
1
|
|
|
|
|
5021
|
|
|
|
1
|
|
|
|
|
89
|
|
|
17
|
1
|
|
|
1
|
|
2380
|
use SelfLoader; |
|
|
1
|
|
|
|
|
12964
|
|
|
|
1
|
|
|
|
|
70
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
15
|
use vars qw($VERSION @ISA @EXPORT $ERROR $SKIPPED $SUSPICIOUS $CALLBACK); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1162
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
22
|
|
|
|
|
|
|
$VERSION = '1.43'; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
($ERROR, $SKIPPED, $SUSPICIOUS, $CALLBACK) = ("", 0, 0, ""); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
SelfLoader->load_stubs(); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
|
29
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
|
30
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
|
31
|
0
|
|
|
|
|
|
my $self = { |
|
32
|
|
|
|
|
|
|
extension => "", |
|
33
|
|
|
|
|
|
|
delete => 0, |
|
34
|
|
|
|
|
|
|
move => "", |
|
35
|
|
|
|
|
|
|
copy => "", |
|
36
|
|
|
|
|
|
|
mkdir => 0, |
|
37
|
|
|
|
|
|
|
max_txt_size => 5120, |
|
38
|
|
|
|
|
|
|
max_bin_size => 10240, |
|
39
|
|
|
|
|
|
|
@_, |
|
40
|
|
|
|
|
|
|
}; |
|
41
|
0
|
|
|
|
|
|
bless ($self, $class); |
|
42
|
0
|
|
|
|
|
|
return($self); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub scan { |
|
46
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
47
|
0
|
|
|
|
|
|
my $file = shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
&_set_error(); |
|
50
|
0
|
|
|
|
|
|
&_set_skip(); |
|
51
|
0
|
|
|
|
|
|
&_set_suspicious(); |
|
52
|
0
|
|
|
|
|
|
&ret_callback(); |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
(-e $file) or return(&_set_error("No such file or directory: $file")); |
|
55
|
0
|
|
|
|
|
|
my $fsize = -s $file; |
|
56
|
0
|
0
|
|
|
|
|
$fsize or return(&_set_skip(2)); |
|
57
|
0
|
|
|
|
|
|
my $res = ""; |
|
58
|
0
|
0
|
0
|
|
|
|
if(-f $file && -T $file) { |
|
59
|
0
|
0
|
|
|
|
|
return(&_set_skip(3)) if($fsize < 23); |
|
60
|
0
|
0
|
0
|
|
|
|
return(&_set_skip(4)) |
|
61
|
|
|
|
|
|
|
if($self->{'max_txt_size'} && ($fsize > $self->{'max_txt_size'} * 1024)); |
|
62
|
0
|
|
|
|
|
|
$res = &scan_text($self, $file); |
|
63
|
|
|
|
|
|
|
} else { |
|
64
|
0
|
0
|
0
|
|
|
|
return(&_set_skip(5)) |
|
65
|
|
|
|
|
|
|
if($self->{'max_bin_size'} && ($fsize > $self->{'max_bin_size'} * 1024)); |
|
66
|
0
|
|
|
|
|
|
$res = &scan_binary($self, $file); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
0
|
0
|
|
|
|
|
if($res) { |
|
69
|
0
|
0
|
0
|
|
|
|
if($self->{'extension'} && $file !~ /\.$self->{'extension'}$/o) { |
|
70
|
0
|
|
|
|
|
|
my $newname = join("\.", $file, $self->{'extension'}); |
|
71
|
0
|
0
|
|
|
|
|
if(move($file, $newname)) { $file = $newname; } |
|
|
0
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
else { &_set_error("Failed to move '$file' to '$newname'"); } |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
0
|
|
|
|
|
if($self->{'copy'}) { |
|
75
|
0
|
0
|
0
|
|
|
|
if(!(-d $self->{'copy'}) && $self->{'mkdir'}) { |
|
76
|
0
|
0
|
|
|
|
|
mkdir($self->{'copy'}, $self->{'mkdir'}) or &_set_error(join("", "Failed to create directory '", $self->{'copy'}, "' $!")); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
0
|
|
|
|
|
|
my ($f) = ($file =~ /([^\/]+)$/o); |
|
79
|
0
|
|
|
|
|
|
my $cpdir = join("/", $self->{'copy'}, $f); |
|
80
|
0
|
0
|
|
|
|
|
copy($file, $cpdir) or &_set_error("Failed to copy '$file' to $cpdir"); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
0
|
0
|
|
|
|
|
if($self->{'move'}) { |
|
83
|
0
|
0
|
0
|
|
|
|
if(!(-d $self->{'move'}) && $self->{'mkdir'}) { |
|
84
|
0
|
0
|
|
|
|
|
mkdir($self->{'move'}, $self->{'mkdir'}) or &_set_error(join("", "Failed to create directory '", $self->{'move'}, "' $!")); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
0
|
|
|
|
|
|
my ($f) = ($file =~ /([^\/]+)$/o); |
|
87
|
0
|
|
|
|
|
|
my $mvfile = join("/", $self->{'move'}, $f); |
|
88
|
0
|
0
|
|
|
|
|
if(move($file, $mvfile)) { $file = $mvfile; } |
|
|
0
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
else { &_set_error("Failed to move '$file' to '$mvfile'"); } |
|
90
|
|
|
|
|
|
|
} |
|
91
|
0
|
0
|
|
|
|
|
if($self->{'delete'}) { |
|
92
|
0
|
0
|
|
|
|
|
if($file =~ /^(.+)$/s) { |
|
93
|
0
|
0
|
|
|
|
|
unlink($1) or &_set_error("Could not delete $1: $!"); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
0
|
|
|
|
|
|
return($res); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub set_callback { |
|
101
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
102
|
0
|
|
0
|
|
|
|
my $subref = shift || undef; |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
0
|
0
|
|
|
|
if(defined($subref) && ref($subref) eq "CODE") { |
|
|
|
0
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->{'callback'} = $subref; |
|
106
|
|
|
|
|
|
|
} elsif(exists($self->{'callback'})) { |
|
107
|
0
|
|
|
|
|
|
delete($self->{'callback'}); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
0
|
|
|
|
|
|
return(); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _set_error { |
|
113
|
0
|
|
0
|
0
|
|
|
$ERROR = shift || ""; |
|
114
|
0
|
|
|
|
|
|
return(); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _set_skip { |
|
118
|
0
|
|
0
|
0
|
|
|
$SKIPPED = shift || 0; |
|
119
|
0
|
|
|
|
|
|
return(); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _set_suspicious { |
|
123
|
0
|
|
0
|
0
|
|
|
$SUSPICIOUS = shift || 0; |
|
124
|
0
|
|
|
|
|
|
return(); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub ret_callback { |
|
128
|
0
|
|
0
|
0
|
0
|
|
$CALLBACK = shift || ""; |
|
129
|
0
|
|
|
|
|
|
return(); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
0
|
1
|
|
sub error { $ERROR; } |
|
133
|
0
|
|
|
0
|
1
|
|
sub skipped { $SKIPPED; } |
|
134
|
0
|
|
|
0
|
1
|
|
sub suspicious { $SUSPICIOUS; } |
|
135
|
0
|
|
|
0
|
1
|
|
sub callback { $CALLBACK; } |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__DATA__ |