diff --git a/esp32_marauder/MenuFunctions.cpp b/esp32_marauder/MenuFunctions.cpp index 27d46cc..ae49925 100644 --- a/esp32_marauder/MenuFunctions.cpp +++ b/esp32_marauder/MenuFunctions.cpp @@ -1301,7 +1301,7 @@ void MenuFunctions::RunSetup() wifiSnifferMenu.name = text_table1[20]; wifiAttackMenu.name = text_table1[21]; wifiGeneralMenu.name = text_table1[22]; - saveFileMenu.name = "Save Files"; + saveFileMenu.name = "Save/Load Files"; saveSSIDsMenu.name = "Save SSIDs"; loadSSIDsMenu.name = "Load SSIDs"; saveAPsMenu.name = "Save APs"; @@ -1497,7 +1497,7 @@ void MenuFunctions::RunSetup() this->changeMenu(&generateSSIDsMenu); wifi_scan_obj.RunGenerateSSIDs(); }); - this->addNodes(&wifiGeneralMenu, "Save Files", TFT_CYAN, NULL, SD_UPDATE, [this]() { + this->addNodes(&wifiGeneralMenu, "Save/Load Files", TFT_CYAN, NULL, SD_UPDATE, [this]() { this->changeMenu(&saveFileMenu); }); #ifdef HAS_ILI9341 @@ -1599,48 +1599,6 @@ void MenuFunctions::RunSetup() this->changeMenu(htmlMenu.parentMenu); }); - // Save Files Menu - saveFileMenu.parentMenu = &wifiGeneralMenu; - this->addNodes(&saveFileMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { - this->changeMenu(saveFileMenu.parentMenu); - }); - this->addNodes(&saveFileMenu, "Save SSIDs", TFT_CYAN, NULL, SD_UPDATE, [this]() { - this->changeMenu(&saveSSIDsMenu); - wifi_scan_obj.RunSaveSSIDList(true); - }); - this->addNodes(&saveFileMenu, "Load SSIDs", TFT_SKYBLUE, NULL, SD_UPDATE, [this]() { - this->changeMenu(&loadSSIDsMenu); - wifi_scan_obj.RunLoadSSIDList(); - }); - this->addNodes(&saveFileMenu, "Save APs", TFT_NAVY, NULL, SD_UPDATE, [this]() { - this->changeMenu(&saveAPsMenu); - //wifi_scan_obj.RunLoadSSIDList(); - }); - this->addNodes(&saveFileMenu, "Load APs", TFT_BLUE, NULL, SD_UPDATE, [this]() { - this->changeMenu(&loadAPsMenu); - //wifi_scan_obj.RunLoadSSIDList(); - }); - - saveSSIDsMenu.parentMenu = &saveFileMenu; - this->addNodes(&saveSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { - this->changeMenu(saveSSIDsMenu.parentMenu); - }); - - loadSSIDsMenu.parentMenu = &saveFileMenu; - this->addNodes(&loadSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { - this->changeMenu(loadSSIDsMenu.parentMenu); - }); - - saveAPsMenu.parentMenu = &saveFileMenu; - this->addNodes(&saveAPsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { - this->changeMenu(saveAPsMenu.parentMenu); - }); - - loadAPsMenu.parentMenu = &saveFileMenu; - this->addNodes(&loadAPsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { - this->changeMenu(loadAPsMenu.parentMenu); - }); - // Select APs on Mini this->addNodes(&wifiGeneralMenu, text_table1[56], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){ wifiAPMenu.list->clear(); @@ -1696,6 +1654,47 @@ void MenuFunctions::RunSetup() this->changeMenu(clearAPsMenu.parentMenu); }); + saveSSIDsMenu.parentMenu = &saveFileMenu; + this->addNodes(&saveSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { + this->changeMenu(saveSSIDsMenu.parentMenu); + }); + + loadSSIDsMenu.parentMenu = &saveFileMenu; + this->addNodes(&loadSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { + this->changeMenu(loadSSIDsMenu.parentMenu); + }); + + saveAPsMenu.parentMenu = &saveFileMenu; + this->addNodes(&saveAPsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { + this->changeMenu(saveAPsMenu.parentMenu); + }); + + loadAPsMenu.parentMenu = &saveFileMenu; + this->addNodes(&loadAPsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { + this->changeMenu(loadAPsMenu.parentMenu); + }); + + // Save Files Menu + saveFileMenu.parentMenu = &wifiGeneralMenu; + this->addNodes(&saveFileMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { + this->changeMenu(saveFileMenu.parentMenu); + }); + this->addNodes(&saveFileMenu, "Save SSIDs", TFT_CYAN, NULL, SD_UPDATE, [this]() { + this->changeMenu(&saveSSIDsMenu); + wifi_scan_obj.RunSaveSSIDList(true); + }); + this->addNodes(&saveFileMenu, "Load SSIDs", TFT_SKYBLUE, NULL, SD_UPDATE, [this]() { + this->changeMenu(&loadSSIDsMenu); + wifi_scan_obj.RunLoadSSIDList(); + }); + this->addNodes(&saveFileMenu, "Save APs", TFT_NAVY, NULL, SD_UPDATE, [this]() { + this->changeMenu(&saveAPsMenu); + wifi_scan_obj.RunSaveAPList(); + }); + this->addNodes(&saveFileMenu, "Load APs", TFT_BLUE, NULL, SD_UPDATE, [this]() { + this->changeMenu(&loadAPsMenu); + wifi_scan_obj.RunLoadAPList(); + }); // Build Bluetooth Menu bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index ddbddd9..cf9d9f9 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -952,9 +952,73 @@ void WiFiScan::startLog(String file_name) { ); } +void WiFiScan::parseBSSID(const char* bssidStr, uint8_t* bssid) { + sscanf(bssidStr, "%02X:%02X:%02X:%02X:%02X:%02X", + &bssid[0], &bssid[1], &bssid[2], + &bssid[3], &bssid[4], &bssid[5]); +} + void WiFiScan::RunLoadAPList() { #ifdef HAS_SD + File file = sd_obj.getFile("/APs_0.log"); + if (!file) { + Serial.println("Could not open /APs_0.log"); + #ifdef HAS_SCREEN + display_obj.tft.setTextWrap(false); + display_obj.tft.setFreeFont(NULL); + display_obj.tft.setCursor(0, 100); + display_obj.tft.setTextSize(1); + display_obj.tft.setTextColor(TFT_CYAN); + + display_obj.tft.println("Could not open /APs_0.log"); + #endif + return; + } + DynamicJsonDocument doc(10048); + DeserializationError error = deserializeJson(doc, file); + if (error) { + Serial.print("JSON deserialize error: "); + Serial.println(error.c_str()); + file.close(); + #ifdef HAS_SCREEN + display_obj.tft.setTextWrap(false); + display_obj.tft.setFreeFont(NULL); + display_obj.tft.setCursor(0, 100); + display_obj.tft.setTextSize(1); + display_obj.tft.setTextColor(TFT_CYAN); + + display_obj.tft.println("Could not deserialize JSON"); + display_obj.tft.println(error.c_str()); + #endif + return; + } + + JsonArray array = doc.as(); + for (JsonObject obj : array) { + AccessPoint ap; + ap.essid = obj["essid"].as(); + ap.channel = obj["channel"]; + ap.selected = false; + parseBSSID(obj["bssid"], ap.bssid); + ap.stations = new LinkedList(); + access_points->add(ap); + } + + file.close(); + + //doc.clear(); + + #ifdef HAS_SCREEN + display_obj.tft.setTextWrap(false); + display_obj.tft.setFreeFont(NULL); + display_obj.tft.setCursor(0, 100); + display_obj.tft.setTextSize(1); + display_obj.tft.setTextColor(TFT_CYAN); + + display_obj.tft.print("Loaded APs: "); + display_obj.tft.println((String)access_points->size()); + #endif #endif } @@ -963,6 +1027,39 @@ void WiFiScan::RunSaveAPList(bool save_as) { sd_obj.removeFile("/APs_0.log"); this->startLog("APs"); + + DynamicJsonDocument jsonDocument(2048); + + JsonArray jsonArray = jsonDocument.to(); + + for (int i = 0; i < access_points->size(); i++) { + const AccessPoint& ap = access_points->get(i); + JsonObject jsonAp = jsonArray.createNestedObject(); + jsonAp["essid"] = ap.essid; + jsonAp["channel"] = ap.channel; + + char bssidStr[18]; + sprintf(bssidStr, "%02X:%02X:%02X:%02X:%02X:%02X", + ap.bssid[0], ap.bssid[1], ap.bssid[2], + ap.bssid[3], ap.bssid[4], ap.bssid[5]); + jsonAp["bssid"] = bssidStr; + } + + String jsonString; + serializeJson(jsonArray, jsonString); + + buffer_obj.append(jsonString); + + #ifdef HAS_SCREEN + display_obj.tft.setTextWrap(false); + display_obj.tft.setFreeFont(NULL); + display_obj.tft.setCursor(0, 100); + display_obj.tft.setTextSize(1); + display_obj.tft.setTextColor(TFT_CYAN); + + display_obj.tft.print("Saved APs: "); + display_obj.tft.println((String)access_points->size()); + #endif } } diff --git a/esp32_marauder/WiFiScan.h b/esp32_marauder/WiFiScan.h index 46723b4..b614553 100644 --- a/esp32_marauder/WiFiScan.h +++ b/esp32_marauder/WiFiScan.h @@ -331,6 +331,7 @@ class WiFiScan void RunLvJoinWiFi(uint8_t scan_mode, uint16_t color); void RunEvilPortal(uint8_t scan_mode, uint16_t color); bool checkMem(); + void parseBSSID(const char* bssidStr, uint8_t* bssid); public: