[FL-2051] BadUSB: new GUI (#844)
* [FL-2051] BadUsb: new GUI * add missing assets * skip empty lines and leading spaces * SubGhz: add alignment check to keystore mess with iv routine Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
30
applications/bad_usb/scenes/bad_usb_scene.c
Normal file
30
applications/bad_usb/scenes/bad_usb_scene.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "bad_usb_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const bad_usb_scene_on_enter_handlers[])(void*) = {
|
||||
#include "bad_usb_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 bad_usb_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "bad_usb_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 bad_usb_scene_on_exit_handlers[])(void* context) = {
|
||||
#include "bad_usb_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers bad_usb_scene_handlers = {
|
||||
.on_enter_handlers = bad_usb_scene_on_enter_handlers,
|
||||
.on_event_handlers = bad_usb_scene_on_event_handlers,
|
||||
.on_exit_handlers = bad_usb_scene_on_exit_handlers,
|
||||
.scene_num = BadUsbSceneNum,
|
||||
};
|
29
applications/bad_usb/scenes/bad_usb_scene.h
Normal file
29
applications/bad_usb/scenes/bad_usb_scene.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) BadUsbScene##id,
|
||||
typedef enum {
|
||||
#include "bad_usb_scene_config.h"
|
||||
BadUsbSceneNum,
|
||||
} BadUsbScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers bad_usb_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "bad_usb_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 "bad_usb_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 "bad_usb_scene_config.h"
|
||||
#undef ADD_SCENE
|
2
applications/bad_usb/scenes/bad_usb_scene_config.h
Normal file
2
applications/bad_usb/scenes/bad_usb_scene_config.h
Normal file
@@ -0,0 +1,2 @@
|
||||
ADD_SCENE(bad_usb, file_select, FileSelect)
|
||||
ADD_SCENE(bad_usb, work, Work)
|
36
applications/bad_usb/scenes/bad_usb_scene_file_select.c
Normal file
36
applications/bad_usb/scenes/bad_usb_scene_file_select.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "../bad_usb_app_i.h"
|
||||
#include "furi-hal-power.h"
|
||||
|
||||
static bool bad_usb_file_select(BadUsbApp* bad_usb) {
|
||||
furi_assert(bad_usb);
|
||||
|
||||
// Input events and views are managed by file_select
|
||||
bool res = dialog_file_select_show(
|
||||
bad_usb->dialogs,
|
||||
BAD_USB_APP_PATH_FOLDER,
|
||||
BAD_USB_APP_EXTENSION,
|
||||
bad_usb->file_name,
|
||||
sizeof(bad_usb->file_name),
|
||||
NULL);
|
||||
return res;
|
||||
}
|
||||
|
||||
void bad_usb_scene_file_select_on_enter(void* context) {
|
||||
BadUsbApp* bad_usb = context;
|
||||
|
||||
if(bad_usb_file_select(bad_usb)) {
|
||||
scene_manager_next_scene(bad_usb->scene_manager, BadUsbAppViewWork);
|
||||
} else {
|
||||
//scene_manager_previous_scene(bad_usb->scene_manager);
|
||||
view_dispatcher_stop(bad_usb->view_dispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
bool bad_usb_scene_file_select_on_event(void* context, SceneManagerEvent event) {
|
||||
// BadUsbApp* bad_usb = context;
|
||||
return false;
|
||||
}
|
||||
|
||||
void bad_usb_scene_file_select_on_exit(void* context) {
|
||||
// BadUsbApp* bad_usb = context;
|
||||
}
|
47
applications/bad_usb/scenes/bad_usb_scene_work.c
Normal file
47
applications/bad_usb/scenes/bad_usb_scene_work.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "../bad_usb_script.h"
|
||||
#include "../bad_usb_app_i.h"
|
||||
#include "../views/bad_usb_view.h"
|
||||
#include "furi-hal.h"
|
||||
|
||||
void bad_usb_scene_work_ok_callback(InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
BadUsbApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, type);
|
||||
}
|
||||
|
||||
bool bad_usb_scene_work_on_event(void* context, SceneManagerEvent event) {
|
||||
BadUsbApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
bad_usb_script_toggle(app->bad_usb_script);
|
||||
consumed = true;
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void bad_usb_scene_work_on_enter(void* context) {
|
||||
BadUsbApp* app = context;
|
||||
|
||||
string_t file_name;
|
||||
string_init(file_name);
|
||||
|
||||
bad_usb_set_file_name(app->bad_usb_view, app->file_name);
|
||||
string_printf(
|
||||
file_name, "%s/%s%s", BAD_USB_APP_PATH_FOLDER, app->file_name, BAD_USB_APP_EXTENSION);
|
||||
app->bad_usb_script = bad_usb_script_open(file_name);
|
||||
|
||||
string_clear(file_name);
|
||||
|
||||
bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
|
||||
|
||||
bad_usb_set_ok_callback(app->bad_usb_view, bad_usb_scene_work_ok_callback, app);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewWork);
|
||||
}
|
||||
|
||||
void bad_usb_scene_work_on_exit(void* context) {
|
||||
BadUsbApp* app = context;
|
||||
bad_usb_script_close(app->bad_usb_script);
|
||||
}
|
Reference in New Issue
Block a user