Converting nfc file to Mifare Classic binary

Hi guys do you know if there exists a script to convert the Flipper recorded nfc to bin format to be usable with CameleonMini.
There exists ClassicConverter to convert bin files to Flipper supported nfc files.

Vote for this … as flipper can’t write it would be cool to have a way to convert the files saved by flipper to write with other tools like ICopy and Proxmark3

i’ll add it to classic converter soon

1 Like

I just mocked up the script based on the original 4b_Converter have a look.
I’m no programmer, especially no python.
nfc_to_bin.zip (1004 Bytes)


import argparse
import os
import pathlib
import time

def write_output(name: str, assemble: bytes, out_dir: str):
    #out = bytearray(assemble,"ascii")
    with open(os.path.join(out_dir, f"{name}.bin"), "wb") as f:
        f.write(assemble)

def convert_file(input_path: str, output_path: str):
    input_extension = os.path.splitext(input_path)[1]
    if input_extension == ".nfc":
        with open(input_path, "rt") as file:
            contents = file.read()
            name = os.path.split(input_path)[1]
            data_init = contents[contents.find("Block 0"):].split(sep="\n")
            buff = bytes()
            for line in data_init:
                block = line[line.find(":")+2:].replace(" ", "")
                buff = buff + bytearray.fromhex(block)
            write_output(name.split(".nfc")[0], buff, output_path)

def process(path: str, output_path: str):
    if os.path.isfile(path):
        convert_file(path, output_path)
    else:
        for filename in os.listdir(path):
            new_path = os.path.join(path, filename)

            if os.path.isfile(path):
                convert_file(path, output_path)
            else:
                process(new_path, output_path)


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-i",
        "--input-path",
        required=True,
        type=pathlib.Path,
        help="Single file or directory path to convert",
    )
    parser.add_argument(
        "-o",
        "--output-path",
        required=False,
        type=pathlib.Path,
        help="Output path, if not specified, the output .nfc file will be created in the same directory the .bin file exists within.",
    )

    args = parser.parse_args()
    return args


def main():
    args = get_args()

    if os.path.isfile(args.input_path):
        if not args.output_path:
            args.output_path = os.path.split(args.input_path)[0]
    
    # os.makedirs(args.output_path, exist_ok=True)
    process(args.input_path, args.output_path)


if __name__ == "__main__":
    main()
    print("Converting...")
    time.sleep(0.3)
    print("Completed Conversion")

1 Like

If you are fair with linux, people use xxd to convert hexadump to binary and reverse. There’s lots of info to read if you want to do that. Pretty straightforward with the correct dependencies.