blackhat_scene_start.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "../blackhat_app_i.h"
  2. BlackhatItem items[] = {
  3. {"Shell", {""}, 1, NULL, SHELL_CMD, FOCUS_CONSOLE_END},
  4. {"Connect WiFi",
  5. {"wlan0", "wlan1", "wlan2"},
  6. 3,
  7. NULL,
  8. WIFI_CON_CMD,
  9. FOCUS_CONSOLE_END},
  10. {"Set inet SSID", {""}, 1, NULL, SET_INET_SSID_CMD, FOCUS_CONSOLE_END},
  11. {"Set inet Password", {""}, 1, NULL, SET_INET_PWD_CMD, FOCUS_CONSOLE_END},
  12. {"Set AP SSID", {""}, 1, NULL, SET_AP_SSID_CMD, FOCUS_CONSOLE_END},
  13. {"List Networks",
  14. {"wlan0", "wlan1", "wlan2"},
  15. 3,
  16. NULL,
  17. LIST_AP_CMD,
  18. FOCUS_CONSOLE_END},
  19. {"Wifi Device Info", {""}, 1, NULL, DEV_CMD, FOCUS_CONSOLE_END},
  20. {"Enable AP",
  21. {"wlan0", "wlan1", "wlan2"},
  22. 3,
  23. NULL,
  24. START_AP_CMD,
  25. FOCUS_CONSOLE_END},
  26. {"Get IP", {""}, 1, NULL, START_AP_CMD, FOCUS_CONSOLE_END},
  27. {"Enable SSH", {""}, 1, NULL, START_SSH_CMD, FOCUS_CONSOLE_END},
  28. {"Start Evil Twin", {""}, 1, NULL, START_EVIL_TWIN, FOCUS_CONSOLE_END},
  29. {"Start Evil Portal", {""}, 1, NULL, START_EVIL_PORT, FOCUS_CONSOLE_END},
  30. {"Start RAT Driver", {""}, 1, NULL, START_RAT, FOCUS_CONSOLE_END},
  31. {"Get Params", {""}, 1, NULL, GET_CMD, FOCUS_CONSOLE_START},
  32. {"Help", {""}, 1, NULL, HELP_CMD, FOCUS_CONSOLE_START},
  33. };
  34. static void blackhat_scene_start_var_list_enter_callback(
  35. void* context, uint32_t index
  36. )
  37. {
  38. furi_assert(context);
  39. BlackhatApp* app = context;
  40. furi_assert(index < NUM_MENU_ITEMS);
  41. const BlackhatItem* item = &items[index];
  42. const int selected_option_index = app->selected_option_index[index];
  43. furi_assert(selected_option_index < item->num_options_menu);
  44. app->selected_tx_string = item->actual_command;
  45. app->selected_menu_index = index;
  46. app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE)
  47. ? (selected_option_index == 0)
  48. : item->focus_console;
  49. app->selected_option_item_text = item->selected_option;
  50. view_dispatcher_send_custom_event(
  51. app->view_dispatcher, BlackhatEventStartConsole
  52. );
  53. }
  54. static void blackhat_scene_start_var_list_change_callback(VariableItem* item)
  55. {
  56. furi_assert(item);
  57. BlackhatApp* app = variable_item_get_context(item);
  58. furi_assert(app);
  59. const BlackhatItem* menu_item = &items[app->selected_menu_index];
  60. uint8_t item_index = variable_item_get_current_value_index(item);
  61. furi_assert(item_index < menu_item->num_options_menu);
  62. variable_item_set_current_value_text(
  63. item, menu_item->options_menu[item_index]
  64. );
  65. items[app->selected_menu_index].selected_option =
  66. menu_item->options_menu[item_index];
  67. app->selected_option_index[app->selected_menu_index] = item_index;
  68. }
  69. void blackhat_scene_start_on_enter(void* context)
  70. {
  71. BlackhatApp* app = context;
  72. VariableItemList* var_item_list = app->var_item_list;
  73. variable_item_list_set_enter_callback(
  74. var_item_list, blackhat_scene_start_var_list_enter_callback, app
  75. );
  76. VariableItem* item;
  77. for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
  78. item = variable_item_list_add(
  79. var_item_list,
  80. items[i].item_string,
  81. items[i].num_options_menu,
  82. blackhat_scene_start_var_list_change_callback,
  83. app
  84. );
  85. items[i].selected_option = items[i].options_menu[0];
  86. variable_item_set_current_value_index(
  87. item, app->selected_option_index[i]
  88. );
  89. variable_item_set_current_value_text(
  90. item, items[i].options_menu[app->selected_option_index[i]]
  91. );
  92. }
  93. variable_item_list_set_selected_item(
  94. var_item_list,
  95. scene_manager_get_scene_state(app->scene_manager, BlackhatSceneStart)
  96. );
  97. view_dispatcher_switch_to_view(
  98. app->view_dispatcher, BlackhatAppViewVarItemList
  99. );
  100. }
  101. bool blackhat_scene_start_on_event(void* context, SceneManagerEvent event)
  102. {
  103. UNUSED(context);
  104. BlackhatApp* app = context;
  105. bool consumed = false;
  106. if (event.type == SceneManagerEventTypeCustom) {
  107. if (event.event == BlackhatEventStartPortal) {
  108. scene_manager_set_scene_state(
  109. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  110. );
  111. scene_manager_next_scene(
  112. app->scene_manager, BlackhatAppViewStartPortal
  113. );
  114. } else if (event.event == BlackhatEventStartKeyboard) {
  115. scene_manager_set_scene_state(
  116. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  117. );
  118. } else if (event.event == BlackhatEventStartConsole) {
  119. scene_manager_set_scene_state(
  120. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  121. );
  122. scene_manager_next_scene(
  123. app->scene_manager, BlackhatAppViewConsoleOutput
  124. );
  125. }
  126. consumed = true;
  127. } else if (event.type == SceneManagerEventTypeTick) {
  128. app->selected_menu_index =
  129. variable_item_list_get_selected_item_index(app->var_item_list);
  130. consumed = true;
  131. }
  132. return consumed;
  133. }
  134. void blackhat_scene_start_on_exit(void* context)
  135. {
  136. BlackhatApp* app = context;
  137. variable_item_list_reset(app->var_item_list);
  138. }