MenuFunctions.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #include "MenuFunctions.h"
  2. MenuFunctions::MenuFunctions()
  3. {
  4. }
  5. // Function to check menu input
  6. void MenuFunctions::main()
  7. {
  8. boolean pressed = false;
  9. // This is code from bodmer's keypad example
  10. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  11. // Get the display buffer out of the way
  12. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
  13. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM))
  14. display_obj.displayBuffer();
  15. // Pressed will be set true is there is a valid touch on the screen
  16. int pre_getTouch = millis();
  17. // getTouch causes a 10ms delay which makes beacon spam less effective
  18. //if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF)
  19. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  20. //boolean pressed = false;
  21. //Serial.print("getTouch: ");
  22. //Serial.print(millis() - pre_getTouch);
  23. //Serial.println("ms");
  24. // This is if there are scans/attacks going on
  25. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) && (pressed))
  26. {
  27. // Stop the current scan
  28. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  29. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  30. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ST) ||
  31. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  32. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  33. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  34. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  35. {
  36. Serial.println("Stopping scan...");
  37. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  38. // If we don't do this, the text and button coordinates will be off
  39. display_obj.tft.init();
  40. // Take us back to the menu
  41. changeMenu(current_menu);
  42. }
  43. x = -1;
  44. y = -1;
  45. return;
  46. }
  47. // Check if any key coordinate boxes contain the touch coordinates
  48. // This is for when on a menu
  49. if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM))
  50. {
  51. // Need this to set all keys to false
  52. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  53. if (pressed && key[b].contains(t_x, t_y)) {
  54. key[b].press(true); // tell the button it is pressed
  55. } else {
  56. key[b].press(false); // tell the button it is NOT pressed
  57. }
  58. }
  59. // Check if any key has changed state
  60. for (uint8_t b = 0; b < current_menu->list->size(); b++) {
  61. display_obj.tft.setFreeFont(MENU_FONT);
  62. if (key[b].justPressed()) {
  63. key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert
  64. }
  65. // If button was just release, execute the button's function
  66. if (key[b].justReleased())
  67. {
  68. key[b].drawButton2(current_menu->list->get(b).name); // draw normal
  69. current_menu->list->get(b).callable();
  70. }
  71. display_obj.tft.setFreeFont(NULL);
  72. }
  73. }
  74. x = -1;
  75. y = -1;
  76. }
  77. // Function to build the menus
  78. void MenuFunctions::RunSetup()
  79. {
  80. // Main menu stuff
  81. mainMenu.list = new SimpleList<MenuNode>(); // Get list in first menu ready
  82. wifiMenu.list = new SimpleList<MenuNode>(); // Get list in second menu ready
  83. bluetoothMenu.list = new SimpleList<MenuNode>(); // Get list in third menu ready
  84. // WiFi menu stuff
  85. wifiSnifferMenu.list = new SimpleList<MenuNode>();
  86. wifiScannerMenu.list = new SimpleList<MenuNode>();
  87. wifiAttackMenu.list = new SimpleList<MenuNode>();
  88. // Bluetooth menu stuff
  89. bluetoothSnifferMenu.list = new SimpleList<MenuNode>();
  90. bluetoothScannerMenu.list = new SimpleList<MenuNode>();
  91. // Work menu names
  92. mainMenu.name = " ESP32 Marauder ";
  93. wifiMenu.name = " WiFi ";
  94. bluetoothMenu.name = " Bluetooth ";
  95. wifiSnifferMenu.name = " WiFi Sniffers ";
  96. wifiScannerMenu.name = " WiFi Scanners";
  97. wifiAttackMenu.name = " WiFi Attacks ";
  98. bluetoothSnifferMenu.name = " Bluetooth Sniffers ";
  99. bluetoothScannerMenu.name = " Bluetooth Scanners ";
  100. // Build Main Menu
  101. mainMenu.parentMenu = NULL;
  102. addNodes(&mainMenu, "WiFi", TFT_GREEN, NULL, 0, [this](){changeMenu(&wifiMenu);});
  103. addNodes(&mainMenu, "Bluetooth", TFT_CYAN, NULL, 1, [this](){changeMenu(&bluetoothMenu);});
  104. addNodes(&mainMenu, "Reboot", TFT_LIGHTGREY, NULL, 2, [](){ESP.restart();});
  105. // Build WiFi Menu
  106. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  107. addNodes(&wifiMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(wifiMenu.parentMenu);});
  108. addNodes(&wifiMenu, "Sniffers", TFT_LIGHTGREY, NULL, 1, [this](){changeMenu(&wifiSnifferMenu);});
  109. addNodes(&wifiMenu, "Scanners", TFT_YELLOW, NULL, 1, [this](){changeMenu(&wifiScannerMenu);});
  110. addNodes(&wifiMenu, "Attacks", TFT_ORANGE, NULL, 1, [this](){changeMenu(&wifiAttackMenu);});
  111. // Build WiFi sniffer Menu
  112. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  113. addNodes(&wifiSnifferMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(wifiSnifferMenu.parentMenu);});
  114. addNodes(&wifiSnifferMenu, "Probe Request Sniff", TFT_CYAN, NULL, 2, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);});
  115. addNodes(&wifiSnifferMenu, "Beacon Sniff", TFT_MAGENTA, NULL, 3, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);});
  116. // Build WiFi scanner Menu
  117. wifiScannerMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  118. addNodes(&wifiScannerMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(wifiScannerMenu.parentMenu);});
  119. // Build WiFi attack menu
  120. wifiAttackMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  121. addNodes(&wifiAttackMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(wifiAttackMenu.parentMenu);});
  122. addNodes(&wifiAttackMenu, "Beacon Spam Random", TFT_ORANGE, NULL, 1, [this](){wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);});
  123. // Build Bluetooth Menu
  124. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  125. addNodes(&bluetoothMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(bluetoothMenu.parentMenu);});
  126. addNodes(&bluetoothMenu, "Sniffers", TFT_LIGHTGREY, NULL, 1, [this](){changeMenu(&bluetoothSnifferMenu);});
  127. addNodes(&bluetoothMenu, "Scanners", TFT_YELLOW, NULL, 1, [this](){changeMenu(&bluetoothScannerMenu);});
  128. // Build bluetooth sniffer Menu
  129. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  130. addNodes(&bluetoothSnifferMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(bluetoothSnifferMenu.parentMenu);});
  131. addNodes(&bluetoothSnifferMenu, "Bluetooth Sniffer", TFT_GREEN, NULL, 1, [this](){wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);});
  132. // Build bluetooth scanner Menu
  133. bluetoothScannerMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  134. addNodes(&bluetoothScannerMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(bluetoothScannerMenu.parentMenu);});
  135. addNodes(&bluetoothScannerMenu, "Detect Card Skimmers", TFT_MAGENTA, NULL, 2, [this](){wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);});
  136. // Set the current menu to the mainMenu
  137. changeMenu(&mainMenu);
  138. }
  139. // Function to change menu
  140. void MenuFunctions::changeMenu(Menu* menu)
  141. {
  142. display_obj.initScrollValues();
  143. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  144. display_obj.tft.init();
  145. current_menu = menu;
  146. buildButtons(menu);
  147. displayCurrentMenu();
  148. }
  149. // Function to show all MenuNodes in a Menu
  150. void MenuFunctions::showMenuList(Menu* menu, int layer)
  151. {
  152. // Iterate through all of the menu nodes in the menu
  153. for (int i = 0; i < menu->list->size(); i++)
  154. {
  155. // Depending on layer, indent
  156. for (int x = 0; x < layer * 4; x++)
  157. Serial.print(" ");
  158. Serial.print("Node: ");
  159. Serial.println(menu->list->get(i).name);
  160. // If the current menu node points to another menu, list that menu
  161. if (menu->list->get(i).childMenu != NULL)
  162. showMenuList(menu->list->get(i).childMenu, layer+1);
  163. }
  164. Serial.println();
  165. }
  166. // Function to add MenuNodes to a menu
  167. void MenuFunctions::addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function<void()> callable)
  168. {
  169. TFT_eSPI_Button new_button;
  170. menu->list->add(MenuNode{name, color, child, &new_button, callable});
  171. }
  172. void MenuFunctions::buildButtons(Menu* menu)
  173. {
  174. Serial.println("Bulding buttons...");
  175. if (menu->list != NULL)
  176. {
  177. //for (int i = 0; i < sizeof(key); i++)
  178. // key[i] = NULL;
  179. for (int i = 0; i < menu->list->size(); i++)
  180. {
  181. TFT_eSPI_Button new_button;
  182. char buf[menu->list->get(i).name.length() + 1] = {};
  183. menu->list->get(i).name.toCharArray(buf, menu->list->get(i).name.length() + 1);
  184. key[i].initButton(&display_obj.tft,
  185. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  186. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  187. KEY_W,
  188. KEY_H,
  189. TFT_BLACK, // Outline
  190. TFT_BLACK, // Fill
  191. menu->list->get(i).color, // Text
  192. buf,
  193. KEY_TEXTSIZE);
  194. }
  195. }
  196. }
  197. void MenuFunctions::displayCurrentMenu()
  198. {
  199. Serial.println("Displaying current menu...");
  200. display_obj.clearScreen();
  201. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  202. display_obj.tft.fillRect(0,0,240,16, TFT_DARKGREY);
  203. //display_obj.tft.drawCentreString(" ESP32 Marauder ",120,0,2);
  204. //Serial.println("Getting size...");
  205. //char buf[&current_menu->parentMenu->name.length() + 1] = {};
  206. //Serial.println("Got size...");
  207. //current_menu->parentMenu->name.toCharArray(buf, current_menu->parentMenu->name.length() + 1);
  208. //String current_name = &current_menu->parentMenu->name;
  209. //Serial.println("gottem");
  210. display_obj.tft.drawCentreString(current_menu->name,120,0,2);
  211. if (current_menu->list != NULL)
  212. {
  213. display_obj.tft.setFreeFont(MENU_FONT);
  214. for (int i = 0; i < current_menu->list->size(); i++)
  215. {
  216. key[i].drawButton2(current_menu->list->get(i).name);
  217. }
  218. display_obj.tft.setFreeFont(NULL);
  219. }
  220. }