Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
164 lines (134 loc) · 4.68 KB

File metadata and controls

164 lines (134 loc) · 4.68 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "precompiled_headers.h"
#include "Encrypter.h"
int Encrypter::encrypt(unsigned const char *keyBuffer, const int keyLength, unsigned char *encKeyBuffer, const int encKeyBufferLength)
{
int retVal = 0;
DATA_BLOB pDataOut;
DATA_BLOB pDataIn;
pDataIn.cbData = keyLength;
pDataIn.pbData = static_cast<BYTE *>(const_cast<unsigned char *>(keyBuffer));
HMODULE crypt32 = LoadLibrary(_T("crypt32.dll"));
if (crypt32 != NULL)
{
typedef BOOL (__stdcall * CryptProtectDataFunc)(DATA_BLOB*, LPCTSTR, DATA_BLOB*, PVOID, CRYPTPROTECT_PROMPTSTRUCT*, DWORD, DATA_BLOB*);
CryptProtectDataFunc cryptProtectData;
cryptProtectData = (CryptProtectDataFunc)GetProcAddress(crypt32, "CryptProtectData");
if (NULL != cryptProtectData)
{
BOOL success = cryptProtectData(&pDataIn, NULL, NULL, NULL, NULL, NULL, &pDataOut);
if (success && (encKeyBufferLength >= static_cast<int>(pDataOut.cbData)))
{
memcpy(encKeyBuffer, pDataOut.pbData, pDataOut.cbData);
retVal = pDataOut.cbData;
}
LocalFree(pDataOut.pbData);
}
}
return retVal;
}
bool Encrypter::convertToHex(const unsigned char *source, int sourceLength, TCHAR *hex, int bufferLength)
{
if (bufferLength < ((sourceLength * 2) + 1))
{
return false;
}
for (int pos = 0; pos < sourceLength; pos++)
{
_stprintf_s((hex + (pos*2)), bufferLength - (pos * 2), _T("%02x"), source[pos]);
}
hex[sourceLength * 2] = '\0';
return true;
}
bool Encrypter::convertFromHex(const TCHAR *hex, int hexLength, unsigned char *result, int resultLength)
{
bool retVal = true;
for(int pos = 0, resultPos = 0; pos < hexLength && resultPos < resultLength; pos += 2)
{
result[resultPos] = ((hex[pos] & 0x0F) + ((hex[pos] & 0x40) ? 9 : 0)) << 4;
result[resultPos++] |= (hex[pos+1] & 0x0F) + ((hex[pos+1] & 0x40) ? 9 : 0);
}
return retVal;
}
int Encrypter::decrypt(const unsigned char *encKeyBuffer, const int encKeyLength, unsigned char *keyBuffer, const int keyLength)
{
int retVal = 0;
DATA_BLOB pDataOut;
DATA_BLOB pDataIn;
pDataIn.cbData = encKeyLength;
pDataIn.pbData = static_cast<BYTE *>(const_cast<unsigned char *>(encKeyBuffer));
HMODULE crypt32 = LoadLibrary(_T("crypt32.dll"));
if (crypt32 != NULL)
{
typedef BOOL (__stdcall * CryptUnprotectDataFunc)(DATA_BLOB*, LPCTSTR, DATA_BLOB*, PVOID, CRYPTPROTECT_PROMPTSTRUCT*, DWORD, DATA_BLOB*);
CryptUnprotectDataFunc cryptUnprotectData;
cryptUnprotectData = (CryptUnprotectDataFunc)GetProcAddress(crypt32, "CryptUnprotectData");
if (NULL != cryptUnprotectData)
{
BOOL success = cryptUnprotectData(&pDataIn, NULL, NULL, NULL, NULL, NULL, &pDataOut);
if (success && (keyLength >= static_cast<int>(pDataOut.cbData)))
{
memcpy(keyBuffer, pDataOut.pbData, pDataOut.cbData);
retVal = pDataOut.cbData;
}
LocalFree(pDataOut.pbData);
}
}
return retVal;
}
int Encrypter::decryptHex(const TCHAR *encrypted, unsigned char *decryptBuffer, const int bufferLength)
{
int encryptedLength = _tcslen(encrypted);
int encBufferSize = (encryptedLength / 2) + 3;
unsigned char *encryptedBuffer = new unsigned char[encBufferSize];
convertFromHex(encrypted, encryptedLength, encryptedBuffer, encBufferSize);
int result = decrypt(encryptedBuffer, encryptedLength / 2, decryptBuffer, bufferLength);
if (bufferLength > result)
{
decryptBuffer[result] = '\0';
}
else
{
decryptBuffer[bufferLength] = '\0';
}
delete[] encryptedBuffer;
return result;
}
int Encrypter::encryptToHex(unsigned char *inBuffer, const int inLength, TCHAR *encHex, const int encHexBufferLength)
{
int encBufferLength = (inLength * 2) + 255;
unsigned char *encBuffer = new unsigned char[encBufferLength];
int encLength = encrypt(inBuffer, inLength, encBuffer, encBufferLength);
convertToHex(encBuffer, encLength, encHex, encHexBufferLength);
delete[] encBuffer;
return encLength;
}
/*
bool getKey(unsigned char *buffer, int bufferSize)
{
TCHAR encKeyBufferHex[1000];
unsigned char encKeyBuffer[500];
unsigned char keyBuffer[16];
int len = ::GetPrivateProfileString(SETTINGS_GROUP, KEY_KEY, _T(""), encKeyBufferHex, 1000, iniFilePath);
if (len == 0)
{
generateKey(keyBuffer, 16);
int encryptedSize = encryptKey(keyBuffer, 16, encKeyBuffer, 500);
convertToHex(encKeyBuffer, encryptedSize, encKeyBufferHex, 1000);
::WritePrivateProfileString(SETTINGS_GROUP, KEY_KEY, encKeyBufferHex, iniFilePath);
}
else
{
convertFromHex(encKeyBufferHex, _tcslen(encKeyBufferHex), encKeyBuffer, 500);
decryptKey(encKeyBuffer, keyBuffer, 16);
}
if (bufferSize >= 16)
{
memcpy(buffer, keyBuffer, 16);
return true;
}
else
{
return false;
}
}
*/
Morty Proxy This is a proxified and sanitized view of the page, visit original site.