Created
May 7, 2023 17:29
-
-
Save ardubev16/339ee55e0e610e9241dd236c11ac3c3d to your computer and use it in GitHub Desktop.
Convert Flipper Zero Mifare Classic 1k & 4k dumps to MCT (Mifare Classic Tools). Fixed version (for 4k) of https://github.com/whyn0/FlipperNFC2MCT
This file contains 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 argparse | |
import re | |
import logging | |
logging.basicConfig( | |
level=logging.INFO, | |
format="[%(levelname)s] %(message)s", | |
) | |
parser = argparse.ArgumentParser( | |
description="[+] Process Mifare Classic 1k & 4k dumps from Flipper Zero to MCT format" | |
) | |
parser.add_argument("source", help="Flipper Zero dump") | |
parser.add_argument("destination", help="MCT filename") | |
args = parser.parse_args() | |
pattern = r"Block (\d{1,3}): (\w\w \w\w \w\w \w\w \w\w \w\w \w\w \w\w \w\w \w\w \w\w \w\w \w\w \w\w \w\w \w\w)" | |
def is_new_sector(sector_counter: int, block: int) -> bool: | |
is_small_sector = sector_counter <= 31 and block % 4 == 0 | |
is_big_sector = sector_counter > 31 and block % 16 == 0 | |
return is_small_sector or is_big_sector | |
with open(args.source, "r") as f: | |
source = f.read() | |
destination = [] | |
sector_counter = 0 | |
for line in source.split("\n")[:-1]: | |
if line.lstrip()[0] == "#": | |
continue | |
try: | |
result = re.search(pattern, line) | |
data = result.group(2).replace(" ", "") | |
block = int(result.group(1)) | |
if is_new_sector(sector_counter, block): | |
destination.append(f"+Sector: {sector_counter}") | |
sector_counter += 1 | |
destination.append(f"{data}") | |
except: | |
logging.warning(f"Failed to parse line: {line}") | |
logging.info(f"Writing to {args.destination}") | |
with open(args.destination, "w") as f: | |
f.write("\n".join(destination)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment