Created
May 2, 2024 19:46
-
-
Save GaryOderNichts/970b2a02662369c569d91dc34cf77a56 to your computer and use it in GitHub Desktop.
Scripts to convert data from NFC scan apps to raw bin files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
pattern = r"^\[ ([0-9A-F]{2}):([0-9A-F]{2}):([0-9A-F]{2}):([0-9A-F]{2}):([0-9A-F]{2}):([0-9A-F]{2}):([0-9A-F]{2}):([0-9A-F]{2}) \] Addr\. ([0-9A-F]+)+ : .*" | |
compiled_regex = re.compile(pattern, re.MULTILINE) | |
with open(sys.argv[1]) as inf: | |
with open(sys.argv[2], "wb") as outf: | |
for l in inf.readlines(): | |
match = compiled_regex.match(l) | |
if match: | |
data = match.groups(1)[0:8] | |
address = int(match.group(2), 16) | |
outf.write(bytearray.fromhex("".join(data))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import xml.etree.ElementTree as ET | |
root = ET.parse(sys.argv[1]).getroot() | |
if root.tag != "scan" and root.tag != "InfoDump": | |
print("unsupported scan format!") | |
sys.exit(1) | |
with open(sys.argv[2], 'wb') as f: | |
if root.tag == "scan": | |
for subsection in root.findall('section/subsection'): | |
# they really changed the capitalization here at some point | |
if subsection.get('title') == "Memory content" or subsection.get('title') == "Memory Content": | |
for block in subsection.findall('block'): | |
address = block.find('address') | |
data = block.find('data') | |
if data != None: | |
f.write(bytearray.fromhex(data.text)) | |
elif root.tag == "InfoDump": | |
for subsection in root.findall('Tag/MemoryTag/Data'): | |
for page in subsection.findall('Page'): | |
f.write(bytearray.fromhex(page.text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment