Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fuzzer App: field_editor view V2
  • Loading branch information
gid9798 committed Jun 6, 2023
commit 237d2ba1a01ff1ea371d92bdaf0df7527c1ac845
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion applications/external/pacs_fuzzer/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- [x] Rewrite `gui_const` logic
- [ ] Separate protocol name from `fuzzer_proto_items`
- [x] Icon in dialog
- [ ] Description and buttons in `field_editor` view
- [x] Description and buttons in `field_editor` view
- [ ] Protocol carousel in `main_menu`
- [x] prototype
- [x] UID
Expand Down
42 changes: 17 additions & 25 deletions applications/external/pacs_fuzzer/views/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct {
const char* attack_name;
const char* protocol_name;
FuzzerAttackState attack_state;
char* uid;
FuriString* uid_str;
} FuzzerViewAttackModel;

void fuzzer_view_attack_reset_data(
Expand All @@ -34,38 +34,25 @@ void fuzzer_view_attack_reset_data(
model->attack_name = attack_name;
model->protocol_name = protocol_name;
model->attack_state = FuzzerAttackStateIdle;
strcpy(model->uid, "Not_set");
furi_string_set_str(model->uid_str, "Not_set");
},
true);
}

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);
furi_assert(uid.data);

with_view_model(
view->view,
FuzzerViewAttackModel * model,
{
snprintf(
model->uid,
uid.data_size * 3,
"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
data[0],
data[1],
data[2],
data[3],
data[4],
data[5],
data[6],
data[7]);
furi_string_printf(model->uid_str, "%02X", uid.data[0]);
for(uint8_t i = 1; i < uid.data_size; i++) {
furi_string_cat_printf(model->uid_str, ":%02X", uid.data[i]);
}
},
true);

free(data);
}

void fuzzer_view_attack_start(FuzzerViewAttack* view) {
Expand Down Expand Up @@ -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_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_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);
if(model->attack_state == FuzzerAttackStateRunning) {
Expand Down Expand Up @@ -245,10 +233,11 @@ FuzzerViewAttack* fuzzer_view_attack_alloc() {
FuzzerViewAttackModel * model,
{
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;

strcpy(model->uid, "Not_set");
// strcpy(model->uid_str, "Not_set");
model->attack_name = "Not_set";
model->protocol_name = "Not_set";
},
Expand All @@ -260,7 +249,10 @@ 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_attack->view,
FuzzerViewAttackModel * model,
{ furi_string_free(model->uid_str); },
true);
view_free(view_attack->view);
free(view_attack);
}
Expand Down
108 changes: 76 additions & 32 deletions applications/external/pacs_fuzzer/views/field_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@
#include <gui/elements.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

#ifdef FIELD_EDITOR_V2
#define EDITOR_STRING_Y 38
#else
#define EDITOR_STRING_Y 50
#endif

struct FuzzerViewFieldEditor {
View* view;
FuzzerViewFieldEditorCallback callback;
void* context;
};

// TODO model
typedef struct {
uint8_t* uid;
uint8_t uid_size;
Expand Down Expand Up @@ -72,23 +84,63 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);

#ifdef FIELD_EDITOR_V2

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];
canvas_set_font(canvas, FontPrimary);
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 #######
FuriString* temp_s = model->uid_str;
canvas_set_font(canvas, FontSecondary);

furi_string_reset(temp_s);
for(int i = -3; i != 0; 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(
Expand All @@ -97,7 +149,7 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m
furi_string_reset(temp_s);
for(int i = 1; i != 4; i++) {
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(
Expand All @@ -108,16 +160,31 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m
furi_string_reset(temp_s);
furi_string_cat_printf(temp_s, "<%02X>", model->uid[model->index]);
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));
w -= 11; // '<' & '>'
w /= 2;

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 {
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 #######
}
Expand Down Expand Up @@ -211,29 +278,6 @@ bool fuzzer_view_field_editor_input(InputEvent* event, void* context) {

void fuzzer_view_field_editor_enter(void* 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) {
Expand Down
1 change: 0 additions & 1 deletion applications/external/pacs_fuzzer/views/main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct FuzzerViewMain {
void* context;
};

// TODO Furi string for procol name
typedef struct {
uint8_t proto_index;
uint8_t menu_index;
Expand Down