From 30ce00aa8e4e0a8f45f2d963ccf8844086847680 Mon Sep 17 00:00:00 2001 From: Kirill Elagin Date: Sat, 11 Apr 2015 23:29:59 +0300 Subject: [PATCH 1/4] Alternative Mifare Classic 1k SAK --- src/mfoc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mfoc.c b/src/mfoc.c index 93c097e..0b9b339 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -226,6 +226,7 @@ int main(int argc, char *const argv[]) switch (t.nt.nti.nai.btSak) { case 0x08: + case 0x88: printf("Found Mifare Classic 1k tag\n"); t.num_sectors = NR_TRAILERS_1k; t.num_blocks = NR_BLOCKS_1k; From b872a328e331086ce02eef590b149b65c450177a Mon Sep 17 00:00:00 2001 From: Kirill Elagin Date: Sat, 11 Apr 2015 23:30:20 +0300 Subject: [PATCH 2/4] Fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was horrible as this made mfoc non-functional for cards with unknown SAK’s. --- src/mfoc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mfoc.c b/src/mfoc.c index 0b9b339..5bd3176 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -241,7 +241,7 @@ int main(int argc, char *const argv[]) t.num_sectors = NR_TRAILERS_4k; t.num_blocks = NR_BLOCKS_4k; break; - defaul: + default: ERR("Cannot determine card type from SAK"); goto error; } From f3ebde09efbbd6e94792cee9cd457515df793a2d Mon Sep 17 00:00:00 2001 From: Kirill Elagin Date: Sat, 11 Apr 2015 23:30:58 +0300 Subject: [PATCH 3/4] Fix user-provided keys handling This makes mfoc try user-provided keys even if the built-in ones are removed from the code (for efficiency). --- src/mfoc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mfoc.c b/src/mfoc.c index 5bd3176..0bd6437 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -284,7 +284,7 @@ int main(int argc, char *const argv[]) n = sizeof(defaultKeys) / sizeof(defaultKeys[0]); size_t defKey_bytes_todo = defKeys_len; key = 0; - while (key < n) { + while (key < n || defKey_bytes_todo) { if (defKey_bytes_todo > 0) { memcpy(mp.mpa.abtKey, defKeys + defKeys_len - defKey_bytes_todo, sizeof(mp.mpa.abtKey)); defKey_bytes_todo -= sizeof(mp.mpa.abtKey); From 3b5be846764e1da40794519a4c7102c7471c7fa1 Mon Sep 17 00:00:00 2001 From: Kirill Elagin Date: Sat, 11 Apr 2015 23:56:21 +0300 Subject: [PATCH 4/4] Proper amount of data to dump --- src/mfoc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mfoc.c b/src/mfoc.c index 0bd6437..ec8ca8e 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -633,7 +633,8 @@ int main(int argc, char *const argv[]) } // Finally save all keys + data to file - if (fwrite(&mtDump, 1, sizeof(mtDump), pfDump) != sizeof(mtDump)) { + uint16_t dump_size = (t.num_blocks + 1) * t.num_sectors; + if (fwrite(&mtDump, 1, dump_size, pfDump) != dump_size) { fprintf(stdout, "Error, cannot write dump\n"); fclose(pfDump); goto error;