Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script for converting NTAG215 dumps (.bin) to Flipper NFC device files (.nfc)
#!/usr/bin/env python
import sys
from os.path import splitext, basename
if len(sys.argv) < 2:
sys.exit('Usage: %s dump.bin' % sys.argv[0])
ntag_file = sys.argv[1]
nfc_file = splitext(ntag_file)[0] + '.nfc'
print('Converting "%s" -> "%s" ... ' % (basename(ntag_file), basename(nfc_file)), end = '')
try:
with open(ntag_file, 'rb') as file:
ntag_data = file.read()
if len(ntag_data) != 540:
raise RuntimeError('Incorrect NTAG215 dump size (expect 540 bytes, got %d bytes)' % len(ntag_data))
nfc_device_header = [
'# Auto-generated by amiibin2nfcdev.py',
'Filetype: Flipper NFC device',
'Version: 2',
'Device type: Mifare Ultralight',
'UID: {uid}',
'ATQA: 44 00',
'SAK: 00',
'Signature: {sig}',
'Mifare version: 00 04 04 02 01 00 11 03',
'Counter 0: 0',
'Tearing 0: 00',
'Counter 1: 0',
'Tearing 1: 00',
'Counter 2: 0',
'Tearing 2: 00',
'Pages total: 135'
]
nfc_device_pages = []
for i in range(0, len(ntag_data), 4):
nfc_device_pages.append('Page %d: %02X %02X %02X %02X' % (i / 4, *ntag_data[i:i + 4]))
nfc_device_uid = ' '.join(['%02X' % x for x in ntag_data[:7]])
nfc_device_sig = ' '.join(['00'] * 32)
nfc_device = '\n'.join(nfc_device_header + nfc_device_pages)
nfc_device = nfc_device.format(uid=nfc_device_uid, sig=nfc_device_sig)
with open(nfc_file, 'w') as file:
file.write(nfc_device + '\n')
print('OK!')
except Exception as e:
print('ERROR!\n%s' % e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment