-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcppRuntime.cpp
More file actions
154 lines (131 loc) · 3.49 KB
/
cppRuntime.cpp
File metadata and controls
154 lines (131 loc) · 3.49 KB
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
#include "DriverPCH.hpp"
_IRQL_requires_max_(DISPATCH_LEVEL)
void* __cdecl operator new(size_t Size, POOL_TYPE PoolType, ULONG Tag) noexcept
{
return ExAllocatePoolUninitialized(PoolType, Size, Tag);
}
_IRQL_requires_max_(DISPATCH_LEVEL)
void* __cdecl operator new[](size_t Size, POOL_TYPE PoolType, ULONG Tag) noexcept
{
return ExAllocatePoolUninitialized(PoolType, Size, Tag);
}
_IRQL_requires_max_(DISPATCH_LEVEL)
void* __cdecl operator new(size_t Size)
{
return ExAllocatePoolUninitialized(NonPagedPool, Size, CppRuntimeTag);
}
_IRQL_requires_max_(DISPATCH_LEVEL)
void* __cdecl operator new[](size_t Size)
{
return ExAllocatePoolUninitialized(NonPagedPool, Size, CppRuntimeTag);
}
_IRQL_requires_max_(DISPATCH_LEVEL)
void __cdecl operator delete(void* Ptr) noexcept
{
if (Ptr)
{
ExFreePool(Ptr);
}
}
_IRQL_requires_max_(DISPATCH_LEVEL)
void __cdecl operator delete[](void* Ptr) noexcept
{
if (Ptr)
{
ExFreePool(Ptr);
}
}
_IRQL_requires_max_(DISPATCH_LEVEL)
void __cdecl operator delete(void* Ptr, size_t) noexcept
{
if (Ptr)
{
ExFreePool(Ptr);
}
}
_IRQL_requires_max_(DISPATCH_LEVEL)
void __cdecl operator delete[](void* Ptr, size_t) noexcept
{
if (Ptr)
{
ExFreePool(Ptr);
}
}
_IRQL_requires_max_(DISPATCH_LEVEL)
void __cdecl operator delete(void* Ptr, ULONG Tag) noexcept
{
if (Ptr)
{
ExFreePoolWithTag(Ptr, Tag);
}
}
_IRQL_requires_max_(DISPATCH_LEVEL)
void __cdecl operator delete[](void* Ptr, ULONG Tag) noexcept
{
if (Ptr)
{
ExFreePoolWithTag(Ptr, Tag);
}
}
using _PVFV = void(__cdecl*)();
using _PIFV = int(__cdecl*)();
#pragma section(".CRT$XCA", long, read)
#pragma section(".CRT$XCZ", long, read)
#pragma section(".CRT$XIA", long, read)
#pragma section(".CRT$XIZ", long, read)
#pragma section(".CRT$XTA", long, read)
#pragma section(".CRT$XTZ", long, read)
__declspec(allocate(".CRT$XCA")) _PVFV __xc_a[] = { nullptr };
__declspec(allocate(".CRT$XCZ")) _PVFV __xc_z[] = { nullptr };
__declspec(allocate(".CRT$XIA")) _PIFV __xi_a[] = { nullptr };
__declspec(allocate(".CRT$XIZ")) _PIFV __xi_z[] = { nullptr };
__declspec(allocate(".CRT$XTA")) _PVFV __xt_a[] = { nullptr };
__declspec(allocate(".CRT$XTZ")) _PVFV __xt_z[] = { nullptr };
#pragma comment(linker, "/merge:.CRT=.rdata")
extern "C" void __cdecl _initterm(_PVFV* pfbegin, _PVFV* pfend)
{
while (pfbegin < pfend)
{
if (*pfbegin != nullptr)
{
(**pfbegin)();
}
++pfbegin;
}
}
extern "C" int __cdecl _initterm_e(_PIFV* pfbegin, _PIFV* pfend)
{
while (pfbegin < pfend)
{
if (*pfbegin != nullptr)
{
int result = (**pfbegin)();
if (result != 0)
{
return result;
}
}
++pfbegin;
}
return 0;
}
extern "C" NTSTATUS DriverCppInitialize()
{
if (_initterm_e(__xi_a, __xi_z) != 0)
{
return STATUS_UNSUCCESSFUL;
}
_initterm(__xc_a, __xc_z);
KdPrint(("[SimpleAntiCheat] C++ runtime initialized\n"));
return STATUS_SUCCESS;
}
// Note: This may introduce complexities with standard DriverUnload cleanup if C++ destructors rely on other kernel resources that may have already been cleaned up by the time this is called.
// Use with caution and ensure proper ordering of cleanup in DriverUnload.
extern "C" void DriverCppCleanup()
{
KdPrint(("[SimpleAntiCheat] C++ runtime cleanup\n"));
}
extern "C" int __cdecl atexit(void(__cdecl*)(void))
{
return 0;
}