From 6515f53752df7b3f754879ff6c7dc1e224185587 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 20 Nov 2022 18:04:42 +0300 Subject: WhatsApp: fix for hex strings encoding --- protocols/WhatsApp/src/utils.h | 7 +++---- protocols/WhatsApp/src/wanode.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'protocols/WhatsApp') diff --git a/protocols/WhatsApp/src/utils.h b/protocols/WhatsApp/src/utils.h index d55e816d8c..02882f1c17 100644 --- a/protocols/WhatsApp/src/utils.h +++ b/protocols/WhatsApp/src/utils.h @@ -180,11 +180,10 @@ struct WASendTask payLoad("message"), arDest(1) { - __int64 msgId; + uint8_t msgId[8]; Utils_GetRandom(&msgId, sizeof(msgId)); - if (msgId < 0) - msgId = -msgId; - _i64toa(msgId, szMsgId, 10); + bin2hex(msgId, sizeof(msgId), szMsgId); + strupr(szMsgId); payLoad << CHAR_PARAM("id", szMsgId) << CHAR_PARAM("type", "text") << CHAR_PARAM("to", jid); } diff --git a/protocols/WhatsApp/src/wanode.cpp b/protocols/WhatsApp/src/wanode.cpp index f48ceaebd9..0c3fe15d03 100644 --- a/protocols/WhatsApp/src/wanode.cpp +++ b/protocols/WhatsApp/src/wanode.cpp @@ -518,17 +518,17 @@ static BYTE packNibble(char c) static BYTE packHex(char c) { - if (c == 0) - return 15; - if (c >= '0' && c <= '9') return c - '0'; if (c >= 'A' && c <= 'F') - return c - 'A'; + return 10 + c - 'A'; if (c >= 'a' && c <= 'f') - return c - 'a'; + return 10 + c - 'a'; + + if (c == 0) + return 15; return -1; } @@ -547,7 +547,7 @@ static bool isNibble(const CMStringA &str) static bool isHex(const CMStringA &str) { - return strspn(str, "0123456789abcdefABCDEF-.") == str.GetLength(); + return strspn(str, "0123456789abcdefABCDEF") == str.GetLength(); } void WAWriter::writePacked(const CMStringA &str, int tag) -- cgit v1.2.3