-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathObfuscate.cpp
86 lines (58 loc) · 2.62 KB
/
Obfuscate.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
//By AlSch092 @ github
#include "Obfuscator.hpp"
template<class T>
class ProtectedData //simple wrapper around obfuscate and deobfuscate, this class is completely optional to use. the actual obfuscator is in Obfuscator.hpp
{
private:
T someData; //data member to protect in memory
public:
ProtectedData(const T val)
{
SetData(val);
}
__forceinline T GetData()
{
return Obfuscator<T>::deobfuscate(someData);
}
__forceinline void SetData(const T value)
{
this->someData = value;
Obfuscator<T>::obfuscate(this->someData);
}
__forceinline T GetData(const unsigned int key)
{
return Obfuscator<T>::deobfuscate_with_key(someData, key);
}
__forceinline void SetData(const T value, const unsigned int key)
{
this->someData = value;
Obfuscator<T>::obfuscate_with_key(this->someData, key);
}
};
int main(void)
{
//test integer obfuscations
unsigned int OriginalValue = 5;
const unsigned int key = 12345;
ProtectedData<unsigned int>* obfuscatedClass = new ProtectedData<unsigned int>(OriginalValue);
unsigned int value = obfuscatedClass->GetData(); //returns original value of 5, now we can try adding a randomized key
cout << "Original value to obfuscate: " << value << endl;
obfuscatedClass->SetData(OriginalValue, key); //key-based approach - a deterministic value is generated based on a key and used in the obfuscation process
int wrong_value = obfuscatedClass->GetData(2222); //wrong key (2222) gets a wrong value back
cout << "GetData with key 2222 (wrong key) -> Value = " << wrong_value << endl;
int correct_value_with_key = obfuscatedClass->GetData(key); //get data back with correct key
cout << "GetData with key " << key << " -> Value = " << correct_value_with_key << endl;
//test string obfuscations
string str_to_obfs = "hello world";
Obfuscator<string>::obfuscate(str_to_obfs);
cout << "Obfuscated string: " << str_to_obfs << endl;
string deobfs_str = Obfuscator<string>::deobfuscate(str_to_obfs);
cout << "Deobfuscated string: " << deobfs_str << endl;
string str_to_obfs_with_key = "a string large enough to show that no strange edge cases will come up, a quick brown fox jumps over !@#$%^&*() the 1234567890 gate";
Obfuscator<string>::obfuscate_with_key(str_to_obfs_with_key, 0x12, 0x34);
cout << "Obfuscated string (using keys 0x12, 0x34): " << str_to_obfs_with_key << endl;
string deobfs_str_with_key = Obfuscator<string>::deobfuscate_with_key(str_to_obfs_with_key, 0x12, 0x34);
cout << "Deobfuscated string (using keys 0x12, 0x34): " << deobfs_str_with_key << endl;
delete obfuscatedClass;
return 0;
}