From ab86f58643be1a9d478c220c95447958cf72c194 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:42:58 +0300 Subject: [PATCH] Fuzzers App: gui start --- .../external/pacs_fuzzer/application.fam | 19 ++++ applications/external/pacs_fuzzer/fuzzer.c | 78 +++++++++++++++ applications/external/pacs_fuzzer/fuzzer_i.h | 21 ++++ .../pacs_fuzzer/helpers/fuzzer_custom_event.h | 8 ++ .../pacs_fuzzer/helpers/fuzzer_types.h | 8 ++ .../external/pacs_fuzzer/rfid_10px.png | Bin 0 -> 2389 bytes .../pacs_fuzzer/scenes/fuzzer_scene.c | 30 ++++++ .../pacs_fuzzer/scenes/fuzzer_scene.h | 29 ++++++ .../pacs_fuzzer/scenes/fuzzer_scene_config.h | 1 + .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 41 ++++++++ .../external/pacs_fuzzer/views/main_menu.c | 94 ++++++++++++++++++ .../external/pacs_fuzzer/views/main_menu.h | 26 +++++ 12 files changed, 355 insertions(+) create mode 100644 applications/external/pacs_fuzzer/application.fam create mode 100644 applications/external/pacs_fuzzer/fuzzer.c create mode 100644 applications/external/pacs_fuzzer/fuzzer_i.h create mode 100644 applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h create mode 100644 applications/external/pacs_fuzzer/helpers/fuzzer_types.h create mode 100644 applications/external/pacs_fuzzer/rfid_10px.png create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene.c create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene.h create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c create mode 100644 applications/external/pacs_fuzzer/views/main_menu.c create mode 100644 applications/external/pacs_fuzzer/views/main_menu.h diff --git a/applications/external/pacs_fuzzer/application.fam b/applications/external/pacs_fuzzer/application.fam new file mode 100644 index 000000000..5e0aafd99 --- /dev/null +++ b/applications/external/pacs_fuzzer/application.fam @@ -0,0 +1,19 @@ +App( + appid="pacs_fuzzer", + name="Fuzzer Gui", + apptype=FlipperAppType.EXTERNAL, + entry_point="fuzzer_start", + requires=[ + "gui", + "storage", + "dialogs", + "input", + "notification", + ], + stack_size=2 * 1024, + order=15, + fap_icon="rfid_10px.png", + fap_category="Debug", + # fap_icon_assets="images", + # fap_icon_assets_symbol="fuzzer", +) diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/pacs_fuzzer/fuzzer.c new file mode 100644 index 000000000..ac0400ae5 --- /dev/null +++ b/applications/external/pacs_fuzzer/fuzzer.c @@ -0,0 +1,78 @@ +#include "fuzzer_i.h" +#include "helpers/fuzzer_types.h" + +static bool fuzzer_app_custom_event_callback(void* context, uint32_t event) { + furi_assert(context); + PacsFuzzerApp* app = context; + return scene_manager_handle_custom_event(app->scene_manager, event); +} + +static bool fuzzer_app_back_event_callback(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + return scene_manager_handle_back_event(app->scene_manager); +} + +static void fuzzer_app_tick_event_callback(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + scene_manager_handle_tick_event(app->scene_manager); +} + +PacsFuzzerApp* fuzzer_app_alloc() { + PacsFuzzerApp* app = malloc(sizeof(PacsFuzzerApp)); + + // GUI + app->gui = furi_record_open(RECORD_GUI); + + // View Dispatcher + app->view_dispatcher = view_dispatcher_alloc(); + + // Main view + app->main_view = fuzzer_view_main_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, FuzzerViewIDMain, fuzzer_view_main_get_view(app->main_view)); + + app->scene_manager = scene_manager_alloc(&fuzzer_scene_handlers, app); + view_dispatcher_enable_queue(app->view_dispatcher); + + view_dispatcher_set_event_callback_context(app->view_dispatcher, app); + view_dispatcher_set_custom_event_callback( + app->view_dispatcher, fuzzer_app_custom_event_callback); + view_dispatcher_set_navigation_event_callback( + app->view_dispatcher, fuzzer_app_back_event_callback); + view_dispatcher_set_tick_event_callback( + app->view_dispatcher, fuzzer_app_tick_event_callback, 100); + + view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + + scene_manager_next_scene(app->scene_manager, FuzzerSceneMain); + + return app; +} + +void fuzzer_app_free(PacsFuzzerApp* app) { + furi_assert(app); + + // Remote view + view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDMain); + fuzzer_view_main_free(app->main_view); + + scene_manager_free(app->scene_manager); + view_dispatcher_free(app->view_dispatcher); + + // Close records + furi_record_close(RECORD_GUI); + + free(app); +} + +int32_t fuzzer_start(void* p) { + UNUSED(p); + PacsFuzzerApp* fuzzer_app = fuzzer_app_alloc(); + + view_dispatcher_run(fuzzer_app->view_dispatcher); + + fuzzer_app_free(fuzzer_app); + return 0; +} \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h new file mode 100644 index 000000000..f1ed6e738 --- /dev/null +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include +#include + +#include "scenes/fuzzer_scene.h" +#include "views/main_menu.h" + +#include "helpers/fuzzer_types.h" + +#include + +typedef struct { + Gui* gui; + ViewDispatcher* view_dispatcher; + SceneManager* scene_manager; + FuzzerViewMain* main_view; + +} PacsFuzzerApp; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h new file mode 100644 index 000000000..2ef8fce56 --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h @@ -0,0 +1,8 @@ +#pragma once + +typedef enum { + + // FuzzerCustomEvent + FuzzerCustomEventViewMainOk = 100, + FuzzerCustomEventViewMainBack, +} FuzzerCustomEvent; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h new file mode 100644 index 000000000..7b6f5a680 --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +typedef enum { + FuzzerViewIDMain, +} FuzzerViewID; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/rfid_10px.png b/applications/external/pacs_fuzzer/rfid_10px.png new file mode 100644 index 0000000000000000000000000000000000000000..8097f477552333f695733baf98f72e52ae840206 GIT binary patch literal 2389 zcmcIleQXnD7{6^!#>U44<0gnZixCj6_tCqycdm@C?Y2%j%BZlR1g>}Qb?4f<$dYAbBp?=L>s9H44zi+G=z@ z$+GSR2r_^Bu5APL?}u;SJTN7D;oJYQXJbzy83Gd~}8wyVLJ?VRDO5w9Zzw8@g?;6Z|IeLEIrsbQiG#zUHZ2RGh zXD*aUd-8i4_PpADs0}HdxBi3jq2Z#Q^P&Dr^r?|WO%j;%cM#(P)0|Mc8; z{t8g`*A^{V)i?clE}f@2H&CjT}F< z?2jues!qd7PS)z04FoBfX?^mLy)Tp_$Rt&cG?`7IrJSH9?7UT9dorQHXauRON@~2& z3QRN#VzT0~4fhY&P+9cYRxu$Wr1?OLT-T+86?9@-1c8#I)9z+Pr-LUJp%g)pI7#A^ z8>2{$U^#~a&AepaJ-|V!`|Vrt9lHFc42XX!YK-a5tz}b zn0yjbjJa6^KQIJc)=XJdPz#Zds%@sn2DzpWkAYyf`V1Rfhy zjlu{PBk2f5aSnoGTnh;YM-b`I5OjjboBR#IOoSjf8osX&Rz+FroJeRW#03?@@6WtU}<<5`k-GmIOPTuus$(zJDPkQf=2B!Xdi7eP5vyx@MnDzsUZu=b~oE2;v- z$W@bzGC*KNw}3fBr-TVK?Z%=6L1S(pkqisLNim1EOqXHr@bS^87Ap}ViVmI>S)RcJ zh9WV*(*TPy(I`d}G$F90;3Qy6q1W>I)VQjLR1sDe;)?<&sd|Ek{*e=W4B(m)v)l~P z;VJ5514`GK>5mm)eP$Jx(Uj>pUa-9Gu?d#Q0Om>GmdB{x#CWFnceDTqI*$11FhiBh z4qgY|7_9WanhU=fd4q2spSnP~C5On1n8Y&u^S%9C@(-&evej?~Ro2+Su!z(GxDJJ~1-%>yfuE?__2!EG(Q-w?lmFd+!g0U&StM zdu5hu`a91J8fzAOad#fF`0WbM%BH;qRp;*CJ^0}3t1p(6l^kTQe)IdHQfq1l0}cMe I)$5-48`f?Vpa1{> literal 0 HcmV?d00001 diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene.c new file mode 100644 index 000000000..0fe0f558d --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene.c @@ -0,0 +1,30 @@ +#include "fuzzer_scene.h" + +// Generate scene on_enter handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter, +void (*const fuzzer_scene_on_enter_handlers[])(void*) = { +#include "fuzzer_scene_config.h" +}; +#undef ADD_SCENE + +// Generate scene on_event handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event, +bool (*const fuzzer_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = { +#include "fuzzer_scene_config.h" +}; +#undef ADD_SCENE + +// Generate scene on_exit handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit, +void (*const fuzzer_scene_on_exit_handlers[])(void* context) = { +#include "fuzzer_scene_config.h" +}; +#undef ADD_SCENE + +// Initialize scene handlers configuration structure +const SceneManagerHandlers fuzzer_scene_handlers = { + .on_enter_handlers = fuzzer_scene_on_enter_handlers, + .on_event_handlers = fuzzer_scene_on_event_handlers, + .on_exit_handlers = fuzzer_scene_on_exit_handlers, + .scene_num = FuzzerSceneNum, +}; diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene.h b/applications/external/pacs_fuzzer/scenes/fuzzer_scene.h new file mode 100644 index 000000000..280654510 --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +// Generate scene id and total number +#define ADD_SCENE(prefix, name, id) FuzzerScene##id, +typedef enum { +#include "fuzzer_scene_config.h" + FuzzerSceneNum, +} FuzzerScene; +#undef ADD_SCENE + +extern const SceneManagerHandlers fuzzer_scene_handlers; + +// Generate scene on_enter handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*); +#include "fuzzer_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_event handlers declaration +#define ADD_SCENE(prefix, name, id) \ + bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event); +#include "fuzzer_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_exit handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context); +#include "fuzzer_scene_config.h" +#undef ADD_SCENE diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h new file mode 100644 index 000000000..7923cd83e --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h @@ -0,0 +1 @@ +ADD_SCENE(fuzzer, main, Main) \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c new file mode 100644 index 000000000..994867ed3 --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -0,0 +1,41 @@ +#include "../fuzzer_i.h" +#include "../helpers/fuzzer_custom_event.h" + +void fuzzer_scene_main_callback(FuzzerCustomEvent event, void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, event); +} + +void fuzzer_scene_main_on_enter(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + + fuzzer_view_main_set_callback(app->main_view, fuzzer_scene_main_callback, app); + + view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDMain); +} + +bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { + furi_assert(context); + PacsFuzzerApp* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == FuzzerCustomEventViewMainBack) { + 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_main_on_exit(void* context) { + // furi_assert(context); + // PacsFuzzerApp* app = context; + UNUSED(context); +} diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c new file mode 100644 index 000000000..7db7d26f3 --- /dev/null +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -0,0 +1,94 @@ +#include "main_menu.h" +#include "../fuzzer_i.h" + +#include +#include + +struct FuzzerViewMain { + View* view; + FuzzerViewMainCallback callback; + void* context; +}; + +typedef struct { + uint8_t proto_index; + uint8_t menu_index; +} FuzzerViewMainModel; + +void fuzzer_view_main_set_callback( + FuzzerViewMain* fuzzer_view_main, + FuzzerViewMainCallback callback, + void* context) { + furi_assert(fuzzer_view_main); + + fuzzer_view_main->callback = callback; + fuzzer_view_main->context = context; +} + +void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) { + UNUSED(canvas); + UNUSED(model); +} + +bool fuzzer_view_main_input(InputEvent* event, void* context) { + furi_assert(context); + FuzzerViewMain* fuzzer_view_main = context; + + if(event->key == InputKeyBack && + (event->type == InputTypeLong || event->type == InputTypeShort)) { + fuzzer_view_main->callback(FuzzerCustomEventViewMainBack, fuzzer_view_main->context); + return true; + } + + return true; +} + +void fuzzer_view_main_enter(void* context) { + furi_assert(context); +} + +void fuzzer_view_main_exit(void* context) { + furi_assert(context); +} + +FuzzerViewMain* fuzzer_view_main_alloc() { + FuzzerViewMain* fuzzer_view_main = malloc(sizeof(FuzzerViewMain)); + + // View allocation and configuration + fuzzer_view_main->view = view_alloc(); + view_allocate_model(fuzzer_view_main->view, ViewModelTypeLocking, sizeof(FuzzerViewMainModel)); + view_set_context(fuzzer_view_main->view, fuzzer_view_main); + view_set_draw_callback(fuzzer_view_main->view, (ViewDrawCallback)fuzzer_view_main_draw); + view_set_input_callback(fuzzer_view_main->view, fuzzer_view_main_input); + view_set_enter_callback(fuzzer_view_main->view, fuzzer_view_main_enter); + view_set_exit_callback(fuzzer_view_main->view, fuzzer_view_main_exit); + + with_view_model( + fuzzer_view_main->view, + FuzzerViewMainModel * model, + { + model->proto_index = 0; + model->menu_index = 0; + }, + true); + return fuzzer_view_main; +} + +void fuzzer_view_main_free(FuzzerViewMain* fuzzer_view_main) { + furi_assert(fuzzer_view_main); + + // with_view_model( + // fuzzer_view_main->view, + // FuzzerViewMainModel * model, + // { + + // }, + // true); + view_free(fuzzer_view_main->view); + free(fuzzer_view_main); +} + +View* fuzzer_view_main_get_view(FuzzerViewMain* fuzzer_view_main) { + furi_assert(fuzzer_view_main); + return fuzzer_view_main->view; +} \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/main_menu.h b/applications/external/pacs_fuzzer/views/main_menu.h new file mode 100644 index 000000000..17631807f --- /dev/null +++ b/applications/external/pacs_fuzzer/views/main_menu.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include "../helpers/fuzzer_custom_event.h" + +typedef enum { + FuzzerViewMainStateIdle, + FuzzerViewMainStateLoading, + FuzzerViewMainStateSending, + FuzzerViewMainStateOFF, +} FuzzerViewMainState; + +typedef struct FuzzerViewMain FuzzerViewMain; + +typedef void (*FuzzerViewMainCallback)(FuzzerCustomEvent event, void* context); + +void fuzzer_view_main_set_callback( + FuzzerViewMain* fuzzer_view_main, + FuzzerViewMainCallback callback, + void* context); + +FuzzerViewMain* fuzzer_view_main_alloc(); + +void fuzzer_view_main_free(FuzzerViewMain* fuzzer_view_main); + +View* fuzzer_view_main_get_view(FuzzerViewMain* fuzzer_view_main); \ No newline at end of file