MenuFunctions.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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(uint32_t currentTime)
  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. //if ((display_obj.current_banner_pos <= 0) || (display_obj.current_banner_pos == SCREEN_WIDTH))
  18. //{
  19. // this->drawStatusBar();
  20. //}
  21. display_obj.updateBanner(current_menu->name);
  22. }
  23. if (currentTime != 0) {
  24. if (currentTime - initTime >= 100) {
  25. this->initTime = millis();
  26. this->updateStatusBar();
  27. }
  28. }
  29. //this->displayCurrentMenu();
  30. boolean pressed = false;
  31. // This is code from bodmer's keypad example
  32. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  33. // Get the display buffer out of the way
  34. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
  35. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  36. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  37. display_obj.displayBuffer();
  38. //Serial.println(wifi_scan_obj.freeRAM());
  39. // Pressed will be set true is there is a valid touch on the screen
  40. int pre_getTouch = millis();
  41. // getTouch causes a 10ms delay which makes beacon spam less effective
  42. //if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF)
  43. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  44. //if (pressed)
  45. // Serial.println("Pressed, son");
  46. //boolean pressed = false;
  47. //Serial.print("getTouch: ");
  48. //Serial.print(millis() - pre_getTouch);
  49. //Serial.println("ms");
  50. // This is if there are scans/attacks going on
  51. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
  52. (pressed) &&
  53. (wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
  54. (wifi_scan_obj.currentScanMode != SHOW_INFO))
  55. {
  56. // Stop the current scan
  57. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  58. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  59. (wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
  60. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  61. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  62. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  63. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  64. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  65. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  66. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  67. {
  68. Serial.println("Stopping scan...");
  69. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  70. // If we don't do this, the text and button coordinates will be off
  71. display_obj.tft.init();
  72. // Take us back to the menu
  73. changeMenu(current_menu);
  74. }
  75. x = -1;
  76. y = -1;
  77. return;
  78. }
  79. // Check if any key coordinate boxes contain the touch coordinates
  80. // This is for when on a menu
  81. if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  82. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  83. {
  84. // Need this to set all keys to false
  85. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  86. if (pressed && display_obj.key[b].contains(t_x, t_y)) {
  87. display_obj.key[b].press(true); // tell the button it is pressed
  88. } else {
  89. display_obj.key[b].press(false); // tell the button it is NOT pressed
  90. }
  91. }
  92. // Check if any key has changed state
  93. for (uint8_t b = 0; b < current_menu->list->size(); b++) {
  94. display_obj.tft.setFreeFont(MENU_FONT);
  95. if (display_obj.key[b].justPressed()) {
  96. //display_obj.key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert
  97. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name, true);
  98. display_obj.key[b].drawButton(true, current_menu->list->get(b).name);
  99. if (current_menu->list->get(b).name != "Back")
  100. display_obj.tft.drawXBitmap(0,
  101. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  102. menu_icons[current_menu->list->get(b).icon],
  103. ICON_W,
  104. ICON_H,
  105. current_menu->list->get(b).color,
  106. TFT_BLACK);
  107. }
  108. //else if (pressed)
  109. // display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  110. // If button was just release, execute the button's function
  111. if ((display_obj.key[b].justReleased()) && (!pressed))
  112. {
  113. //display_obj.key[b].drawButton2(current_menu->list->get(b).name); // draw normal
  114. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name);
  115. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  116. current_menu->list->get(b).callable();
  117. }
  118. // This
  119. else if ((display_obj.key[b].justReleased()) && (pressed)) {
  120. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  121. if (current_menu->list->get(b).name != "Back")
  122. display_obj.tft.drawXBitmap(0,
  123. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  124. menu_icons[current_menu->list->get(b).icon],
  125. ICON_W,
  126. ICON_H,
  127. TFT_BLACK,
  128. current_menu->list->get(b).color);
  129. }
  130. display_obj.tft.setFreeFont(NULL);
  131. }
  132. }
  133. x = -1;
  134. y = -1;
  135. }
  136. #if BATTERY_ANALOG_ON == 1
  137. byte battery_analog_array[10];
  138. byte battery_count = 0;
  139. byte battery_analog_last = 101;
  140. #define BATTERY_CHECK 50
  141. uint16_t battery_analog = 0;
  142. void MenuFunctions::battery(bool initial)
  143. {
  144. if (BATTERY_ANALOG_ON) {
  145. uint8_t n = 0;
  146. byte battery_analog_sample[10];
  147. byte deviation;
  148. if (battery_count == BATTERY_CHECK - 5) digitalWrite(BATTERY_PIN, HIGH);
  149. else if (battery_count == 5) digitalWrite(BATTERY_PIN, LOW);
  150. if (battery_count == 0) {
  151. battery_analog = 0;
  152. for (n = 9; n > 0; n--)battery_analog_array[n] = battery_analog_array[n - 1];
  153. for (n = 0; n < 10; n++) {
  154. battery_analog_sample[n] = map((analogRead(ANALOG_PIN) * 5), 2400, 4200, 0, 100);
  155. if (battery_analog_sample[n] > 100) battery_analog_sample[n] = 100;
  156. else if (battery_analog_sample[n] < 0) battery_analog_sample[n] = 0;
  157. battery_analog += battery_analog_sample[n];
  158. }
  159. battery_analog = battery_analog / 10;
  160. for (n = 0; n < 10; n++) {
  161. deviation = abs(battery_analog - battery_analog_sample[n]);
  162. if (deviation >= 10) battery_analog_sample[n] = battery_analog;
  163. }
  164. battery_analog = 0;
  165. for (n = 0; n < 10; n++) battery_analog += battery_analog_sample[n];
  166. battery_analog = battery_analog / 10;
  167. battery_analog_array[0] = battery_analog;
  168. if (battery_analog_array[9] > 0 ) {
  169. battery_analog = 0;
  170. for (n = 0; n < 10; n++) battery_analog += battery_analog_array[n];
  171. battery_analog = battery_analog / 10;
  172. }
  173. battery_count ++;
  174. }
  175. else if (battery_count < BATTERY_CHECK) battery_count++;
  176. else if (battery_count >= BATTERY_CHECK) battery_count = 0;
  177. if (battery_analog_last != battery_analog) {
  178. battery_analog_last = battery_analog;
  179. MenuFunctions::battery2();
  180. }
  181. }
  182. }
  183. void MenuFunctions::battery2(bool initial)
  184. {
  185. uint16_t the_color;
  186. if ( digitalRead(CHARGING_PIN) == 1) the_color = TFT_BLUE;
  187. else if (battery_analog < 20) the_color = TFT_RED;
  188. else if (battery_analog < 40) the_color = TFT_YELLOW;
  189. else the_color = TFT_GREEN;
  190. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  191. display_obj.tft.fillRect(186, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  192. display_obj.tft.drawXBitmap(186,
  193. 0,
  194. menu_icons[STATUS_BAT],
  195. 16,
  196. 16,
  197. STATUSBAR_COLOR,
  198. the_color);
  199. display_obj.tft.drawString((String) battery_analog + "%", 204, 0, 2);
  200. }
  201. #else
  202. void MenuFunctions::battery(bool initial)
  203. {
  204. uint16_t the_color;
  205. if (battery_obj.i2c_supported)
  206. {
  207. // Could use int compare maybe idk
  208. if (((String)battery_obj.battery_level != "25") && ((String)battery_obj.battery_level != "0"))
  209. the_color = TFT_GREEN;
  210. else
  211. the_color = TFT_RED;
  212. if ((battery_obj.battery_level != battery_obj.old_level) || (initial)) {
  213. battery_obj.old_level = battery_obj.battery_level;
  214. display_obj.tft.fillRect(204, 0, SCREEN_WIDTH, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  215. display_obj.tft.setCursor(0, 1);
  216. display_obj.tft.drawXBitmap(186,
  217. 0,
  218. menu_icons[STATUS_BAT],
  219. 16,
  220. 16,
  221. STATUSBAR_COLOR,
  222. the_color);
  223. display_obj.tft.drawString((String)battery_obj.battery_level + "%", 204, 0, 2);
  224. }
  225. }
  226. }
  227. void MenuFunctions::battery2(bool initial)
  228. {
  229. MenuFunctions::battery(initial);
  230. }
  231. #endif
  232. void MenuFunctions::updateStatusBar()
  233. {
  234. uint16_t the_color;
  235. // Draw temp info
  236. if (temp_obj.current_temp < 70)
  237. the_color = TFT_GREEN;
  238. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  239. the_color = TFT_YELLOW;
  240. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  241. the_color = TFT_ORANGE;
  242. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  243. the_color = TFT_RED;
  244. else
  245. the_color = TFT_MAROON;
  246. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  247. if (temp_obj.current_temp != temp_obj.old_temp) {
  248. temp_obj.old_temp = temp_obj.current_temp;
  249. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  250. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  251. }
  252. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  253. // WiFi Channel Stuff
  254. if (wifi_scan_obj.set_channel != wifi_scan_obj.old_channel) {
  255. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  256. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  257. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  258. }
  259. // RAM Stuff
  260. wifi_scan_obj.freeRAM();
  261. if (wifi_scan_obj.free_ram != wifi_scan_obj.old_free_ram) {
  262. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  263. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  264. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  265. }
  266. // Draw battery info
  267. MenuFunctions::battery(false);
  268. // Draw SD info
  269. if (sd_obj.supported)
  270. the_color = TFT_GREEN;
  271. else
  272. the_color = TFT_RED;
  273. display_obj.tft.drawXBitmap(170,
  274. 0,
  275. menu_icons[STATUS_SD],
  276. 16,
  277. 16,
  278. STATUSBAR_COLOR,
  279. the_color);
  280. //display_obj.tft.print((String)battery_obj.battery_level + "%");
  281. }
  282. void MenuFunctions::drawStatusBar()
  283. {
  284. display_obj.tft.fillRect(0, 0, 240, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  285. //display_obj.tft.fillRect(0, STATUS_BAR_WIDTH + 1, 240, 1, TFT_DARKGREY);
  286. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  287. //display_obj.tft.setTextSize(2);
  288. uint16_t the_color;
  289. // Draw temp info
  290. if (temp_obj.current_temp < 70)
  291. the_color = TFT_GREEN;
  292. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  293. the_color = TFT_YELLOW;
  294. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  295. the_color = TFT_ORANGE;
  296. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  297. the_color = TFT_RED;
  298. else
  299. the_color = TFT_MAROON;
  300. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  301. temp_obj.old_temp = temp_obj.current_temp;
  302. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  303. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  304. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  305. // WiFi Channel Stuff
  306. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  307. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  308. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  309. // RAM Stuff
  310. wifi_scan_obj.freeRAM();
  311. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  312. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  313. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  314. MenuFunctions::battery2(true);
  315. // Draw SD info
  316. if (sd_obj.supported)
  317. the_color = TFT_GREEN;
  318. else
  319. the_color = TFT_RED;
  320. display_obj.tft.drawXBitmap(170,
  321. 0,
  322. menu_icons[STATUS_SD],
  323. 16,
  324. 16,
  325. STATUSBAR_COLOR,
  326. the_color);
  327. //display_obj.tft.print((String)battery_obj.battery_level + "%");
  328. }
  329. void MenuFunctions::orientDisplay()
  330. {
  331. display_obj.tft.init();
  332. display_obj.tft.setRotation(0); // Portrait
  333. display_obj.tft.setCursor(0, 0);
  334. //uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait
  335. //uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  336. #ifdef TFT_SHIELD
  337. uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
  338. Serial.println("Using TFT Shield");
  339. #else if defined(TFT_DIY)
  340. uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  341. Serial.println("Using TFT DIY");
  342. #endif
  343. display_obj.tft.setTouch(calData);
  344. //display_obj.clearScreen();
  345. changeMenu(current_menu);
  346. }
  347. // Function to build the menus
  348. void MenuFunctions::RunSetup()
  349. {
  350. // root menu stuff
  351. mainMenu.list = new LinkedList<MenuNode>(); // Get list in first menu ready
  352. // Main menu stuff
  353. wifiMenu.list = new LinkedList<MenuNode>(); // Get list in second menu ready
  354. bluetoothMenu.list = new LinkedList<MenuNode>(); // Get list in third menu ready
  355. generalMenu.list = new LinkedList<MenuNode>();
  356. deviceMenu.list = new LinkedList<MenuNode>();
  357. // Device menu stuff
  358. failedUpdateMenu.list = new LinkedList<MenuNode>();
  359. whichUpdateMenu.list = new LinkedList<MenuNode>();
  360. confirmMenu.list = new LinkedList<MenuNode>();
  361. updateMenu.list = new LinkedList<MenuNode>();
  362. infoMenu.list = new LinkedList<MenuNode>();
  363. // WiFi menu stuff
  364. wifiSnifferMenu.list = new LinkedList<MenuNode>();
  365. wifiScannerMenu.list = new LinkedList<MenuNode>();
  366. wifiAttackMenu.list = new LinkedList<MenuNode>();
  367. // Bluetooth menu stuff
  368. bluetoothSnifferMenu.list = new LinkedList<MenuNode>();
  369. bluetoothScannerMenu.list = new LinkedList<MenuNode>();
  370. // Work menu names
  371. mainMenu.name = " ESP32 Marauder ";
  372. wifiMenu.name = " WiFi ";
  373. deviceMenu.name = " Device ";
  374. generalMenu.name = " General Apps ";
  375. failedUpdateMenu.name = " Updating... ";
  376. whichUpdateMenu.name = "Select Method ";
  377. confirmMenu.name = " Confirm Update ";
  378. updateMenu.name = " Update Firmware ";
  379. infoMenu.name = " Device Info ";
  380. bluetoothMenu.name = " Bluetooth ";
  381. wifiSnifferMenu.name = " WiFi Sniffers ";
  382. wifiScannerMenu.name = " WiFi Scanners";
  383. wifiAttackMenu.name = " WiFi Attacks ";
  384. bluetoothSnifferMenu.name = " Bluetooth Sniffers ";
  385. bluetoothScannerMenu.name = " Bluetooth Scanners ";
  386. // Build Main Menu
  387. mainMenu.parentMenu = NULL;
  388. addNodes(&mainMenu, "WiFi", TFT_GREEN, NULL, WIFI, [this]() {
  389. changeMenu(&wifiMenu);
  390. });
  391. addNodes(&mainMenu, "Bluetooth", TFT_CYAN, NULL, BLUETOOTH, [this]() {
  392. changeMenu(&bluetoothMenu);
  393. });
  394. addNodes(&mainMenu, "General Apps", TFT_MAGENTA, NULL, GENERAL_APPS, [this]() {
  395. changeMenu(&generalMenu);
  396. });
  397. addNodes(&mainMenu, "Device", TFT_BLUE, NULL, DEVICE, [this]() {
  398. changeMenu(&deviceMenu);
  399. });
  400. addNodes(&mainMenu, "Reboot", TFT_LIGHTGREY, NULL, REBOOT, []() {
  401. ESP.restart();
  402. });
  403. // Build WiFi Menu
  404. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  405. addNodes(&wifiMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  406. changeMenu(wifiMenu.parentMenu);
  407. });
  408. addNodes(&wifiMenu, "Sniffers", TFT_YELLOW, NULL, SNIFFERS, [this]() {
  409. changeMenu(&wifiSnifferMenu);
  410. });
  411. addNodes(&wifiMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this]() {
  412. changeMenu(&wifiScannerMenu);
  413. });
  414. addNodes(&wifiMenu, "Attacks", TFT_RED, NULL, ATTACKS, [this]() {
  415. changeMenu(&wifiAttackMenu);
  416. });
  417. // Build WiFi sniffer Menu
  418. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  419. addNodes(&wifiSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  420. changeMenu(wifiSnifferMenu.parentMenu);
  421. });
  422. addNodes(&wifiSnifferMenu, "Probe Request Sniff", TFT_CYAN, NULL, PROBE_SNIFF, [this]() {
  423. display_obj.clearScreen();
  424. this->drawStatusBar();
  425. wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);
  426. });
  427. addNodes(&wifiSnifferMenu, "Beacon Sniff", TFT_MAGENTA, NULL, BEACON_SNIFF, [this]() {
  428. display_obj.clearScreen();
  429. this->drawStatusBar();
  430. wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);
  431. });
  432. addNodes(&wifiSnifferMenu, "Deauth Sniff", TFT_RED, NULL, DEAUTH_SNIFF, [this]() {
  433. display_obj.clearScreen();
  434. this->drawStatusBar();
  435. wifi_scan_obj.StartScan(WIFI_SCAN_DEAUTH, TFT_RED);
  436. });
  437. // Build WiFi scanner Menu
  438. wifiScannerMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  439. addNodes(&wifiScannerMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  440. changeMenu(wifiScannerMenu.parentMenu);
  441. });
  442. addNodes(&wifiScannerMenu, "Packet Monitor", TFT_BLUE, NULL, PACKET_MONITOR, [this]() {
  443. wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);
  444. });
  445. addNodes(&wifiScannerMenu, "EAPOL/PMKID Scan", TFT_VIOLET, NULL, EAPOL, [this]() {
  446. wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
  447. });
  448. addNodes(&wifiScannerMenu, "Detect Pwnagotchi", TFT_RED, NULL, PWNAGOTCHI, [this]() {
  449. display_obj.clearScreen();
  450. this->drawStatusBar();
  451. wifi_scan_obj.StartScan(WIFI_SCAN_PWN, TFT_RED);
  452. });
  453. addNodes(&wifiScannerMenu, "Detect Espressif", TFT_ORANGE, NULL, ESPRESSIF, [this]() {
  454. display_obj.clearScreen();
  455. this->drawStatusBar();
  456. wifi_scan_obj.StartScan(WIFI_SCAN_ESPRESSIF, TFT_ORANGE);
  457. });
  458. // Build WiFi attack menu
  459. wifiAttackMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  460. addNodes(&wifiAttackMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  461. changeMenu(wifiAttackMenu.parentMenu);
  462. });
  463. addNodes(&wifiAttackMenu, "Beacon Spam Random", TFT_ORANGE, NULL, BEACON_SPAM, [this]() {
  464. display_obj.clearScreen();
  465. this->drawStatusBar();
  466. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);
  467. });
  468. addNodes(&wifiAttackMenu, "Rick Roll Beacon", TFT_YELLOW, NULL, RICK_ROLL, [this]() {
  469. display_obj.clearScreen();
  470. this->drawStatusBar();
  471. wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);
  472. });
  473. // Build Bluetooth Menu
  474. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  475. addNodes(&bluetoothMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  476. changeMenu(bluetoothMenu.parentMenu);
  477. });
  478. addNodes(&bluetoothMenu, "Sniffers", TFT_YELLOW, NULL, SNIFFERS, [this]() {
  479. changeMenu(&bluetoothSnifferMenu);
  480. });
  481. addNodes(&bluetoothMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this]() {
  482. changeMenu(&bluetoothScannerMenu);
  483. });
  484. // Build bluetooth sniffer Menu
  485. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  486. addNodes(&bluetoothSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  487. changeMenu(bluetoothSnifferMenu.parentMenu);
  488. });
  489. addNodes(&bluetoothSnifferMenu, "Bluetooth Sniffer", TFT_GREEN, NULL, BLUETOOTH_SNIFF, [this]() {
  490. display_obj.clearScreen();
  491. this->drawStatusBar();
  492. wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);
  493. });
  494. // Build bluetooth scanner Menu
  495. bluetoothScannerMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  496. addNodes(&bluetoothScannerMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  497. changeMenu(bluetoothScannerMenu.parentMenu);
  498. });
  499. addNodes(&bluetoothScannerMenu, "Detect Card Skimmers", TFT_MAGENTA, NULL, CC_SKIMMERS, [this]() {
  500. display_obj.clearScreen();
  501. this->drawStatusBar();
  502. wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);
  503. });
  504. // General apps menu
  505. generalMenu.parentMenu = &mainMenu;
  506. addNodes(&generalMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  507. display_obj.draw_tft = false;
  508. changeMenu(generalMenu.parentMenu);
  509. });
  510. addNodes(&generalMenu, "Draw", TFT_WHITE, NULL, DRAW, [this]() {
  511. display_obj.clearScreen();
  512. display_obj.draw_tft = true;
  513. });
  514. // Device menu
  515. deviceMenu.parentMenu = &mainMenu;
  516. addNodes(&deviceMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  517. changeMenu(deviceMenu.parentMenu);
  518. });
  519. //addNodes(&deviceMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); web_obj.setupOTAupdate();});
  520. addNodes(&deviceMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this]() {
  521. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  522. changeMenu(&whichUpdateMenu);
  523. });
  524. addNodes(&deviceMenu, "Device Info", TFT_WHITE, NULL, DEVICE_INFO, [this]() {
  525. wifi_scan_obj.currentScanMode = SHOW_INFO;
  526. changeMenu(&infoMenu);
  527. wifi_scan_obj.RunInfo();
  528. });
  529. //addNodes(&deviceMenu, "Join WiFi", TFT_YELLOW, NULL, SNIFFERS, [this](){display_obj.clearScreen(); wifi_scan_obj.currentScanMode = LV_JOIN_WIFI; wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);});
  530. // Select update
  531. whichUpdateMenu.parentMenu = &deviceMenu;
  532. addNodes(&whichUpdateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  533. changeMenu(whichUpdateMenu.parentMenu);
  534. });
  535. addNodes(&whichUpdateMenu, "Web Update", TFT_GREEN, NULL, WEB_UPDATE, [this]() {
  536. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  537. changeMenu(&updateMenu);
  538. web_obj.setupOTAupdate();
  539. });
  540. if (sd_obj.supported) addNodes(&whichUpdateMenu, "SD Update", TFT_MAGENTA, NULL, SD_UPDATE, [this]() {
  541. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  542. changeMenu(&confirmMenu);
  543. });
  544. // Confirm SD update menu
  545. confirmMenu.parentMenu = &whichUpdateMenu;
  546. addNodes(&confirmMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  547. changeMenu(confirmMenu.parentMenu);
  548. });
  549. //addNodes(&confirmMenu, "Yes", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); sd_obj.runUpdate();});
  550. addNodes(&confirmMenu, "Yes", TFT_ORANGE, NULL, UPDATE, [this]() {
  551. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  552. changeMenu(&failedUpdateMenu);
  553. sd_obj.runUpdate();
  554. });
  555. // Web Update
  556. updateMenu.parentMenu = &deviceMenu;
  557. addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  558. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  559. changeMenu(updateMenu.parentMenu);
  560. WiFi.softAPdisconnect(true);
  561. web_obj.shutdownServer();
  562. });
  563. //addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu);});
  564. // Failed update menu
  565. failedUpdateMenu.parentMenu = &whichUpdateMenu;
  566. addNodes(&failedUpdateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  567. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  568. changeMenu(failedUpdateMenu.parentMenu);
  569. });
  570. // Device info menu
  571. infoMenu.parentMenu = &deviceMenu;
  572. addNodes(&infoMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  573. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  574. changeMenu(infoMenu.parentMenu);
  575. });
  576. // Set the current menu to the mainMenu
  577. changeMenu(&mainMenu);
  578. this->initTime = millis();
  579. }
  580. // Function to change menu
  581. void MenuFunctions::changeMenu(Menu * menu)
  582. {
  583. display_obj.initScrollValues();
  584. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  585. display_obj.tft.init();
  586. current_menu = menu;
  587. buildButtons(menu);
  588. displayCurrentMenu();
  589. }
  590. // Function to show all MenuNodes in a Menu
  591. void MenuFunctions::showMenuList(Menu * menu, int layer)
  592. {
  593. // Iterate through all of the menu nodes in the menu
  594. for (int i = 0; i < menu->list->size(); i++)
  595. {
  596. // Depending on layer, indent
  597. for (int x = 0; x < layer * 4; x++)
  598. Serial.print(" ");
  599. Serial.print("Node: ");
  600. Serial.println(menu->list->get(i).name);
  601. // If the current menu node points to another menu, list that menu
  602. //if (menu->list->get(i).childMenu != NULL)
  603. // showMenuList(menu->list->get(i).childMenu, layer+1);
  604. }
  605. Serial.println();
  606. }
  607. // Function to add MenuNodes to a menu
  608. void MenuFunctions::addNodes(Menu * menu, String name, uint16_t color, Menu * child, int place, std::function<void()> callable)
  609. {
  610. TFT_eSPI_Button new_button;
  611. menu->list->add(MenuNode{name, color, place, &new_button, callable});
  612. //strcpy(menu->list->get(-1).icon, bluetooth_icon);
  613. }
  614. void MenuFunctions::buildButtons(Menu * menu)
  615. {
  616. Serial.println("Bulding buttons...");
  617. if (menu->list != NULL)
  618. {
  619. //for (int i = 0; i < sizeof(key); i++)
  620. // key[i] = NULL;
  621. for (int i = 0; i < menu->list->size(); i++)
  622. {
  623. TFT_eSPI_Button new_button;
  624. char buf[menu->list->get(i).name.length() + 1] = {};
  625. menu->list->get(i).name.toCharArray(buf, menu->list->get(i).name.length() + 1);
  626. display_obj.key[i].initButton(&display_obj.tft,
  627. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  628. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  629. KEY_W,
  630. KEY_H,
  631. TFT_BLACK, // Outline
  632. TFT_BLACK, // Fill
  633. menu->list->get(i).color, // Text
  634. buf,
  635. KEY_TEXTSIZE);
  636. display_obj.key[i].setLabelDatum(BUTTON_PADDING - (KEY_W / 2), 2, ML_DATUM);
  637. }
  638. }
  639. }
  640. void MenuFunctions::displayCurrentMenu()
  641. {
  642. Serial.println("Displaying current menu...");
  643. display_obj.clearScreen();
  644. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  645. this->drawStatusBar();
  646. //display_obj.tft.fillRect(0,0,240,16, TFT_DARKGREY);
  647. //display_obj.tft.drawCentreString(" ESP32 Marauder ",120,0,2);
  648. //Serial.println("Getting size...");
  649. //char buf[&current_menu->parentMenu->name.length() + 1] = {};
  650. //Serial.println("Got size...");
  651. //current_menu->parentMenu->name.toCharArray(buf, current_menu->parentMenu->name.length() + 1);
  652. //String current_name = &current_menu->parentMenu->name;
  653. //Serial.println("gottem");
  654. //display_obj.tft.drawCentreString(current_menu->name,120,0,2);
  655. if (current_menu->list != NULL)
  656. {
  657. display_obj.tft.setFreeFont(MENU_FONT);
  658. for (int i = 0; i < current_menu->list->size(); i++)
  659. {
  660. //display_obj.key[i].drawButton2(current_menu->list->get(i).name);
  661. //display_obj.key[i].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(i).name);
  662. //display_obj.key[i].drawButton(true);
  663. display_obj.key[i].drawButton(false, current_menu->list->get(i).name);
  664. if (current_menu->list->get(i).name != "Back")
  665. display_obj.tft.drawXBitmap(0,
  666. KEY_Y + i * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  667. menu_icons[current_menu->list->get(i).icon],
  668. ICON_W,
  669. ICON_H,
  670. TFT_BLACK,
  671. current_menu->list->get(i).color);
  672. }
  673. display_obj.tft.setFreeFont(NULL);
  674. }
  675. }