From 9462d1b49fef13ff5d6d0ab9cea76128559a7c3c Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 20 Jan 2011 19:12:55 +0100 Subject: [PATCH] first try at decoding MIFARE Application Directory --- mifare-mad.pl | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 mifare-mad.pl diff --git a/mifare-mad.pl b/mifare-mad.pl new file mode 100755 index 0000000..c6e3bed --- /dev/null +++ b/mifare-mad.pl @@ -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} || '?'; +} -- 2.20.1