NFC: MF Classic parsers read() fix (dictionary attack skip) (#3355)

* NFC: MF Classic lib: MfClassicErrorPartialRead added

* unnecessary imports removed

* MfClassicError refactor by @gornekich

Co-authored-by: gornekich <n.gorbadey@gmail.com>

---------

Co-authored-by: gornekich <n.gorbadey@gmail.com>
This commit is contained in:
Leptopt1los 2024-02-07 01:53:42 +09:00 committed by GitHub
parent e6f078eeb7
commit ed34dfa1c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 18 additions and 20 deletions

View file

@ -60,7 +60,7 @@ static bool aime_read(Nfc* nfc, NfcDevice* device) {
}
error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}

View file

@ -60,7 +60,7 @@ static bool hid_read(Nfc* nfc, NfcDevice* device) {
}
error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}

View file

@ -135,14 +135,14 @@ static bool plantain_read(Nfc* nfc, NfcDevice* device) {
}
error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error != MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}
nfc_device_set_data(device, NfcProtocolMfClassic, data);
is_read = true;
is_read = (error == MfClassicErrorNone);
} while(false);
mf_classic_free(data);

View file

@ -137,14 +137,14 @@ static bool troika_read(Nfc* nfc, NfcDevice* device) {
}
error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error == MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}
nfc_device_set_data(device, NfcProtocolMfClassic, data);
is_read = true;
is_read = (error == MfClassicErrorNone);
} while(false);
mf_classic_free(data);

View file

@ -85,14 +85,14 @@ static bool two_cities_read(Nfc* nfc, NfcDevice* device) {
}
error = mf_classic_poller_sync_read(nfc, &keys, data);
if(error != MfClassicErrorNone) {
if(error != MfClassicErrorNotPresent) {
FURI_LOG_W(TAG, "Failed to read data");
break;
}
nfc_device_set_data(device, NfcProtocolMfClassic, data);
is_read = true;
is_read = (error == MfClassicErrorNone);
} while(false);
mf_classic_free(data);

View file

@ -39,6 +39,7 @@ typedef enum {
MfClassicErrorNotPresent,
MfClassicErrorProtocol,
MfClassicErrorAuth,
MfClassicErrorPartialRead,
MfClassicErrorTimeout,
} MfClassicError;

View file

@ -475,19 +475,16 @@ MfClassicError
nfc_poller_stop(poller);
if(poller_context.error != MfClassicErrorNone) {
error = poller_context.error;
} else {
const MfClassicData* mfc_data = nfc_poller_get_data(poller);
uint8_t sectors_read = 0;
uint8_t keys_found = 0;
const MfClassicData* mfc_data = nfc_poller_get_data(poller);
uint8_t sectors_read = 0;
uint8_t keys_found = 0;
mf_classic_get_read_sectors_and_keys(mfc_data, &sectors_read, &keys_found);
if((sectors_read > 0) || (keys_found > 0)) {
mf_classic_copy(data, mfc_data);
} else {
error = MfClassicErrorNotPresent;
}
mf_classic_get_read_sectors_and_keys(mfc_data, &sectors_read, &keys_found);
if((sectors_read == 0) && (keys_found == 0)) {
error = MfClassicErrorNotPresent;
} else {
mf_classic_copy(data, mfc_data);
error = mf_classic_is_card_read(mfc_data) ? MfClassicErrorNone : MfClassicErrorPartialRead;
}
nfc_poller_free(poller);