MenuFunctions.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #include "MenuFunctions.h"
  2. MenuFunctions::MenuFunctions()
  3. {
  4. }
  5. // Function to check menu input
  6. void MenuFunctions::main()
  7. {
  8. boolean pressed = false;
  9. // This is code from bodmer's keypad example
  10. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  11. // Get the display buffer out of the way
  12. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
  13. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  14. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  15. display_obj.displayBuffer();
  16. // Pressed will be set true is there is a valid touch on the screen
  17. int pre_getTouch = millis();
  18. // getTouch causes a 10ms delay which makes beacon spam less effective
  19. //if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF)
  20. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  21. //boolean pressed = false;
  22. //Serial.print("getTouch: ");
  23. //Serial.print(millis() - pre_getTouch);
  24. //Serial.println("ms");
  25. // This is if there are scans/attacks going on
  26. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) && (pressed))
  27. {
  28. // Stop the current scan
  29. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  30. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  31. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ST) ||
  32. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  33. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  34. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  35. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  36. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  37. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  38. {
  39. Serial.println("Stopping scan...");
  40. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  41. // If we don't do this, the text and button coordinates will be off
  42. display_obj.tft.init();
  43. // Take us back to the menu
  44. changeMenu(current_menu);
  45. }
  46. x = -1;
  47. y = -1;
  48. return;
  49. }
  50. // Check if any key coordinate boxes contain the touch coordinates
  51. // This is for when on a menu
  52. if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  53. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  54. {
  55. // Need this to set all keys to false
  56. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  57. if (pressed && key[b].contains(t_x, t_y)) {
  58. key[b].press(true); // tell the button it is pressed
  59. } else {
  60. key[b].press(false); // tell the button it is NOT pressed
  61. }
  62. }
  63. // Check if any key has changed state
  64. for (uint8_t b = 0; b < current_menu->list->size(); b++) {
  65. display_obj.tft.setFreeFont(MENU_FONT);
  66. if (key[b].justPressed()) {
  67. key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert
  68. }
  69. // If button was just release, execute the button's function
  70. if (key[b].justReleased())
  71. {
  72. key[b].drawButton2(current_menu->list->get(b).name); // draw normal
  73. current_menu->list->get(b).callable();
  74. }
  75. display_obj.tft.setFreeFont(NULL);
  76. }
  77. }
  78. x = -1;
  79. y = -1;
  80. }
  81. // Function to build the menus
  82. void MenuFunctions::RunSetup()
  83. {
  84. // root menu stuff
  85. mainMenu.list = new SimpleList<MenuNode>(); // Get list in first menu ready
  86. // Main menu stuff
  87. wifiMenu.list = new SimpleList<MenuNode>(); // Get list in second menu ready
  88. bluetoothMenu.list = new SimpleList<MenuNode>(); // Get list in third menu ready
  89. generalMenu.list = new SimpleList<MenuNode>();
  90. // WiFi menu stuff
  91. wifiSnifferMenu.list = new SimpleList<MenuNode>();
  92. wifiScannerMenu.list = new SimpleList<MenuNode>();
  93. wifiAttackMenu.list = new SimpleList<MenuNode>();
  94. // Bluetooth menu stuff
  95. bluetoothSnifferMenu.list = new SimpleList<MenuNode>();
  96. bluetoothScannerMenu.list = new SimpleList<MenuNode>();
  97. // Work menu names
  98. mainMenu.name = " ESP32 Marauder ";
  99. wifiMenu.name = " WiFi ";
  100. generalMenu.name = " General Apps ";
  101. bluetoothMenu.name = " Bluetooth ";
  102. wifiSnifferMenu.name = " WiFi Sniffers ";
  103. wifiScannerMenu.name = " WiFi Scanners";
  104. wifiAttackMenu.name = " WiFi Attacks ";
  105. bluetoothSnifferMenu.name = " Bluetooth Sniffers ";
  106. bluetoothScannerMenu.name = " Bluetooth Scanners ";
  107. // Build Main Menu
  108. mainMenu.parentMenu = NULL;
  109. addNodes(&mainMenu, "WiFi", TFT_GREEN, NULL, 0, [this](){changeMenu(&wifiMenu);});
  110. addNodes(&mainMenu, "Bluetooth", TFT_CYAN, NULL, 1, [this](){changeMenu(&bluetoothMenu);});
  111. addNodes(&mainMenu, "General Apps", TFT_MAGENTA, NULL, 2, [this](){changeMenu(&generalMenu);});
  112. addNodes(&mainMenu, "Reboot", TFT_LIGHTGREY, NULL, 3, [](){ESP.restart();});
  113. // Build WiFi Menu
  114. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  115. addNodes(&wifiMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiMenu.parentMenu);});
  116. addNodes(&wifiMenu, "Sniffers", TFT_YELLOW, NULL, 1, [this](){changeMenu(&wifiSnifferMenu);});
  117. addNodes(&wifiMenu, "Scanners", TFT_ORANGE, NULL, 1, [this](){changeMenu(&wifiScannerMenu);});
  118. addNodes(&wifiMenu, "Attacks", TFT_RED, NULL, 1, [this](){changeMenu(&wifiAttackMenu);});
  119. // Build WiFi sniffer Menu
  120. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  121. addNodes(&wifiSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiSnifferMenu.parentMenu);});
  122. addNodes(&wifiSnifferMenu, "Probe Request Sniff", TFT_CYAN, NULL, 2, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);});
  123. addNodes(&wifiSnifferMenu, "Beacon Sniff", TFT_MAGENTA, NULL, 3, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);});
  124. addNodes(&wifiSnifferMenu, "Deauth Sniff", TFT_RED, NULL, 4, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_DEAUTH, TFT_RED);});
  125. // Build WiFi scanner Menu
  126. wifiScannerMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  127. addNodes(&wifiScannerMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(wifiScannerMenu.parentMenu);});
  128. // Build WiFi attack menu
  129. wifiAttackMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  130. addNodes(&wifiAttackMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiAttackMenu.parentMenu);});
  131. addNodes(&wifiAttackMenu, "Beacon Spam Random", TFT_ORANGE, NULL, 1, [this](){wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);});
  132. addNodes(&wifiAttackMenu, "Rick Roll Beacon", TFT_YELLOW, NULL, 1, [this](){wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);});
  133. // Build Bluetooth Menu
  134. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  135. addNodes(&bluetoothMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(bluetoothMenu.parentMenu);});
  136. addNodes(&bluetoothMenu, "Sniffers", TFT_YELLOW, NULL, 1, [this](){changeMenu(&bluetoothSnifferMenu);});
  137. addNodes(&bluetoothMenu, "Scanners", TFT_ORANGE, NULL, 1, [this](){changeMenu(&bluetoothScannerMenu);});
  138. // Build bluetooth sniffer Menu
  139. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  140. addNodes(&bluetoothSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(bluetoothSnifferMenu.parentMenu);});
  141. addNodes(&bluetoothSnifferMenu, "Bluetooth Sniffer", TFT_GREEN, NULL, 1, [this](){wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);});
  142. // Build bluetooth scanner Menu
  143. bluetoothScannerMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  144. addNodes(&bluetoothScannerMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(bluetoothScannerMenu.parentMenu);});
  145. addNodes(&bluetoothScannerMenu, "Detect Card Skimmers", TFT_MAGENTA, NULL, 2, [this](){wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);});
  146. generalMenu.parentMenu = &mainMenu;
  147. addNodes(&generalMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){display_obj.draw_tft = false; changeMenu(generalMenu.parentMenu);});
  148. addNodes(&generalMenu, "Draw", TFT_WHITE, NULL, 1, [this](){display_obj.clearScreen(); display_obj.draw_tft = true;});
  149. // Set the current menu to the mainMenu
  150. changeMenu(&mainMenu);
  151. }
  152. // Function to change menu
  153. void MenuFunctions::changeMenu(Menu* menu)
  154. {
  155. display_obj.initScrollValues();
  156. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  157. display_obj.tft.init();
  158. current_menu = menu;
  159. buildButtons(menu);
  160. displayCurrentMenu();
  161. }
  162. // Function to show all MenuNodes in a Menu
  163. void MenuFunctions::showMenuList(Menu* menu, int layer)
  164. {
  165. // Iterate through all of the menu nodes in the menu
  166. for (int i = 0; i < menu->list->size(); i++)
  167. {
  168. // Depending on layer, indent
  169. for (int x = 0; x < layer * 4; x++)
  170. Serial.print(" ");
  171. Serial.print("Node: ");
  172. Serial.println(menu->list->get(i).name);
  173. // If the current menu node points to another menu, list that menu
  174. if (menu->list->get(i).childMenu != NULL)
  175. showMenuList(menu->list->get(i).childMenu, layer+1);
  176. }
  177. Serial.println();
  178. }
  179. // Function to add MenuNodes to a menu
  180. void MenuFunctions::addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function<void()> callable)
  181. {
  182. TFT_eSPI_Button new_button;
  183. menu->list->add(MenuNode{name, color, child, &new_button, callable});
  184. }
  185. void MenuFunctions::buildButtons(Menu* menu)
  186. {
  187. Serial.println("Bulding buttons...");
  188. if (menu->list != NULL)
  189. {
  190. //for (int i = 0; i < sizeof(key); i++)
  191. // key[i] = NULL;
  192. for (int i = 0; i < menu->list->size(); i++)
  193. {
  194. TFT_eSPI_Button new_button;
  195. char buf[menu->list->get(i).name.length() + 1] = {};
  196. menu->list->get(i).name.toCharArray(buf, menu->list->get(i).name.length() + 1);
  197. key[i].initButton(&display_obj.tft,
  198. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  199. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  200. KEY_W,
  201. KEY_H,
  202. TFT_BLACK, // Outline
  203. TFT_BLACK, // Fill
  204. menu->list->get(i).color, // Text
  205. buf,
  206. KEY_TEXTSIZE);
  207. }
  208. }
  209. }
  210. void MenuFunctions::displayCurrentMenu()
  211. {
  212. Serial.println("Displaying current menu...");
  213. display_obj.clearScreen();
  214. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  215. display_obj.tft.fillRect(0,0,240,16, TFT_DARKGREY);
  216. //display_obj.tft.drawCentreString(" ESP32 Marauder ",120,0,2);
  217. //Serial.println("Getting size...");
  218. //char buf[&current_menu->parentMenu->name.length() + 1] = {};
  219. //Serial.println("Got size...");
  220. //current_menu->parentMenu->name.toCharArray(buf, current_menu->parentMenu->name.length() + 1);
  221. //String current_name = &current_menu->parentMenu->name;
  222. //Serial.println("gottem");
  223. display_obj.tft.drawCentreString(current_menu->name,120,0,2);
  224. if (current_menu->list != NULL)
  225. {
  226. display_obj.tft.setFreeFont(MENU_FONT);
  227. for (int i = 0; i < current_menu->list->size(); i++)
  228. {
  229. key[i].drawButton2(current_menu->list->get(i).name);
  230. }
  231. display_obj.tft.setFreeFont(NULL);
  232. }
  233. }