-
Notifications
You must be signed in to change notification settings - Fork 3
/
EncryptedCHAR.h
113 lines (90 loc) · 1.9 KB
/
EncryptedCHAR.h
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef __ENCRYPTEDCHAR_H_
#define __ENCRYPTEDCHAR_H_
#pragma once
#include <stdio.h>
#include <time.h>
#include <xtl.h>
class EncryptedCHAR {
private:
WCHAR XORValue;
WCHAR Value;
WCHAR RandFuncXOR;
int (__cdecl *RandFunc)();
void (__cdecl *SRandFunc)(int);
int (__cdecl *TimeFunc)(int);
public:
EncryptedCHAR() {
RandFunc = (int (__cdecl *)())(rand);
SRandFunc = (void (__cdecl *)(int))(srand);
TimeFunc = (int (__cdecl *)(int))(time);
// use time value as seed
int time = CallFunc(2, 0);
//srand - seed our random number
CallFunc(1, time);
RandFuncXOR = CallFunc(0, 0);
XORValue = CallFunc(0, 0);
}
~EncryptedCHAR() {
}
virtual void SetValue(WCHAR val) {
__asm {
mr r6, r7
insrwi r6, r7, 16,0
rlwinm r5, r7, 24,16,23
extlwi r4, r6, 16,8
or r5, r4, r5
or r11, r3, r9
}
Value = val ^ XORValue;
__asm {
mr r7, r9
insrwi r7, r9, 16,0
rlwinm r6, r9, 24,16,23
extlwi r5, r7, 16,8
or r4, r5, r6
or r5, r4, r10
}
}
virtual char GetValue() {
__asm {
mullw r11, r11, r30
addi r11, r11, 1
mullw r10, r11, r30
srwi r5, r11, 8
addi r11, r10, 1
mullw r10, r11, r30
}
WCHAR val = Value ^ XORValue;
//swap out the xor value every time
XORValue = CallFunc(0, 0);
Value = val ^ XORValue;
__asm {
srwi r4, r11, 8
addi r11, r10, 1
mullw r10, r11, r30
addi r10, r10, 1
srwi r5, r11, 8
srwi r7, r10, 8
}
return val;
}
virtual int CallFunc(WCHAR FuncNum, WCHAR arg1) {
int returnVal = RandFunc();
switch (FuncNum) {
case 0:
returnVal = RandFunc();
break;
case 1:
SRandFunc(arg1);
break;
case 2:
returnVal = TimeFunc(arg1);
break;
default:
returnVal = RandFunc();
break;
}
return returnVal;
}
};
#endif