This repository has been archived by the owner on Jul 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
avkmgr.c
290 lines (250 loc) · 7.48 KB
/
avkmgr.c
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#include "ntddk.h"
#include "gdata.h"
#include "avkmgr.h"
#pragma warning(disable:4054)
ULONG g_dwMajorVersion= 0;
ULONG g_dwMinorVersion= 0;
//************************************************************************************************************
// 创建作者 : Tennn
// 修改时间 : 2017/11/25 22:27
// 函数功能 : 驱动入口
//************************************************************************************************************
NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject , _In_ PUNICODE_STRING RegistryPath) {
UNICODE_STRING DeviceName={ 0 };
PDEVICE_OBJECT DeviceObject={ 0 };
UNREFERENCED_PARAMETER(RegistryPath);
OSVERSIONINFOEXW os ={ 0 };
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
RtlGetVersion((POSVERSIONINFOW)&os);
if (os.dwMajorVersion < 5 || os.dwMajorVersion == 5 && !os.dwMinorVersion) {
return 0x0C0000002;
}
g_dwMajorVersion = os.dwMajorVersion;
g_dwMinorVersion = os.dwMinorVersion;
sub_140001718();
avk_GetSystemRoutineAddress();
func9();
if (g_FunTable.sub_100) {
g_FunTable.sub_100(sub_140001390 , 0);
}
else {
g_FunTable.sub_F8(sub_14000130C , 0);
}
g_FunTable.sub_108(sub_140001414);
g_FunTable.sub_110(sub_140001608);
RtlInitUnicodeString(&DeviceName , avk_SystemRoutineName(0x3b));
IoCreateDevice(DriverObject , 0 , &DeviceName , 0x22u , 0x100u , 0 , &DeviceObject);
funcc.field_1C = 1;
avk_IoErrorLog(L"avkmgr.sys successfully loaded" , 0x40070011 , DriverObject);
return 0;
}
extern AVKMGR_EXPORT NTSTATUS func0(__int64 Exchange) {
for (int i = 0; i < 4; i++) {
if (!_InterlockedCompareExchange64((volatile LONG64 *)(&g_FunTable.sub_1F0)[i] , Exchange , 0)) {
return 0;
}
}
return 0x0C0000001;
}
extern AVKMGR_EXPORT NTSTATUS func1(__int64 Exchange) {
for (int i = 0; i < 4; i++) {
if (!_InterlockedCompareExchange64((volatile LONG64 *)(&g_FunTable.sub_210)[i] , Exchange , 0)) {
return 0;
}
}
return 0x0C0000001;
}
extern AVKMGR_EXPORT NTSTATUS func2(__int64 Exchange) {
for (int i = 0; i < 4; i++) {
if (!_InterlockedCompareExchange64((volatile LONG64 *)(&g_FunTable.sub_230)[i] , Exchange , 0)) {
return 0;
}
}
return 0x0C0000001;
}
extern AVKMGR_EXPORT NTSTATUS func3(__int64 Exchange) {
for (int i = 0; i < 4; i++) {
if (!_InterlockedCompareExchange64((volatile LONG64 *)(&g_FunTable.sub_250)[i] , Exchange , 0)) {
return 0;
}
}
return 0x0C0000001;
}
extern AVKMGR_EXPORT NTSTATUS func4(__int64 Exchange) {
for (int i = 0; i < 4; i++) {
if (Exchange == _InterlockedCompareExchange64((volatile LONG64 *)(&g_FunTable.sub_1F0)[i] , 0 , Exchange)) {
return 0;
}
}
return 0x0C0000001;
}
extern AVKMGR_EXPORT NTSTATUS func5(__int64 Exchange) {
for (int i = 0; i < 4; i++) {
if (!_InterlockedCompareExchange64((volatile LONG64 *)(&g_FunTable.sub_210)[i] , Exchange , 0)) {
return 0;
}
}
return 0x0C0000001;
}
extern AVKMGR_EXPORT NTSTATUS func6(__int64 Exchange) {
for (int i = 0; i < 4; i++) {
if (Exchange == _InterlockedCompareExchange64((volatile LONG64 *)(&g_FunTable.sub_230)[i] , 0 , Exchange)) {
return 0;
}
}
return 0x0C0000001;
}
extern AVKMGR_EXPORT NTSTATUS func7(__int64 Exchange) {
for (int i = 0; i < 4; i++) {
if (Exchange == _InterlockedCompareExchange64((volatile LONG64 *)(&g_FunTable.sub_250)[i] , 0 , Exchange)) {
return 0;
}
}
return 0x0C0000001;
}
extern AVKMGR_EXPORT NTSTATUS func8() {
return 0;
}
extern AVKMGR_EXPORT NTSTATUS func9() {
return 0;
}
extern AVKMGR_EXPORT NTSTATUS funca() {
return 0;
}
void sub_140001718() {
unsigned short *loc_word_140004024 = (unsigned short *)word_140004024;
unsigned short *loc_word_140005204 = (unsigned short *)word_140005204;
sub_14000168C();
for (int i = 0 , j = 0; i < 0x6d; i++) {
g_SystemRoutineName[i] = loc_word_140004024;
for (j = 0; loc_word_140004024[j]; j++);
loc_word_140004024 = &loc_word_140004024[j];
}
dword_140004020 = 1;
for (int i = 0 , j = 0; i < 0x2a; i++) {
qword_140005860[i] = loc_word_140005204;
for (j = 0; loc_word_140005204[j]; j++);
loc_word_140005204 = &loc_word_140005204[j];
}
dword_140005200 = 1;
}
void avk_GetSystemRoutineAddress() {
UNICODE_STRING SystemRoutineName={ 0 };
int FunNumber[] ={
6, 7, 8, 9,
0xa, 2, 3, 5,
0xc, 0xd,
0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
4, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26,1 ,
0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, };
if (g_dwMajorVersion < 6) {
g_FunTable.field_0 = 0;
g_FunTable.field_10 = 0;
g_FunTable.field_18 = 0;
}
for (int i = 0; i < 0x38; i++) {
if (!(&g_FunTable.field_0)[i]) {
RtlInitUnicodeString(&SystemRoutineName , avk_SystemRoutineName(FunNumber[i]));
(&g_FunTable.field_0)[i] = MmGetSystemRoutineAddress(&SystemRoutineName);
}
}
if (g_dwMajorVersion < 6) {
g_FunTable.field_0 = 0;
g_FunTable.field_10 = 0;
g_FunTable.field_18 = 0;
}
}
void* sub_140001390(void *a1 , void *a2 , void *a3) {
if (g_FunTable.sub_1F0) {
g_FunTable.sub_1F0();
}
for (int i = 0; i < 3; i++) {
g_FunTable.sub_1F8[i](a1 , a2 , a3);
}
return &g_FunTable.sub_210;
}
void* sub_14000130C(void *a1 , void *a2 , void *a3) {
if (g_FunTable.sub_210) {
g_FunTable.sub_210();
}
for (int i = 0; i < 3; i++) {
g_FunTable.sub_218[i](a1 , a2 , a3);
}
return &g_FunTable.sub_230;
}
void* sub_140001414(void *a1 , void *a2 , void *a3) {
if (g_FunTable.sub_230) {
g_FunTable.sub_230();
}
for (int i = 0; i < 3; i++) {
g_FunTable.sub_238[i](a1 , a2 , a3);
}
return &g_FunTable.sub_250;
}
void* sub_140001608(void *a1 , void *a2 , void *a3) {
if (g_FunTable.sub_250) {
g_FunTable.sub_250();
}
for (int i = 0; i < 3; i++) {
g_FunTable.sub_258[i](a1 , a2 , a3);
}
return &g_FunTable.sub_270;
}
WCHAR * avk_SystemRoutineName(int FunNumber) {
if (FunNumber > 0x6d || !dword_140004020) {
return 0;
}
return g_SystemRoutineName[FunNumber];
}
void avk_IoErrorLog(WCHAR *a1 , int a2 , PDRIVER_OBJECT DriverObject) {
struct ERRORLOGENTRY {
int field_0;
int field_4;
__int16 field_8;
__int16 field_A;
int field_C;
int field_10;
__unaligned __declspec(align(1)) __int64 field_14;
int field_1C;
__int64 field_20;
__int64 field_28;
__int64 field_30;
char field_38[184];
}*pErrorLogEntry;
UNICODE_STRING ustring ={ 0 };
RtlInitUnicodeString(&ustring , a1);
UCHAR EntrySize = (UCHAR)(ustring.Length + 0x32);
if (EntrySize > 0xf0) {
return;
}
pErrorLogEntry = IoAllocateErrorLogEntry(DriverObject , EntrySize);
if (!pErrorLogEntry) {
return;
}
pErrorLogEntry->field_C = a2;
pErrorLogEntry->field_14 = 0;
pErrorLogEntry->field_0 = 0;
pErrorLogEntry->field_10 = 0;
pErrorLogEntry->field_4 = 0x300001;
pErrorLogEntry->field_8 = 0;
pErrorLogEntry->field_1C = 0;
memmove(&pErrorLogEntry->field_30 , ustring.Buffer , ustring.Length);
*(USHORT *)((UCHAR *)pErrorLogEntry->field_30 + ustring.Length) = 0;
IoWriteErrorLogEntry(pErrorLogEntry);
}
void sub_14000168C() {
int i = 0;
short data = 0x57a9;
unsigned short *loc_word_140004024 = (unsigned short *)word_140004024;
unsigned short *loc_word_140005204 = (unsigned short *)word_140005204;
for (; loc_word_140004024[i] != 0x57a9 || loc_word_140004024[i + 1] != 0x57a9; i++ , data += 0x307) {
loc_word_140004024[i] ^= data;
}
loc_word_140004024[i] = 0;
for (i = 0 , data = 0x57a9; loc_word_140005204[i] != 0x57a9 || loc_word_140005204[i + 1] != 0x57a9; i++) {
loc_word_140005204[i] ^= data;
}
loc_word_140005204[i] = 0;
}