From 740ab6bb33455c6fa46817239c366b73c7a23e6e Mon Sep 17 00:00:00 2001 From: douniwan5788 Date: Wed, 4 Sep 2024 14:49:16 +0800 Subject: [PATCH] fix: mfDarkside hangs --- armsrc/iso14443a.c | 6 ++---- client/src/mifare/mifarehost.c | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 2bf375a99..c0ad1aaec 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -3433,8 +3433,8 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) { sync_cycles = (sync_cycles - nt_distance) / elapsed_prng_sequences; - // no negative sync_cycles - if (sync_cycles <= 0) sync_cycles += PRNG_SEQUENCE_LENGTH; + // no negative sync_cycles, and too small sync_cycles will result in continuous misses + if (sync_cycles <= 10) sync_cycles += PRNG_SEQUENCE_LENGTH; // reset sync_cycles if (sync_cycles > PRNG_SEQUENCE_LENGTH * 2) { @@ -3445,11 +3445,9 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) { if (g_dbglevel >= DBG_EXTENDED) Dbprintf("calibrating in cycle %d. nt_distance=%d, elapsed_prng_sequences=%d, new sync_cycles: %d\n", i, nt_distance, elapsed_prng_sequences, sync_cycles); - LED_B_OFF(); continue; } } - LED_B_OFF(); if ((nt != nt_attacked) && nt_attacked) { // we somehow lost sync. Try to catch up again... diff --git a/client/src/mifare/mifarehost.c b/client/src/mifare/mifarehost.c index 8b20cba44..c5c7c91e7 100644 --- a/client/src/mifare/mifarehost.c +++ b/client/src/mifare/mifarehost.c @@ -83,6 +83,8 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { while (true) { PrintAndLogEx(NORMAL, "." NOLF); + if (IsCommunicationThreadDead()) return PM3_EIO; + //TODO: Not really stopping the command in time. if (kbd_enter_pressed()) { SendCommandNG(CMD_BREAK_LOOP, NULL, 0);