X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=nfc-card-dumper.pl;h=5397f06c5b0ecb99c5697ae4a8dfa85948de64f4;hb=117ad2e869b1f7ad6485e60dce85f691b301e081;hp=ffdecc960c2af39f5d65facd059e51848665372d;hpb=d1fb53c418af9be9c98f53f4bc77e760adfcf313;p=perl-Mifare-MAD.git diff --git a/nfc-card-dumper.pl b/nfc-card-dumper.pl index ffdecc9..5397f06 100755 --- a/nfc-card-dumper.pl +++ b/nfc-card-dumper.pl @@ -6,9 +6,18 @@ use RFID::Libnfc::Reader; use RFID::Libnfc::Constants; use File::Slurp; use Digest::MD5 qw(md5_hex); +use Getopt::Long::Descriptive; use Data::Dump qw(dump); +my ($opt,$usage) = describe_options( + '%c %c [dump_with_keys]', + [ 'write=s', 'write dump to card' ], + [ 'debug|d', 'show debug dumps' ], + [ 'help|h', 'usage' ], +); +print $usage->text, exit if $opt->help; + my $debug = $ENV{DEBUG} || 0; my $keyfile = shift @ARGV; @@ -39,7 +48,7 @@ if ($r->init()) { my $card; - print STDERR "$uid reading blocks "; + print STDERR "reading $uid blocks "; for (my $i = 0; $i < $tag->blocks; $i++) { if (my $data = $tag->read_block($i)) { # if we are dumping an ultralight token, @@ -87,7 +96,7 @@ if ($r->init()) { } my $md5 = md5_hex($card); - my $out_file = "cards/$uid.$md5"; + my $out_file = "cards/$uid.$md5.mfd"; if ( -e $out_file ) { warn "$out_file allready exists, not overwriting\n"; } else { @@ -100,8 +109,21 @@ if ($r->init()) { } } - # view dump - system "./mifare-mad.pl $out_file > $out_file.txt"; - $ENV{MAD} && system "vi $out_file.txt"; + if ( $opt->write ) { + my $card = read_file $opt->write; + print STDERR "writing $uid block "; + foreach my $block ( 0 .. $tag->blocks ) { + my $offset = 0x10 * $block; + $tag->write_block( $block, substr($card,$offset,0x10) ); + print STDERR "$block "; + } + print STDERR "done\n"; + } else { + # view dump + my $txt_file = $out_file; + $txt_file =~ s/\.mfd/.txt/ || die "can't change extension to txt"; + system "./mifare-mad.pl $out_file > $txt_file"; + $ENV{MAD} && system "vi $txt_file"; + } }