Skip to content

Instantly share code, notes, and snippets.

@ghettorce
Last active September 2, 2023 12:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ghettorce/0cf426541a83c159efd1f9adeb499761 to your computer and use it in GitHub Desktop.
Save ghettorce/0cf426541a83c159efd1f9adeb499761 to your computer and use it in GitHub Desktop.
Script for converting NTAG215 dumps (.bin) to Flipper NFC device files (.nfc)
#!/usr/bin/env python3
import sys
from os.path import splitext, basename
if not sys.argv[1:]:
sys.exit(f'Usage: {sys.argv[0]} dump.bin')
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: 3',
'# Nfc device type can be UID, Mifare Ultralight, Mifare Classic or ISO15693',
'Device type: NTAG215',
'# UID is common for all formats',
'UID: {uid}',
'# ISO14443 specific fields',
'ATQA: 00 44',
'SAK: 00',
'# Mifare Ultralight specific data',
'Data format version: 1',
'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',
'Pages read: 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)
@ghettorce
Copy link
Author

Get-ChildItem -Recurse *.bin | ForEach { python PATH/TO/amiibin2nfcdev.py $_.FullName }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment