Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 74 lines (66 sloc) 2.123 kb
447c384 first commit
Adam Laurie authored
1 #!/usr/bin/python
2
3 # writemifare1k.py - write all blocks on a mifare standard tag
4 #
5 # Adam Laurie <adam@algroup.co.uk>
6 # http://rfidiot.org/
7 #
8 # This code is copyright (c) Adam Laurie, 2006, All rights reserved.
9 # For non-commercial use only, the following terms apply - for all other
10 # uses, please contact the author:
11 #
12 # This code is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This code is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22
23
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but important d...
authored
24 import rfidiot
447c384 first commit
Adam Laurie authored
25 import sys
26 import random
27 import string
28 import os
29
30 try:
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but important d...
authored
31 card= rfidiot.card
447c384 first commit
Adam Laurie authored
32 except:
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but important d...
authored
33 print "Couldn't open reader!"
447c384 first commit
Adam Laurie authored
34 os._exit(True)
35
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but important d...
authored
36 args= rfidiot.args
37 help= rfidiot.help
447c384 first commit
Adam Laurie authored
38
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but important d...
authored
39 card.info('writemifare1k v0.1f')
447c384 first commit
Adam Laurie authored
40 card.select()
41 print 'Card ID: ' + card.uid
42 while True:
43 x= string.upper(raw_input('\n*** Warning! This will overwrite all data blocks! Proceed (y/n)? '))
44 if x == 'N':
45 os._exit(False)
46 if x == 'Y':
47 break
48
49 sector = 1
50 while sector < 0x10:
51 for type in ['AA', 'BB', 'FF']:
52 card.select()
53 print ' sector %02x: Keytype: %s' % (sector, type),
54 if card.login(sector,type,'FFFFFFFFFFFF'):
55 for block in range(3):
56 print '\n block %02x: ' % ((sector * 4) + block),
57 if len(args) == 1:
58 data= args[0]
59 else:
60 data = '%032x' % random.getrandbits(128)
61 print 'Data: ' + data,
62 if card.writeblock((sector * 4) + block,data):
63 print ' OK'
64 elif card.errorcode:
65 print 'error %s %s' % (card.errorcode , card.ISO7816ErrorCodes[card.errorcode])
66 elif type == 'FF':
67 print 'login failed'
68 print '\r',
69 sys.stdout.flush()
70 sector += 1
71 print
72 print
73 os._exit(False)
Something went wrong with that request. Please try again.