MenuFunctions.cpp 14 KB

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