forked from spender-sandbox/cuckoomon-modified
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hook_reg.c
650 lines (585 loc) · 21.4 KB
/
hook_reg.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/*
Cuckoo Sandbox - Automated Malware Analysis
Copyright (C) 2010-2015 Cuckoo Sandbox Developers, Optiv, Inc. ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "ntapi.h"
#include "hooking.h"
#include "misc.h"
#include "log.h"
#include "config.h"
HOOKDEF(LONG, WINAPI, RegOpenKeyExA,
__in HKEY hKey,
__in_opt LPCTSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
) {
HKEY saved_hkey = phkResult ? *phkResult : INVALID_HANDLE_VALUE;
LONG ret = Old_RegOpenKeyExA(hKey, lpSubKey, ulOptions, samDesired,
phkResult);
// fake the absence of some keys
if (!g_config.no_stealth && (ret == ERROR_SUCCESS || ret == ERROR_ACCESS_DENIED)) {
unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN;
PKEY_NAME_INFORMATION keybuf = malloc(allocsize);
wchar_t *keypath = get_full_key_pathA(hKey, lpSubKey, keybuf, allocsize);
int i;
wchar_t *hidden_keys[] = {
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT"
};
for (i = 0; i < _countof(hidden_keys); ++i) {
if (!wcsicmp(keypath, hidden_keys[i])) {
lasterror_t errors;
// clean up state to avoid leaking information
if (ret == ERROR_SUCCESS && phkResult) {
RegCloseKey(*phkResult);
*phkResult = saved_hkey;
}
ret = errors.Win32Error = ERROR_FILE_NOT_FOUND;
errors.NtstatusError = STATUS_OBJECT_NAME_NOT_FOUND;
set_lasterrors(&errors);
break;
}
}
free(keybuf);
}
LOQ_zero("registry", "psPe", "Registry", hKey, "SubKey", lpSubKey, "Handle", phkResult,
"FullName", hKey, lpSubKey);
return ret;
}
HOOKDEF(LONG, WINAPI, RegOpenKeyExW,
__in HKEY hKey,
__in_opt LPWSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
) {
HKEY saved_hkey = phkResult ? *phkResult : INVALID_HANDLE_VALUE;
LONG ret = Old_RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired,
phkResult);
// fake the absence of some keys
if (!g_config.no_stealth && (ret == ERROR_SUCCESS || ret == ERROR_ACCESS_DENIED)) {
unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN;
PKEY_NAME_INFORMATION keybuf = malloc(allocsize);
wchar_t *keypath = get_full_key_pathW(hKey, lpSubKey, keybuf, allocsize);
int i;
wchar_t *hidden_keys[] = {
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT"
};
for (i = 0; i < _countof(hidden_keys); ++i) {
if (!wcsicmp(keypath, hidden_keys[i])) {
lasterror_t errors;
// clean up state to avoid leaking information
if (ret == ERROR_SUCCESS && phkResult) {
RegCloseKey(*phkResult);
*phkResult = saved_hkey;
}
ret = errors.Win32Error = ERROR_FILE_NOT_FOUND;
errors.NtstatusError = STATUS_OBJECT_NAME_NOT_FOUND;
set_lasterrors(&errors);
break;
}
}
free(keybuf);
}
LOQ_zero("registry", "puPE", "Registry", hKey, "SubKey", lpSubKey, "Handle", phkResult,
"FullName", hKey, lpSubKey);
return ret;
}
HOOKDEF(LONG, WINAPI, RegCreateKeyExA,
__in HKEY hKey,
__in LPCTSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPTSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
) {
LONG ret;
ENSURE_DWORD(lpdwDisposition);
ret = Old_RegCreateKeyExA(hKey, lpSubKey, Reserved, lpClass,
dwOptions, samDesired, lpSecurityAttributes, phkResult,
lpdwDisposition);
// fake the absence of some keys
if (!g_config.no_stealth && ret == ERROR_SUCCESS && *lpdwDisposition == REG_OPENED_EXISTING_KEY) {
unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN;
PKEY_NAME_INFORMATION keybuf = malloc(allocsize);
wchar_t *keypath = get_full_key_pathA(hKey, lpSubKey, keybuf, allocsize);
int i;
wchar_t *hidden_keys[] = {
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT"
};
for (i = 0; i < _countof(hidden_keys); ++i) {
if (!wcsicmp(keypath, hidden_keys[i])) {
*lpdwDisposition = REG_CREATED_NEW_KEY;
break;
}
}
free(keybuf);
}
LOQ_zero("registry", "psshPeI", "Registry", hKey, "SubKey", lpSubKey, "Class", lpClass,
"Access", samDesired, "Handle", phkResult, "FullName", hKey, lpSubKey,
"Disposition", lpdwDisposition);
return ret;
}
HOOKDEF(LONG, WINAPI, RegCreateKeyExW,
__in HKEY hKey,
__in LPWSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPWSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
) {
LONG ret;
ENSURE_DWORD(lpdwDisposition);
ret = Old_RegCreateKeyExW(hKey, lpSubKey, Reserved, lpClass,
dwOptions, samDesired, lpSecurityAttributes, phkResult,
lpdwDisposition);
// fake the absence of some keys
if (!g_config.no_stealth && ret == ERROR_SUCCESS && *lpdwDisposition == REG_OPENED_EXISTING_KEY) {
unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN;
PKEY_NAME_INFORMATION keybuf = malloc(allocsize);
wchar_t *keypath = get_full_key_pathW(hKey, lpSubKey, keybuf, allocsize);
int i;
wchar_t *hidden_keys[] = {
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT"
};
for (i = 0; i < _countof(hidden_keys); ++i) {
if (!wcsicmp(keypath, hidden_keys[i])) {
*lpdwDisposition = REG_CREATED_NEW_KEY;
break;
}
}
free(keybuf);
}
LOQ_zero("registry", "puuhPEI", "Registry", hKey, "SubKey", lpSubKey, "Class", lpClass,
"Access", samDesired, "Handle", phkResult, "FullName", hKey, lpSubKey,
"Disposition", lpdwDisposition);
return ret;
}
HOOKDEF(LONG, WINAPI, RegDeleteKeyA,
__in HKEY hKey,
__in LPCTSTR lpSubKey
) {
LONG ret = Old_RegDeleteKeyA(hKey, lpSubKey);
LOQ_zero("registry", "pse", "Handle", hKey, "SubKey", lpSubKey,
"FullName", hKey, lpSubKey);
return ret;
}
HOOKDEF(LONG, WINAPI, RegDeleteKeyW,
__in HKEY hKey,
__in LPWSTR lpSubKey
) {
LONG ret = Old_RegDeleteKeyW(hKey, lpSubKey);
LOQ_zero("registry", "puE", "Handle", hKey, "SubKey", lpSubKey,
"FullName", hKey, lpSubKey);
return ret;
}
HOOKDEF(LONG, WINAPI, RegEnumKeyW,
__in HKEY hKey,
__in DWORD dwIndex,
__out LPWSTR lpName,
__in DWORD cchName
) {
LONG ret = Old_RegEnumKeyW(hKey, dwIndex, lpName, cchName);
// fake the absence of some keys
if (!g_config.no_stealth && ret == ERROR_SUCCESS) {
unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN;
PKEY_NAME_INFORMATION keybuf = malloc(allocsize);
wchar_t *keypath = get_full_key_pathW(hKey, NULL, keybuf, allocsize);
int i, j;
wchar_t *parent_keys[] = {
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT",
};
wchar_t *replace_subkeys[] = {
L"VBOX__", L"DELL__",
L"VBOX__", L"DELL__",
L"VBOX__", L"DELL__"
};
for (i = 0, j = 0; i < _countof(parent_keys); i += 1, j += 2) {
if (!wcsicmp(keypath, parent_keys[i]) && !wcsicmp(lpName, replace_subkeys[j])) {
wcscpy(lpName, replace_subkeys[j + 1]);
break;
}
}
free(keybuf);
}
LOQ_zero("registry", "piuE", "Handle", hKey, "Index", dwIndex, "Name", ret ? L"" : lpName,
"FullName", hKey, ret ? L"" : lpName);
return ret;
}
HOOKDEF(LONG, WINAPI, RegEnumKeyExA,
__in HKEY hKey,
__in DWORD dwIndex,
__out LPTSTR lpName,
__inout LPDWORD lpcName,
__reserved LPDWORD lpReserved,
__inout LPTSTR lpClass,
__inout_opt LPDWORD lpcClass,
__out_opt PFILETIME lpftLastWriteTime
) {
LONG ret = Old_RegEnumKeyExA(hKey, dwIndex, lpName, lpcName, lpReserved,
lpClass, lpcClass, lpftLastWriteTime);
// fake the absence of some keys
if (!g_config.no_stealth && ret == ERROR_SUCCESS) {
unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN;
PKEY_NAME_INFORMATION keybuf = malloc(allocsize);
wchar_t *keypath = get_full_key_pathA(hKey, NULL, keybuf, allocsize);
int i, j;
wchar_t *parent_keys[] = {
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT"
};
char *replace_subkeys[] = {
"VBOX__", "DELL__",
"VBOX__", "DELL__",
"VBOX__", "DELL__"
};
for (i = 0, j = 0; i < _countof(parent_keys); i += 1, j += 2) {
if (!wcsicmp(keypath, parent_keys[i]) && !stricmp(lpName, replace_subkeys[j])) {
strcpy(lpName, replace_subkeys[j + 1]);
break;
}
}
free(keybuf);
}
LOQ_zero("registry", "pisse", "Handle", hKey, "Index", dwIndex, "Name", ret ? "" : lpName,
"Class", ret ? "" : lpClass, "FullName", hKey, ret ? "" : lpName);
return ret;
}
HOOKDEF(LONG, WINAPI, RegEnumKeyExW,
__in HKEY hKey,
__in DWORD dwIndex,
__out LPWSTR lpName,
__inout LPDWORD lpcName,
__reserved LPDWORD lpReserved,
__inout LPWSTR lpClass,
__inout_opt LPDWORD lpcClass,
__out_opt PFILETIME lpftLastWriteTime
) {
LONG ret = Old_RegEnumKeyExW(hKey, dwIndex, lpName, lpcName, lpReserved,
lpClass, lpcClass, lpftLastWriteTime);
// fake the absence of some keys
if (!g_config.no_stealth && ret == ERROR_SUCCESS) {
unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN;
PKEY_NAME_INFORMATION keybuf = malloc(allocsize);
wchar_t *keypath = get_full_key_pathW(hKey, NULL, keybuf, allocsize);
int i, j;
wchar_t *parent_keys[] = {
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT",
L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT",
};
wchar_t *replace_subkeys[] = {
L"VBOX__", L"DELL__",
L"VBOX__", L"DELL__",
L"VBOX__", L"DELL__"
};
for (i = 0, j = 0; i < _countof(parent_keys); i += 1, j += 2) {
if (!wcsicmp(keypath, parent_keys[i]) && !wcsicmp(lpName, replace_subkeys[j])) {
wcscpy(lpName, replace_subkeys[j + 1]);
break;
}
}
free(keybuf);
}
LOQ_zero("registry", "piuuE", "Handle", hKey, "Index", dwIndex, "Name", ret ? L"" : lpName,
"Class", ret ? L"" : lpClass, "FullName", hKey, ret ? L"" : lpName);
return ret;
}
HOOKDEF(LONG, WINAPI, RegEnumValueA,
__in HKEY hKey,
__in DWORD dwIndex,
__out LPTSTR lpValueName,
__inout LPDWORD lpcchValueName,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpType,
__out_opt LPBYTE lpData,
__inout_opt LPDWORD lpcbData
) {
LONG ret;
ENSURE_DWORD(lpType);
ret = Old_RegEnumValueA(hKey, dwIndex, lpValueName, lpcchValueName,
lpReserved, lpType, lpData, lpcbData);
if(ret == ERROR_SUCCESS && lpType != NULL && lpData != NULL &&
lpcbData != NULL) {
LOQ_zero("registry", "pisre", "Handle", hKey, "Index", dwIndex,
"ValueName", lpValueName, "Data", *lpType, *lpcbData, lpData,
"FullName", hKey, lpValueName);
}
else {
LOQ_zero("registry", "pisIIe", "Handle", hKey, "Index", dwIndex,
"ValueName", ret == ERROR_SUCCESS ? lpValueName : "", "Type", lpType, "DataLength", lpcbData,
"FullName", hKey, ret == ERROR_SUCCESS ? lpValueName : "");
}
return ret;
}
HOOKDEF(LONG, WINAPI, RegEnumValueW,
__in HKEY hKey,
__in DWORD dwIndex,
__out LPWSTR lpValueName,
__inout LPDWORD lpcchValueName,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpType,
__out_opt LPBYTE lpData,
__inout_opt LPDWORD lpcbData
) {
LONG ret;
ENSURE_DWORD(lpType);
ret = Old_RegEnumValueW(hKey, dwIndex, lpValueName, lpcchValueName,
lpReserved, lpType, lpData, lpcbData);
if(ret == ERROR_SUCCESS && lpType != NULL && lpData != NULL &&
lpcbData != NULL) {
LOQ_zero("registry", "piuRE", "Handle", hKey, "Index", dwIndex,
"ValueName", lpValueName, "Data", *lpType, *lpcbData, lpData,
"FullName", hKey, lpValueName);
}
else {
LOQ_zero("registry", "piuIIE", "Handle", hKey, "Index", dwIndex,
"ValueName", ret == ERROR_SUCCESS ? lpValueName : L"", "Type", lpType, "DataLength", lpcbData,
"FullName", hKey, ret == ERROR_SUCCESS ? lpValueName : L"");
}
return ret;
}
HOOKDEF(LONG, WINAPI, RegSetValueExA,
__in HKEY hKey,
__in_opt LPCTSTR lpValueName,
__reserved DWORD Reserved,
__in DWORD dwType,
__in const BYTE *lpData,
__in DWORD cbData
) {
LONG ret = Old_RegSetValueExA(hKey, lpValueName, Reserved, dwType, lpData,
cbData);
if(ret == ERROR_SUCCESS) {
LOQ_zero("registry", "psiriv", "Handle", hKey, "ValueName", lpValueName, "Type", dwType,
"Buffer", dwType, cbData, lpData, "BufferLength", cbData,
"FullName", hKey, lpValueName);
}
else {
LOQ_zero("registry", "psiv", "Handle", hKey, "ValueName", lpValueName, "Type", dwType,
"FullName", hKey, lpValueName);
}
return ret;
}
HOOKDEF(LONG, WINAPI, RegSetValueExW,
__in HKEY hKey,
__in_opt LPWSTR lpValueName,
__reserved DWORD Reserved,
__in DWORD dwType,
__in const BYTE *lpData,
__in DWORD cbData
) {
LONG ret = Old_RegSetValueExW(hKey, lpValueName, Reserved, dwType, lpData,
cbData);
if(ret == ERROR_SUCCESS) {
LOQ_zero("registry", "puiRiV", "Handle", hKey, "ValueName", lpValueName, "Type", dwType,
"Buffer", dwType, cbData, lpData, "BufferLength", cbData,
"FullName", hKey, lpValueName);
}
else {
LOQ_zero("registry", "puiV", "Handle", hKey, "ValueName", lpValueName, "Type", dwType,
"FullName", hKey, lpValueName);
}
return ret;
}
HOOKDEF(LONG, WINAPI, RegQueryValueExA,
__in HKEY hKey,
__in_opt LPCTSTR lpValueName,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpType,
__out_opt LPBYTE lpData,
__inout_opt LPDWORD lpcbData
) {
LONG ret;
ENSURE_DWORD(lpType);
ret = Old_RegQueryValueExA(hKey, lpValueName, lpReserved, lpType,
lpData, lpcbData);
if(ret == ERROR_SUCCESS && lpType != NULL && lpData != NULL &&
lpcbData != NULL) {
unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN;
PKEY_NAME_INFORMATION keybuf = malloc(allocsize);
wchar_t *keypath = get_full_keyvalue_pathA(hKey, lpValueName, keybuf, allocsize);
LOQ_zero("registry", "psru", "Handle", hKey, "ValueName", lpValueName,
"Data", *lpType, *lpcbData, lpData,
"FullName", keypath);
// fake some values
if (!g_config.no_stealth)
perform_ascii_registry_fakery(keypath, lpData, *lpcbData);
free(keybuf);
}
else if (ret == ERROR_MORE_DATA) {
LOQ_zero("registry", "psPIv", "Handle", hKey, "ValueName", lpValueName,
"Type", lpType, "DataLength", lpcbData,
"FullName", hKey, lpValueName);
}
else {
LOQ_zero("registry", "psv", "Handle", hKey, "ValueName", lpValueName,
"FullName", hKey, lpValueName);
}
return ret;
}
HOOKDEF(LONG, WINAPI, RegQueryValueExW,
__in HKEY hKey,
__in_opt LPWSTR lpValueName,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpType,
__out_opt LPBYTE lpData,
__inout_opt LPDWORD lpcbData
) {
LONG ret;
ENSURE_DWORD(lpType);
ret = Old_RegQueryValueExW(hKey, lpValueName, lpReserved, lpType,
lpData, lpcbData);
if (ret == ERROR_SUCCESS && lpType != NULL && lpData != NULL &&
lpcbData != NULL) {
unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN;
PKEY_NAME_INFORMATION keybuf = malloc(allocsize);
wchar_t *keypath = get_full_keyvalue_pathW(hKey, lpValueName, keybuf, allocsize);
LOQ_zero("registry", "puRu", "Handle", hKey, "ValueName", lpValueName,
"Data", *lpType, *lpcbData, lpData,
"FullName", keypath);
// fake some values
if (!g_config.no_stealth)
perform_unicode_registry_fakery(keypath, lpData, *lpcbData);
free(keybuf);
}
else if (ret == ERROR_MORE_DATA) {
LOQ_zero("registry", "puPIV", "Handle", hKey, "ValueName", lpValueName,
"Type", lpType, "DataLength", lpcbData,
"FullName", hKey, lpValueName);
}
else {
LOQ_zero("registry", "puV", "Handle", hKey, "ValueName", lpValueName,
"FullName", hKey, lpValueName);
}
return ret;
}
HOOKDEF(LONG, WINAPI, RegDeleteValueA,
__in HKEY hKey,
__in_opt LPCTSTR lpValueName
) {
LONG ret = Old_RegDeleteValueA(hKey, lpValueName);
LOQ_zero("registry", "psv", "Handle", hKey, "ValueName", lpValueName,
"FullName", hKey, lpValueName);
return ret;
}
HOOKDEF(LONG, WINAPI, RegDeleteValueW,
__in HKEY hKey,
__in_opt LPWSTR lpValueName
) {
LONG ret = Old_RegDeleteValueW(hKey, lpValueName);
LOQ_zero("registry", "puV", "Handle", hKey, "ValueName", lpValueName,
"FullName", hKey, lpValueName);
return ret;
}
HOOKDEF(LONG, WINAPI, RegQueryInfoKeyA,
_In_ HKEY hKey,
_Out_opt_ LPTSTR lpClass,
_Inout_opt_ LPDWORD lpcClass,
_Reserved_ LPDWORD lpReserved,
_Out_opt_ LPDWORD lpcSubKeys,
_Out_opt_ LPDWORD lpcMaxSubKeyLen,
_Out_opt_ LPDWORD lpcMaxClassLen,
_Out_opt_ LPDWORD lpcValues,
_Out_opt_ LPDWORD lpcMaxValueNameLen,
_Out_opt_ LPDWORD lpcMaxValueLen,
_Out_opt_ LPDWORD lpcbSecurityDescriptor,
_Out_opt_ PFILETIME lpftLastWriteTime
) {
LONG ret = Old_RegQueryInfoKeyA(hKey, lpClass, lpcClass, lpReserved,
lpcSubKeys, lpcMaxSubKeyLen, lpcMaxClassLen, lpcValues,
lpcMaxValueNameLen, lpcMaxValueLen, lpcbSecurityDescriptor,
lpftLastWriteTime);
LOQ_zero("registry", "pS6I", "KeyHandle", hKey, "Class", lpcClass ? *lpcClass : 0, lpClass,
"SubKeyCount", lpcSubKeys, "MaxSubKeyLength", lpcMaxSubKeyLen,
"MaxClassLength", lpcMaxClassLen, "ValueCount", lpcValues,
"MaxValueNameLength", lpcMaxValueNameLen,
"MaxValueLength", lpcMaxValueLen);
return ret;
}
HOOKDEF(LONG, WINAPI, RegQueryInfoKeyW,
_In_ HKEY hKey,
_Out_opt_ LPWSTR lpClass,
_Inout_opt_ LPDWORD lpcClass,
_Reserved_ LPDWORD lpReserved,
_Out_opt_ LPDWORD lpcSubKeys,
_Out_opt_ LPDWORD lpcMaxSubKeyLen,
_Out_opt_ LPDWORD lpcMaxClassLen,
_Out_opt_ LPDWORD lpcValues,
_Out_opt_ LPDWORD lpcMaxValueNameLen,
_Out_opt_ LPDWORD lpcMaxValueLen,
_Out_opt_ LPDWORD lpcbSecurityDescriptor,
_Out_opt_ PFILETIME lpftLastWriteTime
) {
LONG ret = Old_RegQueryInfoKeyW(hKey, lpClass, lpcClass, lpReserved,
lpcSubKeys, lpcMaxSubKeyLen, lpcMaxClassLen, lpcValues,
lpcMaxValueNameLen, lpcMaxValueLen, lpcbSecurityDescriptor,
lpftLastWriteTime);
LOQ_zero("registry", "pU6I", "KeyHandle", hKey, "Class", lpcClass ? *lpcClass : 0, lpClass,
"SubKeyCount", lpcSubKeys, "MaxSubKeyLength", lpcMaxSubKeyLen,
"MaxClassLength", lpcMaxClassLen, "ValueCount", lpcValues,
"MaxValueNameLength", lpcMaxValueNameLen,
"MaxValueLength", lpcMaxValueLen);
return ret;
}
HOOKDEF(LONG, WINAPI, RegCloseKey,
__in HKEY hKey
) {
LONG ret = Old_RegCloseKey(hKey);
LOQ_zero("registry", "p", "Handle", hKey);
return ret;
}
HOOKDEF(LONG, WINAPI, RegNotifyChangeKeyValue,
_In_ HKEY hKey,
_In_ BOOL bWatchSubtree,
_In_ DWORD dwNotifyFilter,
_In_opt_ HANDLE hEvent,
_In_ BOOL fAsynchronous
) {
LONG ret = 0;
if (!fAsynchronous)
LOQ_zero("registry", "Ehii", "FullName", hKey, NULL, "NotifyFilter", dwNotifyFilter, "WatchSubtree", bWatchSubtree, "Asynchronous", fAsynchronous);
ret = Old_RegNotifyChangeKeyValue(hKey, bWatchSubtree, dwNotifyFilter, hEvent, fAsynchronous);
if (fAsynchronous)
LOQ_zero("registry", "Ehii", "FullName", hKey, NULL, "NotifyFilter", dwNotifyFilter, "WatchSubtree", bWatchSubtree, "Asynchronous", fAsynchronous);
return ret;
}