diff --git a/ErrorCodes.py b/ErrorCodes.py index 97565f8cfc98fe707f790c6b21b105c10c7da9ce..a1c1e67d774686bfa11fb4c5dd15b634b09c1841 100644 --- a/ErrorCodes.py +++ b/ErrorCodes.py @@ -75,13 +75,13 @@ DESFIRE_ERROR_CODES = { 0xBBF : 'COMMIT_TRANSACTION_NO_REPLY', #// 3007 [dec] 0x0BC0 : 'COMMIT_TRANSACTION_ERROR', #// 3008 [dec] 0x0C0C : 'DESFIRE_CARD_NO_CHANGES', - 0x0C03 : 'DESFIRE_CARD_OUT_OF_EEPROM_ERROR', + 0x0C0E : 'DESFIRE_CARD_OUT_OF_EEPROM_ERROR', 0x0C1C : 'DESFIRE_CARD_ILLEGAL_COMMAND_CODE', 0x0C1E : 'DESFIRE_CARD_INTEGRITY_ERROR', 0x0C40 : 'DESFIRE_CARD_NO_SUCH_KEY', 0x0C7E : 'DESFIRE_CARD_LENGTH_ERROR', 0x0C9D : 'DESFIRE_CARD_PERMISSION_DENIED', - 0x0C93 : 'DESFIRE_CARD_PARAMETER_ERROR', + 0x0C9E : 'DESFIRE_CARD_PARAMETER_ERROR', 0x0CA0 : 'DESFIRE_CARD_APPLICATION_NOT_FOUND', 0x0CA1 : 'DESFIRE_CARD_APPL_INTEGRITY_ERROR', 0x0CAE : 'DESFIRE_CARD_AUTHENTICATION_ERROR', diff --git a/Functions.py b/Functions.py index 52f354901526e89d9da820983605b770e5f1107e..b6404f25fb6579dd6f7db8ce5eecda448449f49c 100644 --- a/Functions.py +++ b/Functions.py @@ -1318,4 +1318,44 @@ def ReadStdFile(): for x in range(file_length): hex_str = ('%x' % data[x]).upper() #f.write(('0x%02x' % data[x]).upper()) - f.write(hex_str) \ No newline at end of file + f.write(hex_str) + +################################################################################ + +def getDesfireApplicationIDs(): + application_ids = (c_uint32*128)() + number_of_application_ids = c_ubyte(0) + card_status = c_uint32() + exec_time = c_uint32() + print_ids = "Application IDs: " # string used to print out IDs stored in array + + if globals.internal_key == False: + pk_key = (c_ubyte*16)() + pk_key = PrepareKey(pk_key) + else: + aes_key_nr = int(globals.settings[4]) + + if globals.master_authent_req == True: + if globals.internal_key == True: + getIDsFunc = uFR.uFR_int_DesfireGetApplicationIds + getIDsFunc.argtypes = [c_ubyte, (c_uint32*128), POINTER(c_ubyte), POINTER(c_uint32), POINTER(c_uint32)] + status = getIDsFunc(aes_key_nr, application_ids, byref(number_of_application_ids), byref(card_status), byref(exec_time)) + else: + getIDsFunc = uFR.uFR_int_DesfireGetApplicationIds_PK + getIDsFunc.argtypes = [(c_ubyte*16), (c_uint32*128), POINTER(c_ubyte), POINTER(c_uint32), POINTER(c_uint32)] + status = getIDsFunc(pk_key, application_ids, byref(number_of_application_ids), byref(card_status), byref(exec_time)) + else: + getIDsFunc = uFR.uFR_int_DesfireGetApplicationIds_no_auth + getIDsFunc.argtypes = [(c_uint32*128), POINTER(c_ubyte), POINTER(c_uint32), POINTER(c_uint32)] + status = getIDsFunc(application_ids, byref(number_of_application_ids), byref(card_status), byref(exec_time)) + + if card_status.value == 3001: + print("Getting application IDs successfull") + print("Number of IDs: " + str(number_of_application_ids.value)) + print(" Application IDs: ") + for x in range(number_of_application_ids.value): + print_ids += str(application_ids[x]) + "," + print(print_ids[:-1]) + print("Function status: " + ErrorCodes.UFCODER_ERROR_CODES[status]) + print("Card status: " + DESFIRE_ERROR_CODES[card_status.value]) + print("Execution time: " + str(exec_time.value) + " ms.") \ No newline at end of file diff --git a/__pycache__/ErrorCodes.cpython-37.pyc b/__pycache__/ErrorCodes.cpython-37.pyc index f160b9f5e020448b781b6ae210937639a6892889..6b91a8ef8144b002e1a41d7883ca974c64607f8e 100644 Binary files a/__pycache__/ErrorCodes.cpython-37.pyc and b/__pycache__/ErrorCodes.cpython-37.pyc differ diff --git a/__pycache__/Functions.cpython-37.pyc b/__pycache__/Functions.cpython-37.pyc index 72fcb9d76633d628b44deddaa7cacbaa9ab48f8d..94eb44266f57e00bfae8111e364a72ae28a8c5f2 100644 Binary files a/__pycache__/Functions.cpython-37.pyc and b/__pycache__/Functions.cpython-37.pyc differ diff --git a/__pycache__/desfire_example.cpython-37.pyc b/__pycache__/desfire_example.cpython-37.pyc index cee6e4f3e4dbc5a873b19f26634ddc77b4606a65..c4ac79ca8b0b1008c425793d357746dee73b8159 100644 Binary files a/__pycache__/desfire_example.cpython-37.pyc and b/__pycache__/desfire_example.cpython-37.pyc differ diff --git a/__pycache__/globals.cpython-37.pyc b/__pycache__/globals.cpython-37.pyc index 19a7524167b5c8c41f4f6ff3a9ebac636603e28d..7710923cae8a24f9577a88b38162e39f27cd162d 100644 Binary files a/__pycache__/globals.cpython-37.pyc and b/__pycache__/globals.cpython-37.pyc differ diff --git a/desfire_example.py b/desfire_example.py index e508ada80ff0f792cf84e9c935ecf93f9263f606..b6ad502d796a54f15001b583a8a0692464e692f6 100644 --- a/desfire_example.py +++ b/desfire_example.py @@ -5,7 +5,6 @@ import platform import os import array import ErrorCodes -import msvcrt from Functions import * import globals import struct @@ -212,15 +211,16 @@ def usage(): print(" (d) - Change AES key") print(" (e) - Change key settings") print(" (f) - Get key settings") - print(" (g) - Make application") - print(" (h) - Delete application") - print(" (j) - Make file") - print(" (k) - Delete file") - print(" (l) - Write Std file") - print(" (m) - Read Std file") - print(" (n) - Read Value file") - print(" (o) - Increase Value file") - print(" (p) - Decrease Value file") + print(" (g) - Get application IDs on card") + print(" (h) - Make application") + print(" (j) - Delete application") + print(" (k) - Make file") + print(" (l) - Delete file") + print(" (m) - Write Std file") + print(" (n) - Read Std file") + print(" (o) - Read Value file") + print(" (p) - Increase Value file") + print(" (q) - Decrease Value file") print(" (r) - Change config parameters\n"); print(" --------------------------------------------------") @@ -283,30 +283,33 @@ def menu(key): print("GetKeySettings()") GetKeySettings() elif key == 'g': + print("getDesfireApplicationIDs()") + getDesfireApplicationIDs() + elif key == "h": print("MakeApplication()") MakeApplication() - elif key == 'h': + elif key == 'j': print("DeleteApplication()") DeleteApplication() - elif key == 'j': + elif key == 'k': print("MakeFile()") MakeFile() - elif key == 'k': + elif key == 'l': print("DeleteFile()") DeleteFile() - elif key == 'l': + elif key == 'm': print("WriteStdFile()") WriteStdFile() - elif key == 'm': + elif key == 'n': print("ReadStdFile()") ReadStdFile() - elif key == 'n': + elif key == 'o': print("ReadValueFile") ReadValueFile() - elif key == 'o': + elif key == 'p': print("IncreaseValueFile()") IncreaseValueFile() - elif key == 'p': + elif key == 'q': print("DecreaseValueFile()") DecreaseValueFile() elif key == 'r': @@ -326,10 +329,11 @@ def menu(key): def ReaderOpenEx(reader_type, port_name, port_interface, arg): openReader = uFR.ReaderOpenEx - openReader.argtypes = (c_uint32, c_char_p, c_uint32, c_void_p) + openReader.argtypes = (c_uint32, c_char_p, c_uint32, c_char_p) openReader.restype = c_uint b = c_char_p(port_name.encode('utf-8')) - return openReader(reader_type, b, port_interface, arg) + c = c_char_p(arg.encode('utf-8')) + return openReader(reader_type, b, port_interface, c) ##########################################################################