- CLIParserInit("hf mf ndef",\r
- "Prints NFC Data Exchange Format (NDEF)",\r
- "Usage:\n\thf mf ndef -> shows NDEF data\n"\r
- "\thf mf ndef -a 03e1 -k ffffffffffff -b -> shows NDEF data with custom AID, key and with key B\n");\r
-\r
- void *argtable[] = {\r
- arg_param_begin,\r
- arg_litn("vV", "verbose", 0, 2, "show technical data"),\r
- arg_str0("aA", "aid", "replace default aid for NDEF", NULL),\r
- arg_str0("kK", "key", "replace default key for NDEF", NULL),\r
- arg_lit0("bB", "keyb", "use key B for access sectors (by default: key A)"),\r
- arg_param_end\r
- };\r
- CLIExecWithReturn(cmd, argtable, true);\r
-\r
- bool verbose = arg_get_lit(1);\r
- bool verbose2 = arg_get_lit(1) > 1;\r
- uint8_t aid[2] = {0};\r
- int aidlen;\r
- CLIGetHexWithReturn(2, aid, &aidlen);\r
- uint8_t key[6] = {0};\r
- int keylen;\r
- CLIGetHexWithReturn(3, key, &keylen);\r
- bool keyB = arg_get_lit(4);\r
-\r
- CLIParserFree();\r
-\r
- uint16_t ndefAID = 0x03e1;\r
- if (aidlen == 2)\r
- ndefAID = (aid[0] << 8) + aid[1];\r
-\r
- uint8_t ndefkey[6] = {0};\r
- memcpy(ndefkey, g_mifare_ndef_key, 6);\r
- if (keylen == 6) {\r
- memcpy(ndefkey, key, 6);\r
- }\r
-\r
- uint8_t sector0[16 * 4] = {0};\r
- uint8_t sector10[16 * 4] = {0};\r
- uint8_t data[4096] = {0};\r
- int datalen = 0;\r
-\r
- PrintAndLogEx(NORMAL, "");\r
-\r
- if (mfReadSector(MF_MAD1_SECTOR, MF_KEY_A, (uint8_t *)g_mifare_mad_key, sector0)) {\r
- PrintAndLogEx(ERR, "read sector 0 error. card don't have MAD or don't have MAD on default keys.");\r
- return 2;\r
- }\r
-\r
- bool haveMAD2 = false;\r
- int res = MADCheck(sector0, NULL, verbose, &haveMAD2);\r
- if (res) {\r
- PrintAndLogEx(ERR, "MAD error %d.", res);\r
- return res;\r
- }\r
-\r
- if (haveMAD2) {\r
- if (mfReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifare_mad_key, sector10)) {\r
- PrintAndLogEx(ERR, "read sector 0x10 error. card don't have MAD or don't have MAD on default keys.");\r
- return 2;\r
- }\r
- }\r
-\r
- uint16_t mad[7 + 8 + 8 + 8 + 8] = {0};\r
- size_t madlen = 0;\r
- if (MADDecode(sector0, (haveMAD2 ? sector10 : NULL), mad, &madlen)) {\r
- PrintAndLogEx(ERR, "can't decode mad.");\r
- return 10;\r
- }\r
-\r
- printf("data reading:");\r
- for (int i = 0; i < madlen; i++) {\r
- if (ndefAID == mad[i]) {\r
- uint8_t vsector[16 * 4] = {0};\r
- if (mfReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, ndefkey, vsector)) {\r
- PrintAndLogEx(ERR, "read sector %d error.", i + 1);\r
- return 2;\r
- }\r
-\r
- memcpy(&data[datalen], vsector, 16 * 3);\r
- datalen += 16 * 3;\r
-\r
- printf(".");\r
- }\r
- }\r
- printf(" OK\n");\r
-\r
- if (!datalen) {\r
- PrintAndLogEx(ERR, "no NDEF data.");\r
- return 11;\r
- }\r
-\r
- if (verbose2) {\r
- PrintAndLogEx(NORMAL, "NDEF data:");\r
- dump_buffer(data, datalen, stdout, 1);\r
- }\r
-\r
- NDEFDecodeAndPrint(data, datalen, verbose);\r
-\r
- return 0;\r
+ CLIParserInit("hf mf ndef",\r
+ "Prints NFC Data Exchange Format (NDEF)",\r
+ "Usage:\n\thf mf ndef -> shows NDEF data\n"\r
+ "\thf mf ndef -a 03e1 -k ffffffffffff -b -> shows NDEF data with custom AID, key and with key B\n");\r
+\r
+ void *argtable[] = {\r
+ arg_param_begin,\r
+ arg_litn("vV", "verbose", 0, 2, "show technical data"),\r
+ arg_str0("aA", "aid", "replace default aid for NDEF", NULL),\r
+ arg_str0("kK", "key", "replace default key for NDEF", NULL),\r
+ arg_lit0("bB", "keyb", "use key B for access sectors (by default: key A)"),\r
+ arg_param_end\r
+ };\r
+ CLIExecWithReturn(cmd, argtable, true);\r
+\r
+ bool verbose = arg_get_lit(1);\r
+ bool verbose2 = arg_get_lit(1) > 1;\r
+ uint8_t aid[2] = {0};\r
+ int aidlen;\r
+ CLIGetHexWithReturn(2, aid, &aidlen);\r
+ uint8_t key[6] = {0};\r
+ int keylen;\r
+ CLIGetHexWithReturn(3, key, &keylen);\r
+ bool keyB = arg_get_lit(4);\r
+\r
+ CLIParserFree();\r
+\r
+ uint16_t ndefAID = 0x03e1;\r
+ if (aidlen == 2)\r
+ ndefAID = (aid[0] << 8) + aid[1];\r
+\r
+ uint8_t ndefkey[6] = {0};\r
+ memcpy(ndefkey, g_mifare_ndef_key, 6);\r
+ if (keylen == 6) {\r
+ memcpy(ndefkey, key, 6);\r
+ }\r
+\r
+ uint8_t sector0[16 * 4] = {0};\r
+ uint8_t sector10[16 * 4] = {0};\r
+ uint8_t data[4096] = {0};\r
+ int datalen = 0;\r
+\r
+ PrintAndLogEx(NORMAL, "");\r
+\r
+ if (mfReadSector(MF_MAD1_SECTOR, MF_KEY_A, (uint8_t *)g_mifare_mad_key, sector0)) {\r
+ PrintAndLogEx(ERR, "read sector 0 error. card don't have MAD or don't have MAD on default keys.");\r
+ return 2;\r
+ }\r
+\r
+ bool haveMAD2 = false;\r
+ int res = MADCheck(sector0, NULL, verbose, &haveMAD2);\r
+ if (res) {\r
+ PrintAndLogEx(ERR, "MAD error %d.", res);\r
+ return res;\r
+ }\r
+\r
+ if (haveMAD2) {\r
+ if (mfReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifare_mad_key, sector10)) {\r
+ PrintAndLogEx(ERR, "read sector 0x10 error. card don't have MAD or don't have MAD on default keys.");\r
+ return 2;\r
+ }\r
+ }\r
+\r
+ uint16_t mad[7 + 8 + 8 + 8 + 8] = {0};\r
+ size_t madlen = 0;\r
+ if (MADDecode(sector0, (haveMAD2 ? sector10 : NULL), mad, &madlen)) {\r
+ PrintAndLogEx(ERR, "can't decode mad.");\r
+ return 10;\r
+ }\r
+\r
+ printf("data reading:");\r
+ for (int i = 0; i < madlen; i++) {\r
+ if (ndefAID == mad[i]) {\r
+ uint8_t vsector[16 * 4] = {0};\r
+ if (mfReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, ndefkey, vsector)) {\r
+ PrintAndLogEx(ERR, "read sector %d error.", i + 1);\r
+ return 2;\r
+ }\r
+\r
+ memcpy(&data[datalen], vsector, 16 * 3);\r
+ datalen += 16 * 3;\r
+\r
+ printf(".");\r
+ }\r
+ }\r
+ printf(" OK\n");\r
+\r
+ if (!datalen) {\r
+ PrintAndLogEx(ERR, "no NDEF data.");\r
+ return 11;\r
+ }\r
+\r
+ if (verbose2) {\r
+ PrintAndLogEx(NORMAL, "NDEF data:");\r
+ dump_buffer(data, datalen, stdout, 1);\r
+ }\r
+\r
+ NDEFDecodeAndPrint(data, datalen, verbose);\r
+\r
+ return 0;\r