Skip to content

Commit

Permalink
Merge pull request #45 from runcom/update-marauder-0310
Browse files Browse the repository at this point in the history
update esp32_marauder to v0.13.10
  • Loading branch information
eried committed May 27, 2024
2 parents 56bcf20 + dd34ade commit e640555
Show file tree
Hide file tree
Showing 86 changed files with 5,626 additions and 7,816 deletions.
5 changes: 4 additions & 1 deletion esp32cam_marauder/Assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ PROGMEM static const unsigned char menu_icons[][66] = {
0x1F, 0xD0, 0x3F, 0x3F, 0xE0, 0x3F, 0x5F, 0xF0, 0x3F, 0xEF, 0xE8, 0x3F,
0xF7, 0xE5, 0x3B, 0xFB, 0xDE, 0x3A, 0x7D, 0xFF, 0x3A, 0xBB, 0x7F, 0x3B,
0xD7, 0x9F, 0x3D, 0xEF, 0xFF, 0x3E, 0xFF, 0x0F, 0x3F, 0xFF, 0xFF, 0x3F,
0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F}
0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F},
{0xFF, 0xFF, 0xFD, 0xBF, 0x0B, 0xD0, 0xE7, 0xE7, 0xEF, 0xF7, 0xCF, 0xF3, // DISABLED TOUCH: 34
0xAF, 0xF5, 0x6F, 0xF6, 0x6F, 0xF6, 0xAF, 0xF5, 0xCF, 0xF3, 0x0F, 0xF0,
0xE7, 0xE7, 0x0B, 0xD0, 0xFD, 0xBF, 0xFF, 0xFF}
};

#ifndef MARAUDER_MINI
Expand Down
191 changes: 93 additions & 98 deletions esp32cam_marauder/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Buffer::Buffer(){
bufB = (uint8_t*)malloc(BUF_SIZE);
}

void Buffer::createPcapFile(fs::FS* fs, String fn, bool log){
void Buffer::createFile(String name, bool is_pcap){
int i=0;
if (!log) {
if (is_pcap) {
do{
fileName = "/"+fn+"_"+(String)i+".pcap";
fileName = "/"+name+"_"+(String)i+".pcap";
i++;
} while(fs->exists(fileName));
}
else {
do{
fileName = "/"+fn+"_"+(String)i+".log";
fileName = "/"+name+"_"+(String)i+".log";
i++;
} while(fs->exists(fileName));
}
Expand All @@ -27,15 +27,15 @@ void Buffer::createPcapFile(fs::FS* fs, String fn, bool log){
file.close();
}

void Buffer::open(bool log){
void Buffer::open(bool is_pcap){
bufSizeA = 0;
bufSizeB = 0;

bufSizeB = 0;

writing = true;

if (!log) {
if (is_pcap) {
write(uint32_t(0xa1b2c3d4)); // magic number
write(uint16_t(2)); // major version number
write(uint16_t(4)); // minor version number
Expand All @@ -46,14 +46,35 @@ void Buffer::open(bool log){
}
}

void Buffer::close(fs::FS* fs){
if(!writing) return;
forceSave(fs);
writing = false;
Serial.println(text01);
void Buffer::openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap) {
bool save_pcap = settings_obj.loadSetting<bool>("SavePCAP");
if (!save_pcap) {
this->fs = NULL;
this->serial = false;
writing = false;
return;
}
this->fs = fs;
this->serial = serial;
if (this->fs) {
createFile(file_name, is_pcap);
}
if (this->fs || this->serial) {
open(is_pcap);
} else {
writing = false;
}
}

void Buffer::pcapOpen(String file_name, fs::FS* fs, bool serial) {
openFile(file_name, fs, serial, true);
}

void Buffer::addPacket(uint8_t* buf, uint32_t len, bool log){
void Buffer::logOpen(String file_name, fs::FS* fs, bool serial) {
openFile(file_name, fs, serial, false);
}

void Buffer::add(const uint8_t* buf, uint32_t len, bool is_pcap){
// buffer is full -> drop packet
if((useA && bufSizeA + len >= BUF_SIZE && bufSizeB > 0) || (!useA && bufSizeB + len >= BUF_SIZE && bufSizeA > 0)){
//Serial.print(";");
Expand All @@ -74,7 +95,7 @@ void Buffer::addPacket(uint8_t* buf, uint32_t len, bool log){

microSeconds -= seconds*1000*1000; // e.g. 45200400 - 45*1000*1000 = 45200400 - 45000000 = 400us (because we only need the offset)

if (!log) {
if (is_pcap) {
write(seconds); // ts_sec
write(microSeconds); // ts_usec
write(len); // incl_len
Expand All @@ -84,6 +105,20 @@ void Buffer::addPacket(uint8_t* buf, uint32_t len, bool log){
write(buf, len); // packet payload
}

void Buffer::append(wifi_promiscuous_pkt_t *packet, int len) {
bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
if (save_packet) {
add(packet->payload, len, true);
}
}

void Buffer::append(String log) {
bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
if (save_packet) {
add((const uint8_t*)log.c_str(), log.length(), false);
}
}

void Buffer::write(int32_t n){
uint8_t buf[4];
buf[0] = n;
Expand All @@ -109,8 +144,9 @@ void Buffer::write(uint16_t n){
write(buf,2);
}

void Buffer::write(uint8_t* buf, uint32_t len){
void Buffer::write(const uint8_t* buf, uint32_t len){
if(!writing) return;
while(saving) delay(10);

if(useA){
memcpy(&bufA[bufSizeA], buf, len);
Expand All @@ -121,127 +157,86 @@ void Buffer::write(uint8_t* buf, uint32_t len){
}
}

void Buffer::save(fs::FS* fs){
if(saving) return; // makes sure the function isn't called simultaneously on different cores

// buffers are already emptied, therefor saving is unecessary
if((useA && bufSizeB == 0) || (!useA && bufSizeA == 0)){
//Serial.printf("useA: %s, bufA %u, bufB %u\n",useA ? "true" : "false",bufSizeA,bufSizeB); // for debug porpuses
return;
}

//Serial.println("saving file");

uint32_t startTime = millis();
uint32_t finishTime;

file = fs->open(fileName, FILE_APPEND);
if (!file) {
Serial.println(text02 + fileName+"'");
//useSD = false;
return;
}

saving = true;

uint32_t len;

if(useA){
file.write(bufB, bufSizeB);
len = bufSizeB;
bufSizeB = 0;
}
else{
file.write(bufA, bufSizeA);
len = bufSizeA;
bufSizeA = 0;
}

file.close();

finishTime = millis() - startTime;

//Serial.printf("\n%u bytes written for %u ms\n", len, finishTime);

saving = false;

}

void Buffer::forceSave(fs::FS* fs){
uint32_t len = bufSizeA + bufSizeB;
if(len == 0) return;

void Buffer::saveFs(){
file = fs->open(fileName, FILE_APPEND);
if (!file) {
Serial.println(text02+fileName+"'");
//useSD = false;
return;
}

saving = true;
writing = false;

if(useA){

if(bufSizeB > 0){
file.write(bufB, bufSizeB);
bufSizeB = 0;
}

if(bufSizeA > 0){
file.write(bufA, bufSizeA);
bufSizeA = 0;
}

} else {

if(bufSizeA > 0){
file.write(bufA, bufSizeA);
bufSizeA = 0;
}

if(bufSizeB > 0){
file.write(bufB, bufSizeB);
bufSizeB = 0;
}

}

file.close();

//Serial.printf("saved %u bytes\n",len);

saving = false;
writing = true;
}

void Buffer::forceSaveSerial() {
uint32_t len = bufSizeA + bufSizeB;
if(len == 0) return;

saving = true;
writing = false;
void Buffer::saveSerial() {
// Saves to main console UART, user-facing app will ignore these markers
// Uses / and ] in markers as they are illegal characters for SSIDs
const char* mark_begin = "[BUF/BEGIN]";
const size_t mark_begin_len = strlen(mark_begin);
const char* mark_close = "[BUF/CLOSE]";
const size_t mark_close_len = strlen(mark_close);

// Additional buffer and memcpy's so that a single Serial.write() is called
// This is necessary so that other console output isn't mixed into buffer stream
uint8_t* buf = (uint8_t*)malloc(mark_begin_len + bufSizeA + bufSizeB + mark_close_len);
uint8_t* it = buf;
memcpy(it, mark_begin, mark_begin_len);
it += mark_begin_len;

if(useA){
if(bufSizeB > 0){
Serial1.write(bufB, bufSizeB);
bufSizeB = 0;
memcpy(it, bufB, bufSizeB);
it += bufSizeB;
}
if(bufSizeA > 0){
Serial1.write(bufA, bufSizeA);
bufSizeA = 0;
memcpy(it, bufA, bufSizeA);
it += bufSizeA;
}
} else {
if(bufSizeA > 0){
Serial1.write(bufA, bufSizeA);
bufSizeA = 0;
memcpy(it, bufA, bufSizeA);
it += bufSizeA;
}
if(bufSizeB > 0){
Serial1.write(bufB, bufSizeB);
bufSizeB = 0;
memcpy(it, bufB, bufSizeB);
it += bufSizeB;
}
}

memcpy(it, mark_close, mark_close_len);
it += mark_close_len;
Serial.write(buf, it - buf);
free(buf);
}

void Buffer::save() {
saving = true;

if((bufSizeA + bufSizeB) == 0){
saving = false;
return;
}

if(this->fs) saveFs();
if(this->serial) saveSerial();

bufSizeA = 0;
bufSizeB = 0;

saving = false;
writing = true;
}
26 changes: 16 additions & 10 deletions esp32cam_marauder/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "Arduino.h"
#include "FS.h"
#include "settings.h"
//#include "SD_MMC.h"
#include "esp_wifi_types.h"

#define BUF_SIZE 3 * 1024 // Had to reduce buffer size to save RAM. GG @spacehuhn
#define SNAP_LEN 2324 // max len of each recieved packet
Expand All @@ -18,19 +18,23 @@ extern Settings settings_obj;
class Buffer {
public:
Buffer();
void createPcapFile(fs::FS* fs, String fn = "", bool log = false);
void open(bool log = false);
void close(fs::FS* fs);
void addPacket(uint8_t* buf, uint32_t len, bool log = false);
void save(fs::FS* fs);
void forceSave(fs::FS* fs);
void forceSaveSerial();
void pcapOpen(String file_name, fs::FS* fs, bool serial);
void logOpen(String file_name, fs::FS* fs, bool serial);
void append(wifi_promiscuous_pkt_t *packet, int len);
void append(String log);
void save();
private:
void createFile(String name, bool is_pcap);
void open(bool is_pcap);
void openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap);
void add(const uint8_t* buf, uint32_t len, bool is_pcap);
void write(int32_t n);
void write(uint32_t n);
void write(uint16_t n);
void write(uint8_t* buf, uint32_t len);

void write(const uint8_t* buf, uint32_t len);
void saveFs();
void saveSerial();

uint8_t* bufA;
uint8_t* bufB;

Expand All @@ -43,6 +47,8 @@ class Buffer {

String fileName = "/0.pcap";
File file;
fs::FS* fs;
bool serial;
};

#endif
8 changes: 6 additions & 2 deletions esp32cam_marauder/CommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifdef HAS_SCREEN
#include "MenuFunctions.h"
#include "Display.h"
#endif
#endif

#include "WiFiScan.h"
//#include "Web.h"
Expand Down Expand Up @@ -80,6 +80,8 @@ const char PROGMEM ATTACK_TYPE_RR[] = "rickroll";
const char PROGMEM LIST_AP_CMD[] = "list";
const char PROGMEM SEL_CMD[] = "select";
const char PROGMEM SSID_CMD[] = "ssid";
const char PROGMEM SAVE_CMD[] = "save";
const char PROGMEM LOAD_CMD[] = "load";

// Bluetooth sniff/scan
const char PROGMEM BT_SPAM_CMD[] = "blespam";
Expand Down Expand Up @@ -131,6 +133,8 @@ const char PROGMEM HELP_LIST_AP_CMD_C[] = "list -c";
const char PROGMEM HELP_SEL_CMD_A[] = "select -a/-s/-c <index (comma separated)>/-f \"equals <String> or contains <String>\"";
const char PROGMEM HELP_SSID_CMD_A[] = "ssid -a [-g <count>/-n <name>]";
const char PROGMEM HELP_SSID_CMD_B[] = "ssid -r <index>";
const char PROGMEM HELP_SAVE_CMD[] = "save -a/-s";
const char PROGMEM HELP_LOAD_CMD[] = "load -a/-s";

// Bluetooth sniff/scan
const char PROGMEM HELP_BT_SNIFF_CMD[] = "sniffbt";
Expand Down Expand Up @@ -184,7 +188,7 @@ class CommandLine {
" @@@@@@ \r\n"
" @@@@ \r\n"
"\r\n";

public:
CommandLine();

Expand Down
Loading

0 comments on commit e640555

Please sign in to comment.