MenuFunctions.cpp 15 KB

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