This commit is contained in:
RogueMaster
2022-09-17 05:41:21 -04:00
parent 1a78318fdd
commit ef24eefea3
16 changed files with 200 additions and 58 deletions

View File

@@ -47,7 +47,9 @@ void nfc_scene_device_info_on_enter(void* context) {
}
string_clear(country_name);
}
} else if(dev_data->protocol == NfcDeviceProtocolMifareClassic) {
} else if(
dev_data->protocol == NfcDeviceProtocolMifareClassic ||
dev_data->protocol == NfcDeviceProtocolMifareUl) {
string_set(temp_str, nfc->dev->dev_data.parsed_data);
}

View File

@@ -57,7 +57,7 @@ static void nfc_scene_mf_classic_dict_attack_prepare_view(Nfc* nfc, DictAttackSt
// If failed to load user dictionary - try flipper dictionary
if(!dict) {
FURI_LOG_E(TAG, "User dictionary not found");
FURI_LOG_E(TAG, "User Dictionary Not Found");
state = DictAttackStateFlipperDictInProgress;
}
}
@@ -66,7 +66,7 @@ static void nfc_scene_mf_classic_dict_attack_prepare_view(Nfc* nfc, DictAttackSt
dict_attack_set_header(nfc->dict_attack, "Mf Classic Flipper Dict.");
dict = mf_classic_dict_alloc(MfClassicDictTypeFlipper);
if(!dict) {
FURI_LOG_E(TAG, "Flipper dictionary not found");
FURI_LOG_E(TAG, "Flipper Dictionary Not Found");
// Pass through to let worker handle the failure
}
}

View File

@@ -28,9 +28,9 @@ void nfc_scene_mf_classic_keys_on_enter(void* context) {
widget_add_string_element(
nfc->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "MF Classic Keys");
char temp_str[32];
snprintf(temp_str, sizeof(temp_str), "Flipper dict: %ld", flipper_dict_keys_total);
snprintf(temp_str, sizeof(temp_str), "Flipper Dict: %ld", flipper_dict_keys_total);
widget_add_string_element(nfc->widget, 0, 20, AlignLeft, AlignTop, FontSecondary, temp_str);
snprintf(temp_str, sizeof(temp_str), "User dict: %ld", user_dict_keys_total);
snprintf(temp_str, sizeof(temp_str), "User Dict: %ld", user_dict_keys_total);
widget_add_string_element(nfc->widget, 0, 32, AlignLeft, AlignTop, FontSecondary, temp_str);
widget_add_button_element(
nfc->widget, GuiButtonTypeCenter, "Add", nfc_scene_mf_classic_keys_widget_callback, nfc);

View File

@@ -1,34 +1,109 @@
#include "../nfc_i.h"
#include <lib/nfc/protocols/mifare_ultralight.h>
#include <dolphin/dolphin.h>
#define NFC_MF_UL_DATA_NOT_CHANGED (0UL)
#define NFC_MF_UL_DATA_CHANGED (1UL)
#define NFC_SCENE_MF_ULTRALIGHT_EMULATE_LOG_SIZE_MAX (200)
enum {
// View states
NfcSceneMfUltralightEmulateStateWidget,
NfcSceneMfUltralightEmulateStateTextBox,
NfcSceneMfUltralightEmulateStateMax = 0xFF,
// State flags
NfcSceneMfUltralightEmulateStateDataChanged = 1 << 8,
NfcSceneMfUltralightEmulateStateAuthAttempted = 1 << 9,
NfcSceneMfUltralightEmulateStateLogButtonShown = 1 << 10,
};
bool nfc_mf_ultralight_emulate_worker_callback(NfcWorkerEvent event, void* context) {
UNUSED(event);
Nfc* nfc = context;
uint32_t state =
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate);
if(event == NfcWorkerEventSuccess)
state |= NfcSceneMfUltralightEmulateStateDataChanged;
else if(event == NfcWorkerEventMfUltralightPwdAuth) {
// Don't update if we're exiting
if(nfc_worker_get_state(nfc->worker) != NfcWorkerStateStop) {
// Event data is only available for the duration of this callback, so we're updating the
// text box right here
MfUltralightAuth* auth = nfc_worker_get_event_data(nfc->worker);
if(auth != NULL &&
string_size(nfc->text_box_store) < NFC_SCENE_MF_ULTRALIGHT_EMULATE_LOG_SIZE_MAX) {
string_cat(nfc->text_box_store, "PWD:");
for(size_t i = 0; i < sizeof(auth->pwd.raw); ++i) {
string_cat_printf(nfc->text_box_store, " %02X", auth->pwd.raw[i]);
}
string_push_back(nfc->text_box_store, '\n');
text_box_set_text(nfc->text_box, string_get_cstr(nfc->text_box_store));
}
state |= NfcSceneMfUltralightEmulateStateAuthAttempted;
}
}
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate, state);
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventWorkerExit);
scene_manager_set_scene_state(
nfc->scene_manager, NfcSceneMfUltralightEmulate, NFC_MF_UL_DATA_CHANGED);
return true;
}
void nfc_scene_mf_ultralight_emulate_widget_callback(
GuiButtonType result,
InputType type,
void* context) {
furi_assert(context);
Nfc* nfc = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
}
}
void nfc_scene_mf_ultralight_emulate_widget_config(Nfc* nfc, bool auth_attempted) {
Widget* widget = nfc->widget;
widget_reset(widget);
string_t info_str;
string_init(info_str);
widget_add_icon_element(widget, 0, 3, &I_RFIDDolphinSend_97x61);
if(strcmp(nfc->dev->dev_name, "")) {
string_printf(info_str, "Emulating\n%s", nfc->dev->dev_name);
} else {
string_printf(info_str, "Emulating\nMf Ultralight");
}
widget_add_string_multiline_element(
widget, 56, 31, AlignLeft, AlignTop, FontPrimary, string_get_cstr(info_str));
string_clear(info_str);
if(auth_attempted) {
widget_add_button_element(
widget,
GuiButtonTypeCenter,
"Log",
nfc_scene_mf_ultralight_emulate_widget_callback,
nfc);
}
}
void nfc_scene_mf_ultralight_emulate_on_enter(void* context) {
Nfc* nfc = context;
uint32_t state =
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate);
DOLPHIN_DEED(DolphinDeedNfcEmulate);
// Setup view
Popup* popup = nfc->popup;
if(strcmp(nfc->dev->dev_name, "")) {
nfc_text_store_set(nfc, "Emulating\n%s", nfc->dev->dev_name);
} else {
nfc_text_store_set(nfc, "Emulating\nMf Ultralight", nfc->dev->dev_name);
}
popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
popup_set_header(popup, nfc->text_store, 56, 31, AlignLeft, AlignTop);
// Setup Widget
nfc_scene_mf_ultralight_emulate_widget_config(nfc, false);
state &= ~NfcSceneMfUltralightEmulateStateLogButtonShown;
// Setup TextBox
TextBox* text_box = nfc->text_box;
text_box_set_font(text_box, TextBoxFontHex);
text_box_set_focus(text_box, TextBoxFocusEnd);
string_reset(nfc->text_box_store);
// Setup and start worker
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
// Set Widget state and view
state = (state & ~NfcSceneMfUltralightEmulateStateMax) |
NfcSceneMfUltralightEmulateStateWidget;
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate, state);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
// Start worker
nfc_worker_start(
nfc->worker,
NfcWorkerStateMfUltralightEmulate,
@@ -40,28 +115,64 @@ void nfc_scene_mf_ultralight_emulate_on_enter(void* context) {
bool nfc_scene_mf_ultralight_emulate_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = context;
uint32_t state =
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate);
bool consumed = false;
if(event.type == SceneManagerEventTypeBack) {
// Stop worker
nfc_worker_stop(nfc->worker);
// Check if data changed and save in shadow file
if(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate) ==
NFC_MF_UL_DATA_CHANGED) {
scene_manager_set_scene_state(
nfc->scene_manager, NfcSceneMfUltralightEmulate, NFC_MF_UL_DATA_NOT_CHANGED);
nfc_device_save_shadow(nfc->dev, nfc->dev->dev_name);
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventWorkerExit) {
if(state & NfcSceneMfUltralightEmulateStateAuthAttempted) {
if(!(state & NfcSceneMfUltralightEmulateStateLogButtonShown)) {
// Add log button to widget not already showing
nfc_scene_mf_ultralight_emulate_widget_config(nfc, true);
state |= NfcSceneMfUltralightEmulateStateLogButtonShown;
}
// The text box update logic is handled in the worker callback
state &= ~NfcSceneMfUltralightEmulateStateAuthAttempted;
scene_manager_set_scene_state(
nfc->scene_manager, NfcSceneMfUltralightEmulate, state);
consumed = true;
}
} else if(
event.event == GuiButtonTypeCenter && (state & NfcSceneMfUltralightEmulateStateMax) ==
NfcSceneMfUltralightEmulateStateWidget) {
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
state = (state & ~NfcSceneMfUltralightEmulateStateMax) |
NfcSceneMfUltralightEmulateStateTextBox;
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate, state);
consumed = true;
}
} else if(event.type == SceneManagerEventTypeBack) {
if((state & NfcSceneMfUltralightEmulateStateMax) ==
NfcSceneMfUltralightEmulateStateTextBox) {
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
state = (state & ~NfcSceneMfUltralightEmulateStateMax) |
NfcSceneMfUltralightEmulateStateWidget;
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate, state);
consumed = true;
}
consumed = false;
}
return consumed;
}
void nfc_scene_mf_ultralight_emulate_on_exit(void* context) {
Nfc* nfc = context;
uint32_t state =
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate);
// Stop worker
nfc_worker_stop(nfc->worker);
// Check if data changed and save in shadow file
if(state & NfcSceneMfUltralightEmulateStateDataChanged) {
state &= ~NfcSceneMfUltralightEmulateStateDataChanged;
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate, state);
nfc_device_save_shadow(nfc->dev, nfc->dev->dev_name);
}
// Clear view
popup_reset(nfc->popup);
widget_reset(nfc->widget);
text_box_reset(nfc->text_box);
string_reset(nfc->text_box_store);
nfc_blink_stop(nfc);
}

View File

@@ -11,7 +11,7 @@ void nfc_scene_mf_ultralight_key_input_on_enter(void* context) {
// Setup view
ByteInput* byte_input = nfc->byte_input;
byte_input_set_header_text(byte_input, "Enter the password in hex");
byte_input_set_header_text(byte_input, "Enter The Password In Hex");
byte_input_set_result_callback(
byte_input,
nfc_scene_mf_ultralight_key_input_byte_input_callback,

View File

@@ -26,19 +26,19 @@ void nfc_scene_mf_ultralight_read_auth_set_state(Nfc* nfc, NfcSceneMfUlReadState
if(state == NfcSceneMfUlReadStateDetecting) {
popup_reset(nfc->popup);
popup_set_text(
nfc->popup, "Apply card to\nFlipper's back", 97, 24, AlignCenter, AlignTop);
nfc->popup, "Apply Card To\nFlipper's Back", 97, 24, AlignCenter, AlignTop);
popup_set_icon(nfc->popup, 0, 8, &I_NFC_manual);
} else if(state == NfcSceneMfUlReadStateReading) {
popup_reset(nfc->popup);
popup_set_header(
nfc->popup, "Reading card\nDon't move...", 85, 24, AlignCenter, AlignTop);
nfc->popup, "Reading Card\nDon't Move...", 85, 24, AlignCenter, AlignTop);
popup_set_icon(nfc->popup, 12, 23, &A_Loading_24);
} else if(state == NfcSceneMfUlReadStateNotSupportedCard) {
popup_reset(nfc->popup);
popup_set_header(nfc->popup, "Wrong type of card!", 64, 3, AlignCenter, AlignTop);
popup_set_header(nfc->popup, "Wrong Type Of Card!", 64, 3, AlignCenter, AlignTop);
popup_set_text(
nfc->popup,
"Only MIFARE\nUltralight & NTAG\n are supported",
"Only MIFARE\nUltralight & NTAG\n Are Supported",
4,
22,
AlignLeft,

View File

@@ -34,15 +34,19 @@ void nfc_scene_mf_ultralight_read_success_on_enter(void* context) {
nfc);
string_t temp_str;
string_init_printf(temp_str, "\e#%s\n", nfc_mf_ul_type(mf_ul_data->type, true));
string_cat_printf(temp_str, "UID:");
for(size_t i = 0; i < data->uid_len; i++) {
string_cat_printf(temp_str, " %02X", data->uid[i]);
}
string_cat_printf(
temp_str, "\nPages Read: %d/%d", mf_ul_data->data_read / 4, mf_ul_data->data_size / 4);
if(mf_ul_data->data_read != mf_ul_data->data_size) {
string_cat_printf(temp_str, "\nPassword-protected pages!");
if(string_size(nfc->dev->dev_data.parsed_data)) {
string_init_set(temp_str, nfc->dev->dev_data.parsed_data);
} else {
string_init_printf(temp_str, "\e#%s\n", nfc_mf_ul_type(mf_ul_data->type, true));
string_cat_printf(temp_str, "UID:");
for(size_t i = 0; i < data->uid_len; i++) {
string_cat_printf(temp_str, " %02X", data->uid[i]);
}
string_cat_printf(
temp_str, "\nPages Read: %d/%d", mf_ul_data->data_read / 4, mf_ul_data->data_size / 4);
if(mf_ul_data->data_read != mf_ul_data->data_size) {
string_cat_printf(temp_str, "\nPassword-protected pages!");
}
}
widget_add_text_scroll_element(widget, 0, 0, 128, 52, string_get_cstr(temp_str));
string_clear(temp_str);

View File

@@ -26,7 +26,7 @@ void nfc_scene_mf_ultralight_unlock_menu_on_enter(void* context) {
nfc);
submenu_add_item(
submenu,
"Auth As Am11bo",
"Auth As Ameebo",
SubmenuIndexMfUlUnlockMenuAmeebo,
nfc_scene_mf_ultralight_unlock_menu_submenu_callback,
nfc);

View File

@@ -13,7 +13,7 @@ void nfc_scene_mf_ultralight_unlock_warn_on_enter(void* context) {
dialog_ex_set_context(dialog_ex, nfc);
dialog_ex_set_result_callback(dialog_ex, nfc_scene_mf_ultralight_unlock_warn_dialog_callback);
dialog_ex_set_header(dialog_ex, "Risky function!", 64, 4, AlignCenter, AlignTop);
dialog_ex_set_header(dialog_ex, "Risky Function!", 64, 4, AlignCenter, AlignTop);
dialog_ex_set_text(
dialog_ex, "Wrong password\ncan block your\ncard.", 4, 18, AlignLeft, AlignTop);
dialog_ex_set_icon(dialog_ex, 73, 20, &I_DolphinCommon_56x48);

View File

@@ -25,12 +25,12 @@ void nfc_scene_read_set_state(Nfc* nfc, NfcSceneReadState state) {
if(state == NfcSceneReadStateDetecting) {
popup_reset(nfc->popup);
popup_set_text(
nfc->popup, "Apply card to\nFlipper's back", 97, 24, AlignCenter, AlignTop);
nfc->popup, "Apply Card To\nFlipper's Back", 97, 24, AlignCenter, AlignTop);
popup_set_icon(nfc->popup, 0, 8, &I_NFC_manual);
} else if(state == NfcSceneReadStateReading) {
popup_reset(nfc->popup);
popup_set_header(
nfc->popup, "Reading card\nDon't move...", 85, 24, AlignCenter, AlignTop);
nfc->popup, "Reading Card\nDon't Move...", 85, 24, AlignCenter, AlignTop);
popup_set_icon(nfc->popup, 12, 23, &A_Loading_24);
}
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneRead, state);

View File

@@ -22,7 +22,7 @@ void nfc_scene_save_name_on_enter(void* context) {
} else {
nfc_text_store_set(nfc, nfc->dev->dev_name);
}
text_input_set_header_text(text_input, "Name the card");
text_input_set_header_text(text_input, "Name The Card");
text_input_set_result_callback(
text_input,
nfc_scene_save_name_text_input_callback,

View File

@@ -91,7 +91,9 @@ bool nfc_scene_saved_menu_on_event(void* context, SceneManagerEvent event) {
bool application_info_present = false;
if(dev_data->protocol == NfcDeviceProtocolEMV) {
application_info_present = true;
} else if(dev_data->protocol == NfcDeviceProtocolMifareClassic) {
} else if(
dev_data->protocol == NfcDeviceProtocolMifareClassic ||
dev_data->protocol == NfcDeviceProtocolMifareUl) {
application_info_present = nfc_supported_card_verify_and_parse(dev_data);
}