Fuzzer App: field_editor view V2

This commit is contained in:
gid9798 2023-06-06 11:14:23 +03:00
parent b346487e76
commit 237d2ba1a0
9 changed files with 94 additions and 59 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -22,7 +22,7 @@
- [x] Rewrite `gui_const` logic - [x] Rewrite `gui_const` logic
- [ ] Separate protocol name from `fuzzer_proto_items` - [ ] Separate protocol name from `fuzzer_proto_items`
- [x] Icon in dialog - [x] Icon in dialog
- [ ] Description and buttons in `field_editor` view - [x] Description and buttons in `field_editor` view
- [ ] Protocol carousel in `main_menu` - [ ] Protocol carousel in `main_menu`
- [x] prototype - [x] prototype
- [x] UID - [x] UID

View file

@ -18,7 +18,7 @@ typedef struct {
const char* attack_name; const char* attack_name;
const char* protocol_name; const char* protocol_name;
FuzzerAttackState attack_state; FuzzerAttackState attack_state;
char* uid; FuriString* uid_str;
} FuzzerViewAttackModel; } FuzzerViewAttackModel;
void fuzzer_view_attack_reset_data( void fuzzer_view_attack_reset_data(
@ -34,38 +34,25 @@ void fuzzer_view_attack_reset_data(
model->attack_name = attack_name; model->attack_name = attack_name;
model->protocol_name = protocol_name; model->protocol_name = protocol_name;
model->attack_state = FuzzerAttackStateIdle; model->attack_state = FuzzerAttackStateIdle;
strcpy(model->uid, "Not_set"); furi_string_set_str(model->uid_str, "Not_set");
}, },
true); true);
} }
void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid) { void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid) {
furi_assert(view); furi_assert(view);
furi_assert(uid.data);
// TODO fix it
uint8_t* data = malloc(uid.data_size);
memcpy(data, uid.data, uid.data_size);
with_view_model( with_view_model(
view->view, view->view,
FuzzerViewAttackModel * model, FuzzerViewAttackModel * model,
{ {
snprintf( furi_string_printf(model->uid_str, "%02X", uid.data[0]);
model->uid, for(uint8_t i = 1; i < uid.data_size; i++) {
uid.data_size * 3, furi_string_cat_printf(model->uid_str, ":%02X", uid.data[i]);
"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", }
data[0],
data[1],
data[2],
data[3],
data[4],
data[5],
data[6],
data[7]);
}, },
true); true);
free(data);
} }
void fuzzer_view_attack_start(FuzzerViewAttack* view) { void fuzzer_view_attack_start(FuzzerViewAttack* view) {
@ -133,10 +120,11 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) {
canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, model->protocol_name); canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, model->protocol_name);
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
if(128 < canvas_string_width(canvas, model->uid)) { if(128 < canvas_string_width(canvas, furi_string_get_cstr(model->uid_str))) {
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
} }
canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignTop, model->uid); canvas_draw_str_aligned(
canvas, 64, 38, AlignCenter, AlignTop, furi_string_get_cstr(model->uid_str));
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
if(model->attack_state == FuzzerAttackStateRunning) { if(model->attack_state == FuzzerAttackStateRunning) {
@ -245,10 +233,11 @@ FuzzerViewAttack* fuzzer_view_attack_alloc() {
FuzzerViewAttackModel * model, FuzzerViewAttackModel * model,
{ {
model->time_delay = FUZZ_TIME_DELAY_MIN; model->time_delay = FUZZ_TIME_DELAY_MIN;
model->uid = malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1); model->uid_str = furi_string_alloc_set_str("Not_set");
// malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1);
model->attack_state = FuzzerAttackStateOff; model->attack_state = FuzzerAttackStateOff;
strcpy(model->uid, "Not_set"); // strcpy(model->uid_str, "Not_set");
model->attack_name = "Not_set"; model->attack_name = "Not_set";
model->protocol_name = "Not_set"; model->protocol_name = "Not_set";
}, },
@ -260,7 +249,10 @@ void fuzzer_view_attack_free(FuzzerViewAttack* view_attack) {
furi_assert(view_attack); furi_assert(view_attack);
with_view_model( with_view_model(
view_attack->view, FuzzerViewAttackModel * model, { free(model->uid); }, true); view_attack->view,
FuzzerViewAttackModel * model,
{ furi_string_free(model->uid_str); },
true);
view_free(view_attack->view); view_free(view_attack->view);
free(view_attack); free(view_attack);
} }

View file

@ -5,8 +5,21 @@
#include <gui/elements.h> #include <gui/elements.h>
#include <toolbox/hex.h> #include <toolbox/hex.h>
#define FIELD_EDITOR_V2
#define GUI_DISPLAY_WIDTH 128
#define GUI_DISPLAY_HEIGHT 64
#define GUI_DISPLAY_HORIZONTAL_CENTER 64
#define GUI_DISPLAY_VERTICAL_CENTER 32
#define UID_STR_LENGTH 25 #define UID_STR_LENGTH 25
#ifdef FIELD_EDITOR_V2
#define EDITOR_STRING_Y 38
#else
#define EDITOR_STRING_Y 50 #define EDITOR_STRING_Y 50
#endif
struct FuzzerViewFieldEditor { struct FuzzerViewFieldEditor {
View* view; View* view;
@ -14,7 +27,6 @@ struct FuzzerViewFieldEditor {
void* context; void* context;
}; };
// TODO model
typedef struct { typedef struct {
uint8_t* uid; uint8_t* uid;
uint8_t uid_size; uint8_t uid_size;
@ -72,15 +84,55 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m
canvas_clear(canvas); canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
#ifdef FIELD_EDITOR_V2
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 64, 5, AlignCenter, AlignTop, "Left and right: select byte");
canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Up and down: adjust byte"); canvas_draw_icon(canvas, 2, 4, &I_ButtonLeft_4x7);
canvas_draw_icon(canvas, 8, 4, &I_ButtonRight_4x7);
canvas_draw_icon_ex(canvas, 62, 3, &I_Pin_arrow_up_7x9, IconRotation180);
canvas_draw_icon(canvas, 69, 3, &I_Pin_arrow_up_7x9);
canvas_draw_str(canvas, 14, 10, "select byte");
canvas_draw_str(canvas, 79, 10, "adjust byte");
char msg_index[18]; char msg_index[18];
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
snprintf(msg_index, sizeof(msg_index), "Field index : %d", model->index); snprintf(msg_index, sizeof(msg_index), "Field index : %d", model->index);
canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignTop, msg_index);
canvas_draw_str_aligned(
canvas, GUI_DISPLAY_HORIZONTAL_CENTER, 24, AlignCenter, AlignBottom, msg_index);
canvas_set_font(canvas, FontSecondary);
canvas_draw_icon(canvas, 4, 52, &I_Pin_back_arrow_10x8);
canvas_draw_icon(canvas, 85, 52, &I_Ok_btn_9x9);
canvas_draw_str(canvas, 16, 60, "Back");
canvas_draw_str(canvas, 96, 60, "Attack");
#else
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(
canvas,
GUI_DISPLAY_HORIZONTAL_CENTER,
5,
AlignCenter,
AlignTop,
"Left and right: select byte");
canvas_draw_str_aligned(
canvas,
GUI_DISPLAY_HORIZONTAL_CENTER,
15,
AlignCenter,
AlignTop,
"Up and down: adjust byte");
char msg_index[18];
canvas_set_font(canvas, FontPrimary);
snprintf(msg_index, sizeof(msg_index), "Field index : %d", model->index);
canvas_draw_str_aligned(
canvas, GUI_DISPLAY_HORIZONTAL_CENTER, 28, AlignCenter, AlignTop, msg_index);
#endif
// ####### Editor ####### // ####### Editor #######
FuriString* temp_s = model->uid_str; FuriString* temp_s = model->uid_str;
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
@ -88,7 +140,7 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m
furi_string_reset(temp_s); furi_string_reset(temp_s);
for(int i = -3; i != 0; i++) { for(int i = -3; i != 0; i++) {
if(0 <= (model->index + i)) { if(0 <= (model->index + i)) {
furi_string_cat_printf(temp_s, "%2X ", model->uid[model->index + i]); furi_string_cat_printf(temp_s, "%02X ", model->uid[model->index + i]);
} }
} }
canvas_draw_str_aligned( canvas_draw_str_aligned(
@ -97,7 +149,7 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m
furi_string_reset(temp_s); furi_string_reset(temp_s);
for(int i = 1; i != 4; i++) { for(int i = 1; i != 4; i++) {
if((model->index + i) < model->uid_size) { if((model->index + i) < model->uid_size) {
furi_string_cat_printf(temp_s, " %2X", model->uid[model->index + i]); furi_string_cat_printf(temp_s, " %02X", model->uid[model->index + i]);
} }
} }
canvas_draw_str_aligned( canvas_draw_str_aligned(
@ -108,16 +160,31 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m
furi_string_reset(temp_s); furi_string_reset(temp_s);
furi_string_cat_printf(temp_s, "<%02X>", model->uid[model->index]); furi_string_cat_printf(temp_s, "<%02X>", model->uid[model->index]);
canvas_draw_str_aligned( canvas_draw_str_aligned(
canvas, 64, EDITOR_STRING_Y, AlignCenter, AlignBottom, furi_string_get_cstr(temp_s)); canvas,
GUI_DISPLAY_HORIZONTAL_CENTER,
EDITOR_STRING_Y,
AlignCenter,
AlignBottom,
furi_string_get_cstr(temp_s));
uint16_t w = canvas_string_width(canvas, furi_string_get_cstr(temp_s)); uint16_t w = canvas_string_width(canvas, furi_string_get_cstr(temp_s));
w -= 11; // '<' & '>' w -= 11; // '<' & '>'
w /= 2; w /= 2;
if(model->lo) { if(model->lo) {
canvas_draw_line(canvas, 64 + 1, EDITOR_STRING_Y + 2, 64 + w, EDITOR_STRING_Y + 2); canvas_draw_line(
canvas,
GUI_DISPLAY_HORIZONTAL_CENTER + 1,
EDITOR_STRING_Y + 2,
GUI_DISPLAY_HORIZONTAL_CENTER + w,
EDITOR_STRING_Y + 2);
} else { } else {
canvas_draw_line(canvas, 64 - w, EDITOR_STRING_Y + 2, 64 - 1, EDITOR_STRING_Y + 2); canvas_draw_line(
canvas,
GUI_DISPLAY_HORIZONTAL_CENTER - w,
EDITOR_STRING_Y + 2,
GUI_DISPLAY_HORIZONTAL_CENTER - 1,
EDITOR_STRING_Y + 2);
} }
// ####### Editor ####### // ####### Editor #######
} }
@ -211,29 +278,6 @@ bool fuzzer_view_field_editor_input(InputEvent* event, void* context) {
void fuzzer_view_field_editor_enter(void* context) { void fuzzer_view_field_editor_enter(void* context) {
furi_assert(context); furi_assert(context);
// TODO delete only for debug
// FuzzerViewFieldEditor* view_edit = context;
// uint8_t temp[8] = {
// 0x12,
// 0x34,
// 0x56,
// 0x78,
// 0x90,
// 0xAB,
// 0xCD,
// 0xEF,
// };
// with_view_model(
// view_edit->view,
// FuzzerViewFieldEditorModel * model,
// {
// memcpy(model->uid, &temp, 8);
// // memset(model->uid, 0xCC, 8);
// model->index = 0;
// model->uid_size = 8;
// },
// true);
} }
void fuzzer_view_field_editor_exit(void* context) { void fuzzer_view_field_editor_exit(void* context) {

View file

@ -14,7 +14,6 @@ struct FuzzerViewMain {
void* context; void* context;
}; };
// TODO Furi string for procol name
typedef struct { typedef struct {
uint8_t proto_index; uint8_t proto_index;
uint8_t menu_index; uint8_t menu_index;