From ffe81214b6bd99544d072545be47dac745786794 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 1 May 2024 17:20:19 +0200 Subject: add package fiddling + editorconfig + preprocessor options --- .editorconfig | 3 ++ captures.txt | 9 ++++++ src/frontend/qt_sdl/LocalMP.cpp | 67 ++++++++++++++++++++++++++++++----------- 3 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 .editorconfig create mode 100644 captures.txt diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3c77f6d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*.{cpp,h}] +indent_style = space +indent_size = 4 diff --git a/captures.txt b/captures.txt new file mode 100644 index 0000000..c3ed84f --- /dev/null +++ b/captures.txt @@ -0,0 +1,9 @@ +historically significant pictochat captures + +melon_1714483602.pcap: first plain-text proof +melon_1714557482.pcap: completely black message capture +melon_1714564166.pcap: pattern v2 message + +melon_1714566548.pcap: 1 pixel vertical line, then 1 pixel horizontal line (check structure) + + diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index cc42706..b2e307e 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -16,6 +16,11 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +// VSR-specific experiments + +// #define VSR_MESSAGE_FIDDLING 1 +#define VSR_DUMP_MESSAGES 1 + #include #include #include @@ -39,13 +44,18 @@ #include "LocalMP.h" #include "Platform.h" -#include -#include -#include #include +#ifdef VSR_DUMP_MESSAGES +#include +#include pcap_dumper_t* dumper; +#endif + +#ifdef VSR_MESSAGE_FIDDLING +#include unsigned long test_start = time(NULL); +#endif using namespace melonDS; using namespace melonDS::Platform; @@ -241,10 +251,12 @@ void SemReset(int num) bool Init() { +#ifdef VSR_DUMP_MESSAGES pcap_t* handle = pcap_open_dead(DLT_USER0, 1 << 16); char filename[80]; snprintf(filename, 79, "melon_%lu.pcap", time(NULL)); dumper = pcap_dump_open(handle, filename); +#endif MPQueue = new QSharedMemory("melonNIFI"); @@ -307,7 +319,9 @@ bool Init() void DeInit() { +#ifdef VSR_DUMP_MESSAGES pcap_dump_close(dumper); +#endif if (MPQueue) { @@ -447,16 +461,18 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) u16 mask = header->ConnectedBitmask; - // // packet dropping test - // unsigned long now = time(NULL); - // static bool first = true; - // bool dropping = false; - // if (now - test_start > 20 && InstanceID == 0) { - // if (first == true) - // printf("[INSTANCE %d] started dropping packets!\n", InstanceID); - // first = false; - // dropping = true; - // } +#ifdef VSR_MESSAGE_FIDDLING + // fiddle the packets after 20 seconds + unsigned long now = time(NULL); + static bool first = true; + bool fiddle = false; + if (now - test_start > 20 && InstanceID == 0) { + if (first == true) + printf("[INSTANCE %d] started fiddling!\n", InstanceID); + first = false; + fiddle = true; + } +#endif // TODO: check if the FIFO is full! @@ -467,30 +483,47 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) pktheader.Length = len; pktheader.Timestamp = timestamp; +#ifdef VSR_DUMP_MESSAGES std::vector buf; +#endif type &= 0xFFFF; int nfifo = (type == 2) ? 1 : 0; // NOTE: this is the ni-fi packet header, altering this header in any way // seems to consistently trigger PACKET FIFO OVERFLOW errors FIFOWrite(nfifo, &pktheader, sizeof(pktheader)); +#ifdef VSR_DUMP_MESSAGES buf.insert(buf.end(), (uint8_t*) &pktheader, (uint8_t*) &pktheader + sizeof(pktheader)); +#endif if (len) { - // // replace packet content with random noise while dropping - // if (dropping) - // for (size_t i = 0; i < len; i++) - // packet[i] = rand(); +#ifdef VSR_MESSAGE_FIDDLING + if (fiddle && len == 0xde) { + // NOTE: packet indexes are after NIFI header! + packet[0x80] = 0x11; + packet[0x81] = 0x11; + packet[0x82] = 0x11; + packet[0x83] = 0x11; + packet[0x84] = 0x11; + packet[0x85] = 0x11; + packet[0x86] = 0x11; + packet[0x87] = 0x11; + } +#endif +#ifdef VSR_DUMP_MESSAGES buf.insert(buf.end(), (uint8_t*) packet, (uint8_t*) packet + len); +#endif FIFOWrite(nfifo, packet, len); } +#ifdef VSR_DUMP_MESSAGES struct pcap_pkthdr p; p.len = buf.size(); p.caplen = buf.size(); gettimeofday(&p.ts, NULL); pcap_dump((u_char*) dumper, &p, buf.data()); +#endif if (type == 1) { -- cgit v1.2.3