MenuFunctions.cpp 11 KB

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