mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-19 11:21:39 +03:00
Fuzzers App: attack gui
This commit is contained in:
parent
321f2d8d50
commit
e31a0c4d6d
12
applications/external/pacs_fuzzer/fuzzer.c
vendored
12
applications/external/pacs_fuzzer/fuzzer.c
vendored
@ -22,6 +22,9 @@ static void fuzzer_app_tick_event_callback(void* context) {
|
||||
PacsFuzzerApp* fuzzer_app_alloc() {
|
||||
PacsFuzzerApp* app = malloc(sizeof(PacsFuzzerApp));
|
||||
|
||||
app->fuzzer_state.menu_index = 0;
|
||||
app->fuzzer_state.proto_index = 0;
|
||||
|
||||
// GUI
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
@ -33,6 +36,11 @@ PacsFuzzerApp* fuzzer_app_alloc() {
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, FuzzerViewIDMain, fuzzer_view_main_get_view(app->main_view));
|
||||
|
||||
// Attack view
|
||||
app->attack_view = fuzzer_view_attack_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, FuzzerViewIDAttack, fuzzer_view_attack_get_view(app->attack_view));
|
||||
|
||||
app->scene_manager = scene_manager_alloc(&fuzzer_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
|
||||
@ -58,6 +66,10 @@ void fuzzer_app_free(PacsFuzzerApp* app) {
|
||||
view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDMain);
|
||||
fuzzer_view_main_free(app->main_view);
|
||||
|
||||
// Attack view
|
||||
view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDAttack);
|
||||
fuzzer_view_attack_free(app->attack_view);
|
||||
|
||||
scene_manager_free(app->scene_manager);
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
|
||||
|
6
applications/external/pacs_fuzzer/fuzzer_i.h
vendored
6
applications/external/pacs_fuzzer/fuzzer_i.h
vendored
@ -7,6 +7,7 @@
|
||||
|
||||
#include "scenes/fuzzer_scene.h"
|
||||
#include "views/main_menu.h"
|
||||
#include "views/attack.h"
|
||||
|
||||
#include "helpers/fuzzer_types.h"
|
||||
|
||||
@ -16,6 +17,9 @@ typedef struct {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
SceneManager* scene_manager;
|
||||
FuzzerViewMain* main_view;
|
||||
|
||||
FuzzerViewMain* main_view;
|
||||
FuzzerViewAttack* attack_view;
|
||||
|
||||
FuzzerState fuzzer_state;
|
||||
} PacsFuzzerApp;
|
@ -3,6 +3,9 @@
|
||||
typedef enum {
|
||||
|
||||
// FuzzerCustomEvent
|
||||
FuzzerCustomEventViewMainOk = 100,
|
||||
FuzzerCustomEventViewMainBack,
|
||||
FuzzerCustomEventViewMainBack = 100,
|
||||
FuzzerCustomEventViewMainOk,
|
||||
|
||||
FuzzerCustomEventViewAttackBack,
|
||||
FuzzerCustomEventViewAttackOk,
|
||||
} FuzzerCustomEvent;
|
@ -3,15 +3,12 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
// TODO replace it
|
||||
typedef enum {
|
||||
FuzzerMainMenuIndexDefaultValues = 0,
|
||||
FuzzerMainMenuIndexLoadFile,
|
||||
FuzzerMainMenuIndexLoadFileCustomUids,
|
||||
|
||||
FuzzerMainMenuIndexMax,
|
||||
} FuzzerMainMenuIndex;
|
||||
typedef struct {
|
||||
uint8_t menu_index;
|
||||
uint8_t proto_index;
|
||||
} FuzzerState;
|
||||
|
||||
typedef enum {
|
||||
FuzzerViewIDMain,
|
||||
FuzzerViewIDAttack,
|
||||
} FuzzerViewID;
|
7
applications/external/pacs_fuzzer/helpers/gui_const.c
vendored
Normal file
7
applications/external/pacs_fuzzer/helpers/gui_const.c
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
#include "gui_const.h"
|
||||
|
||||
const char* fuzzer_attack_names[FuzzerMainMenuIndexMax] = {
|
||||
[FuzzerMainMenuIndexDefaultValues] = "Default Values",
|
||||
[FuzzerMainMenuIndexLoadFile] = "Load File",
|
||||
[FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file",
|
||||
};
|
12
applications/external/pacs_fuzzer/helpers/gui_const.h
vendored
Normal file
12
applications/external/pacs_fuzzer/helpers/gui_const.h
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
// TODO replace it
|
||||
typedef enum {
|
||||
FuzzerMainMenuIndexDefaultValues = 0,
|
||||
FuzzerMainMenuIndexLoadFile,
|
||||
FuzzerMainMenuIndexLoadFileCustomUids,
|
||||
|
||||
FuzzerMainMenuIndexMax,
|
||||
} FuzzerMainMenuIndex;
|
||||
|
||||
extern const char* fuzzer_attack_names[];
|
@ -2,6 +2,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define FUZZ_TIME_DELAY_MIN (4)
|
||||
#define FUZZ_TIME_DELAY_DEFAULT (8)
|
||||
#define FUZZ_TIME_DELAY_MAX (80)
|
||||
|
||||
typedef enum {
|
||||
DS1990,
|
||||
Metakom,
|
||||
|
53
applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c
vendored
Normal file
53
applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
#include "../fuzzer_i.h"
|
||||
#include "../helpers/fuzzer_custom_event.h"
|
||||
|
||||
#include "../helpers/protocol.h"
|
||||
#include "../helpers/gui_const.h"
|
||||
|
||||
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);
|
||||
fuzzer_view_attack_set_uid(app->attack_view, &proto.dict.val[0], false);
|
||||
|
||||
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) {
|
||||
if(!scene_manager_previous_scene(app->scene_manager)) {
|
||||
scene_manager_stop(app->scene_manager);
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void fuzzer_scene_attack_on_exit(void* context) {
|
||||
// furi_assert(context);
|
||||
// PacsFuzzerApp* app = context;
|
||||
UNUSED(context);
|
||||
}
|
@ -1 +1,2 @@
|
||||
ADD_SCENE(fuzzer, main, Main)
|
||||
ADD_SCENE(fuzzer, main, Main)
|
||||
ADD_SCENE(fuzzer, attack, Attack)
|
@ -13,6 +13,8 @@ void fuzzer_scene_main_on_enter(void* context) {
|
||||
|
||||
fuzzer_view_main_set_callback(app->main_view, fuzzer_scene_main_callback, app);
|
||||
|
||||
fuzzer_view_main_update_data(app->main_view, app->fuzzer_state);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDMain);
|
||||
}
|
||||
|
||||
@ -28,6 +30,10 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) {
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event.event == FuzzerCustomEventViewMainOk) {
|
||||
fuzzer_view_main_get_state(app->main_view, &app->fuzzer_state);
|
||||
scene_manager_next_scene(app->scene_manager, FuzzerSceneAttack);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
212
applications/external/pacs_fuzzer/views/attack.c
vendored
Normal file
212
applications/external/pacs_fuzzer/views/attack.c
vendored
Normal file
@ -0,0 +1,212 @@
|
||||
#include "attack.h"
|
||||
#include "../fuzzer_i.h"
|
||||
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
|
||||
#include "../helpers/protocol.h"
|
||||
|
||||
#define ATTACK_SCENE_MAX_UID_LENGTH 25
|
||||
|
||||
struct FuzzerViewAttack {
|
||||
View* view;
|
||||
FuzzerViewAttackCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t time_delay;
|
||||
const char* attack_name;
|
||||
const char* protocol_name;
|
||||
bool attack_enabled;
|
||||
char* uid;
|
||||
uint8_t uid_size;
|
||||
} FuzzerViewAttackModel;
|
||||
|
||||
void fuzzer_view_attack_reset_data(
|
||||
FuzzerViewAttack* view,
|
||||
const char* attack_name,
|
||||
const char* protocol_name,
|
||||
uint8_t uid_size) {
|
||||
furi_assert(view);
|
||||
|
||||
with_view_model(
|
||||
view->view,
|
||||
FuzzerViewAttackModel * model,
|
||||
{
|
||||
model->attack_name = attack_name;
|
||||
model->protocol_name = protocol_name;
|
||||
model->attack_enabled = false;
|
||||
model->uid_size = uid_size;
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid, bool attack) {
|
||||
furi_assert(view);
|
||||
|
||||
with_view_model(
|
||||
view->view,
|
||||
FuzzerViewAttackModel * model,
|
||||
{
|
||||
snprintf(
|
||||
model->uid,
|
||||
model->uid_size * 3,
|
||||
"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
uid[0],
|
||||
uid[1],
|
||||
uid[2],
|
||||
uid[3],
|
||||
uid[4],
|
||||
uid[5],
|
||||
uid[6],
|
||||
uid[7]);
|
||||
model->attack_enabled = attack;
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void fuzzer_view_attack_set_callback(
|
||||
FuzzerViewAttack* view_attack,
|
||||
FuzzerViewAttackCallback callback,
|
||||
void* context) {
|
||||
furi_assert(view_attack);
|
||||
|
||||
view_attack->callback = callback;
|
||||
view_attack->context = context;
|
||||
}
|
||||
|
||||
void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) {
|
||||
char time_delay[16];
|
||||
snprintf(time_delay, sizeof(time_delay), "Time delay: %d", model->time_delay);
|
||||
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, model->attack_name);
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(canvas, 64, 14, AlignCenter, AlignTop, time_delay);
|
||||
canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, model->protocol_name);
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
if(128 < canvas_string_width(canvas, model->uid)) {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
}
|
||||
canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignTop, model->uid);
|
||||
|
||||
if(model->attack_enabled) {
|
||||
elements_button_center(canvas, "Stop");
|
||||
} else {
|
||||
elements_button_center(canvas, "Start");
|
||||
elements_button_left(canvas, "TD -");
|
||||
elements_button_right(canvas, "+ TD");
|
||||
}
|
||||
}
|
||||
|
||||
bool fuzzer_view_attack_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
FuzzerViewAttack* view_attack = context;
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
view_attack->callback(FuzzerCustomEventViewAttackBack, view_attack->context);
|
||||
return true;
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
view_attack->callback(FuzzerCustomEventViewAttackOk, view_attack->context);
|
||||
return true;
|
||||
} else if(event->key == InputKeyLeft) {
|
||||
with_view_model(
|
||||
view_attack->view,
|
||||
FuzzerViewAttackModel * model,
|
||||
{
|
||||
if(!model->attack_enabled) {
|
||||
if(event->type == InputTypeShort) {
|
||||
if(model->time_delay > FUZZ_TIME_DELAY_MIN) {
|
||||
model->time_delay--;
|
||||
}
|
||||
} else if(event->type == InputTypeLong) {
|
||||
if((model->time_delay - 10) >= FUZZ_TIME_DELAY_MIN) {
|
||||
model->time_delay -= 10;
|
||||
} else {
|
||||
model->time_delay = FUZZ_TIME_DELAY_MIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
} else if(event->key == InputKeyRight) {
|
||||
with_view_model(
|
||||
view_attack->view,
|
||||
FuzzerViewAttackModel * model,
|
||||
{
|
||||
if(!model->attack_enabled) {
|
||||
if(event->type == InputTypeShort) {
|
||||
if(model->time_delay < FUZZ_TIME_DELAY_MAX) {
|
||||
model->time_delay++;
|
||||
}
|
||||
} else if(event->type == InputTypeLong) {
|
||||
model->time_delay += 10;
|
||||
if(model->time_delay > FUZZ_TIME_DELAY_MAX) {
|
||||
model->time_delay = FUZZ_TIME_DELAY_MAX;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void fuzzer_view_attack_enter(void* context) {
|
||||
furi_assert(context);
|
||||
}
|
||||
|
||||
void fuzzer_view_attack_exit(void* context) {
|
||||
furi_assert(context);
|
||||
}
|
||||
|
||||
FuzzerViewAttack* fuzzer_view_attack_alloc() {
|
||||
FuzzerViewAttack* view_attack = malloc(sizeof(FuzzerViewAttack));
|
||||
|
||||
// View allocation and configuration
|
||||
view_attack->view = view_alloc();
|
||||
view_allocate_model(view_attack->view, ViewModelTypeLocking, sizeof(FuzzerViewAttackModel));
|
||||
view_set_context(view_attack->view, view_attack);
|
||||
view_set_draw_callback(view_attack->view, (ViewDrawCallback)fuzzer_view_attack_draw);
|
||||
view_set_input_callback(view_attack->view, fuzzer_view_attack_input);
|
||||
view_set_enter_callback(view_attack->view, fuzzer_view_attack_enter);
|
||||
view_set_exit_callback(view_attack->view, fuzzer_view_attack_exit);
|
||||
|
||||
with_view_model(
|
||||
view_attack->view,
|
||||
FuzzerViewAttackModel * model,
|
||||
{
|
||||
model->time_delay = FUZZ_TIME_DELAY_MIN;
|
||||
model->uid = malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1);
|
||||
model->attack_enabled = false;
|
||||
|
||||
strcpy(model->uid, "Not_set");
|
||||
model->attack_name = "Not_set";
|
||||
model->protocol_name = "Not_set";
|
||||
},
|
||||
true);
|
||||
return view_attack;
|
||||
}
|
||||
|
||||
void fuzzer_view_attack_free(FuzzerViewAttack* view_attack) {
|
||||
furi_assert(view_attack);
|
||||
|
||||
with_view_model(
|
||||
view_attack->view, FuzzerViewAttackModel * model, { free(model->uid); }, true);
|
||||
view_free(view_attack->view);
|
||||
free(view_attack);
|
||||
}
|
||||
|
||||
View* fuzzer_view_attack_get_view(FuzzerViewAttack* view_attack) {
|
||||
furi_assert(view_attack);
|
||||
return view_attack->view;
|
||||
}
|
27
applications/external/pacs_fuzzer/views/attack.h
vendored
Normal file
27
applications/external/pacs_fuzzer/views/attack.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/fuzzer_custom_event.h"
|
||||
|
||||
typedef struct FuzzerViewAttack FuzzerViewAttack;
|
||||
|
||||
typedef void (*FuzzerViewAttackCallback)(FuzzerCustomEvent event, void* context);
|
||||
|
||||
void fuzzer_view_attack_set_callback(
|
||||
FuzzerViewAttack* view_attack,
|
||||
FuzzerViewAttackCallback callback,
|
||||
void* context);
|
||||
|
||||
FuzzerViewAttack* fuzzer_view_attack_alloc();
|
||||
|
||||
void fuzzer_view_attack_free(FuzzerViewAttack* view_attack);
|
||||
|
||||
View* fuzzer_view_attack_get_view(FuzzerViewAttack* view_attack);
|
||||
|
||||
void fuzzer_view_attack_reset_data(
|
||||
FuzzerViewAttack* view,
|
||||
const char* attack_name,
|
||||
const char* protocol_name,
|
||||
uint8_t uid_size);
|
||||
|
||||
void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid, bool attack);
|
@ -2,15 +2,10 @@
|
||||
#include "../fuzzer_i.h"
|
||||
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
// #include <gui/elements.h>
|
||||
|
||||
#include "../helpers/protocol.h"
|
||||
|
||||
const char* main_menu_items[FuzzerMainMenuIndexMax] = {
|
||||
[FuzzerMainMenuIndexDefaultValues] = "Default Values",
|
||||
[FuzzerMainMenuIndexLoadFile] = "Load File",
|
||||
[FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file",
|
||||
};
|
||||
#include "../helpers/gui_const.h"
|
||||
|
||||
struct FuzzerViewMain {
|
||||
View* view;
|
||||
@ -24,14 +19,38 @@ typedef struct {
|
||||
uint8_t menu_index;
|
||||
} FuzzerViewMainModel;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void fuzzer_view_main_set_callback(
|
||||
FuzzerViewMain* fuzzer_view_main,
|
||||
FuzzerViewMain* view,
|
||||
FuzzerViewMainCallback callback,
|
||||
void* context) {
|
||||
furi_assert(fuzzer_view_main);
|
||||
furi_assert(view);
|
||||
|
||||
fuzzer_view_main->callback = callback;
|
||||
fuzzer_view_main->context = context;
|
||||
view->callback = callback;
|
||||
view->context = context;
|
||||
}
|
||||
|
||||
void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) {
|
||||
@ -41,17 +60,17 @@ void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) {
|
||||
if(model->menu_index > 0) {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, 24, AlignCenter, AlignTop, main_menu_items[model->menu_index - 1]);
|
||||
canvas, 64, 24, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index - 1]);
|
||||
}
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, 36, AlignCenter, AlignTop, main_menu_items[model->menu_index]);
|
||||
canvas, 64, 36, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index]);
|
||||
|
||||
if(model->menu_index < FuzzerMainMenuIndexMax) {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, 48, AlignCenter, AlignTop, main_menu_items[model->menu_index + 1]);
|
||||
canvas, 64, 48, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index + 1]);
|
||||
}
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
@ -63,15 +82,18 @@ void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) {
|
||||
|
||||
bool fuzzer_view_main_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
FuzzerViewMain* fuzzer_view_main = context;
|
||||
FuzzerViewMain* view = context;
|
||||
|
||||
if(event->key == InputKeyBack &&
|
||||
(event->type == InputTypeLong || event->type == InputTypeShort)) {
|
||||
fuzzer_view_main->callback(FuzzerCustomEventViewMainBack, fuzzer_view_main->context);
|
||||
view->callback(FuzzerCustomEventViewMainBack, view->context);
|
||||
return true;
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
view->callback(FuzzerCustomEventViewMainOk, view->context);
|
||||
return true;
|
||||
} else if(event->key == InputKeyDown && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
fuzzer_view_main->view,
|
||||
view->view,
|
||||
FuzzerViewMainModel * model,
|
||||
{
|
||||
if(model->menu_index < (FuzzerMainMenuIndexMax - 1)) {
|
||||
@ -82,7 +104,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) {
|
||||
return true;
|
||||
} else if(event->key == InputKeyUp && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
fuzzer_view_main->view,
|
||||
view->view,
|
||||
FuzzerViewMainModel * model,
|
||||
{
|
||||
if(model->menu_index != 0) {
|
||||
@ -93,7 +115,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) {
|
||||
return true;
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
fuzzer_view_main->view,
|
||||
view->view,
|
||||
FuzzerViewMainModel * model,
|
||||
{
|
||||
if(model->proto_index != 0) {
|
||||
@ -106,7 +128,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) {
|
||||
return true;
|
||||
} else if(event->key == InputKeyRight && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
fuzzer_view_main->view,
|
||||
view->view,
|
||||
FuzzerViewMainModel * model,
|
||||
{
|
||||
if(model->proto_index == (FuzzerProtoMax - 1)) {
|
||||
@ -131,43 +153,43 @@ void fuzzer_view_main_exit(void* context) {
|
||||
}
|
||||
|
||||
FuzzerViewMain* fuzzer_view_main_alloc() {
|
||||
FuzzerViewMain* fuzzer_view_main = malloc(sizeof(FuzzerViewMain));
|
||||
FuzzerViewMain* view = malloc(sizeof(FuzzerViewMain));
|
||||
|
||||
// View allocation and configuration
|
||||
fuzzer_view_main->view = view_alloc();
|
||||
view_allocate_model(fuzzer_view_main->view, ViewModelTypeLocking, sizeof(FuzzerViewMainModel));
|
||||
view_set_context(fuzzer_view_main->view, fuzzer_view_main);
|
||||
view_set_draw_callback(fuzzer_view_main->view, (ViewDrawCallback)fuzzer_view_main_draw);
|
||||
view_set_input_callback(fuzzer_view_main->view, fuzzer_view_main_input);
|
||||
view_set_enter_callback(fuzzer_view_main->view, fuzzer_view_main_enter);
|
||||
view_set_exit_callback(fuzzer_view_main->view, fuzzer_view_main_exit);
|
||||
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);
|
||||
|
||||
with_view_model(
|
||||
fuzzer_view_main->view,
|
||||
view->view,
|
||||
FuzzerViewMainModel * model,
|
||||
{
|
||||
model->proto_index = 0;
|
||||
model->menu_index = 0;
|
||||
},
|
||||
true);
|
||||
return fuzzer_view_main;
|
||||
return view;
|
||||
}
|
||||
|
||||
void fuzzer_view_main_free(FuzzerViewMain* fuzzer_view_main) {
|
||||
furi_assert(fuzzer_view_main);
|
||||
void fuzzer_view_main_free(FuzzerViewMain* view) {
|
||||
furi_assert(view);
|
||||
|
||||
// with_view_model(
|
||||
// fuzzer_view_main->view,
|
||||
// view->view,
|
||||
// FuzzerViewMainModel * model,
|
||||
// {
|
||||
|
||||
// },
|
||||
// true);
|
||||
view_free(fuzzer_view_main->view);
|
||||
free(fuzzer_view_main);
|
||||
view_free(view->view);
|
||||
free(view);
|
||||
}
|
||||
|
||||
View* fuzzer_view_main_get_view(FuzzerViewMain* fuzzer_view_main) {
|
||||
furi_assert(fuzzer_view_main);
|
||||
return fuzzer_view_main->view;
|
||||
View* fuzzer_view_main_get_view(FuzzerViewMain* view) {
|
||||
furi_assert(view);
|
||||
return view->view;
|
||||
}
|
@ -2,13 +2,7 @@
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/fuzzer_custom_event.h"
|
||||
|
||||
typedef enum {
|
||||
FuzzerViewMainStateIdle,
|
||||
FuzzerViewMainStateLoading,
|
||||
FuzzerViewMainStateSending,
|
||||
FuzzerViewMainStateOFF,
|
||||
} FuzzerViewMainState;
|
||||
#include "../helpers/fuzzer_types.h"
|
||||
|
||||
typedef struct FuzzerViewMain FuzzerViewMain;
|
||||
|
||||
@ -21,6 +15,9 @@ void fuzzer_view_main_set_callback(
|
||||
|
||||
FuzzerViewMain* fuzzer_view_main_alloc();
|
||||
|
||||
void fuzzer_view_main_free(FuzzerViewMain* fuzzer_view_main);
|
||||
void fuzzer_view_main_free(FuzzerViewMain* view);
|
||||
|
||||
View* fuzzer_view_main_get_view(FuzzerViewMain* fuzzer_view_main);
|
||||
View* fuzzer_view_main_get_view(FuzzerViewMain* view);
|
||||
|
||||
void fuzzer_view_main_update_data(FuzzerViewMain* view, FuzzerState state);
|
||||
void fuzzer_view_main_get_state(FuzzerViewMain* view, FuzzerState* state);
|
Loading…
Reference in New Issue
Block a user