MenuFunctions.cpp 9.0 KB

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