diff options
author | George Hazan <ghazan@miranda.im> | 2022-10-21 13:51:21 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-10-21 13:51:21 +0300 |
commit | f565cc4efeace9a9f1c034f3956bd7192382bea7 (patch) | |
tree | 437d14bc2433b5453ac1f63c07f1a4a9b6ecbbde /protocols/WhatsApp/src/utils.cpp | |
parent | 51037c1032b29ac1090cf4ecb78f3dce1bda554a (diff) |
WhatsApp: app state sync
Diffstat (limited to 'protocols/WhatsApp/src/utils.cpp')
-rw-r--r-- | protocols/WhatsApp/src/utils.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/protocols/WhatsApp/src/utils.cpp b/protocols/WhatsApp/src/utils.cpp index 455428bd7b..9bbea8a88b 100644 --- a/protocols/WhatsApp/src/utils.cpp +++ b/protocols/WhatsApp/src/utils.cpp @@ -72,6 +72,28 @@ CMStringA WAJid::toString() const ///////////////////////////////////////////////////////////////////////////////////////// +static uint8_t sttLtHashInfo[] = "WhatsApp Patch Integrity"; + +void LT_HASH::add(const void *pData, size_t len) +{ + uint16_t tmp[_countof(hash)]; + HKDF(EVP_sha256(), (BYTE *)"", 0, (BYTE*)pData, len, sttLtHashInfo, sizeof(sttLtHashInfo) - 1, (BYTE *)tmp, sizeof(tmp)); + + for (int i = 0; i < _countof(hash); i++) + hash[i] += tmp[i]; +} + +void LT_HASH::sub(const void *pData, size_t len) +{ + uint16_t tmp[_countof(hash)]; + HKDF(EVP_sha256(), (BYTE *)"", 0, (BYTE *)pData, len, sttLtHashInfo, sizeof(sttLtHashInfo) - 1, (BYTE *)tmp, sizeof(tmp)); + + for (int i = 0; i < _countof(hash); i++) + hash[i] -= tmp[i]; +} + +///////////////////////////////////////////////////////////////////////////////////////// + WAUser* WhatsAppProto::FindUser(const char *szId) { mir_cslock lck(m_csUsers); @@ -193,6 +215,18 @@ int WhatsAppProto::WSSendNode(WANode &node, WA_PKT_HANDLER pHandler) ///////////////////////////////////////////////////////////////////////////////////////// +std::string decodeBinStr(const std::string &buf) +{ + size_t cbLen; + void *pData = mir_base64_decode(buf.c_str(), &cbLen); + if (pData == nullptr) + return ""; + + std::string res((char *)pData, cbLen); + mir_free(pData); + return res; +} + uint32_t decodeBigEndian(const std::string &buf) { uint32_t ret = 0; @@ -328,6 +362,21 @@ void string2file(const std::string &str, const wchar_t *pwszFileName) } } +CMStringA file2string(const wchar_t *pwszFileName) +{ + CMStringA res; + + int fileId = _wopen(pwszFileName, _O_RDONLY | _O_BINARY, _S_IREAD | _S_IWRITE); + if (fileId != -1) { + res.Truncate(filelength(fileId)); + read(fileId, res.GetBuffer(), res.GetLength()); + close(fileId); + } + return res; +} + +///////////////////////////////////////////////////////////////////////////////////////// + CMStringA directPath2url(const char *pszDirectPath) { return CMStringA("https://mmg.whatsapp.net") + pszDirectPath; |