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

111 lines
4.2 KiB
C
Raw Normal View History

2023-06-02 20:33:28 +03:00
#include "../fuzzer_i.h"
#include "../helpers/fuzzer_custom_event.h"
#include "../helpers/gui_const.h"
2023-06-03 00:32:32 +03:00
// TODO simlify callbacks and attack state
void fuzzer_scene_attack_worker_tick_callback(void* context) {
furi_assert(context);
PacsFuzzerApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackTick);
}
void fuzzer_scene_attack_worker_end_callback(void* context) {
furi_assert(context);
PacsFuzzerApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackEnd);
}
2023-06-02 20:33:28 +03:00
void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) {
furi_assert(context);
PacsFuzzerApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void fuzzer_scene_attack_on_enter(void* context) {
furi_assert(context);
PacsFuzzerApp* app = context;
fuzzer_view_attack_set_callback(app->attack_view, fuzzer_scene_attack_callback, app);
FuzzerProtocol proto = fuzzer_proto_items[app->fuzzer_state.proto_index];
fuzzer_view_attack_reset_data(
app->attack_view,
fuzzer_attack_names[app->fuzzer_state.menu_index],
proto.name,
proto.data_size);
2023-06-03 00:32:32 +03:00
fuzzer_worker_set_uid_chaged_callback(
app->worker, fuzzer_scene_attack_worker_tick_callback, app);
fuzzer_worker_set_end_callback(app->worker, fuzzer_scene_attack_worker_end_callback, app);
uint8_t temp_uid[MAX_PAYLOAD_SIZE];
fuzzer_worker_get_current_key(app->worker, temp_uid);
fuzzer_view_attack_set_attack(app->attack_view, false);
fuzzer_view_attack_set_uid(app->attack_view, (uint8_t*)&temp_uid);
scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false);
2023-06-02 20:33:28 +03:00
view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDAttack);
}
bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) {
furi_assert(context);
PacsFuzzerApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == FuzzerCustomEventViewAttackBack) {
2023-06-03 00:32:32 +03:00
if(!scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack)) {
if(!scene_manager_previous_scene(app->scene_manager)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
}
} else {
scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false);
fuzzer_view_attack_set_attack(app->attack_view, false);
fuzzer_worker_stop(app->worker);
2023-06-02 20:33:28 +03:00
}
consumed = true;
2023-06-03 00:32:32 +03:00
} else if(event.event == FuzzerCustomEventViewAttackOk) {
if(!scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack)) {
scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, true);
fuzzer_view_attack_set_attack(app->attack_view, true);
fuzzer_worker_start(
app->worker, fuzzer_view_attack_get_time_delay(app->attack_view));
} else {
scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false);
fuzzer_view_attack_set_attack(app->attack_view, false);
fuzzer_worker_stop(app->worker);
}
consumed = true;
} else if(event.event == FuzzerCustomEventViewAttackTick) {
uint8_t temp_uid[MAX_PAYLOAD_SIZE];
fuzzer_worker_get_current_key(app->worker, temp_uid);
fuzzer_view_attack_set_uid(app->attack_view, (uint8_t*)&temp_uid);
consumed = true;
} else if(event.event == FuzzerCustomEventViewAttackEnd) {
scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false);
fuzzer_view_attack_set_attack(app->attack_view, false);
consumed = true;
2023-06-02 20:33:28 +03:00
}
}
return consumed;
}
void fuzzer_scene_attack_on_exit(void* context) {
2023-06-03 00:32:32 +03:00
furi_assert(context);
PacsFuzzerApp* app = context;
fuzzer_worker_set_uid_chaged_callback(app->worker, NULL, NULL);
fuzzer_worker_set_end_callback(app->worker, NULL, NULL);
2023-06-02 20:33:28 +03:00
}