blackhat_scene_start.c 5.1 KB

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