2023-06-02 17:33:28 +00:00
|
|
|
#include "attack.h"
|
|
|
|
#include "../fuzzer_i.h"
|
|
|
|
|
|
|
|
#include <input/input.h>
|
|
|
|
#include <gui/elements.h>
|
|
|
|
|
|
|
|
#define ATTACK_SCENE_MAX_UID_LENGTH 25
|
2023-06-05 11:10:51 +00:00
|
|
|
#define UID_MAX_DISPLAYED_LEN (8U)
|
2023-06-02 17:33:28 +00:00
|
|
|
|
|
|
|
struct FuzzerViewAttack {
|
|
|
|
View* view;
|
|
|
|
FuzzerViewAttackCallback callback;
|
|
|
|
void* context;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t time_delay;
|
|
|
|
const char* attack_name;
|
|
|
|
const char* protocol_name;
|
2023-06-05 14:49:30 +00:00
|
|
|
FuzzerAttackState attack_state;
|
2023-06-02 17:33:28 +00:00
|
|
|
char* uid;
|
|
|
|
} FuzzerViewAttackModel;
|
|
|
|
|
|
|
|
void fuzzer_view_attack_reset_data(
|
|
|
|
FuzzerViewAttack* view,
|
|
|
|
const char* attack_name,
|
2023-06-05 11:10:51 +00:00
|
|
|
const char* protocol_name) {
|
2023-06-02 17:33:28 +00:00
|
|
|
furi_assert(view);
|
|
|
|
|
|
|
|
with_view_model(
|
|
|
|
view->view,
|
|
|
|
FuzzerViewAttackModel * model,
|
|
|
|
{
|
|
|
|
model->attack_name = attack_name;
|
|
|
|
model->protocol_name = protocol_name;
|
2023-06-05 14:49:30 +00:00
|
|
|
model->attack_state = FuzzerAttackStateIdle;
|
2023-06-05 11:10:51 +00:00
|
|
|
strcpy(model->uid, "Not_set");
|
2023-06-02 17:33:28 +00:00
|
|
|
},
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2023-06-05 11:10:51 +00:00
|
|
|
void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid) {
|
2023-06-02 17:33:28 +00:00
|
|
|
furi_assert(view);
|
|
|
|
|
2023-06-05 11:10:51 +00:00
|
|
|
// TODO fix it
|
|
|
|
uint8_t* data = malloc(uid.data_size);
|
|
|
|
memcpy(data, uid.data, uid.data_size);
|
|
|
|
|
2023-06-02 17:33:28 +00:00
|
|
|
with_view_model(
|
|
|
|
view->view,
|
|
|
|
FuzzerViewAttackModel * model,
|
|
|
|
{
|
|
|
|
snprintf(
|
|
|
|
model->uid,
|
2023-06-05 11:10:51 +00:00
|
|
|
uid.data_size * 3,
|
2023-06-02 17:33:28 +00:00
|
|
|
"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
|
2023-06-05 11:10:51 +00:00
|
|
|
data[0],
|
|
|
|
data[1],
|
|
|
|
data[2],
|
|
|
|
data[3],
|
|
|
|
data[4],
|
|
|
|
data[5],
|
|
|
|
data[6],
|
|
|
|
data[7]);
|
2023-06-02 17:33:28 +00:00
|
|
|
},
|
|
|
|
true);
|
2023-06-05 11:10:51 +00:00
|
|
|
|
|
|
|
free(data);
|
2023-06-02 17:33:28 +00:00
|
|
|
}
|
|
|
|
|
2023-06-05 14:49:30 +00:00
|
|
|
void fuzzer_view_attack_start(FuzzerViewAttack* view) {
|
2023-06-02 21:32:32 +00:00
|
|
|
furi_assert(view);
|
|
|
|
|
|
|
|
with_view_model(
|
2023-06-05 14:49:30 +00:00
|
|
|
view->view,
|
|
|
|
FuzzerViewAttackModel * model,
|
|
|
|
{ model->attack_state = FuzzerAttackStateRunning; },
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_view_attack_stop(FuzzerViewAttack* view) {
|
|
|
|
furi_assert(view);
|
|
|
|
|
|
|
|
with_view_model(
|
|
|
|
view->view,
|
|
|
|
FuzzerViewAttackModel * model,
|
|
|
|
{ model->attack_state = FuzzerAttackStateOff; },
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_view_attack_pause(FuzzerViewAttack* view) {
|
|
|
|
furi_assert(view);
|
|
|
|
|
|
|
|
with_view_model(
|
|
|
|
view->view,
|
|
|
|
FuzzerViewAttackModel * model,
|
|
|
|
{ model->attack_state = FuzzerAttackStateIdle; },
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_view_attack_end(FuzzerViewAttack* view) {
|
|
|
|
furi_assert(view);
|
|
|
|
|
|
|
|
with_view_model(
|
|
|
|
view->view,
|
|
|
|
FuzzerViewAttackModel * model,
|
|
|
|
{ model->attack_state = FuzzerAttackStateEnd; },
|
|
|
|
true);
|
2023-06-02 21:32:32 +00:00
|
|
|
}
|
|
|
|
|
2023-06-02 17:33:28 +00:00
|
|
|
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);
|
|
|
|
|
2023-06-02 21:32:32 +00:00
|
|
|
canvas_set_font(canvas, FontSecondary);
|
2023-06-05 14:49:30 +00:00
|
|
|
if(model->attack_state == FuzzerAttackStateRunning) {
|
2023-06-02 17:33:28 +00:00
|
|
|
elements_button_center(canvas, "Stop");
|
2023-06-05 14:49:30 +00:00
|
|
|
} else if(model->attack_state == FuzzerAttackStateIdle) {
|
2023-06-02 17:33:28 +00:00
|
|
|
elements_button_center(canvas, "Start");
|
|
|
|
elements_button_left(canvas, "TD -");
|
|
|
|
elements_button_right(canvas, "+ TD");
|
2023-06-05 14:49:30 +00:00
|
|
|
} else if(model->attack_state == FuzzerAttackStateEnd) {
|
|
|
|
// elements_button_center(canvas, "Restart"); // Reset
|
|
|
|
elements_button_left(canvas, "Exit");
|
2023-06-02 17:33:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
{
|
2023-06-05 14:49:30 +00:00
|
|
|
if(model->attack_state == FuzzerAttackStateIdle) {
|
|
|
|
// TimeDelay
|
2023-06-02 17:33:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-06-05 14:49:30 +00:00
|
|
|
} else if(
|
|
|
|
(model->attack_state == FuzzerAttackStateEnd) &&
|
|
|
|
(event->type == InputTypeShort)) {
|
|
|
|
// Exit if Ended
|
|
|
|
view_attack->callback(FuzzerCustomEventViewAttackBack, view_attack->context);
|
2023-06-02 17:33:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
return true;
|
|
|
|
} else if(event->key == InputKeyRight) {
|
|
|
|
with_view_model(
|
|
|
|
view_attack->view,
|
|
|
|
FuzzerViewAttackModel * model,
|
|
|
|
{
|
2023-06-05 14:49:30 +00:00
|
|
|
if(model->attack_state == FuzzerAttackStateIdle) {
|
|
|
|
// TimeDelay
|
2023-06-02 17:33:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-06-05 14:49:30 +00:00
|
|
|
} else {
|
|
|
|
// Nothing
|
2023-06-02 17:33:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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() {
|
2023-06-05 11:10:51 +00:00
|
|
|
if(fuzzer_proto_get_max_data_size() > UID_MAX_DISPLAYED_LEN) {
|
|
|
|
furi_crash("Maximum of displayed bytes exceeded");
|
|
|
|
}
|
|
|
|
|
2023-06-02 17:33:28 +00:00
|
|
|
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);
|
2023-06-05 14:49:30 +00:00
|
|
|
model->attack_state = FuzzerAttackStateOff;
|
2023-06-02 17:33:28 +00:00
|
|
|
|
|
|
|
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;
|
2023-06-02 21:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t fuzzer_view_attack_get_time_delay(FuzzerViewAttack* view) {
|
|
|
|
furi_assert(view);
|
|
|
|
uint8_t time_delay;
|
|
|
|
|
|
|
|
with_view_model(
|
|
|
|
view->view, FuzzerViewAttackModel * model, { time_delay = model->time_delay; }, false);
|
|
|
|
|
|
|
|
return time_delay;
|
2023-06-02 17:33:28 +00:00
|
|
|
}
|