MenuFunctions.cpp 11 KB

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