MenuFunctions.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. #include "MenuFunctions.h"
  2. //#include "icons.h"
  3. PROGMEM const unsigned char menu_icons[][66] = {
  4. {0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x37, 0xFF, 0xFF, 0x3A, // Attack: 0
  5. 0xFF, 0xFF, 0x39, 0xFF, 0xBF, 0x3C, 0xFF, 0x7F, 0x3E, 0xFF, 0x2F, 0x3F,
  6. 0xFF, 0x9F, 0x3F, 0xFF, 0xCB, 0x3F, 0xFF, 0xE7, 0x3F, 0xCF, 0xF2, 0x3F,
  7. 0xDF, 0xF9, 0x3F, 0xBF, 0xFC, 0x3F, 0x3F, 0xFF, 0x3F, 0x7F, 0xFE, 0x3F,
  8. 0xDF, 0xF9, 0x3F, 0xCF, 0xFB, 0x3F, 0xE7, 0xFF, 0x3F, 0xF3, 0xFF, 0x3F,
  9. 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F},
  10. {0xBF, 0xDD, 0x3E, 0xDF, 0xBE, 0x3D, 0x5F, 0x6B, 0x3D, 0x5F, 0x5D, 0x3D, // Beacon sniff: 1
  11. 0x5F, 0x55, 0x3D, 0xFF, 0xF7, 0x3F, 0xFF, 0xF7, 0x3F, 0xFF, 0xEB, 0x3F,
  12. 0xFF, 0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F, 0x3F, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F, // WiFi: 11
  71. 0x7F, 0x80, 0x3F, 0x9F, 0x7F, 0x3E, 0xE7, 0xFF, 0x39, 0xFB, 0xFF, 0x37,
  72. 0xFF, 0xC0, 0x3F, 0x1F, 0x3F, 0x3E, 0xEF, 0xFF, 0x3D, 0xFF, 0xFF, 0x3F,
  73. 0xFF, 0xE1, 0x3F, 0x7F, 0x9E, 0x3F, 0xBF, 0x7F, 0x3F, 0xFF, 0xFF, 0x3F,
  74. 0xFF, 0xF3, 0x3F, 0xFF, 0xF3, 0x3F, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F,
  75. 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F}};
  76. MenuFunctions::MenuFunctions()
  77. {
  78. }
  79. // Function to check menu input
  80. void MenuFunctions::main()
  81. {
  82. if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) {
  83. if (wifi_scan_obj.orient_display) {
  84. this->orientDisplay();
  85. wifi_scan_obj.orient_display = false;
  86. }
  87. display_obj.updateBanner(current_menu->name);
  88. }
  89. //this->displayCurrentMenu();
  90. boolean pressed = false;
  91. // This is code from bodmer's keypad example
  92. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  93. // Get the display buffer out of the way
  94. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
  95. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  96. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  97. display_obj.displayBuffer();
  98. // Pressed will be set true is there is a valid touch on the screen
  99. int pre_getTouch = millis();
  100. // getTouch causes a 10ms delay which makes beacon spam less effective
  101. //if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF)
  102. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  103. //boolean pressed = false;
  104. //Serial.print("getTouch: ");
  105. //Serial.print(millis() - pre_getTouch);
  106. //Serial.println("ms");
  107. // This is if there are scans/attacks going on
  108. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) && (pressed))
  109. {
  110. // Stop the current scan
  111. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  112. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  113. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ST) ||
  114. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  115. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  116. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  117. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  118. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  119. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  120. {
  121. Serial.println("Stopping scan...");
  122. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  123. // If we don't do this, the text and button coordinates will be off
  124. display_obj.tft.init();
  125. // Take us back to the menu
  126. changeMenu(current_menu);
  127. }
  128. x = -1;
  129. y = -1;
  130. return;
  131. }
  132. // Check if any key coordinate boxes contain the touch coordinates
  133. // This is for when on a menu
  134. if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  135. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  136. {
  137. // Need this to set all keys to false
  138. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  139. if (pressed && display_obj.key[b].contains(t_x, t_y)) {
  140. display_obj.key[b].press(true); // tell the button it is pressed
  141. } else {
  142. display_obj.key[b].press(false); // tell the button it is NOT pressed
  143. }
  144. }
  145. // Check if any key has changed state
  146. for (uint8_t b = 0; b < current_menu->list->size(); b++) {
  147. display_obj.tft.setFreeFont(MENU_FONT);
  148. if (display_obj.key[b].justPressed()) {
  149. display_obj.key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert
  150. }
  151. // If button was just release, execute the button's function
  152. if (display_obj.key[b].justReleased())
  153. {
  154. display_obj.key[b].drawButton2(current_menu->list->get(b).name); // draw normal
  155. current_menu->list->get(b).callable();
  156. }
  157. display_obj.tft.setFreeFont(NULL);
  158. }
  159. }
  160. x = -1;
  161. y = -1;
  162. }
  163. void MenuFunctions::orientDisplay()
  164. {
  165. display_obj.tft.init();
  166. display_obj.tft.setRotation(0); // Portrait
  167. display_obj.tft.setCursor(0, 0);
  168. uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait
  169. display_obj.tft.setTouch(calData);
  170. //display_obj.clearScreen();
  171. changeMenu(current_menu);
  172. }
  173. // Function to build the menus
  174. void MenuFunctions::RunSetup()
  175. {
  176. // root menu stuff
  177. mainMenu.list = new SimpleList<MenuNode>(); // Get list in first menu ready
  178. // Main menu stuff
  179. wifiMenu.list = new SimpleList<MenuNode>(); // Get list in second menu ready
  180. bluetoothMenu.list = new SimpleList<MenuNode>(); // Get list in third menu ready
  181. generalMenu.list = new SimpleList<MenuNode>();
  182. // WiFi menu stuff
  183. wifiSnifferMenu.list = new SimpleList<MenuNode>();
  184. wifiScannerMenu.list = new SimpleList<MenuNode>();
  185. wifiAttackMenu.list = new SimpleList<MenuNode>();
  186. // Bluetooth menu stuff
  187. bluetoothSnifferMenu.list = new SimpleList<MenuNode>();
  188. bluetoothScannerMenu.list = new SimpleList<MenuNode>();
  189. // Work menu names
  190. mainMenu.name = " ESP32 Marauder ";
  191. wifiMenu.name = " WiFi ";
  192. generalMenu.name = " General Apps ";
  193. bluetoothMenu.name = " Bluetooth ";
  194. wifiSnifferMenu.name = " WiFi Sniffers ";
  195. wifiScannerMenu.name = " WiFi Scanners";
  196. wifiAttackMenu.name = " WiFi Attacks ";
  197. bluetoothSnifferMenu.name = " Bluetooth Sniffers ";
  198. bluetoothScannerMenu.name = " Bluetooth Scanners ";
  199. // Build Main Menu
  200. mainMenu.parentMenu = NULL;
  201. addNodes(&mainMenu, "WiFi", TFT_GREEN, NULL, WIFI, [this](){changeMenu(&wifiMenu);});
  202. addNodes(&mainMenu, "Bluetooth", TFT_CYAN, NULL, BLUETOOTH, [this](){changeMenu(&bluetoothMenu);});
  203. addNodes(&mainMenu, "General Apps", TFT_MAGENTA, NULL, ATTACKS, [this](){changeMenu(&generalMenu);});
  204. addNodes(&mainMenu, "Reboot", TFT_LIGHTGREY, NULL, SCANNERS, [](){ESP.restart();});
  205. // Build WiFi Menu
  206. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  207. addNodes(&wifiMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiMenu.parentMenu);});
  208. addNodes(&wifiMenu, "Sniffers", TFT_YELLOW, NULL, SNIFFERS, [this](){changeMenu(&wifiSnifferMenu);});
  209. addNodes(&wifiMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this](){changeMenu(&wifiScannerMenu);});
  210. addNodes(&wifiMenu, "Attacks", TFT_RED, NULL, ATTACKS, [this](){changeMenu(&wifiAttackMenu);});
  211. // Build WiFi sniffer Menu
  212. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  213. addNodes(&wifiSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiSnifferMenu.parentMenu);});
  214. addNodes(&wifiSnifferMenu, "Probe Request Sniff", TFT_CYAN, NULL, PROBE_SNIFF, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);});
  215. addNodes(&wifiSnifferMenu, "Beacon Sniff", TFT_MAGENTA, NULL, BEACON_SNIFF, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);});
  216. addNodes(&wifiSnifferMenu, "Deauth Sniff", TFT_RED, NULL, DEAUTH_SNIFF, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_DEAUTH, TFT_RED);});
  217. // Build WiFi scanner Menu
  218. wifiScannerMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  219. addNodes(&wifiScannerMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiScannerMenu.parentMenu);});
  220. addNodes(&wifiScannerMenu, "Packet Monitor", TFT_BLUE, NULL, PACKET_MONITOR, [this](){wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);});
  221. // Build WiFi attack menu
  222. wifiAttackMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  223. addNodes(&wifiAttackMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiAttackMenu.parentMenu);});
  224. addNodes(&wifiAttackMenu, "Beacon Spam Random", TFT_ORANGE, NULL, ATTACKS, [this](){wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);});
  225. addNodes(&wifiAttackMenu, "Rick Roll Beacon", TFT_YELLOW, NULL, ATTACKS, [this](){wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);});
  226. // Build Bluetooth Menu
  227. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  228. addNodes(&bluetoothMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(bluetoothMenu.parentMenu);});
  229. addNodes(&bluetoothMenu, "Sniffers", TFT_YELLOW, NULL, SNIFFERS, [this](){changeMenu(&bluetoothSnifferMenu);});
  230. addNodes(&bluetoothMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this](){changeMenu(&bluetoothScannerMenu);});
  231. // Build bluetooth sniffer Menu
  232. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  233. addNodes(&bluetoothSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(bluetoothSnifferMenu.parentMenu);});
  234. addNodes(&bluetoothSnifferMenu, "Bluetooth Sniffer", TFT_GREEN, NULL, BLUETOOTH_SNIFF, [this](){wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);});
  235. // Build bluetooth scanner Menu
  236. bluetoothScannerMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  237. addNodes(&bluetoothScannerMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(bluetoothScannerMenu.parentMenu);});
  238. addNodes(&bluetoothScannerMenu, "Detect Card Skimmers", TFT_MAGENTA, NULL, CC_SKIMMERS, [this](){wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);});
  239. generalMenu.parentMenu = &mainMenu;
  240. addNodes(&generalMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){display_obj.draw_tft = false; changeMenu(generalMenu.parentMenu);});
  241. addNodes(&generalMenu, "Draw", TFT_WHITE, NULL, DRAW, [this](){display_obj.clearScreen(); display_obj.draw_tft = true;});
  242. // Set the current menu to the mainMenu
  243. changeMenu(&mainMenu);
  244. }
  245. // Function to change menu
  246. void MenuFunctions::changeMenu(Menu* menu)
  247. {
  248. display_obj.initScrollValues();
  249. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  250. display_obj.tft.init();
  251. current_menu = menu;
  252. buildButtons(menu);
  253. displayCurrentMenu();
  254. }
  255. // Function to show all MenuNodes in a Menu
  256. void MenuFunctions::showMenuList(Menu* menu, int layer)
  257. {
  258. // Iterate through all of the menu nodes in the menu
  259. for (int i = 0; i < menu->list->size(); i++)
  260. {
  261. // Depending on layer, indent
  262. for (int x = 0; x < layer * 4; x++)
  263. Serial.print(" ");
  264. Serial.print("Node: ");
  265. Serial.println(menu->list->get(i).name);
  266. // If the current menu node points to another menu, list that menu
  267. //if (menu->list->get(i).childMenu != NULL)
  268. // showMenuList(menu->list->get(i).childMenu, layer+1);
  269. }
  270. Serial.println();
  271. }
  272. // Function to add MenuNodes to a menu
  273. void MenuFunctions::addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function<void()> callable)
  274. {
  275. TFT_eSPI_Button new_button;
  276. menu->list->add(MenuNode{name, color, place, &new_button, callable});
  277. //strcpy(menu->list->get(-1).icon, bluetooth_icon);
  278. }
  279. void MenuFunctions::buildButtons(Menu* menu)
  280. {
  281. Serial.println("Bulding buttons...");
  282. if (menu->list != NULL)
  283. {
  284. //for (int i = 0; i < sizeof(key); i++)
  285. // key[i] = NULL;
  286. for (int i = 0; i < menu->list->size(); i++)
  287. {
  288. TFT_eSPI_Button new_button;
  289. char buf[menu->list->get(i).name.length() + 1] = {};
  290. menu->list->get(i).name.toCharArray(buf, menu->list->get(i).name.length() + 1);
  291. display_obj.key[i].initButton(&display_obj.tft,
  292. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  293. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  294. KEY_W,
  295. KEY_H,
  296. TFT_BLACK, // Outline
  297. TFT_BLACK, // Fill
  298. menu->list->get(i).color, // Text
  299. buf,
  300. KEY_TEXTSIZE);
  301. }
  302. }
  303. }
  304. void MenuFunctions::displayCurrentMenu()
  305. {
  306. Serial.println("Displaying current menu...");
  307. display_obj.clearScreen();
  308. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  309. //display_obj.tft.fillRect(0,0,240,16, TFT_DARKGREY);
  310. //display_obj.tft.drawCentreString(" ESP32 Marauder ",120,0,2);
  311. //Serial.println("Getting size...");
  312. //char buf[&current_menu->parentMenu->name.length() + 1] = {};
  313. //Serial.println("Got size...");
  314. //current_menu->parentMenu->name.toCharArray(buf, current_menu->parentMenu->name.length() + 1);
  315. //String current_name = &current_menu->parentMenu->name;
  316. //Serial.println("gottem");
  317. //display_obj.tft.drawCentreString(current_menu->name,120,0,2);
  318. if (current_menu->list != NULL)
  319. {
  320. display_obj.tft.setFreeFont(MENU_FONT);
  321. for (int i = 0; i < current_menu->list->size(); i++)
  322. {
  323. display_obj.key[i].drawButton2(current_menu->list->get(i).name);
  324. display_obj.tft.drawXBitmap(0,
  325. KEY_Y + i * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  326. menu_icons[current_menu->list->get(i).icon],
  327. ICON_W,
  328. ICON_H,
  329. TFT_BLACK,
  330. current_menu->list->get(i).color);
  331. }
  332. display_obj.tft.setFreeFont(NULL);
  333. }
  334. }