2023-06-02 13:42:58 +00:00
|
|
|
#include "main_menu.h"
|
|
|
|
#include "../fuzzer_i.h"
|
|
|
|
|
|
|
|
#include <input/input.h>
|
2023-06-02 17:33:28 +00:00
|
|
|
// #include <gui/elements.h>
|
2023-06-02 13:42:58 +00:00
|
|
|
|
2023-06-02 14:48:21 +00:00
|
|
|
#include "../helpers/protocol.h"
|
2023-06-02 17:33:28 +00:00
|
|
|
#include "../helpers/gui_const.h"
|
2023-06-02 14:48:21 +00:00
|
|
|
|
2023-06-02 13:42:58 +00:00
|
|
|
struct FuzzerViewMain {
|
|
|
|
View* view;
|
|
|
|
FuzzerViewMainCallback callback;
|
|
|
|
void* context;
|
|
|
|
};
|
|
|
|
|
2023-06-02 14:48:21 +00:00
|
|
|
// TODO Furi string for procol name
|
2023-06-02 13:42:58 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t proto_index;
|
|
|
|
uint8_t menu_index;
|
|
|
|
} FuzzerViewMainModel;
|
|
|
|
|
2023-06-02 17:33:28 +00:00
|
|
|
void fuzzer_view_main_update_data(FuzzerViewMain* view, FuzzerState state) {
|
|
|
|
furi_assert(view);
|
|
|
|
with_view_model(
|
|
|
|
view->view,
|
|
|
|
FuzzerViewMainModel * model,
|
|
|
|
{
|
|
|
|
model->proto_index = state.proto_index;
|
|
|
|
model->menu_index = state.menu_index;
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_view_main_get_state(FuzzerViewMain* view, FuzzerState* state) {
|
|
|
|
furi_assert(view);
|
|
|
|
with_view_model(
|
|
|
|
view->view,
|
|
|
|
FuzzerViewMainModel * model,
|
|
|
|
{
|
|
|
|
state->proto_index = model->proto_index;
|
|
|
|
state->menu_index = model->menu_index;
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2023-06-02 13:42:58 +00:00
|
|
|
void fuzzer_view_main_set_callback(
|
2023-06-02 17:33:28 +00:00
|
|
|
FuzzerViewMain* view,
|
2023-06-02 13:42:58 +00:00
|
|
|
FuzzerViewMainCallback callback,
|
|
|
|
void* context) {
|
2023-06-02 17:33:28 +00:00
|
|
|
furi_assert(view);
|
2023-06-02 13:42:58 +00:00
|
|
|
|
2023-06-02 17:33:28 +00:00
|
|
|
view->callback = callback;
|
|
|
|
view->context = context;
|
2023-06-02 13:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) {
|
2023-06-02 14:48:21 +00:00
|
|
|
canvas_clear(canvas);
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
|
|
|
|
if(model->menu_index > 0) {
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_draw_str_aligned(
|
2023-06-02 17:33:28 +00:00
|
|
|
canvas, 64, 24, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index - 1]);
|
2023-06-02 14:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
|
canvas_draw_str_aligned(
|
2023-06-02 17:33:28 +00:00
|
|
|
canvas, 64, 36, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index]);
|
2023-06-02 14:48:21 +00:00
|
|
|
|
|
|
|
if(model->menu_index < FuzzerMainMenuIndexMax) {
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_draw_str_aligned(
|
2023-06-02 17:33:28 +00:00
|
|
|
canvas, 64, 48, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index + 1]);
|
2023-06-02 14:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
|
canvas_draw_str_aligned(canvas, 27, 4, AlignCenter, AlignTop, "<");
|
|
|
|
canvas_draw_str_aligned(
|
|
|
|
canvas, 64, 4, AlignCenter, AlignTop, fuzzer_proto_items[model->proto_index].name);
|
|
|
|
canvas_draw_str_aligned(canvas, 101, 4, AlignCenter, AlignTop, ">");
|
2023-06-02 13:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool fuzzer_view_main_input(InputEvent* event, void* context) {
|
|
|
|
furi_assert(context);
|
2023-06-02 17:33:28 +00:00
|
|
|
FuzzerViewMain* view = context;
|
2023-06-02 13:42:58 +00:00
|
|
|
|
|
|
|
if(event->key == InputKeyBack &&
|
|
|
|
(event->type == InputTypeLong || event->type == InputTypeShort)) {
|
2023-06-02 17:33:28 +00:00
|
|
|
view->callback(FuzzerCustomEventViewMainBack, view->context);
|
|
|
|
return true;
|
|
|
|
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
|
|
|
view->callback(FuzzerCustomEventViewMainOk, view->context);
|
2023-06-02 13:42:58 +00:00
|
|
|
return true;
|
2023-06-02 14:48:21 +00:00
|
|
|
} else if(event->key == InputKeyDown && event->type == InputTypeShort) {
|
|
|
|
with_view_model(
|
2023-06-02 17:33:28 +00:00
|
|
|
view->view,
|
2023-06-02 14:48:21 +00:00
|
|
|
FuzzerViewMainModel * model,
|
|
|
|
{
|
|
|
|
if(model->menu_index < (FuzzerMainMenuIndexMax - 1)) {
|
|
|
|
model->menu_index++;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
return true;
|
|
|
|
} else if(event->key == InputKeyUp && event->type == InputTypeShort) {
|
|
|
|
with_view_model(
|
2023-06-02 17:33:28 +00:00
|
|
|
view->view,
|
2023-06-02 14:48:21 +00:00
|
|
|
FuzzerViewMainModel * model,
|
|
|
|
{
|
|
|
|
if(model->menu_index != 0) {
|
|
|
|
model->menu_index--;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
return true;
|
|
|
|
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
|
|
|
with_view_model(
|
2023-06-02 17:33:28 +00:00
|
|
|
view->view,
|
2023-06-02 14:48:21 +00:00
|
|
|
FuzzerViewMainModel * model,
|
|
|
|
{
|
|
|
|
if(model->proto_index != 0) {
|
|
|
|
model->proto_index--;
|
|
|
|
} else {
|
|
|
|
model->proto_index = (FuzzerProtoMax - 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
return true;
|
|
|
|
} else if(event->key == InputKeyRight && event->type == InputTypeShort) {
|
|
|
|
with_view_model(
|
2023-06-02 17:33:28 +00:00
|
|
|
view->view,
|
2023-06-02 14:48:21 +00:00
|
|
|
FuzzerViewMainModel * model,
|
|
|
|
{
|
|
|
|
if(model->proto_index == (FuzzerProtoMax - 1)) {
|
|
|
|
model->proto_index = 0;
|
|
|
|
} else {
|
|
|
|
model->proto_index++;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
return true;
|
2023-06-02 13:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_view_main_enter(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_view_main_exit(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
FuzzerViewMain* fuzzer_view_main_alloc() {
|
2023-06-02 17:33:28 +00:00
|
|
|
FuzzerViewMain* view = malloc(sizeof(FuzzerViewMain));
|
2023-06-02 13:42:58 +00:00
|
|
|
|
|
|
|
// View allocation and configuration
|
2023-06-02 17:33:28 +00:00
|
|
|
view->view = view_alloc();
|
|
|
|
view_allocate_model(view->view, ViewModelTypeLocking, sizeof(FuzzerViewMainModel));
|
|
|
|
view_set_context(view->view, view);
|
|
|
|
view_set_draw_callback(view->view, (ViewDrawCallback)fuzzer_view_main_draw);
|
|
|
|
view_set_input_callback(view->view, fuzzer_view_main_input);
|
|
|
|
view_set_enter_callback(view->view, fuzzer_view_main_enter);
|
|
|
|
view_set_exit_callback(view->view, fuzzer_view_main_exit);
|
2023-06-02 13:42:58 +00:00
|
|
|
|
|
|
|
with_view_model(
|
2023-06-02 17:33:28 +00:00
|
|
|
view->view,
|
2023-06-02 13:42:58 +00:00
|
|
|
FuzzerViewMainModel * model,
|
|
|
|
{
|
|
|
|
model->proto_index = 0;
|
|
|
|
model->menu_index = 0;
|
|
|
|
},
|
|
|
|
true);
|
2023-06-02 17:33:28 +00:00
|
|
|
return view;
|
2023-06-02 13:42:58 +00:00
|
|
|
}
|
|
|
|
|
2023-06-02 17:33:28 +00:00
|
|
|
void fuzzer_view_main_free(FuzzerViewMain* view) {
|
|
|
|
furi_assert(view);
|
2023-06-02 13:42:58 +00:00
|
|
|
|
|
|
|
// with_view_model(
|
2023-06-02 17:33:28 +00:00
|
|
|
// view->view,
|
2023-06-02 13:42:58 +00:00
|
|
|
// FuzzerViewMainModel * model,
|
|
|
|
// {
|
|
|
|
|
|
|
|
// },
|
|
|
|
// true);
|
2023-06-02 17:33:28 +00:00
|
|
|
view_free(view->view);
|
|
|
|
free(view);
|
2023-06-02 13:42:58 +00:00
|
|
|
}
|
|
|
|
|
2023-06-02 17:33:28 +00:00
|
|
|
View* fuzzer_view_main_get_view(FuzzerViewMain* view) {
|
|
|
|
furi_assert(view);
|
|
|
|
return view->view;
|
2023-06-02 13:42:58 +00:00
|
|
|
}
|