unleashed-firmware/applications/flipfrid/scene/flipfrid_scene_load_custom_uids.c

80 lines
2.4 KiB
C
Raw Normal View History

2022-09-04 21:32:58 +00:00
#include "flipfrid_scene_load_custom_uids.h"
#include "flipfrid_scene_run_attack.h"
#include "flipfrid_scene_entrypoint.h"
#define LFRFID_UIDS_EXTENSION ".txt"
2022-09-05 11:05:43 +00:00
#define RFIDFUZZER_APP_PATH_FOLDER "/ext/rfidfuzzer"
2022-09-04 21:32:58 +00:00
bool flipfrid_load_uids(FlipFridState* context, const char* file_path) {
bool result = false;
Storage* storage = furi_record_open(RECORD_STORAGE);
context->uids_stream = buffered_file_stream_alloc(storage);
result =
buffered_file_stream_open(context->uids_stream, file_path, FSAM_READ, FSOM_OPEN_EXISTING);
// Close if loading fails
if(!result) {
buffered_file_stream_close(context->uids_stream);
return false;
}
return result;
}
bool flipfrid_load_custom_uids_from_file(FlipFridState* context) {
// Input events and views are managed by file_select
2022-09-05 11:05:43 +00:00
string_t uid_path;
string_init(uid_path);
string_set_str(uid_path, RFIDFUZZER_APP_PATH_FOLDER);
2022-09-04 21:32:58 +00:00
bool res = dialog_file_browser_show(
2022-09-05 11:05:43 +00:00
context->dialogs, uid_path, uid_path, LFRFID_UIDS_EXTENSION, true, &I_125_10px, false);
2022-09-04 21:32:58 +00:00
if(res) {
2022-09-05 11:05:43 +00:00
res = flipfrid_load_uids(context, string_get_cstr(uid_path));
2022-09-04 21:32:58 +00:00
}
2022-09-05 11:05:43 +00:00
string_clear(uid_path);
2022-09-04 21:32:58 +00:00
return res;
}
void flipfrid_scene_load_custom_uids_on_enter(FlipFridState* context) {
if(flipfrid_load_custom_uids_from_file(context)) {
// Force context loading
flipfrid_scene_run_attack_on_enter(context);
context->current_scene = SceneAttack;
} else {
flipfrid_scene_entrypoint_on_enter(context);
context->current_scene = SceneEntryPoint;
}
}
void flipfrid_scene_load_custom_uids_on_exit(FlipFridState* context) {
UNUSED(context);
}
void flipfrid_scene_load_custom_uids_on_tick(FlipFridState* context) {
UNUSED(context);
}
void flipfrid_scene_load_custom_uids_on_event(FlipFridEvent event, FlipFridState* context) {
if(event.evt_type == EventTypeKey) {
if(event.input_type == InputTypeShort) {
switch(event.key) {
case InputKeyDown:
case InputKeyUp:
case InputKeyLeft:
case InputKeyRight:
case InputKeyOk:
case InputKeyBack:
context->current_scene = SceneEntryPoint;
break;
}
}
}
}
void flipfrid_scene_load_custom_uids_on_draw(Canvas* canvas, FlipFridState* context) {
UNUSED(context);
UNUSED(canvas);
}