MenuFunctions.cpp 14 KB

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