-
Notifications
You must be signed in to change notification settings - Fork 6
/
packet.cpp
54 lines (49 loc) · 3.53 KB
/
packet.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
#include "packet.hpp"
const unsigned char
key_08[0x50] = {0x02E,0x0C7,0x0C4,0x08D,0x0FF,0x0E5,0x05D,0x00B,0x0D6,0x0FF,0x07F,0x0FF,0x0D7,0x034,0x0D2,0x002,0x0E2,0x06D,0x09E,0x048,0x07B,0x0C6,0x06A,0x0F1,0x097,0x073,0x056,0x077,0x0FA,0x09D,0x080,0x000,0x011,0x004,0x029,0x008,0x0A6,0x08B,0x02A,0x047,0x064,0x000,0x001,0x038,0x084,0x0A0,0x040,0x069,0x001,0x0F9,0x0FA,0x0BE,0x0EA,0x0FF,0x097,0x07B,0x0A7,0x026,0x0ED,0x0F7,0x06B,0x07B,0x03B,0x04F,0x044,0x074,0x0A3,0x009,0x079,0x040,0x038,0x03A,0x020,0x05D,0x0A3,0x040,0x0C3,0x0E8,0x07F,0x03B,},
key_10[0x50] = {0x0DF,0x019,0x061,0x043,0x0AD,0x0C4,0x04C,0x01C,0x038,0x08D,0x01D,0x0BE,0x070,0x081,0x0EB,0x063,0x01A,0x052,0x0F4,0x0EC,0x084,0x0E1,0x04E,0x0EF,0x048,0x05D,0x069,0x011,0x083,0x06E,0x0E6,0x0C6,0x0F8,0x02F,0x053,0x0D0,0x0FF,0x0EA,0x0D1,0x016,0x037,0x0D4,0x0C0,0x0BE,0x056,0x051,0x0E6,0x08D,0x0A0,0x068,0x0B3,0x004,0x0CC,0x073,0x09D,0x0C0,0x063,0x03B,0x0AC,0x009,0x0F6,0x00F,0x0BC,0x0A1,0x096,0x074,0x001,0x035,0x07E,0x08C,0x0DB,0x00D,0x00A,0x0DF,0x052,0x008,0x0C1,0x02B,0x03D,0x0B5,},
key_11[0x50] = {0x0D1,0x016,0x037,0x0D4,0x0C0,0x0BE,0x056,0x051,0x0E6,0x08D,0x0A0,0x068,0x0B3,0x004,0x0CC,0x073,0x09D,0x0C0,0x0AC,0x009,0x0F6,0x00F,0x0BC,0x0A1,0x096,0x075,0x001,0x035,0x07E,0x08C,0x0DB,0x00D,0x02B,0x03D,0x0B5,0x00A,0x0DF,0x052,0x008,0x063,0x03B,0x08D,0x01D,0x0BE,0x070,0x0EB,0x063,0x0EF,0x048,0x05D,0x0AD,0x0C4,0x0C1,0x01A,0x052,0x0F4,0x0EC,0x084,0x0E1,0x04E,0x04C,0x01C,0x038,0x069,0x011,0x0DF,0x019,0x061,0x043,0x081,0x083,0x06E,0x0E6,0x0C6,0x0F8,0x02F,0x053,0x0D0,0x0FF,0x0EA,},
key_15[0x50] = {0x0A0,0x061,0x091,0x07A,0x09A,0x03F,0x08C,0x0F1,0x0A9,0x02F,0x09F,0x05E,0x0DE,0x0AD,0x0CF,0x04E,0x080,0x000,0x081,0x0A9,0x001,0x0F0,0x0FF,0x08E,0x041,0x048,0x0A6,0x02A,0x0EF,0x0DF,0x019,0x061,0x043,0x0AD,0x0C4,0x04C,0x01C,0x038,0x08D,0x01D,0x0BE,0x070,0x0D6,0x0FF,0x07F,0x0FF,0x0D7,0x034,0x0D2,0x002,0x0E2,0x06D,0x09E,0x048,0x07B,0x0C6,0x0E1,0x04E,0x0EF,0x048,0x05D,0x069,0x011,0x083,0x06E,0x0E6,0x0C6,0x0F8,0x02F,0x053,0x0D0,0x0FF,0x0EA,0x0D1,0x016,0x037,0x0DE,0x0AD,0x0BE,0x0EF,},
key_20[0x50] = {0x0C9,0x086,0x093,0x0FC,0x06A,0x044,0x018,0x0AA,0x0AA,0x012,0x09A,0x060,0x0CF,0x010,0x041,0x0E8,0x0BA,0x0BA,0x01A,0x088,0x010,0x0AF,0x0DE,0x0AD,0x0BE,0x0EF,0x084,0x091,0x05A,0x015,0x020,0x01A,0x055,0x005,0x0E7,0x087,0x001,0x011,0x0E5,0x0D1,0x006,0x0E6,0x068,0x071,0x0CC,0x0CC,0x018,0x080,0x000,0x011,0x03F,0x018,0x0CA,0x016,0x0C9,0x026,0x0AD,0x051,0x05A,0x080,0x0CD,0x0EF,0x034,0x088,0x014,0x081,0x0BE,0x0FE,0x0EE,0x0ED,0x0C0,0x0FF,0x0EE,0x0E8,0x079,0x0A5,0x0E7,0x050,0x041,0x0CA,};
const unsigned char* PACKET_GetKey(unsigned long ver)
{
switch(ver)
{
case 7:
case 8:
case 9:
return key_08;
case 10:
return key_10;
case 11:
case 12:
case 13:
case 14:
case 15:
return key_11;
/*case 15:
return key_15;*/ // absent protocol version
case 20:
return key_20;
default:
return NULL;
}
}
void PACKET_XorByKey(unsigned char* data, unsigned long size, unsigned long protover)
{
const unsigned char* key = PACKET_GetKey(protover);
if(!key) return;
uint8_t* p = data;
for(uint32_t i = 0; i < size; ++i)
*(p++) ^= key[(i%0x08E)%0x050];
}
void PACKET_Crypt(Archive& packet, unsigned long protover)
{
uint32_t size = 0;
uint8_t* data = NULL;
packet.GetAllData(data, size);
PACKET_XorByKey(data, size, protover);
packet.SetAllData(data, size);
packet.ResetPosition();
delete[] data;
}