MenuFunctions.cpp 28 KB

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