wifi_marauder_scene_text_input.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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->special_case_input_step == 1) {
  43. wifi_text_input_set_header_text(text_input, "Enter source MAC");
  44. } else if(0 == strncmp("ssid -a -g", app->selected_tx_string, strlen("ssid -a -g"))) {
  45. wifi_text_input_set_header_text(text_input, "Enter # SSIDs to generate");
  46. } else if(0 == strncmp("ssid -a -n", app->selected_tx_string, strlen("ssid -a -n"))) {
  47. wifi_text_input_set_header_text(text_input, "Enter SSID name to add");
  48. } else if(0 == strncmp("ssid -r", app->selected_tx_string, strlen("ssid -r"))) {
  49. wifi_text_input_set_header_text(text_input, "Remove target from SSID list");
  50. } else if(0 == strncmp("select -a", app->selected_tx_string, strlen("select -a"))) {
  51. wifi_text_input_set_header_text(text_input, "Add target from AP list");
  52. } else if(0 == strncmp("select -s", app->selected_tx_string, strlen("select -s"))) {
  53. wifi_text_input_set_header_text(text_input, "Add target from SSID list");
  54. } else {
  55. wifi_text_input_set_header_text(text_input, "Add command arguments");
  56. }
  57. wifi_text_input_set_result_callback(
  58. text_input,
  59. wifi_marauder_scene_text_input_callback,
  60. app,
  61. app->text_input_store,
  62. WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE,
  63. false);
  64. view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewTextInput);
  65. }
  66. bool wifi_marauder_scene_text_input_on_event(void* context, SceneManagerEvent event) {
  67. WifiMarauderApp* app = context;
  68. bool consumed = false;
  69. if(event.type == SceneManagerEventTypeCustom) {
  70. if(event.event == WifiMarauderEventStartConsole) {
  71. // Point to custom string to send
  72. app->selected_tx_string = app->text_input_store;
  73. scene_manager_next_scene(app->scene_manager, WifiMarauderSceneConsoleOutput);
  74. consumed = true;
  75. } else if(event.event == WifiMarauderEventSaveSourceMac) {
  76. if(12 != strlen(app->text_input_store)) {
  77. wifi_text_input_set_header_text(app->text_input, "MAC must be 12 hex chars!");
  78. } else {
  79. snprintf(
  80. app->special_case_input_src_addr,
  81. sizeof(app->special_case_input_src_addr),
  82. "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
  83. app->text_input_store[0],
  84. app->text_input_store[1],
  85. app->text_input_store[2],
  86. app->text_input_store[3],
  87. app->text_input_store[4],
  88. app->text_input_store[5],
  89. app->text_input_store[6],
  90. app->text_input_store[7],
  91. app->text_input_store[8],
  92. app->text_input_store[9],
  93. app->text_input_store[10],
  94. app->text_input_store[11]);
  95. // Advance scene to input destination MAC, clear text input
  96. app->special_case_input_step = 2;
  97. bzero(app->text_input_store, WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE);
  98. wifi_text_input_set_header_text(app->text_input, "Enter destination MAC");
  99. }
  100. consumed = true;
  101. } else if(event.event == WifiMarauderEventSaveDestinationMac) {
  102. if(12 != strlen(app->text_input_store)) {
  103. wifi_text_input_set_header_text(app->text_input, "MAC must be 12 hex chars!");
  104. } else {
  105. snprintf(
  106. app->special_case_input_dst_addr,
  107. sizeof(app->special_case_input_dst_addr),
  108. "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
  109. app->text_input_store[0],
  110. app->text_input_store[1],
  111. app->text_input_store[2],
  112. app->text_input_store[3],
  113. app->text_input_store[4],
  114. app->text_input_store[5],
  115. app->text_input_store[6],
  116. app->text_input_store[7],
  117. app->text_input_store[8],
  118. app->text_input_store[9],
  119. app->text_input_store[10],
  120. app->text_input_store[11]);
  121. // Construct command with source and destination MACs
  122. snprintf(
  123. app->text_input_store,
  124. WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE,
  125. "attack -t deauth -s %18s -d %18s",
  126. app->special_case_input_src_addr,
  127. app->special_case_input_dst_addr);
  128. app->selected_tx_string = app->text_input_store;
  129. scene_manager_next_scene(app->scene_manager, WifiMarauderSceneConsoleOutput);
  130. }
  131. consumed = true;
  132. }
  133. }
  134. return consumed;
  135. }
  136. void wifi_marauder_scene_text_input_on_exit(void* context) {
  137. WifiMarauderApp* app = context;
  138. wifi_text_input_reset(app->text_input);
  139. }