Skip to content

Commit

Permalink
upd picopass
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Dec 19, 2023
1 parent 7c40674 commit bbf4ed1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
11 changes: 11 additions & 0 deletions base_pack/picopass/picopass.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions base_pack/picopass/picopass_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <gui/modules/loading.h>
#include <gui/modules/text_input.h>
#include <gui/modules/byte_input.h>
#include <gui/modules/text_box.h>
#include <gui/modules/widget.h>

#include <input/input.h>
Expand Down Expand Up @@ -100,6 +101,7 @@ struct Picopass {
Loading* loading;
TextInput* text_input;
ByteInput* byte_input;
TextBox* text_box;
Widget* widget;
DictAttack* dict_attack;
Loclass* loclass;
Expand All @@ -115,6 +117,7 @@ typedef enum {
PicopassViewLoading,
PicopassViewTextInput,
PicopassViewByteInput,
PicopassViewTextBox,
PicopassViewWidget,
PicopassViewDictAttack,
PicopassViewLoclass,
Expand Down
1 change: 1 addition & 0 deletions base_pack/picopass/scenes/picopass_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 9 additions & 0 deletions base_pack/picopass/scenes/picopass_scene_device_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
50 changes: 50 additions & 0 deletions base_pack/picopass/scenes/picopass_scene_more_info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "../picopass_i.h"
#include <dolphin/dolphin.h>

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);
}
8 changes: 5 additions & 3 deletions base_pack/picopass/scenes/picopass_scene_read_card_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void picopass_scene_read_card_success_on_enter(void* context) {
AA1[PICOPASS_ICLASS_PACS_CFG_BLOCK_INDEX].data, 0x00, PICOPASS_BLOCK_LEN);
bool empty = picopass_is_memset(
AA1[PICOPASS_ICLASS_PACS_CFG_BLOCK_INDEX].data, 0xFF, PICOPASS_BLOCK_LEN);
bool sio = 0x30 == AA1[PICOPASS_ICLASS_PACS_CFG_BLOCK_INDEX].data[0];
bool SE = 0x30 == AA1[PICOPASS_ICLASS_PACS_CFG_BLOCK_INDEX].data[0];
bool configCard = (AA1[PICOPASS_ICLASS_PACS_CFG_BLOCK_INDEX].data[7] >> 2 & 3) == 2;

if(no_key) {
furi_string_cat_printf(wiegand_str, "Read Failed");
Expand All @@ -68,7 +69,8 @@ void picopass_scene_read_card_success_on_enter(void* context) {
"More",
picopass_scene_read_card_success_widget_callback,
picopass);

} else if(configCard) {
furi_string_cat_printf(wiegand_str, "Config Card");
} else if(empty) {
furi_string_cat_printf(wiegand_str, "Empty");
widget_add_button_element(
Expand All @@ -79,7 +81,7 @@ void picopass_scene_read_card_success_on_enter(void* context) {
picopass);
} else if(pacs->bitLength == 0 || pacs->bitLength == 255) {
// Neither of these are valid. Indicates the block was all 0x00 or all 0xff
if(sio) {
if(SE) {
furi_string_cat_printf(wiegand_str, "SIO");
} else {
furi_string_cat_printf(wiegand_str, "Invalid PACS");
Expand Down

0 comments on commit bbf4ed1

Please sign in to comment.