-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmfclassic_bin_to_nfc.py
More file actions
85 lines (69 loc) · 2.79 KB
/
mfclassic_bin_to_nfc.py
File metadata and controls
85 lines (69 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import argparse
def bytes_to_hex(b):
return ' '.join(f"{x:02X}" for x in b)
def extract_uid(block0):
if block0[0] == 0x88:
uid = bytes_to_hex(block0[1:4] + block0[4:7])
uid_type = 7
else:
uid = bytes_to_hex(block0[0:4])
uid_type = 4
return uid, uid_type
def detect_card_type_and_params(data):
size = len(data)
block0 = data[0:16]
uid, uid_length = extract_uid(block0)
if size == 1024:
if uid_length == 7:
atqa = "44 00"
sak = "88"
else:
atqa = "04 00"
sak = "08"
return "1K", 64, uid, atqa, sak
elif size == 4096:
atqa = "04 00"
sak = "18"
return "4K", 256, uid, atqa, sak
elif size == 320:
atqa = "04 00"
sak = "09"
return "Mini", 20, uid, atqa, sak
else:
raise ValueError(f"Invalid size: {size} bytes. Expected 320 (Mini), 1024 (1K), or 4096 (4K).")
def convert_dump_to_flipper_format(dump_file, output_file, uid=None):
with open(dump_file, "rb") as f:
data = f.read()
card_type, block_count, extracted_uid, atqa, sak = detect_card_type_and_params(data)
uid = uid or extracted_uid
print(f"[INFO] Type: Mifare Classic {card_type}")
print(f"[INFO] UID: {uid}")
print(f"[INFO] ATQA: {atqa}")
print(f"[INFO] SAK: {sak}")
with open(output_file, "w") as out:
out.write("Filetype: Flipper NFC device\n")
out.write("Version: 4\n")
out.write("# Device type can be ISO14443-3A, ISO14443-3B, ISO14443-4A, ISO14443-4B, ISO15693-3, FeliCa, NTAG/Ultralight, Mifare Classic, Mifare Plus, Mifare DESFire, SLIX, ST25TB, NTAG4xx, Type 4 Tag, EMV\n")
out.write("Device type: Mifare Classic\n")
out.write("# UID, ATQA and SAK are common for all formats\n")
out.write(f"UID: {uid}\n")
out.write(f"ATQA: {atqa}\n")
out.write(f"SAK: {sak}\n")
out.write(f"Mifare Classic type: {card_type}\n")
out.write("Data format version: 2\n")
out.write("# Mifare Classic blocks, '??' means unknown data\n")
for i in range(block_count):
block = data[i*16:(i+1)*16]
out.write(f"Block {i}: {bytes_to_hex(block)}\n")
print(f"[OK] File written: {output_file}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Convert a Mifare Classic dump to a .nfc file for Flipper Zero")
parser.add_argument("-i", "--input", required=True, help="Path to the .dmp file")
parser.add_argument("-o", "--output", required=True, help="Output path for the .nfc file")
parser.add_argument("--uid", help="Custom UID (e.g. FE:3B:17:86)")
args = parser.parse_args()
convert_dump_to_flipper_format(
dump_file=args.input,
output_file=args.output,
uid=args.uid
)