mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-22 05:14:46 -07:00
Fuzzers App: attack gui
This commit is contained in:
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);
|
||||
Reference in New Issue
Block a user