From 24881bd32d5d9d3310842c09af80d20c945459a8 Mon Sep 17 00:00:00 2001 From: Adam Laurie Date: Wed, 7 Sep 2011 09:41:04 +0000 Subject: [PATCH] Fix accidental overwrite of Mifare special trailer block in unlocked read --- examples/nfc-mfclassic.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/nfc-mfclassic.c b/examples/nfc-mfclassic.c index 6818437..6f0708f 100644 --- a/examples/nfc-mfclassic.c +++ b/examples/nfc-mfclassic.c @@ -296,10 +296,14 @@ read_card (int read_unlocked) } // Try to read out the trailer if (nfc_initiator_mifare_cmd (pnd, MC_READ, iBlock, &mp)) { - // Copy the keys over from our key dump and store the retrieved access bits - memcpy (mtDump.amb[iBlock].mbt.abtKeyA, mtKeys.amb[iBlock].mbt.abtKeyA, 6); - memcpy (mtDump.amb[iBlock].mbt.abtAccessBits, mp.mpd.abtData + 6, 4); - memcpy (mtDump.amb[iBlock].mbt.abtKeyB, mtKeys.amb[iBlock].mbt.abtKeyB, 6); + if(read_unlocked) { + memcpy (mtDump.amb[iBlock].mbd.abtData, mp.mpd.abtData, 16); + } else { + // Copy the keys over from our key dump and store the retrieved access bits + memcpy (mtDump.amb[iBlock].mbt.abtKeyA, mtKeys.amb[iBlock].mbt.abtKeyA, 6); + memcpy (mtDump.amb[iBlock].mbt.abtAccessBits, mp.mpd.abtData + 6, 4); + memcpy (mtDump.amb[iBlock].mbt.abtKeyB, mtKeys.amb[iBlock].mbt.abtKeyB, 6); + } } else { printf ("!\nError: unable to read trailer block 0x%02x\n", iBlock); }