-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExileSocket.cpp
93 lines (74 loc) · 2.44 KB
/
ExileSocket.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "ExileSocket.h"
void ExileSocket::SetKeyWithIV(QByteArray key)
{
Q_ASSERT(key.size() == 0x40);
this->m_Encryption.SetKeyWithIV((CryptoPP::byte *)key.data(), 0x20,
(CryptoPP::byte *)&key.data()[0x20], 8);
this->m_Decryption.SetKeyWithIV((CryptoPP::byte *)key.data(), 0x20,
(CryptoPP::byte *)&key.data()[0x30], 8);
}
void ExileSocket::EnableCrypto()
{
this->isCrypto = true;
}
// ========== write ==========
qint64 ExileSocket::write(QByteArray data, int type, QString name)
{
if (data.size() == 0)
{
return 0;
}
m_PacketListModel.appendField(type, name, data);
if (this->isCrypto == true)
{
this->m_Encryption.ProcessData((CryptoPP::byte *)data.data(),
(CryptoPP::byte *)data.data(),
data.size());
}
return QTcpSocket::write(data);
}
qint64 ExileSocket::write(const char *data, qint64 len, int type, QString name)
{
return this->write(QByteArray(data, len), type, name);
}
qint64 ExileSocket::write(QString data, QString name)
{
qint64 size = this->write<quint16>(data.size());
size += this->write((char *)data.data(), data.size() * sizeof(char16_t), qMetaTypeId<QString>(), name);
return size;
}
qint64 ExileSocket::write(const char *data, QString name)
{
return this->write(QString(data), name);
}
// ========== read ==========
QByteArray ExileSocket::read(qint64 maxlen, QString name, int type)
{
QByteArray data;
if (maxlen == 0)
{
return data;
}
do
{
data.append(QTcpSocket::read(maxlen - data.size()));
} while (data.size() != maxlen && this->waitForReadyRead());
if (this->isCrypto == true)
{
this->m_Decryption.ProcessData((CryptoPP::byte *)data.data(),
(CryptoPP::byte *)data.data(),
data.size());
}
m_PacketListModel.appendField(type, name, data);
return data;
}
QByteArray ExileSocket::readAll(QString name)
{
return this->read(QTcpSocket::size(), name, QMetaType::QByteArray);
}
QString ExileSocket::readString(QString name)
{
quint16 size = this->read<quint16>("size");
QByteArray data = this->read(size * sizeof(char16_t), name, QMetaType::QString);
return data.size() == size * sizeof(char16_t) ? QString::fromUtf16((char16_t *)data.data(), size) : "";
}