Преглед изворни кода

Add text input and console focus

0xchocolate пре 3 година
родитељ
комит
105b573f74

+ 2 - 1
applications/wifi_marauder_companion/scenes/wifi_marauder_scene_config.h

@@ -1,2 +1,3 @@
 ADD_SCENE(wifi_marauder, start, Start)
 ADD_SCENE(wifi_marauder, start, Start)
-ADD_SCENE(wifi_marauder, console_output, ConsoleOutput)
+ADD_SCENE(wifi_marauder, console_output, ConsoleOutput)
+ADD_SCENE(wifi_marauder, text_input, TextInput)

+ 7 - 2
applications/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c

@@ -20,7 +20,11 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
 
 
     TextBox* text_box = app->text_box;
     TextBox* text_box = app->text_box;
     text_box_set_font(text_box, TextBoxFontText);
     text_box_set_font(text_box, TextBoxFontText);
-    text_box_set_focus(text_box, TextBoxFocusEnd);
+    if (app->focus_console_start) {
+        text_box_set_focus(text_box, TextBoxFocusStart);
+    } else {
+        text_box_set_focus(text_box, TextBoxFocusEnd);
+    }
     string_reset(app->text_box_store);
     string_reset(app->text_box_store);
 
 
     scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneConsoleOutput, 0);
     scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneConsoleOutput, 0);
@@ -29,9 +33,10 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
     // Register callback to receive data
     // Register callback to receive data
     wifi_marauder_uart_set_handle_rx_data_cb(app->uart, wifi_marauder_console_output_handle_rx_data_cb); // setup callback for rx thread
     wifi_marauder_uart_set_handle_rx_data_cb(app->uart, wifi_marauder_console_output_handle_rx_data_cb); // setup callback for rx thread
 
 
-    // Send command
+    // Send command with newline '\n'
     if (app->selected_tx_string) {
     if (app->selected_tx_string) {
         wifi_marauder_uart_tx((uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
         wifi_marauder_uart_tx((uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
+        wifi_marauder_uart_tx((uint8_t*)("\n"), 1);
     }
     }
 }
 }
 
 

+ 54 - 54
applications/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c

@@ -1,77 +1,74 @@
 #include "../wifi_marauder_app_i.h"
 #include "../wifi_marauder_app_i.h"
 
 
-#define NUM_MENU_ITEMS (26)
-const char* const item_strings[NUM_MENU_ITEMS] = {
-    "attack -t beacon -l\n",
-    "attack -t beacon -r\n",
-    "attack -t beacon -a\n",
-    "attack -t deauth\n",
-    "attack -t probe\n",
-    "attack -t rickroll\n",
-    "channel\n",
-    "channel -s\n",
-    "clearlist -a\n",
-    "clearlist -s\n",
-    "help\n",
-    "list -a\n",
-    "list -s\n",
-    "reboot\n",
-    "scanap\n",
-    "select -a\n",
-    "select -s\n",
-    "sniffbeacon\n",
-    "sniffdeauth\n",
-    "sniffesp\n",
-    "sniffpmkid\n",
-    "sniffpwn\n",
-    "ssid -a -g\n",
-    "ssid -a -n\n",
-    "ssid -r\n",
-    "update -w\n",
+#define NUM_MENU_ITEMS (27)
+
+// For each command, define whether additional arguments are needed
+// (enabling text input to fill them out), and whether the console
+// text box should focus at the start of the output or the end
+#define INPUT_ARGS          (true)
+#define NO_ARGS             (false)
+#define FOCUS_CONSOLE_START (true)
+#define FOCUS_CONSOLE_END   (false)
+struct WifiMarauderItem {
+    const char* item_string;
+    bool needs_keyboard;
+    bool focus_console_start;
 };
 };
 
 
-// TODO: check if all these channels are actually supported
-#define NUM_CHANNELS (14)
-const char* const channel_select_text[NUM_CHANNELS] = {
-    "1", "2", "3", "4", "5", "6", "7",
-    "8", "9", "10", "11", "12", "13", "14",
+const struct WifiMarauderItem items[NUM_MENU_ITEMS] = {
+    { "attack -t beacon -l", NO_ARGS, FOCUS_CONSOLE_END },
+    { "attack -t beacon -r", NO_ARGS, FOCUS_CONSOLE_END },
+    { "attack -t beacon -a", NO_ARGS, FOCUS_CONSOLE_END },
+    { "attack -t deauth", NO_ARGS, FOCUS_CONSOLE_END },
+    { "attack -t probe", NO_ARGS, FOCUS_CONSOLE_END },
+    { "attack -t rickroll", NO_ARGS, FOCUS_CONSOLE_END },
+    { "channel", NO_ARGS, FOCUS_CONSOLE_END },
+    { "channel -s", INPUT_ARGS, FOCUS_CONSOLE_END },
+    { "clearlist -a", NO_ARGS, FOCUS_CONSOLE_END },
+    { "clearlist -s", NO_ARGS, FOCUS_CONSOLE_END },
+    { "help", NO_ARGS, FOCUS_CONSOLE_START },
+    { "list -a", NO_ARGS, FOCUS_CONSOLE_START },
+    { "list -s", NO_ARGS, FOCUS_CONSOLE_START },
+    { "reboot", NO_ARGS, FOCUS_CONSOLE_END },
+    { "scanap", NO_ARGS, FOCUS_CONSOLE_END },
+    { "select -a", INPUT_ARGS, FOCUS_CONSOLE_END },
+    { "select -s", INPUT_ARGS, FOCUS_CONSOLE_END },
+    { "sniffbeacon", NO_ARGS, FOCUS_CONSOLE_END },
+    { "sniffdeauth", NO_ARGS, FOCUS_CONSOLE_END },
+    { "sniffesp", NO_ARGS, FOCUS_CONSOLE_END },
+    { "sniffpmkid", NO_ARGS, FOCUS_CONSOLE_END },
+    { "sniffpmkid -c", INPUT_ARGS, FOCUS_CONSOLE_END },
+    { "sniffpwn", NO_ARGS, FOCUS_CONSOLE_END },
+    { "ssid -a -g", INPUT_ARGS, FOCUS_CONSOLE_END },
+    { "ssid -a -n", INPUT_ARGS, FOCUS_CONSOLE_END },
+    { "ssid -r", INPUT_ARGS, FOCUS_CONSOLE_END },
+    { "update -w", NO_ARGS, FOCUS_CONSOLE_END },
 };
 };
 
 
 static void wifi_marauder_scene_start_var_list_enter_callback(void* context, uint32_t index) {
 static void wifi_marauder_scene_start_var_list_enter_callback(void* context, uint32_t index) {
     furi_assert(context);
     furi_assert(context);
     WifiMarauderApp* app = context;
     WifiMarauderApp* app = context;
-    app->selected_tx_string = item_strings[index];
+    app->selected_tx_string = items[index].item_string;
+    app->is_custom_tx_string = false;
     app->selected_menu_index = index;
     app->selected_menu_index = index;
-    view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartConsole);
-}
-
-static void wifi_marauder_scene_start_var_list_change_callback(VariableItem* item) {
-    WifiMarauderApp* app = variable_item_get_context(item);
-    uint8_t index = variable_item_get_current_value_index(item);
-
-    variable_item_set_current_value_text(item, channel_select_text[index]);
-    app->selected_wifi_channel = index + 1;
+    app->focus_console_start = items[index].focus_console_start;
+    if (items[index].needs_keyboard) {
+        view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartKeyboard);
+    } else {
+        view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartConsole);
+    }
 }
 }
 
 
 void wifi_marauder_scene_start_on_enter(void* context) {
 void wifi_marauder_scene_start_on_enter(void* context) {
     WifiMarauderApp* app = context;
     WifiMarauderApp* app = context;
     VariableItemList* var_item_list = app->var_item_list;
     VariableItemList* var_item_list = app->var_item_list;
 
 
-    VariableItem* item;
     variable_item_list_set_enter_callback(
     variable_item_list_set_enter_callback(
         var_item_list, wifi_marauder_scene_start_var_list_enter_callback, app);
         var_item_list, wifi_marauder_scene_start_var_list_enter_callback, app);
 
 
     // TODO: organize menu
     // TODO: organize menu
     for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
     for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
-        if (0 == strncmp(item_strings[i], "channel -s", strlen("channel -s"))) {
-            item = variable_item_list_add(var_item_list, item_strings[i], NUM_CHANNELS,
-                                          wifi_marauder_scene_start_var_list_change_callback,
-                                          app);
-            variable_item_set_current_value_index(item, 0);
-            variable_item_set_current_value_text(item, channel_select_text[0]);
-        } else {
-            variable_item_list_add(var_item_list, item_strings[i], 0, NULL, NULL);
-        }
+        variable_item_list_add(var_item_list, items[i].item_string, 0, NULL, NULL);
     }
     }
 
 
     variable_item_list_set_selected_item(
     variable_item_list_set_selected_item(
@@ -86,7 +83,10 @@ bool wifi_marauder_scene_start_on_event(void* context, SceneManagerEvent event)
     bool consumed = false;
     bool consumed = false;
 
 
     if(event.type == SceneManagerEventTypeCustom) {
     if(event.type == SceneManagerEventTypeCustom) {
-        if (event.event == WifiMarauderEventStartConsole) {
+        if (event.event == WifiMarauderEventStartKeyboard) {
+            scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneStart, app->selected_menu_index);
+            scene_manager_next_scene(app->scene_manager, WifiMarauderAppViewTextInput);
+        } else if (event.event == WifiMarauderEventStartConsole) {
             scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneStart, app->selected_menu_index);
             scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneStart, app->selected_menu_index);
             scene_manager_next_scene(app->scene_manager, WifiMarauderAppViewConsoleOutput);
             scene_manager_next_scene(app->scene_manager, WifiMarauderAppViewConsoleOutput);
         }
         }

+ 54 - 0
applications/wifi_marauder_companion/scenes/wifi_marauder_scene_text_input.c

@@ -0,0 +1,54 @@
+#include "../wifi_marauder_app_i.h"
+
+
+void wifi_marauder_scene_text_input_callback(void* context) {
+    WifiMarauderApp* app = context;
+
+    view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartConsole);
+}
+
+void wifi_marauder_scene_text_input_on_enter(void* context) {
+    WifiMarauderApp* app = context;
+
+    if (false == app->is_custom_tx_string) {
+        // Fill text input with selected string so that user can add to it
+        size_t length = strlen(app->selected_tx_string);
+        furi_assert(length < WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE);
+        bzero(app->text_input_store, WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE);
+        strncpy(app->text_input_store, app->selected_tx_string, length);
+
+        // Add space - because flipper keyboard currently doesn't have a space
+        app->text_input_store[length] = ' ';
+        app->text_input_store[length+1] = '\0';
+        app->is_custom_tx_string = true;
+    }
+
+    // Setup view
+    TextInput* text_input = app->text_input;
+    text_input_set_header_text(text_input, "Add command arguments");
+    text_input_set_result_callback(text_input, wifi_marauder_scene_text_input_callback, app, app->text_input_store, WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE, false);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewTextInput);
+}
+
+bool wifi_marauder_scene_text_input_on_event(void* context, SceneManagerEvent event) {
+    WifiMarauderApp* app = context;
+    bool consumed = false;
+
+    if (event.type == SceneManagerEventTypeCustom) {
+        if (event.event == WifiMarauderEventStartConsole) {
+            // Point to custom string to send
+            app->selected_tx_string = app->text_input_store;
+            scene_manager_next_scene(app->scene_manager, WifiMarauderAppViewConsoleOutput);
+            consumed = true;
+        }
+    }
+
+    return consumed;
+}
+
+void wifi_marauder_scene_text_input_on_exit(void* context) {
+    WifiMarauderApp* app = context;
+
+    text_input_reset(app->text_input);
+}

+ 0 - 0
applications/wifi_marauder_companion/views/wifi_marauder_console_output.c


+ 5 - 3
applications/wifi_marauder_companion/wifi_marauder_app.c

@@ -24,8 +24,6 @@ static void wifi_marauder_app_tick_event_callback(void* context) {
 WifiMarauderApp* wifi_marauder_app_alloc() {
 WifiMarauderApp* wifi_marauder_app_alloc() {
     WifiMarauderApp* app = malloc(sizeof(WifiMarauderApp));
     WifiMarauderApp* app = malloc(sizeof(WifiMarauderApp));
 
 
-    app->selected_wifi_channel = 1;
-
     app->gui = furi_record_open("gui");
     app->gui = furi_record_open("gui");
 
 
     app->view_dispatcher = view_dispatcher_alloc();
     app->view_dispatcher = view_dispatcher_alloc();
@@ -52,7 +50,9 @@ WifiMarauderApp* wifi_marauder_app_alloc() {
     view_dispatcher_add_view(app->view_dispatcher, WifiMarauderAppViewConsoleOutput, text_box_get_view(app->text_box));
     view_dispatcher_add_view(app->view_dispatcher, WifiMarauderAppViewConsoleOutput, text_box_get_view(app->text_box));
     string_init(app->text_box_store);
     string_init(app->text_box_store);
     string_reserve(app->text_box_store, WIFI_MARAUDER_TEXT_BOX_STORE_SIZE);
     string_reserve(app->text_box_store, WIFI_MARAUDER_TEXT_BOX_STORE_SIZE);
-    // TODO add other views
+
+    app->text_input = text_input_alloc();
+    view_dispatcher_add_view(app->view_dispatcher, WifiMarauderAppViewTextInput, text_input_get_view(app->text_input));
 
 
     scene_manager_next_scene(app->scene_manager, WifiMarauderSceneStart);
     scene_manager_next_scene(app->scene_manager, WifiMarauderSceneStart);
 
 
@@ -65,8 +65,10 @@ void wifi_marauder_app_free(WifiMarauderApp* app) {
     // Views
     // Views
     view_dispatcher_remove_view(app->view_dispatcher, WifiMarauderAppViewVarItemList);
     view_dispatcher_remove_view(app->view_dispatcher, WifiMarauderAppViewVarItemList);
     view_dispatcher_remove_view(app->view_dispatcher, WifiMarauderAppViewConsoleOutput);
     view_dispatcher_remove_view(app->view_dispatcher, WifiMarauderAppViewConsoleOutput);
+    view_dispatcher_remove_view(app->view_dispatcher, WifiMarauderAppViewTextInput);
     text_box_free(app->text_box);
     text_box_free(app->text_box);
     string_clear(app->text_box_store);
     string_clear(app->text_box_store);
+    text_input_free(app->text_input);
 
 
     // View dispatcher
     // View dispatcher
     view_dispatcher_free(app->view_dispatcher);
     view_dispatcher_free(app->view_dispatcher);

+ 7 - 9
applications/wifi_marauder_companion/wifi_marauder_app_i.h

@@ -9,26 +9,30 @@
 #include <gui/view_dispatcher.h>
 #include <gui/view_dispatcher.h>
 #include <gui/scene_manager.h>
 #include <gui/scene_manager.h>
 #include <gui/modules/text_box.h>
 #include <gui/modules/text_box.h>
+#include <gui/modules/text_input.h>
 #include <gui/modules/variable_item_list.h>
 #include <gui/modules/variable_item_list.h>
 
 
 #define WIFI_MARAUDER_TEXT_BOX_STORE_SIZE (4096)
 #define WIFI_MARAUDER_TEXT_BOX_STORE_SIZE (4096)
+#define WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE (512)
 
 
 struct WifiMarauderApp {
 struct WifiMarauderApp {
     Gui* gui;
     Gui* gui;
     ViewDispatcher* view_dispatcher;
     ViewDispatcher* view_dispatcher;
     SceneManager* scene_manager;
     SceneManager* scene_manager;
 
 
+    char text_input_store[WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE + 1];
     string_t text_box_store;
     string_t text_box_store;
     TextBox* text_box;
     TextBox* text_box;
+    TextInput* text_input;
     //Widget* widget;
     //Widget* widget;
 
 
     VariableItemList* var_item_list;
     VariableItemList* var_item_list;
-    //WifiMarauderDetect* detect;
 
 
     WifiMarauderUart* uart;
     WifiMarauderUart* uart;
-    int selected_wifi_channel;
     int selected_menu_index;
     int selected_menu_index;
     const char* selected_tx_string;
     const char* selected_tx_string;
+    bool is_custom_tx_string;
+    bool focus_console_start;
 };
 };
 
 
 // Supported commands:
 // Supported commands:
@@ -55,11 +59,5 @@ struct WifiMarauderApp {
 typedef enum {
 typedef enum {
     WifiMarauderAppViewVarItemList,
     WifiMarauderAppViewVarItemList,
     WifiMarauderAppViewConsoleOutput,
     WifiMarauderAppViewConsoleOutput,
-    WifiMarauderAppViewDetect,
-    WifiMarauderAppViewScan,
-    WifiMarauderAppViewAttack,
-    WifiMarauderAppViewSniff,
-    WifiMarauderAppViewChannel,
-    WifiMarauderAppViewUpdate,
-    WifiMarauderAppViewReboot,
+    WifiMarauderAppViewTextInput,
 } WifiMarauderAppView;
 } WifiMarauderAppView;

+ 1 - 0
applications/wifi_marauder_companion/wifi_marauder_custom_event.h

@@ -3,4 +3,5 @@
 typedef enum {
 typedef enum {
     WifiMarauderEventRefreshConsoleOutput = 0,
     WifiMarauderEventRefreshConsoleOutput = 0,
     WifiMarauderEventStartConsole,
     WifiMarauderEventStartConsole,
+    WifiMarauderEventStartKeyboard,
 } WifiMarauderCustomEvent;
 } WifiMarauderCustomEvent;