Skip to content

Commit e5b76f8

Browse files
committed
Picopass: key change to custom elite key
1 parent d625492 commit e5b76f8

5 files changed

+77
-1
lines changed

picopass/picopass.c

+11
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ Picopass* picopass_alloc() {
6868
PicopassViewTextInput,
6969
text_input_get_view(picopass->text_input));
7070

71+
// Byte Input
72+
picopass->byte_input = byte_input_alloc();
73+
view_dispatcher_add_view(
74+
picopass->view_dispatcher,
75+
PicopassViewByteInput,
76+
byte_input_get_view(picopass->byte_input));
77+
7178
// Custom Widget
7279
picopass->widget = widget_alloc();
7380
view_dispatcher_add_view(
@@ -109,6 +116,10 @@ void picopass_free(Picopass* picopass) {
109116
view_dispatcher_remove_view(picopass->view_dispatcher, PicopassViewTextInput);
110117
text_input_free(picopass->text_input);
111118

119+
// ByteInput
120+
view_dispatcher_remove_view(picopass->view_dispatcher, PicopassViewByteInput);
121+
byte_input_free(picopass->byte_input);
122+
112123
// Custom Widget
113124
view_dispatcher_remove_view(picopass->view_dispatcher, PicopassViewWidget);
114125
widget_free(picopass->widget);

picopass/picopass_i.h

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <gui/modules/popup.h>
1717
#include <gui/modules/loading.h>
1818
#include <gui/modules/text_input.h>
19+
#include <gui/modules/byte_input.h>
1920
#include <gui/modules/widget.h>
2021

2122
#include <input/input.h>
@@ -60,12 +61,14 @@ struct Picopass {
6061

6162
char text_store[PICOPASS_TEXT_STORE_SIZE + 1];
6263
FuriString* text_box_store;
64+
uint8_t byte_input_store[RFAL_PICOPASS_BLOCK_LEN];
6365

6466
// Common Views
6567
Submenu* submenu;
6668
Popup* popup;
6769
Loading* loading;
6870
TextInput* text_input;
71+
ByteInput* byte_input;
6972
Widget* widget;
7073
DictAttack* dict_attack;
7174
Loclass* loclass;
@@ -76,6 +79,7 @@ typedef enum {
7679
PicopassViewPopup,
7780
PicopassViewLoading,
7881
PicopassViewTextInput,
82+
PicopassViewByteInput,
7983
PicopassViewWidget,
8084
PicopassViewDictAttack,
8185
PicopassViewLoclass,

picopass/scenes/picopass_scene_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ ADD_SCENE(picopass, key_menu, KeyMenu)
1818
ADD_SCENE(picopass, elite_dict_attack, EliteDictAttack)
1919
ADD_SCENE(picopass, emulate, Emulate)
2020
ADD_SCENE(picopass, loclass, Loclass)
21+
ADD_SCENE(picopass, key_input, KeyInput)
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "../picopass_i.h"
2+
#include <lib/toolbox/random_name.h>
3+
#include <gui/modules/validators.h>
4+
#include <toolbox/path.h>
5+
6+
void picopass_scene_key_input_text_input_callback(void* context) {
7+
Picopass* picopass = context;
8+
9+
picopass->dev->dev_data.pacs.elite_kdf = true;
10+
memcpy(picopass->dev->dev_data.pacs.key, picopass->byte_input_store, RFAL_PICOPASS_BLOCK_LEN);
11+
view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventByteInputDone);
12+
}
13+
14+
void picopass_scene_key_input_on_enter(void* context) {
15+
Picopass* picopass = context;
16+
17+
ByteInput* byte_input = picopass->byte_input;
18+
byte_input_set_header_text(byte_input, "Enter The Key In Hex");
19+
byte_input_set_result_callback(
20+
byte_input,
21+
picopass_scene_key_input_text_input_callback,
22+
NULL,
23+
picopass,
24+
picopass->byte_input_store,
25+
RFAL_PICOPASS_BLOCK_LEN);
26+
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewByteInput);
27+
}
28+
29+
bool picopass_scene_key_input_on_event(void* context, SceneManagerEvent event) {
30+
Picopass* picopass = context;
31+
bool consumed = false;
32+
33+
if(event.type == SceneManagerEventTypeCustom) {
34+
if(event.event == PicopassCustomEventByteInputDone) {
35+
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
36+
consumed = true;
37+
}
38+
}
39+
return consumed;
40+
}
41+
42+
void picopass_scene_key_input_on_exit(void* context) {
43+
Picopass* picopass = context;
44+
45+
// Clear view
46+
byte_input_set_result_callback(picopass->byte_input, NULL, NULL, NULL, NULL, 0);
47+
byte_input_set_header_text(picopass->byte_input, "");
48+
}

picopass/scenes/picopass_scene_key_menu.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ enum SubmenuIndex {
66
SubmenuIndexWriteiCE,
77
SubmenuIndexWriteiCL,
88
SubmenuIndexWriteiCS,
9-
SubmenuIndexWriteCustom, //TODO: user input of key
9+
SubmenuIndexWriteCustom,
1010
};
1111

1212
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) {
4343
SubmenuIndexWriteiCS,
4444
picopass_scene_key_menu_submenu_callback,
4545
picopass);
46+
submenu_add_item(
47+
submenu,
48+
"Write Elite",
49+
SubmenuIndexWriteCustom,
50+
picopass_scene_key_menu_submenu_callback,
51+
picopass);
4652

4753
submenu_set_selected_item(
4854
picopass->submenu,
@@ -84,6 +90,12 @@ bool picopass_scene_key_menu_on_event(void* context, SceneManagerEvent event) {
8490
picopass->dev->dev_data.pacs.elite_kdf = false;
8591
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
8692
consumed = true;
93+
} else if(event.event == SubmenuIndexWriteCustom) {
94+
scene_manager_set_scene_state(
95+
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteCustom);
96+
// Key and elite_kdf = true are both set in key_input scene
97+
scene_manager_next_scene(picopass->scene_manager, PicopassSceneKeyInput);
98+
consumed = true;
8799
}
88100
} else if(event.type == SceneManagerEventTypeBack) {
89101
consumed = scene_manager_search_and_switch_to_previous_scene(

0 commit comments

Comments
 (0)