wifi_deauther_scene_start.c 6.3 KB

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