Fuzzer App: Some Improvement

This commit is contained in:
gid9798 2023-06-05 14:10:51 +03:00
parent 3bd08ab31c
commit b95620cdd0
18 changed files with 218 additions and 159 deletions

View File

@ -113,6 +113,7 @@ int32_t fuzzer_start_ibtn(void* p) {
.custom_dict_extension = ".txt",
.key_extension = ".ibtn",
.path_key_folder = "/ext/ibutton",
.key_icon = &I_ibutt_10px,
};
fuzzer_app->fuzzer_const = &app_const;
@ -131,6 +132,7 @@ int32_t fuzzer_start_rfid(void* p) {
.custom_dict_extension = ".txt",
.key_extension = ".rfid",
.path_key_folder = "/ext/lfrfid",
.key_icon = &I_125_10px,
};
fuzzer_app->fuzzer_const = &app_const;

View File

@ -28,6 +28,7 @@ typedef struct {
const char* custom_dict_folder;
const char* key_extension;
const char* path_key_folder;
const Icon* key_icon;
} FuzzerConsts;
typedef struct {

View File

@ -1,7 +0,0 @@
#include "gui_const.h"
const char* fuzzer_attack_names[FuzzerMainMenuIndexMax] = {
[FuzzerMainMenuIndexDefaultValues] = "Default Values",
[FuzzerMainMenuIndexLoadFile] = "Load File",
[FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file",
};

View File

@ -1,12 +0,0 @@
#pragma once
// TODO replace it
typedef enum {
FuzzerMainMenuIndexDefaultValues = 0,
FuzzerMainMenuIndexLoadFile,
FuzzerMainMenuIndexLoadFileCustomUids,
FuzzerMainMenuIndexMax,
} FuzzerMainMenuIndex;
extern const char* fuzzer_attack_names[];

View File

@ -1,4 +1,5 @@
#include "fake_worker.h"
#include "protocol_i.h"
#include <timer.h>
@ -11,14 +12,12 @@
#if defined(RFID_125_PROTOCOL)
#define MAX_PAYLOAD_SIZE 6
#include <lib/lfrfid/lfrfid_dict_file.h>
#include <lib/lfrfid/lfrfid_worker.h>
#include <lfrfid/protocols/lfrfid_protocols.h>
#else
#define MAX_PAYLOAD_SIZE 8
#include <lib/ibutton/ibutton_worker.h>
#include <lib/ibutton/ibutton_key.h>
@ -175,14 +174,17 @@ static void fuzzer_worker_on_tick_callback(void* context) {
}
}
void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key) {
void fuzzer_worker_get_current_key(FuzzerWorker* worker, FuzzerPayload* output_key) {
furi_assert(worker);
furi_assert(output_key);
furi_assert(worker->protocol);
memcpy(key, worker->payload, worker->protocol->data_size);
output_key->data_size = worker->protocol->data_size;
output_key->data = malloc(sizeof(output_key->data_size));
memcpy(output_key->data, worker->payload, worker->protocol->data_size);
}
static void fuzzer_worker_set_protocol(FuzzerWorker* worker, FuzzerProtos protocol_index) {
static void fuzzer_worker_set_protocol(FuzzerWorker* worker, FuzzerProtocolsID protocol_index) {
worker->protocol = &fuzzer_proto_items[protocol_index];
#if defined(RFID_125_PROTOCOL)
@ -195,7 +197,7 @@ static void fuzzer_worker_set_protocol(FuzzerWorker* worker, FuzzerProtos protoc
#endif
}
bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index) {
bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtocolsID protocol_index) {
furi_assert(worker);
bool res = false;
@ -215,7 +217,7 @@ bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index
bool fuzzer_worker_attack_file_dict(
FuzzerWorker* worker,
FuzzerProtos protocol_index,
FuzzerProtocolsID protocol_index,
FuriString* file_path) {
furi_assert(worker);
furi_assert(file_path);
@ -248,7 +250,7 @@ bool fuzzer_worker_attack_file_dict(
bool fuzzer_worker_attack_bf_byte(
FuzzerWorker* worker,
FuzzerProtos protocol_index,
FuzzerProtocolsID protocol_index,
const uint8_t* uid,
uint8_t chusen) {
furi_assert(worker);
@ -269,7 +271,7 @@ bool fuzzer_worker_attack_bf_byte(
// TODO make it protocol independent
bool fuzzer_worker_load_key_from_file(
FuzzerWorker* worker,
FuzzerProtos protocol_index,
FuzzerProtocolsID protocol_index,
const char* filename) {
furi_assert(worker);

View File

@ -25,24 +25,24 @@ bool fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay);
void fuzzer_worker_stop(FuzzerWorker* worker);
bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index);
bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtocolsID protocol_index);
bool fuzzer_worker_attack_bf_byte(
FuzzerWorker* worker,
FuzzerProtos protocol_index,
FuzzerProtocolsID protocol_index,
const uint8_t* uid,
uint8_t chusen);
bool fuzzer_worker_attack_file_dict(
FuzzerWorker* worker,
FuzzerProtos protocol_index,
FuzzerProtocolsID protocol_index,
FuriString* file_path);
void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key);
void fuzzer_worker_get_current_key(FuzzerWorker* worker, FuzzerPayload* output_key);
bool fuzzer_worker_load_key_from_file(
FuzzerWorker* worker,
FuzzerProtos protocol_index,
FuzzerProtocolsID protocol_index,
const char* filename);
void fuzzer_worker_set_uid_chaged_callback(

View File

@ -1,4 +1,5 @@
#include "protocol.h"
#include "protocol_i.h"
#include "furi.h"
// #######################
// ## Ibutton Protocols ##
@ -156,32 +157,40 @@ const FuzzerProtocol fuzzer_proto_items[] = {
.name = "EM4100",
.data_size = EM4100_DATA_SIZE,
.dict =
{.val = (const uint8_t*)&uid_list_em4100,
.len = sizeof(uid_list_em4100) / EM4100_DATA_SIZE},
{
.val = (const uint8_t*)&uid_list_em4100,
.len = COUNT_OF(uid_list_em4100),
},
},
[HIDProx] =
{
.name = "HIDProx",
.data_size = HIDProx_DATA_SIZE,
.dict =
{.val = (const uint8_t*)&uid_list_hid,
.len = sizeof(uid_list_hid) / HIDProx_DATA_SIZE},
{
.val = (const uint8_t*)&uid_list_hid,
.len = COUNT_OF(uid_list_hid),
},
},
[PAC] =
{
.name = "PAC/Stanley",
.data_size = PAC_DATA_SIZE,
.dict =
{.val = (const uint8_t*)&uid_list_pac,
.len = sizeof(uid_list_pac) / PAC_DATA_SIZE},
{
.val = (const uint8_t*)&uid_list_pac,
.len = COUNT_OF(uid_list_pac),
},
},
[H10301] =
{
.name = "H10301",
.data_size = H10301_DATA_SIZE,
.dict =
{.val = (const uint8_t*)&uid_list_h10301,
.len = sizeof(uid_list_h10301) / H10301_DATA_SIZE},
{
.val = (const uint8_t*)&uid_list_h10301,
.len = COUNT_OF(uid_list_h10301),
},
},
};
#else
@ -191,24 +200,56 @@ const FuzzerProtocol fuzzer_proto_items[] = {
.name = "DS1990",
.data_size = DS1990_DATA_SIZE,
.dict =
{.val = (const uint8_t*)&uid_list_ds1990,
.len = sizeof(uid_list_ds1990) / DS1990_DATA_SIZE},
{
.val = (const uint8_t*)&uid_list_ds1990,
.len = COUNT_OF(uid_list_ds1990),
},
},
[Metakom] =
{
.name = "Metakom",
.data_size = Metakom_DATA_SIZE,
.dict =
{.val = (const uint8_t*)&uid_list_metakom,
.len = sizeof(uid_list_metakom) / Metakom_DATA_SIZE},
{
.val = (const uint8_t*)&uid_list_metakom,
.len = COUNT_OF(uid_list_metakom),
},
},
[Cyfral] =
{
.name = "Cyfral",
.data_size = Cyfral_DATA_SIZE,
.dict =
{.val = (const uint8_t*)&uid_list_cyfral,
.len = sizeof(uid_list_cyfral) / Cyfral_DATA_SIZE},
{
.val = (const uint8_t*)&uid_list_cyfral,
.len = COUNT_OF(uid_list_cyfral),
},
},
};
#endif
const char* fuzzer_attack_names[] = {
[FuzzerMainMenuIndexDefaultValues] = "Default Values",
[FuzzerMainMenuIndexLoadFile] = "Load File",
[FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file",
};
const char* fuzzer_proto_get_name(FuzzerProtocolsID index) {
return fuzzer_proto_items[index].name;
}
uint8_t fuzzer_proto_get_count_of_protocols() {
return COUNT_OF(fuzzer_proto_items);
}
uint8_t fuzzer_proto_get_max_data_size() {
return MAX_PAYLOAD_SIZE;
}
const char* fuzzer_proto_get_menu_label(FuzzerMainMenuIndex index) {
return fuzzer_attack_names[index];
}
uint8_t fuzzer_proto_get_count_of_menu_items() {
return COUNT_OF(fuzzer_attack_names);
}

View File

@ -4,8 +4,9 @@
// #define RFID_125_PROTOCOL
typedef enum {
typedef struct FuzzerPayload FuzzerPayload;
typedef enum {
#if defined(RFID_125_PROTOCOL)
EM4100,
HIDProx,
@ -16,24 +17,25 @@ typedef enum {
Metakom,
Cyfral,
#endif
} FuzzerProtocolsID;
// Reserved
FuzzerProtoMax,
} FuzzerProtos;
typedef enum {
FuzzerMainMenuIndexDefaultValues = 0,
FuzzerMainMenuIndexLoadFile,
FuzzerMainMenuIndexLoadFileCustomUids,
} FuzzerMainMenuIndex;
struct ProtoDict {
const uint8_t* val;
const uint8_t len;
struct FuzzerPayload {
uint8_t* data;
uint8_t data_size;
};
typedef struct ProtoDict ProtoDict;
uint8_t fuzzer_proto_get_max_data_size();
struct FuzzerProtocol {
const char* name;
const uint8_t data_size;
const ProtoDict dict;
};
const char* fuzzer_proto_get_name(FuzzerProtocolsID index);
typedef struct FuzzerProtocol FuzzerProtocol;
uint8_t fuzzer_proto_get_count_of_protocols();
extern const FuzzerProtocol fuzzer_proto_items[];
const char* fuzzer_proto_get_menu_label(FuzzerMainMenuIndex index);
uint8_t fuzzer_proto_get_count_of_menu_items();

View File

@ -3,29 +3,45 @@
#include "protocol.h"
#if defined(RFID_125_PROTOCOL)
#define MAX_PAYLOAD_SIZE 6
#define FUZZ_TIME_DELAY_MIN (5)
#define FUZZ_TIME_DELAY_DEFAULT (10)
#define FUZZ_TIME_DELAY_MAX (70)
#define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt"
#define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/rfidfuzzer"
#define FUZZER_APP_KEY_EXTENSION ".rfid"
#define FUZZER_APP_PATH_KEY_FOLDER "/ext/lfrfid"
#define MAX_PAYLOAD_SIZE (6)
#else
#define MAX_PAYLOAD_SIZE 8
#define FUZZ_TIME_DELAY_MIN (4)
#define FUZZ_TIME_DELAY_DEFAULT (8)
#define FUZZ_TIME_DELAY_MAX (80)
#define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt"
#define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/ibtnfuzzer"
#define FUZZER_APP_KEY_EXTENSION ".ibtn"
#define FUZZER_APP_PATH_KEY_FOLDER "/ext/ibutton"
#define MAX_PAYLOAD_SIZE (8)
#endif
typedef struct ProtoDict ProtoDict;
typedef struct FuzzerProtocol FuzzerProtocol;
struct ProtoDict {
const uint8_t* val;
const uint8_t len; // TODO
};
struct FuzzerProtocol {
const char* name;
const uint8_t data_size;
const ProtoDict dict;
};
// #define MAX_PAYLOAD_SIZE 6
// #define FUZZ_TIME_DELAY_MIN (5)
// #define FUZZ_TIME_DELAY_DEFAULT (10)
// #define FUZZ_TIME_DELAY_MAX (70)
// #define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt"
// #define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/rfidfuzzer"
// #define FUZZER_APP_KEY_EXTENSION ".rfid"
// #define FUZZER_APP_PATH_KEY_FOLDER "/ext/lfrfid"
// #define MAX_PAYLOAD_SIZE 8
// #define FUZZ_TIME_DELAY_MIN (4)
// #define FUZZ_TIME_DELAY_DEFAULT (8)
// #define FUZZ_TIME_DELAY_MAX (80)
// #define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt"
// #define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/ibtnfuzzer"
// #define FUZZER_APP_KEY_EXTENSION ".ibtn"
// #define FUZZER_APP_PATH_KEY_FOLDER "/ext/ibutton"
extern const FuzzerProtocol fuzzer_proto_items[];

View File

@ -1,8 +1,6 @@
#include "../fuzzer_i.h"
#include "../helpers/fuzzer_custom_event.h"
#include "../helpers/gui_const.h"
// TODO simlify callbacks and attack state
void fuzzer_scene_attack_worker_tick_callback(void* context) {
@ -23,30 +21,37 @@ void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) {
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
static void fuzzer_scene_attack_update_uid(PacsFuzzerApp* app) {
furi_assert(app);
furi_assert(app->worker);
furi_assert(app->attack_view);
FuzzerPayload uid;
fuzzer_worker_get_current_key(app->worker, &uid);
fuzzer_view_attack_set_uid(app->attack_view, uid);
free(uid.data);
}
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_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[proto.data_size];
fuzzer_worker_get_current_key(app->worker, temp_uid);
fuzzer_view_attack_reset_data(
app->attack_view,
fuzzer_attack_names[app->fuzzer_state.menu_index],
proto.name,
proto.data_size);
fuzzer_proto_get_menu_label(app->fuzzer_state.menu_index),
fuzzer_proto_get_name(app->fuzzer_state.proto_index));
fuzzer_view_attack_set_attack(app->attack_view, false);
fuzzer_view_attack_set_uid(app->attack_view, (uint8_t*)&temp_uid);
fuzzer_scene_attack_update_uid(app);
scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false);
@ -84,11 +89,7 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) {
}
consumed = true;
} else if(event.event == FuzzerCustomEventViewAttackTick) {
uint8_t temp_uid[fuzzer_proto_items[app->fuzzer_state.proto_index].data_size];
fuzzer_worker_get_current_key(app->worker, temp_uid);
fuzzer_view_attack_set_uid(app->attack_view, (uint8_t*)&temp_uid);
fuzzer_scene_attack_update_uid(app);
consumed = true;
} else if(event.event == FuzzerCustomEventViewAttackEnd) {
scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false);

View File

@ -1,8 +1,6 @@
#include "../fuzzer_i.h"
#include "../helpers/fuzzer_custom_event.h"
#define UID_MAX_SIZE 8 // TODO
void fuzzer_scene_field_editor_callback(FuzzerCustomEvent event, void* context) {
furi_assert(context);
PacsFuzzerApp* app = context;
@ -16,16 +14,12 @@ void fuzzer_scene_field_editor_on_enter(void* context) {
fuzzer_view_field_editor_set_callback(
app->field_editor_view, fuzzer_scene_field_editor_callback, app);
uint8_t uid[UID_MAX_SIZE];
FuzzerPayload uid;
fuzzer_worker_get_current_key(app->worker, &uid);
uint8_t* uid_p = &uid[0];
fuzzer_view_field_editor_reset_data(app->field_editor_view, uid);
fuzzer_worker_get_current_key(app->worker, uid_p);
fuzzer_view_field_editor_reset_data(
app->field_editor_view,
uid_p,
fuzzer_proto_items[app->fuzzer_state.proto_index].data_size); // TODO
free(uid.data);
view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDFieldEditor);
}

View File

@ -2,7 +2,6 @@
#include "../helpers/fuzzer_custom_event.h"
#include "../lib/worker/protocol.h"
#include "../helpers/gui_const.h"
void fuzzer_scene_main_callback(FuzzerCustomEvent event, void* context) {
furi_assert(context);
@ -40,7 +39,7 @@ static bool fuzzer_scene_main_load_key(void* context) {
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
&browser_options, consts->key_extension, &I_rfid_10px); // TODO icon
&browser_options, consts->key_extension, consts->key_icon);
browser_options.base_path = consts->path_key_folder;
browser_options.hide_ext = true;

View File

@ -19,14 +19,14 @@
## Code Improvement
- [ ] GUI
- [ ] Rewrite `gui_const` logic
- [x] Rewrite `gui_const` logic
- [ ] Separate protocol name from `fuzzer_proto_items`
- [ ] Icon in dialog
- [x] Icon in dialog
- [ ] Description and buttons in `field_editor` view
- [ ] Protocol carousel in `main_menu`
- [ ] UID
- [ ] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views`
- [ ] `UID_MAX_SIZE`
- [x] UID
- [x] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views`
- [x] `UID_MAX_SIZE`
- [ ] Add pause
- [ ] Fix `Custom dict` attack when ended
- [ ] this can be simplified `fuzzer_proto_items`
- [x] this can be simplified `fuzzer_proto_items`

View File

@ -5,6 +5,7 @@
#include <gui/elements.h>
#define ATTACK_SCENE_MAX_UID_LENGTH 25
#define UID_MAX_DISPLAYED_LEN (8U)
struct FuzzerViewAttack {
View* view;
@ -18,14 +19,12 @@ typedef struct {
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) {
const char* protocol_name) {
furi_assert(view);
with_view_model(
@ -35,32 +34,38 @@ void fuzzer_view_attack_reset_data(
model->attack_name = attack_name;
model->protocol_name = protocol_name;
model->attack_enabled = false;
model->uid_size = uid_size;
strcpy(model->uid, "Not_set");
},
true);
}
void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid) {
void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid) {
furi_assert(view);
// TODO fix it
uint8_t* data = malloc(uid.data_size);
memcpy(data, uid.data, uid.data_size);
with_view_model(
view->view,
FuzzerViewAttackModel * model,
{
snprintf(
model->uid,
model->uid_size * 3,
uid.data_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]);
data[0],
data[1],
data[2],
data[3],
data[4],
data[5],
data[6],
data[7]);
},
true);
free(data);
}
void fuzzer_view_attack_set_attack(FuzzerViewAttack* view, bool attack) {
@ -175,6 +180,10 @@ void fuzzer_view_attack_exit(void* context) {
}
FuzzerViewAttack* fuzzer_view_attack_alloc() {
if(fuzzer_proto_get_max_data_size() > UID_MAX_DISPLAYED_LEN) {
furi_crash("Maximum of displayed bytes exceeded");
}
FuzzerViewAttack* view_attack = malloc(sizeof(FuzzerViewAttack));
// View allocation and configuration

View File

@ -2,6 +2,7 @@
#include <gui/view.h>
#include "../helpers/fuzzer_custom_event.h"
#include "../lib/worker/protocol.h"
typedef struct FuzzerViewAttack FuzzerViewAttack;
@ -21,10 +22,9 @@ 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);
const char* protocol_name);
void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid);
void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid);
void fuzzer_view_attack_set_attack(FuzzerViewAttack* view, bool attack);

View File

@ -8,8 +8,6 @@
#define UID_STR_LENGTH 25
#define EDITOR_STRING_Y 50
#define UID_MAX_SIZE 8 // TODO
struct FuzzerViewFieldEditor {
View* view;
FuzzerViewFieldEditorCallback callback;
@ -39,18 +37,17 @@ void fuzzer_view_field_editor_set_callback(
void fuzzer_view_field_editor_reset_data(
FuzzerViewFieldEditor* view_edit,
uint8_t* uid,
uint8_t uid_size) {
const FuzzerPayload new_uid) {
furi_assert(view_edit);
with_view_model(
view_edit->view,
FuzzerViewFieldEditorModel * model,
{
memcpy(model->uid, uid, uid_size);
memcpy(model->uid, new_uid.data, new_uid.data_size);
model->index = 0;
model->lo = false;
model->uid_size = uid_size;
model->uid_size = new_uid.data_size;
},
true);
}
@ -260,8 +257,7 @@ FuzzerViewFieldEditor* fuzzer_view_field_editor_alloc() {
FuzzerViewFieldEditorModel * model,
{
model->uid_str = furi_string_alloc();
model->uid = malloc(UID_MAX_SIZE);
model->uid = malloc(fuzzer_proto_get_max_data_size());
},
true);

View File

@ -2,6 +2,7 @@
#include <gui/view.h>
#include "../helpers/fuzzer_custom_event.h"
#include "../lib/worker/protocol.h"
typedef struct FuzzerViewFieldEditor FuzzerViewFieldEditor;
@ -20,9 +21,9 @@ View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_attack);
void fuzzer_view_field_editor_reset_data(
FuzzerViewFieldEditor* view_edit,
uint8_t* uid,
uint8_t uid_size);
const FuzzerPayload new_uid);
// TODO
const uint8_t* fuzzer_view_field_editor_get_uid(FuzzerViewFieldEditor* view_edit);
uint8_t fuzzer_view_field_editor_get_index(FuzzerViewFieldEditor* view_edit);

View File

@ -3,7 +3,7 @@
#include <input/input.h>
#include "../helpers/gui_const.h"
#include "../lib/worker/protocol.h"
struct FuzzerViewMain {
View* view;
@ -15,6 +15,8 @@ struct FuzzerViewMain {
typedef struct {
uint8_t proto_index;
uint8_t menu_index;
uint8_t proto_max;
uint8_t menu_max;
} FuzzerViewMainModel;
void fuzzer_view_main_update_data(FuzzerViewMain* view, FuzzerState state) {
@ -58,23 +60,33 @@ 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, fuzzer_attack_names[model->menu_index - 1]);
canvas,
64,
24,
AlignCenter,
AlignTop,
fuzzer_proto_get_menu_label(model->menu_index - 1));
}
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(
canvas, 64, 36, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index]);
canvas, 64, 36, AlignCenter, AlignTop, fuzzer_proto_get_menu_label(model->menu_index));
if(model->menu_index < FuzzerMainMenuIndexMax) {
if(model->menu_index < model->menu_max) {
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(
canvas, 64, 48, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index + 1]);
canvas,
64,
48,
AlignCenter,
AlignTop,
fuzzer_proto_get_menu_label(model->menu_index + 1));
}
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, 64, 4, AlignCenter, AlignTop, fuzzer_proto_get_name(model->proto_index));
canvas_draw_str_aligned(canvas, 101, 4, AlignCenter, AlignTop, ">");
}
@ -94,7 +106,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) {
view->view,
FuzzerViewMainModel * model,
{
if(model->menu_index < (FuzzerMainMenuIndexMax - 1)) {
if(model->menu_index < (model->menu_max - 1)) {
model->menu_index++;
}
},
@ -119,7 +131,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) {
if(model->proto_index != 0) {
model->proto_index--;
} else {
model->proto_index = (FuzzerProtoMax - 1);
model->proto_index = (model->proto_max - 1);
}
},
true);
@ -129,7 +141,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) {
view->view,
FuzzerViewMainModel * model,
{
if(model->proto_index == (FuzzerProtoMax - 1)) {
if(model->proto_index == (model->proto_max - 1)) {
model->proto_index = 0;
} else {
model->proto_index++;
@ -167,7 +179,9 @@ FuzzerViewMain* fuzzer_view_main_alloc() {
FuzzerViewMainModel * model,
{
model->proto_index = 0;
model->proto_max = fuzzer_proto_get_count_of_protocols();
model->menu_index = 0;
model->menu_max = fuzzer_proto_get_count_of_menu_items();
},
true);
return view;