Added MiFare Classic 4K support

This commit is contained in:
2018-07-29 02:41:41 +02:00
parent 1f4cc71845
commit d6e6db0f85

44
wipe.py
View File

@@ -23,41 +23,53 @@ print("Waiting for tag...\n")
while True: while True:
sector = 1 Sector = 1
while True: while True:
(status, TagSize) = RFID.Request(RFID.PICC_REQIDL) (Status, TagSize) = RFID.Request(RFID.PICC_REQIDL)
if status != RFID.MI_OK: if Status != RFID.MI_OK:
continue continue
if TagSize < 1: if TagSize < 1:
print("Can't read tag properly!") print("Can't read tag properly!")
break break
if sector >= TagSize: if Sector >= TagSize:
break break
spacer = "" # Only for formatting
if sector < 10: Spacer = ""
spacer = " " if Sector < 10:
Spacer = " "
print("Wiping sector %s%s ... " % (spacer, sector), end="") print("Wiping sector %s%s ... " % (Spacer, Sector), end="")
# Selecting blocks # Selecting blocks
BlockAddrs = [ (sector * 4), (sector * 4 + 1), (sector * 4 + 2) ] BaseBlockLength = 4
TrailerBlockAddr = (sector * 4 + 3) if Sector < 32:
BlockLength = BaseBlockLength
StartAddr = Sector * BlockLength
else:
BlockLength = 16
StartAddr = 32 * BaseBlockLength + (Sector - 32) * BlockLength
# Writing data BlockAddrs = []
(status, UID) = RFID.Anticoll() for i in range(0, (BlockLength - 1)):
BlockAddrs.append((StartAddr + i))
TrailerBlockAddr = (StartAddr + (BlockLength - 1))
if status != RFID.MI_OK: # Initializing tag
(Status, UID) = RFID.Anticoll()
if Status != RFID.MI_OK:
break break
# Wiping sector
RFID.SelectTag(UID) RFID.SelectTag(UID)
status = RFID.Auth(RFID.PICC_AUTHENT1A, TrailerBlockAddr, KEY, UID) Status = RFID.Auth(RFID.PICC_AUTHENT1A, TrailerBlockAddr, KEY, UID)
if status == RFID.MI_OK: if Status == RFID.MI_OK:
data = bytearray() data = bytearray()
data.extend(bytearray("".ljust(len(BlockAddrs) * 16))) data.extend(bytearray("".ljust(len(BlockAddrs) * 16)))
i = 0 i = 0
@@ -68,7 +80,7 @@ while True:
else: else:
print("NO ACCESS!") print("NO ACCESS!")
RFID.StopCrypto1() RFID.StopCrypto1()
sector += 1 Sector += 1
print("\nTag wiped!") print("\nTag wiped!")
break break