Deutsch   English   Français   Italiano  
<ZZudndD3wtZu5aH-nZ2dnZfqlJxg4p2d@giganews.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 04 Oct 2022 18:18:27 +0000
Newsgroups: fr.comp.lang.python
Subject: Script Python ne fonctionne pas
X-poster: PEAR::Net_NNTP v1.5.0 (stable)
From: Pebrok <nospam_pebrok1@gmail.com.invalid>
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit
Organization: !No_Organization!
Message-ID: <ZZudndD3wtZu5aH-nZ2dnZfqlJxg4p2d@giganews.com>
Date: Tue, 04 Oct 2022 18:18:27 +0000
Lines: 98
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-wUyutUCv7eBLGX7+NRWJ2N+APUYOkgZod+uXkWWqS159C1/bXaOprPk2HGKxWx8JzoPv4wwMx9QzuSk!2nXwB8rnLPnK/xFKnj3if1TSV41Zah4girrDbLri7/V4H2gAo9hdUl4HMGqu+UP6uE5L+JJG9ZHm
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Bytes: 3711
X-Original-Lines: 97

Bonjour, j'ai récupéré un script Python pour convertir un fichier .json en
fichier .nfc, mais quand je le passe dans IDLE et que k'essaie de le faire
tourner, rien ne se passe.
J'ai mis tous les fichiers (script .py et fichier .json) dans le même dossier. 
C:UsersCJ78714Python>

J'essaie de vous joindre le script ci-dessous: 
#!/usr/local/bin/python3

"""
    Reads: proxmark3 MiFare json dump files
    Outputs: Flipper NFC compatable format

    nfc_prox2flip.py Gate25.json > Gate25.nfc

    Written By: Peter Shipley github.com/evilpete

    From pkg https://github.com/evilpete/flipper_toolbox
"""

import sys
import json


# Nfc device type can be UID, Mifare Ultralight, Mifare Classic, Bank card
# ATQA SAK
CARD_TYPE = {
    ("0400", "08"): "Mifare Classic",      # 1k
    ("0200", "18"): "Mifare Classic",      # 1k
    ("0400", "09"): "Mifare Mini",
    ("4400", "00"): "Mifare Ultralight",   # "NTAG213" "NTAG216"
    ("4400", "20"): "Bank card",
    ("4403", "20"): "Mifare DESFire",
}


def convert_dat(in_dat):
    """
        Take a parsed proxmark json dump arg
        returns list in Flipper NFC compatable format
    """

    # output list
    out_dat = []

    x = in_dat["Card"]

    # Guess card type by looking at ATQA/SAK combo
    j = (x['ATQA'], x['SAK'])

    t = CARD_TYPE.get(j, x['UID'])

    # this is a hack to generate Key maps
    # should add code to actually parse "SectorKeys"
    y = len(in_dat["SectorKeys"])
    s = int("1" * y, 2)
    ska = skb = f"{s:016X}"

    out_dat.append(f"""
Filetype: Flipper NFC device
Version: 2
# generated with flipper_toolbox
# Nfc device type can be UID, Mifare Ultralight, Mifare Classic, Bank card
Device type: {t}
# UID, ATQA and SAK are common for all formats
UID: {x['UID'][0:2]} {x['UID'][2:4]} {x['UID'][4:6]} {x['UID'][6:8]}
ATQA: {x['ATQA'][0:2]} {x['ATQA'][2:4]}
SAK: {x['SAK']}
# Mifare Classic specific data
Mifare Classic type: 1K
Data format version: 1
# Key map is the bit mask indicating valid key in each sector
Key A map: {ska}
Key B map: {skb}
# Mifare Classic blocks""")

    # Loop through blocks spliting data into 1 byte pieces
    for k, v in in_dat["blocks"].items():
        b = " ".join([v[i:i + 2] for i in range(0, len(v), 2)])
        out_dat.append(f"Block {k}: {b}")

    return out_dat


if __name__ == '__main__':

    in_filename = "Gate25.json"

    if len(sys.argv) > 2:
        in_filename = int(sys.argv[2])

    with open(in_filename, encoding="utf-8") as fd:
        input_dat = json.load(fd)

    output_list = convert_dat(input_dat)

    print("n".join(output_list))

    sys.exit()