From 963eb074ecc623506ba68d92879dcb15bf5a8c47 Mon Sep 17 00:00:00 2001 From: Adam Laurie Date: Thu, 23 Mar 2017 16:42:10 +0000 Subject: [PATCH] vary expected dump size based on tag type --- utils/nfc-mfultralight.c | 51 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index b4459db..72629ca 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -466,6 +466,7 @@ int main(int argc, const char *argv[]) { int iAction = 0; + uint8_t iDumpSize= sizeof(mifareul_tag); uint8_t iUID[MAX_UID_LEN] = { 0x0 }; size_t szUID = 0; bool bOTP = false; @@ -521,30 +522,6 @@ main(int argc, const char *argv[]) } } - if (iAction == 1) { - memset(&mtDump, 0x00, sizeof(mtDump)); - } else if (iAction == 2) { - pfDump = fopen(argv[2], "rb"); - - if (pfDump == NULL) { - ERR("Could not open dump file: %s\n", argv[2]); - exit(EXIT_FAILURE); - } - - if (fread(&mtDump, 1, sizeof(mtDump), pfDump) != sizeof(mtDump)) { - ERR("Could not read from dump file: %s\n", argv[2]); - fclose(pfDump); - exit(EXIT_FAILURE); - } - fclose(pfDump); - DBG("Successfully opened the dump file\n"); - } else if (iAction == 3) { - DBG("Switching to Check Magic Mode\n"); - } else { - ERR("Unable to determine operating mode"); - exit(EXIT_FAILURE); - } - nfc_context *context; nfc_init(&context); if (context == NULL) { @@ -615,11 +592,13 @@ main(int argc, const char *argv[]) printf("48 bytes\n"); uiBlocks= 0x13; iEV1Type= EV1_UL11; + iDumpSize= sizeof(mifareul_ev1_mf0ul11_tag); } else if(abtRx[6] == 0x0e) { printf("128 bytes\n"); uiBlocks= 0x28; iEV1Type= EV1_UL21; + iDumpSize= sizeof(mifareul_ev1_mf0ul21_tag); } else printf("unknown!\n"); @@ -648,6 +627,30 @@ main(int argc, const char *argv[]) } } + if (iAction == 1) { + memset(&mtDump, 0x00, sizeof(mtDump)); + } else if (iAction == 2) { + pfDump = fopen(argv[2], "rb"); + + if (pfDump == NULL) { + ERR("Could not open dump file: %s\n", argv[2]); + exit(EXIT_FAILURE); + } + + if (fread(&mtDump, 1, sizeof(mtDump), pfDump) != iDumpSize) { + ERR("Could not read from dump file or size mismatch: %s\n", argv[2]); + fclose(pfDump); + exit(EXIT_FAILURE); + } + fclose(pfDump); + DBG("Successfully opened the dump file\n"); + } else if (iAction == 3) { + DBG("Switching to Check Magic Mode\n"); + } else { + ERR("Unable to determine operating mode"); + exit(EXIT_FAILURE); + } + if (iAction == 1) { bool bRF= read_card(); printf("Writing data to file: %s ... ", argv[2]);