mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 20:49:49 +04:00
Add MIFARE Classic "Show Keys" UI
by aaronjamt
This commit is contained in:
@@ -15,6 +15,7 @@ enum {
|
||||
SubmenuIndexDictAttack,
|
||||
SubmenuIndexCrackNonces,
|
||||
SubmenuIndexUpdate,
|
||||
SubmenuIndexShowKeys,
|
||||
};
|
||||
|
||||
static void nfc_scene_info_on_enter_mf_classic(NfcApp* instance) {
|
||||
@@ -139,6 +140,13 @@ static void nfc_scene_read_menu_on_enter_mf_classic(NfcApp* instance) {
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
}
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Show Keys",
|
||||
SubmenuIndexShowKeys,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
}
|
||||
|
||||
static void nfc_scene_read_success_on_enter_mf_classic(NfcApp* instance) { //-V524
|
||||
@@ -186,6 +194,13 @@ static void nfc_scene_saved_menu_on_enter_mf_classic(NfcApp* instance) {
|
||||
SubmenuIndexUpdate,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Show Keys",
|
||||
SubmenuIndexShowKeys,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
}
|
||||
|
||||
static void nfc_scene_emulate_on_enter_mf_classic(NfcApp* instance) {
|
||||
@@ -218,6 +233,9 @@ static bool nfc_scene_read_menu_on_event_mf_classic(NfcApp* instance, SceneManag
|
||||
instance->scene_manager, NfcSceneSaveConfirm, NfcSceneSaveConfirmStateCrackNonces);
|
||||
scene_manager_next_scene(instance->scene_manager, NfcSceneSaveConfirm);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexShowKeys) {
|
||||
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicShowKeys);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,6 +258,9 @@ static bool nfc_scene_saved_menu_on_event_mf_classic(NfcApp* instance, SceneMana
|
||||
} else if(event.event == SubmenuIndexUpdate) {
|
||||
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicUpdateInitial);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexShowKeys) {
|
||||
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicShowKeys);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ ADD_SCENE(nfc, mf_classic_mfkey_complete, MfClassicMfkeyComplete)
|
||||
ADD_SCENE(nfc, mf_classic_update_initial, MfClassicUpdateInitial)
|
||||
ADD_SCENE(nfc, mf_classic_update_initial_success, MfClassicUpdateInitialSuccess)
|
||||
ADD_SCENE(nfc, mf_classic_update_initial_wrong_card, MfClassicUpdateInitialWrongCard)
|
||||
ADD_SCENE(nfc, mf_classic_show_keys, MfClassicShowKeys)
|
||||
|
||||
ADD_SCENE(nfc, mf_classic_keys, MfClassicKeys)
|
||||
ADD_SCENE(nfc, mf_classic_keys_list, MfClassicKeysList)
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "../nfc_app_i.h"
|
||||
|
||||
#include <bit_lib/bit_lib.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
#define TAG "NfcMfClassicShowKeys"
|
||||
|
||||
void nfc_scene_mf_classic_show_keys_callback(GuiButtonType button, InputType type, void* context) {
|
||||
NfcApp* instance = context;
|
||||
if(button == GuiButtonTypeLeft && type == InputTypeShort) {
|
||||
scene_manager_previous_scene(instance->scene_manager);
|
||||
}
|
||||
}
|
||||
|
||||
void nfc_scene_mf_classic_show_keys_on_enter(void* context) {
|
||||
NfcApp* instance = context;
|
||||
|
||||
const MfClassicData* mfc_data =
|
||||
nfc_device_get_data(instance->nfc_device, NfcProtocolMfClassic);
|
||||
|
||||
furi_string_reset(instance->text_box_store);
|
||||
nfc_append_filename_string_when_present(instance, instance->text_box_store);
|
||||
|
||||
furi_string_cat_printf(instance->text_box_store, "\e#Found MFC Keys:");
|
||||
|
||||
uint8_t num_sectors = mf_classic_get_total_sectors_num(mfc_data->type);
|
||||
uint8_t found_keys_a = 0, found_keys_b = 0;
|
||||
for(uint8_t i = 0; i < num_sectors; i++) {
|
||||
MfClassicSectorTrailer* sec_tr = mf_classic_get_sector_trailer_by_sector(mfc_data, i);
|
||||
|
||||
bool key_a = FURI_BIT(mfc_data->key_a_mask, i);
|
||||
bool key_b = FURI_BIT(mfc_data->key_b_mask, i);
|
||||
|
||||
if(key_a || key_b) {
|
||||
furi_string_cat_printf(instance->text_box_store, "\n -> Sector %d\n\e*AccBits:", i);
|
||||
for(uint8_t j = 0; j < MF_CLASSIC_ACCESS_BYTES_SIZE; j++) {
|
||||
furi_string_cat_printf(
|
||||
instance->text_box_store, " %02X", sec_tr->access_bits.data[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if(key_a) {
|
||||
found_keys_a++;
|
||||
furi_string_cat_printf(instance->text_box_store, "\n\e*A:");
|
||||
for(uint8_t j = 0; j < MF_CLASSIC_KEY_SIZE; j++)
|
||||
furi_string_cat_printf(instance->text_box_store, " %02X", sec_tr->key_a.data[j]);
|
||||
}
|
||||
if(key_b) {
|
||||
found_keys_b++;
|
||||
furi_string_cat_printf(instance->text_box_store, "\n\e*B:");
|
||||
for(uint8_t j = 0; j < MF_CLASSIC_KEY_SIZE; j++)
|
||||
furi_string_cat_printf(instance->text_box_store, " %02X", sec_tr->key_b.data[j]);
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_cat_printf(
|
||||
instance->text_box_store,
|
||||
"\nTotal keys found:\n -> %d/%d A keys\n -> %d/%d B keys",
|
||||
found_keys_a,
|
||||
num_sectors,
|
||||
found_keys_b,
|
||||
num_sectors);
|
||||
|
||||
widget_add_text_scroll_element(
|
||||
instance->widget, 2, 2, 124, 60, furi_string_get_cstr(instance->text_box_store));
|
||||
widget_add_button_element(
|
||||
instance->widget,
|
||||
GuiButtonTypeLeft,
|
||||
"Back",
|
||||
nfc_scene_mf_classic_show_keys_callback,
|
||||
instance);
|
||||
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewWidget);
|
||||
}
|
||||
|
||||
bool nfc_scene_mf_classic_show_keys_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
void nfc_scene_mf_classic_show_keys_on_exit(void* context) {
|
||||
NfcApp* instance = context;
|
||||
widget_reset(instance->widget);
|
||||
furi_string_reset(instance->text_box_store);
|
||||
}
|
||||
Reference in New Issue
Block a user