MenuFunctions.cpp 12 KB

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