+ return 0;
+}
+
+int usage_hf_mfu_info(void) {
+ PrintAndLog("It gathers information about the tag and tries to detect what kind it is.");
+ PrintAndLog("Sometimes the tags are locked down, and you may need a key to be able to read the information");
+ PrintAndLog("The following tags can be identified:\n");
+ PrintAndLog("Ultralight, Ultralight-C, Ultralight EV1, NTAG 203, NTAG 210,");
+ PrintAndLog("NTAG 212, NTAG 213, NTAG 215, NTAG 216, NTAG I2C 1K & 2K");
+ PrintAndLog("my-d, my-d NFC, my-d move, my-d move NFC\n");
+ PrintAndLog("Usage: hf mfu info k <key> l");
+ PrintAndLog(" Options : ");
+ PrintAndLog(" k <key> : (optional) key for authentication [UL-C 16bytes, EV1/NTAG 4bytes]");
+ PrintAndLog(" l : (optional) swap entered key's endianness");
+ PrintAndLog("");
+ PrintAndLog(" sample : hf mfu info");
+ PrintAndLog(" : hf mfu info k 00112233445566778899AABBCCDDEEFF");
+ PrintAndLog(" : hf mfu info k AABBCCDDD");
+ return 0;
+}
+
+int usage_hf_mfu_dump(void) {
+ PrintAndLog("Reads all pages from Ultralight, Ultralight-C, Ultralight EV1");
+ PrintAndLog("NTAG 203, NTAG 210, NTAG 212, NTAG 213, NTAG 215, NTAG 216");
+ PrintAndLog("and saves binary dump into the file `filename.bin` or `cardUID.bin`");
+ PrintAndLog("It autodetects card type.\n");
+ PrintAndLog("Usage: hf mfu dump k <key> l n <filename w/o .bin>");
+ PrintAndLog(" Options : ");
+ PrintAndLog(" k <key> : (optional) key for authentication [UL-C 16bytes, EV1/NTAG 4bytes]");
+ PrintAndLog(" l : (optional) swap entered key's endianness");
+ PrintAndLog(" n <FN > : filename w/o .bin to save the dump as");
+ PrintAndLog(" p <Pg > : starting Page number to manually set a page to start the dump at");
+ PrintAndLog(" q <qty> : number of Pages to manually set how many pages to dump");
+
+ PrintAndLog("");
+ PrintAndLog(" sample : hf mfu dump");
+ PrintAndLog(" : hf mfu dump n myfile");
+ PrintAndLog(" : hf mfu dump k 00112233445566778899AABBCCDDEEFF");
+ PrintAndLog(" : hf mfu dump k AABBCCDDD\n");
+ return 0;
+}
+
+int usage_hf_mfu_rdbl(void) {
+ PrintAndLog("Read a block and print. It autodetects card type.\n");
+ PrintAndLog("Usage: hf mfu rdbl b <block number> k <key> l\n");
+ PrintAndLog(" Options:");
+ PrintAndLog(" b <no> : block to read");
+ PrintAndLog(" k <key> : (optional) key for authentication [UL-C 16bytes, EV1/NTAG 4bytes]");
+ PrintAndLog(" l : (optional) swap entered key's endianness");
+ PrintAndLog("");
+ PrintAndLog(" sample : hf mfu rdbl b 0");
+ PrintAndLog(" : hf mfu rdbl b 0 k 00112233445566778899AABBCCDDEEFF");
+ PrintAndLog(" : hf mfu rdbl b 0 k AABBCCDDD\n");
+ return 0;
+}
+
+int usage_hf_mfu_wrbl(void) {
+ PrintAndLog("Write a block. It autodetects card type.\n");
+ PrintAndLog("Usage: hf mfu wrbl b <block number> d <data> k <key> l\n");
+ PrintAndLog(" Options:");
+ PrintAndLog(" b <no> : block to write");
+ PrintAndLog(" d <data> : block data - (8 hex symbols)");
+ PrintAndLog(" k <key> : (optional) key for authentication [UL-C 16bytes, EV1/NTAG 4bytes]");
+ PrintAndLog(" l : (optional) swap entered key's endianness");
+ PrintAndLog("");
+ PrintAndLog(" sample : hf mfu wrbl b 0 d 01234567");
+ PrintAndLog(" : hf mfu wrbl b 0 d 01234567 k AABBCCDDD\n");
+ return 0;
+}
+
+//
+// Mifare Ultralight / Ultralight-C / Ultralight-EV1
+// Read and Dump Card Contents, using auto detection of tag size.
+int CmdHF14AMfUDump(const char *Cmd){
+
+ FILE *fout;
+ char filename[FILE_PATH_SIZE] = {0x00};
+ char *fnameptr = filename;
+ uint8_t *lockbytes_t = NULL;
+ uint8_t lockbytes[2] = {0x00};
+ uint8_t *lockbytes_t2 = NULL;
+ uint8_t lockbytes2[2] = {0x00};
+ bool bit[16] = {0x00};
+ bool bit2[16] = {0x00};
+ uint8_t data[1024] = {0x00};
+ bool hasAuthKey = false;
+ int i = 0;
+ int Pages = 16;
+ bool tmplockbit = false;
+ uint8_t dataLen = 0;
+ uint8_t cmdp = 0;
+ uint8_t authenticationkey[16] = {0x00};
+ uint8_t *authKeyPtr = authenticationkey;
+ size_t fileNlen = 0;
+ bool errors = false;
+ bool swapEndian = false;
+ bool manualPages = false;
+ uint8_t startPage = 0;
+ char tempStr[50];
+
+ while(param_getchar(Cmd, cmdp) != 0x00)
+ {
+ switch(param_getchar(Cmd, cmdp))
+ {
+ case 'h':
+ case 'H':
+ return usage_hf_mfu_dump();
+ case 'k':
+ case 'K':
+ dataLen = param_getstr(Cmd, cmdp+1, tempStr);
+ if (dataLen == 32 || dataLen == 8) { //ul-c or ev1/ntag key length
+ errors = param_gethex(tempStr, 0, authenticationkey, dataLen);
+ dataLen /= 2;
+ } else {
+ PrintAndLog("\nERROR: Key is incorrect length\n");
+ errors = true;
+ }
+ cmdp += 2;
+ hasAuthKey = true;
+ break;
+ case 'l':
+ case 'L':
+ swapEndian = true;
+ cmdp++;
+ break;
+ case 'n':
+ case 'N':
+ fileNlen = param_getstr(Cmd, cmdp+1, filename);
+ if (!fileNlen) errors = true;
+ if (fileNlen > FILE_PATH_SIZE-5) fileNlen = FILE_PATH_SIZE-5;
+ cmdp += 2;
+ break;
+ case 'p':
+ case 'P':
+ startPage = param_get8(Cmd, cmdp+1);
+ manualPages = true;
+ cmdp += 2;
+ break;
+ case 'q':
+ case 'Q':
+ Pages = param_get8(Cmd, cmdp+1);
+ cmdp += 2;
+ manualPages = true;
+ break;
+ default:
+ PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
+ errors = true;
+ break;
+ }
+ if(errors) break;
+ }
+
+ //Validations
+ if(errors) return usage_hf_mfu_dump();
+
+ if (swapEndian && hasAuthKey)
+ authKeyPtr = SwapEndian64(authenticationkey, dataLen, (dataLen == 16) ? 8 : 4);
+
+ TagTypeUL_t tagtype = GetHF14AMfU_Type();
+ if (tagtype == UL_ERROR) return -1;
+
+ if (!manualPages) //get number of pages to read
+ for (uint8_t idx = 0; idx < MAX_UL_TYPES; idx++)
+ if (tagtype & UL_TYPES_ARRAY[idx])
+ Pages = UL_MEMORY_ARRAY[idx]+1; //add one as maxblks starts at 0
+
+ ul_print_type(tagtype, 0);
+ PrintAndLog("Reading tag memory...");
+ UsbCommand c = {CMD_MIFAREU_READCARD, {startPage,Pages}};
+ if ( hasAuthKey ) {
+ if (tagtype & UL_C)
+ c.arg[2] = 1; //UL_C auth
+ else
+ c.arg[2] = 2; //UL_EV1/NTAG auth
+
+ memcpy(c.d.asBytes, authKeyPtr, dataLen);
+ }
+
+ clearCommandBuffer();
+ SendCommand(&c);
+ UsbCommand resp;
+ if (!WaitForResponseTimeout(CMD_ACK, &resp,1500)) {
+ PrintAndLog("Command execute time-out");
+ return 1;
+ }
+ if (resp.arg[0] != 1) {
+ PrintAndLog("Failed reading block: (%02x)", i);
+ return 1;
+ }
+
+ uint32_t startindex = resp.arg[2];
+ uint32_t bufferSize = resp.arg[1];
+ if (bufferSize > sizeof(data)) {
+ PrintAndLog("Data exceeded Buffer size!");
+ bufferSize = sizeof(data);
+ }
+ GetFromBigBuf(data, bufferSize, startindex);
+ WaitForResponse(CMD_ACK,NULL);
+
+ Pages = bufferSize/4;