blob: aa74f865f2a96c7d53aa3c486f9ed8007de0960a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/*
WhatsAppWeb plugin for Miranda NG
Copyright © 2019-21 George Hazan
*/
#define LIST_EMPTY 0
#define STREAM_END 2
#define DICTIONARY_0 236
#define DICTIONARY_1 237
#define DICTIONARY_2 238
#define DICTIONARY_3 239
#define LIST_8 248
#define LIST_16 249
#define JID_PAIR 250
#define HEX_8 251
#define BINARY_8 252
#define BINARY_20 253
#define BINARY_32 254
#define NIBBLE_8 255
class WAReader
{
const BYTE *m_buf, *m_limit;
uint32_t readIntN(int i);
CMStringA readStringFromChars(int size);
public:
WAReader(const void *buf, size_t cbLen) :
m_buf((BYTE*)buf),
m_limit((BYTE*)buf + cbLen)
{}
__forceinline uint32_t readInt8() { return readIntN(1); }
__forceinline uint32_t readInt16() { return readIntN(2); }
__forceinline uint32_t readInt32() { return readIntN(4); }
bool readAttributes(JSONNode &node, int count);
uint32_t readInt20();
bool readList(JSONNode &node, int tag);
int readListSize(int tag);
CMStringA readPacked(int tag);
CMStringA readString(int tag);
bool readNode(JSONNode&);
};
/////////////////////////////////////////////////////////////////////////////////////////
// object serialization
#define WAS_STRING 1
#define WAS_BINARY 2
#define WAS_BOOL 3
#define WAS_INT8 4
#define WAS_INT64 5
struct WAS_Field
{
uint8_t type;
uint8_t len;
uint16_t offset;
};
class WAS_Decoder
{
const BYTE *m_buf, *m_limit;
public:
WAS_Decoder(const void *pData, size_t cbLen) :
m_buf((BYTE*)pData),
m_limit((BYTE*)pData + cbLen)
{}
bool read(void *pObj, const WAS_Field *fields, size_t iFieldCount);
};
|