Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from bettse/custom_key
Browse files Browse the repository at this point in the history
Picopass: key change to custom elite key
  • Loading branch information
skotopes authored Aug 5, 2023
2 parents d625492 + e5b76f8 commit fdb9b1c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
11 changes: 11 additions & 0 deletions picopass/picopass.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions picopass/picopass_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -76,6 +79,7 @@ typedef enum {
PicopassViewPopup,
PicopassViewLoading,
PicopassViewTextInput,
PicopassViewByteInput,
PicopassViewWidget,
PicopassViewDictAttack,
PicopassViewLoclass,
Expand Down
1 change: 1 addition & 0 deletions picopass/scenes/picopass_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 48 additions & 0 deletions picopass/scenes/picopass_scene_key_input.c
Original file line number Diff line number Diff line change
@@ -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, "");
}
14 changes: 13 additions & 1 deletion picopass/scenes/picopass_scene_key_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit fdb9b1c

Please sign in to comment.