mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-25 01:18:15 +00:00
Add XML support for keepass keyfile and improve performance by not using chdir()
This commit is contained in:
parent
fd5700a607
commit
e363bf787e
57
tools/recursivefiles2sha256sum.pl
Normal file → Executable file
57
tools/recursivefiles2sha256sum.pl
Normal file → Executable file
@ -16,6 +16,7 @@ use strict;
|
||||
use warnings;
|
||||
use File::Find;
|
||||
use Digest::SHA;
|
||||
use XML::Simple;
|
||||
|
||||
my $sha = Digest::SHA->new ("sha256");
|
||||
|
||||
@ -26,7 +27,13 @@ if (scalar @folders == 0)
|
||||
die ("use: $0 folder1 folder2...\n");
|
||||
}
|
||||
|
||||
find (\&handlefile, @folders);
|
||||
my $conf =
|
||||
{
|
||||
wanted => \&handlefile,
|
||||
no_chdir => 1,
|
||||
};
|
||||
|
||||
find ($conf, @folders);
|
||||
|
||||
sub handlefile
|
||||
{
|
||||
@ -35,11 +42,51 @@ sub handlefile
|
||||
return unless -f $file;
|
||||
return unless -r $file;
|
||||
|
||||
my $sha_copy = $sha->clone;
|
||||
open (my $fh, $file) or return;
|
||||
|
||||
$sha_copy->addfile ($file);
|
||||
binmode $fh;
|
||||
|
||||
my $digest = $sha_copy->hexdigest;
|
||||
my $nread = read ($fh, my $data, 5);
|
||||
|
||||
print "$digest\n";
|
||||
close ($fh);
|
||||
|
||||
my $xmlhash;
|
||||
|
||||
if (($nread == 5) && ($data eq "<?xml"))
|
||||
{
|
||||
my $xml = eval { XMLin ($file) or die };
|
||||
|
||||
if ($@)
|
||||
{
|
||||
# not interesting
|
||||
}
|
||||
else
|
||||
{
|
||||
if (exists $xml->{"Key"} && exists $xml->{"Key"}->{"Data"})
|
||||
{
|
||||
chomp $xml->{"Key"}->{"Data"};
|
||||
|
||||
$xmlhash = $xml->{"Key"}->{"Data"};
|
||||
}
|
||||
else
|
||||
{
|
||||
# not interesting
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defined $xmlhash)
|
||||
{
|
||||
print "$xmlhash\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
my $sha_copy = $sha->clone;
|
||||
|
||||
$sha_copy->addfile ($file);
|
||||
|
||||
my $digest = $sha_copy->hexdigest;
|
||||
|
||||
print "$digest\n";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user