Просмотр исходного кода

Picopass: key change to custom elite key

Eric Betts 2 лет назад
Родитель
Сommit
01b00bb65a
5 измененных файлов с 77 добавлено и 1 удалено
  1. 11 0
      picopass.c
  2. 4 0
      picopass_i.h
  3. 1 0
      scenes/picopass_scene_config.h
  4. 48 0
      scenes/picopass_scene_key_input.c
  5. 13 1
      scenes/picopass_scene_key_menu.c

+ 11 - 0
picopass.c

@@ -68,6 +68,13 @@ Picopass* picopass_alloc() {
         PicopassViewTextInput,
         text_input_get_view(picopass->text_input));
 
+    // Byte Input
+    picopass->byte_input = byte_input_alloc();
+    view_dispatcher_add_view(
+        picopass->view_dispatcher,
+        PicopassViewByteInput,
+        byte_input_get_view(picopass->byte_input));
+
     // Custom Widget
     picopass->widget = widget_alloc();
     view_dispatcher_add_view(
@@ -109,6 +116,10 @@ void picopass_free(Picopass* picopass) {
     view_dispatcher_remove_view(picopass->view_dispatcher, PicopassViewTextInput);
     text_input_free(picopass->text_input);
 
+    // ByteInput
+    view_dispatcher_remove_view(picopass->view_dispatcher, PicopassViewByteInput);
+    byte_input_free(picopass->byte_input);
+
     // Custom Widget
     view_dispatcher_remove_view(picopass->view_dispatcher, PicopassViewWidget);
     widget_free(picopass->widget);

+ 4 - 0
picopass_i.h

@@ -16,6 +16,7 @@
 #include <gui/modules/popup.h>
 #include <gui/modules/loading.h>
 #include <gui/modules/text_input.h>
+#include <gui/modules/byte_input.h>
 #include <gui/modules/widget.h>
 
 #include <input/input.h>
@@ -60,12 +61,14 @@ struct Picopass {
 
     char text_store[PICOPASS_TEXT_STORE_SIZE + 1];
     FuriString* text_box_store;
+    uint8_t byte_input_store[RFAL_PICOPASS_BLOCK_LEN];
 
     // Common Views
     Submenu* submenu;
     Popup* popup;
     Loading* loading;
     TextInput* text_input;
+    ByteInput* byte_input;
     Widget* widget;
     DictAttack* dict_attack;
     Loclass* loclass;
@@ -76,6 +79,7 @@ typedef enum {
     PicopassViewPopup,
     PicopassViewLoading,
     PicopassViewTextInput,
+    PicopassViewByteInput,
     PicopassViewWidget,
     PicopassViewDictAttack,
     PicopassViewLoclass,

+ 1 - 0
scenes/picopass_scene_config.h

@@ -18,3 +18,4 @@ ADD_SCENE(picopass, key_menu, KeyMenu)
 ADD_SCENE(picopass, elite_dict_attack, EliteDictAttack)
 ADD_SCENE(picopass, emulate, Emulate)
 ADD_SCENE(picopass, loclass, Loclass)
+ADD_SCENE(picopass, key_input, KeyInput)

+ 48 - 0
scenes/picopass_scene_key_input.c

@@ -0,0 +1,48 @@
+#include "../picopass_i.h"
+#include <lib/toolbox/random_name.h>
+#include <gui/modules/validators.h>
+#include <toolbox/path.h>
+
+void picopass_scene_key_input_text_input_callback(void* context) {
+    Picopass* picopass = context;
+
+    picopass->dev->dev_data.pacs.elite_kdf = true;
+    memcpy(picopass->dev->dev_data.pacs.key, picopass->byte_input_store, RFAL_PICOPASS_BLOCK_LEN);
+    view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventByteInputDone);
+}
+
+void picopass_scene_key_input_on_enter(void* context) {
+    Picopass* picopass = context;
+
+    ByteInput* byte_input = picopass->byte_input;
+    byte_input_set_header_text(byte_input, "Enter The Key In Hex");
+    byte_input_set_result_callback(
+        byte_input,
+        picopass_scene_key_input_text_input_callback,
+        NULL,
+        picopass,
+        picopass->byte_input_store,
+        RFAL_PICOPASS_BLOCK_LEN);
+    view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewByteInput);
+}
+
+bool picopass_scene_key_input_on_event(void* context, SceneManagerEvent event) {
+    Picopass* picopass = context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == PicopassCustomEventByteInputDone) {
+            scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
+            consumed = true;
+        }
+    }
+    return consumed;
+}
+
+void picopass_scene_key_input_on_exit(void* context) {
+    Picopass* picopass = context;
+
+    // Clear view
+    byte_input_set_result_callback(picopass->byte_input, NULL, NULL, NULL, NULL, 0);
+    byte_input_set_header_text(picopass->byte_input, "");
+}

+ 13 - 1
scenes/picopass_scene_key_menu.c

@@ -6,7 +6,7 @@ enum SubmenuIndex {
     SubmenuIndexWriteiCE,
     SubmenuIndexWriteiCL,
     SubmenuIndexWriteiCS,
-    SubmenuIndexWriteCustom, //TODO: user input of key
+    SubmenuIndexWriteCustom,
 };
 
 void picopass_scene_key_menu_submenu_callback(void* context, uint32_t index) {
@@ -43,6 +43,12 @@ void picopass_scene_key_menu_on_enter(void* context) {
         SubmenuIndexWriteiCS,
         picopass_scene_key_menu_submenu_callback,
         picopass);
+    submenu_add_item(
+        submenu,
+        "Write Elite",
+        SubmenuIndexWriteCustom,
+        picopass_scene_key_menu_submenu_callback,
+        picopass);
 
     submenu_set_selected_item(
         picopass->submenu,
@@ -84,6 +90,12 @@ bool picopass_scene_key_menu_on_event(void* context, SceneManagerEvent event) {
             picopass->dev->dev_data.pacs.elite_kdf = false;
             scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
             consumed = true;
+        } else if(event.event == SubmenuIndexWriteCustom) {
+            scene_manager_set_scene_state(
+                picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteCustom);
+            // Key and elite_kdf = true are both set in key_input scene
+            scene_manager_next_scene(picopass->scene_manager, PicopassSceneKeyInput);
+            consumed = true;
         }
     } else if(event.type == SceneManagerEventTypeBack) {
         consumed = scene_manager_search_and_switch_to_previous_scene(