wifi_marauder_scene_text_input.c 6.6 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. TextInput* text_input = app->text_input;
  41. // Add help message to header
  42. if(app->special_case_input_step == 1) {
  43. 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. 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. 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. 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. 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. text_input_set_header_text(text_input, "Add target from SSID list");
  54. } else {
  55. text_input_set_header_text(text_input, "Add command arguments");
  56. }
  57. 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. text_input_show_illegal_symbols(text_input, true);
  65. view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewTextInput);
  66. }
  67. bool wifi_marauder_scene_text_input_on_event(void* context, SceneManagerEvent event) {
  68. WifiMarauderApp* app = context;
  69. bool consumed = false;
  70. if(event.type == SceneManagerEventTypeCustom) {
  71. if(event.event == WifiMarauderEventStartConsole) {
  72. // Point to custom string to send
  73. app->selected_tx_string = app->text_input_store;
  74. scene_manager_next_scene(app->scene_manager, WifiMarauderSceneConsoleOutput);
  75. consumed = true;
  76. } else if(event.event == WifiMarauderEventSaveSourceMac) {
  77. if(12 != strlen(app->text_input_store)) {
  78. text_input_set_header_text(app->text_input, "MAC must be 12 hex chars!");
  79. } else {
  80. snprintf(
  81. app->special_case_input_src_addr,
  82. sizeof(app->special_case_input_src_addr),
  83. "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
  84. app->text_input_store[0],
  85. app->text_input_store[1],
  86. app->text_input_store[2],
  87. app->text_input_store[3],
  88. app->text_input_store[4],
  89. app->text_input_store[5],
  90. app->text_input_store[6],
  91. app->text_input_store[7],
  92. app->text_input_store[8],
  93. app->text_input_store[9],
  94. app->text_input_store[10],
  95. app->text_input_store[11]);
  96. // Advance scene to input destination MAC, clear text input
  97. app->special_case_input_step = 2;
  98. bzero(app->text_input_store, WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE);
  99. text_input_set_header_text(app->text_input, "Enter destination MAC");
  100. }
  101. consumed = true;
  102. } else if(event.event == WifiMarauderEventSaveDestinationMac) {
  103. if(12 != strlen(app->text_input_store)) {
  104. text_input_set_header_text(app->text_input, "MAC must be 12 hex chars!");
  105. } else {
  106. snprintf(
  107. app->special_case_input_dst_addr,
  108. sizeof(app->special_case_input_dst_addr),
  109. "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
  110. app->text_input_store[0],
  111. app->text_input_store[1],
  112. app->text_input_store[2],
  113. app->text_input_store[3],
  114. app->text_input_store[4],
  115. app->text_input_store[5],
  116. app->text_input_store[6],
  117. app->text_input_store[7],
  118. app->text_input_store[8],
  119. app->text_input_store[9],
  120. app->text_input_store[10],
  121. app->text_input_store[11]);
  122. // Construct command with source and destination MACs
  123. snprintf(
  124. app->text_input_store,
  125. WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE,
  126. "attack -t deauth -s %18s -d %18s",
  127. app->special_case_input_src_addr,
  128. app->special_case_input_dst_addr);
  129. app->selected_tx_string = app->text_input_store;
  130. scene_manager_next_scene(app->scene_manager, WifiMarauderSceneConsoleOutput);
  131. }
  132. consumed = true;
  133. }
  134. }
  135. return consumed;
  136. }
  137. void wifi_marauder_scene_text_input_on_exit(void* context) {
  138. WifiMarauderApp* app = context;
  139. text_input_reset(app->text_input);
  140. }