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 000000000..8097f4775 Binary files /dev/null and b/applications/external/pacs_fuzzer/rfid_10px.png differ 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