1
mirror of https://github.com/hashcat/hashcat synced 2024-11-24 14:27:14 +01:00

Add XML support for keepass keyfile and improve performance by not using chdir()

This commit is contained in:
Jens Steube 2022-08-25 20:33:10 +02:00
parent fd5700a607
commit e363bf787e

49
tools/recursivefiles2sha256sum.pl Normal file → Executable file
View 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,6 +42,45 @@ sub handlefile
return unless -f $file;
return unless -r $file;
open (my $fh, $file) or return;
binmode $fh;
my $nread = read ($fh, my $data, 5);
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);
@ -43,3 +89,4 @@ sub handlefile
print "$digest\n";
}
}