forked from cuckoosandbox/cuckoomon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.h
1485 lines (1284 loc) · 39.6 KB
/
hooks.h
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Cuckoo Sandbox - Automated Malware Analysis
Copyright (C) 2010-2014 Cuckoo Sandbox Developers
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 <windns.h>
#include <wininet.h>
#include "ntapi.h"
//
// File Hooks
//
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateFile,
__out PHANDLE FileHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes,
__out PIO_STATUS_BLOCK IoStatusBlock,
__in_opt PLARGE_INTEGER AllocationSize,
__in ULONG FileAttributes,
__in ULONG ShareAccess,
__in ULONG CreateDisposition,
__in ULONG CreateOptions,
__in PVOID EaBuffer,
__in ULONG EaLength
);
extern HOOKDEF(NTSTATUS, WINAPI, NtOpenFile,
__out PHANDLE FileHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes,
__out PIO_STATUS_BLOCK IoStatusBlock,
__in ULONG ShareAccess,
__in ULONG OpenOptions
);
extern HOOKDEF(NTSTATUS, WINAPI, NtReadFile,
__in HANDLE FileHandle,
__in_opt HANDLE Event,
__in_opt PIO_APC_ROUTINE ApcRoutine,
__in_opt PVOID ApcContext,
__out PIO_STATUS_BLOCK IoStatusBlock,
__out PVOID Buffer,
__in ULONG Length,
__in_opt PLARGE_INTEGER ByteOffset,
__in_opt PULONG Key
);
extern HOOKDEF(NTSTATUS, WINAPI, NtWriteFile,
__in HANDLE FileHandle,
__in_opt HANDLE Event,
__in_opt PIO_APC_ROUTINE ApcRoutine,
__in_opt PVOID ApcContext,
__out PIO_STATUS_BLOCK IoStatusBlock,
__in PVOID Buffer,
__in ULONG Length,
__in_opt PLARGE_INTEGER ByteOffset,
__in_opt PULONG Key
);
extern HOOKDEF(NTSTATUS, WINAPI, NtDeleteFile,
__in POBJECT_ATTRIBUTES ObjectAttributes
);
extern HOOKDEF(NTSTATUS, WINAPI, NtDeviceIoControlFile,
__in HANDLE FileHandle,
__in HANDLE Event,
__in PIO_APC_ROUTINE ApcRoutine,
__in PVOID ApcContext,
__out PIO_STATUS_BLOCK IoStatusBlock,
__in ULONG IoControlCode,
__in PVOID InputBuffer,
__in ULONG InputBufferLength,
__out PVOID OutputBuffer,
__in ULONG OutputBufferLength
);
extern HOOKDEF(NTSTATUS, WINAPI, NtQueryDirectoryFile,
__in HANDLE FileHandle,
__in_opt HANDLE Event,
__in_opt PIO_APC_ROUTINE ApcRoutine,
__in_opt PVOID ApcContext,
__out PIO_STATUS_BLOCK IoStatusBlock,
__out PVOID FileInformation,
__in ULONG Length,
__in FILE_INFORMATION_CLASS FileInformationClass,
__in BOOLEAN ReturnSingleEntry,
__in_opt PUNICODE_STRING FileName,
__in BOOLEAN RestartScan
);
extern HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationFile,
__in HANDLE FileHandle,
__out PIO_STATUS_BLOCK IoStatusBlock,
__out PVOID FileInformation,
__in ULONG Length,
__in FILE_INFORMATION_CLASS FileInformationClass
);
extern HOOKDEF(NTSTATUS, WINAPI, NtSetInformationFile,
__in HANDLE FileHandle,
__out PIO_STATUS_BLOCK IoStatusBlock,
__in PVOID FileInformation,
__in ULONG Length,
__in FILE_INFORMATION_CLASS FileInformationClass
);
extern HOOKDEF(NTSTATUS, WINAPI, NtOpenDirectoryObject,
__out PHANDLE DirectoryHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes
);
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateDirectoryObject,
__out PHANDLE DirectoryHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes
);
extern HOOKDEF(BOOL, WINAPI, MoveFileWithProgressW,
__in LPWSTR lpExistingFileName,
__in_opt LPWSTR lpNewFileName,
__in_opt LPPROGRESS_ROUTINE lpProgressRoutine,
__in_opt LPVOID lpData,
__in DWORD dwFlags
);
extern HOOKDEF(BOOL, WINAPI, CreateDirectoryW,
__in LPCTSTR lpPathName,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes
);
extern HOOKDEF(BOOL, WINAPI, CreateDirectoryExW,
__in LPWSTR lpTemplateDirectory,
__in LPWSTR lpNewDirectory,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes
);
extern HOOKDEF(BOOL, WINAPI, RemoveDirectoryA,
__in LPCTSTR lpPathName
);
extern HOOKDEF(BOOL, WINAPI, RemoveDirectoryW,
__in LPWSTR lpPathName
);
extern HOOKDEF(BOOL, WINAPI, MoveFileWithProgressW,
__in LPWSTR lpExistingFileName,
__in_opt LPWSTR lpNewFileName,
__in_opt LPPROGRESS_ROUTINE lpProgressRoutine,
__in_opt LPVOID lpData,
__in DWORD dwFlags
);
extern HOOKDEF(HANDLE, WINAPI, FindFirstFileExA,
__in LPCTSTR lpFileName,
__in FINDEX_INFO_LEVELS fInfoLevelId,
__out LPVOID lpFindFileData,
__in FINDEX_SEARCH_OPS fSearchOp,
__reserved LPVOID lpSearchFilter,
__in DWORD dwAdditionalFlags
);
extern HOOKDEF(HANDLE, WINAPI, FindFirstFileExW,
__in LPWSTR lpFileName,
__in FINDEX_INFO_LEVELS fInfoLevelId,
__out LPVOID lpFindFileData,
__in FINDEX_SEARCH_OPS fSearchOp,
__reserved LPVOID lpSearchFilter,
__in DWORD dwAdditionalFlags
);
extern HOOKDEF(BOOL, WINAPI, CopyFileA,
__in LPCTSTR lpExistingFileName,
__in LPCTSTR lpNewFileName,
__in BOOL bFailIfExists
);
extern HOOKDEF(BOOL, WINAPI, CopyFileW,
__in LPWSTR lpExistingFileName,
__in LPWSTR lpNewFileName,
__in BOOL bFailIfExists
);
extern HOOKDEF(BOOL, WINAPI, CopyFileExW,
_In_ LPWSTR lpExistingFileName,
_In_ LPWSTR lpNewFileName,
_In_opt_ LPPROGRESS_ROUTINE lpProgressRoutine,
_In_opt_ LPVOID lpData,
_In_opt_ LPBOOL pbCancel,
_In_ DWORD dwCopyFlags
);
extern HOOKDEF(BOOL, WINAPI, DeleteFileA,
__in LPCSTR lpFileName
);
extern HOOKDEF(BOOL, WINAPI, DeleteFileW,
__in LPWSTR lpFileName
);
//
// Registry Hooks
//
extern HOOKDEF(LONG, WINAPI, RegOpenKeyExA,
__in HKEY hKey,
__in_opt LPCTSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
extern HOOKDEF(LONG, WINAPI, RegOpenKeyExW,
__in HKEY hKey,
__in_opt LPWSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
extern 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
);
extern 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
);
extern HOOKDEF(LONG, WINAPI, RegDeleteKeyA,
__in HKEY hKey,
__in LPCTSTR lpSubKey
);
extern HOOKDEF(LONG, WINAPI, RegDeleteKeyW,
__in HKEY hKey,
__in LPWSTR lpSubKey
);
extern HOOKDEF(LONG, WINAPI, RegEnumKeyW,
__in HKEY hKey,
__in DWORD dwIndex,
__out LPWSTR lpName,
__in DWORD cchName
);
extern 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
);
extern 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
);
extern 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
);
extern 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
);
extern HOOKDEF(LONG, WINAPI, RegSetValueExA,
__in HKEY hKey,
__in_opt LPCTSTR lpValueName,
__reserved DWORD Reserved,
__in DWORD dwType,
__in const BYTE *lpData,
__in DWORD cbData
);
extern HOOKDEF(LONG, WINAPI, RegSetValueExW,
__in HKEY hKey,
__in_opt LPWSTR lpValueName,
__reserved DWORD Reserved,
__in DWORD dwType,
__in const BYTE *lpData,
__in DWORD cbData
);
extern 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
);
extern 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
);
extern HOOKDEF(LONG, WINAPI, RegDeleteValueA,
__in HKEY hKey,
__in_opt LPCTSTR lpValueName
);
extern HOOKDEF(LONG, WINAPI, RegDeleteValueW,
__in HKEY hKey,
__in_opt LPWSTR lpValueName
);
extern 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
);
extern 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
);
extern HOOKDEF(LONG, WINAPI, RegCloseKey,
__in HKEY hKey
);
//
// Native Registry Hooks
//
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateKey,
__out PHANDLE KeyHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes,
__reserved ULONG TitleIndex,
__in_opt PUNICODE_STRING Class,
__in ULONG CreateOptions,
__out_opt PULONG Disposition
);
extern HOOKDEF(NTSTATUS, WINAPI, NtOpenKey,
__out PHANDLE KeyHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes
);
extern HOOKDEF(NTSTATUS, WINAPI, NtOpenKeyEx,
__out PHANDLE KeyHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes,
__in ULONG OpenOptions
);
extern HOOKDEF(NTSTATUS, WINAPI, NtRenameKey,
__in HANDLE KeyHandle,
__in PUNICODE_STRING NewName
);
extern HOOKDEF(NTSTATUS, WINAPI, NtReplaceKey,
__in POBJECT_ATTRIBUTES NewHiveFileName,
__in HANDLE KeyHandle,
__in POBJECT_ATTRIBUTES BackupHiveFileName
);
extern HOOKDEF(NTSTATUS, WINAPI, NtEnumerateKey,
__in HANDLE KeyHandle,
__in ULONG Index,
__in KEY_INFORMATION_CLASS KeyInformationClass,
__out_opt PVOID KeyInformation,
__in ULONG Length,
__out PULONG ResultLength
);
extern HOOKDEF(NTSTATUS, WINAPI, NtEnumerateValueKey,
__in HANDLE KeyHandle,
__in ULONG Index,
__in KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
__out_opt PVOID KeyValueInformation,
__in ULONG Length,
__out PULONG ResultLength
);
extern HOOKDEF(NTSTATUS, WINAPI, NtSetValueKey,
__in HANDLE KeyHandle,
__in PUNICODE_STRING ValueName,
__in_opt ULONG TitleIndex,
__in ULONG Type,
__in_opt PVOID Data,
__in ULONG DataSize
);
extern HOOKDEF(NTSTATUS, WINAPI, NtQueryValueKey,
__in HANDLE KeyHandle,
__in PUNICODE_STRING ValueName,
__in KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
__out_opt PVOID KeyValueInformation,
__in ULONG Length,
__out PULONG ResultLength
);
extern HOOKDEF(NTSTATUS, WINAPI, NtQueryMultipleValueKey,
__in HANDLE KeyHandle,
__inout PKEY_VALUE_ENTRY ValueEntries,
__in ULONG EntryCount,
__out PVOID ValueBuffer,
__inout PULONG BufferLength,
__out_opt PULONG RequiredBufferLength
);
extern HOOKDEF(NTSTATUS, WINAPI, NtDeleteKey,
__in HANDLE KeyHandle
);
extern HOOKDEF(NTSTATUS, WINAPI, NtDeleteValueKey,
__in HANDLE KeyHandle,
__in PUNICODE_STRING ValueName
);
extern HOOKDEF(NTSTATUS, WINAPI, NtLoadKey,
__in POBJECT_ATTRIBUTES TargetKey,
__in POBJECT_ATTRIBUTES SourceFile
);
extern HOOKDEF(NTSTATUS, WINAPI, NtLoadKey2,
__in POBJECT_ATTRIBUTES TargetKey,
__in POBJECT_ATTRIBUTES SourceFile,
__in ULONG Flags
);
extern HOOKDEF(NTSTATUS, WINAPI, NtLoadKeyEx,
__in POBJECT_ATTRIBUTES TargetKey,
__in POBJECT_ATTRIBUTES SourceFile,
__in ULONG Flags,
__in_opt HANDLE TrustClassKey
);
extern HOOKDEF(NTSTATUS, WINAPI, NtQueryKey,
__in HANDLE KeyHandle,
__in KEY_INFORMATION_CLASS KeyInformationClass,
__out_opt PVOID KeyInformation,
__in ULONG Length,
__out PULONG ResultLength
);
extern HOOKDEF(NTSTATUS, WINAPI, NtSaveKey,
__in HANDLE KeyHandle,
__in HANDLE FileHandle
);
extern HOOKDEF(NTSTATUS, WINAPI, NtSaveKeyEx,
__in HANDLE KeyHandle,
__in HANDLE FileHandle,
__in ULONG Format
);
//
// Window Hooks
//
extern HOOKDEF(HWND, WINAPI, FindWindowA,
__in_opt LPCTSTR lpClassName,
__in_opt LPCTSTR lpWindowName
);
extern HOOKDEF(HWND, WINAPI, FindWindowW,
__in_opt LPWSTR lpClassName,
__in_opt LPWSTR lpWindowName
);
extern HOOKDEF(HWND, WINAPI, FindWindowExA,
__in_opt HWND hwndParent,
__in_opt HWND hwndChildAfter,
__in_opt LPCTSTR lpszClass,
__in_opt LPCTSTR lpszWindow
);
extern HOOKDEF(HWND, WINAPI, FindWindowExW,
__in_opt HWND hwndParent,
__in_opt HWND hwndChildAfter,
__in_opt LPWSTR lpszClass,
__in_opt LPWSTR lpszWindow
);
//
// Sync Hooks
//
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateMutant,
__out PHANDLE MutantHandle,
__in ACCESS_MASK DesiredAccess,
__in_opt POBJECT_ATTRIBUTES ObjectAttributes,
__in BOOLEAN InitialOwner
);
extern HOOKDEF(NTSTATUS, WINAPI, NtOpenMutant,
__out PHANDLE MutantHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes
);
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateNamedPipeFile,
OUT PHANDLE NamedPipeFileHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
OUT PIO_STATUS_BLOCK IoStatusBlock,
IN ULONG ShareAccess,
IN ULONG CreateDisposition,
IN ULONG CreateOptions,
IN BOOLEAN WriteModeMessage,
IN BOOLEAN ReadModeMessage,
IN BOOLEAN NonBlocking,
IN ULONG MaxInstances,
IN ULONG InBufferSize,
IN ULONG OutBufferSize,
IN PLARGE_INTEGER DefaultTimeOut
);
//
// Process Hooks
//
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateProcess,
__out PHANDLE ProcessHandle,
__in ACCESS_MASK DesiredAccess,
__in_opt POBJECT_ATTRIBUTES ObjectAttributes,
__in HANDLE ParentProcess,
__in BOOLEAN InheritObjectTable,
__in_opt HANDLE SectionHandle,
__in_opt HANDLE DebugPort,
__in_opt HANDLE ExceptionPort
);
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateProcessEx,
__out PHANDLE ProcessHandle,
__in ACCESS_MASK DesiredAccess,
__in_opt POBJECT_ATTRIBUTES ObjectAttributes,
__in HANDLE ParentProcess,
__in ULONG Flags,
__in_opt HANDLE SectionHandle,
__in_opt HANDLE DebugPort,
__in_opt HANDLE ExceptionPort,
__in BOOLEAN InJob
);
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateUserProcess,
__out PHANDLE ProcessHandle,
__out PHANDLE ThreadHandle,
__in ACCESS_MASK ProcessDesiredAccess,
__in ACCESS_MASK ThreadDesiredAccess,
__in_opt POBJECT_ATTRIBUTES ProcessObjectAttributes,
__in_opt POBJECT_ATTRIBUTES ThreadObjectAttributes,
__in ULONG ProcessFlags,
__in ULONG ThreadFlags,
__in_opt PRTL_USER_PROCESS_PARAMETERS ProcessParameters,
__inout PPS_CREATE_INFO CreateInfo,
__in_opt PPS_ATTRIBUTE_LIST AttributeList
);
extern HOOKDEF(NTSTATUS, WINAPI, RtlCreateUserProcess,
IN PUNICODE_STRING ImagePath,
IN ULONG ObjectAttributes,
IN OUT PRTL_USER_PROCESS_PARAMETERS ProcessParameters,
IN PSECURITY_DESCRIPTOR ProcessSecurityDescriptor OPTIONAL,
IN PSECURITY_DESCRIPTOR ThreadSecurityDescriptor OPTIONAL,
IN HANDLE ParentProcess,
IN BOOLEAN InheritHandles,
IN HANDLE DebugPort OPTIONAL,
IN HANDLE ExceptionPort OPTIONAL,
OUT PRTL_USER_PROCESS_INFORMATION ProcessInformation
);
extern HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess,
__out PHANDLE ProcessHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes,
__in_opt PCLIENT_ID ClientId
);
extern HOOKDEF(NTSTATUS, WINAPI, NtTerminateProcess,
__in_opt HANDLE ProcessHandle,
__in NTSTATUS ExitStatus
);
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateSection,
__out PHANDLE SectionHandle,
__in ACCESS_MASK DesiredAccess,
__in_opt POBJECT_ATTRIBUTES ObjectAttributes,
__in_opt PLARGE_INTEGER MaximumSize,
__in ULONG SectionPageProtection,
__in ULONG AllocationAttributes,
__in_opt HANDLE FileHandle
);
extern HOOKDEF(NTSTATUS, WINAPI, NtMakeTemporaryObject,
__in HANDLE ObjectHandle
);
extern HOOKDEF(NTSTATUS, WINAPI, NtMakePermanentObject,
__in HANDLE ObjectHandle
);
extern HOOKDEF(NTSTATUS, WINAPI, NtOpenSection,
__out PHANDLE SectionHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes
);
extern HOOKDEF(BOOL, WINAPI, CreateProcessInternalW,
__in_opt LPVOID lpUnknown1,
__in_opt LPWSTR lpApplicationName,
__inout_opt LPWSTR lpCommandLine,
__in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes,
__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in BOOL bInheritHandles,
__in DWORD dwCreationFlags,
__in_opt LPVOID lpEnvironment,
__in_opt LPWSTR lpCurrentDirectory,
__in LPSTARTUPINFO lpStartupInfo,
__out LPPROCESS_INFORMATION lpProcessInformation,
__in_opt LPVOID lpUnknown2
);
extern HOOKDEF2(BOOL, WINAPI, CreateProcessInternalW,
__in_opt LPVOID lpUnknown1,
__in_opt LPWSTR lpApplicationName,
__inout_opt LPWSTR lpCommandLine,
__in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes,
__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in BOOL bInheritHandles,
__in DWORD dwCreationFlags,
__in_opt LPVOID lpEnvironment,
__in_opt LPWSTR lpCurrentDirectory,
__in LPSTARTUPINFO lpStartupInfo,
__out LPPROCESS_INFORMATION lpProcessInformation,
__in_opt LPVOID lpUnknown2
);
extern HOOKDEF(VOID, WINAPI, ExitProcess,
__in UINT uExitCode
);
extern HOOKDEF(BOOL, WINAPI, ShellExecuteExW,
__inout SHELLEXECUTEINFOW *pExecInfo
);
extern HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection,
_In_ HANDLE ProcessHandle,
_In_opt_ PVOID BaseAddress
);
extern HOOKDEF(NTSTATUS, WINAPI, NtAllocateVirtualMemory,
__in HANDLE ProcessHandle,
__inout PVOID *BaseAddress,
__in ULONG_PTR ZeroBits,
__inout PSIZE_T RegionSize,
__in ULONG AllocationType,
__in ULONG Protect
);
extern HOOKDEF(NTSTATUS, WINAPI, NtReadVirtualMemory,
__in HANDLE ProcessHandle,
__in LPCVOID BaseAddress,
__out LPVOID Buffer,
__in ULONG NumberOfBytesToRead,
__out_opt PULONG NumberOfBytesReaded
);
extern HOOKDEF(BOOL, WINAPI, ReadProcessMemory,
_In_ HANDLE hProcess,
_In_ LPCVOID lpBaseAddress,
_Out_ LPVOID lpBuffer,
_In_ SIZE_T nSize,
_Out_ SIZE_T *lpNumberOfBytesRead
);
extern HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory,
__in HANDLE ProcessHandle,
__in LPVOID BaseAddress,
__in LPCVOID Buffer,
__in ULONG NumberOfBytesToWrite,
__out_opt ULONG *NumberOfBytesWritten
);
extern HOOKDEF(BOOL, WINAPI, WriteProcessMemory,
_In_ HANDLE hProcess,
_In_ LPVOID lpBaseAddress,
_In_ LPCVOID lpBuffer,
_In_ SIZE_T nSize,
_Out_ SIZE_T *lpNumberOfBytesWritten
);
extern HOOKDEF(NTSTATUS, WINAPI, NtProtectVirtualMemory,
IN HANDLE ProcessHandle,
IN OUT PVOID *BaseAddress,
IN OUT PULONG NumberOfBytesToProtect,
IN ULONG NewAccessProtection,
OUT PULONG OldAccessProtection
);
extern HOOKDEF(BOOL, WINAPI, VirtualProtectEx,
__in HANDLE hProcess,
__in LPVOID lpAddress,
__in SIZE_T dwSize,
__in DWORD flNewProtect,
__out PDWORD lpflOldProtect
);
extern HOOKDEF(NTSTATUS, WINAPI, NtFreeVirtualMemory,
IN HANDLE ProcessHandle,
IN PVOID *BaseAddress,
IN OUT PULONG RegionSize,
IN ULONG FreeType
);
extern HOOKDEF(BOOL, WINAPI, VirtualFreeEx,
__in HANDLE hProcess,
__in LPVOID lpAddress,
__in SIZE_T dwSize,
__in DWORD dwFreeType
);
extern HOOKDEF(int, CDECL, system,
const char *command
);
//
// Thread Hooks
//
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateThread,
__out PHANDLE ThreadHandle,
__in ACCESS_MASK DesiredAccess,
__in_opt POBJECT_ATTRIBUTES ObjectAttributes,
__in HANDLE ProcessHandle,
__out PCLIENT_ID ClientId,
__in PCONTEXT ThreadContext,
__in PINITIAL_TEB InitialTeb,
__in BOOLEAN CreateSuspended
);
extern HOOKDEF(NTSTATUS, WINAPI, NtCreateThreadEx,
OUT PHANDLE hThread,
IN ACCESS_MASK DesiredAccess,
IN PVOID ObjectAttributes,
IN HANDLE ProcessHandle,
IN LPTHREAD_START_ROUTINE lpStartAddress,
IN PVOID lpParameter,
IN BOOL CreateSuspended,
IN LONG StackZeroBits,
IN LONG SizeOfStackCommit,
IN LONG SizeOfStackReserve,
OUT PVOID lpBytesBuffer
);
extern HOOKDEF(NTSTATUS, WINAPI, NtOpenThread,
__out PHANDLE ThreadHandle,
__in ACCESS_MASK DesiredAccess,
__in POBJECT_ATTRIBUTES ObjectAttributes,
__in PCLIENT_ID ClientId
);
extern HOOKDEF(NTSTATUS, WINAPI, NtGetContextThread,
__in HANDLE ThreadHandle,
__inout LPCONTEXT Context
);
extern HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread,
__in HANDLE ThreadHandle,
__in const CONTEXT *Context
);
extern HOOKDEF(NTSTATUS, WINAPI, NtSuspendThread,
__in HANDLE ThreadHandle,
__out_opt ULONG *PreviousSuspendCount
);
extern HOOKDEF(NTSTATUS, WINAPI, NtResumeThread,
__in HANDLE ThreadHandle,
__out_opt ULONG *SuspendCount
);
extern HOOKDEF(NTSTATUS, WINAPI, NtTerminateThread,
__in HANDLE ThreadHandle,
__in NTSTATUS ExitStatus
);
extern HOOKDEF(HANDLE, WINAPI, CreateThread,
__in LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in SIZE_T dwStackSize,
__in LPTHREAD_START_ROUTINE lpStartAddress,
__in LPVOID lpParameter,
__in DWORD dwCreationFlags,
__out LPDWORD lpThreadId
);
extern HOOKDEF(HANDLE, WINAPI, CreateRemoteThread,
__in HANDLE hProcess,
__in LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in SIZE_T dwStackSize,
__in LPTHREAD_START_ROUTINE lpStartAddress,
__in LPVOID lpParameter,
__in DWORD dwCreationFlags,
__out LPDWORD lpThreadId
);
extern HOOKDEF(BOOL, WINAPI, TerminateThread,
__inout HANDLE hThread,
__in DWORD dwExitCode
);
extern HOOKDEF(VOID, WINAPI, ExitThread,
__in DWORD dwExitCode
);
extern HOOKDEF(NTSTATUS, WINAPI, RtlCreateUserThread,
IN HANDLE ProcessHandle,
IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
IN BOOLEAN CreateSuspended,
IN ULONG StackZeroBits,
IN OUT PULONG StackReserved,
IN OUT PULONG StackCommit,
IN PVOID StartAddress,
IN PVOID StartParameter OPTIONAL,
OUT PHANDLE ThreadHandle,
OUT PCLIENT_ID ClientId
);
//
// Misc Hooks
//
extern HOOKDEF(HHOOK, WINAPI, SetWindowsHookExA,
__in int idHook,
__in HOOKPROC lpfn,
__in HINSTANCE hMod,
__in DWORD dwThreadId
);
extern HOOKDEF(HHOOK, WINAPI, SetWindowsHookExW,
__in int idHook,
__in HOOKPROC lpfn,
__in HINSTANCE hMod,
__in DWORD dwThreadId
);
extern HOOKDEF(BOOL, WINAPI, UnhookWindowsHookEx,
__in HHOOK hhk
);
extern HOOKDEF(NTSTATUS, WINAPI, LdrLoadDll,
__in_opt PWCHAR PathToFile,
__in_opt ULONG Flags,
__in PUNICODE_STRING ModuleFileName,
__out PHANDLE ModuleHandle
);
extern HOOKDEF(NTSTATUS, WINAPI, LdrGetDllHandle,
__in_opt PWORD pwPath,
__in_opt PVOID Unused,
__in PUNICODE_STRING ModuleFileName,
__out PHANDLE pHModule
);
extern HOOKDEF(NTSTATUS, WINAPI, LdrGetProcedureAddress,
__in HMODULE ModuleHandle,
__in_opt PANSI_STRING FunctionName,
__in_opt WORD Ordinal,
__out PVOID *FunctionAddress
);
extern HOOKDEF(BOOL, WINAPI, DeviceIoControl,
__in HANDLE hDevice,
__in DWORD dwIoControlCode,
__in_opt LPVOID lpInBuffer,
__in DWORD nInBufferSize,
__out_opt LPVOID lpOutBuffer,
__in DWORD nOutBufferSize,
__out_opt LPDWORD lpBytesReturned,
__inout_opt LPOVERLAPPED lpOverlapped
);
extern HOOKDEF(NTSTATUS, WINAPI, NtDelayExecution,
__in BOOLEAN Alertable,
__in PLARGE_INTEGER DelayInterval
);
extern HOOKDEF(BOOL, WINAPI, ExitWindowsEx,
__in UINT uFlags,
__in DWORD dwReason
);
extern HOOKDEF(BOOL, WINAPI, IsDebuggerPresent,
void
);
extern HOOKDEF(BOOL, WINAPI, LookupPrivilegeValueW,
__in_opt LPWSTR lpSystemName,
__in LPWSTR lpName,
__out PLUID lpLuid
);
extern HOOKDEF(NTSTATUS, WINAPI, NtClose,
__in HANDLE Handle
);
extern HOOKDEF(BOOL, WINAPI, WriteConsoleA,
_In_ HANDLE hConsoleOutput,
_In_ const VOID *lpBuffer,
_In_ DWORD nNumberOfCharsToWrite,
_Out_ LPDWORD lpNumberOfCharsWritten,
_Reserved_ LPVOID lpReseverd
);
extern HOOKDEF(BOOL, WINAPI, WriteConsoleW,
_In_ HANDLE hConsoleOutput,
_In_ const VOID *lpBuffer,
_In_ DWORD nNumberOfCharsToWrite,
_Out_ LPDWORD lpNumberOfCharsWritten,
_Reserved_ LPVOID lpReseverd
);
extern HOOKDEF(int, WINAPI, GetSystemMetrics,
_In_ int nIndex
);
extern HOOKDEF(BOOL, WINAPI, GetCursorPos,
_Out_ LPPOINT lpPoint