Skip to content

Commit

Permalink
Mifare Fuzzer: Fix crash on unsupported card type loaded (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Aug 23, 2024
1 parent 70fae8d commit 9a453c5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
2 changes: 2 additions & 0 deletions mifare_fuzzer/mifare_fuzzer_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ struct MifareFuzzerApp {
FuriString* uid_file_path;
FuriString* uid_str;
Stream* uids_stream;

bool nfc_device_parsed;
};
26 changes: 3 additions & 23 deletions mifare_fuzzer/scenes/mifare_fuzzer_scene_emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,13 @@ bool mifare_fuzzer_scene_emulator_on_event(void* context, SceneManagerEvent even
NfcDevice* nfc_device = NULL;
bool nfc_device_parsed = false;
if(app->card_file_path) {
nfc_device = app->worker->nfc_device;
const char* path = furi_string_get_cstr(app->card_file_path);
if(nfc_device_load(nfc_device, path)) {
nfc_device_parsed = true;
NfcProtocol protocol = nfc_device_get_protocol(nfc_device);
if(protocol == NfcProtocolMfClassic) {
const MfClassicData* mfc_data = nfc_device_get_data(nfc_device, protocol);
if(mfc_data->type == MfClassicType1k) {
app->card = MifareCardClassic1k;
} else if(mfc_data->type == MfClassicType4k) {
app->card = MifareCardClassic4k;
} else {
nfc_device_parsed = false;
}
} else if(protocol == NfcProtocolMfUltralight) {
app->card = MifareCardUltralight;
}
if(nfc_device_parsed) {
mifare_fuzzer_emulator_set_card(emulator, app->card, app->card_file_path);
}
}
}

Iso14443_3aData* nfc_data = iso14443_3a_alloc();
if(nfc_device_parsed) {
if(app->nfc_device_parsed) {
iso14443_3a_copy(
nfc_data, nfc_device_get_data(nfc_device, NfcProtocolIso14443_3a));
nfc_data,
nfc_device_get_data(app->worker->nfc_device, NfcProtocolIso14443_3a));
}

// Stop worker
Expand Down
32 changes: 30 additions & 2 deletions mifare_fuzzer/scenes/mifare_fuzzer_scene_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ bool mifare_fuzzer_scene_start_on_event(void* context, SceneManagerEvent event)
if(event.type == SceneManagerEventTypeCustom) {
//FURI_LOG_D(TAG, "mifare_fuzzer_scene_start_on_event() :: event.event = %ld", event.event);
app->card_file_path = NULL;
app->nfc_device_parsed = false;
if(event.event == MifareFuzzerEventClassic1k) {
// save selected item
scene_manager_set_scene_state(
Expand Down Expand Up @@ -135,8 +136,35 @@ bool mifare_fuzzer_scene_start_on_event(void* context, SceneManagerEvent event)
app->dialogs, app->card_file_path, initial_path, &browser_options);
furi_string_free(initial_path);
if(wasFileSelected) {
// open next scene
scene_manager_next_scene(app->scene_manager, MifareFuzzerSceneAttack);
MifareFuzzerEmulator* emulator = app->emulator_view;
NfcDevice* nfc_device = app->worker->nfc_device;
const char* path = furi_string_get_cstr(app->card_file_path);
if(nfc_device_load(nfc_device, path)) {
app->nfc_device_parsed = true;
NfcProtocol protocol = nfc_device_get_protocol(nfc_device);
if(protocol == NfcProtocolMfClassic) {
const MfClassicData* mfc_data = nfc_device_get_data(nfc_device, protocol);
if(mfc_data->type == MfClassicType1k) {
app->card = MifareCardClassic1k;
} else if(mfc_data->type == MfClassicType4k) {
app->card = MifareCardClassic4k;
} else {
app->nfc_device_parsed = false;
}
} else if(protocol == NfcProtocolMfUltralight) {
app->card = MifareCardUltralight;
} else {
app->nfc_device_parsed = false;
}
if(app->nfc_device_parsed) {
mifare_fuzzer_emulator_set_card(emulator, app->card, app->card_file_path);
scene_manager_next_scene(app->scene_manager, MifareFuzzerSceneAttack);
} else {
app->card = MifareCardUnsupported;
mifare_fuzzer_emulator_set_card(emulator, MifareCardUnsupported, NULL);
scene_manager_next_scene(app->scene_manager, MifareFuzzerSceneEmulator);
}
}
consumed = true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions mifare_fuzzer/views/mifare_fuzzer_emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ void mifare_fuzzer_emulator_set_card(
case MifareCardUltralight:
model->mifare_card_dsc = "Ultralight";
break;
case MifareCardUnsupported:
model->mifare_card_dsc = "Unsupported Card!";
break;
}
} else {
FuriString* card_name = furi_string_alloc_set(name);
Expand Down
1 change: 1 addition & 0 deletions mifare_fuzzer/views/mifare_fuzzer_emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef enum MifareCard {
MifareCardClassic1k = 1,
MifareCardClassic4k,
MifareCardUltralight,
MifareCardUnsupported,
} MifareCard;

typedef enum MifareFuzzerAttack {
Expand Down

0 comments on commit 9a453c5

Please sign in to comment.