I still haven't worked out how to check for macros yet but the text has been
sorted
#!/usr/bin/perl
use strict;
use warnings;
use Text::Extract::Word;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseXLSX;
use File::Basename;
if (!$ARGV[0]) {
die "Usage: $0 <filename>";
}
if (! -r $ARGV[0]) {
die "Cannot read file";
}
my ($base,$path,$suffix) = fileparse($ARGV[0],'.doc','.docx','.xls','.xlsx');
print "suffix='$suffix'\n";
if ($suffix eq '.doc') {
print "Checking doc\n";
my $file = Text::Extract::Word->new($ARGV[0]);
if (length($file->get_text()) < 5) {
print "virus found\n";
exit 1;
}
}
if ($suffix eq '.docx') {
print "Checking docx\n";
if (length(`/usr/local/bin/docx2txt.pl $ARGV[0] -`) < 5) {
print "virus found\n";
exit 1;
}
}
if ($suffix=~/.xls/) {
print "Checking Excel $suffix\n";
my $parser;
if ($suffix eq '.xls') {
$parser = Spreadsheet::ParseExcel->new();
} else {
$parser = Spreadsheet::ParseXLSX->new();
}
my $workbook = $parser->parse($ARGV[0]);
if ( !defined $workbook ) {
die $parser->error(), ".\n";
}
my $cells=0;
for my $worksheet ( $workbook->worksheets() ) {
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
if ($cell) {
$cells++;
}
if ($cells > 1) {
exit 0;
}
}
}
}
print "virus found\n";
exit 1;
} # xls
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/