blackhat_scene_start.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. {"Start Kismet",
  27. {"wlan0", "wlan1", "wlan2"},
  28. 3,
  29. NULL,
  30. START_KISMET_CMD,
  31. FOCUS_CONSOLE_END},
  32. {"Get IP", {""}, 1, NULL, GET_IP_CMD, false},
  33. {"Enable SSH", {""}, 1, NULL, START_SSH_CMD, false},
  34. {"Start Evil Twin", {""}, 1, NULL, ST_EVIL_TWIN_CMD, false},
  35. {"Start Evil Portal", {""}, 1, NULL, ST_EVIL_PORT_CMD, false},
  36. {"Start RAT Driver", {""}, 1, NULL, ST_RAT_CMD, false},
  37. {"Get Params", {""}, 1, NULL, GET_CMD, false},
  38. {"Reboot", {""}, 1, NULL, REBOOT_CMD, false},
  39. {"Help", {""}, 1, NULL, HELP_CMD, false},
  40. };
  41. static void blackhat_scene_start_var_list_enter_callback(
  42. void* context, uint32_t index
  43. )
  44. {
  45. furi_assert(context);
  46. BlackhatApp* app = context;
  47. furi_assert(index < NUM_MENU_ITEMS);
  48. const BlackhatItem* item = &items[index];
  49. const int selected_option_index = app->selected_option_index[index];
  50. furi_assert(selected_option_index < item->num_options_menu);
  51. app->selected_tx_string = item->actual_command;
  52. app->text_input_req = item->text_input_req;
  53. app->selected_menu_index = index;
  54. app->selected_option_item_text = item->selected_option;
  55. view_dispatcher_send_custom_event(
  56. app->view_dispatcher, BlackhatEventStartConsole
  57. );
  58. }
  59. static void blackhat_scene_start_var_list_change_callback(VariableItem* item)
  60. {
  61. furi_assert(item);
  62. BlackhatApp* app = variable_item_get_context(item);
  63. furi_assert(app);
  64. const BlackhatItem* menu_item = &items[app->selected_menu_index];
  65. uint8_t item_index = variable_item_get_current_value_index(item);
  66. furi_assert(item_index < menu_item->num_options_menu);
  67. variable_item_set_current_value_text(
  68. item, menu_item->options_menu[item_index]
  69. );
  70. items[app->selected_menu_index].selected_option =
  71. menu_item->options_menu[item_index];
  72. app->selected_option_index[app->selected_menu_index] = item_index;
  73. }
  74. void blackhat_scene_start_on_enter(void* context)
  75. {
  76. BlackhatApp* app = context;
  77. VariableItemList* var_item_list = app->var_item_list;
  78. variable_item_list_set_enter_callback(
  79. var_item_list, blackhat_scene_start_var_list_enter_callback, app
  80. );
  81. VariableItem* item;
  82. for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
  83. item = variable_item_list_add(
  84. var_item_list,
  85. items[i].item_string,
  86. items[i].num_options_menu,
  87. blackhat_scene_start_var_list_change_callback,
  88. app
  89. );
  90. items[i].selected_option = items[i].options_menu[0];
  91. variable_item_set_current_value_index(
  92. item, app->selected_option_index[i]
  93. );
  94. variable_item_set_current_value_text(
  95. item, items[i].options_menu[app->selected_option_index[i]]
  96. );
  97. }
  98. variable_item_list_set_selected_item(
  99. var_item_list,
  100. scene_manager_get_scene_state(app->scene_manager, BlackhatSceneStart)
  101. );
  102. view_dispatcher_switch_to_view(
  103. app->view_dispatcher, BlackhatAppViewVarItemList
  104. );
  105. }
  106. bool blackhat_scene_start_on_event(void* context, SceneManagerEvent event)
  107. {
  108. UNUSED(context);
  109. BlackhatApp* app = context;
  110. bool consumed = false;
  111. if (event.type == SceneManagerEventTypeCustom) {
  112. if (event.event == BlackhatEventStartPortal) {
  113. scene_manager_set_scene_state(
  114. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  115. );
  116. scene_manager_next_scene(
  117. app->scene_manager, BlackhatAppViewStartPortal
  118. );
  119. } else if (event.event == BlackhatEventStartKeyboard) {
  120. scene_manager_set_scene_state(
  121. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  122. );
  123. } else if (event.event == BlackhatEventStartConsole) {
  124. scene_manager_set_scene_state(
  125. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  126. );
  127. scene_manager_next_scene(
  128. app->scene_manager, BlackhatAppViewConsoleOutput
  129. );
  130. }
  131. consumed = true;
  132. } else if (event.type == SceneManagerEventTypeTick) {
  133. app->selected_menu_index =
  134. variable_item_list_get_selected_item_index(app->var_item_list);
  135. consumed = true;
  136. }
  137. return consumed;
  138. }
  139. void blackhat_scene_start_on_exit(void* context)
  140. {
  141. BlackhatApp* app = context;
  142. variable_item_list_reset(app->var_item_list);
  143. }