wifi_deauther_scene_start.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include "../wifi_deauther_app_i.h"
  2. // For each command, define whether additional arguments are needed
  3. // (enabling text input to fill them out), and whether the console
  4. // text box should focus at the start of the output or the end
  5. typedef enum {
  6. NO_ARGS = 0,
  7. INPUT_ARGS,
  8. TOGGLE_ARGS
  9. } InputArgs;
  10. typedef enum {
  11. FOCUS_CONSOLE_END = 0,
  12. FOCUS_CONSOLE_START,
  13. FOCUS_CONSOLE_TOGGLE
  14. } FocusConsole;
  15. #define SHOW_STOPSCAN_TIP (true)
  16. #define NO_TIP (false)
  17. #define MAX_OPTIONS (6)
  18. typedef struct {
  19. const char* item_string;
  20. const char* options_menu[MAX_OPTIONS];
  21. int num_options_menu;
  22. const char* actual_commands[MAX_OPTIONS];
  23. InputArgs needs_keyboard;
  24. FocusConsole focus_console;
  25. bool show_stopscan_tip;
  26. } WifideautherItem;
  27. // NUM_MENU_ITEMS defined in wifi_deauther_app_i.h - if you add an entry here, increment it!
  28. const WifideautherItem MenuItems[NUM_MENU_ITEMS] = {
  29. {"View Log from", {"start", "end"}, 2, {}, NO_ARGS, FOCUS_CONSOLE_TOGGLE, NO_TIP},
  30. {"Help", {""}, 1, {"help"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP},
  31. {"Stop", {""}, 1, {"stop all"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP},
  32. {"Scan",
  33. {"All", "SSIDs", "Stations"},
  34. 3,
  35. {"scan", "scan aps", "scan stations"},
  36. NO_ARGS,
  37. FOCUS_CONSOLE_END,
  38. NO_TIP},
  39. {"Select",
  40. {"All", "SSIDs", "Stations"},
  41. 3,
  42. {"select all", "select aps", "select stations"},
  43. INPUT_ARGS,
  44. FOCUS_CONSOLE_END,
  45. NO_TIP},
  46. {"Deselect",
  47. {"All", "SSIDs", "Stations"},
  48. 3,
  49. {"deselect all", "deselect aps", "deselect stations"},
  50. INPUT_ARGS,
  51. FOCUS_CONSOLE_END,
  52. NO_TIP},
  53. {"Show",
  54. {"SSIDs", "Stations", "All", "Selected"},
  55. 4,
  56. {"show ap", "show station", "show all", "show selected"},
  57. NO_ARGS,
  58. FOCUS_CONSOLE_END,
  59. NO_TIP},
  60. {"Attack",
  61. {"deauth", "deauthall", "beacon", "probe"},
  62. 4,
  63. {"attack deauth", "attack deauthall", "attack beacon", "attack probe"},
  64. NO_ARGS,
  65. FOCUS_CONSOLE_END,
  66. SHOW_STOPSCAN_TIP},
  67. {"Settings",
  68. {"Get", "Remove AP", "Set SSID", "Set Pass", "Save"},
  69. 5,
  70. {"get settings",
  71. "set webinterface false",
  72. "set ssid: pwned",
  73. "set password: deauther",
  74. "save settings"},
  75. INPUT_ARGS,
  76. FOCUS_CONSOLE_END,
  77. NO_TIP},
  78. {"Sysinfo", {""}, 1, {"sysinfo"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP},
  79. {"Reboot", {""}, 1, {"reboot"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP},
  80. };
  81. static void wifi_deauther_scene_start_var_list_enter_callback(void* context, uint32_t index) {
  82. furi_assert(context);
  83. WifideautherApp* app = context;
  84. if(app->selected_option_index[index] < MenuItems[index].num_options_menu) {
  85. app->selected_tx_string =
  86. MenuItems[index].actual_commands[app->selected_option_index[index]];
  87. }
  88. app->is_command = (1 <= index);
  89. app->is_custom_tx_string = false;
  90. app->selected_menu_index = index;
  91. app->focus_console_start = (MenuItems[index].focus_console == FOCUS_CONSOLE_TOGGLE) ?
  92. (app->selected_option_index[index] == 0) :
  93. MenuItems[index].focus_console;
  94. app->show_stopscan_tip = MenuItems[index].show_stopscan_tip;
  95. bool needs_keyboard = (MenuItems[index].needs_keyboard == TOGGLE_ARGS) ?
  96. (app->selected_option_index[index] != 0) :
  97. MenuItems[index].needs_keyboard;
  98. if(needs_keyboard) {
  99. view_dispatcher_send_custom_event(app->view_dispatcher, WifideautherEventStartKeyboard);
  100. } else {
  101. view_dispatcher_send_custom_event(app->view_dispatcher, WifideautherEventStartConsole);
  102. }
  103. }
  104. static void wifi_deauther_scene_start_var_list_change_callback(VariableItem* item) {
  105. furi_assert(item);
  106. WifideautherApp* app = variable_item_get_context(item);
  107. furi_assert(app);
  108. const WifideautherItem* menu_item = &MenuItems[app->selected_menu_index];
  109. uint8_t item_index = variable_item_get_current_value_index(item);
  110. furi_assert(item_index < menu_item->num_options_menu);
  111. variable_item_set_current_value_text(item, menu_item->options_menu[item_index]);
  112. app->selected_option_index[app->selected_menu_index] = item_index;
  113. }
  114. void wifi_deauther_scene_start_on_enter(void* context) {
  115. WifideautherApp* app = context;
  116. VariableItemList* var_item_list = app->var_item_list;
  117. variable_item_list_set_enter_callback(
  118. var_item_list, wifi_deauther_scene_start_var_list_enter_callback, app);
  119. VariableItem* item;
  120. for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
  121. item = variable_item_list_add(
  122. var_item_list,
  123. MenuItems[i].item_string,
  124. MenuItems[i].num_options_menu,
  125. wifi_deauther_scene_start_var_list_change_callback,
  126. app);
  127. if(MenuItems[i].num_options_menu) {
  128. variable_item_set_current_value_index(item, app->selected_option_index[i]);
  129. variable_item_set_current_value_text(
  130. item, MenuItems[i].options_menu[app->selected_option_index[i]]);
  131. }
  132. }
  133. variable_item_list_set_selected_item(
  134. var_item_list, scene_manager_get_scene_state(app->scene_manager, WifideautherSceneStart));
  135. view_dispatcher_switch_to_view(app->view_dispatcher, WifideautherAppViewVarItemList);
  136. }
  137. bool wifi_deauther_scene_start_on_event(void* context, SceneManagerEvent event) {
  138. UNUSED(context);
  139. WifideautherApp* app = context;
  140. bool consumed = false;
  141. if(event.type == SceneManagerEventTypeCustom) {
  142. if(event.event == WifideautherEventStartKeyboard) {
  143. scene_manager_set_scene_state(
  144. app->scene_manager, WifideautherSceneStart, app->selected_menu_index);
  145. scene_manager_next_scene(app->scene_manager, WifideautherAppViewTextInput);
  146. } else if(event.event == WifideautherEventStartConsole) {
  147. scene_manager_set_scene_state(
  148. app->scene_manager, WifideautherSceneStart, app->selected_menu_index);
  149. scene_manager_next_scene(app->scene_manager, WifideautherAppViewConsoleOutput);
  150. }
  151. consumed = true;
  152. } else if(event.type == SceneManagerEventTypeTick) {
  153. app->selected_menu_index = variable_item_list_get_selected_item_index(app->var_item_list);
  154. consumed = true;
  155. }
  156. return consumed;
  157. }
  158. void wifi_deauther_scene_start_on_exit(void* context) {
  159. WifideautherApp* app = context;
  160. variable_item_list_reset(app->var_item_list);
  161. }