Skip to content

Commit

Permalink
Merge branch 'enh/wardriving' into feat/main_menu
Browse files Browse the repository at this point in the history
  • Loading branch information
rennancockles committed Aug 29, 2024
2 parents 95c1e44 + 98503a3 commit a99f6c0
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 286 deletions.
70 changes: 48 additions & 22 deletions src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,93 +92,119 @@ void displayWarning(String txt) { displayRedStripe(txt, TFT_BLACK,TFT_YELLOW); }
void displayInfo(String txt) { displayRedStripe(txt, TFT_WHITE, TFT_BLUE); }
void displaySuccess(String txt) { displayRedStripe(txt, TFT_WHITE, TFT_DARKGREEN); }

void setPadCursor(int16_t padx, int16_t pady) {
for (int y=0; y<pady; y++) tft.println();
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
}

void padprintf(int16_t padx, const char *format, ...) {
char buffer[64];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);

tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.printf("%s", buffer);
}
void padprintf(const char *format, ...) {
char buffer[64];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);

tft.setCursor(BORDER_PAD_X, tft.getCursorY());
tft.printf("%s", buffer);
}

void padprint(const String &s, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(s);
}
void padprint(const char str[], int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(str);
}
void padprint(char c, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(c);
}
void padprint(unsigned char b, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(b, base);
}
void padprint(int n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(n, base);
}
void padprint(unsigned int n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(n, base);
}
void padprint(long n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(n, base);
}
void padprint(unsigned long n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(n, base);
}
void padprint(long long n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(n, base);
}
void padprint(unsigned long long n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(n, base);
}
void padprint(double n, int digits, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.print(n, digits);
}

void padprintln(const String &s, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(s);
}
void padprintln(const char str[], int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(str);
}
void padprintln(char c, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(c);
}
void padprintln(unsigned char b, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(b, base);
}
void padprintln(int n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(n, base);
}
void padprintln(unsigned int n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(n, base);
}
void padprintln(long n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(n, base);
}
void padprintln(unsigned long n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(n, base);
}
void padprintln(long long n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(n, base);
}
void padprintln(unsigned long long n, int base, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(n, base);
}
void padprintln(double n, int digits, int16_t padx) {
tft.setCursor(padx, tft.getCursorY());
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(n, digits);
}

Expand Down
50 changes: 28 additions & 22 deletions src/core/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,34 @@ void displayWarning(String txt);// Faixa amarela
void displayInfo(String txt); // Faixa Azul
void displaySuccess(String txt);// Faixa Verde

void padprint(const String &s, int16_t padx=BORDER_PAD_X);
void padprint(const char str[], int16_t padx=BORDER_PAD_X);
void padprint(char c, int16_t padx=BORDER_PAD_X);
void padprint(unsigned char b, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprint(int n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprint(unsigned int n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprint(long n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprint(unsigned long n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprint(long long n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprint(unsigned long long n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprint(double n, int digits, int16_t padx=BORDER_PAD_X);
void padprintln(const String &s, int16_t padx=BORDER_PAD_X);
void padprintln(const char str[], int16_t padx=BORDER_PAD_X);
void padprintln(char c, int16_t padx=BORDER_PAD_X);
void padprintln(unsigned char b, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprintln(int n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprintln(unsigned int n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprintln(long n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprintln(unsigned long n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprintln(long long n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprintln(unsigned long long n, int base=DEC, int16_t padx=BORDER_PAD_X);
void padprintln(double n, int digits, int16_t padx=BORDER_PAD_X);
void setPadCursor(int16_t padx=1, int16_t pady=0);

void padprintf(int16_t padx, const char *format, ...);
void padprintf(const char *format, ...);

void padprint(const String &s, int16_t padx=1);
void padprint(const char str[], int16_t padx=1);
void padprint(char c, int16_t padx=1);
void padprint(unsigned char b, int base=DEC, int16_t padx=1);
void padprint(int n, int base=DEC, int16_t padx=1);
void padprint(unsigned int n, int base=DEC, int16_t padx=1);
void padprint(long n, int base=DEC, int16_t padx=1);
void padprint(unsigned long n, int base=DEC, int16_t padx=1);
void padprint(long long n, int base=DEC, int16_t padx=1);
void padprint(unsigned long long n, int base=DEC, int16_t padx=1);
void padprint(double n, int digits, int16_t padx=1);

void padprintln(const String &s, int16_t padx=1);
void padprintln(const char str[], int16_t padx=1);
void padprintln(char c, int16_t padx=1);
void padprintln(unsigned char b, int base=DEC, int16_t padx=1);
void padprintln(int n, int base=DEC, int16_t padx=1);
void padprintln(unsigned int n, int base=DEC, int16_t padx=1);
void padprintln(long n, int base=DEC, int16_t padx=1);
void padprintln(unsigned long n, int base=DEC, int16_t padx=1);
void padprintln(long long n, int base=DEC, int16_t padx=1);
void padprintln(unsigned long long n, int base=DEC, int16_t padx=1);
void padprintln(double n, int digits, int16_t padx=1);

//loopOptions will now return the last index used in the function
int loopOptions(std::vector<Option>& options, bool bright, bool submenu, String subText,int index = 0);
Expand Down
2 changes: 1 addition & 1 deletion src/core/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void wifiOptions() {
};
}
options.push_back({"Wifi Atks", [=]() { wifi_atk_menu(); }});
options.push_back({"Wardriving", [=]() { wardriving_setup(); }});
options.push_back({"Wardriving", [=]() { Wardriving(); }});
#ifndef LITE_VERSION
options.push_back({"TelNET", [=]() { telnet_setup(); }});
options.push_back({"SSH", [=]() { ssh_setup(); }});
Expand Down
53 changes: 32 additions & 21 deletions src/core/sd_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ String readSmallFile(FS &fs, String filepath) {
Serial.println("File is too big");
return "";
}

fileContent = file.readString();

file.close();
Expand All @@ -321,8 +321,8 @@ String readSmallFile(FS &fs, String filepath) {
size_t getFileSize(FS &fs, String filepath) {
/*
#if !defined(M5STACK)
if(&fs == &SD) filepath = "/sd" + filepath;
else if(&fs == &LittleFS) filepath = "/littlefs" + filepath;
if(&fs == &SD) filepath = "/sd" + filepath;
else if(&fs == &LittleFS) filepath = "/littlefs" + filepath;
else return 0; // not found
struct stat st;
memset(&st, 0, sizeof(struct stat));
Expand Down Expand Up @@ -358,35 +358,35 @@ String readDecryptedAesFile(FS &fs, String filepath) {
displayError("File is too big");
return "";
}

char buffer[fileSize];
size_t bytesRead = file.readBytes(buffer, fileSize);
//Serial.print("fileSize:");
//Serial.println(fileSize);
//Serial.println(bytesRead);

/*
// read the whole file with a single call
char buffer[fileSize + 1];
size_t bytesRead = file.readBytes(buffer, fileSize);
buffer[bytesRead] = '\0'; // Null-terminate the string
return String(buffer);
*/

if (bytesRead==0) {
Serial.println("empty cypherText");
return "";
}
// else

if(cachedPassword.length()==0) {
cachedPassword = keyboard("", 32, "password");
if(cachedPassword.length()==0) return ""; // cancelled
}

// else try to decrypt
String plaintext = aes_decrypt((uint8_t*)buffer, bytesRead, cachedPassword);

// check if really plaintext
if(!is_valid_ascii(plaintext)) {
// invalidate cached password -> will ask again on the next try
Expand Down Expand Up @@ -644,23 +644,23 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
if(&fs == &LittleFS && sdcardMounted) options.push_back({"Copy->SD", [=]() { copyToFs(LittleFS, SD, filepath); }});

// custom file formats commands added in front
if(filepath.endsWith(".ir")) options.insert(options.begin(), {"IR Tx SpamAll", [&]() {
if(filepath.endsWith(".ir")) options.insert(options.begin(), {"IR Tx SpamAll", [&]() {
delay(200);
txIrFile(&fs, filepath);
}});
if(filepath.endsWith(".sub")) options.insert(options.begin(), {"Subghz Tx", [&]() {
if(filepath.endsWith(".sub")) options.insert(options.begin(), {"Subghz Tx", [&]() {
delay(200);
txSubFile(&fs, filepath);
}});
#if defined(USB_as_HID)
if(filepath.endsWith(".txt")) {
options.push_back({"BadUSB Run", [&]() {
Kb.begin(); USB.begin();
options.push_back({"BadUSB Run", [&]() {
Kb.begin(); USB.begin();
// TODO: set default keyboard layout
key_input(fs, filepath);
}});
/*
options.push_back({"USB HID Type", [&]() {
options.push_back({"USB HID Type", [&]() {
Kb.begin(); USB.begin();
Kb.print(readSmallFile(fs, filepath).c_str()); // buggy?
//String t = readSmallFile(fs, filepath).c_str();
Expand All @@ -670,7 +670,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
#endif
/* WIP
if(filepath.endsWith(".aes") || filepath.endsWith(".enc")) { // aes encrypted files
options.insert(options.begin(), {"Decrypt+Type", [&]() {
options.insert(options.begin(), {"Decrypt+Type", [&]() {
String plaintext = readDecryptedAesFile(fs, filepath);
if(plaintext.length()==0) return displayError("invalid password");; // file is too big or cannot read, or cancelled
// else
Expand All @@ -690,7 +690,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
}});
}*/
#if defined(HAS_NS4168_SPKR)
if(isAudioFile(filepath)) options.insert(options.begin(), {"Play Audio", [&]() {
if(isAudioFile(filepath)) options.insert(options.begin(), {"Play Audio", [&]() {
delay(200);
playAudioFile(&fs, filepath);
setup_gpio(); //TODO: remove after fix select loop
Expand All @@ -699,7 +699,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
// generate qr codes from small files (<3K)
size_t filesize = getFileSize(fs, filepath);
//Serial.println(filesize);
if(filesize < 3*1024 && filesize>0) options.push_back({"QR code", [&]() {
if(filesize < 3*1024 && filesize>0) options.push_back({"QR code", [&]() {
delay(200);
qrcode_display(readSmallFile(fs, filepath));
}});
Expand Down Expand Up @@ -751,7 +751,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
// else look again from the start
for(int i=0; i<maxFiles; i++) {
if(tolower(fileList[i][0].c_str()[0]) == pressed_letter) { // check if 1st char matches
index = i;
index = i;
redraw = true;
break; // quit on 1st match
}
Expand Down Expand Up @@ -888,7 +888,18 @@ bool checkLittleFsSize() {
** Check if there are more then 4096 bytes available for storage
**********************************************************************/
bool checkLittleFsSizeNM() {
if((LittleFS.totalBytes() - LittleFS.usedBytes()) < 4096) {
return false;
} else return true;
return (LittleFS.totalBytes() - LittleFS.usedBytes()) >= 4096;
}

/*********************************************************************
** Function: getFsStorage
** Function will return true and FS will point to SDFS if available
** and LittleFS otherwise. If LittleFS is full it wil return false.
**********************************************************************/
bool getFsStorage(FS *&fs) {
if(setupSdCard()) fs=&SD;
else if(checkLittleFsSize()) fs=&LittleFS;
else return false;

return true;
}
2 changes: 2 additions & 0 deletions src/core/sd_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ int createFilePages(String fileContent);
bool checkLittleFsSize();

bool checkLittleFsSizeNM(); //Don't display msg

bool getFsStorage(FS *&fs);
11 changes: 2 additions & 9 deletions src/modules/rfid/PN532.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ int PN532::load() {
File file;
FS *fs;

if(setupSdCard()) fs=&SD;
else fs=&LittleFS;
if(!getFsStorage(fs)) return FAILURE;
filepath = loopSD(*fs, true, "RFID|NFC");
file = fs->open(filepath, FILE_READ);

Expand Down Expand Up @@ -105,13 +104,7 @@ int PN532::load() {

int PN532::save(String filename) {
FS *fs;
if(setupSdCard()) fs=&SD;
else {
if(!checkLittleFsSize()) fs=&LittleFS;
else {
return FAILURE;
}
}
if(!getFsStorage(fs)) return FAILURE;

if (!(*fs).exists("/BruceRFID")) (*fs).mkdir("/BruceRFID");
if ((*fs).exists("/BruceRFID/" + filename + ".rfid")) {
Expand Down
Loading

0 comments on commit a99f6c0

Please sign in to comment.