blackhat_scene_start.c 4.9 KB

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