mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-19 03:11:52 +03:00
Fuzzer App: Field editor view
This commit is contained in:
parent
2b677c83e3
commit
5b4bb66848
11
applications/external/pacs_fuzzer/fuzzer.c
vendored
11
applications/external/pacs_fuzzer/fuzzer.c
vendored
@ -48,6 +48,13 @@ PacsFuzzerApp* fuzzer_app_alloc() {
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, FuzzerViewIDAttack, fuzzer_view_attack_get_view(app->attack_view));
|
||||
|
||||
// FieldEditor view
|
||||
app->field_editor_view = fuzzer_view_field_editor_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
FuzzerViewIDFieldEditor,
|
||||
fuzzer_view_field_editor_get_view(app->field_editor_view));
|
||||
|
||||
app->scene_manager = scene_manager_alloc(&fuzzer_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
|
||||
@ -77,6 +84,10 @@ void fuzzer_app_free(PacsFuzzerApp* app) {
|
||||
view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDAttack);
|
||||
fuzzer_view_attack_free(app->attack_view);
|
||||
|
||||
// FieldEditor view
|
||||
view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDFieldEditor);
|
||||
fuzzer_view_field_editor_free(app->field_editor_view);
|
||||
|
||||
scene_manager_free(app->scene_manager);
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
|
||||
|
2
applications/external/pacs_fuzzer/fuzzer_i.h
vendored
2
applications/external/pacs_fuzzer/fuzzer_i.h
vendored
@ -12,6 +12,7 @@
|
||||
#include "scenes/fuzzer_scene.h"
|
||||
#include "views/main_menu.h"
|
||||
#include "views/attack.h"
|
||||
#include "views/field_editor.h"
|
||||
|
||||
#include "helpers/fuzzer_types.h"
|
||||
#include "lib/worker/fake_worker.h"
|
||||
@ -37,6 +38,7 @@ typedef struct {
|
||||
DialogsApp* dialogs;
|
||||
FuzzerViewMain* main_view;
|
||||
FuzzerViewAttack* attack_view;
|
||||
FuzzerViewFieldEditor* field_editor_view;
|
||||
|
||||
FuriString* file_path;
|
||||
|
||||
|
@ -10,4 +10,7 @@ typedef enum {
|
||||
FuzzerCustomEventViewAttackOk,
|
||||
FuzzerCustomEventViewAttackTick,
|
||||
FuzzerCustomEventViewAttackEnd,
|
||||
|
||||
FuzzerCustomEventViewFieldEditorBack,
|
||||
FuzzerCustomEventViewFieldEditorOk,
|
||||
} FuzzerCustomEvent;
|
@ -11,4 +11,5 @@ typedef struct {
|
||||
typedef enum {
|
||||
FuzzerViewIDMain,
|
||||
FuzzerViewIDAttack,
|
||||
FuzzerViewIDFieldEditor,
|
||||
} FuzzerViewID;
|
@ -1,2 +1,3 @@
|
||||
ADD_SCENE(fuzzer, main, Main)
|
||||
ADD_SCENE(fuzzer, attack, Attack)
|
||||
ADD_SCENE(fuzzer, attack, Attack)
|
||||
ADD_SCENE(fuzzer, field_editor, FieldEditor)
|
42
applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c
vendored
Normal file
42
applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
#include "../fuzzer_i.h"
|
||||
#include "../helpers/fuzzer_custom_event.h"
|
||||
|
||||
void fuzzer_scene_field_editor_callback(FuzzerCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
PacsFuzzerApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void fuzzer_scene_field_editor_on_enter(void* context) {
|
||||
furi_assert(context);
|
||||
PacsFuzzerApp* app = context;
|
||||
|
||||
fuzzer_view_field_editor_set_callback(
|
||||
app->field_editor_view, fuzzer_scene_field_editor_callback, app);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDFieldEditor);
|
||||
}
|
||||
|
||||
bool fuzzer_scene_field_editor_on_event(void* context, SceneManagerEvent event) {
|
||||
furi_assert(context);
|
||||
PacsFuzzerApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == FuzzerCustomEventViewFieldEditorBack) {
|
||||
if(!scene_manager_previous_scene(app->scene_manager)) {
|
||||
scene_manager_stop(app->scene_manager);
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void fuzzer_scene_field_editor_on_exit(void* context) {
|
||||
// furi_assert(context);
|
||||
// PacsFuzzerApp* app = context;
|
||||
UNUSED(context);
|
||||
}
|
@ -69,6 +69,12 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
break;
|
||||
|
||||
case FuzzerMainMenuIndexLoadFile:
|
||||
// TODO Delete
|
||||
scene_manager_next_scene(app->scene_manager, FuzzerSceneFieldEditor);
|
||||
|
||||
break;
|
||||
|
||||
case FuzzerMainMenuIndexLoadFileCustomUids:
|
||||
if(!fuzzer_scene_main_load_custom_dict(app)) {
|
||||
break;
|
||||
|
@ -4,8 +4,6 @@
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
|
||||
#include "../lib/worker/protocol.h"
|
||||
|
||||
#define ATTACK_SCENE_MAX_UID_LENGTH 25
|
||||
|
||||
struct FuzzerViewAttack {
|
||||
|
251
applications/external/pacs_fuzzer/views/field_editor.c
vendored
Normal file
251
applications/external/pacs_fuzzer/views/field_editor.c
vendored
Normal file
@ -0,0 +1,251 @@
|
||||
#include "field_editor.h"
|
||||
#include "../fuzzer_i.h"
|
||||
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
#include <toolbox/hex.h>
|
||||
|
||||
#define UID_STR_LENGTH 25
|
||||
#define EDITOR_STRING_Y 50
|
||||
|
||||
struct FuzzerViewFieldEditor {
|
||||
View* view;
|
||||
FuzzerViewFieldEditorCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
// TODO model
|
||||
typedef struct {
|
||||
uint8_t* uid;
|
||||
uint8_t uid_size;
|
||||
uint8_t index;
|
||||
FuriString* uid_str;
|
||||
bool lo;
|
||||
} FuzzerViewFieldEditorModel;
|
||||
|
||||
void fuzzer_view_field_editor_set_callback(
|
||||
FuzzerViewFieldEditor* view_edit,
|
||||
FuzzerViewFieldEditorCallback callback,
|
||||
void* context) {
|
||||
furi_assert(view_edit);
|
||||
|
||||
view_edit->callback = callback;
|
||||
view_edit->context = context;
|
||||
}
|
||||
|
||||
void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* model) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
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");
|
||||
|
||||
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);
|
||||
|
||||
// ####### 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]);
|
||||
}
|
||||
}
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 52, EDITOR_STRING_Y, AlignRight, AlignBottom, furi_string_get_cstr(temp_s));
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 77, EDITOR_STRING_Y, AlignLeft, AlignBottom, furi_string_get_cstr(temp_s));
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
|
||||
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));
|
||||
|
||||
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);
|
||||
} else {
|
||||
canvas_draw_line(canvas, 64 - w, EDITOR_STRING_Y + 2, 64 - 1, EDITOR_STRING_Y + 2);
|
||||
}
|
||||
// ####### Editor #######
|
||||
}
|
||||
|
||||
bool fuzzer_view_field_editor_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
FuzzerViewFieldEditor* view_edit = context;
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
view_edit->callback(FuzzerCustomEventViewFieldEditorBack, view_edit->context);
|
||||
return true;
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
view_edit->callback(FuzzerCustomEventViewFieldEditorOk, view_edit->context);
|
||||
return true;
|
||||
} else if(event->key == InputKeyLeft) {
|
||||
with_view_model(
|
||||
view_edit->view,
|
||||
FuzzerViewFieldEditorModel * model,
|
||||
{
|
||||
if(event->type == InputTypeShort) {
|
||||
if(model->index > 0 || model->lo) {
|
||||
if(!model->lo) {
|
||||
model->index--;
|
||||
}
|
||||
model->lo = !model->lo;
|
||||
}
|
||||
} else if(event->type == InputTypeLong) {
|
||||
model->index = 0;
|
||||
model->lo = false;
|
||||
}
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
} else if(event->key == InputKeyRight) {
|
||||
with_view_model(
|
||||
view_edit->view,
|
||||
FuzzerViewFieldEditorModel * model,
|
||||
{
|
||||
if(event->type == InputTypeShort) {
|
||||
if(model->index < (model->uid_size - 1) || !model->lo) {
|
||||
if(model->lo) {
|
||||
model->index++;
|
||||
}
|
||||
model->lo = !model->lo;
|
||||
}
|
||||
} else if(event->type == InputTypeLong) {
|
||||
model->index = model->uid_size - 1;
|
||||
model->lo = true;
|
||||
}
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
} else if(event->key == InputKeyUp) {
|
||||
with_view_model(
|
||||
view_edit->view,
|
||||
FuzzerViewFieldEditorModel * model,
|
||||
{
|
||||
if(event->type == InputTypeShort) {
|
||||
if(model->lo) {
|
||||
model->uid[model->index] = (model->uid[model->index] & 0xF0) |
|
||||
((model->uid[model->index] + 1) & 0x0F);
|
||||
} else {
|
||||
model->uid[model->index] = ((model->uid[model->index] + 0x10) & 0xF0) |
|
||||
(model->uid[model->index] & 0x0F);
|
||||
}
|
||||
}
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
} else if(event->key == InputKeyDown) {
|
||||
with_view_model(
|
||||
view_edit->view,
|
||||
FuzzerViewFieldEditorModel * model,
|
||||
{
|
||||
if(event->type == InputTypeShort) {
|
||||
if(model->lo) {
|
||||
model->uid[model->index] = (model->uid[model->index] & 0xF0) |
|
||||
((model->uid[model->index] - 1) & 0x0F);
|
||||
} else {
|
||||
model->uid[model->index] = ((model->uid[model->index] - 0x10) & 0xF0) |
|
||||
(model->uid[model->index] & 0x0F);
|
||||
}
|
||||
}
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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) {
|
||||
furi_assert(context);
|
||||
}
|
||||
|
||||
FuzzerViewFieldEditor* fuzzer_view_field_editor_alloc() {
|
||||
FuzzerViewFieldEditor* view_edit = malloc(sizeof(FuzzerViewFieldEditor));
|
||||
|
||||
// View allocation and configuration
|
||||
view_edit->view = view_alloc();
|
||||
view_allocate_model(view_edit->view, ViewModelTypeLocking, sizeof(FuzzerViewFieldEditorModel));
|
||||
view_set_context(view_edit->view, view_edit);
|
||||
view_set_draw_callback(view_edit->view, (ViewDrawCallback)fuzzer_view_field_editor_draw);
|
||||
view_set_input_callback(view_edit->view, fuzzer_view_field_editor_input);
|
||||
view_set_enter_callback(view_edit->view, fuzzer_view_field_editor_enter);
|
||||
view_set_exit_callback(view_edit->view, fuzzer_view_field_editor_exit);
|
||||
|
||||
with_view_model(
|
||||
view_edit->view,
|
||||
FuzzerViewFieldEditorModel * model,
|
||||
{
|
||||
model->uid_str = furi_string_alloc();
|
||||
|
||||
model->uid = malloc(8);
|
||||
},
|
||||
true);
|
||||
|
||||
return view_edit;
|
||||
}
|
||||
|
||||
void fuzzer_view_field_editor_free(FuzzerViewFieldEditor* view_edit) {
|
||||
furi_assert(view_edit);
|
||||
|
||||
with_view_model(
|
||||
view_edit->view,
|
||||
FuzzerViewFieldEditorModel * model,
|
||||
{
|
||||
furi_string_free(model->uid_str);
|
||||
free(model->uid);
|
||||
},
|
||||
true);
|
||||
view_free(view_edit->view);
|
||||
free(view_edit);
|
||||
}
|
||||
|
||||
View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_edit) {
|
||||
furi_assert(view_edit);
|
||||
return view_edit->view;
|
||||
}
|
19
applications/external/pacs_fuzzer/views/field_editor.h
vendored
Normal file
19
applications/external/pacs_fuzzer/views/field_editor.h
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/fuzzer_custom_event.h"
|
||||
|
||||
typedef struct FuzzerViewFieldEditor FuzzerViewFieldEditor;
|
||||
|
||||
typedef void (*FuzzerViewFieldEditorCallback)(FuzzerCustomEvent event, void* context);
|
||||
|
||||
void fuzzer_view_field_editor_set_callback(
|
||||
FuzzerViewFieldEditor* view_attack,
|
||||
FuzzerViewFieldEditorCallback callback,
|
||||
void* context);
|
||||
|
||||
FuzzerViewFieldEditor* fuzzer_view_field_editor_alloc();
|
||||
|
||||
void fuzzer_view_field_editor_free(FuzzerViewFieldEditor* view_attack);
|
||||
|
||||
View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_attack);
|
@ -2,9 +2,7 @@
|
||||
#include "../fuzzer_i.h"
|
||||
|
||||
#include <input/input.h>
|
||||
// #include <gui/elements.h>
|
||||
|
||||
#include "../lib/worker/protocol.h"
|
||||
#include "../helpers/gui_const.h"
|
||||
|
||||
struct FuzzerViewMain {
|
||||
|
Loading…
Reference in New Issue
Block a user