From 21fa85ca1deeacf88634cb524cbf03db3dbeb042 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Tue, 27 Jul 2010 13:37:57 +0000 Subject: [PATCH] Only search keys of existing sectors. --- examples/mifare-classic-write-ndef.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/mifare-classic-write-ndef.c b/examples/mifare-classic-write-ndef.c index 9ab2b52..fcbfa72 100644 --- a/examples/mifare-classic-write-ndef.c +++ b/examples/mifare-classic-write-ndef.c @@ -239,7 +239,20 @@ main(int argc, char *argv[]) .application_code = 0xff, .function_cluster_code = 0xff }; - for (size_t s = 40; s; s--) { + + MifareClassicSectorNumber max_s; + switch (freefare_get_tag_type (tags[i])) { + case CLASSIC_1K: + max_s = 16; + break; + case CLASSIC_4K: + max_s = 40; + break; + default: + /* Keep compiler quiet */ + break; + } + for (size_t s = max_s; s; s--) { if (s == 0x10) continue; if (!search_sector_key (tags[i], s, &(card_write_keys[s].key), &(card_write_keys[s].type))) { mad_set_aid (mad, s, reserved);