Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use constant { STAT_DEVNO=>0, STAT_INO=>1, STAT_MODE=>2, STAT_LINKS=>3, STAT_UID=>4, STAT_GID=>5, STAT_DEVIDENT=>6, STAT_SIZE=>7, STAT_ATIME=>8, STAT_MTIME=>9, STAT_CTIME=>10, STAT_PREFBLKSZ=>11, STAT_BLOCKS=>12 };
- use Digest::MD5;
- $SIG{'USR1'} = sub { print STDERR "Processing: $FILE\n"; };
- sub walkdir
- {
- my $dir = shift;
- opendir my $dh, $dir;
- while(my $entry = readdir $dh)
- {
- my $file = "$dir/$entry";
- $FILE = $file;
- if(-f $file)
- {
- my ($size) = (stat $file)[STAT_SIZE];
- if($size > 1_000_000)
- {
- if(open my $fh, '<', $file)
- {
- read $fh, my $sign, 4;
- if($sign eq "\x{7F}ELF")
- {
- seek $fh, 0, 0;
- my $ctx = Digest::MD5->new;
- $ctx->addfile($fh);
- my $digest = $ctx->hexdigest;
- if(grep { $digest eq $_ } @ARGV)
- {
- print "$digest $file\n";
- }
- }
- close $fh;
- }
- else
- {
- warn "Can not open $file: $!\n";
- }
- }
- }
- elsif(-d $file and ! -l $file)
- {
- if($entry !~ /^\.\.?$/)
- {
- walkdir($file);
- }
- }
- }
- closedir $dh;
- }
- walkdir(shift @ARGV);
Advertisement
Add Comment
Please, Sign In to add comment