-// Tries to identify cardsize.\r
-// Returns <num> where num is:\r
-// -1 unidentified\r
-// 0 - MINI (320bytes)\r
-// 1 - 1K\r
-// 2 - 2K\r
-// 4 - 4K\r
-int GetCardSize()\r
-{\r
- UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};\r
- SendCommand(&c);\r
-\r
- UsbCommand resp;\r
- WaitForResponse(CMD_ACK,&resp);\r
-\r
- if(resp.arg[0] == 0) {\r
- PrintAndLog("iso14443a card select failed");\r
- return -1;\r
- }\r
- \r
- iso14a_card_select_t *card = (iso14a_card_select_t *)resp.d.asBytes;\r
-\r
- PrintAndLog("Trying to detect card size.");\r
- \r
- uint16_t atqa = 0;\r
- uint8_t sak = 0;\r
- atqa = (card->atqa[1] & 0xff) << 8;\r
- atqa += card->atqa[0] & 0xff;\r
- sak = card->sak;\r
- \r
- // https://code.google.com/p/libnfc/source/browse/libnfc/target-subr.c\r
- \r
- PrintAndLog("found ATAQ: %04X SAK: %02X", atqa, sak);\r
- \r
- \r
- // NXP MIFARE Mini 0.3k\r
- if ( ( (atqa & 0xff0f) == 0x0004) && (sak == 0x09) ) return 0;\r
- \r
- // MIFARE Classic 1K\r
- if ( ((atqa & 0xff0f) == 0x0004) && (sak == 0x08) ) return 1;\r
- \r
- // MIFARE Classik 4K\r
- if ( ((atqa & 0xff0f) == 0x0002) && (sak == 0x18) ) return 4;\r
- \r
- // SmartMX with MIFARE 1K emulation \r
- if ( ((atqa & 0xf0ff) == 0x0004) ) return 1;\r
-\r
- // SmartMX with MIFARE 4K emulation \r
- if ( ((atqa & 0xf0ff) == 0x0002) ) return 4; \r
- \r
- // Infineon MIFARE CLASSIC 1K\r
- if ( ((atqa & 0xffff) == 0x0004) && (sak == 0x88) ) return 1;\r
- \r
- // MFC 4K emulated by Nokia 6212 Classic\r
- if ( ((atqa & 0xffff) == 0x0002) && (sak == 0x38) ) return 4;\r
-\r
- // MFC 4K emulated by Nokia 6131 NFC\r
- if ( ((atqa & 0xffff) == 0x0008) && (sak == 0x38) ) return 4;\r
-\r
- \r
- PrintAndLog("BEFOOO 1K %02X", (atqa & 0xff0f));\r
- \r
- // MIFARE Plus (4 Byte UID or 4 Byte RID)\r
- // MIFARE Plus (7 Byte UID)\r
- if (\r
- ((atqa & 0xffff) == 0x0002) |\r
- ((atqa & 0xffff) == 0x0004) |\r
- ((atqa & 0xffff) == 0x0042) | \r
- ((atqa & 0xffff) == 0x0044) \r
- )\r
- {\r
- switch(sak){\r
- case 0x08:\r
- case 0x10: {\r
- //case 0x20:\r
- PrintAndLog("2");\r
- return 2;\r
- break;\r
- }\r
- case 0x11:\r
- case 0x18:{\r
- //case 0x20:\r
- PrintAndLog("4");\r
- return 4;\r
- break;\r
- }\r
- }\r
- }\r
- \r
- return -1;\r
-}\r
-\r
-\r
-\r
-\r
-static command_t CommandTable[] =\r
-{\r
- {"help", CmdHelp, 1, "This help"},\r
- {"dbg", CmdHF14AMfDbg, 0, "Set default debug mode"},\r
- {"rdbl", CmdHF14AMfRdBl, 0, "Read MIFARE classic block"},\r
- //{"urdbl", CmdHF14AMfURdBl, 0, "Read MIFARE Ultralight block"},\r
- //{"urdcard", CmdHF14AMfURdCard, 0,"Read MIFARE Ultralight Card"},\r
- //{"uwrbl", CmdHF14AMfUWrBl, 0,"Write MIFARE Ultralight block"},\r
- {"rdsc", CmdHF14AMfRdSc, 0, "Read MIFARE classic sector"},\r
- {"dump", CmdHF14AMfDump, 0, "Dump MIFARE classic tag to binary file"},\r
- {"restore", CmdHF14AMfRestore, 0, "Restore MIFARE classic binary file to BLANK tag"},\r
- {"wrbl", CmdHF14AMfWrBl, 0, "Write MIFARE classic block"},\r
- {"chk", CmdHF14AMfChk, 0, "Test block keys"},\r
- {"mifare", CmdHF14AMifare, 0, "Read parity error messages."},\r
- {"nested", CmdHF14AMfNested, 0, "Test nested authentication"},\r
- {"sniff", CmdHF14AMfSniff, 0, "Sniff card-reader communication"},\r
- {"sim", CmdHF14AMf1kSim, 0, "Simulate MIFARE card"},\r
- {"eclr", CmdHF14AMfEClear, 0, "Clear simulator memory block"},\r
- {"eget", CmdHF14AMfEGet, 0, "Get simulator memory block"},\r
- {"eset", CmdHF14AMfESet, 0, "Set simulator memory block"},\r
- {"eload", CmdHF14AMfELoad, 0, "Load from file emul dump"},\r
- {"esave", CmdHF14AMfESave, 0, "Save to file emul dump"},\r
- {"ecfill", CmdHF14AMfECFill, 0, "Fill simulator memory with help of keys from simulator"},\r
- {"ekeyprn", CmdHF14AMfEKeyPrn, 0, "Print keys from simulator memory"},\r
- {"csetuid", CmdHF14AMfCSetUID, 0, "Set UID for magic Chinese card"},\r
- {"csetblk", CmdHF14AMfCSetBlk, 0, "Write block into magic Chinese card"},\r
- {"cgetblk", CmdHF14AMfCGetBlk, 0, "Read block from magic Chinese card"},\r
- {"cgetsc", CmdHF14AMfCGetSc, 0, "Read sector from magic Chinese card"},\r
- {"cload", CmdHF14AMfCLoad, 0, "Load dump into magic Chinese card"},\r
- {"csave", CmdHF14AMfCSave, 0, "Save dump from magic Chinese card into file or emulator"},\r
- {NULL, NULL, 0, NULL}\r
+static command_t CommandTable[] = {\r
+ {"help", CmdHelp, 1, "This help"},\r
+ {"dbg", CmdHF14AMfDbg, 0, "Set default debug mode"},\r
+ {"rdbl", CmdHF14AMfRdBl, 0, "Read MIFARE classic block"},\r
+ {"rdsc", CmdHF14AMfRdSc, 0, "Read MIFARE classic sector"},\r
+ {"dump", CmdHF14AMfDump, 0, "Dump MIFARE classic tag to binary file"},\r
+ {"restore", CmdHF14AMfRestore, 0, "Restore MIFARE classic binary file to BLANK tag"},\r
+ {"wrbl", CmdHF14AMfWrBl, 0, "Write MIFARE classic block"},\r
+ {"chk", CmdHF14AMfChk, 0, "Test block keys"},\r
+ {"mifare", CmdHF14AMifare, 0, "Read parity error messages."},\r
+ {"nested", CmdHF14AMfNested, 0, "Test nested authentication"},\r
+ {"hardnested", CmdHF14AMfNestedHard, 0, "Nested attack for hardened Mifare cards"},\r
+ {"sniff", CmdHF14AMfSniff, 0, "Sniff card-reader communication"},\r
+ {"sim", CmdHF14AMf1kSim, 0, "Simulate MIFARE card"},\r
+ {"eclr", CmdHF14AMfEClear, 0, "Clear simulator memory block"},\r
+ {"eget", CmdHF14AMfEGet, 0, "Get simulator memory block"},\r
+ {"eset", CmdHF14AMfESet, 0, "Set simulator memory block"},\r
+ {"eload", CmdHF14AMfELoad, 0, "Load from file emul dump"},\r
+ {"esave", CmdHF14AMfESave, 0, "Save to file emul dump"},\r
+ {"ecfill", CmdHF14AMfECFill, 0, "Fill simulator memory with help of keys from simulator"},\r
+ {"ekeyprn", CmdHF14AMfEKeyPrn, 0, "Print keys from simulator memory"},\r
+ {"csetuid", CmdHF14AMfCSetUID, 0, "Set UID for magic Chinese card"},\r
+ {"csetblk", CmdHF14AMfCSetBlk, 0, "Write block - Magic Chinese card"},\r
+ {"cgetblk", CmdHF14AMfCGetBlk, 0, "Read block - Magic Chinese card"},\r
+ {"cgetsc", CmdHF14AMfCGetSc, 0, "Read sector - Magic Chinese card"},\r
+ {"cload", CmdHF14AMfCLoad, 0, "Load dump into magic Chinese card"},\r
+ {"csave", CmdHF14AMfCSave, 0, "Save dump from magic Chinese card into file or emulator"},\r
+ {"decrypt", CmdHf14MfDecryptBytes, 1, "[nt] [ar_enc] [at_enc] [data] - to decrypt snoop or trace"},\r
+ {NULL, NULL, 0, NULL}\r