blackhat_scene_start.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "../blackhat_app_i.h"
  2. BlackhatItem items[] = {
  3. {"Shell", {""}, 1, NULL, SHELL_CMD, false},
  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, true},
  11. {"Set inet Password", {""}, 1, NULL, SET_INET_PWD_CMD, true},
  12. {"Set AP SSID", {""}, 1, NULL, SET_AP_SSID_CMD, true},
  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, false},
  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, false},
  27. {"Enable SSH", {""}, 1, NULL, START_SSH_CMD, false},
  28. {"Start Evil Twin", {""}, 1, NULL, START_EVIL_TWIN, false},
  29. {"Start Evil Portal", {""}, 1, NULL, START_EVIL_PORT, false},
  30. {"Start RAT Driver", {""}, 1, NULL, START_RAT, false},
  31. {"Get Params", {""}, 1, NULL, GET_CMD, false},
  32. {"Help", {""}, 1, NULL, HELP_CMD, false},
  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->text_input_req = item->text_input_req;
  46. app->selected_menu_index = index;
  47. app->selected_option_item_text = item->selected_option;
  48. view_dispatcher_send_custom_event(
  49. app->view_dispatcher, BlackhatEventStartConsole
  50. );
  51. }
  52. static void blackhat_scene_start_var_list_change_callback(VariableItem* item)
  53. {
  54. furi_assert(item);
  55. BlackhatApp* app = variable_item_get_context(item);
  56. furi_assert(app);
  57. const BlackhatItem* menu_item = &items[app->selected_menu_index];
  58. uint8_t item_index = variable_item_get_current_value_index(item);
  59. furi_assert(item_index < menu_item->num_options_menu);
  60. variable_item_set_current_value_text(
  61. item, menu_item->options_menu[item_index]
  62. );
  63. items[app->selected_menu_index].selected_option =
  64. menu_item->options_menu[item_index];
  65. app->selected_option_index[app->selected_menu_index] = item_index;
  66. }
  67. void blackhat_scene_start_on_enter(void* context)
  68. {
  69. BlackhatApp* app = context;
  70. VariableItemList* var_item_list = app->var_item_list;
  71. variable_item_list_set_enter_callback(
  72. var_item_list, blackhat_scene_start_var_list_enter_callback, app
  73. );
  74. VariableItem* item;
  75. for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
  76. item = variable_item_list_add(
  77. var_item_list,
  78. items[i].item_string,
  79. items[i].num_options_menu,
  80. blackhat_scene_start_var_list_change_callback,
  81. app
  82. );
  83. items[i].selected_option = items[i].options_menu[0];
  84. variable_item_set_current_value_index(
  85. item, app->selected_option_index[i]
  86. );
  87. variable_item_set_current_value_text(
  88. item, items[i].options_menu[app->selected_option_index[i]]
  89. );
  90. }
  91. variable_item_list_set_selected_item(
  92. var_item_list,
  93. scene_manager_get_scene_state(app->scene_manager, BlackhatSceneStart)
  94. );
  95. view_dispatcher_switch_to_view(
  96. app->view_dispatcher, BlackhatAppViewVarItemList
  97. );
  98. }
  99. bool blackhat_scene_start_on_event(void* context, SceneManagerEvent event)
  100. {
  101. UNUSED(context);
  102. BlackhatApp* app = context;
  103. bool consumed = false;
  104. if (event.type == SceneManagerEventTypeCustom) {
  105. if (event.event == BlackhatEventStartPortal) {
  106. scene_manager_set_scene_state(
  107. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  108. );
  109. scene_manager_next_scene(
  110. app->scene_manager, BlackhatAppViewStartPortal
  111. );
  112. } else if (event.event == BlackhatEventStartKeyboard) {
  113. scene_manager_set_scene_state(
  114. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  115. );
  116. } else if (event.event == BlackhatEventStartConsole) {
  117. scene_manager_set_scene_state(
  118. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  119. );
  120. scene_manager_next_scene(
  121. app->scene_manager, BlackhatAppViewConsoleOutput
  122. );
  123. }
  124. consumed = true;
  125. } else if (event.type == SceneManagerEventTypeTick) {
  126. app->selected_menu_index =
  127. variable_item_list_get_selected_item_index(app->var_item_list);
  128. consumed = true;
  129. }
  130. return consumed;
  131. }
  132. void blackhat_scene_start_on_exit(void* context)
  133. {
  134. BlackhatApp* app = context;
  135. variable_item_list_reset(app->var_item_list);
  136. }