MenuFunctions.cpp 28 KB

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