wifi_marauder_scene_text_input.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include "../wifi_marauder_app_i.h"
  2. void wifi_marauder_scene_text_input_callback(void* context) {
  3. WifiMarauderApp* app = context;
  4. switch(app->special_case_input_step) {
  5. case 0: // most commands
  6. view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartConsole);
  7. break;
  8. case 1: // special case for deauth: save source MAC
  9. view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventSaveSourceMac);
  10. break;
  11. case 2: // special case for deauth: save destination MAC
  12. view_dispatcher_send_custom_event(
  13. app->view_dispatcher, WifiMarauderEventSaveDestinationMac);
  14. break;
  15. default:
  16. break;
  17. }
  18. }
  19. void wifi_marauder_scene_text_input_on_enter(void* context) {
  20. WifiMarauderApp* app = context;
  21. if(0 ==
  22. strncmp("attack -t deauth -s", app->selected_tx_string, strlen("attack -t deauth -s"))) {
  23. // Special case for manual deauth input
  24. app->special_case_input_step = 1;
  25. bzero(app->text_input_store, WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE);
  26. } else if(false == app->is_custom_tx_string) {
  27. // Most commands
  28. app->special_case_input_step = 0;
  29. // Fill text input with selected string so that user can add to it
  30. size_t length = strlen(app->selected_tx_string);
  31. furi_assert(length < WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE);
  32. bzero(app->text_input_store, WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE);
  33. strncpy(app->text_input_store, app->selected_tx_string, length);
  34. // Add space - because flipper keyboard currently doesn't have a space
  35. app->text_input_store[length] = ' ';
  36. app->text_input_store[length + 1] = '\0';
  37. app->is_custom_tx_string = true;
  38. }
  39. // Setup view
  40. WIFI_TextInput* text_input = app->text_input;
  41. // Add help message to header
  42. if(app->flash_mode) {
  43. wifi_text_input_set_header_text(text_input, "Enter destination address");
  44. } else if(app->special_case_input_step == 1) {
  45. wifi_text_input_set_header_text(text_input, "Enter source MAC");
  46. } else if(0 == strncmp("ssid -a -g", app->selected_tx_string, strlen("ssid -a -g"))) {
  47. wifi_text_input_set_header_text(text_input, "Enter # SSIDs to generate");
  48. } else if(0 == strncmp("ssid -a -n", app->selected_tx_string, strlen("ssid -a -n"))) {
  49. wifi_text_input_set_header_text(text_input, "Enter SSID name to add");
  50. } else if(0 == strncmp("ssid -r", app->selected_tx_string, strlen("ssid -r"))) {
  51. wifi_text_input_set_header_text(text_input, "Remove target from SSID list");
  52. } else if(0 == strncmp("select -a", app->selected_tx_string, strlen("select -a"))) {
  53. wifi_text_input_set_header_text(text_input, "Add target from AP list");
  54. } else if(0 == strncmp("select -s", app->selected_tx_string, strlen("select -s"))) {
  55. wifi_text_input_set_header_text(text_input, "Add target from SSID list");
  56. } else {
  57. wifi_text_input_set_header_text(text_input, "Add command arguments");
  58. }
  59. wifi_text_input_set_result_callback(
  60. text_input,
  61. wifi_marauder_scene_text_input_callback,
  62. app,
  63. app->text_input_store,
  64. WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE,
  65. false);
  66. view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewTextInput);
  67. }
  68. bool wifi_marauder_scene_text_input_on_event(void* context, SceneManagerEvent event) {
  69. WifiMarauderApp* app = context;
  70. bool consumed = false;
  71. if(event.type == SceneManagerEventTypeCustom) {
  72. if(event.event == WifiMarauderEventStartConsole) {
  73. // Point to custom string to send
  74. app->selected_tx_string = app->text_input_store;
  75. scene_manager_next_scene(app->scene_manager, WifiMarauderSceneConsoleOutput);
  76. consumed = true;
  77. } else if(event.event == WifiMarauderEventSaveSourceMac) {
  78. if(12 != strlen(app->text_input_store)) {
  79. wifi_text_input_set_header_text(app->text_input, "MAC must be 12 hex chars!");
  80. } else {
  81. snprintf(
  82. app->special_case_input_src_addr,
  83. sizeof(app->special_case_input_src_addr),
  84. "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
  85. app->text_input_store[0],
  86. app->text_input_store[1],
  87. app->text_input_store[2],
  88. app->text_input_store[3],
  89. app->text_input_store[4],
  90. app->text_input_store[5],
  91. app->text_input_store[6],
  92. app->text_input_store[7],
  93. app->text_input_store[8],
  94. app->text_input_store[9],
  95. app->text_input_store[10],
  96. app->text_input_store[11]);
  97. // Advance scene to input destination MAC, clear text input
  98. app->special_case_input_step = 2;
  99. bzero(app->text_input_store, WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE);
  100. wifi_text_input_set_header_text(app->text_input, "Enter destination MAC");
  101. }
  102. consumed = true;
  103. } else if(event.event == WifiMarauderEventSaveDestinationMac) {
  104. if(12 != strlen(app->text_input_store)) {
  105. wifi_text_input_set_header_text(app->text_input, "MAC must be 12 hex chars!");
  106. } else {
  107. snprintf(
  108. app->special_case_input_dst_addr,
  109. sizeof(app->special_case_input_dst_addr),
  110. "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
  111. app->text_input_store[0],
  112. app->text_input_store[1],
  113. app->text_input_store[2],
  114. app->text_input_store[3],
  115. app->text_input_store[4],
  116. app->text_input_store[5],
  117. app->text_input_store[6],
  118. app->text_input_store[7],
  119. app->text_input_store[8],
  120. app->text_input_store[9],
  121. app->text_input_store[10],
  122. app->text_input_store[11]);
  123. // Construct command with source and destination MACs
  124. snprintf(
  125. app->text_input_store,
  126. WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE,
  127. "attack -t deauth -s %18s -d %18s",
  128. app->special_case_input_src_addr,
  129. app->special_case_input_dst_addr);
  130. app->selected_tx_string = app->text_input_store;
  131. scene_manager_next_scene(app->scene_manager, WifiMarauderSceneConsoleOutput);
  132. }
  133. consumed = true;
  134. }
  135. }
  136. return consumed;
  137. }
  138. void wifi_marauder_scene_text_input_on_exit(void* context) {
  139. WifiMarauderApp* app = context;
  140. wifi_text_input_reset(app->text_input);
  141. }