first try at decoding MIFARE Application Directory
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 20 Jan 2011 18:12:55 +0000 (19:12 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 20 Jan 2011 18:12:55 +0000 (19:12 +0100)
mifare-mad.pl [new file with mode: 0755]

diff --git a/mifare-mad.pl b/mifare-mad.pl
new file mode 100755 (executable)
index 0000000..c6e3bed
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+# based on AN10787
+# MIFARE Application Directory (MAD)
+
+
+use Data::Dump qw(dump);
+
+# http://www.nxp.com/acrobat_download2/other/identification/MAD_overview.pdf
+my $mad_id = {
+       0x0000 => 'sector free',
+       0x0001 => 'sector defective',
+       0x0002 => 'sector reserved',
+       0x0003 => 'DIR continuted',
+       0x0004 => 'card holder',
+       # ...
+       0x0015 => 'card administration - MIKROELEKTRONIKA spol.s.v.M',
+
+       0x071D => 'miscellaneous applications - ZAGREBACKI Holding d.o.o. [1] Customer profile',
+       0x071E => 'miscellaneous applications - ZAGREBACKI Holding d.o.o. [1] Bonus counter',
+
+       0x1837 => 'city traffic - ZAGREBACKI Holding d.o.o. [1] Prepaid coupon',
+
+       0x2062 => 'bus services - ZAGREBACKI Holding d.o.o. [1] electronic ticket',
+
+       0x887B => 'electronic purse - ZAGREBACKI Holding d.o.o. [4]',
+};
+
+local $/ = undef;
+my $card = <>;
+
+die "expected 4096 bytes, got ",length($card), " bytes\n"
+       unless length $card == 4096;
+
+foreach my $i ( 0 .. 15 ) {
+       my $v = unpack('v',(substr($card, 0x10 + ( $i * 2 ), 2)));
+       printf "MAD sector %-2d %04x %s\n", $i, $v, $mad_id->{$v} || '?';
+}