Skip to content

Commit

Permalink
Move save files menu and add save/load airtags
Browse files Browse the repository at this point in the history
  • Loading branch information
justcallmekoko committed Dec 14, 2024
1 parent 0ab6d5c commit 006e750
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 45 deletions.
114 changes: 69 additions & 45 deletions esp32_marauder/MenuFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,8 @@ void MenuFunctions::RunSetup()
loadSSIDsMenu.list = new LinkedList<MenuNode>();
saveAPsMenu.list = new LinkedList<MenuNode>();
loadAPsMenu.list = new LinkedList<MenuNode>();
saveATsMenu.list = new LinkedList<MenuNode>();
loadATsMenu.list = new LinkedList<MenuNode>();

// Work menu names
mainMenu.name = text_table1[6];
Expand All @@ -1453,6 +1455,9 @@ void MenuFunctions::RunSetup()
loadSSIDsMenu.name = "Load SSIDs";
saveAPsMenu.name = "Save APs";
loadAPsMenu.name = "Load APs";
saveATsMenu.name = "Save Airtags";
loadATsMenu.name = "Load Airtags";

bluetoothSnifferMenu.name = text_table1[23];
bluetoothAttackMenu.name = "Bluetooth Attacks";
generateSSIDsMenu.name = text_table1[27];
Expand Down Expand Up @@ -1660,9 +1665,6 @@ void MenuFunctions::RunSetup()
this->changeMenu(&generateSSIDsMenu);
wifi_scan_obj.RunGenerateSSIDs();
});
this->addNodes(&wifiGeneralMenu, "Save/Load Files", TFT_CYAN, NULL, SD_UPDATE, [this]() {
this->changeMenu(&saveFileMenu);
});
#ifdef HAS_ILI9341
this->addNodes(&wifiGeneralMenu, text_table1[1], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
display_obj.clearScreen();
Expand Down Expand Up @@ -1929,48 +1931,6 @@ 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
this->addNodes(&bluetoothMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
Expand Down Expand Up @@ -2131,6 +2091,10 @@ void MenuFunctions::RunSetup()
this->changeMenu(&whichUpdateMenu);
});

this->addNodes(&deviceMenu, "Save/Load Files", TFT_CYAN, NULL, SD_UPDATE, [this]() {
this->changeMenu(&saveFileMenu);
});

this->addNodes(&deviceMenu, text_table1[16], TFT_GREEN, NULL, LANGUAGE, [this]() {

wifi_scan_obj.currentScanMode = SHOW_INFO;
Expand Down Expand Up @@ -2236,6 +2200,66 @@ void MenuFunctions::RunSetup()
#endif
#endif

// Save Files Menu
saveFileMenu.parentMenu = &deviceMenu;
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();
});
this->addNodes(&saveFileMenu, "Save Airtags", TFT_WHITE, NULL, SD_UPDATE, [this]() {
this->changeMenu(&saveAPsMenu);
wifi_scan_obj.RunSaveATList();
});
this->addNodes(&saveFileMenu, "Load Airtags", TFT_WHITE, NULL, SD_UPDATE, [this]() {
this->changeMenu(&loadAPsMenu);
wifi_scan_obj.RunLoadATList();
});

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);
});

saveATsMenu.parentMenu = &saveFileMenu;
this->addNodes(&saveATsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
this->changeMenu(saveATsMenu.parentMenu);
});

loadATsMenu.parentMenu = &saveFileMenu;
this->addNodes(&loadATsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
this->changeMenu(loadATsMenu.parentMenu);
});

// GPS Menu
#ifdef HAS_GPS
if (gps_obj.getGpsModuleStatus()) {
Expand Down
2 changes: 2 additions & 0 deletions esp32_marauder/MenuFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ class MenuFunctions
Menu loadSSIDsMenu;
Menu saveAPsMenu;
Menu loadAPsMenu;
Menu saveATsMenu;
Menu loadATsMenu;

#ifdef HAS_GPS
// GPS Menu
Expand Down
105 changes: 105 additions & 0 deletions esp32_marauder/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,111 @@ void WiFiScan::parseBSSID(const char* bssidStr, uint8_t* bssid) {
&bssid[3], &bssid[4], &bssid[5]);
}

void WiFiScan::RunLoadATList() {
#ifdef HAS_SD
// Prepare to access the file
File file = sd_obj.getFile("/Airtags_0.log");
if (!file) {
Serial.println("Could not open /Airtags_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 /Airtags_0.log");
#endif
return;
}

// Prepare JSON
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<JsonArray>();
for (JsonObject obj : array) {
AirTag at;
at.mac = obj["mac"].as<String>();
at.payloadSize = obj["payload_size"];
at.payload = hexStringToByteArray(obj["payload"].as<String>());
at.selected = false;
airtags->add(at);
}

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 Airtags: ");
display_obj.tft.println((String)airtags->size());
#endif
Serial.print("Loaded Airtags:");
Serial.println((String)airtags->size());
#endif
}

void WiFiScan::RunSaveATList(bool save_as) {
if (save_as) {
sd_obj.removeFile("/Airtags_0.log");

this->startLog("Airtags");

DynamicJsonDocument jsonDocument(2048);

JsonArray jsonArray = jsonDocument.to<JsonArray>();

for (int i = 0; i < airtags->size(); i++) {
const AirTag& at = airtags->get(i);
JsonObject jsonAt = jsonArray.createNestedObject();
jsonAt["mac"] = at.mac;
jsonAt["payload"] = byteArrayToHexString(at.payload);
jsonAt["payload_size"] = at.payloadSize;
}

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 Airtags: ");
display_obj.tft.println((String)airtags->size());
#endif
Serial.print("Saved Airtags:");
Serial.println((String)airtags->size());
}
}

void WiFiScan::RunLoadAPList() {
#ifdef HAS_SD
File file = sd_obj.getFile("/APs_0.log");
Expand Down
2 changes: 2 additions & 0 deletions esp32_marauder/WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ class WiFiScan
void RunLoadSSIDList();
void RunSaveAPList(bool save_as = true);
void RunLoadAPList();
void RunSaveATList(bool save_as = true);
void RunLoadATList();
void channelHop();
uint8_t currentScanMode = 0;
void main(uint32_t currentTime);
Expand Down
51 changes: 51 additions & 0 deletions esp32_marauder/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define utils_h

#include <Arduino.h>
#include <vector>

struct mac_addr {
unsigned char bytes[6];
Expand All @@ -13,6 +14,56 @@ struct Station {
bool selected;
};

String byteArrayToHexString(const std::vector<uint8_t>& byteArray) {
String result;

for (size_t i = 0; i < byteArray.size(); i++) {
// Append the byte in "0xXX" format
result += "0x";
if (byteArray[i] < 0x10) {
result += "0"; // Add leading zero for single-digit hex values
}
result += String(byteArray[i], HEX);

// Add a space between bytes, but not at the end
if (i < byteArray.size() - 1) {
result += " ";
}
}

return result;
}

std::vector<uint8_t> hexStringToByteArray(const String& hexString) {
std::vector<uint8_t> byteArray;

// Split the input string by spaces
int startIndex = 0;
while (startIndex < hexString.length()) {
// Find the next space or end of string
int spaceIndex = hexString.indexOf(' ', startIndex);

// If no space is found, process the last token
if (spaceIndex == -1) {
spaceIndex = hexString.length();
}

// Extract the "0xXX" part
String byteString = hexString.substring(startIndex, spaceIndex);

// Convert "0xXX" to an integer and store it in the vector
if (byteString.startsWith("0x") || byteString.startsWith("0X")) {
uint8_t byte = strtol(byteString.c_str() + 2, nullptr, 16);
byteArray.push_back(byte);
}

// Move the start index to the next byte
startIndex = spaceIndex + 1;
}

return byteArray;
}

void generateRandomName(char *name, size_t length) {
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz";

Expand Down

0 comments on commit 006e750

Please sign in to comment.