blackhat_scene_start.c 5.0 KB

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