mirror of
https://github.com/justcallmekoko/ESP32Marauder.git
synced 2025-12-22 15:16:43 -08:00
* Trims serial input for PuTTY * v0.9.7 Release * Re-release v0.9.7 * add OG-Marauder enclosure (#124) * add Marauder Mini Case and rearrange files * Add OG-Marauder Enclosure * Add more cmd, clean serial, add ascii * Add attack command to CLI * Add SSID commands * print eapol when received * Add more sniff and attack commands * Fix OTA update shutdown via CLI * Add help command * Release v0.9.8 * Add channel arg to pmkid sniff * Add targeted ap beacon spam * Save a beacon packet * AP obfuscation attack * Update README.md * Send deauth for pmkid * PMKID deauth optional * Release v0.9.9 * v0.9.10 Release * Select all and flipper LED * Add screen buffer for mini * Fix screen buffer formatting * packet monitor eapol scan formatting * Release v0.9.11 * Update README.md * Add settings command and SD CS * Release v0.9.12 * Fix mini update menu * Release v0.9.13-rc1 * Fix stopscan and sniffpmkid * fix sniffpmkid SSID visible (#140) * Add rssi and setting reset * Release v0.9.13 * Create build_push.yml * Add libraries * Fix library red * Spelling * Adjust ref for SwitchLib * Add ESP32 Board * Update board fqdn * Specify package version for ESP32 * Add compiler switches * Update compile args * Lib args * Fix multdefs * Update version of arduino test compile * Separate lib install * Jobs together * Fix warnings flag * Add muldefs arg to cli * Update build_push.yml * Specify build property * Full build property string * Fix quote placement * Add find and replace * Update build_push.yml * Update build_push.yml * Update build_push.yml * Cat platform file * Update build_push.yml * Add install boards * Update build_push.yml * Add bash for loop for platform * Update build_push.yml * find and replace * Add muldefs to ESP32 and ESP32S2 * Add display bins * minimal spiffs * Minimal SPIFFS syntax * More Minimal SPIFFS syntax * Add more build params * Add upload artifacts * Add TFT Setup files * Add configure TFT_eSPI * Configure libs and configs * Fix sed file locations * Update build_push.yml * Update build_push.yml * Look for TFT_eSPI * Update start location for find * Update locations of libraries * Fix path to TFT_eSPI * Compile for other platforms * Create draft release * Update README.md * Only allow manual workflow * Fix blank PCAPs * Switch configs * Specify NimBLE 1.2.0 * No "v" in tag * Fix SD card init issues Copy SD lib from arduino-esp32 v2.0.4 to replace SD lib from arduino-esp32 v2.0.0-rc2 * Pull arduino-esp32 v2.0.4 * Replace 2.0.0-rc1 SD lib with 2.0.4 * Fix path * Gramatical (#155) * Add raw cap and manual deauth * Revert to flipper * Change color * Change color again * define white * Update issue templates * Create config.yml * Specify dst mac again * Update README.md * Create .gitignore Co-authored-by: Gregor Hermani <53179565+trisp3ar@users.noreply.github.com> Co-authored-by: improving-rigmarole <17810364+improving-rigmarole@users.noreply.github.com> Co-authored-by: Ayden <butera.ayden@gmail.com>
230 lines
5.9 KiB
C++
230 lines
5.9 KiB
C++
#include "SDInterface.h"
|
|
#include "lang_var.h"
|
|
|
|
bool SDInterface::initSD() {
|
|
String display_string = "";
|
|
|
|
#ifdef KIT
|
|
pinMode(SD_DET, INPUT);
|
|
if (digitalRead(SD_DET) == LOW) {
|
|
Serial.println(F("SD Card Detect Pin Detected"));
|
|
}
|
|
else {
|
|
Serial.println(F("SD Card Detect Pin Not Detected"));
|
|
this->supported = false;
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
pinMode(SD_CS, OUTPUT);
|
|
|
|
delay(10);
|
|
|
|
if (!SD.begin(SD_CS)) {
|
|
Serial.println(F("Failed to mount SD Card"));
|
|
this->supported = false;
|
|
return false;
|
|
}
|
|
else {
|
|
this->supported = true;
|
|
this->cardType = SD.cardType();
|
|
//if (cardType == CARD_MMC)
|
|
// Serial.println(F("SD: MMC Mounted"));
|
|
//else if(cardType == CARD_SD)
|
|
// Serial.println(F("SD: SDSC Mounted"));
|
|
//else if(cardType == CARD_SDHC)
|
|
// Serial.println(F("SD: SDHC Mounted"));
|
|
//else
|
|
// Serial.println(F("SD: UNKNOWN Card Mounted"));
|
|
|
|
this->cardSizeMB = SD.cardSize() / (1024 * 1024);
|
|
|
|
//Serial.printf("SD Card Size: %lluMB\n", this->cardSizeMB);
|
|
|
|
if (this->supported) {
|
|
const int NUM_DIGITS = log10(this->cardSizeMB) + 1;
|
|
|
|
char sz[NUM_DIGITS + 1];
|
|
|
|
sz[NUM_DIGITS] = 0;
|
|
for ( size_t i = NUM_DIGITS; i--; this->cardSizeMB /= 10)
|
|
{
|
|
sz[i] = '0' + (this->cardSizeMB % 10);
|
|
display_string.concat((String)sz[i]);
|
|
}
|
|
|
|
this->card_sz = sz;
|
|
}
|
|
|
|
buffer_obj = Buffer();
|
|
|
|
if (!SD.exists("/SCRIPTS")) {
|
|
Serial.println("/SCRIPTS does not exist. Creating...");
|
|
|
|
SD.mkdir("/SCRIPTS");
|
|
Serial.println("/SCRIPTS created");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
void SDInterface::addPacket(uint8_t* buf, uint32_t len) {
|
|
if ((this->supported) && (this->do_save)) {
|
|
buffer_obj.addPacket(buf, len);
|
|
}
|
|
}
|
|
|
|
void SDInterface::openCapture(String file_name) {
|
|
if (this->supported)
|
|
buffer_obj.open(&SD, file_name);
|
|
}
|
|
|
|
void SDInterface::runUpdate() {
|
|
#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_WHITE);
|
|
|
|
display_obj.tft.println(F(text15));
|
|
#endif
|
|
File updateBin = SD.open("/update.bin");
|
|
if (updateBin) {
|
|
if(updateBin.isDirectory()){
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.setTextColor(TFT_RED);
|
|
display_obj.tft.println(F(text_table2[0]));
|
|
#endif
|
|
Serial.println(F("Error, update.bin is not a file"));
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.setTextColor(TFT_WHITE);
|
|
#endif
|
|
updateBin.close();
|
|
return;
|
|
}
|
|
|
|
size_t updateSize = updateBin.size();
|
|
|
|
if (updateSize > 0) {
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.println(F(text_table2[1]));
|
|
#endif
|
|
Serial.println(F("Try to start update"));
|
|
this->performUpdate(updateBin, updateSize);
|
|
}
|
|
else {
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.setTextColor(TFT_RED);
|
|
display_obj.tft.println(F(text_table2[2]));
|
|
#endif
|
|
Serial.println(F("Error, file is empty"));
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.setTextColor(TFT_WHITE);
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
updateBin.close();
|
|
|
|
// whe finished remove the binary from sd card to indicate end of the process
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.println(F(text_table2[3]));
|
|
#endif
|
|
Serial.println(F("rebooting..."));
|
|
//SD.remove("/update.bin");
|
|
delay(1000);
|
|
ESP.restart();
|
|
}
|
|
else {
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.setTextColor(TFT_RED);
|
|
display_obj.tft.println(F(text_table2[4]));
|
|
#endif
|
|
Serial.println(F("Could not load update.bin from sd root"));
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.setTextColor(TFT_WHITE);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void SDInterface::performUpdate(Stream &updateSource, size_t updateSize) {
|
|
if (Update.begin(updateSize)) {
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.println(text_table2[5] + String(updateSize));
|
|
display_obj.tft.println(F(text_table2[6]));
|
|
#endif
|
|
size_t written = Update.writeStream(updateSource);
|
|
if (written == updateSize) {
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.println(text_table2[7] + String(written) + text_table2[10]);
|
|
#endif
|
|
Serial.println("Written : " + String(written) + " successfully");
|
|
}
|
|
else {
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.println(text_table2[8] + String(written) + "/" + String(updateSize) + text_table2[9]);
|
|
#endif
|
|
Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
|
|
}
|
|
if (Update.end()) {
|
|
Serial.println("OTA done!");
|
|
if (Update.isFinished()) {
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.println(F(text_table2[11]));
|
|
#endif
|
|
Serial.println(F("Update successfully completed. Rebooting."));
|
|
}
|
|
else {
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.setTextColor(TFT_RED);
|
|
display_obj.tft.println(text_table2[12]);
|
|
#endif
|
|
Serial.println("Update not finished? Something went wrong!");
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.setTextColor(TFT_WHITE);
|
|
#endif
|
|
}
|
|
}
|
|
else {
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.println(text_table2[13] + String(Update.getError()));
|
|
#endif
|
|
Serial.println("Error Occurred. Error #: " + String(Update.getError()));
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
#ifdef HAS_SCREEN
|
|
display_obj.tft.println(text_table2[14]);
|
|
#endif
|
|
Serial.println("Not enough space to begin OTA");
|
|
}
|
|
}
|
|
|
|
bool SDInterface::checkDetectPin() {
|
|
#ifdef KIT
|
|
if (digitalRead(SD_DET) == LOW)
|
|
return true;
|
|
else
|
|
return false;
|
|
#endif
|
|
|
|
return false;
|
|
}
|
|
|
|
void SDInterface::main() {
|
|
if ((this->supported) && (this->do_save)) {
|
|
//Serial.println("Saving packet...");
|
|
buffer_obj.forceSave(&SD);
|
|
}
|
|
else if (!this->supported) {
|
|
if (checkDetectPin()) {
|
|
delay(100);
|
|
this->initSD();
|
|
}
|
|
}
|
|
}
|