unleashed-firmware/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c

150 lines
4.8 KiB
C
Raw Normal View History

2023-06-02 13:42:58 +00:00
#include "../fuzzer_i.h"
#include "../helpers/fuzzer_custom_event.h"
2023-06-03 11:24:27 +00:00
#include "../lib/worker/protocol.h"
2023-06-02 21:32:32 +00:00
2023-06-02 13:42:58 +00:00
void fuzzer_scene_main_callback(FuzzerCustomEvent event, void* context) {
furi_assert(context);
PacsFuzzerApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
2023-06-03 15:47:53 +00:00
static bool fuzzer_scene_main_load_custom_dict(void* context) {
furi_assert(context);
PacsFuzzerApp* app = context;
FuzzerConsts* consts = app->fuzzer_const;
furi_string_set_str(app->file_path, consts->custom_dict_folder);
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
&browser_options, consts->custom_dict_extension, &I_rfid_10px);
browser_options.base_path = consts->custom_dict_folder;
browser_options.hide_ext = false;
bool res =
dialog_file_browser_show(app->dialogs, app->file_path, app->file_path, &browser_options);
return res;
}
2023-06-04 17:21:51 +00:00
static bool fuzzer_scene_main_load_key(void* context) {
furi_assert(context);
PacsFuzzerApp* app = context;
FuzzerConsts* consts = app->fuzzer_const;
furi_string_set_str(app->file_path, consts->path_key_folder);
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
2023-06-05 11:10:51 +00:00
&browser_options, consts->key_extension, consts->key_icon);
2023-06-04 17:21:51 +00:00
browser_options.base_path = consts->path_key_folder;
browser_options.hide_ext = true;
bool res =
dialog_file_browser_show(app->dialogs, app->file_path, app->file_path, &browser_options);
return res;
}
2023-06-02 13:42:58 +00:00
void fuzzer_scene_main_on_enter(void* context) {
furi_assert(context);
PacsFuzzerApp* app = context;
fuzzer_view_main_set_callback(app->main_view, fuzzer_scene_main_callback, app);
2023-06-02 17:33:28 +00:00
fuzzer_view_main_update_data(app->main_view, app->fuzzer_state);
2023-06-02 13:42:58 +00:00
view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDMain);
}
bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) {
furi_assert(context);
PacsFuzzerApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == FuzzerCustomEventViewMainBack) {
if(!scene_manager_previous_scene(app->scene_manager)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
}
consumed = true;
2023-06-02 17:33:28 +00:00
} else if(event.event == FuzzerCustomEventViewMainOk) {
fuzzer_view_main_get_state(app->main_view, &app->fuzzer_state);
2023-06-02 21:32:32 +00:00
2023-06-03 15:47:53 +00:00
// TODO error logic
bool loading_ok = false;
uint8_t d_size = fuzzer_proto_get_max_data_size();
uint8_t* uid;
2023-06-03 15:47:53 +00:00
switch(fuzzer_proto_get_attack_id_by_index(app->fuzzer_state.menu_index)) {
case FuzzerAttackIdDefaultValues:
2023-06-03 15:47:53 +00:00
2023-06-05 17:24:38 +00:00
loading_ok =
fuzzer_worker_init_attack_dict(app->worker, app->fuzzer_state.proto_index);
2023-06-03 15:47:53 +00:00
if(!loading_ok) {
// error
}
break;
case FuzzerAttackIdBFCustomerID:
uid = malloc(d_size);
memset(uid, 0x00, d_size);
2023-06-03 15:47:53 +00:00
loading_ok = fuzzer_worker_init_attack_bf_byte(
app->worker, app->fuzzer_state.proto_index, uid, 0);
free(uid);
if(!loading_ok) {
// error
}
break;
case FuzzerAttackIdLoadFile:
2023-06-04 17:21:51 +00:00
if(!fuzzer_scene_main_load_key(app)) {
break;
} else {
if(fuzzer_worker_load_key_from_file(
app->worker,
app->fuzzer_state.proto_index,
furi_string_get_cstr(app->file_path))) {
scene_manager_next_scene(app->scene_manager, FuzzerSceneFieldEditor);
FURI_LOG_I("Scene", "Load ok");
} else {
FURI_LOG_W("Scene", "Load err");
}
}
2023-06-03 19:03:20 +00:00
break;
case FuzzerAttackIdLoadFileCustomUids:
2023-06-03 15:47:53 +00:00
if(!fuzzer_scene_main_load_custom_dict(app)) {
break;
} else {
2023-06-05 17:24:38 +00:00
loading_ok = fuzzer_worker_init_attack_file_dict(
2023-06-03 15:47:53 +00:00
app->worker, app->fuzzer_state.proto_index, app->file_path);
}
2023-06-02 21:32:32 +00:00
break;
default:
break;
}
2023-06-03 15:47:53 +00:00
if(loading_ok) {
scene_manager_next_scene(app->scene_manager, FuzzerSceneAttack);
}
2023-06-02 17:33:28 +00:00
consumed = true;
2023-06-02 13:42:58 +00:00
}
}
return consumed;
}
void fuzzer_scene_main_on_exit(void* context) {
// furi_assert(context);
// PacsFuzzerApp* app = context;
UNUSED(context);
}