From e5b86f712146bfa45523b5abf42438e336553f05 Mon Sep 17 00:00:00 2001 From: Eric Betts Date: Mon, 18 Dec 2023 05:35:22 -0800 Subject: [PATCH] Picopass: More info view (raw bytes) (#86) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- picopass/picopass.c | 11 +++++ picopass/picopass_i.h | 3 ++ picopass/scenes/picopass_scene_config.h | 1 + picopass/scenes/picopass_scene_device_info.c | 9 ++++ picopass/scenes/picopass_scene_more_info.c | 50 ++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 picopass/scenes/picopass_scene_more_info.c diff --git a/picopass/picopass.c b/picopass/picopass.c index 14855870..9b5532e5 100644 --- a/picopass/picopass.c +++ b/picopass/picopass.c @@ -76,6 +76,12 @@ Picopass* picopass_alloc() { PicopassViewByteInput, byte_input_get_view(picopass->byte_input)); + // TextBox + picopass->text_box = text_box_alloc(); + view_dispatcher_add_view( + picopass->view_dispatcher, PicopassViewTextBox, text_box_get_view(picopass->text_box)); + picopass->text_box_store = furi_string_alloc(); + // Custom Widget picopass->widget = widget_alloc(); view_dispatcher_add_view( @@ -123,6 +129,11 @@ void picopass_free(Picopass* picopass) { view_dispatcher_remove_view(picopass->view_dispatcher, PicopassViewByteInput); byte_input_free(picopass->byte_input); + // TextBox + view_dispatcher_remove_view(picopass->view_dispatcher, PicopassViewTextBox); + text_box_free(picopass->text_box); + furi_string_free(picopass->text_box_store); + // Custom Widget view_dispatcher_remove_view(picopass->view_dispatcher, PicopassViewWidget); widget_free(picopass->widget); diff --git a/picopass/picopass_i.h b/picopass/picopass_i.h index 98d4fa87..dbb1a5d0 100644 --- a/picopass/picopass_i.h +++ b/picopass/picopass_i.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -100,6 +101,7 @@ struct Picopass { Loading* loading; TextInput* text_input; ByteInput* byte_input; + TextBox* text_box; Widget* widget; DictAttack* dict_attack; Loclass* loclass; @@ -115,6 +117,7 @@ typedef enum { PicopassViewLoading, PicopassViewTextInput, PicopassViewByteInput, + PicopassViewTextBox, PicopassViewWidget, PicopassViewDictAttack, PicopassViewLoclass, diff --git a/picopass/scenes/picopass_scene_config.h b/picopass/scenes/picopass_scene_config.h index 496591a2..0830834f 100644 --- a/picopass/scenes/picopass_scene_config.h +++ b/picopass/scenes/picopass_scene_config.h @@ -20,3 +20,4 @@ ADD_SCENE(picopass, emulate, Emulate) ADD_SCENE(picopass, loclass, Loclass) ADD_SCENE(picopass, key_input, KeyInput) ADD_SCENE(picopass, nr_mac_saved, NrMacSaved) +ADD_SCENE(picopass, more_info, MoreInfo) diff --git a/picopass/scenes/picopass_scene_device_info.c b/picopass/scenes/picopass_scene_device_info.c index de794bb4..2954d3fa 100644 --- a/picopass/scenes/picopass_scene_device_info.c +++ b/picopass/scenes/picopass_scene_device_info.c @@ -77,6 +77,12 @@ void picopass_scene_device_info_on_enter(void* context) { "Back", picopass_scene_device_info_widget_callback, picopass); + widget_add_button_element( + picopass->widget, + GuiButtonTypeRight, + "More", + picopass_scene_device_info_widget_callback, + picopass); view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget); } @@ -88,6 +94,9 @@ bool picopass_scene_device_info_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeCustom) { if(event.event == GuiButtonTypeLeft) { consumed = scene_manager_previous_scene(picopass->scene_manager); + } else if(event.event == GuiButtonTypeRight) { + scene_manager_next_scene(picopass->scene_manager, PicopassSceneMoreInfo); + consumed = true; } else if(event.event == PicopassCustomEventViewExit) { view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget); consumed = true; diff --git a/picopass/scenes/picopass_scene_more_info.c b/picopass/scenes/picopass_scene_more_info.c new file mode 100644 index 00000000..f37cdae1 --- /dev/null +++ b/picopass/scenes/picopass_scene_more_info.c @@ -0,0 +1,50 @@ +#include "../picopass_i.h" +#include + +void picopass_scene_more_info_widget_callback(GuiButtonType result, InputType type, void* context) { + Picopass* picopass = context; + if(type == InputTypeShort) { + view_dispatcher_send_custom_event(picopass->view_dispatcher, result); + } +} + +void picopass_scene_more_info_on_enter(void* context) { + Picopass* picopass = context; + PicopassBlock* AA1 = picopass->dev->dev_data.AA1; + + furi_string_reset(picopass->text_box_store); + + size_t app_limit = MIN(AA1[PICOPASS_CONFIG_BLOCK_INDEX].data[0], PICOPASS_MAX_APP_LIMIT); + FuriString* str = picopass->text_box_store; + + for(size_t i = 0; i < app_limit; i++) { + for(size_t j = 0; j < PICOPASS_BLOCK_LEN; j += 2) { + furi_string_cat_printf(str, "%02X%02X ", AA1[i].data[j], AA1[i].data[j + 1]); + } + } + + text_box_set_font(picopass->text_box, TextBoxFontHex); + text_box_set_text(picopass->text_box, furi_string_get_cstr(picopass->text_box_store)); + view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewTextBox); +} + +bool picopass_scene_more_info_on_event(void* context, SceneManagerEvent event) { + Picopass* picopass = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == GuiButtonTypeLeft) { + consumed = scene_manager_previous_scene(picopass->scene_manager); + } + } else if(event.type == SceneManagerEventTypeBack) { + consumed = scene_manager_previous_scene(picopass->scene_manager); + } + return consumed; +} + +void picopass_scene_more_info_on_exit(void* context) { + Picopass* picopass = context; + + // Clear views + widget_reset(picopass->widget); +}