X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=mifare-mad.pl;h=5319f2c5b5aa547d638b3021b6bbe6ac15da93b7;hb=bffc5fe4ca42fbeb7577657b1b9f058030011329;hp=d5dd772d2cce8920598a47baa0afc69c7426b2b4;hpb=884f0b0bf7278d8223e0e9f341ffa5dfca3be0a5;p=perl-Mifare-MAD.git diff --git a/mifare-mad.pl b/mifare-mad.pl index d5dd772..5319f2c 100755 --- a/mifare-mad.pl +++ b/mifare-mad.pl @@ -74,6 +74,8 @@ foreach my $sector ( 0 .. 39 ) { my $blocks = $sector < 32 ? 4 : 16; + next if substr($card,$pos,$blocks * 0x10) eq "\x00" x ($blocks * 0x10); + # General purpose byte (GPB) my $GBP = ord(substr($card,0x39,1)); @@ -88,7 +90,7 @@ foreach my $sector ( 0 .. 39 ) { $ADV = $GBP & 0b00000011; $MA = $GBP & 0b01000000; $DA = $GBP & 0b10000000; - printf "ADV (MAD version code): %d %s\n", $ADV, + printf "ADV (MAD version code): %d %s\n", $ADV; printf "MA (multiapplication): %s\n", $MA ? 'yes' : 'monoaplication'; printf "DA (MAD available): %s%s\n", $DA ? 'yes' : 'no', substr($card,$pos+0x30,6) eq "\xA0\xA1\xA2\xA3\xA4\xA5" ? ' public' : ''; @@ -136,7 +138,7 @@ foreach my $sector ( 0 .. 39 ) { my $c2 = ( ord(substr($card,$trailer_pos+8,1)) & 0x0f ); my $c3 = ( ord(substr($card,$trailer_pos+8,1)) & 0xf0 ) >> 4; - printf "# trailer @%x c1:%d c2:%d c3:%d [%16b]\n" + printf "# trailer @%x c1:%d c2:%d c3:%d [%016b]\n" , $trailer_pos, $c1, $c2, $c3 , unpack('n',(substr($card,$trailer_pos+7,2))) ; @@ -155,7 +157,7 @@ foreach my $sector ( 0 .. 39 ) { my $hex = unpack('H*',$block); $hex =~ s/(....)/$1 /g; - if ( $ENV{SWAP} && $j < 3 ) { + if ( $ENV{SWAP} && $j < $blocks - 1 ) { my $hex_sw = unpack('h*',$block); $hex_sw =~ s/(....)/$1 /g; $hex .= " | $hex_sw"; @@ -169,10 +171,10 @@ foreach my $sector ( 0 .. 39 ) { printf "KEY A:%s | %s GDP: %s | B:%s\n" - ,unpack('H*',substr($card,$pos+0x30 ,6)) - ,unpack('H*',substr($card,$pos+0x30+6 ,3)) - ,unpack('H*',substr($card,$pos+0x30+9 ,1)) - ,unpack('H*',substr($card,$pos+0x30+10,6)) + ,unpack('H*',substr($card,$trailer_pos ,6)) + ,unpack('H*',substr($card,$trailer_pos+6 ,3)) + ,unpack('H*',substr($card,$trailer_pos+9 ,1)) + ,unpack('H*',substr($card,$trailer_pos+10,6)) ; print "\n";