diff options
author | George Hazan <ghazan@miranda.im> | 2021-04-19 22:19:54 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-04-19 22:19:54 +0300 |
commit | 1aa3e3bc713f7ad632d70f1c26ba6fc4070870b3 (patch) | |
tree | 74f1f3c4c9df9acd0f891057a6b6d674ce1433f3 /protocols/WhatsAppWeb/src | |
parent | 3577c55cb91c10b68b2e162c0d9140659dea5d3c (diff) |
cleaner implementation of packet analyzer
Diffstat (limited to 'protocols/WhatsAppWeb/src')
-rw-r--r-- | protocols/WhatsAppWeb/src/server.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/protocols/WhatsAppWeb/src/server.cpp b/protocols/WhatsAppWeb/src/server.cpp index 06241e46c2..c26a590af9 100644 --- a/protocols/WhatsAppWeb/src/server.cpp +++ b/protocols/WhatsAppWeb/src/server.cpp @@ -330,7 +330,11 @@ bool WhatsAppProto::ServerThreadWorker() // read all payloads from the current buffer, one by one size_t prevSize = 0; while (true) { - const char *start = netbuf.data() + hdr.headerSize; + MBinBuffer currPacket; + currPacket.assign(netbuf.data() + hdr.headerSize, hdr.payloadSize); + currPacket.append("", 1); + + const char *start = currPacket.data(); switch (hdr.opCode) { case 1: // json packet @@ -338,18 +342,15 @@ bool WhatsAppProto::ServerThreadWorker() if (hdr.bIsFinal) { // process a packet here const char *pos = strchr(start, ','); - if (pos == nullptr) { - debugLogA("invalid packet received, no comma"); - break; - } - pos++; + if (pos != nullptr) + pos++; size_t dataSize = hdr.payloadSize - size_t(pos - start); // try to decode if (hdr.opCode == 2 && hdr.payloadSize > 32) { MBinBuffer dest; if (!decryptBinaryMessage(dataSize, pos, dest)) { - Netlib_Dump(m_hServerConn, netbuf.data(), hdr.headerSize + hdr.payloadSize, false, 0); + Netlib_Dump(m_hServerConn, currPacket.data(), currPacket.length(), false, 0); debugLogA("cannot decrypt incoming message"); break; } @@ -359,10 +360,11 @@ bool WhatsAppProto::ServerThreadWorker() } else { CMStringA szJson(pos, (int)dataSize); - debugLogA("JSON received:\n%s", szJson.c_str()); JSONNode root = JSONNode::parse(szJson); if (root) { + debugLogA("JSON received:\n%s", szJson.c_str()); + int sessId, pktId; if (sscanf(start, "%d.--%d,", &sessId, &pktId) == 2) { auto *pReq = m_arPacketQueue.find((WARequest *)&pktId); |