Skip to content

Commit 3b5a1db

Browse files
committed
refactor: migrate project to C++20 and improve client security
- change project standard to C++20 - add CProtection API - replace Sleep() with std::this_thread::sleep_for() - refactor get_hwid() to syscall functions - general code cleanup"
1 parent 3ef0703 commit 3b5a1db

30 files changed

+15959
-863
lines changed

Syscaller/crt.hpp

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#ifndef SYSCALL_CRT_HPP
2+
#define SYSCALL_CRT_HPP
3+
4+
#include <cstdint>
5+
#include <cwchar>
6+
7+
namespace syscall::crt
8+
{
9+
template<typename T, size_t N>
10+
[[nodiscard]] constexpr size_t getCountOf(T(&)[N]) noexcept
11+
{
12+
return N;
13+
}
14+
15+
namespace string
16+
{
17+
constexpr char toLower(char c) noexcept
18+
{
19+
return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c;
20+
}
21+
constexpr wchar_t toLower(wchar_t c) noexcept
22+
{
23+
return (c >= L'A' && c <= L'Z') ? (c + (L'a' - L'A')) : c;
24+
}
25+
26+
constexpr size_t getLength(const char* szStr) noexcept
27+
{
28+
const char* s = szStr;
29+
while (*s)
30+
++s;
31+
32+
return s - szStr;
33+
}
34+
35+
constexpr size_t getLength(const wchar_t* wzStr) noexcept
36+
{
37+
const wchar_t* s = wzStr;
38+
while (*s)
39+
++s;
40+
41+
return s - wzStr;
42+
}
43+
44+
[[nodiscard]] constexpr int compare(const char* szFirst, const char* szSecond) noexcept
45+
{
46+
while (*szFirst && (*szFirst == *szSecond))
47+
{
48+
szFirst++;
49+
szSecond++;
50+
}
51+
52+
return *(const unsigned char*)szFirst - *(const unsigned char*)szSecond;
53+
}
54+
55+
[[nodiscard]] constexpr int compareIgnoreCase(const wchar_t* szFirst, const wchar_t* szSecond) noexcept
56+
{
57+
wchar_t c1, c2;
58+
do {
59+
c1 = toLower(*szFirst++);
60+
c2 = toLower(*szSecond++);
61+
62+
if (c1 == L'\0')
63+
return c1 - c2;
64+
} while (c1 == c2);
65+
66+
return c1 - c2;
67+
}
68+
69+
[[nodiscard]] constexpr const char* findChar(const char* str, int character) noexcept
70+
{
71+
while (*str != '\0')
72+
{
73+
if (*str == static_cast<char>(character))
74+
return str;
75+
76+
str++;
77+
}
78+
return nullptr;
79+
}
80+
81+
[[nodiscard]] inline char* findChar(char* str, int character) noexcept
82+
{
83+
return const_cast<char*>(findChar(static_cast<const char*>(str), character));
84+
}
85+
86+
inline void copy(char* szDest, size_t uDestLength, const char* src) noexcept
87+
{
88+
if (!szDest || !uDestLength)
89+
return;
90+
91+
const size_t uSourceLength = getLength(src);
92+
93+
const size_t uCount = (uSourceLength < uDestLength) ? uSourceLength : (uDestLength - 1);
94+
std::copy_n(src, uCount, szDest);
95+
szDest[uCount] = '\0';
96+
}
97+
98+
inline void concat(wchar_t* pDest, size_t uSizeInElements, const wchar_t* pSource) noexcept
99+
{
100+
if (!pDest || !uSizeInElements)
101+
return;
102+
103+
const size_t uDestLength = getLength(pDest);
104+
if (uDestLength >= uSizeInElements - 1)
105+
return;
106+
107+
108+
const size_t uSourceLength = getLength(pSource);
109+
const size_t uRemainingSpace = uSizeInElements - uDestLength - 1;
110+
const size_t uCount = (uSourceLength < uRemainingSpace) ? uSourceLength : uRemainingSpace;
111+
112+
std::copy_n(pSource, uCount * sizeof(wchar_t), pDest + uDestLength);
113+
pDest[uDestLength + uCount] = L'\0';
114+
}
115+
116+
inline void mbToWcs(wchar_t* pDest, size_t uSizeInElements, const char* pSource) noexcept
117+
{
118+
if (!pDest || !uSizeInElements)
119+
return;
120+
121+
const size_t uSourceLength = getLength(pSource);
122+
const size_t uCount = (uSourceLength < uSizeInElements) ? uSourceLength : (uSizeInElements - 1);
123+
for (size_t i = 0; i < uCount; ++i)
124+
pDest[i] = static_cast<wchar_t>(static_cast<unsigned char>(pSource[i]));
125+
126+
pDest[uCount] = L'\0';
127+
}
128+
}
129+
}
130+
131+
#endif

Syscaller/hash.hpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#ifndef HASHING_HPP
2+
#define HASHING_HPP
3+
4+
#include <cstdint>
5+
#include <string>
6+
#include <bit>
7+
8+
namespace syscall::hashing
9+
{
10+
using Hash_t = uint64_t;
11+
12+
constexpr Hash_t getCompileTimeSeed()
13+
{
14+
Hash_t seed = 0;
15+
const char* szCurrentTime = __TIME__;
16+
const char* szCurrentDate = __DATE__;
17+
18+
for (int i = 0; szCurrentTime[i] != '\0'; ++i)
19+
seed = std::rotr(seed, 3) + szCurrentTime[i];
20+
21+
for (int i = 0; szCurrentDate[i] != '\0'; ++i)
22+
seed = std::rotr(seed, 5) + szCurrentDate[i];
23+
24+
return seed;
25+
}
26+
27+
constexpr Hash_t currentSeed = getCompileTimeSeed();
28+
constexpr Hash_t polyKey1 = 0xAF6F01BD5B2D7583ULL ^ currentSeed;
29+
constexpr Hash_t polyKey2 = 0xB4F281729182741DULL ^ std::rotr(currentSeed, 7);
30+
31+
consteval Hash_t calculateHash(const char* szData)
32+
{
33+
Hash_t hash = polyKey1;
34+
while (*szData)
35+
{
36+
hash ^= static_cast<Hash_t>(*szData++);
37+
hash += std::rotr(hash, 11) + polyKey2;
38+
}
39+
return hash;
40+
}
41+
42+
consteval Hash_t calculateHash(const char* szData, size_t uLength)
43+
{
44+
Hash_t hash = polyKey1;
45+
for (size_t i = 0; i < uLength && szData[i]; ++i)
46+
{
47+
hash ^= static_cast<Hash_t>(szData[i]);
48+
hash += std::rotr(hash, 11) + polyKey2;
49+
}
50+
return hash;
51+
}
52+
53+
54+
inline Hash_t calculateHashRuntime(const char* szData)
55+
{
56+
Hash_t hash = polyKey1;
57+
while (*szData)
58+
{
59+
hash ^= static_cast<Hash_t>(*szData++);
60+
hash += std::rotr(hash, 11) + polyKey2;
61+
}
62+
return hash;
63+
}
64+
65+
inline Hash_t calculateHashRuntime(const char* szData, size_t uLength)
66+
{
67+
Hash_t hash = polyKey1;
68+
for (size_t i = 0; i < uLength && szData[i]; ++i)
69+
{
70+
hash ^= static_cast<Hash_t>(szData[i]);
71+
hash += std::rotr(hash, 11) + polyKey2;
72+
}
73+
return hash;
74+
}
75+
}
76+
77+
#ifdef SYSCALLS_NO_HASH
78+
#define SYSCALL_ID(str) (str)
79+
#define SYSCALL_ID_RT(str) (str)
80+
#else
81+
#define SYSCALL_ID(str) (syscall::hashing::calculateHash(str))
82+
#define SYSCALL_ID_RT(str) (syscall::hashing::calculateHashRuntime(str))
83+
84+
#endif
85+
86+
#endif

0 commit comments

Comments
 (0)