-
Notifications
You must be signed in to change notification settings - Fork 72
/
KeDetective.h
1175 lines (930 loc) · 28.2 KB
/
KeDetective.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
/*
* Copyright (c) 2008 Arab Team 4 Reverse Engineering. All rights reserved.
*
* Module Name:
*
* core.h
*
* Abstract:
*
* This module is the main header .
*
* Author:
*
* GamingMasteR
*
*/
#pragma once
//#define _REPORT_
#include "ntifs.h"
#include <ntddk.h>
#include <WinDef.h>
#include <ntimage.h>
#include <stdio.h>
#include <stdlib.h>
#include "dasm.h"
#include "memory.h"
#include "help.h"
#include "VM.h"
#include "dbg.h"
#include "DispatchLock.h"
#include "wdbgexts.h"
#ifdef __cplusplus
extern "C" {
#endif
#pragma warning(disable : 4995)
#pragma warning(disable : 4090)
#pragma warning(disable : 4996)
#define FILE_DEVICE_CORE 0x00008300
#define CORE_IOCTL_INDEX 0x830
#define CODE(CTL) CTL_CODE(FILE_DEVICE_CORE,CTL,METHOD_NEITHER,FILE_ANY_ACCESS)
typedef enum {
IOCTL_INITIALIZE = 1,
IOCTL_ENUM_PROCESS,
IOCTL_VM_READ,
IOCTL_VM_WRITE,
IOCTL_ENUM_DLL,
IOCTL_DBG_MSG,
IOCTL_ENUM_SSDT,
IOCTL_SET_SSDT,
IOCTL_ENUM_IDT,
IOCTL_GET_MODULE,
IOCTL_IDT_OFFSET,
IOCTL_IDT_SELECTOR,
IOCTL_ENUM_SHADOW_SSDT,
IOCTL_SET_SHADOW_SSDT,
IOCTL_ENUM_HOOKS,
IOCTL_UNHOOK_KERNEL,
IOCTL_ENUM_HANDLES,
IOCTL_PROCESS_KILL,
IOCTL_ENUM_DRIVER,
IOCTL_RESTORE_SSDT,
IOCTL_RESTORE_SHADOW_SSDT,
IOCTL_HOOK_KIDEBUGSERVICE,
IOCTL_UNHOOK_KIDEBUGSERVICE ,
IOCTL_ALLOCATE_PROCESS_VM,
IOCTL_DEALLOCATE_PROCESS_VM,
IOCTL_PROCESS_OPEN,
IOCTL_CLOSE_HANDLE,
IOCTL_UPDATE_MODULE_LIST,
IOCTL_THREAD_TO_PROCESS,
IOCTL_GET_OBJECT_TYPE,
IOCTL_ENUM_THREADS,
IOCTL_THREAD_KILL,
IOCTL_THREAD_SET_SSDT,
IOCTL_THREAD_RESTORE_SSDT,
IOCTL_THREAD_SUSPEND,
IOCTL_PROCESS_SUSPEND,
IOCTL_THREAD_RESUME,
IOCTL_PROCESS_RESUME,
IOCTL_ENUM_UNLOADED_DRIVERS,
IOCTL_ENUM_TIMERS,
IOCTL_ENUM_OBJECT_TYPES ,
IOCTL_CANCEL_TIMER,
IOCTL_CHANGE_OBJECT_PROC,
IOCTL_ENUM_IMAGE_NOTIFY ,
IOCTL_ENUM_PROCESS_NOTIFY,
IOCTL_ENUM_THREAD_NOTIFY,
IOCTL_ENUM_LEGO_NOTIFY,
IOCTL_ENUM_CM_NOTIFY,
IOCTL_DELETE_NOTIFY,
IOCTL_DELETE_FILE,
IOCTL_COPY_FILE ,
IOCTL_ENUM_BUGCHECK,
IOCTL_ENUM_BUGCHECK_REASON,
IOCTL_ENUM_THREAD_TRACE,
IOCTL_THREAD_OPEN,
IOCTL_UNMAP_SECTION ,
IOCTL_GET_PROCESS_INFO,
IOCTL_PROCESS_BY_PID,
IOCTL_PROCESS_BY_HANDLE ,
IOCTL_THREAD_BY_PID ,
IOCTL_THREAD_BY_HANDLE,
IOCTL_THREAD_CONTEXT,
IOCTL_GET_MEMORY_INFO,
IOCTL_ALLOC_NONPAGED_POOL,
IOCTL_FREE_NONPAGED_POOL,
IOCTL_PROTECT_PROCESS_VM,
IOCTL_QUERY_PROCESS_VM,
IOCTL_PHYSICAL_PAGE_READ,
IOCTL_PHYSICAL_PAGE_WRITE,
IOCTL_GET_FILENAME_BY_OBJECT,
IOCTL_GET_FILENAME_BY_HANDLE,
IOCTL_READ_FILE_BY_HANDLE,
IOCTL_WRITE_FILE_BY_HANDLE,
IOCTL_READ_FILE_BY_NAME,
IOCTL_WRITE_FILE_BY_NAME,
IOCTL_OPEN_FILE ,
IOCTL_ENUM_DEVICES,
IOCTL_GET_DRIVER_INFO,
IOCTL_GET_OBJECT_NAME,
IOCTL_GET_CONTROL_REG,
IOCTL_SET_CONTROL_REG,
IOCTL_GET_KERNEL_INFO,
IOCTL_CALL_BIOS,
IOCTL_DISK_READWRITE,
IOCTL_PORT_READ,
IOCTL_PORT_WRITE,
IOCTL_MSR,
IOCTL_IO_PACKET,
IOCTL_GET_OBJECT_BY_HANDLE,
IOCTL_CREATE_THREAD,
IOCTL_GET_TYPE_NAME
}IOCTL;
#define MAX_PATH 260
#define MAX_FAST_REFS 7
#define PSP_MAX_NOTIFY 8
#define CM_MAX_CALLBACKS 100
#define COF(_array) (sizeof(_array)/sizeof(_array[0]))
#define SYSCALL_INDEX(_address) *(PULONG)((PUCHAR)_address+1)
#define OBJECT_TO_OBJECT_HEADER(o) ((POBJECT_HEADER)CONTAINING_RECORD((o), OBJECT_HEADER, Body))
#define IsXp ((KdBuildNumber == 2600))
#define IsVista ((KdBuildNumber == 6000) || (KdBuildNumber == 6001) || (KdBuildNumber == 6002))
#define IsVistaSE ((KdBuildNumber == 6001) || (KdBuildNumber == 6002))
#define IsWin7 ((KdBuildNumber == 7600) || (KdBuildNumber == 7601))
#define parseobject(_obj, _mem, _type)((_type*)((ULONG)_obj + info.Ps##_mem))
#define UpdateModulesList()\
{\
if (gDrivers)\
{\
delete gDrivers;\
}\
gDrivers = new CDriver();\
gDrivers->Scan();\
gDrivers->ScanPhysicalMemory();\
}
typedef struct _DEVICE_EXTENSION {
CSHORT Type;
USHORT Size;
PDEVICE_OBJECT DeviceObject; // owning device object
ULONG PowerFlags;
PVOID Dope;
ULONG ExtensionFlags;
PVOID DeviceNode;
PDEVICE_OBJECT AttachedTo;
LONG StartIoCount; // Used to keep track of number of pending start ios.
LONG StartIoKey; // Next startio key
ULONG StartIoFlags; // Start Io Flags. Need a separate flag so that it can be accessed without locks
PVPB Vpb; // If not NULL contains the VPB of the mounted volume.
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
typedef struct _MEMORY_BASIC_INFORMATION {
PVOID BaseAddress;
PVOID AllocationBase;
DWORD AllocationProtect;
SIZE_T RegionSize;
DWORD State;
DWORD Protect;
DWORD Type;
} MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
typedef struct _PLATFORM_OPTIONS{ /* XP - Vista */
ULONG Max_ServiceID; /* 0x11c - 0x11c */
PVOID* SDT; /* ----- - ----- */
ULONG Max_ShadowServiceID; /* 0x29B - 0x29B */
PVOID* ShadowSDT; /* ----- - ----- */
ULONG PsSizeofProcess; /* 0x25c - 0x26c */
ULONG PsSizeofThread; /* 0x256 - 0x284 */
ULONG PsServiceTable; /* 0x0e0 - 0x12c */
ULONG PsProcessRundown; /* 0x080 - 0x098 */
ULONG PsThreadRundown; /* 0x234 - 0x250 */
ULONG PsStartAddress; /* 0x224 - 0x1f8 */
ULONG PsDeviceMap; /* 0x15c - 0x134 */
ULONG PsExceptionPort; /* 0x0c0 - 0x0d8 */
ULONG PsActiveProcessLinks; /* 0x088 - 0x0a0 */
ULONG PsThreadListHead; /* 0x190 - 0x168 */
ULONG PsKiThreadListEntry; /* 0x1b0 - 0x1c4 */
ULONG PsKeThreadListEntry; /* 0x22c - 0x248 */
ULONG PsVirtualSize; /* 0x0b0 - 0x0c8 */
ULONG PsSeAuditProcessCreationInfo; /* 0x1f4 - 0x1cc */
ULONG PsThreadFlags; /* 0x248 - 0x260 */
ULONG PsProcessFlags; /* 0x248 - 0x228 */
ULONG PsPreviousMode; /* 0x140 - 0x0e7 */
ULONG PsObjectListHead; /* 0x038 - 0x000 */ //VSP1
ULONG PsObjectTypeName; /* 0x040 - 0x008 */ //VSP1
ULONG PsFreezeCount; /* 0x1b8 - 0x16b */
ULONG PsSuspendSemaphore; /* 0x19c - 0x1ac */
}PLATFORM_OPTIONS, *PPLATFORM_OPTIONS;
#define MAKE_FLAG(pos) 1<<pos
#define ProcessExiting MAKE_FLAG(2)
#define ProcessDelete MAKE_FLAG(3)
#define BreakOnTermination MAKE_FLAG(13)
#define DeadThread MAKE_FLAG(1)
#define SystemThread MAKE_FLAG(4)
typedef struct DECLSPEC_ALIGN(1) _KD_IO_PACKET {
UCHAR MajorFunction;
union {
struct {
PVOID Buffer;
ULONG Length;
PLARGE_INTEGER StartingOffset;
} Read;
struct {
PVOID Buffer;
ULONG Length;
PLARGE_INTEGER StartingOffset;
} Write;
struct {
ULONG IoControlCode;
PVOID InputBuffer;
ULONG InputBufferLength;
PVOID OutputBuffer;
ULONG OutputBufferLength;
BOOL InternalDeviceIoControl;
} DeviceIoControl;
} Parameters;
DEVICE_OBJECT *DeviceObject;
FILE_OBJECT *FileObject;
} KD_IO_PACKET, *PKD_IO_PACKET;
typedef struct DECLSPEC_ALIGN(1) _PROCESS_ENTRY {
PVOID ProcessObject;
ULONG ImageBase;
PVOID Peb;
ULONG Status;
ULONG Pid;
ULONG ParentId;
ULONG Cb;
WCHAR Name[MAX_PATH];
} PROCESS_ENTRY, *PPROCESS_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _THREAD_ENTRY {
PVOID Process;
ULONG ParentId;
PVOID Thread;
ULONG Cid;
PVOID Teb;
PVOID ServiceTable;
PVOID Address;
ULONG Type;
ULONG ThreadState;
ULONG WaitReason;
ULONG Status;
} THREAD_ENTRY, *PTHREAD_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _DLL_ENTRY {
PVOID BaseAddress;
PVOID EntryPoint;
ULONG SizeOfImage;
WCHAR FullDllName[MAX_PATH];
} DLL_ENTRY, *PDLL_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _SDT_ENTRY {
ULONG Index;
ULONG Current;
ULONG Original;
ULONG Status;
WCHAR Module[MAX_PATH];
} SDT_ENTRY, *PSDT_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _DRIVER_ENTRY {
PVOID ImageBase;
PVOID DriverObject;
PVOID Unload;
PVOID EntryPoint;
ULONG ImageSize;
WCHAR ImagePath[MAX_PATH];
} DRIVER_ENTRY, *PDRIVER_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _HANDLE_ENTRY {
PVOID QuotaProcess;
PVOID UniqueProcessId;
HANDLE Handle;
PVOID Object;
PVOID ObjectType;
ULONG GrantedAccess;
ULONG HandleCount;
WCHAR Name[MAX_PATH];
} HANDLE_ENTRY, *PHANDLE_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _OBJECT_TYPE_ENTRY {
PVOID Address;
DWORD Count;
DWORD Index;
struct {
PVOID DumpProcedure;
PVOID OpenProcedure;
PVOID CloseProcedure;
PVOID DeleteProcedure;
PVOID ParseProcedure;
PVOID SecurityProcedure;
PVOID QueryNameProcedure;
PVOID OkayToCloseProcedure;
} ProcedureTable;
WCHAR Name[MAX_PATH];
} OBJECT_TYPE_ENTRY, *POBJECT_TYPE_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _HOOK_ENTRY {
ULONG ImageBase;
ULONG Rva;
ULONG Size;
ULONG State;
ULONG Parameter1;
ULONG Parameter2;
ULONG Parameter3;
ULONG Parameter4;
UCHAR Origin[64];
UCHAR Current[64];
} HOOK_ENTRY, *PHOOK_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _KIDT_ENTRY {
USHORT Offset;
USHORT Selector;
struct {
USHORT __unnamed1 : 8;
USHORT type : 2;
USHORT __unnamed2 : 1;
USHORT size : 2;
USHORT DPL : 2;
USHORT P : 1;
} Access;
USHORT ExtendedOffset;
} KIDT_ENTRY, *PKIDT_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _TIMER_ENTRY {
PVOID Object;
PVOID Thread;
KTIMER Timer;
KDPC Dpc;
} TIMER_ENTRY, *PTIMER_ENTRY;
typedef struct DECLSPEC_ALIGN(1) _DBGMSG{
CLIENT_ID Cid;
LARGE_INTEGER time;
WCHAR process[16];
WCHAR Msg[512];
}DBGMSG, *LPDBGMSG;
typedef struct DECLSPEC_ALIGN(1) _BIOS_REGISTERS {
ULONG Eax;
ULONG Ecx;
ULONG Edx;
ULONG Ebx;
ULONG Ebp;
ULONG Esi;
ULONG Edi;
USHORT SegDs;
USHORT SegEs;
ULONG EFlags;
} BIOS_REGISTERS, *PBIOS_REGISTERS;
typedef struct DECLSPEC_ALIGN(8) _IO_INPUT_BUFFER {
union {
ULONG Key;
struct {
ULONG Index : CHAR_BIT;
};
};
ULONG ControlCode[UCHAR_MAX + 1];
PVOID InputBuffer[UCHAR_MAX + 1];
} IO_INPUT_BUFFER, *PIO_INPUT_BUFFER;
typedef struct DECLSPEC_ALIGN(8) _KI_PACKET {
union {
struct {
ULONG_PTR Parameter1;
ULONG_PTR Parameter2;
ULONG_PTR Parameter3;
ULONG_PTR Parameter4;
ULONG_PTR Parameter5;
ULONG_PTR Parameter6;
ULONG_PTR Parameter7;
ULONG_PTR Parameter8;
} Common;
struct {
ULONG_PTR *InterruptServiceRoutines;
ULONG_PTR *Ssdt;
ULONG_PTR *ShadowSsdt;
BOOL CaptureDbgMode;
USHORT NtBuildNumber;
PWCHAR KernelFileName;
PWCHAR SystemrootPath;
PVOID KiKdProcess;
PVOID KiCsrProcess;
PVOID KiSystemProcess;
PVOID KiIdleProcess;
PVOID CsrProcessId;
} Initialize;
struct {
KD_IO_PACKET Packet;
} IoPacket;
struct {
PVOID Process;
PKSTART_ROUTINE StartAddress;
PVOID Context;
} CreateThread;
struct {
ULONG Register;
ULONGLONG Value;
BOOL Write;
} Msr;
struct {
ULONG LowestPhysicalPage;
ULONG HighestPhysicalPage;
ULONG NumberOfPhysicalPages;
ULONG_PTR HighestUserAddress;
ULONG_PTR SystemRangeStart;
ULONG_PTR UserProbeAddress;
} SystemInformation;
struct {
PVOID KernelBase;
ULONG KernelSize;
PVOID PsLoadedModuleList;
PVOID MmLoadedUserImageList;
PVOID PspCidTable;
} KernelInformation;
struct {
ULONG_PTR Address;
BOOL GetExports;
BOOL GetSymbols;
PWCHAR Buffer;
SIZE_T Size;
} GetModuleInfo;
struct {
PVOID ProcessObject;
PVOID VirtualAddress;
PVOID Buffer;
SIZE_T Size;
PULONG NumberOfBytesRead;
} VirtualRead;
struct {
PVOID ProcessObject;
PVOID VirtualAddress;
PVOID Buffer;
SIZE_T Size;
PULONG NumberOfBytesWritten;
} VirtualWrite;
struct {
PLARGE_INTEGER PhysicalAddress;
PVOID Buffer;
SIZE_T Size;
} PhysicalRead;
struct {
PLARGE_INTEGER PhysicalAddress;
PVOID Buffer;
SIZE_T Size;
} PhysicalWrite;
struct {
PVOID ProcessObject;
SIZE_T Size;
PVOID Address;
} VirtualAlloc;
struct {
PVOID ProcessObject;
PVOID Address;
SIZE_T Size;
} VirtualFree;
struct {
PVOID ProcessObject;
PVOID Address;
SIZE_T Size;
ULONG NewProtection;
PULONG OldProtection;
} VirtualProtect;
struct {
PVOID ProcessObject;
PVOID Address;
PMEMORY_BASIC_INFORMATION MemoryBasicInformation;
SIZE_T Size;
} VirtualQuery;
struct {
PVOID ProcessObject;
PVOID SectionBase;
} SectionUnmap;
struct {
PPROCESS_ENTRY Processes;
ULONG Count;
} ProcessEnumerate;
struct {
PVOID ProcessObject;
PPROCESS_ENTRY Process;
} ProcessQueryInformation;
struct {
PVOID ProcessObject;
ULONG ProcessId;
HANDLE Handle;
} ProcessOpen;
struct {
PVOID ProcessObject;
} ProcessSuspend;
struct {
PVOID ProcessObject;
BOOL ForceResume;
} ProcessResume;
struct {
PVOID ProcessObject;
BOOL ForceKill;
} ProcessKill;
struct {
PVOID ProcessObject;
PDLL_ENTRY Dlls;
ULONG Count;
} DllEnumerate;
struct {
PVOID ProcessObject;
PTHREAD_ENTRY Threads;
ULONG Count;
} ThreadEnumerate;
struct {
PVOID ThreadObject;
PPROCESS_ENTRY Process;
PTHREAD_ENTRY Thread;
} ThreadQueryInformation;
struct {
PVOID ThreadObject;
ULONG ThreadId;
HANDLE Handle;
} ThreadOpen;
struct {
PVOID ThreadObject;
} ThreadSuspend;
struct {
PVOID ThreadObject;
BOOL ForceResume;
} ThreadResume;
struct {
PVOID ThreadObject;
} ThreadKill;
struct {
PVOID ThreadObject;
PCONTEXT Context;
} ThreadCaptureStack;
struct {
PVOID ThreadObject;
PCONTEXT Context;
BOOL Set;
} ThreadContext;
struct {
PVOID ProcessObject;
HANDLE Handle;
} CloseHandle;
struct {
PWCHAR FilePath;
BOOL ForceDelete;
} FileDelete;
struct {
PWCHAR SourceFilePath;
PWCHAR DestinationFilePath;
} FileCopy;
struct {
PKIDT_ENTRY InterruptEntries;
} InterruptEnumerate;
struct {
ULONG Index;
union {
ULONG_PTR Offset;
USHORT Selector;
};
} InterrupHook;
struct {
PSDT_ENTRY Ssdt;
ULONG Count;
} SsdtEnumerate;
struct {
PDRIVER_ENTRY Drivers;
ULONG Count;
} DriversEnumerate;
struct {
PVOID DriverObject;
PDRIVER_ENTRY DriverInformation;
} DriversQueryInformation;
struct {
PVOID *DeviceObjects;
ULONG Count;
} DevicesEnumerate;
struct {
PVOID Object;
PWCHAR ObjectName;
} ObjectQueryName;
struct {
PVOID Object;
PWCHAR ObjectTypeName;
} ObjectQueryTypeName;
struct {
PWCHAR ImagePath;
ULONG Flags;
ULONG Count;
PHOOK_ENTRY HookEntries;
} ImageHooksEnumerate;
struct {
PVOID ProcessObject;
PHANDLE_ENTRY HandleEntries;
ULONG Count;
} HandlesEnumerate;
struct {
ULONG BiosCommand;
PBIOS_REGISTERS BiosArguments;
} BiosCall;
struct {
ULONG Disk;
ULONG SectorNumber;
USHORT SectorCount;
PVOID Buffer;
BOOL IsWrite;
} DiskReadWrite;
} Parameters;
} KI_PACKET, *PKI_PACKET;
typedef struct _CONTROL_AREA {
PVOID Segment; // 0x00
LIST_ENTRY DereferenceList; // 0x04
ULONG NumberOfSectionReferences; // 0x0c
ULONG NumberOfPfnReferences; // 0x10
ULONG NumberOfMappedViews; // 0x14
USHORT NumberOfSubsections; // 0x18
USHORT FlushInProgressCount; // 0x1a
ULONG NumberOfUserReferences; // 0x1c
ULONG Flags; // MMSECTION_FLAGS // 0x20
PFILE_OBJECT FilePointer; // 0x24
PVOID WaitingForDeletion; // PEVENT_COUNTER // 0x28
USHORT ModifiedWriteCount; // 0x2c
USHORT NumberOfSystemCacheViews; // 0x2e
ULONG PagedPoolUsage; // 0x30
ULONG NonPagedPoolUsage; // 0x34
} CONTROL_AREA, *PCONTROL_AREA;
typedef struct _SEGMENT {
PCONTROL_AREA ControlArea; // 0x00
PVOID SegmentBaseAddress; // 0x04
ULONG TotalNumberOfPtes; // 0x08
ULONG NonExtendedPtes; // 0x0c
LARGE_INTEGER SizeOfSegment; // 0x10
ULONG ImageCommitment; // 0x18
PVOID ImageInformation; // 0x1c PSECTION_IMAGE_INFORMATION
PVOID SystemImageBase; // 0x20
ULONG NumberOfCommittedPages; // 0x24
ULONG SegmentPteTemplate; // 0x28
PVOID BaseAddress; // 0x2c
PVOID BaseAddrPae; // 0x30 if PAE enabled
PULONG PrototypePte; // 0x34
ULONG ThePtes[1]; // 0x38
} SEGMENT, *PSEGMENT;
typedef struct _EX_CALLBACK {
EX_FAST_REF RoutineBlock;
} EX_CALLBACK, *PEX_CALLBACK;
typedef struct _EX_CALLBACK_ROUTINE_BLOCK {
EX_RUNDOWN_REF RundownProtect;
PVOID Function;
PVOID Context;
} EX_CALLBACK_ROUTINE_BLOCK, *PEX_CALLBACK_ROUTINE_BLOCK;
typedef struct _CM_CALLBACK_CONTEXT_BLOCK {
LARGE_INTEGER Cookie; // to identify a specific callback for deregistration purposes
LIST_ENTRY ThreadListHead; // Active threads inside this callback
EX_PUSH_LOCK ThreadListLock; // synchronize access to the above
PVOID CallerContext;
} CM_CALLBACK_CONTEXT_BLOCK, *PCM_CALLBACK_CONTEXT_BLOCK;
typedef struct _CM_VISTA_CALLBACK_BLOCK {
LIST_ENTRY CallbackListHead;
LIST_ENTRY ThreadListHead;
LARGE_INTEGER Cookie;
PVOID CallerContext;
PVOID Function;
} CM_VISTA_CALLBACK_BLOCK, *PCM_VISTA_CALLBACK_BLOCK;
typedef enum _MEMORY_INFORMATION_ {
MemoryBasicInformation,
MemoryWorkingSetList,
MemorySectionName,
MemoryBasicVlmInformation
} MEMORY_INFORMATION_CLASS;
// NtQuerySystemInformation
extern NTSTATUS
(NTAPI *KdQuerySystemInformation)(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength);
// NtTerminateProcess
extern NTSTATUS
(NTAPI *KdTerminateProcess)(IN HANDLE ProcessHandle, IN NTSTATUS ExitStatus);
// NtTerminateThread
extern NTSTATUS
(NTAPI *KdTerminateThread)(IN HANDLE ThreadHandle, IN NTSTATUS ExitStatus);
// KeStackAttachProcess
extern VOID
(NTAPI *KdStackAttachProcess)(PKPROCESS Process, PKAPC_STATE ApcState);
// KeUnstackDetachProcess
extern VOID
(NTAPI *KdUnstackDetachProcess)(PKAPC_STATE ApcState);
// PsLookupProcessByProcessId
extern NTSTATUS
(NTAPI *KdLookupProcessByProcessId)(HANDLE ProcessId, PEPROCESS *Process);
// PsLookupThreadByThreadId
extern NTSTATUS
(NTAPI *KdLookupThreadByThreadId)(PVOID UniqueThreadId, PETHREAD *Thread);
// ObOpenObjectByPointer
extern NTSTATUS
(NTAPI *KdOpenObjectByPointer)(PVOID Object, ULONG HandleAttributes, PACCESS_STATE PassedAccessState, ACCESS_MASK DesiredAccess, POBJECT_TYPE ObjectType OPTIONAL, KPROCESSOR_MODE AccessMode, PHANDLE Handle);
// NtClose
extern NTSTATUS
(NTAPI *KdClose)(HANDLE Handle);
// NtOpenFile
extern NTSTATUS
(NTAPI *KdOpenFile)(PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock, ULONG ShareAccess, ULONG OpenOptions);
// NtAllocateVirtualMemory
extern NTSTATUS
(NTAPI *KdAllocateVirtualMemory)(HANDLE ProcessHandle, PVOID *BaseAddress, ULONG ZeroBits, PSIZE_T RegionSize, ULONG AllocationType, ULONG Protect);
// NtFreeVirtualMemory
extern NTSTATUS
(NTAPI *KdFreeVirtualMemory)( HANDLE ProcessHandle, PVOID *BaseAddress, PSIZE_T RegionSize, ULONG FreeType);
// MmGetPhysicalAddress
extern ULONGLONG
(NTAPI *KdGetPhysicalAddress)(PVOID BaseAddress);
// MmGetVirtualForPhysical
extern PVOID
(NTAPI *KdGetVirtualForPhysical)(ULONGLONG PhysicalAddress);
// NtReadVirtualMemory
extern NTSTATUS
(NTAPI *KdReadVirtualMemory)(HANDLE ProcessHandle, PVOID BaseAddress, PVOID Buffer, ULONG NumberOfBytesToRead, PULONG NumberOfBytesReaded);
// NtWriteVirtualMemory
extern NTSTATUS
(NTAPI *KdWriteVirtualMemory)(HANDLE ProcessHandle, PVOID BaseAddress, PVOID Buffer, ULONG NumberOfBytesToRead, PULONG NumberOfBytesReaded);
// NtProtectVirtualMemory
extern NTSTATUS
(NTAPI *KdProtectVirtualMemory)(HANDLE ProcessHandle, PVOID *BaseAddress, PULONG NumberOfBytesToProtect, ULONG NewAccessProtection, PULONG OldAccessProtection);
// NtQueryVirtualMemory
extern NTSTATUS
(NTAPI *KdQueryVirtualMemory)(HANDLE ProcessHandle, PVOID BaseAddress, MEMORY_INFORMATION_CLASS MemoryInformationClass, PVOID MemoryInformation, ULONG MemoryInformationLength, PULONG ReturnLength OPTIONAL);
// NtFlushInstructionCache
extern NTSTATUS
(NTAPI *KdFlushInstructionCache)(HANDLE ProcessHandle, PVOID BaseAddress, ULONG FlushSize);
// NtOpenProcess
extern NTSTATUS
(NTAPI *KdOpenProcess)(PHANDLE ProcessHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PCLIENT_ID ClientId);
// NtOpenThread
extern NTSTATUS
(NTAPI *KdOpenThread)(PHANDLE ThreadHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PCLIENT_ID ClientId);
// MmCopyVirtualMemory
extern NTSTATUS
(NTAPI *MmCopyVirtualMemory)(PEPROCESS FromProcess, PVOID FromAddress, PEPROCESS ToProcess, PVOID ToAddress, ULONG BufferSize, KPROCESSOR_MODE PreviousMode, PULONG NumberOfBytesCopied);
// NtDuplicateObject
extern NTSTATUS
(NTAPI *KdDuplicateObject)(HANDLE SourceProcessHandle, HANDLE SourceHandle, HANDLE TargetProcessHandle, PHANDLE TargetHandle, ACCESS_MASK DesiredAccess, ULONG HandleAttributes, ULONG Options);
// KeInsertQueueApc
extern BOOLEAN
(NTAPI *KdInsertQueueApc)(PKAPC Apc, PVOID SystemArgument1, PVOID SystemArgument2, KPRIORITY Increment);
// PsTerminateSystemThread
extern NTSTATUS
(NTAPI *KdTerminateSystemThread)(NTSTATUS ExitStatus);
// ObReferenceObjectByHandle
extern NTSTATUS
(NTAPI *KdReferenceObjectByHandle)(HANDLE Handle, ACCESS_MASK DesiredAccess, POBJECT_TYPE ObjectType OPTIONAL, KPROCESSOR_MODE AccessMode, PVOID *Object, POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL);
// ObOpenObjectByName
extern NTSTATUS
(NTAPI *KdOpenObjectByName)(POBJECT_ATTRIBUTES ObjectAttributes, POBJECT_TYPE ObjectType, KPROCESSOR_MODE AccessMode, PACCESS_STATE AccessState, ACCESS_MASK DesiredAccess, PVOID ParseContext, PHANDLE Handle);
// NtResumeThread
extern NTSTATUS
(NTAPI *KdResumeThread)(HANDLE ThreadHandle, PULONG SuspendCount);
// NtOpenDirectoryObject
extern NTSTATUS
(NTAPI *KdOpenDirectoryObject)(PHANDLE DirectoryHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes);
// NtUnloadDriver
extern NTSTATUS
(NTAPI *KdUnloadDriver)(PUNICODE_STRING RegistryPath);
// Ke386CallBios
extern NTSTATUS
(NTAPI *Kd386CallBios)(ULONG BiosCommand, PCONTEXT BiosArguments);
// MmMapViewOfSection
extern NTSTATUS
(NTAPI *KdMapViewOfSection)(PVOID SectionObject, PEPROCESS Process, PVOID *BaseAddress, ULONG ZeroBits, ULONG CommitSize, PLARGE_INTEGER SectionOffset, PULONG ViewSize, SECTION_INHERIT InheritDisposition, ULONG AllocationType, ULONG Protect);
// KdUnmapViewOfSection
extern NTSTATUS
(NTAPI *KdUnmapViewOfSection)(PEPROCESS Process, PVOID BaseAddress);
// PsSuspendThread
extern NTSTATUS
(NTAPI *KdSuspendThread)(PKTHREAD Thread, PULONG PreviousCount);
// KeAlertThread
extern BOOLEAN
(NTAPI *KdAlertThread)(PKTHREAD Thread, KPROCESSOR_MODE AlertMode);
NTKERNELAPI
KPROCESSOR_MODE KeGetPreviousMode(void);
NTSTATUS
RtlMultiByteToUnicodeN(
PWSTR UnicodeString,
ULONG MaxBytesInUnicodeString,
PULONG BytesInUnicodeString OPTIONAL,
PCHAR MultiByteString,
ULONG BytesInMultiByteString
);
NTSTATUS
ObOpenObjectByName(
IN POBJECT_ATTRIBUTES ObjectAttributes,
IN POBJECT_TYPE ObjectType OPTIONAL,
IN KPROCESSOR_MODE AccessMode,
IN OUT PACCESS_STATE AccessState OPTIONAL,
IN ACCESS_MASK DesiredAccess OPTIONAL,
IN OUT PVOID ParseContext OPTIONAL,
OUT PHANDLE Handle
);
PVOID
RtlImageDirectoryEntryToData(
PVOID Base,
BOOLEAN MappedAsImage,
USHORT DirectoryEntry,
PULONG Size
);
NTKERNELAPI
PPEB
PsGetProcessPeb(PEPROCESS);