-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsimple_obfuscator.cpp
62 lines (52 loc) · 1.32 KB
/
simple_obfuscator.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
#pragma once
#include "shared.cpp"
#include "obfuscate_base.cpp"
class simple_obfuscator : virtual public obfuscate_base
{
public:
char key;
simple_obfuscator(char *key)
{
if (key == nullptr || key[0] == 0)
{
this->key = 0x90; // nop sled anyone?
printf("Obfuscating packets with simple obfuscator and built-in key.\n");
}
else
{
this->key = key[0];
printf("Obfuscating packets with simple obfuscator and specified byte.\n");
}
}
simple_obfuscator(struct session* session)
: simple_obfuscator(session->key)
{
}
static inline int process(char* message, int length, char key)
{
int process = min(16, length);
if (length > 32)
{
for (int i = 0; i < process; i++)
{
message[i] ^= key ^ message[i + 16];
}
}
else
{
for (int i = 0; i < process; i++)
{
message[i] ^= key;
}
}
return length;
}
virtual int encipher(char* message, int length)
{
return process(message, length, this->key);
}
virtual int decipher(char* message, int length)
{
return process(message, length, this->key);
}
};