Fuzzers App: gui start

This commit is contained in:
gid9798 2023-06-02 16:42:58 +03:00
parent 4c134d8fdc
commit ab86f58643
12 changed files with 355 additions and 0 deletions

View File

@ -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",
)

View File

@ -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;
}

View File

@ -0,0 +1,21 @@
#pragma once
#include <stdint.h>
#include <gui/gui.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include "scenes/fuzzer_scene.h"
#include "views/main_menu.h"
#include "helpers/fuzzer_types.h"
#include <flipper_format/flipper_format_i.h>
typedef struct {
Gui* gui;
ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;
FuzzerViewMain* main_view;
} PacsFuzzerApp;

View File

@ -0,0 +1,8 @@
#pragma once
typedef enum {
// FuzzerCustomEvent
FuzzerCustomEventViewMainOk = 100,
FuzzerCustomEventViewMainBack,
} FuzzerCustomEvent;

View File

@ -0,0 +1,8 @@
#pragma once
#include <furi.h>
#include <furi_hal.h>
typedef enum {
FuzzerViewIDMain,
} FuzzerViewID;

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -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,
};

View File

@ -0,0 +1,29 @@
#pragma once
#include <gui/scene_manager.h>
// 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

View File

@ -0,0 +1 @@
ADD_SCENE(fuzzer, main, Main)

View File

@ -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);
}

View File

@ -0,0 +1,94 @@
#include "main_menu.h"
#include "../fuzzer_i.h"
#include <input/input.h>
#include <gui/elements.h>
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;
}

View File

@ -0,0 +1,26 @@
#pragma once
#include <gui/view.h>
#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);