Bitdefender Hypervisor Memory Introspection
winhkhnd.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
47 
48 #include "introcore.h"
49 #include "winbugcheck.h"
50 #include "winpool.h"
51 #include "winpower.h"
52 #include "winthread.h"
53 #include "winumcrash.h"
54 #include "winvad.h"
55 #include "drivers.h"
56 
61 __section(".detours") =
62 {
63  {
64  .ModuleName = u"ntoskrnl.exe",
65  .FunctionName = "ExAllocatePoolWithTag",
66  .MinVersion = DETOUR_MIN_VERSION_ANY,
67  .MaxVersion = DETOUR_MAX_VERSION_ANY,
68  .Callback = IntWinPoolHandleAlloc,
69  .Tag = detTagPoolAlloc,
70  .Exported = TRUE,
71  .NotCritical = FALSE,
72  .DisableFlags = 0,
73  .EnableFlags = DETOUR_ENABLE_ALWAYS,
74  .Arguments = DET_ARGS_DEFAULT_WIN86,
75  .HandlersCount = 1,
76  .Handlers =
77  {
78  {
79  .MinVersion = DETOUR_MIN_VERSION_ANY,
80  .MaxVersion = DETOUR_MAX_VERSION_ANY,
81  .HypercallType = hypercallTypeInt3,
82 
83  .CodeLength = 0x3c,
84  .Code =
85  {
86  // 0x00: CMP dword ptr [esp+0xc], 0xf6697244
87  0x81, 0x7C, 0x24, 0x0c, 0x44, 0x72, 0x69, 0xF6,
88  // 0x08: JZ 0x34
89  0x74, 0x2a,
90  // 0x0A: CMP dword ptr [esp+0xc], 0x76697244
91  0x81, 0x7C, 0x24, 0x0c, 0x44, 0x72, 0x69, 0x76,
92  // 0x12: JZ 0x34
93  0x74, 0x20,
94  // 0x14: CMP dword ptr [esp+0xc], 0x69664d46
95  0x81, 0x7C, 0x24, 0x0c, 0x46, 0x4D, 0x66, 0x69,
96  // 0x1C: JZ 0x34
97  0x74, 0x16,
98  // 0x1E: CMP dword ptr [esp+0xc], 0x656b6f54
99  0x81, 0x7C, 0x24, 0x0c, 0x54, 0x6f, 0x6b, 0x65,
100  // 0x26: JZ 0x34
101  0x74, 0x0C,
102  // 0x28: CMP dword ptr [esp+0xc], 0xe56b6f54
103  0x81, 0x7C, 0x24, 0x0c, 0x54, 0x6f, 0x6b, 0xe5,
104  // 0x30: JZ 0x34
105  0x74, 0x02,
106  // 0x32: JMP 0x37
107  0xEB, 0x03,
108  // 0x34: INT3
109  0xCC,
110  // 0x35: NOP
111  0x90,
112  // 0x36: NOP
113  0x90,
114  // 0x37: JMP 0x3c
115  0xE9, 0x00, 0x00, 0x00, 0x00,
116  },
117  .HypercallOffset = 0x34,
118  .RelocatedCodeOffset = 0x37,
119  },
120  },
121  },
122 
123  {
124  .ModuleName = u"ntoskrnl.exe",
125  .FunctionName = "ExFreePoolWithTag",
126  .MinVersion = DETOUR_MIN_VERSION_ANY,
127  .MaxVersion = DETOUR_MAX_VERSION_ANY,
128  .Callback = IntWinPoolHandleFree,
129  .Tag = detTagPoolFree,
130  .Exported = TRUE,
131  .NotCritical = FALSE,
132  .DisableFlags = 0,
133  .EnableFlags = DETOUR_ENABLE_ALWAYS,
134  .Arguments = DET_ARGS_DEFAULT_WIN86,
135  .HandlersCount = 1,
136  .Handlers =
137  {
138  {
139  .MinVersion = DETOUR_MIN_VERSION_ANY,
140  .MaxVersion = DETOUR_MAX_VERSION_ANY,
141  .HypercallType = hypercallTypeInt3,
142 
143  .CodeLength = 0x28,
144  .Code =
145  {
146  // 0x00: CMP dword ptr [esp+0x8], 0xf6697244
147  0x81, 0x7C, 0x24, 0x08, 0x44, 0x72, 0x69, 0xF6,
148  // 0x08: JZ 0x20
149  0x74, 0x16,
150  // 0x0A: CMP dword ptr [esp+0x8], 0x76697244
151  0x81, 0x7C, 0x24, 0x08, 0x44, 0x72, 0x69, 0x76,
152  // 0x12: JZ 0x20
153  0x74, 0x0C,
154  // 0x14: CMP dword ptr [esp+0x8], 0x69664d46
155  0x81, 0x7C, 0x24, 0x08, 0x46, 0x4D, 0x66, 0x69,
156  // 0x1C: JZ 0x20
157  0x74, 0x02,
158  // 0x1E: JMP 0x23
159  0xEB, 0x03,
160  // 0x20: INT3
161  0xCC,
162  // 0x21: NOP
163  0x90,
164  // 0x22: NOP
165  0x90,
166  // 0x23: JMP 0x28
167  0xE9, 0x00, 0x00, 0x00, 0x00
168  },
169  .HypercallOffset = 0x20,
170  .RelocatedCodeOffset = 0x23,
171  },
172  },
173  },
174 
175  {
176  .ModuleName = u"ntoskrnl.exe",
177  .FunctionName = "KeBugCheck2",
178  .MinVersion = DETOUR_MIN_VERSION_ANY,
179  .MaxVersion = DETOUR_MAX_VERSION_ANY,
180  .Callback = IntWinBcHandleBugCheck,
181  .Tag = detTagBugcheck,
182  .Exported = FALSE,
183  .NotCritical = FALSE,
184  .DisableFlags = 0,
186  .Arguments = DET_ARGS_DEFAULT_WIN86,
187  .HandlersCount = 1,
188  .Handlers =
189  {
190  {
191  .MinVersion = DETOUR_MIN_VERSION_ANY,
192  .MaxVersion = DETOUR_MAX_VERSION_ANY,
193  .HypercallType = hypercallTypeInt3,
194 
195  .CodeLength = 0x8,
196  .Code =
197  {
198  // 0x00: INT3
199  0xCC,
200  // 0x01: NOP
201  0x90,
202  // 0x02: NOP
203  0x90,
204  // 0x03: JMP 0x8
205  0xE9, 0x00, 0x00, 0x00, 0x00
206  },
207  .HypercallOffset = 0x0,
208  .RelocatedCodeOffset = 0x3,
209  },
210  },
211  },
212 
213  {
214  .ModuleName = u"ntoskrnl.exe",
215  .FunctionName = "MiProcessLoaderEntry",
216  .MinVersion = DETOUR_MIN_VERSION_ANY,
217  .MaxVersion = DETOUR_MAX_VERSION_ANY,
218  .Callback = IntDriverLoadHandler,
219  .Tag = detTagModuleLoad,
220  .Exported = FALSE,
221  .NotCritical = FALSE,
222  .DisableFlags = 0,
223  .EnableFlags = DETOUR_ENABLE_ALWAYS,
224  .Arguments = DET_ARGS_DEFAULT_WIN86,
225  .HandlersCount = 1,
226  .Handlers =
227  {
228  {
229  .MinVersion = DETOUR_MIN_VERSION_ANY,
230  .MaxVersion = DETOUR_MAX_VERSION_ANY,
231  .HypercallType = hypercallTypeInt3,
232 
233  .CodeLength = 0x8,
234  .Code =
235  {
236  // 0x00: INT3
237  0xCC,
238  // 0x01: NOP
239  0x90,
240  // 0x02: NOP
241  0x90,
242  // 0x03: JMP 0x8
243  0xE9, 0x00, 0x00, 0x00, 0x00
244  },
245  .HypercallOffset = 0x0,
246  .RelocatedCodeOffset = 0x3,
247  },
248  },
249  },
250 
251  {
252  .ModuleName = u"ntoskrnl.exe",
253  .FunctionName = "MiUnloadSystemImage",
254  .MinVersion = DETOUR_MIN_VERSION_ANY,
255  .MaxVersion = DETOUR_MAX_VERSION_ANY,
256  .Callback = IntDriverUnloadHandler,
257  .Tag = detTagModuleUnload,
258  .Exported = FALSE,
259  .NotCritical = FALSE,
260  .DisableFlags = 0,
261  .EnableFlags = DETOUR_ENABLE_ALWAYS,
262  .Arguments = DET_ARGS_DEFAULT_WIN86,
263  .HandlersCount = 1,
264  .Handlers =
265  {
266  {
267  .MinVersion = DETOUR_MIN_VERSION_ANY,
268  .MaxVersion = DETOUR_MAX_VERSION_ANY,
269  .HypercallType = hypercallTypeInt3,
270 
271  .CodeLength = 0x8,
272  .Code =
273  {
274  // 0x00: INT3
275  0xCC,
276  // 0x01: NOP
277  0x90,
278  // 0x02: NOP
279  0x90,
280  // 0x03: JMP 0x8
281  0xE9, 0x00, 0x00, 0x00, 0x00
282  },
283  .HypercallOffset = 0x0,
284  .RelocatedCodeOffset = 0x3,
285  },
286  },
287  },
288 
289  {
290  .ModuleName = u"ntoskrnl.exe",
291  .FunctionName = "PspInsertProcess",
292  .MinVersion = DETOUR_MIN_VERSION_ANY,
293  .MaxVersion = DETOUR_MAX_VERSION_ANY,
294  .PreCallback = IntWinProcPatchPspInsertProcess86,
295  .Callback = IntWinProcHandleCreate,
296  .Tag = detTagProcCreate,
297  .Exported = FALSE,
298  .NotCritical = FALSE,
299  .DisableFlags = 0,
300  .EnableFlags = DETOUR_ENABLE_ALWAYS,
301  .Arguments = DET_ARGS_DEFAULT_WIN86,
302  .HandlersCount = 1,
303  .Handlers =
304  {
305  {
306  .MinVersion = DETOUR_MIN_VERSION_ANY,
307  .MaxVersion = DETOUR_MAX_VERSION_ANY,
308  .HypercallType = hypercallTypeInt3,
309 
310  .CodeLength = 0x10,
311  .Code =
312  {
313  // 0x00: INT3
314  0xCC,
315  // 0x01: JMP 0xb
316  0xEB, 0x08,
317  // If we want to block a process, we increment the RIP from IntWinProcHandleCreate
318  // so that it points here.
319  // 0x03: MOV eax, 0xc0000022
320  0xB8, 0x22, 0x00, 0x00, 0xC0,
321  // 0x08: RETN 0x0018
322  0xC2, 0x18, 0x00,
323  // <call PspInsertProcess>
324  // 0x0B: JMP 0x10
325  0xE9, 0x00, 0x00, 0x00, 0x00
326  },
327  .HypercallOffset = 0x00,
328  .RelocatedCodeOffset = 0x0B,
329  },
330  },
331  },
332 
333  {
334  .ModuleName = u"ntoskrnl.exe",
335  .FunctionName = "MmCleanProcessAddressSpace",
336  .MinVersion = DETOUR_MIN_VERSION_ANY,
337  .MaxVersion = DETOUR_MAX_VERSION_ANY,
338  .Callback = IntWinProcHandleTerminate,
339  .Tag = detTagProcTerminate,
340  .Exported = FALSE,
341  .NotCritical = FALSE,
342  .DisableFlags = 0,
343  .EnableFlags = DETOUR_ENABLE_ALWAYS,
344  .Arguments = DET_ARGS_DEFAULT_WIN86,
345  .HandlersCount = 1,
346  .Handlers =
347  {
348  {
349  .MinVersion = DETOUR_MIN_VERSION_ANY,
350  .MaxVersion = DETOUR_MAX_VERSION_ANY,
351  .HypercallType = hypercallTypeInt3,
352 
353  .CodeLength = 0x8,
354  .Code =
355  {
356  // 0x00: INT3
357  0xCC,
358  // 0x01: NOP
359  0x90,
360  // 0x02: NOP
361  0x90,
362  // 0x03: JMP 0x8
363  0xE9, 0x00, 0x00, 0x00, 0x00
364  },
365  .HypercallOffset = 0x0,
366  .RelocatedCodeOffset = 0x3,
367  },
368  },
369  },
370 
371 
372  {
373  .ModuleName = u"ntoskrnl.exe",
374  .FunctionName = "MmCopyVirtualMemory",
375  .MinVersion = DETOUR_MIN_VERSION_ANY,
376  .MaxVersion = DETOUR_MAX_VERSION_ANY,
377  .Callback = IntWinProcHandleCopyMemory,
378  .PreCallback = IntWinProcPatchCopyMemoryDetour,
379  .Tag = detTagProcInject,
380  .Exported = FALSE,
381  .NotCritical = FALSE,
382  .DisableFlags = 0,
383  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
384  .Arguments = DET_ARGS_DEFAULT_WIN86,
385  .HandlersCount = 1,
386  .Handlers =
387  {
388  {
389  .MinVersion = DETOUR_MIN_VERSION_ANY,
390  .MaxVersion = DETOUR_MAX_VERSION_ANY,
391  .HypercallType = hypercallTypeInt3,
392 
393  .CodeLength = 0x55,
394  .Code =
395  {
396  // 0x00: PUSH eax
397  0x50,
398  // 0x01: PUSH ebx
399  0x53,
400  // 0x02: PUSH ecx
401  0x51,
402  // 0x03: MOV eax, dword ptr [esp+0x10]
403  0x8b, 0x44, 0x24, 0x10,
404  // 0x07: MOV ebx, dword ptr [esp+0x18]
405  0x8b, 0x5c, 0x24, 0x18,
406  // 0x0B: CMP eax, ebx
407  0x39, 0xd8,
408  // 0x0D: JZ 0x4d
409  0x74, 0x3e,
410  // 0x0F: MOV ecx, cr3
411  0x0f, 0x20, 0xd9,
412  // 0x12: CMP ecx, dword ptr [ebx+0x0]
413  0x3b, 0x8b, 0x00, 0x00, 0x00, 0x00,
414  // 0x18: JZ 0x2d
415  0x74, 0x13,
416  // is_write:
417  // 0x1A: MOV ebx, dword ptr [ebx+0x0]
418  0x8b, 0x9b, 0x00, 0x00, 0x00, 0x00,
419  // 0x20: CMP bl, 0x2a
420  0x80, 0xfb, 0x2a,
421  // 0x23: JNZ 0x4d
422  0x75, 0x28,
423  // 0x25: BT ebx, 0x09
424  0x0f, 0xba, 0xe3, 0x09,
425  // 0x29: JNC 0x4d
426  0x73, 0x22,
427  // 0x2B: JMP 0x3d
428  0xeb, 0x10,
429  // _is_read:
430  // 0x2D: MOV eax, dword ptr [eax+0x0]
431  0x8b, 0x80, 0x00, 0x00, 0x00, 0x00,
432  // 0x33: CMP al, 0x2a
433  0x3c, 0x2a,
434  // 0x35: JNZ 0x4d
435  0x75, 0x16,
436  // 0x37: BT eax, 0x0a
437  0x0f, 0xba, 0xe0, 0x0a,
438  // 0x3B: JNC 0x4d
439  0x73, 0x10,
440  // _do_int3:
441  // 0x3D: INT3
442  0xcc,
443  // 0x3E: CMP eax, 0xc0000022
444  0x3d, 0x22, 0x00, 0x00, 0xc0,
445  // 0x43: JNZ 0x4d
446  0x75, 0x08,
447  // 0x45: POP ecx
448  0x59,
449  // 0x46: POP ebx
450  0x5b,
451  // 0x47: ADD esp, 0x04
452  0x83, 0xc4, 0x04,
453  // 0x4A: RETN 0x001c
454  0xc2, 0x1c, 0x00,
455  // _continue_function:
456  // 0x4D: POP ecx
457  0x59,
458  // 0x4E: POP ebx
459  0x5b,
460  // 0x4F: POP eax
461  0x58,
462  // _leave:
463  // 0x50: JMP 0x55
464  0xe9, 0x00, 0x00, 0x00, 0x00,
465  },
466  .HypercallOffset = 0x3d,
467  .RelocatedCodeOffset = 0x50,
468  },
469  },
470  },
471 
472  {
473  .ModuleName = u"ntoskrnl.exe",
474  .FunctionName = "NtQueueApcThreadEx",
475  .MinVersion = DETOUR_MIN_VERSION_ANY,
476  .MaxVersion = DETOUR_MAX_VERSION_ANY,
477  .Callback = IntWinThrHandleQueueApc,
478  .PreCallback = IntWinThrPrepareApcHandler,
479  .Tag = detTagProcQueueApc,
480  .Exported = FALSE,
481  .NotCritical = FALSE,
482  .DisableFlags = 0,
483  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
484  .Arguments = DET_ARGS_DEFAULT_WIN86,
485  .HandlersCount = 1,
486  .Handlers =
487  {
488  {
489  .MinVersion = DETOUR_MIN_VERSION_ANY,
490  .MaxVersion = DETOUR_MAX_VERSION_ANY,
491  .HypercallType = hypercallTypeInt3,
492 
493  .CodeLength = 0x89,
494  .Code =
495  {
496  // 0x00: PUSH eax
497  0x50,
498  // 0x01: PUSH ecx
499  0x51,
500  // 0x02: PUSH edx
501  0x52,
502  // 0x03: MOV ecx, dword ptr [esp+0x10]
503  0x8b, 0x4c, 0x24, 0x10,
504  // 0x07: SUB esp, 0x10
505  0x83, 0xec, 0x10,
506  // 0x0A: LEA eax, [esp+0x4]
507  0x8d, 0x44, 0x24, 0x04,
508  // 0x0E: MOV dword ptr [esp+0x4], 0x00000000
509  0xc7, 0x44, 0x24, 0x04, 0x00, 0x00, 0x00, 0x00,
510  // 0x16: PUSH 0x00
511  0x6a, 0x00,
512  // 0x18: PUSH eax
513  0x50,
514  // 0x19: PUSH 0x01
515  0x6a, 0x01,
516  // 0x1B: PUSH dword ptr [0xfffff800]
517  0xff, 0x35, 0x00, 0xf8, 0xff, 0xff,
518  // PsThreadType
519  // 0x21: PUSH 0x10
520  0x6a, 0x10,
521  // 0x23: PUSH ecx
522  0x51,
523  // 0x24: MOV eax, 0xfffff800
524  0xb8, 0x00, 0xf8, 0xff, 0xff,
525  // ObReferenceObjectByHandle
526  // 0x29: CALL eax
527  0xff, 0xd0,
528  // 0x2B: TEST eax, eax
529  0x85, 0xc0,
530  // 0x2D: JNZ 0x71
531  0x75, 0x42,
532  // 0x2F: MOV ecx, dword ptr [esp+0x4]
533  0x8b, 0x4c, 0x24, 0x04,
534  // Victim thread obj
535  // 0x33: MOV eax, dword ptr [ecx+0x150]
536  0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
537  // AttachedProcess
538  // 0x39: TEST eax, eax
539  0x85, 0xc0,
540  // 0x3B: JNZ 0x43
541  0x75, 0x06,
542  // 0x3D: MOV eax, dword ptr [ecx+0x150]
543  0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
544  // _attached:
545  // 0x43: MOV eax, dword ptr [eax+0x150]
546  0x8b, 0x80, 0x50, 0x01, 0x00, 0x00,
547  // ImageFileName
548  // 0x49: CMP al, 0x2a
549  0x3c, 0x2a,
550  // Check for '*' in process name
551  // 0x4B: BT eax, 0x0c
552  0x0f, 0xba, 0xe0, 0x0c,
553  // Check QueueApc protection flag
554  // 0x4F: MOV eax, 0x00000000
555  0xb8, 0x00, 0x00, 0x00, 0x00,
556  // 0x54: JNZ 0x61
557  0x75, 0x0b,
558  // 0x56: JNC 0x61
559  0x73, 0x09,
560  // 0x58: MOV eax, dword ptr fs:[0x124]
561  0x64, 0xa1, 0x24, 0x01, 0x00, 0x00,
562  // 0x5E: INT3
563  0xcc,
564  // 0x5F: NOP
565  0x90,
566  // 0x60: NOP
567  0x90,
568  // _skip_exit:
569  // 0x61: MOV dword ptr [esp+0x8], eax
570  0x89, 0x44, 0x24, 0x08,
571  // 0x65: PUSH ecx
572  0x51,
573  // 0x66: MOV eax, 0xfffff800
574  0xb8, 0x00, 0xf8, 0xff, 0xff,
575  // ObDereferenceObject
576  // 0x6B: CALL eax
577  0xff, 0xd0,
578  // 0x6D: MOV eax, dword ptr [esp+0x8]
579  0x8b, 0x44, 0x24, 0x08,
580  // _cleanup_and_exit:
581  // 0x71: ADD esp, 0x10
582  0x83, 0xc4, 0x10,
583  // 0x74: POP edx
584  0x5a,
585  // 0x75: POP ecx
586  0x59,
587  // 0x76: CMP eax, 0xc0000022
588  0x3d, 0x22, 0x00, 0x00, 0xc0,
589  // 0x7B: JNZ 0x83
590  0x75, 0x06,
591  // 0x7D: ADD esp, 0x04
592  0x83, 0xc4, 0x04,
593  // 0x80: RETN 0x0018
594  0xc2, 0x18, 0x00,
595  // _skip:
596  // 0x83: POP eax
597  0x58,
598  // 0x84: JMP 0x85
599  0xe9, 0xfc, 0xff, 0xff, 0xff,
600  },
601  .HypercallOffset = 0x5e,
602  .RelocatedCodeOffset = 0x84,
603  },
604  },
605  },
606 
607  {
608  .ModuleName = u"ntoskrnl.exe",
609  .FunctionName = "PspSetContextThreadInternal",
610  .MinVersion = DETOUR_MIN_VERSION_ANY,
611  .MaxVersion = DETOUR_MAX_VERSION_ANY,
612  .Callback = IntWinThrHandleThreadHijack,
613  .PreCallback = IntWinThrPatchThreadHijackHandler,
614  .Tag = detTagProcThrHijack,
615  .Exported = FALSE,
616  .NotCritical = FALSE,
617  .DisableFlags = 0,
618  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
619  .Arguments = DET_ARGS_DEFAULT_WIN86,
620  .HandlersCount = 1,
621  .Handlers =
622  {
623  {
624  .MinVersion = DETOUR_MIN_VERSION_ANY,
625  .MaxVersion = DETOUR_MAX_VERSION_ANY,
626  .HypercallType = hypercallTypeInt3,
627 
628  .CodeLength = 0x4a,
629  .Code =
630  {
631  // 0x00: PUSH eax
632  0x50,
633  // 0x01: PUSH ecx
634  0x51,
635  // 0x02: MOV ecx, dword ptr [esp+0xc]
636  0x8b, 0x4c, 0x24, 0x0c,
637  // 0x06: MOV eax, dword ptr [ecx+0x80]
638  0x8b, 0x81, 0x80, 0x00, 0x00, 0x00,
639  // 0x0C: TEST eax, eax
640  0x85, 0xc0,
641  // 0x0E: JNZ 0x16
642  0x75, 0x06,
643  // 0x10: MOV eax, dword ptr [ecx+0x150]
644  0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
645  // _attached:
646  // 0x16: MOV eax, dword ptr [eax+0x170]
647  0x8b, 0x80, 0x70, 0x01, 0x00, 0x00,
648  // 0x1C: CMP al, 0x2a
649  0x3c, 0x2a,
650  // 0x1E: BT eax, 0x0b
651  0x0f, 0xba, 0xe0, 0x0b,
652  // 0x22: JNZ 0x43
653  0x75, 0x1f,
654  // 0x24: JNC 0x43
655  0x73, 0x1d,
656  // 0x26: MOV eax, dword ptr fs:[0x124]
657  0x64, 0xa1, 0x24, 0x01, 0x00, 0x00,
658  // 0x2C: CMP eax, dword ptr [esp+0xc]
659  0x3b, 0x44, 0x24, 0x0c,
660  // 0x30: JZ 0x43
661  0x74, 0x11,
662  // 0x32: INT3
663  0xcc,
664  // 0x33: NOP
665  0x90,
666  // 0x34: NOP
667  0x90,
668  // 0x35: CMP eax, 0xc0000022
669  0x3d, 0x22, 0x00, 0x00, 0xc0,
670  // 0x3A: JNZ 0x43
671  0x75, 0x07,
672  // 0x3C: POP ecx
673  0x59,
674  // 0x3D: ADD esp, 0x04
675  0x83, 0xc4, 0x04,
676  // 0x40: RETN 0x0000
677  0xc2, 0x00, 0x00,
678  // <skip>:
679  // 0x43: POP ecx
680  0x59,
681  // 0x44: POP eax
682  0x58,
683  // 0x45: JMP 0x4a
684  0xe9, 0x00, 0x00, 0x00, 0x00,
685  },
686  .HypercallOffset = 0x32,
687  .RelocatedCodeOffset = 0x45,
688  },
689  }
690 
691  },
692 
693  {
694  .ModuleName = u"ntoskrnl.exe",
695  .FunctionName = "KiDispatchException",
696  .MinVersion = DETOUR_MIN_VERSION_ANY,
697  .MaxVersion = DETOUR_MAX_VERSION_ANY,
698  .Callback = IntWinHandleException,
699  .Tag = detTagException,
700  .Exported = FALSE,
701  .NotCritical = FALSE,
702  .DisableFlags = 0,
704  .Arguments = DET_ARGS_DEFAULT_WIN86,
705  .HandlersCount = 1,
706  .Handlers =
707  {
708  {
709  .MinVersion = DETOUR_MIN_VERSION_ANY,
710  .MaxVersion = DETOUR_MAX_VERSION_ANY,
711  .HypercallType = hypercallTypeInt3,
712 
713  .CodeLength = 0x0F,
714  .Code =
715  {
716  // 0x00: CMP dword ptr [esp+0x10], 0x01
717  0x83, 0x7C, 0x24, 0x10, 0x01,
718  // 0x05: JNZ 0xa
719  0x75, 0x03,
720  // 0x07: INT3
721  0xCC,
722  // 0x08: NOP
723  0x90,
724  // 0x09: NOP
725  0x90,
726  // 0x0A: JMP 0xf
727  0xE9, 0x00, 0x00, 0x00, 0x00
728  },
729  .HypercallOffset = 0x07,
730  .RelocatedCodeOffset = 0x0A,
731  },
732  },
733  },
734 
735  {
736  .ModuleName = u"ntoskrnl.exe",
737  .FunctionName = "MiInsertPrivateVad",
738  .MinVersion = DETOUR_MIN_VERSION_ANY,
739  .MaxVersion = 18362,
740  .Callback = IntWinVadHandleInsertPrivate,
741  .PreCallback = IntWinVadPatchInsertPrivate,
742  .Tag = detTagVadInsertPriv,
743  .Exported = FALSE,
744  .NotCritical = FALSE,
745  .DisableFlags = 0,
747  .Arguments = DET_ARGS_DEFAULT_WIN86,
748  .HandlersCount = 4,
749  .Handlers =
750  {
751  {
752  .MinVersion = 7600,
753  .MaxVersion = 7602,
754  .HypercallType = hypercallTypeInt3,
755 
756  .CodeLength = 0x34,
757  .Code =
758  {
759  // 0x00: TEST byte ptr [edi+0x17], 0x02
760  0xF6, 0x47, 0x17, 0x02,
761  // 0x04: JZ 0x2f
762  0x74, 0x29,
763  // 0x06: PUSH eax
764  0x50,
765  // 0x07: PUSH ecx
766  0x51,
767  // 0x08: MOV ecx, dword ptr fs:[0x124]
768  0x64, 0x8b, 0x0d, 0x24, 0x01, 0x00, 0x00,
769  // 0x0F: MOV eax, dword ptr [ecx+0x50]
770  0x8b, 0x41, 0x50,
771  // 0x12: TEST eax, eax
772  0x85, 0xc0,
773  // 0x14: JNZ 0x1c
774  0x75, 0x06,
775  // 0x16: MOV eax, dword ptr [ecx+0x150]
776  0x8B, 0x81, 0x50, 0x01, 0x00, 0x00,
777  // 0x1C: MOV eax, dword ptr [eax+0x16c]
778  0x8b, 0x80, 0x6c, 0x01, 0x00, 0x00,
779  // 0x22: CMP al, 0x2a
780  0x3c, 0x2a,
781  // 0x24: BT eax, 0x08
782  0x0f, 0xba, 0xe0, 0x08,
783  // 0x28: POP ecx
784  0x59,
785  // 0x29: POP eax
786  0x58,
787  // 0x2A: JNZ 0x2f
788  0x75, 0x03,
789  // 0x2C: JNC 0x2f
790  0x73, 0x01,
791  // 0x2E: INT3
792  0xCC,
793  // 0x2F: JMP 0x34
794  0xE9, 0x00, 0x00, 0x00, 0x00
795  },
796  .HypercallOffset = 0x2e,
797  .RelocatedCodeOffset = 0x2f,
798  },
799 
800  {
801  .MinVersion = 9200,
802  .MaxVersion = 9200,
803  .HypercallType = hypercallTypeInt3,
804 
805  .CodeLength = 0x1c,
806  .Code =
807  {
808  // 0x00: PUSH eax
809  0x50,
810  // 0x01: MOV eax, dword ptr [esp+0x10]
811  0x8b, 0x44, 0x24, 0x10,
812  // 0x05: MOV eax, dword ptr [eax+0x170]
813  0x8b, 0x80, 0x70, 0x01, 0x00, 0x00,
814  // 0x0B: CMP al, 0x2a
815  0x3c, 0x2a,
816  // 0x0D: BT eax, 0x08
817  0x0f, 0xba, 0xe0, 0x08,
818  // 0x11: POP eax
819  0x58,
820  // 0x12: JNZ 0x17
821  0x75, 0x03,
822  // 0x14: JNC 0x17
823  0x73, 0x01,
824  // 0x16: INT3
825  0xcc,
826  // 0x17: JMP 0x1c
827  0xe9, 0x00, 0x00, 0x00, 0x00,
828  },
829  .HypercallOffset = 0x16,
830  .RelocatedCodeOffset = 0x17,
831  },
832 
833  {
834  .MinVersion = 9600,
835  .MaxVersion = 17763,
836  .HypercallType = hypercallTypeInt3,
837 
838  .CodeLength = 0x22,
839  .Code =
840  {
841  // 0x00: TEST byte ptr [ecx+0x1c], 0x10
842  0xF6, 0x41, 0x1C, 0x10,
843  // 0x04: JZ 0x1d
844  0x74, 0x17,
845  // 0x06: PUSH eax
846  0x50,
847  // 0x07: MOV eax, dword ptr [esp+0x8]
848  0x8b, 0x44, 0x24, 0x08,
849  // 0x0B: MOV eax, dword ptr [eax+0x170]
850  0x8b, 0x80, 0x70, 0x01, 0x00, 0x00,
851  // 0x11: CMP al, 0x2a
852  0x3c, 0x2a,
853  // 0x13: BT eax, 0x08
854  0x0f, 0xba, 0xe0, 0x08,
855  // 0x17: POP eax
856  0x58,
857  // 0x18: JNZ 0x1d
858  0x75, 0x03,
859  // 0x1A: JNC 0x1d
860  0x73, 0x01,
861  // 0x1C: INT3
862  0xcc,
863  // 0x1D: JMP 0x22
864  0xe9, 0x00, 0x00, 0x00, 0x00,
865  },
866  .HypercallOffset = 0x1c,
867  .RelocatedCodeOffset = 0x1d,
868  },
869 
870  {
871  .MinVersion = 18362,
872  .MaxVersion = 18362,
873  .HypercallType = hypercallTypeInt3,
874 
875  .CodeLength = 0x22,
876  .Code =
877  {
878  // 0x00: TEST byte ptr [ecx+0x1d], 0x01
879  0xF6, 0x41, 0x1d, 0x01,
880  // Flag is set in the MMVAD.MMVAD_SHORT.u (flags)
881  // 0x04: JZ 0x1d
882  0x74, 0x17,
883  // 0x06: PUSH eax
884  0x50,
885  // 0x07: MOV eax, dword ptr [esp+0x8]
886  0x8b, 0x44, 0x24, 0x08,
887  // 0x0B: MOV eax, dword ptr [eax+0x17c]
888  0x8b, 0x80, 0x7c, 0x01, 0x00, 0x00,
889  // 0x11: CMP al, 0x2a
890  0x3c, 0x2a,
891  // 0x13: BT eax, 0x08
892  0x0f, 0xba, 0xe0, 0x08,
893  // 0x17: POP eax
894  0x58,
895  // 0x18: JNZ 0x1d
896  0x75, 0x03,
897  // 0x1A: JNC 0x1d
898  0x73, 0x01,
899  // 0x1C: INT3
900  0xcc,
901  // 0x1D: JMP 0x22
902  0xe9, 0x00, 0x00, 0x00, 0x00,
903  },
904  .HypercallOffset = 0x1c,
905  .RelocatedCodeOffset = 0x1d,
906  },
907  },
908  },
909 
910  {
911  .ModuleName = u"ntoskrnl.exe",
912  .FunctionName = "MiInsertVad",
913  .MinVersion = 18363,
914  .MaxVersion = DETOUR_MAX_VERSION_ANY,
915  .Callback = IntWinVadHandleInsert,
916  .PreCallback = IntWinVadPatchInsert,
917  .Tag = detTagVadInsert,
918  .Exported = FALSE,
919  .NotCritical = FALSE,
920  .DisableFlags = 0,
922  .Arguments = DET_ARGS_DEFAULT_WIN86,
923  .HandlersCount = 1,
924  .Handlers =
925  {
926  {
927  .MinVersion = 18363,
928  .MaxVersion = DETOUR_MAX_VERSION_ANY,
929  .HypercallType = hypercallTypeInt3,
930 
931  .CodeLength = 0x1e,
932  .Code =
933  {
934  // 0x00: TEST byte ptr [ecx+0x1d], 0x01
935  0xF6, 0x41, 0x1D, 0x01,
936  // Flag is set in the MMVAD.MMVAD_SHORT.u (flags)
937  // 0x04: JZ 0x19
938  0x74, 0x13,
939  // 0x06: PUSH eax
940  0x50,
941  // 0x07: MOV eax, dword ptr [edx+0x17c]
942  0x8b, 0x82, 0x7c, 0x01, 0x00, 0x00,
943  // 0x0D: CMP al, 0x2a
944  0x3c, 0x2a,
945  // 0x0F: BT eax, 0x08
946  0x0f, 0xba, 0xe0, 0x08,
947  // 0x13: POP eax
948  0x58,
949  // 0x14: JNZ 0x19
950  0x75, 0x03,
951  // 0x16: JNC 0x19
952  0x73, 0x01,
953  // 0x18: INT3
954  0xcc,
955  // 0x19: JMP 0x1e
956  0xe9, 0x00, 0x00, 0x00, 0x00,
957  },
958  .HypercallOffset = 0x18,
959  .RelocatedCodeOffset = 0x19,
960  },
961  },
962  },
963 
964  {
965  .ModuleName = u"ntoskrnl.exe",
966  .FunctionName = "MiGetWsAndInsertVad",
967  .MinVersion = DETOUR_MIN_VERSION_ANY,
968  .MaxVersion = 18362,
969  .Callback = IntWinVadHandleInsertMap,
970  .PreCallback = IntWinVadPatchInsertMap,
971  .Tag = detTagVadInsertMap,
972  .Exported = FALSE,
973  .NotCritical = FALSE,
974  .DisableFlags = 0,
976  .Arguments = DET_ARGS_DEFAULT_WIN86,
977  .HandlersCount = 6,
978  .Handlers =
979  {
980  {
981  .MinVersion = 7600,
982  .MaxVersion = 7602,
983  .HypercallType = hypercallTypeInt3,
984 
985  .CodeLength = 0x34,
986  .Code =
987  {
988  // 0x00: TEST byte ptr [edi+0x17], 0x02
989  0xf6, 0x47, 0x17, 0x02,
990  // 0x04: JZ 0x2f
991  0x74, 0x29,
992  // 0x06: PUSH eax
993  0x50,
994  // 0x07: PUSH ecx
995  0x51,
996  // 0x08: MOV ecx, dword ptr fs:[0x124]
997  0x64, 0x8b, 0x0d, 0x24, 0x01, 0x00, 0x00,
998  // 0x0F: MOV eax, dword ptr [ecx+0x50]
999  0x8b, 0x41, 0x50,
1000  // 0x12: TEST eax, eax
1001  0x85, 0xc0,
1002  // 0x14: JNZ 0x1c
1003  0x75, 0x06,
1004  // 0x16: MOV eax, dword ptr [ecx+0x150]
1005  0x8B, 0x81, 0x50, 0x01, 0x00, 0x00,
1006  // 0x1C: MOV eax, dword ptr [eax+0x16c]
1007  0x8b, 0x80, 0x6c, 0x01, 0x00, 0x00,
1008  // 0x22: CMP al, 0x2a
1009  0x3c, 0x2a,
1010  // 0x24: BT eax, 0x08
1011  0x0f, 0xba, 0xe0, 0x08,
1012  // 0x28: POP ecx
1013  0x59,
1014  // 0x29: POP eax
1015  0x58,
1016  // 0x2A: JNZ 0x2f
1017  0x75, 0x03,
1018  // 0x2C: JNC 0x2f
1019  0x73, 0x01,
1020  // 0x2E: INT3
1021  0xCC,
1022  // 0x2F: JMP 0x34
1023  0xE9, 0x00, 0x00, 0x00, 0x00
1024  },
1025  .HypercallOffset = 0x2e,
1026  .RelocatedCodeOffset = 0x2f,
1027  },
1028 
1029  {
1030  .MinVersion = 9200,
1031  .MaxVersion = 9200,
1032  .HypercallType = hypercallTypeInt3,
1033 
1034  .CodeLength = 0x37,
1035  .Code =
1036  {
1037  // 0x00: TEST byte ptr [eax+0x18], 0x10
1038  0xf6, 0x40, 0x18, 0x10,
1039  // 0x04: JZ 0x32
1040  0x74, 0x2c,
1041  // 0x06: PUSH eax
1042  0x50,
1043  // 0x07: PUSH ecx
1044  0x51,
1045  // 0x08: MOV ecx, dword ptr fs:[0x124]
1046  0x64, 0x8b, 0x0d, 0x24, 0x01, 0x00, 0x00,
1047  // 0x0F: MOV eax, dword ptr [ecx+0x80]
1048  0x8b, 0x81, 0x80, 0x00, 0x00, 0x00,
1049  // 0x15: TEST eax, eax
1050  0x85, 0xc0,
1051  // 0x17: JNZ 0x1f
1052  0x75, 0x06,
1053  // 0x19: MOV eax, dword ptr [ecx+0x150]
1054  0x8B, 0x81, 0x50, 0x01, 0x00, 0x00,
1055  // 0x1F: MOV eax, dword ptr [eax+0x170]
1056  0x8b, 0x80, 0x70, 0x01, 0x00, 0x00,
1057  // 0x25: CMP al, 0x2a
1058  0x3c, 0x2a,
1059  // 0x27: BT eax, 0x08
1060  0x0f, 0xba, 0xe0, 0x08,
1061  // 0x2B: POP ecx
1062  0x59,
1063  // 0x2C: POP eax
1064  0x58,
1065  // 0x2D: JNZ 0x32
1066  0x75, 0x03,
1067  // 0x2F: JNC 0x32
1068  0x73, 0x01,
1069  // 0x31: INT3
1070  0xCC,
1071  // 0x32: JMP 0x37
1072  0xE9, 0x00, 0x00, 0x00, 0x00
1073  },
1074  .HypercallOffset = 0x31,
1075  .RelocatedCodeOffset = 0x32,
1076  },
1077 
1078  {
1079  .MinVersion = 9600,
1080  .MaxVersion = 17763,
1081  .HypercallType = hypercallTypeInt3,
1082 
1083  .CodeLength = 0x37,
1084  .Code =
1085  {
1086  // 0x00: TEST byte ptr [ecx+0x1c], 0x10
1087  0xf6, 0x41, 0x1c, 0x10,
1088  // 0x04: JZ 0x32
1089  0x74, 0x2c,
1090  // 0x06: PUSH eax
1091  0x50,
1092  // 0x07: PUSH ecx
1093  0x51,
1094  // 0x08: MOV ecx, dword ptr fs:[0x124]
1095  0x64, 0x8b, 0x0d, 0x24, 0x01, 0x00, 0x00,
1096  // 0x0F: MOV eax, dword ptr [ecx+0x80]
1097  0x8b, 0x81, 0x80, 0x00, 0x00, 0x00,
1098  // 0x15: TEST eax, eax
1099  0x85, 0xc0,
1100  // 0x17: JNZ 0x1f
1101  0x75, 0x06,
1102  // 0x19: MOV eax, dword ptr [ecx+0x150]
1103  0x8B, 0x81, 0x50, 0x01, 0x00, 0x00,
1104  // 0x1F: MOV eax, dword ptr [eax+0x170]
1105  0x8b, 0x80, 0x70, 0x01, 0x00, 0x00,
1106  // 0x25: CMP al, 0x2a
1107  0x3c, 0x2a,
1108  // 0x27: BT eax, 0x08
1109  0x0f, 0xba, 0xe0, 0x08,
1110  // 0x2B: POP ecx
1111  0x59,
1112  // 0x2C: POP eax
1113  0x58,
1114  // 0x2D: JNZ 0x32
1115  0x75, 0x03,
1116  // 0x2F: JNC 0x32
1117  0x73, 0x01,
1118  // 0x31: INT3
1119  0xCC,
1120  // 0x32: JMP 0x37
1121  0xE9, 0x00, 0x00, 0x00, 0x00
1122  },
1123  .HypercallOffset = 0x31,
1124  .RelocatedCodeOffset = 0x32,
1125  },
1126 
1127  {
1128  .MinVersion = 18362,
1129  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1130  .HypercallType = hypercallTypeInt3,
1131 
1132  .CodeLength = 0x37,
1133  .Code =
1134  {
1135  // 0x00:
1136  0xf6, 0x41, 0x1d, 0x1,
1137  // 0x04: JZ 0x32
1138  0x74, 0x2c,
1139  // 0x06: PUSH eax
1140  0x50,
1141  // 0x07: PUSH ecx
1142  0x51,
1143  // 0x08: MOV ecx, dword ptr fs:[0x124]
1144  0x64, 0x8b, 0x0d, 0x24, 0x01, 0x00, 0x00,
1145  // 0x0F: MOV eax, dword ptr [ecx+0x80]
1146  0x8b, 0x81, 0x80, 0x00, 0x00, 0x00,
1147  // 0x15: TEST eax, eax
1148  0x85, 0xc0,
1149  // 0x17: JNZ 0x1f
1150  0x75, 0x06,
1151  // 0x19: MOV eax, dword ptr [ecx+0x150]
1152  0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
1153  // 0x1F: MOV eax, dword ptr [eax+0x17c]
1154  0x8b, 0x80, 0x7c, 0x01, 0x00, 0x00,
1155  // 0x25: CMP al, 0x2a
1156  0x3c, 0x2a,
1157  // 0x27: BT eax, 0x08
1158  0x0f, 0xba, 0xe0, 0x08,
1159  // 0x2B: POP ecx
1160  0x59,
1161  // 0x2C: POP eax
1162  0x58,
1163  // 0x2D: JNZ 0x32
1164  0x75, 0x03,
1165  // 0x2F: JNC 0x32
1166  0x73, 0x01,
1167  // 0x31: INT3
1168  0xcc,
1169  // 0x32: JMP 0x37
1170  0xe9, 0x00, 0x00, 0x00, 0x00,
1171  },
1172  .HypercallOffset = 0x31,
1173  .RelocatedCodeOffset = 0x32,
1174  },
1175  },
1176  },
1177 
1178  {
1179  .ModuleName = u"ntoskrnl.exe",
1180  .FunctionName = "MiCommitExistingVad",
1181  .MinVersion = DETOUR_MIN_VERSION_ANY,
1182  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1183  .PreCallback = IntWinPatchVadHandleCommit,
1184  .Callback = IntWinVadHandleCommit,
1185  .Tag = detTagVadCommit,
1186  .Exported = FALSE,
1187  .NotCritical = FALSE,
1188  .DisableFlags = 0,
1189  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
1190  .Arguments = DET_ARGS_DEFAULT_WIN86,
1191  .HandlersCount = 1,
1192  .Handlers =
1193  {
1194  {
1195  .MinVersion = DETOUR_MIN_VERSION_ANY,
1196  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1197  .HypercallType = hypercallTypeInt3,
1198  .CodeLength = 0x3b,
1199  .Code =
1200  {
1201  // VmProtection & (PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE |
1202  // PAGE_EXECUTE_READ | PAGE_EXECUTE)
1203  // 0x00: TEST byte ptr [esp+0x0], 0xf0
1204  0xf6, 0x44, 0x24, 0x00, 0xf0,
1205  // 0x05: JZ 0x36
1206  0x74, 0x2f,
1207  // 0x07: PUSH ecx
1208  0x51,
1209  // 0x08: PUSH eax
1210  0x50,
1211  // ecx = Kpcr.Prcb.CurrentThread
1212  // 0x09: MOV ecx, dword ptr fs:[0x0]
1213  0x64, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
1214  // eax = Thread.ApcState.AttachedProcess
1215  // 0x10: MOV eax, dword ptr [ecx+0x0]
1216  0x8b, 0x81, 0x00, 0x00, 0x00, 0x00,
1217  // 0x16: TEST eax, eax
1218  0x85, 0xc0,
1219  // 0x18: JNZ 0x20
1220  0x75, 0x06,
1221  // eax = Thread.Process
1222  // 0x1A: MOV eax, dword ptr [ecx+0x0]
1223  0x8b, 0x81, 0x00, 0x00, 0x00, 0x00,
1224  // cmp Process.ImageFileName[0], '*'
1225  // 0x20: CMP byte ptr [eax+0x0], 0x2a
1226  0x80, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x2a,
1227  // check if 0 != (Process.ImageFileName[1] & winProcExitVad)
1228  // 0x27: BT dword ptr [eax+0x0], 0x08
1229  0x0f, 0xba, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x08,
1230  // 0x2F: POP eax
1231  0x58,
1232  // 0x30: POP ecx
1233  0x59,
1234  // 0x31: JNZ 0x36
1235  0x75, 0x03,
1236  // 0x33: JNC 0x36
1237  0x73, 0x01,
1238  // 0x35: INT3
1239  0xcc,
1240  // 0x36: JMP 0x3b
1241  0xe9, 0x00, 0x00, 0x00, 0x00
1242  },
1243  .HypercallOffset = 0x35,
1244  .RelocatedCodeOffset = 0x36,
1245  },
1246  },
1247  },
1248 
1249  {
1250  .ModuleName = u"ntoskrnl.exe",
1251  .FunctionName = "MiProtectVirtualMemory",
1252  .MinVersion = DETOUR_MIN_VERSION_ANY,
1253  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1254  .Callback = IntWinVadHandleVirtualProtect,
1255  .PreCallback = IntWinVadPatchVirtualProtect,
1256  .Tag = detTagVmProtect,
1257  .Exported = FALSE,
1258  .NotCritical = FALSE,
1259  .DisableFlags = 0,
1261  .Arguments = DET_ARGS_DEFAULT_WIN86,
1262  .HandlersCount = 5,
1263  .Handlers =
1264  {
1265  {
1266  .MinVersion = 7600,
1267  .MaxVersion = 9200,
1268  .HypercallType = hypercallTypeInt3,
1269 
1270  .CodeLength = 0x23,
1271  .Code =
1272  {
1273  // 0x00: TEST byte ptr [esp+0x10], 0xf0
1274  0xF6, 0x44, 0x24, 0x10, 0xF0,
1275  // 0x05: JZ 0x1e
1276  0x74, 0x17,
1277  // 0x07: PUSH eax
1278  0x50,
1279  // 0x08: MOV eax, dword ptr [esp+0x8]
1280  0x8b, 0x44, 0x24, 0x08,
1281  // 0x0C: MOV eax, dword ptr [eax+0x16c]
1282  0x8b, 0x80, 0x6c, 0x01, 0x00, 0x00,
1283  // 0x12: CMP al, 0x2a
1284  0x3c, 0x2a,
1285  // 0x14: BT eax, 0x08
1286  0x0f, 0xba, 0xe0, 0x08,
1287  // 0x18: POP eax
1288  0x58,
1289  // 0x19: JNZ 0x1e
1290  0x75, 0x03,
1291  // 0x1B: JNC 0x1e
1292  0x73, 0x01,
1293  // 0x1D: INT3
1294  0xcc,
1295  // 0x1E: JMP 0x23
1296  0xe9, 0x00, 0x00, 0x00, 0x00,
1297  },
1298  .HypercallOffset = 0x1d,
1299  .RelocatedCodeOffset = 0x1e,
1300  },
1301 
1302  {
1303  .MinVersion = 9600,
1304  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1305  .HypercallType = hypercallTypeInt3,
1306 
1307  .CodeLength = 0x20,
1308  .Code =
1309  {
1310  // 0x00: TEST byte ptr [esp+0xc], 0xf0
1311  0xF6, 0x44, 0x24, 0x0C, 0xF0,
1312  // 0x05: JZ 0x1b
1313  0x74, 0x14,
1314  // 0x07: CMP byte ptr [edx+0x170], 0x2a
1315  0x80, 0xba, 0x70, 0x01, 0x00, 0x00, 0x2a,
1316  // 0x0E: BT dword ptr [edx+0x170], 0x08
1317  0x0f, 0xba, 0xa2, 0x70, 0x01, 0x00, 0x00, 0x08,
1318  // 0x16: JNZ 0x1b
1319  0x75, 0x03,
1320  // 0x18: JNC 0x1b
1321  0x73, 0x01,
1322  // 0x1A: INT3
1323  0xcc,
1324  // 0x1B: JMP 0x20
1325  0xe9, 0x00, 0x00, 0x00, 0x00,
1326  },
1327  .HypercallOffset = 0x1a,
1328  .RelocatedCodeOffset = 0x1b,
1329  },
1330  },
1331  },
1332 
1333  {
1334  .ModuleName = u"ntoskrnl.exe",
1335  .FunctionName = "MiDeleteVirtualAddresses",
1336  .MinVersion = DETOUR_MIN_VERSION_ANY,
1337  .MaxVersion = 16299,
1338  .Callback = IntWinVadHandleDeleteVaRange,
1339  .PreCallback = IntWinVadPatchDeleteVaRange,
1340  .Tag = detTagVaDelete,
1341  .Exported = FALSE,
1342  .NotCritical = FALSE,
1343  .DisableFlags = 0,
1345  .Arguments = DET_ARGS_DEFAULT_WIN86,
1346  .HandlersCount = 4,
1347  .Handlers =
1348  {
1349  {
1350  .MinVersion = 7600,
1351  .MaxVersion = 7602,
1352  .HypercallType = hypercallTypeInt3,
1353 
1354  .CodeLength = 0x2e,
1355  .Code =
1356  {
1357  // 0x00: PUSH eax
1358  0x50,
1359  // 0x01: PUSH ecx
1360  0x51,
1361  // 0x02: MOV ecx, dword ptr fs:[0x124]
1362  0x64, 0x8b, 0x0d, 0x24, 0x01, 0x00, 0x00,
1363  // 0x09: MOV eax, dword ptr [ecx+0x50]
1364  0x8b, 0x41, 0x50,
1365  // 0x0C: TEST eax, eax
1366  0x85, 0xc0,
1367  // 0x0E: JNZ 0x16
1368  0x75, 0x06,
1369  // 0x10: MOV eax, dword ptr [ecx+0x150]
1370  0x8B, 0x81, 0x50, 0x01, 0x00, 0x00,
1371  // 0x16: MOV eax, dword ptr [eax+0x16c]
1372  0x8b, 0x80, 0x6c, 0x01, 0x00, 0x00,
1373  // 0x1C: CMP al, 0x2a
1374  0x3c, 0x2a,
1375  // 0x1E: BT eax, 0x08
1376  0x0f, 0xba, 0xe0, 0x08,
1377  // 0x22: POP ecx
1378  0x59,
1379  // 0x23: POP eax
1380  0x58,
1381  // 0x24: JNZ 0x29
1382  0x75, 0x03,
1383  // 0x26: JNC 0x29
1384  0x73, 0x01,
1385  // 0x28: INT3
1386  0xCC,
1387  // 0x29: JMP 0x2e
1388  0xE9, 0x00, 0x00, 0x00, 0x00
1389  },
1390  .HypercallOffset = 0x28,
1391  .RelocatedCodeOffset = 0x29,
1392  },
1393 
1394  {
1395  .MinVersion = 9200,
1396  .MaxVersion = 16299,
1397  .HypercallType = hypercallTypeInt3,
1398 
1399  .CodeLength = 0x31,
1400  .Code =
1401  {
1402  // 0x00: PUSH eax
1403  0x50,
1404  // 0x01: PUSH ecx
1405  0x51,
1406  // 0x02: MOV ecx, dword ptr fs:[0x124]
1407  0x64, 0x8b, 0x0d, 0x24, 0x01, 0x00, 0x00,
1408  // 0x09: MOV eax, dword ptr [ecx+0x80]
1409  0x8b, 0x81, 0x80, 0x00, 0x00, 0x00,
1410  // 0x0F: TEST eax, eax
1411  0x85, 0xc0,
1412  // 0x11: JNZ 0x19
1413  0x75, 0x06,
1414  // 0x13: MOV eax, dword ptr [ecx+0x150]
1415  0x8B, 0x81, 0x50, 0x01, 0x00, 0x00,
1416  // 0x19: MOV eax, dword ptr [eax+0x170]
1417  0x8b, 0x80, 0x70, 0x01, 0x00, 0x00,
1418  // 0x1F: CMP al, 0x2a
1419  0x3c, 0x2a,
1420  // 0x21: BT eax, 0x08
1421  0x0f, 0xba, 0xe0, 0x08,
1422  // 0x25: POP ecx
1423  0x59,
1424  // 0x26: POP eax
1425  0x58,
1426  // 0x27: JNZ 0x2c
1427  0x75, 0x03,
1428  // 0x29: JNC 0x2c
1429  0x73, 0x01,
1430  // 0x2B: INT3
1431  0xCC,
1432  // 0x2C: JMP 0x31
1433  0xE9, 0x00, 0x00, 0x00, 0x00
1434  },
1435  .HypercallOffset = 0x2b,
1436  .RelocatedCodeOffset = 0x2c,
1437  },
1438  },
1439  },
1440 
1441  {
1442  .ModuleName = u"ntoskrnl.exe",
1443  .FunctionName = "MiFinishVadDeletion",
1444  .MinVersion = 17134,
1445  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1447  .PreCallback = IntWinVadPatchFinishVadDeletion,
1448  .Tag = detTagFinishVadDeletion,
1449  .Exported = FALSE,
1450  .NotCritical = FALSE,
1451  .DisableFlags = 0,
1453  .Arguments = DET_ARGS_DEFAULT_WIN86,
1454  .HandlersCount = 1,
1455  .Handlers =
1456  {
1457  {
1458  .MinVersion = 17134,
1459  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1460  .HypercallType = hypercallTypeInt3,
1461 
1462  .CodeLength = 0x31,
1463  .Code =
1464  {
1465  // 0x00: PUSH eax
1466  0x50,
1467  // 0x01: PUSH ecx
1468  0x51,
1469  // 0x02: MOV ecx, dword ptr fs:[0x124]
1470  0x64, 0x8b, 0x0d, 0x24, 0x01, 0x00, 0x00,
1471  // 0x09: MOV eax, dword ptr [ecx+0x80]
1472  0x8b, 0x81, 0x80, 0x00, 0x00, 0x00,
1473  // 0x0F: TEST eax, eax
1474  0x85, 0xc0,
1475  // 0x11: JNZ 0x19
1476  0x75, 0x06,
1477  // 0x13: MOV eax, dword ptr [ecx+0x150]
1478  0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
1479  // 0x19: MOV eax, dword ptr [eax+0x17c]
1480  0x8b, 0x80, 0x7c, 0x01, 0x00, 0x00,
1481  // 0x1F: CMP al, 0x2a
1482  0x3c, 0x2a,
1483  // 0x21: BT eax, 0x08
1484  0x0f, 0xba, 0xe0, 0x08,
1485  // 0x25: POP ecx
1486  0x59,
1487  // 0x26: POP eax
1488  0x58,
1489  // 0x27: JNZ 0x2c
1490  0x75, 0x03,
1491  // 0x29: JNC 0x2c
1492  0x73, 0x01,
1493  // 0x2B: INT3
1494  0xcc,
1495  // 0x2C: JMP 0x31
1496  0xE9, 0x00, 0x00, 0x00, 0x00
1497  },
1498  .HypercallOffset = 0x2b,
1499  .RelocatedCodeOffset = 0x2c,
1500  },
1501  },
1502  },
1503 
1504  {
1505  .ModuleName = u"ntoskrnl.exe",
1506  .FunctionName = "NtSetSystemPowerState",
1507  .MinVersion = DETOUR_MIN_VERSION_ANY,
1508  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1509  .Callback = IntWinPowHandlePowerStateChange,
1510  .Tag = detTagPowerState,
1511  .Exported = FALSE,
1512  .NotCritical = TRUE,
1513  .DisableFlags = 0,
1514  .EnableFlags = DETOUR_ENABLE_ALWAYS,
1515  .Arguments = DET_ARGS_DEFAULT_WIN86,
1516  .HandlersCount = 1,
1517  .Handlers =
1518  {
1519  {
1520  .MinVersion = DETOUR_MIN_VERSION_ANY,
1521  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1522  .HypercallType = hypercallTypeInt3,
1523 
1524  .CodeLength = 0xF,
1525  .Code =
1526  {
1527  // 0x00: INT3
1528  0xcc,
1529  // 0x01: NOP
1530  0x66, 0x66, 0x66, 0x66, 0x90,
1531  // 0x06: NOP
1532  0x66, 0x90,
1533  // 0x08: NOP
1534  0x66, 0x90,
1535  // 0x0A: JMP 0xf
1536  0xe9, 0x00, 0x00, 0x00, 0x00
1537  },
1538  .HypercallOffset = 0x0,
1539  .RelocatedCodeOffset = 0xA,
1540  },
1541  },
1542  },
1543 
1544  {
1545  .ModuleName = u"ntoskrnl.exe",
1546  .FunctionName = "KiDisplayBlueScreen",
1547  .MinVersion = DETOUR_MIN_VERSION_ANY,
1548  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1549  .Callback = IntGuestUninitOnBugcheck,
1550  .Tag = detTagCleanupMemDump,
1551  .Exported = FALSE,
1552  .NotCritical = TRUE,
1553  .DisableFlags = 0,
1554  .EnableFlags = INTRO_OPT_BUGCHECK_CLEANUP,
1555  .Arguments = DET_ARGS_DEFAULT_WIN86,
1556  .HandlersCount = 1,
1557  .Handlers =
1558  {
1559  {
1560  .MinVersion = DETOUR_MIN_VERSION_ANY,
1561  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1562  .HypercallType = hypercallTypeInt3,
1563 
1564  .CodeLength = 0x8,
1565  .Code =
1566  {
1567  // 0x00: INT3
1568  0xCC,
1569  // 0x01: NOP
1570  0x90,
1571  // 0x02: NOP
1572  0x90,
1573  // 0x03: JMP 0x8
1574  0xE9, 0x00, 0x00, 0x00, 0x00
1575  },
1576  .HypercallOffset = 0x0,
1577  .RelocatedCodeOffset = 0x3,
1578  },
1579  },
1580  },
1581 };
1582 
1585 
1590 __section(".detours") =
1591 {
1592  {
1593  .ModuleName = u"ntoskrnl.exe",
1594  .FunctionName = "ExAllocatePoolWithTag",
1595  .MinVersion = DETOUR_MIN_VERSION_ANY,
1596  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1597  .Callback = IntWinPoolHandleAlloc,
1598  .Tag = detTagPoolAlloc,
1599  .Exported = TRUE,
1600  .NotCritical = FALSE,
1601  .DisableFlags = 0,
1602  .EnableFlags = DETOUR_ENABLE_ALWAYS,
1603  .Arguments = DET_ARGS_DEFAULT_WIN64,
1604  .HandlersCount = 1,
1605  .Handlers =
1606  {
1607  {
1608  .MinVersion = DETOUR_MIN_VERSION_ANY,
1609  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1610  .HypercallType = hypercallTypeInt3,
1611 
1612  .CodeLength = 0x37,
1613  .Code =
1614  {
1615  // 0x00: CMP r8d, 0xf6697244
1616  0x41, 0x81, 0xF8, 0x44, 0x72, 0x69, 0xF6,
1617  // 0x07: JZ 0x2f
1618  0x74, 0x26,
1619  // 0x09: CMP r8d, 0x76697244
1620  0x41, 0x81, 0xF8, 0x44, 0x72, 0x69, 0x76,
1621  // 0x10: JZ 0x2f
1622  0x74, 0x1D,
1623  // 0x12: CMP r8d, 0x69664d46
1624  0x41, 0x81, 0xF8, 0x46, 0x4D, 0x66, 0x69,
1625  // 0x19: JZ 0x2f
1626  0x74, 0x14,
1627  // 0x1B: CMP r8d, 0x656b6f54
1628  0x41, 0x81, 0xF8, 0x54, 0x6f, 0x6b, 0x65,
1629  // 0x22: JZ 0x2f
1630  0x74, 0x0B,
1631  // 0x24: CMP r8d, 0xe56b6f54
1632  0x41, 0x81, 0xF8, 0x54, 0x6f, 0x6b, 0xe5,
1633  // 0x2B: JZ 0x2f
1634  0x74, 0x02,
1635  // 0x2D: JMP 0x32
1636  0xEB, 0x03,
1637  // 0x2F: INT3
1638  0xCC,
1639  // 0x30: NOP
1640  0x90,
1641  // 0x31: NOP
1642  0x90,
1643  // 0x32: JMP 0x37
1644  0xE9, 0x00, 0x00, 0x00, 0x00,
1645  },
1646  .HypercallOffset = 0x2F,
1647  .RelocatedCodeOffset = 0x32,
1648  },
1649  },
1650  },
1651 
1652  {
1653  .ModuleName = u"ntoskrnl.exe",
1654  .FunctionName = "ExFreePoolWithTag",
1655  .MinVersion = DETOUR_MIN_VERSION_ANY,
1656  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1657  .Callback = IntWinPoolHandleFree,
1658  .Tag = detTagPoolFree,
1659  .Exported = TRUE,
1660  .NotCritical = FALSE,
1661  .DisableFlags = 0,
1662  .EnableFlags = DETOUR_ENABLE_ALWAYS,
1663  .Arguments = DET_ARGS_DEFAULT_WIN64,
1664  .HandlersCount = 1,
1665  .Handlers =
1666  {
1667  {
1668  .MinVersion = DETOUR_MIN_VERSION_ANY,
1669  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1670  .HypercallType = hypercallTypeInt3,
1671 
1672  .CodeLength = 0x22,
1673  .Code =
1674  {
1675  // 0x00: CMP edx, 0xf6697244
1676  0x81, 0xFA, 0x44, 0x72, 0x69, 0xF6,
1677  // 0x06: JZ 0x1a
1678  0x74, 0x12,
1679  // 0x08: CMP edx, 0x76697244
1680  0x81, 0xFA, 0x44, 0x72, 0x69, 0x76,
1681  // 0x0E: JZ 0x1a
1682  0x74, 0x0A,
1683  // 0x10: CMP edx, 0x69664d46
1684  0x81, 0xFA, 0x46, 0x4D, 0x66, 0x69,
1685  // 0x16: JZ 0x1a
1686  0x74, 0x02,
1687  // 0x18: JMP 0x1d
1688  0xEB, 0x03,
1689  // 0x1A: INT3
1690  0xCC,
1691  // 0x1B: NOP
1692  0x90,
1693  // 0x1C: NOP
1694  0x90,
1695  // 0x1D: JMP 0x22
1696  0xE9, 0x00, 0x00, 0x00, 0x00,
1697  },
1698  .HypercallOffset = 0x1A,
1699  .RelocatedCodeOffset = 0x1D,
1700  },
1701  },
1702  },
1703 
1704  {
1705  .ModuleName = u"ntoskrnl.exe",
1706  .FunctionName = "KeBugCheckEx",
1707  .MinVersion = DETOUR_MIN_VERSION_ANY,
1708  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1709  .Callback = IntWinBcHandleBugCheck,
1710  .Tag = detTagBugcheck,
1711  .Exported = TRUE,
1712  .NotCritical = FALSE,
1713  .DisableFlags = 0,
1715  .Arguments = DET_ARGS_DEFAULT_WIN64,
1716  .HandlersCount = 1,
1717  .Handlers =
1718  {
1719  {
1720  .MinVersion = DETOUR_MIN_VERSION_ANY,
1721  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1722  .HypercallType = hypercallTypeInt3,
1723 
1724  .CodeLength = 0x8,
1725  .Code =
1726  {
1727  // 0x00: INT3
1728  0xCC,
1729  // 0x01: NOP
1730  0x90,
1731  // 0x02: NOP
1732  0x90,
1733  // 0x03: JMP 0x8
1734  0xE9, 0x00, 0x00, 0x00, 0x00
1735  },
1736  .HypercallOffset = 0x0,
1737  .RelocatedCodeOffset = 0x3,
1738  },
1739  },
1740  },
1741 
1742  {
1743  .ModuleName = u"ntoskrnl.exe",
1744  .FunctionName = "MiProcessLoaderEntry",
1745  .MinVersion = DETOUR_MIN_VERSION_ANY,
1746  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1747  .Callback = IntDriverLoadHandler,
1748  .Tag = detTagModuleLoad,
1749  .Exported = FALSE,
1750  .NotCritical = FALSE,
1751  .DisableFlags = 0,
1752  .EnableFlags = DETOUR_ENABLE_ALWAYS,
1753  .Arguments = DET_ARGS_DEFAULT_WIN64,
1754  .HandlersCount = 1,
1755  .Handlers =
1756  {
1757  {
1758  .MinVersion = DETOUR_MIN_VERSION_ANY,
1759  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1760  .HypercallType = hypercallTypeInt3,
1761 
1762  .CodeLength = 0x8,
1763  .Code =
1764  {
1765  // 0x00: INT3
1766  0xCC,
1767  // 0x01: NOP
1768  0x90,
1769  // 0x02: NOP
1770  0x90,
1771  // 0x03: JMP 0x8
1772  0xE9, 0x00, 0x00, 0x00, 0x00
1773  },
1774  .HypercallOffset = 0x0,
1775  .RelocatedCodeOffset = 0x3,
1776  },
1777  },
1778  },
1779 
1780  {
1781  .ModuleName = u"ntoskrnl.exe",
1782  .FunctionName = "MiUnloadSystemImage",
1783  .MinVersion = DETOUR_MIN_VERSION_ANY,
1784  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1785  .Callback = IntDriverUnloadHandler,
1786  .Tag = detTagModuleUnload,
1787  .Exported = FALSE,
1788  .NotCritical = FALSE,
1789  .DisableFlags = 0,
1790  .EnableFlags = DETOUR_ENABLE_ALWAYS,
1791  .Arguments = DET_ARGS_DEFAULT_WIN64,
1792  .HandlersCount = 1,
1793  .Handlers =
1794  {
1795  {
1796  .MinVersion = DETOUR_MIN_VERSION_ANY,
1797  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1798  .HypercallType = hypercallTypeInt3,
1799 
1800  .CodeLength = 0x0F,
1801  .Code =
1802  {
1803  // cmp LoadCount, 1
1804  // 0x00: CMP word ptr [rcx+0x6c], 0x01
1805  0x66, 0x83, 0x79, 0x6C, 0x01,
1806  // 0x05: JNZ 0xa
1807  0x75, 0x03,
1808  // 0x07: INT3
1809  0xCC,
1810  // 0x08: NOP
1811  0x90,
1812  // 0x09: NOP
1813  0x90,
1814  // 0x0A: JMP 0xf
1815  0xE9, 0x00, 0x00, 0x00, 0x00,
1816  },
1817  .HypercallOffset = 0x07,
1818  .RelocatedCodeOffset = 0x0A,
1819  },
1820  },
1821  },
1822 
1823  {
1824  .ModuleName = u"ntoskrnl.exe",
1825  .FunctionName = "PspInsertProcess",
1826  .MinVersion = DETOUR_MIN_VERSION_ANY,
1827  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1828  .Callback = IntWinProcHandleCreate,
1829  .Tag = detTagProcCreate,
1830  .Exported = FALSE,
1831  .NotCritical = FALSE,
1832  .DisableFlags = 0,
1833  .EnableFlags = DETOUR_ENABLE_ALWAYS,
1834  .Arguments = DET_ARGS_DEFAULT_WIN64,
1835  .HandlersCount = 1,
1836  .Handlers =
1837  {
1838  {
1839  .MinVersion = DETOUR_MIN_VERSION_ANY,
1840  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1841  .HypercallType = hypercallTypeInt3,
1842 
1843  .CodeLength = 0x0E,
1844  .Code =
1845  {
1846  // 0x00: INT3
1847  0xCC,
1848  // 0x01: JMP 0x9
1849  0xEB, 0x06,
1850  // If we want to block a process, we increment the RIP from
1851  // IntWinProcHandleCreate so that it points here.
1852  // 0x03: MOV eax, 0xc0000022
1853  0xB8, 0x22, 0x00, 0x00, 0xC0,
1854  // 0x08: RETN
1855  0xC3,
1856  // <call PspInsertProcess>
1857  // 0x09: JMP 0xe
1858  0xE9, 0x00, 0x00, 0x00, 0x00,
1859  },
1860  .HypercallOffset = 0x00,
1861  .RelocatedCodeOffset = 0x09,
1862  },
1863  },
1864  },
1865 
1866  {
1867  .ModuleName = u"ntoskrnl.exe",
1868  .FunctionName = "MmCleanProcessAddressSpace",
1869  .MinVersion = DETOUR_MIN_VERSION_ANY,
1870  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1871  .Callback = IntWinProcHandleTerminate,
1872  .Tag = detTagProcTerminate,
1873  .Exported = FALSE,
1874  .NotCritical = FALSE,
1875  .DisableFlags = 0,
1876  .EnableFlags = DETOUR_ENABLE_ALWAYS,
1877  .Arguments = DET_ARGS_DEFAULT_WIN64,
1878  .HandlersCount = 1,
1879  .Handlers =
1880  {
1881  {
1882  .MinVersion = DETOUR_MIN_VERSION_ANY,
1883  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1884  .HypercallType = hypercallTypeInt3,
1885 
1886  .CodeLength = 0x8,
1887  .Code =
1888  {
1889  // 0x00: INT3
1890  0xCC,
1891  // 0x01: NOP
1892  0x90,
1893  // 0x02: NOP
1894  0x90,
1895  // 0x03: JMP 0x8
1896  0xE9, 0x00, 0x00, 0x00, 0x00
1897  },
1898  .HypercallOffset = 0x0,
1899  .RelocatedCodeOffset = 0x3,
1900  },
1901  },
1902  },
1903 
1904  {
1905  .ModuleName = u"ntoskrnl.exe",
1906  .FunctionName = "MmCopyVirtualMemory",
1907  .MinVersion = DETOUR_MIN_VERSION_ANY,
1908  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1909  .Callback = IntWinProcHandleCopyMemory,
1910  .PreCallback = IntWinProcPatchCopyMemoryDetour,
1911  .Tag = detTagProcInject,
1912  .Exported = FALSE,
1913  .NotCritical = FALSE,
1914  .DisableFlags = 0,
1915  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
1916  .Arguments = DET_ARGS_DEFAULT_WIN64,
1917  .HandlersCount = 1,
1918  .Handlers =
1919  {
1920  {
1921  .MinVersion = DETOUR_MIN_VERSION_ANY,
1922  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1923  .HypercallType = hypercallTypeInt3,
1924 
1925  .CodeLength = 0x53,
1926  .Code =
1927  {
1928  // 0x00: CMP rcx, r8
1929  0x4c, 0x39, 0xc1,
1930  // 0x03: JZ 0x4e
1931  0x74, 0x49,
1932  // 0x05: PUSH rax
1933  0x50,
1934  // 0x06: PUSH rbx
1935  0x53,
1936  // Is this a read or a write
1937  // 0x07: MOV rax, cr3
1938  0x0f, 0x20, 0xd8,
1939  // 0x0A: CMP rax, qword ptr [r8+0x0]
1940  0x49, 0x3b, 0x80, 0x00, 0x00, 0x00, 0x00,
1941  // 0x11: JZ 0x2a
1942  0x74, 0x17,
1943  // _is_write:
1944  // 0x13: CMP byte ptr [r8+0x0], 0x2a
1945  0x41, 0x80, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x2a,
1946  // 0x1B: JNZ 0x4c
1947  0x75, 0x2f,
1948  // 0x1D: BT dword ptr [r8+0x0], 0x09
1949  0x41, 0x0f, 0xba, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x09,
1950  // 0x26: JNC 0x4c
1951  0x73, 0x24,
1952  // 0x28: JMP 0x3d
1953  0xeb, 0x13,
1954  // _is_read:
1955  // 0x2A: CMP byte ptr [rcx+0x0], 0x2a
1956  0x80, 0xb9, 0x00, 0x00, 0x00, 0x00, 0x2a,
1957  // 0x31: JNZ 0x4c
1958  0x75, 0x19,
1959  // 0x33: BT dword ptr [rcx+0x0], 0x0a
1960  0x0f, 0xba, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x0a,
1961  // 0x3B: JNC 0x4c
1962  0x73, 0x0f,
1963  // _do_int3:
1964  // 0x3D: INT3
1965  0xcc,
1966  // 0x3E: NOP
1967  0x90,
1968  // 0x3F: NOP
1969  0x90,
1970  // 0x40: CMP eax, 0xc0000022
1971  0x3d, 0x22, 0x00, 0x00, 0xc0,
1972  // 0x45: JNZ 0x4c
1973  0x75, 0x05,
1974  // 0x47: ADD rsp, 0x10
1975  0x48, 0x83, 0xc4, 0x10,
1976  // 0x4B: RETN
1977  0xc3,
1978  // _continue_function:
1979  // 0x4C: POP rbx
1980  0x5b,
1981  // 0x4D: POP rax
1982  0x58,
1983  // _skip_detour:
1984  // 0x4E: JMP 0x53
1985  0xe9, 0x00, 0x00, 0x00, 0x00,
1986  },
1987  .HypercallOffset = 0x3d,
1988  .RelocatedCodeOffset = 0x4e,
1989  },
1990  },
1991  },
1992 
1993  {
1994  .ModuleName = u"ntoskrnl.exe",
1995  .FunctionName = "NtQueueApcThreadEx",
1996  .MinVersion = DETOUR_MIN_VERSION_ANY,
1997  .MaxVersion = DETOUR_MAX_VERSION_ANY,
1998  .Callback = IntWinThrHandleQueueApc,
1999  .PreCallback = IntWinThrPrepareApcHandler,
2000  .Tag = detTagProcQueueApc,
2001  .Exported = FALSE,
2002  .NotCritical = FALSE,
2003  .DisableFlags = 0,
2004  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
2005  .Arguments = DET_ARGS_DEFAULT_WIN64,
2006  .HandlersCount = 1,
2007  .Handlers =
2008  {
2009  {
2010  .MinVersion = DETOUR_MIN_VERSION_ANY,
2011  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2012  .HypercallType = hypercallTypeInt3,
2013 
2014  .CodeLength = 0xcf,
2015  .Code =
2016  {
2017  // 0x00: PUSH rax
2018  0x50,
2019  // 0x01: PUSH rcx
2020  0x51,
2021  // 0x02: PUSH rdx
2022  0x52,
2023  // 0x03: PUSH r8
2024  0x41, 0x50,
2025  // 0x05: PUSH r9
2026  0x41, 0x51,
2027  // 0x07: PUSH r10
2028  0x41, 0x52,
2029  // 0x09: PUSH r11
2030  0x41, 0x53,
2031  // 0x0B: SUB rsp, 0x20
2032  0x48, 0x83, 0xec, 0x20,
2033  // 0x0F: MOV rax, 0xfffff80000000000
2034  0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff,
2035  // PsThreadType
2036  // 0x19: MOV r8, qword ptr [rax]
2037  0x4c, 0x8b, 0x00,
2038  // 0x1C: MOV r9b, 0x01
2039  0x41, 0xb1, 0x01,
2040  // 0x1F: MOV edx, 0x00000010
2041  0xba, 0x10, 0x00, 0x00, 0x00,
2042  // 0x24: LEA rax, [rsp+0x8]
2043  0x48, 0x8d, 0x44, 0x24, 0x08,
2044  // 0x29: MOV qword ptr [rsp+0x8], 0x00000000
2045  0x48, 0xc7, 0x44, 0x24, 0x08, 0x00, 0x00, 0x00, 0x00,
2046  // 0x32: PUSH 0x00
2047  0x6a, 0x00,
2048  // 0x34: PUSH rax
2049  0x50,
2050  // 0x35: SUB rsp, 0x20
2051  0x48, 0x83, 0xec, 0x20,
2052  // 0x39: MOV rax, 0xfffff80000000000
2053  0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff,
2054  // ObReferenceObject
2055  // 0x43: CALL rax
2056  0xff, 0xd0,
2057  // 0x45: ADD rsp, 0x30
2058  0x48, 0x83, 0xc4, 0x30,
2059  // 0x49: TEST eax, eax
2060  0x85, 0xc0,
2061  // 0x4B: JNZ 0xaf
2062  0x75, 0x62,
2063  // 0x4D: MOV rcx, qword ptr [rsp+0x8]
2064  0x48, 0x8b, 0x4c, 0x24, 0x08,
2065  // Victim thread obj
2066  // 0x52: MOV r9, qword ptr [rsp+0x30]
2067  0x4c, 0x8b, 0x4c, 0x24, 0x30,
2068  // 0x57: MOV r8, qword ptr [rsp+0x38]
2069  0x4c, 0x8b, 0x44, 0x24, 0x38,
2070  // 0x5C: MOV rax, qword ptr [rcx+0x150]
2071  0x48, 0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
2072  // AttachedProcess
2073  // 0x63: TEST rax, rax
2074  0x48, 0x85, 0xc0,
2075  // 0x66: JNZ 0x6f
2076  0x75, 0x07,
2077  // 0x68: MOV rax, qword ptr [rcx+0x150]
2078  0x48, 0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
2079  // Process
2080  // _attached:
2081  // 0x6F: MOV rax, qword ptr [rax+0x150]
2082  0x48, 0x8b, 0x80, 0x50, 0x01, 0x00, 0x00,
2083  // ImageFileName
2084  // 0x76: CMP al, 0x2a
2085  0x3c, 0x2a,
2086  // Check for '*' in process name
2087  // 0x78: BT rax, 0x0c
2088  0x48, 0x0f, 0xba, 0xe0, 0x0c,
2089  // Check QueueApc protection flag
2090  // 0x7D: MOV rax, 0x00000000
2091  0x48, 0xc7, 0xc0, 0x00, 0x00, 0x00, 0x00,
2092  // 0x84: JNZ 0x94
2093  0x75, 0x0e,
2094  // 0x86: JNC 0x94
2095  0x73, 0x0c,
2096  // 0x88: MOV rax, qword ptr gs:[0x188]
2097  0x65, 0x48, 0x8b, 0x04, 0x25, 0x88, 0x01, 0x00, 0x00,
2098  // 0x91: INT3
2099  0xcc,
2100  // 0x92: NOP
2101  0x90,
2102  // 0x93: NOP
2103  0x90,
2104  // _skip_exit:
2105  // 0x94: MOV qword ptr [rsp+0x10], rax
2106  0x48, 0x89, 0x44, 0x24, 0x10,
2107  // 0x99: MOV rcx, qword ptr [rsp+0x8]
2108  0x48, 0x8b, 0x4c, 0x24, 0x08,
2109  // 0x9E: MOV rax, 0xfffff80000000000
2110  0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff,
2111  // ObDereference
2112  // 0xA8: CALL rax
2113  0xff, 0xd0,
2114  // 0xAA: MOV rax, qword ptr [rsp+0x10]
2115  0x48, 0x8b, 0x44, 0x24, 0x10,
2116  // _cleanup_and_exit:
2117  // 0xAF: ADD rsp, 0x20
2118  0x48, 0x83, 0xc4, 0x20,
2119  // 0xB3: POP r11
2120  0x41, 0x5b,
2121  // 0xB5: POP r10
2122  0x41, 0x5a,
2123  // 0xB7: POP r9
2124  0x41, 0x59,
2125  // 0xB9: POP r8
2126  0x41, 0x58,
2127  // 0xBB: POP rdx
2128  0x5a,
2129  // 0xBC: POP rcx
2130  0x59,
2131  // 0xBD: CMP eax, 0xc0000022
2132  0x3d, 0x22, 0x00, 0x00, 0xc0,
2133  // 0xC2: JNZ 0xc9
2134  0x75, 0x05,
2135  // 0xC4: ADD rsp, 0x08
2136  0x48, 0x83, 0xc4, 0x08,
2137  // 0xC8: RETN
2138  0xc3,
2139  // _skip:
2140  // 0xC9: POP rax
2141  0x58,
2142  // 0xCA: JMP 0xcf
2143  0xe9, 0x00, 0x00, 0x00, 0x00,
2144  },
2145  .HypercallOffset = 0x91,
2146  .RelocatedCodeOffset = 0xca,
2147  },
2148  },
2149  },
2150 
2151  {
2152  .ModuleName = u"ntoskrnl.exe",
2153  .FunctionName = "PspSetContextThreadInternal",
2154  .MinVersion = DETOUR_MIN_VERSION_ANY,
2155  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2156  .Callback = IntWinThrHandleThreadHijack,
2157  .PreCallback = IntWinThrPatchThreadHijackHandler,
2158  .Tag = detTagProcThrHijack,
2159  .Exported = FALSE,
2160  .NotCritical = FALSE,
2161  .DisableFlags = 0,
2162  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
2163  .Arguments = DET_ARGS_DEFAULT_WIN64,
2164  .HandlersCount = 1,
2165  .Handlers =
2166  {
2167  {
2168  .MinVersion = DETOUR_MIN_VERSION_ANY,
2169  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2170  .HypercallType = hypercallTypeInt3,
2171 
2172  .CodeLength = 0x49,
2173  .Code =
2174  {
2175  // 0x00: PUSH rax
2176  0x50,
2177  // 0x01: MOV rax, qword ptr [rcx+0x150]
2178  0x48, 0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
2179  // AttachedProcess
2180  // 0x08: TEST rax, rax
2181  0x48, 0x85, 0xc0,
2182  // 0x0B: JNZ 0x14
2183  0x75, 0x07,
2184  // 0x0D: MOV rax, qword ptr [rcx+0x150]
2185  0x48, 0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
2186  // Process
2187  // _attached:
2188  // 0x14: MOV rax, qword ptr [rax+0x150]
2189  0x48, 0x8b, 0x80, 0x50, 0x01, 0x00, 0x00,
2190  // ImageFileName
2191  // 0x1B: CMP al, 0x2a
2192  0x3c, 0x2a,
2193  // Check for "*" in process name
2194  // 0x1D: BT rax, 0x0b
2195  0x48, 0x0f, 0xba, 0xe0, 0x0b,
2196  // ThreadCtx protection flag
2197  // 0x22: JNZ 0x43
2198  0x75, 0x1f,
2199  // 0x24: JNC 0x43
2200  0x73, 0x1d,
2201  // 0x26: MOV rax, qword ptr gs:[0x188]
2202  0x65, 0x48, 0x8b, 0x04, 0x25, 0x88, 0x01, 0x00, 0x00,
2203  // 0x2F: CMP rax, rcx
2204  0x48, 0x39, 0xc8,
2205  // 0x32: JZ 0x43
2206  0x74, 0x0f,
2207  // 0x34: INT3
2208  0xcc,
2209  // 0x35: NOP
2210  0x90,
2211  // 0x36: NOP
2212  0x90,
2213  // 0x37: CMP eax, 0xc0000022
2214  0x3d, 0x22, 0x00, 0x00, 0xc0,
2215  // 0x3C: JNZ 0x43
2216  0x75, 0x05,
2217  // 0x3E: ADD rsp, 0x08
2218  0x48, 0x83, 0xc4, 0x08,
2219  // 0x42: RETN
2220  0xc3,
2221  // <skip>:
2222  // 0x43: POP rax
2223  0x58,
2224  // 0x44: JMP 0x49
2225  0xe9, 0x00, 0x00, 0x00, 0x00,
2226  },
2227  .HypercallOffset = 0x34,
2228  .RelocatedCodeOffset = 0x44,
2229  },
2230  },
2231  },
2232 
2233  // This has the same functionality as PspSetContextThreadInternal, but for a WOW64 Process setting context on a
2234  // WOW64 victim, PspSetContextThreadInternal is saved only when XSAVE_STATE is set.
2235  // This function has the same PspWow64SetContextThreadOnAmd64 for NtBuildNumber < 10240, PspWowSetContextThread
2236  // for NtBuildNumber == 10240 and PspWow64SetContextThread for NtBuildNumber > 10240
2237  {
2238  .ModuleName = u"ntoskrnl.exe",
2239  .FunctionName = "PspWow64SetContextThread",
2240  .MinVersion = DETOUR_MIN_VERSION_ANY,
2241  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2242  .Callback = IntWinThrHandleThreadHijack,
2243  .PreCallback = IntWinThrPatchThreadHijackHandler,
2244  .Tag = detTagProcThrHijackWow64,
2245  .Exported = FALSE,
2246  .NotCritical = FALSE,
2247  .DisableFlags = 0,
2248  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
2249  .Arguments = DET_ARGS_DEFAULT_WIN64,
2250  .HandlersCount = 1,
2251  .Handlers =
2252  {
2253  {
2254  .MinVersion = DETOUR_MIN_VERSION_ANY,
2255  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2256  .HypercallType = hypercallTypeInt3,
2257 
2258  .CodeLength = 0x49,
2259  .Code =
2260  {
2261  // 0x00: PUSH rax
2262  0x50,
2263  // 0x01: MOV rax, qword ptr [rcx+0x150]
2264  0x48, 0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
2265  // AttachedProcess
2266  // 0x08: TEST rax, rax
2267  0x48, 0x85, 0xc0,
2268  // 0x0B: JNZ 0x14
2269  0x75, 0x07,
2270  // 0x0D: MOV rax, qword ptr [rcx+0x150]
2271  0x48, 0x8b, 0x81, 0x50, 0x01, 0x00, 0x00,
2272  // Process
2273  // _attached
2274  // 0x14: MOV rax, qword ptr [rax+0x150]
2275  0x48, 0x8b, 0x80, 0x50, 0x01, 0x00, 0x00,
2276  // ImageFileName
2277  // 0x1B: CMP al, 0x2a
2278  0x3c, 0x2a,
2279  // 0x1D: BT rax, 0x0b
2280  0x48, 0x0f, 0xba, 0xe0, 0x0b,
2281  // ThreadCtx protection flag
2282  // 0x22: JNZ 0x43
2283  0x75, 0x1f,
2284  // 0x24: JNC 0x43
2285  0x73, 0x1d,
2286  // 0x26: MOV rax, qword ptr gs:[0x188]
2287  0x65, 0x48, 0x8b, 0x04, 0x25, 0x88, 0x01, 0x00, 0x00,
2288  // 0x2F: CMP rax, rcx
2289  0x48, 0x39, 0xc8,
2290  // 0x32: JZ 0x43
2291  0x74, 0x0f,
2292  // 0x34: INT3
2293  0xcc,
2294  // 0x35: NOP
2295  0x90,
2296  // 0x36: NOP
2297  0x90,
2298  // 0x37: CMP eax, 0xc0000022
2299  0x3d, 0x22, 0x00, 0x00, 0xc0,
2300  // 0x3C: JNZ 0x43
2301  0x75, 0x05,
2302  // 0x3E: ADD rsp, 0x08
2303  0x48, 0x83, 0xc4, 0x08,
2304  // 0x42: RETN
2305  0xc3,
2306  // _skip:
2307  // 0x43: POP rax
2308  0x58,
2309  // 0x44: JMP 0x49
2310  0xe9, 0x00, 0x00, 0x00, 0x00,
2311  },
2312  .HypercallOffset = 0x34,
2313  .RelocatedCodeOffset = 0x44,
2314  },
2315  },
2316  },
2317 
2318  {
2319  .ModuleName = u"ntoskrnl.exe",
2320  .FunctionName = "KiDispatchException",
2321  .MinVersion = DETOUR_MIN_VERSION_ANY,
2322  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2323  .Callback = IntWinHandleException,
2324  .Tag = detTagException,
2325  .Exported = FALSE,
2326  .NotCritical = FALSE,
2327  .DisableFlags = 0,
2329  .Arguments = DET_ARGS_DEFAULT_WIN64,
2330  .HandlersCount = 1,
2331  .Handlers =
2332  {
2333  {
2334  .MinVersion = DETOUR_MIN_VERSION_ANY,
2335  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2336  .HypercallType = hypercallTypeInt3,
2337 
2338  .CodeLength = 0x0E,
2339  .Code =
2340  {
2341  // 0x00: CMP r9d, 0x00
2342  0x41, 0x83, 0xf9, 0x00,
2343  // 0x04: JZ 0x9
2344  0x74, 0x03,
2345  // 0x06: INT3
2346  0xCC,
2347  // 0x07: NOP
2348  0x90,
2349  // 0x08: NOP
2350  0x90,
2351  // 0x09: JMP 0xe
2352  0xE9, 0x00, 0x00, 0x00, 0x00
2353  },
2354  .HypercallOffset = 0x06,
2355  .RelocatedCodeOffset = 0x09,
2356  },
2357  },
2358  },
2359 
2360  {
2361  .ModuleName = u"ntoskrnl.exe",
2362  .FunctionName = "MiInsertVad",
2363  .MinVersion = 10240,
2364  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2365  .Callback = IntWinVadHandleInsert,
2366  .PreCallback = IntWinVadPatchInsert,
2367  .Tag = detTagVadInsert,
2368  .Exported = FALSE,
2369  .NotCritical = FALSE,
2370  .DisableFlags = 0,
2372  .Arguments = DET_ARGS_DEFAULT_WIN64,
2373  .HandlersCount = 2,
2374  .Handlers =
2375  {
2376  {
2377  .MinVersion = 10240,
2378  .MaxVersion = 17763,
2379  .HypercallType = hypercallTypeInt3,
2380 
2381  .CodeLength = 0x1f,
2382  .Code =
2383  {
2384  // 0x00: TEST byte ptr [rcx+0x30], 0x10
2385  0xF6, 0x41, 0x30, 0x10,
2386  // 0x04: JZ 0x1a
2387  0x74, 0x14,
2388  // 0x06: CMP byte ptr [rdx+0x448], 0x2a
2389  0x80, 0xBA, 0x48, 0x04, 0x00, 0x00, 0x2A,
2390  // 0x0D: BT dword ptr [rdx+0x448], 0x08
2391  0x0f, 0xba, 0xa2, 0x48, 0x04, 0x00, 0x00, 0x08,
2392  // 0x15: JNZ 0x1a
2393  0x75, 0x03,
2394  // 0x17: JNC 0x1a
2395  0x73, 0x01,
2396  // 0x19: INT3
2397  0xCC,
2398  // 0x1A: JMP 0x1f
2399  0xE9, 0x00, 0x00, 0x00, 0x00,
2400  },
2401  .HypercallOffset = 0x19,
2402  .RelocatedCodeOffset = 0x1a,
2403  },
2404 
2405  {
2406  .MinVersion = 18362,
2407  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2408  .HypercallType = hypercallTypeInt3,
2409 
2410  .CodeLength = 0x1f,
2411  .Code =
2412  {
2413  // 0x00: TEST byte ptr [rcx+0x31], 0x01
2414  0xF6, 0x41, 0x31, 0x01,
2415  // 0x04: JZ 0x1a
2416  0x74, 0x14,
2417  // 0x06: CMP byte ptr [rdx+0x448], 0x2a
2418  0x80, 0xBA, 0x48, 0x04, 0x00, 0x00, 0x2A,
2419  // 0x0D: BT dword ptr [rdx+0x448], 0x08
2420  0x0f, 0xba, 0xa2, 0x48, 0x04, 0x00, 0x00, 0x08,
2421  // 0x15: JNZ 0x1a
2422  0x75, 0x03,
2423  // 0x17: JNC 0x1a
2424  0x73, 0x01,
2425  // 0x19: INT3
2426  0xCC,
2427  // 0x1A: JMP 0x1f
2428  0xE9, 0x00, 0x00, 0x00, 0x00,
2429  },
2430  .HypercallOffset = 0x19,
2431  .RelocatedCodeOffset = 0x1a,
2432  },
2433  },
2434  },
2435 
2436 
2437  {
2438  .ModuleName = u"ntoskrnl.exe",
2439  .FunctionName = "MiInsertPrivateVad",
2440  .MinVersion = DETOUR_MIN_VERSION_ANY,
2441  .MaxVersion = 9600,
2442  .Callback = IntWinVadHandleInsertPrivate,
2443  .PreCallback = IntWinVadPatchInsertPrivate,
2444  .Tag = detTagVadInsertPriv,
2445  .Exported = FALSE,
2446  .NotCritical = FALSE,
2447  .DisableFlags = 0,
2449  .Arguments = DET_ARGS_DEFAULT_WIN64,
2450  .HandlersCount = 3,
2451  .Handlers =
2452  {
2453  {
2454  .MinVersion = 7600,
2455  .MaxVersion = 7602,
2456  .HypercallType = hypercallTypeInt3,
2457 
2458  .CodeLength = 0x3e,
2459  .Code =
2460  {
2461  // 0x00: TEST byte ptr [rcx+0x2f], 0x02
2462  0xF6, 0x41, 0x2F, 0x02,
2463  // 0x04: JZ 0x39
2464  0x74, 0x33,
2465  // 0x06: PUSH rax
2466  0x50,
2467  // 0x07: PUSH rcx
2468  0x51,
2469  // 0x08: MOV rcx, qword ptr gs:[0x188]
2470  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
2471  // 0x11: MOV rax, qword ptr [rcx+0x70]
2472  0x48, 0x8B, 0x81, 0x70, 0x00, 0x00, 0x00,
2473  // 0x18: TEST eax, eax
2474  0x85, 0xC0,
2475  // 0x1A: JNZ 0x23
2476  0x75, 0x07,
2477  // 0x1C: MOV rax, qword ptr [rcx+0x210]
2478  0x48, 0x8B, 0x81, 0x10, 0x02, 0x00, 0x00,
2479  // 0x23: CMP byte ptr [rax+0x2e0], 0x2a
2480  0x80, 0xB8, 0xE0, 0x02, 0x00, 0x00, 0x2A,
2481  // 0x2A: BT dword ptr [rax+0x2e0], 0x08
2482  0x0f, 0xba, 0xa0, 0xe0, 0x02, 0x00, 0x00, 0x08,
2483  // 0x32: POP rcx
2484  0x59,
2485  // 0x33: POP rax
2486  0x58,
2487  // 0x34: JNZ 0x39
2488  0x75, 0x03,
2489  // 0x36: JNC 0x39
2490  0x73, 0x01,
2491  // 0x38: INT3
2492  0xCC,
2493  // 0x39: JMP 0x3e
2494  0xE9, 0x00, 0x00, 0x00, 0x00
2495  },
2496  .HypercallOffset = 0x38,
2497  .RelocatedCodeOffset = 0x39,
2498  },
2499 
2500  {
2501  .MinVersion = 9200,
2502  .MaxVersion = 9200,
2503  .HypercallType = hypercallTypeInt3,
2504 
2505  .CodeLength = 0x3e,
2506  .Code =
2507  {
2508  // 0x00: TEST byte ptr [rcx+0x28], 0x10
2509  0xF6, 0x41, 0x28, 0x10,
2510  // 0x04: JZ 0x39
2511  0x74, 0x33,
2512  // 0x06: PUSH rax
2513  0x50,
2514  // 0x07: PUSH rcx
2515  0x51,
2516  // 0x08: MOV rcx, qword ptr gs:[0x188]
2517  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
2518  // 0x11: MOV rax, qword ptr [rcx+0xb8]
2519  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
2520  // 0x18: TEST eax, eax
2521  0x85, 0xC0,
2522  // 0x1A: JNZ 0x23
2523  0x75, 0x07,
2524  // 0x1C: MOV rax, qword ptr [rcx+0x220]
2525  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
2526  // 0x23: CMP byte ptr [rax+0x438], 0x2a
2527  0x80, 0xB8, 0x38, 0x04, 0x00, 0x00, 0x2A,
2528  // 0x2A: BT dword ptr [rax+0x438], 0x08
2529  0x0f, 0xba, 0xa0, 0x38, 0x04, 0x00, 0x00, 0x08,
2530  // 0x32: POP rcx
2531  0x59,
2532  // 0x33: POP rax
2533  0x58,
2534  // 0x34: JNZ 0x39
2535  0x75, 0x03,
2536  // 0x36: JNC 0x39
2537  0x73, 0x01,
2538  // 0x38: INT3
2539  0xCC,
2540  // 0x39: JMP 0x3e
2541  0xE9, 0x00, 0x00, 0x00, 0x00
2542  },
2543  .HypercallOffset = 0x38,
2544  .RelocatedCodeOffset = 0x39,
2545  },
2546 
2547  {
2548  .MinVersion = 9600,
2549  .MaxVersion = 9600,
2550  .HypercallType = hypercallTypeInt3,
2551 
2552  .CodeLength = 0x21,
2553  .Code =
2554  {
2555  // 0x00: TEST byte ptr [rcx+0x30], 0x10
2556  0xF6, 0x41, 0x30, 0x10,
2557  // 0x04: JZ 0x1b
2558  0x74, 0x15,
2559  // 0x06: CMP byte ptr [r8+0x438], 0x2a
2560  0x41, 0x80, 0xB8, 0x38, 0x04, 0x00, 0x00, 0x2A,
2561  // 0x0E: BT dword ptr [r8+0x438], 0x08
2562  0x41, 0x0f, 0xba, 0xa0, 0x38, 0x04, 0x00, 0x00, 0x08,
2563  // 0x17: JNZ 0x1c
2564  0x75, 0x03,
2565  // 0x19: JNC 0x1c
2566  0x73, 0x01,
2567  // 0x1B: INT3
2568  0xCC,
2569  // 0x1C: JMP 0x21
2570  0xE9, 0x00, 0x00, 0x00, 0x00,
2571  },
2572  .HypercallOffset = 0x1b,
2573  .RelocatedCodeOffset = 0x1c,
2574  },
2575  },
2576  },
2577 
2578  {
2579  .ModuleName = u"ntoskrnl.exe",
2580  .FunctionName = "MiInsertPrivateVad",
2581  .MinVersion = 17763,
2582  .MaxVersion = 18362,
2583  .Callback = IntWinVadHandleInsertPrivate,
2584  .PreCallback = IntWinVadPatchInsertPrivate,
2585  .Tag = detTagVadInsertPriv,
2586  .Exported = FALSE,
2587  .NotCritical = FALSE,
2588  .DisableFlags = 0,
2590  .Arguments = DET_ARGS_DEFAULT_WIN64,
2591  .HandlersCount = 2,
2592  .Handlers = {
2593  // Windows 10 RS5 17763
2594  {
2595  .MinVersion = 17763,
2596  .MaxVersion = 17763,
2597  .HypercallType = hypercallTypeInt3,
2598 
2599  .CodeLength = 0x3e,
2600  .Code =
2601  {
2602  // 0x00: TEST byte ptr [rcx+0x30], 0x10
2603  0xF6, 0x41, 0x30, 0x10,
2604  // 0x04: JZ 0x39
2605  0x74, 0x33,
2606  // 0x06: PUSH rax
2607  0x50,
2608  // 0x07: PUSH rcx
2609  0x51,
2610  // 0x08: MOV rcx, qword ptr gs:[0x188]
2611  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
2612  // 0x11: MOV rax, qword ptr [rcx+0xb8]
2613  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
2614  // 0x18: TEST eax, eax
2615  0x85, 0xC0,
2616  // 0x1A: JNZ 0x23
2617  0x75, 0x07,
2618  // 0x1C: MOV rax, qword ptr [rcx+0x220]
2619  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
2620  // 0x23: CMP byte ptr [rax+0x450], 0x2a
2621  0x80, 0xB8, 0x50, 0x04, 0x00, 0x00, 0x2A,
2622  // 0x2A: BT dword ptr [rax+0x450], 0x08
2623  0x0f, 0xba, 0xa0, 0x50, 0x04, 0x00, 0x00, 0x08,
2624  // 0x32: POP rcx
2625  0x59,
2626  // 0x33: POP rax
2627  0x58,
2628  // 0x34: JNZ 0x39
2629  0x75, 0x03,
2630  // 0x36: JNC 0x39
2631  0x73, 0x01,
2632  // 0x38: INT3
2633  0xCC,
2634  // 0x39: JMP 0x3e
2635  0xE9, 0x00, 0x00, 0x00, 0x00
2636  },
2637  .HypercallOffset = 0x38,
2638  .RelocatedCodeOffset = 0x39,
2639  },
2640  // Windows 10 19H1
2641  {
2642  .MinVersion = 18362,
2643  .MaxVersion = 18362,
2644  .HypercallType = hypercallTypeInt3,
2645 
2646  .CodeLength = 0x3e,
2647  .Code =
2648  {
2649  // 0x00: TEST byte ptr [rcx+0x31], 0x01
2650  0xf6, 0x41, 0x31, 0x01,
2651  // 0x04: JZ 0x39
2652  0x74, 0x33,
2653  // 0x06: PUSH rax
2654  0x50,
2655  // 0x07: PUSH rcx
2656  0x51,
2657  // 0x08: MOV rcx, qword ptr gs:[0x188]
2658  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
2659  // 0x11: MOV rax, qword ptr [rcx+0xb8]
2660  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
2661  // 0x18: TEST eax, eax
2662  0x85, 0xC0,
2663  // 0x1A: JNZ 0x23
2664  0x75, 0x07,
2665  // 0x1C: MOV rax, qword ptr [rcx+0x220]
2666  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
2667  // 0x23: CMP byte ptr [rax+0x450], 0x2a
2668  0x80, 0xB8, 0x50, 0x04, 0x00, 0x00, 0x2A,
2669  // 0x2A: BT dword ptr [rax+0x450], 0x08
2670  0x0f, 0xba, 0xa0, 0x50, 0x04, 0x00, 0x00, 0x08,
2671  // 0x32: POP rcx
2672  0x59,
2673  // 0x33: POP rax
2674  0x58,
2675  // 0x34: JNZ 0x39
2676  0x75, 0x03,
2677  // 0x36: JNC 0x39
2678  0x73, 0x01,
2679  // 0x38: INT3
2680  0xCC,
2681  // 0x39: JMP 0x3e
2682  0xE9, 0x00, 0x00, 0x00, 0x00
2683  },
2684  .HypercallOffset = 0x38,
2685  .RelocatedCodeOffset = 0x39,
2686  },
2687  },
2688  },
2689 
2690  {
2691  .ModuleName = u"ntoskrnl.exe",
2692  .FunctionName = "MiGetWsAndInsertVad",
2693  .MinVersion = DETOUR_MIN_VERSION_ANY,
2694  .MaxVersion = 9600,
2695  .Callback = IntWinVadHandleInsertMap,
2696  .PreCallback = IntWinVadPatchInsertMap,
2697  .Tag = detTagVadInsertMap,
2698  .Exported = FALSE,
2699  .NotCritical = FALSE,
2700  .DisableFlags = 0,
2702  .Arguments = DET_ARGS_DEFAULT_WIN64,
2703  .HandlersCount = 3,
2704  .Handlers =
2705  {
2706  {
2707  .MinVersion = 7600,
2708  .MaxVersion = 7602,
2709  .HypercallType = hypercallTypeInt3,
2710 
2711  .CodeLength = 0x3e,
2712  .Code =
2713  {
2714  // 0x00: TEST byte ptr [rcx+0x2f], 0x02
2715  0xF6, 0x41, 0x2F, 0x02,
2716  // 0x04: JZ 0x39
2717  0x74, 0x33,
2718  // 0x06: PUSH rax
2719  0x50,
2720  // 0x07: PUSH rcx
2721  0x51,
2722  // 0x08: MOV rcx, qword ptr gs:[0x188]
2723  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
2724  // 0x11: MOV rax, qword ptr [rcx+0x70]
2725  0x48, 0x8B, 0x81, 0x70, 0x00, 0x00, 0x00,
2726  // 0x18: TEST eax, eax
2727  0x85, 0xC0,
2728  // 0x1A: JNZ 0x23
2729  0x75, 0x07,
2730  // 0x1C: MOV rax, qword ptr [rcx+0x210]
2731  0x48, 0x8B, 0x81, 0x10, 0x02, 0x00, 0x00,
2732  // 0x23: CMP byte ptr [rax+0x2e0], 0x2a
2733  0x80, 0xB8, 0xE0, 0x02, 0x00, 0x00, 0x2A,
2734  // 0x2A: BT dword ptr [rax+0x2e0], 0x08
2735  0x0f, 0xba, 0xa0, 0xe0, 0x02, 0x00, 0x00, 0x08,
2736  // 0x32: POP rcx
2737  0x59,
2738  // 0x33: POP rax
2739  0x58,
2740  // 0x34: JNZ 0x39
2741  0x75, 0x03,
2742  // 0x36: JNC 0x39
2743  0x73, 0x01,
2744  // 0x38: INT3
2745  0xCC,
2746  // 0x39: JMP 0x3e
2747  0xE9, 0x00, 0x00, 0x00, 0x00
2748  },
2749  .HypercallOffset = 0x38,
2750  .RelocatedCodeOffset = 0x39,
2751  },
2752 
2753  {
2754  .MinVersion = 9200,
2755  .MaxVersion = 9200,
2756  .HypercallType = hypercallTypeInt3,
2757 
2758  .CodeLength = 0x3e,
2759  .Code =
2760  {
2761  // 0x00: TEST byte ptr [rcx+0x28], 0x10
2762  0xF6, 0x41, 0x28, 0x10,
2763  // 0x04: JZ 0x39
2764  0x74, 0x33,
2765  // 0x06: PUSH rax
2766  0x50,
2767  // 0x07: PUSH rcx
2768  0x51,
2769  // 0x08: MOV rcx, qword ptr gs:[0x188]
2770  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
2771  // 0x11: MOV rax, qword ptr [rcx+0xb8]
2772  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
2773  // 0x18: TEST eax, eax
2774  0x85, 0xC0,
2775  // 0x1A: JNZ 0x23
2776  0x75, 0x07,
2777  // 0x1C: MOV rax, qword ptr [rcx+0x220]
2778  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
2779  // 0x23: CMP byte ptr [rax+0x438], 0x2a
2780  0x80, 0xB8, 0x38, 0x04, 0x00, 0x00, 0x2A,
2781  // 0x2A: BT dword ptr [rax+0x438], 0x08
2782  0x0f, 0xba, 0xa0, 0x38, 0x04, 0x00, 0x00, 0x08,
2783  // 0x32: POP rcx
2784  0x59,
2785  // 0x33: POP rax
2786  0x58,
2787  // 0x34: JNZ 0x39
2788  0x75, 0x03,
2789  // 0x36: JNC 0x39
2790  0x73, 0x01,
2791  // 0x38: INT3
2792  0xCC,
2793  // 0x39: JMP 0x3e
2794  0xE9, 0x00, 0x00, 0x00, 0x00
2795  },
2796  .HypercallOffset = 0x38,
2797  .RelocatedCodeOffset = 0x39,
2798  },
2799 
2800  {
2801  .MinVersion = 9600,
2802  .MaxVersion = 9600,
2803  .HypercallType = hypercallTypeInt3,
2804 
2805  .CodeLength = 0x3e,
2806  .Code =
2807  {
2808  // 0x00: TEST byte ptr [rcx+0x30], 0x10
2809  0xF6, 0x41, 0x30, 0x10,
2810  // 0x04: JZ 0x39
2811  0x74, 0x33,
2812  // 0x06: PUSH rax
2813  0x50,
2814  // 0x07: PUSH rcx
2815  0x51,
2816  // 0x08: MOV rcx, qword ptr gs:[0x188]
2817  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
2818  // 0x11: MOV rax, qword ptr [rcx+0xb8]
2819  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
2820  // 0x18: TEST eax, eax
2821  0x85, 0xC0,
2822  // 0x1A: JNZ 0x23
2823  0x75, 0x07,
2824  // 0x1C: MOV rax, qword ptr [rcx+0x220]
2825  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
2826  // 0x23: CMP byte ptr [rax+0x438], 0x2a
2827  0x80, 0xB8, 0x38, 0x04, 0x00, 0x00, 0x2A,
2828  // 0x2A: BT dword ptr [rax+0x438], 0x08
2829  0x0f, 0xba, 0xa0, 0x38, 0x04, 0x00, 0x00, 0x08,
2830  // 0x32: POP rcx
2831  0x59,
2832  // 0x33: POP rax
2833  0x58,
2834  // 0x34: JNZ 0x39
2835  0x75, 0x03,
2836  // 0x36: JNC 0x39
2837  0x73, 0x01,
2838  // 0x38: INT3
2839  0xCC,
2840  // 0x39: JMP 0x3e
2841  0xE9, 0x00, 0x00, 0x00, 0x00
2842  },
2843  .HypercallOffset = 0x38,
2844  .RelocatedCodeOffset = 0x39,
2845  },
2846  },
2847  },
2848 
2849  {
2850  .ModuleName = u"ntoskrnl.exe",
2851  .FunctionName = "MiGetWsAndInsertVad",
2852  .MinVersion = 17763,
2853  .MaxVersion = 18362,
2854  .Callback = IntWinVadHandleInsertMap,
2855  .PreCallback = IntWinVadPatchInsertMap,
2856  .Tag = detTagVadInsertMap,
2857  .Exported = FALSE,
2858  .NotCritical = FALSE,
2859  .DisableFlags = 0,
2861  .Arguments = DET_ARGS_DEFAULT_WIN64,
2862  .HandlersCount = 2,
2863  .Handlers = {
2864  // Windows 10 RS5 17763
2865  {
2866  .MinVersion = 17763,
2867  .MaxVersion = 17763,
2868  .HypercallType = hypercallTypeInt3,
2869 
2870  .CodeLength = 0x3e,
2871  .Code =
2872  {
2873  // 0x00: TEST byte ptr [rcx+0x30], 0x10
2874  0xF6, 0x41, 0x30, 0x10,
2875  // 0x04: JZ 0x39
2876  0x74, 0x33,
2877  // 0x06: PUSH rax
2878  0x50,
2879  // 0x07: PUSH rcx
2880  0x51,
2881  // 0x08: MOV rcx, qword ptr gs:[0x188]
2882  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
2883  // 0x11: MOV rax, qword ptr [rcx+0xb8]
2884  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
2885  // 0x18: TEST eax, eax
2886  0x85, 0xC0,
2887  // 0x1A: JNZ 0x23
2888  0x75, 0x07,
2889  // 0x1C: MOV rax, qword ptr [rcx+0x220]
2890  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
2891  // 0x23: CMP byte ptr [rax+0x450], 0x2a
2892  0x80, 0xB8, 0x50, 0x04, 0x00, 0x00, 0x2A,
2893  // 0x2A: BT dword ptr [rax+0x450], 0x08
2894  0x0f, 0xba, 0xa0, 0x50, 0x04, 0x00, 0x00, 0x08,
2895  // 0x32: POP rcx
2896  0x59,
2897  // 0x33: POP rax
2898  0x58,
2899  // 0x34: JNZ 0x39
2900  0x75, 0x03,
2901  // 0x36: JNC 0x39
2902  0x73, 0x01,
2903  // 0x38: INT3
2904  0xCC,
2905  // 0x39: JMP 0x3e
2906  0xE9, 0x00, 0x00, 0x00, 0x00
2907  },
2908  .HypercallOffset = 0x38,
2909  .RelocatedCodeOffset = 0x39,
2910  },
2911  {
2912  .MinVersion = 18362,
2913  .MaxVersion = 18362,
2914  .HypercallType = hypercallTypeInt3,
2915 
2916  .CodeLength = 0x3e,
2917  .Code =
2918  {
2919  // 0x00: TEST byte ptr [rcx+0x31], 0x01
2920  0xf6, 0x41, 0x31, 0x01,
2921  // 0x04: JZ 0x39
2922  0x74, 0x33,
2923  // 0x06: PUSH rax
2924  0x50,
2925  // 0x07: PUSH rcx
2926  0x51,
2927  // 0x08: MOV rcx, qword ptr gs:[0x188]
2928  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
2929  // 0x11: MOV rax, qword ptr [rcx+0xb8]
2930  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
2931  // 0x18: TEST eax, eax
2932  0x85, 0xC0,
2933  // 0x1A: JNZ 0x23
2934  0x75, 0x07,
2935  // 0x1C: MOV rax, qword ptr [rcx+0x220]
2936  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
2937  // 0x23: CMP byte ptr [rax+0x450], 0x2a
2938  0x80, 0xB8, 0x50, 0x04, 0x00, 0x00, 0x2A,
2939  // 0x2A: BT dword ptr [rax+0x450], 0x08
2940  0x0f, 0xba, 0xa0, 0x50, 0x04, 0x00, 0x00, 0x08,
2941  // 0x32: POP rcx
2942  0x59,
2943  // 0x33: POP rax
2944  0x58,
2945  // 0x34: JNZ 0x39
2946  0x75, 0x03,
2947  // 0x36: JNC 0x39
2948  0x73, 0x01,
2949  // 0x38: INT3
2950  0xCC,
2951  // 0x39: JMP 0x3e
2952  0xE9, 0x00, 0x00, 0x00, 0x00
2953  },
2954  .HypercallOffset = 0x38,
2955  .RelocatedCodeOffset = 0x39,
2956  },
2957  },
2958  },
2959 
2960  {
2961  .ModuleName = u"ntoskrnl.exe",
2962  .FunctionName = "MiCommitExistingVad",
2963  .MinVersion = DETOUR_MIN_VERSION_ANY,
2964  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2965  .PreCallback = IntWinPatchVadHandleCommit,
2966  .Callback = IntWinVadHandleCommit,
2967  .Tag = detTagVadCommit,
2968  .Exported = FALSE,
2969  .NotCritical = FALSE,
2970  .DisableFlags = 0,
2971  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
2972  .Arguments = DET_ARGS_DEFAULT_WIN64,
2973  .HandlersCount = 1,
2974  .Handlers =
2975  {
2976  {
2977  .MinVersion = DETOUR_MIN_VERSION_ANY,
2978  .MaxVersion = DETOUR_MAX_VERSION_ANY,
2979  .HypercallType = hypercallTypeInt3,
2980  .CodeLength = 0x3e,
2981  .Code =
2982  {
2983  // VmProtection & (PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE |
2984  // PAGE_EXECUTE_READ | PAGE_EXECUTE)
2985  // 0x00: TEST r9b, 0xf0
2986  0x41, 0xf6, 0xc1, 0xf0,
2987  // not executable, skip hook
2988  // 0x04: JZ 0x39
2989  0x74, 0x33,
2990  // 0x06: PUSH rcx
2991  0x51,
2992  // 0x07: PUSH rax
2993  0x50,
2994  // rcx = Kpcr.Prcb.CurrentThread
2995  // 0x08: MOV rcx, qword ptr gs:[0x0]
2996  0x65, 0x48, 0x8b, 0x0c, 0x25, 0x00, 0x00, 0x00, 0x00,
2997  // rax = Thread.ApcState.AttachedProcess
2998  // 0x11: MOV rax, qword ptr [rcx+0x0]
2999  0x48, 0x8b, 0x81, 0x00, 0x00, 0x00, 0x00,
3000  // 0x18: TEST eax, eax
3001  0x85, 0xc0,
3002  // 0x1A: JNZ 0x23
3003  0x75, 0x07,
3004  // rax = Thread.Process
3005  // 0x1C: MOV rax, qword ptr [rcx+0x0]
3006  0x48, 0x8b, 0x81, 0x00, 0x00, 0x00, 0x00,
3007  // cmp Process.ImageFileName[0], '*'
3008  // 0x23: CMP byte ptr [rax+0x0], 0x2a
3009  0x80, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x2a,
3010  // check if 0 != (Process.ImageFileName[1] & winProcExitVad)
3011  // 0x2A: BT dword ptr [rax+0x0], 0x08
3012  0x0f, 0xba, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x08,
3013  // 0x32: POP rax
3014  0x58,
3015  // 0x33: POP rcx
3016  0x59,
3017  // 0x34: JNZ 0x39
3018  0x75, 0x03,
3019  // 0x36: JNC 0x39
3020  0x73, 0x01,
3021  // 0x38: INT3
3022  0xcc,
3023  // 0x39: JMP 0x3e
3024  0xe9, 0x00, 0x00, 0x00, 0x00
3025  },
3026  .HypercallOffset = 0x38,
3027  .RelocatedCodeOffset = 0x39,
3028  }
3029  },
3030  },
3031 
3032  {
3033  .ModuleName = u"ntoskrnl.exe",
3034  .FunctionName = "MiProtectVirtualMemory",
3035  .MinVersion = DETOUR_MIN_VERSION_ANY,
3036  .MaxVersion = DETOUR_MAX_VERSION_ANY,
3037  .Callback = IntWinVadHandleVirtualProtect,
3038  .PreCallback = IntWinVadPatchVirtualProtect,
3039  .Tag = detTagVmProtect,
3040  .Exported = FALSE,
3041  .NotCritical = FALSE,
3042  .DisableFlags = 0,
3043  .EnableFlags = INTRO_OPT_ENABLE_UM_PROTECTION,
3044  .Arguments = DET_ARGS_DEFAULT_WIN64,
3045  .HandlersCount = 5,
3046  .Handlers =
3047  {
3048  {
3049  .MinVersion = 7600,
3050  .MaxVersion = 9200,
3051  .HypercallType = hypercallTypeInt3,
3052 
3053  .CodeLength = 0x1f,
3054  .Code =
3055  {
3056  // 0x00: TEST r9b, 0xf0
3057  0x41, 0xF6, 0xC1, 0xF0,
3058  // 0x04: JZ 0x1a
3059  0x74, 0x14,
3060  // 0x06: CMP byte ptr [rcx+0x2e0], 0x2a
3061  0x80, 0xB9, 0xe0, 0x02, 0x00, 0x00, 0x2A,
3062  // 0x0D: BT dword ptr [rcx+0x2e0], 0x08
3063  0x0f, 0xba, 0xa1, 0xe0, 0x02, 0x00, 0x00, 0x08,
3064  // 0x15: JNZ 0x1a
3065  0x75, 0x03,
3066  // 0x17: JNC 0x1a
3067  0x73, 0x01,
3068  // 0x19: INT3
3069  0xCC,
3070  // 0x1A: JMP 0x1f
3071  0xE9, 0x00, 0x00, 0x00, 0x00,
3072  },
3073  .HypercallOffset = 0x19,
3074  .RelocatedCodeOffset = 0x1a,
3075  },
3076 
3077  {
3078  .MinVersion = 9600,
3079  .MaxVersion = DETOUR_MAX_VERSION_ANY,
3080  .HypercallType = hypercallTypeInt3,
3081 
3082  .CodeLength = 0x20,
3083  .Code =
3084  {
3085  // 0x00: TEST byte ptr [rsp+0x28], 0xf0
3086  0xF6, 0x44, 0x24, 0x28, 0xF0,
3087  // 0x05: JZ 0x1b
3088  0x74, 0x14,
3089  // 0x07: CMP byte ptr [rdx+0x438], 0x2a
3090  0x80, 0xBA, 0x38, 0x04, 0x00, 0x00, 0x2A,
3091  // 0x0E: BT dword ptr [rdx+0x438], 0x08
3092  0x0f, 0xba, 0xa2, 0x38, 0x04, 0x00, 0x00, 0x08,
3093  // 0x16: JNZ 0x1b
3094  0x75, 0x03,
3095  // 0x18: JNC 0x1b
3096  0x73, 0x01,
3097  // 0x1A: INT3
3098  0xCC,
3099  // 0x1B: JMP 0x20
3100  0xE9, 0x00, 0x00, 0x00, 0x00,
3101  },
3102  .HypercallOffset = 0x1a,
3103  .RelocatedCodeOffset = 0x1b,
3104  },
3105  },
3106  },
3107 
3108  {
3109  .ModuleName = u"ntoskrnl.exe",
3110  .FunctionName = "MiDeleteVirtualAddresses",
3111  .MinVersion = DETOUR_MIN_VERSION_ANY,
3112  .MaxVersion = 16299,
3113  .Callback = IntWinVadHandleDeleteVaRange,
3114  .PreCallback = IntWinVadPatchDeleteVaRange,
3115  .Tag = detTagVaDelete,
3116  .Exported = FALSE,
3117  .NotCritical = FALSE,
3118  .DisableFlags = 0,
3120  .Arguments = DET_ARGS_DEFAULT_WIN64,
3121  .HandlersCount = 4,
3122  .Handlers =
3123  {
3124  {
3125  .MinVersion = 7600,
3126  .MaxVersion = 7602,
3127  .HypercallType = hypercallTypeInt3,
3128 
3129  .CodeLength = 0x38,
3130  .Code =
3131  {
3132  // 0x00: PUSH rax
3133  0x50,
3134  // 0x01: PUSH rcx
3135  0x51,
3136  // 0x02: MOV rcx, qword ptr gs:[0x188]
3137  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
3138  // 0x0B: MOV rax, qword ptr [rcx+0x70]
3139  0x48, 0x8B, 0x81, 0x70, 0x00, 0x00, 0x00,
3140  // 0x12: TEST eax, eax
3141  0x85, 0xC0,
3142  // 0x14: JNZ 0x1d
3143  0x75, 0x07,
3144  // 0x16: MOV rax, qword ptr [rcx+0x210]
3145  0x48, 0x8B, 0x81, 0x10, 0x02, 0x00, 0x00,
3146  // 0x1D: CMP byte ptr [rax+0x2e0], 0x2a
3147  0x80, 0xB8, 0xE0, 0x02, 0x00, 0x00, 0x2A,
3148  // 0x24: BT dword ptr [rax+0x2e0], 0x08
3149  0x0f, 0xba, 0xa0, 0xe0, 0x02, 0x00, 0x00, 0x08,
3150  // 0x2C: POP rcx
3151  0x59,
3152  // 0x2D: POP rax
3153  0x58,
3154  // 0x2E: JNZ 0x33
3155  0x75, 0x03,
3156  // 0x30: JNC 0x33
3157  0x73, 0x01,
3158  // 0x32: INT3
3159  0xCC,
3160  // 0x33: JMP 0x38
3161  0xE9, 0x00, 0x00, 0x00, 0x00
3162  },
3163  .HypercallOffset = 0x32,
3164  .RelocatedCodeOffset = 0x33,
3165  },
3166 
3167  {
3168  .MinVersion = 9200,
3169  .MaxVersion = 9600,
3170  .HypercallType = hypercallTypeInt3,
3171 
3172  .CodeLength = 0x38,
3173  .Code =
3174  {
3175  // 0x00: PUSH rax
3176  0x50,
3177  // 0x01: PUSH rcx
3178  0x51,
3179  // 0x02: MOV rcx, qword ptr gs:[0x188]
3180  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
3181  // 0x0B: MOV rax, qword ptr [rcx+0xb8]
3182  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
3183  // 0x12: TEST eax, eax
3184  0x85, 0xC0,
3185  // 0x14: JNZ 0x1d
3186  0x75, 0x07,
3187  // 0x16: MOV rax, qword ptr [rcx+0x220]
3188  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
3189  // 0x1D: CMP byte ptr [rax+0x438], 0x2a
3190  0x80, 0xB8, 0x38, 0x04, 0x00, 0x00, 0x2A,
3191  // 0x24: BT dword ptr [rax+0x438], 0x08
3192  0x0f, 0xba, 0xa0, 0x38, 0x04, 0x00, 0x00, 0x08,
3193  // 0x2C: POP rcx
3194  0x59,
3195  // 0x2D: POP rax
3196  0x58,
3197  // 0x2E: JNZ 0x33
3198  0x75, 0x03,
3199  // 0x30: JNC 0x33
3200  0x73, 0x01,
3201  // 0x32: INT3
3202  0xCC,
3203  // 0x33: JMP 0x38
3204  0xE9, 0x00, 0x00, 0x00, 0x00
3205  },
3206  .HypercallOffset = 0x32,
3207  .RelocatedCodeOffset = 0x33,
3208  },
3209 
3210  {
3211  .MinVersion = 10240,
3212  .MaxVersion = 10240,
3213  .HypercallType = hypercallTypeInt3,
3214 
3215  .CodeLength = 0x38,
3216  .Code =
3217  {
3218  // 0x00: PUSH rax
3219  0x50,
3220  // 0x01: PUSH rcx
3221  0x51,
3222  // 0x02: MOV rcx, qword ptr gs:[0x188]
3223  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
3224  // 0x0B: MOV rax, qword ptr [rcx+0xb8]
3225  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
3226  // 0x12: TEST eax, eax
3227  0x85, 0xC0,
3228  // 0x14: JNZ 0x1d
3229  0x75, 0x07,
3230  // 0x16: MOV rax, qword ptr [rcx+0x220]
3231  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
3232  // 0x1D: CMP byte ptr [rax+0x448], 0x2a
3233  0x80, 0xB8, 0x48, 0x04, 0x00, 0x00, 0x2A,
3234  // 0x24: BT dword ptr [rax+0x448], 0x08
3235  0x0f, 0xba, 0xa0, 0x48, 0x04, 0x00, 0x00, 0x08,
3236  // 0x2C: POP rcx
3237  0x59,
3238  // 0x2D: POP rax
3239  0x58,
3240  // 0x2E: JNZ 0x33
3241  0x75, 0x03,
3242  // 0x30: JNC 0x33
3243  0x73, 0x01,
3244  // 0x32: INT3
3245  0xCC,
3246  // 0x33: JMP 0x38
3247  0xE9, 0x00, 0x00, 0x00, 0x00
3248  },
3249  .HypercallOffset = 0x32,
3250  .RelocatedCodeOffset = 0x33,
3251  },
3252 
3253  {
3254  .MinVersion = 10586,
3255  .MaxVersion = 16299,
3256  .HypercallType = hypercallTypeInt3,
3257 
3258  .CodeLength = 0x38,
3259  .Code =
3260  {
3261  // 0x00: PUSH rax
3262  0x50,
3263  // 0x01: PUSH rcx
3264  0x51,
3265  // 0x02: MOV rcx, qword ptr gs:[0x188]
3266  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
3267  // 0x0B: MOV rax, qword ptr [rcx+0xb8]
3268  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
3269  // 0x12: TEST eax, eax
3270  0x85, 0xC0,
3271  // 0x14: JNZ 0x1d
3272  0x75, 0x07,
3273  // 0x16: MOV rax, qword ptr [rcx+0x220]
3274  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
3275  // 0x1D: CMP byte ptr [rax+0x450], 0x2a
3276  0x80, 0xB8, 0x50, 0x04, 0x00, 0x00, 0x2A,
3277  // 0x24: BT dword ptr [rax+0x450], 0x08
3278  0x0f, 0xba, 0xa0, 0x50, 0x04, 0x00, 0x00, 0x08,
3279  // 0x2C: POP rcx
3280  0x59,
3281  // 0x2D: POP rax
3282  0x58,
3283  // 0x2E: JNZ 0x33
3284  0x75, 0x03,
3285  // 0x30: JNC 0x33
3286  0x73, 0x01,
3287  // 0x32: INT3
3288  0xCC,
3289  // 0x33: JMP 0x38
3290  0xE9, 0x00, 0x00, 0x00, 0x00
3291  },
3292  .HypercallOffset = 0x32,
3293  .RelocatedCodeOffset = 0x33,
3294  },
3295  },
3296  },
3297 
3298  {
3299  .ModuleName = u"ntoskrnl.exe",
3300  .FunctionName = "MiFinishVadDeletion",
3301  .MinVersion = 17134,
3302  .MaxVersion = DETOUR_MAX_VERSION_ANY,
3304  .PreCallback = IntWinVadPatchFinishVadDeletion,
3305  .Tag = detTagFinishVadDeletion,
3306  .Exported = FALSE,
3307  .NotCritical = FALSE,
3308  .DisableFlags = 0,
3310  .Arguments = DET_ARGS_DEFAULT_WIN64,
3311  .HandlersCount = 2,
3312  .Handlers =
3313  {
3314  {
3315  .MinVersion = 17134,
3316  .MaxVersion = 17763,
3317  .HypercallType = hypercallTypeInt3,
3318 
3319  .CodeLength = 0x3e,
3320  .Code =
3321  {
3322  // 0x00: TEST byte ptr [rcx+0x30], 0x10
3323  0xF6, 0x41, 0x30, 0x10,
3324  // 0x04: JZ 0x39
3325  0x74, 0x33,
3326  // 0x06: PUSH rax
3327  0x50,
3328  // 0x07: PUSH rcx
3329  0x51,
3330  // 0x08: MOV rcx, qword ptr gs:[0x188]
3331  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
3332  // 0x11: MOV rax, qword ptr [rcx+0xb8]
3333  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
3334  // 0x18: TEST eax, eax
3335  0x85, 0xC0,
3336  // 0x1A: JNZ 0x23
3337  0x75, 0x07,
3338  // 0x1C: MOV rax, qword ptr [rcx+0x220]
3339  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
3340  // 0x23: CMP byte ptr [rax+0x450], 0x2a
3341  0x80, 0xB8, 0x50, 0x04, 0x00, 0x00, 0x2A,
3342  // 0x2A: BT dword ptr [rax+0x450], 0x08
3343  0x0f, 0xba, 0xa0, 0x50, 0x04, 0x00, 0x00, 0x08,
3344  // 0x32: POP rcx
3345  0x59,
3346  // 0x33: POP rax
3347  0x58,
3348  // 0x34: JNZ 0x39
3349  0x75, 0x03,
3350  // 0x36: JNC 0x39
3351  0x73, 0x01,
3352  // 0x38: INT3
3353  0xCC,
3354  // 0x39: JMP 0x3e
3355  0xE9, 0x00, 0x00, 0x00, 0x00
3356  },
3357  .HypercallOffset = 0x38,
3358  .RelocatedCodeOffset = 0x39,
3359  },
3360  // 19H1
3361  {
3362  .MinVersion = 18362,
3363  .MaxVersion = DETOUR_MAX_VERSION_ANY,
3364  .HypercallType = hypercallTypeInt3,
3365 
3366  .CodeLength = 0x3e,
3367  .Code =
3368  {
3369  // 0x00: TEST byte ptr [rcx+0x31], 0x01
3370  0xf6, 0x41, 0x31, 0x01,
3371  // 0x04: JZ 0x39
3372  0x74, 0x33,
3373  // 0x06: PUSH rax
3374  0x50,
3375  // 0x07: PUSH rcx
3376  0x51,
3377  // 0x08: MOV rcx, qword ptr gs:[0x188]
3378  0x65, 0x48, 0x8B, 0x0C, 0x25, 0x88, 0x01, 0x00, 0x00,
3379  // 0x11: MOV rax, qword ptr [rcx+0xb8]
3380  0x48, 0x8B, 0x81, 0xB8, 0x00, 0x00, 0x00,
3381  // 0x18: TEST eax, eax
3382  0x85, 0xC0,
3383  // 0x1A: JNZ 0x23
3384  0x75, 0x07,
3385  // 0x1C: MOV rax, qword ptr [rcx+0x220]
3386  0x48, 0x8B, 0x81, 0x20, 0x02, 0x00, 0x00,
3387  // 0x23: CMP byte ptr [rax+0x450], 0x2a
3388  0x80, 0xB8, 0x50, 0x04, 0x00, 0x00, 0x2A,
3389  // 0x2A: BT dword ptr [rax+0x450], 0x08
3390  0x0f, 0xba, 0xa0, 0x50, 0x04, 0x00, 0x00, 0x08,
3391  // 0x32: POP rcx
3392  0x59,
3393  // 0x33: POP rax
3394  0x58,
3395  // 0x34: JNZ 0x39
3396  0x75, 0x03,
3397  // 0x36: JNC 0x39
3398  0x73, 0x01,
3399  // 0x38: INT3
3400  0xCC,
3401  // 0x39: JMP 0x3e
3402  0xE9, 0x00, 0x00, 0x00, 0x00
3403  },
3404  .HypercallOffset = 0x38,
3405  .RelocatedCodeOffset = 0x39,
3406  },
3407  },
3408  },
3409 
3410  {
3411  .ModuleName = u"ntoskrnl.exe",
3412  .FunctionName = "NtSetSystemPowerState",
3413  .MinVersion = DETOUR_MIN_VERSION_ANY,
3414  .MaxVersion = DETOUR_MAX_VERSION_ANY,
3415  .Callback = IntWinPowHandlePowerStateChange,
3416  .Tag = detTagPowerState,
3417  .Exported = FALSE,
3418  .NotCritical = TRUE,
3419  .DisableFlags = 0,
3420  .EnableFlags = DETOUR_ENABLE_ALWAYS,
3421  .Arguments = DET_ARGS_DEFAULT_WIN64,
3422  .HandlersCount = 1,
3423  .Handlers =
3424  {
3425  {
3426  .MinVersion = DETOUR_MIN_VERSION_ANY,
3427  .MaxVersion = DETOUR_MAX_VERSION_ANY,
3428  .HypercallType = hypercallTypeInt3,
3429 
3430  .CodeLength = 0xF,
3431  .Code =
3432  {
3433  // 0x00: INT3
3434  0xcc,
3435  // 0x01: NOP
3436  0x66, 0x66, 0x66, 0x66, 0x90,
3437  // 0x06: NOP
3438  0x66, 0x90,
3439  // 0x08: NOP
3440  0x66, 0x90,
3441  // 0x0A: JMP 0xf
3442  0xe9, 0x00, 0x00, 0x00, 0x00
3443  },
3444  .HypercallOffset = 0x0,
3445  .RelocatedCodeOffset = 0xA,
3446  .PublicDataOffsets = {
3447  {
3448  .PublicDataName = "5bytenop",
3449  .PublicDataOffset = 0x1,
3450  .PublicDataSize = 0x5
3451  },
3452  {
3453  .PublicDataName = "spinwait",
3454  .PublicDataOffset = 0x6,
3455  .PublicDataSize = 0x4
3456  },
3457  },
3458  .NrPublicDataOffsets = 2,
3459  },
3460  },
3461  },
3462 
3467 
3468  //
3469  // Monstrous hack on order to avoid reads made by RtlpVirtualUnwind...
3470  //
3471  {
3472  .ModuleName = u"ntoskrnl.exe",
3473  .FunctionName = "RtlpVirtualUnwind1",
3474  .MinVersion = 7600,
3475  .MaxVersion = 7602,
3476  .Callback = NULL,
3477  .Tag = detTagRtlVirtualUnwind1,
3478  .Exported = FALSE,
3479  .NotCritical = TRUE,
3480  .DisableFlags = 0,
3481  .EnableFlags = DETOUR_ENABLE_ALWAYS,
3482  .Arguments = DET_ARGS_DEFAULT_WIN64,
3483  .HandlersCount = 1,
3484  .Handlers =
3485  {
3486  {
3487  .MinVersion = 7600,
3488  .MaxVersion = 7602,
3489  .HypercallType = hypercallTypeInt3,
3490 
3491  .CodeLength = 0x81,
3492  .Code =
3493  {
3494  // 0x00: CLI
3495  0xFA,
3496  // 0x01: MOV al, 0x00
3497  0xB0, 0x00,
3498  // 0x03: CMP ecx, 0x00000000
3499  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3500  // 0x09: JZ 0x79
3501  0x74, 0x6E,
3502  // 0x0B: MOV al, 0x00
3503  0xB0, 0x00,
3504  // 0x0D: CMP ecx, 0x00000000
3505  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3506  // 0x13: JZ 0x79
3507  0x74, 0x64,
3508  // 0x15: MOV al, 0x00
3509  0xB0, 0x00,
3510  // 0x17: CMP ecx, 0x00000000
3511  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3512  // 0x1D: JZ 0x79
3513  0x74, 0x5A,
3514  // 0x1F: MOV al, 0x00
3515  0xB0, 0x00,
3516  // 0x21: CMP ecx, 0x00000000
3517  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3518  // 0x27: JZ 0x79
3519  0x74, 0x50,
3520  // 0x29: MOV al, 0x00
3521  0xB0, 0x00,
3522  // 0x2B: CMP ecx, 0x00000000
3523  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3524  // 0x31: JZ 0x79
3525  0x74, 0x46,
3526  // 0x33: MOV al, 0x00
3527  0xB0, 0x00,
3528  // 0x35: CMP ecx, 0x00000000
3529  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3530  // 0x3B: JZ 0x79
3531  0x74, 0x3C,
3532  // 0x3D: MOV al, 0x00
3533  0xB0, 0x00,
3534  // 0x3F: CMP ecx, 0x00000000
3535  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3536  // 0x45: JZ 0x79
3537  0x74, 0x32,
3538  // 0x47: MOV al, 0x00
3539  0xB0, 0x00,
3540  // 0x49: CMP ecx, 0x00000000
3541  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3542  // 0x4F: JZ 0x79
3543  0x74, 0x28,
3544  // 0x51: MOV al, 0x00
3545  0xB0, 0x00,
3546  // 0x53: CMP ecx, 0x00000000
3547  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3548  // 0x59: JZ 0x79
3549  0x74, 0x1E,
3550  // 0x5B: MOV al, 0x00
3551  0xB0, 0x00,
3552  // 0x5D: CMP ecx, 0x00000000
3553  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3554  // 0x63: JZ 0x79
3555  0x74, 0x14,
3556  // 0x65: MOV al, 0x00
3557  0xB0, 0x00,
3558  // 0x67: CMP ecx, 0x00000000
3559  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3560  // 0x6D: JZ 0x79
3561  0x74, 0x0A,
3562  // 0x6F: MOV al, 0x00
3563  0xB0, 0x00,
3564  // 0x71: CMP ecx, 0x00000000
3565  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3566  // 0x77: JZ 0x79
3567  0x74, 0x00,
3568  // 0x79: STI
3569  0xFB,
3570  // 0x7A: JZ 0x7e
3571  0x74, 0x02,
3572  // mov al, [rcx] comes here, it is two bytes
3573  // the rest of the instructions come here.
3574  // 0x7C: JMP 0x81
3575  0xE9, 0x00, 0x00, 0x00, 0x00
3576  },
3577  .HypercallOffset = 0xFF,
3578  .RelocatedCodeOffset = 0x7C,
3579  },
3580  },
3581  },
3582 
3583  {
3584  .ModuleName = u"ntoskrnl.exe",
3585  .FunctionName = "RtlpVirtualUnwind2",
3586  .MinVersion = 7600,
3587  .MaxVersion = 7602,
3588  .Callback = NULL,
3589  .Tag = detTagRtlVirtualUnwind2,
3590  .Exported = FALSE,
3591  .NotCritical = TRUE,
3592  .DisableFlags = 0,
3593  .EnableFlags = DETOUR_ENABLE_ALWAYS,
3594  .Arguments = DET_ARGS_DEFAULT_WIN64,
3595  .HandlersCount = 1,
3596  .Handlers =
3597  {
3598  {
3599  .MinVersion = 7600,
3600  .MaxVersion = 7602,
3601  .HypercallType = hypercallTypeInt3,
3602 
3603  .CodeLength = 0x81,
3604  .Code =
3605  {
3606  // 0x00: CLI
3607  0xFA,
3608  // 0x01: MOV al, 0x00
3609  0xB0, 0x00,
3610  // 0x03: CMP ecx, 0x00000000
3611  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3612  // 0x09: JZ 0x79
3613  0x74, 0x6E,
3614  // 0x0B: MOV al, 0x00
3615  0xB0, 0x00,
3616  // 0x0D: CMP ecx, 0x00000000
3617  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3618  // 0x13: JZ 0x79
3619  0x74, 0x64,
3620  // 0x15: MOV al, 0x00
3621  0xB0, 0x00,
3622  // 0x17: CMP ecx, 0x00000000
3623  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3624  // 0x1D: JZ 0x79
3625  0x74, 0x5A,
3626  // 0x1F: MOV al, 0x00
3627  0xB0, 0x00,
3628  // 0x21: CMP ecx, 0x00000000
3629  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3630  // 0x27: JZ 0x79
3631  0x74, 0x50,
3632  // 0x29: MOV al, 0x00
3633  0xB0, 0x00,
3634  // 0x2B: CMP ecx, 0x00000000
3635  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3636  // 0x31: JZ 0x79
3637  0x74, 0x46,
3638  // 0x33: MOV al, 0x00
3639  0xB0, 0x00,
3640  // 0x35: CMP ecx, 0x00000000
3641  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3642  // 0x3B: JZ 0x79
3643  0x74, 0x3C,
3644  // 0x3D: MOV al, 0x00
3645  0xB0, 0x00,
3646  // 0x3F: CMP ecx, 0x00000000
3647  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3648  // 0x45: JZ 0x79
3649  0x74, 0x32,
3650  // 0x47: MOV al, 0x00
3651  0xB0, 0x00,
3652  // 0x49: CMP ecx, 0x00000000
3653  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3654  // 0x4F: JZ 0x79
3655  0x74, 0x28,
3656  // 0x51: MOV al, 0x00
3657  0xB0, 0x00,
3658  // 0x53: CMP ecx, 0x00000000
3659  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3660  // 0x59: JZ 0x79
3661  0x74, 0x1E,
3662  // 0x5B: MOV al, 0x00
3663  0xB0, 0x00,
3664  // 0x5D: CMP ecx, 0x00000000
3665  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3666  // 0x63: JZ 0x79
3667  0x74, 0x14,
3668  // 0x65: MOV al, 0x00
3669  0xB0, 0x00,
3670  // 0x67: CMP ecx, 0x00000000
3671  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3672  // 0x6D: JZ 0x79
3673  0x74, 0x0A,
3674  // 0x6F: MOV al, 0x00
3675  0xB0, 0x00,
3676  // 0x71: CMP ecx, 0x00000000
3677  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3678  // 0x77: JZ 0x79
3679  0x74, 0x00,
3680  // 0x79: STI
3681  0xFB,
3682  // 0x7A: JZ 0x7f
3683  0x74, 0x03,
3684  // mov al, [rcx+1] comes here, 3 bytes
3685  // 0x7C: JMP 0x81
3686  0xE9, 0x00, 0x00, 0x00, 0x00
3687  },
3688  .HypercallOffset = 0xFF,
3689  .RelocatedCodeOffset = 0x7C,
3690  },
3691  },
3692  },
3693 
3694  {
3695  .ModuleName = u"ntoskrnl.exe",
3696  .FunctionName = "RtlpVirtualUnwind3",
3697  .MinVersion = 7600,
3698  .MaxVersion = 7602,
3699  .Callback = NULL,
3700  .Tag = detTagRtlVirtualUnwind3,
3701  .Exported = FALSE,
3702  .NotCritical = TRUE,
3703  .DisableFlags = 0,
3704  .EnableFlags = DETOUR_ENABLE_ALWAYS,
3705  .Arguments = DET_ARGS_DEFAULT_WIN64,
3706  .HandlersCount = 1,
3707  .Handlers =
3708  {
3709  {
3710  .MinVersion = 7600,
3711  .MaxVersion = 7602,
3712 
3713  .HypercallType = hypercallTypeInt3,
3714  .CodeLength = 0x81,
3715  .Code =
3716  {
3717  // 0x00: CLI
3718  0xFA,
3719  // 0x01: MOV dl, 0x00
3720  0xB2, 0x00,
3721  // 0x03: CMP ecx, 0x00000000
3722  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3723  // 0x09: JZ 0x79
3724  0x74, 0x6E,
3725  // 0x0B: MOV dl, 0x00
3726  0xB2, 0x00,
3727  // 0x0D: CMP ecx, 0x00000000
3728  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3729  // 0x13: JZ 0x79
3730  0x74, 0x64,
3731  // 0x15: MOV dl, 0x00
3732  0xB2, 0x00,
3733  // 0x17: CMP ecx, 0x00000000
3734  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3735  // 0x1D: JZ 0x79
3736  0x74, 0x5A,
3737  // 0x1F: MOV dl, 0x00
3738  0xB2, 0x00,
3739  // 0x21: CMP ecx, 0x00000000
3740  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3741  // 0x27: JZ 0x79
3742  0x74, 0x50,
3743  // 0x29: MOV dl, 0x00
3744  0xB2, 0x00,
3745  // 0x2B: CMP ecx, 0x00000000
3746  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3747  // 0x31: JZ 0x79
3748  0x74, 0x46,
3749  // 0x33: MOV dl, 0x00
3750  0xB2, 0x00,
3751  // 0x35: CMP ecx, 0x00000000
3752  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3753  // 0x3B: JZ 0x79
3754  0x74, 0x3C,
3755  // 0x3D: MOV dl, 0x00
3756  0xB2, 0x00,
3757  // 0x3F: CMP ecx, 0x00000000
3758  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3759  // 0x45: JZ 0x79
3760  0x74, 0x32,
3761  // 0x47: MOV dl, 0x00
3762  0xB2, 0x00,
3763  // 0x49: CMP ecx, 0x00000000
3764  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3765  // 0x4F: JZ 0x79
3766  0x74, 0x28,
3767  // 0x51: MOV dl, 0x00
3768  0xB2, 0x00,
3769  // 0x53: CMP ecx, 0x00000000
3770  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3771  // 0x59: JZ 0x79
3772  0x74, 0x1E,
3773  // 0x5B: MOV dl, 0x00
3774  0xB2, 0x00,
3775  // 0x5D: CMP ecx, 0x00000000
3776  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3777  // 0x63: JZ 0x79
3778  0x74, 0x14,
3779  // 0x65: MOV dl, 0x00
3780  0xB2, 0x00,
3781  // 0x67: CMP ecx, 0x00000000
3782  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3783  // 0x6D: JZ 0x79
3784  0x74, 0x0A,
3785  // 0x6F: MOV dl, 0x00
3786  0xB2, 0x00,
3787  // 0x71: CMP ecx, 0x00000000
3788  0x81, 0xF9, 0x00, 0x00, 0x00, 0x00,
3789  // 0x77: JZ 0x79
3790  0x74, 0x00,
3791  // 0x79: STI
3792  0xFB,
3793  // 0x7A: JZ 0x7e
3794  0x74, 0x02,
3795  // mov dl, [rcx] 2 bytes
3796  // 0x7C: JMP 0x81
3797  0xE9, 0x00, 0x00, 0x00, 0x00
3798  },
3799  .HypercallOffset = 0xFF,
3800  .RelocatedCodeOffset = 0x7C,
3801  },
3802  },
3803  },
3804 
3805  {
3806  .ModuleName = u"ntoskrnl.exe",
3807  .FunctionName = "RtlpVirtualUnwind4",
3808  .MinVersion = 7600,
3809  .MaxVersion = 7602,
3810  .Callback = NULL,
3811  .Tag = detTagRtlVirtualUnwind4,
3812  .Exported = FALSE,
3813  .NotCritical = TRUE,
3814  .DisableFlags = 0,
3815  .EnableFlags = DETOUR_ENABLE_ALWAYS,
3816  .Arguments = DET_ARGS_DEFAULT_WIN64,
3817  .HandlersCount = 1,
3818  .Handlers =
3819  {
3820  {
3821  .MinVersion = 7600,
3822  .MaxVersion = 7602,
3823  .HypercallType = hypercallTypeInt3,
3824 
3825  .CodeLength = 0x81,
3826  .Code =
3827  {
3828  // 0x00: CLI
3829  0xFA,
3830  // 0x01: MOV al, 0x00
3831  0xB0, 0x00,
3832  // 0x03: CMP ebp, 0x00000000
3833  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3834  // 0x09: JZ 0x79
3835  0x74, 0x6E,
3836  // 0x0B: MOV al, 0x00
3837  0xB0, 0x00,
3838  // 0x0D: CMP ebp, 0x00000000
3839  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3840  // 0x13: JZ 0x79
3841  0x74, 0x64,
3842  // 0x15: MOV al, 0x00
3843  0xB0, 0x00,
3844  // 0x17: CMP ebp, 0x00000000
3845  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3846  // 0x1D: JZ 0x79
3847  0x74, 0x5A,
3848  // 0x1F: MOV al, 0x00
3849  0xB0, 0x00,
3850  // 0x21: CMP ebp, 0x00000000
3851  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3852  // 0x27: JZ 0x79
3853  0x74, 0x50,
3854  // 0x29: MOV al, 0x00
3855  0xB0, 0x00,
3856  // 0x2B: CMP ebp, 0x00000000
3857  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3858  // 0x31: JZ 0x79
3859  0x74, 0x46,
3860  // 0x33: MOV al, 0x00
3861  0xB0, 0x00,
3862  // 0x35: CMP ebp, 0x00000000
3863  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3864  // 0x3B: JZ 0x79
3865  0x74, 0x3C,
3866  // 0x3D: MOV al, 0x00
3867  0xB0, 0x00,
3868  // 0x3F: CMP ebp, 0x00000000
3869  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3870  // 0x45: JZ 0x79
3871  0x74, 0x32,
3872  // 0x47: MOV al, 0x00
3873  0xB0, 0x00,
3874  // 0x49: CMP ebp, 0x00000000
3875  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3876  // 0x4F: JZ 0x79
3877  0x74, 0x28,
3878  // 0x51: MOV al, 0x00
3879  0xB0, 0x00,
3880  // 0x53: CMP ebp, 0x00000000
3881  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3882  // 0x59: JZ 0x79
3883  0x74, 0x1E,
3884  // 0x5B: MOV al, 0x00
3885  0xB0, 0x00,
3886  // 0x5D: CMP ebp, 0x00000000
3887  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3888  // 0x63: JZ 0x79
3889  0x74, 0x14,
3890  // 0x65: MOV al, 0x00
3891  0xB0, 0x00,
3892  // 0x67: CMP ebp, 0x00000000
3893  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3894  // 0x6D: JZ 0x79
3895  0x74, 0x0A,
3896  // 0x6F: MOV al, 0x00
3897  0xB0, 0x00,
3898  // 0x71: CMP ebp, 0x00000000
3899  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
3900  // 0x77: JZ 0x79
3901  0x74, 0x00,
3902  // 0x79: STI
3903  0xFB,
3904  // 0x7A: JZ 0x7f
3905  0x74, 0x03,
3906  // mov al, [rbp+1]
3907  // 0x7C: JMP 0x81
3908  0xE9, 0x00, 0x00, 0x00, 0x00
3909  },
3910  .HypercallOffset = 0xFF,
3911  .RelocatedCodeOffset = 0x7C,
3912  },
3913  },
3914  },
3915 
3916  {
3917  .ModuleName = u"ntoskrnl.exe",
3918  .FunctionName = "RtlpVirtualUnwind5",
3919  .MinVersion = 7600,
3920  .MaxVersion = 7602,
3921  .Callback = NULL,
3922  .Tag = detTagRtlVirtualUnwind5,
3923  .Exported = FALSE,
3924  .NotCritical = TRUE,
3925  .DisableFlags = 0,
3926  .EnableFlags = DETOUR_ENABLE_ALWAYS,
3927  .Arguments = DET_ARGS_DEFAULT_WIN64,
3928  .HandlersCount = 1,
3929  .Handlers =
3930  {
3931  {
3932  .MinVersion = 7600,
3933  .MaxVersion = 7602,
3934 
3935  .HypercallType = hypercallTypeInt3,
3936  .CodeLength = 0x89,
3937  .Code =
3938  {
3939  // 0x00: PUSH rax
3940  0x50,
3941  // 0x01: CLI
3942  0xFA,
3943  // 0x02: CMP ebp, 0xbdbdbdbd
3944  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
3945  // 0x08: JNZ 0x12
3946  0x75, 0x08,
3947  // 0x0A: MOV al, 0xbd
3948  0xB0, 0xBD,
3949  // 0x0C: CMP al, 0x48
3950  0x3C, 0x48,
3951  // 0x0E: STI
3952  0xFB,
3953  // 0x0F: POP rax
3954  0x58,
3955  // 0x10: JMP 0x88
3956  0xEB, 0x76,
3957  // 0x12: CMP ebp, 0xbdbdbdbd
3958  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
3959  // 0x18: JNZ 0x22
3960  0x75, 0x08,
3961  // 0x1A: MOV al, 0xbd
3962  0xB0, 0xBD,
3963  // 0x1C: CMP al, 0x48
3964  0x3C, 0x48,
3965  // 0x1E: STI
3966  0xFB,
3967  // 0x1F: POP rax
3968  0x58,
3969  // 0x20: JMP 0x88
3970  0xEB, 0x66,
3971  // 0x22: CMP ebp, 0xbdbdbdbd
3972  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
3973  // 0x28: JNZ 0x32
3974  0x75, 0x08,
3975  // 0x2A: MOV al, 0xbd
3976  0xB0, 0xBD,
3977  // 0x2C: CMP al, 0x48
3978  0x3C, 0x48,
3979  // 0x2E: STI
3980  0xFB,
3981  // 0x2F: POP rax
3982  0x58,
3983  // 0x30: JMP 0x88
3984  0xEB, 0x56,
3985  // 0x32: CMP ebp, 0xbdbdbdbd
3986  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
3987  // 0x38: JNZ 0x42
3988  0x75, 0x08,
3989  // 0x3A: MOV al, 0xbd
3990  0xB0, 0xBD,
3991  // 0x3C: CMP al, 0x48
3992  0x3C, 0x48,
3993  // 0x3E: STI
3994  0xFB,
3995  // 0x3F: POP rax
3996  0x58,
3997  // 0x40: JMP 0x88
3998  0xEB, 0x46,
3999  // 0x42: CMP ebp, 0xbdbdbdbd
4000  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4001  // 0x48: JNZ 0x52
4002  0x75, 0x08,
4003  // 0x4A: MOV al, 0xbd
4004  0xB0, 0xBD,
4005  // 0x4C: CMP al, 0x48
4006  0x3C, 0x48,
4007  // 0x4E: STI
4008  0xFB,
4009  // 0x4F: POP rax
4010  0x58,
4011  // 0x50: JMP 0x88
4012  0xEB, 0x36,
4013  // 0x52: CMP ebp, 0xbdbdbdbd
4014  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4015  // 0x58: JNZ 0x62
4016  0x75, 0x08,
4017  // 0x5A: MOV al, 0xbd
4018  0xB0, 0xBD,
4019  // 0x5C: CMP al, 0x48
4020  0x3C, 0x48,
4021  // 0x5E: STI
4022  0xFB,
4023  // 0x5F: POP rax
4024  0x58,
4025  // 0x60: JMP 0x88
4026  0xEB, 0x26,
4027  // 0x62: CMP ebp, 0xbdbdbdbd
4028  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4029  // 0x68: JNZ 0x72
4030  0x75, 0x08,
4031  // 0x6A: MOV al, 0xbd
4032  0xB0, 0xBD,
4033  // 0x6C: CMP al, 0x48
4034  0x3C, 0x48,
4035  // 0x6E: STI
4036  0xFB,
4037  // 0x6F: POP rax
4038  0x58,
4039  // 0x70: JMP 0x88
4040  0xEB, 0x16,
4041  // 0x72: CMP ebp, 0xbdbdbdbd
4042  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4043  // 0x78: JNZ 0x82
4044  0x75, 0x08,
4045  // 0x7A: MOV al, 0xbd
4046  0xB0, 0xBD,
4047  // 0x7C: CMP al, 0x48
4048  0x3C, 0x48,
4049  // 0x7E: STI
4050  0xFB,
4051  // 0x7F: POP rax
4052  0x58,
4053  // 0x80: JMP 0x88
4054  0xEB, 0x06,
4055  // 0x82: STI
4056  0xFB,
4057  // 0x83: POP rax
4058  0x58,
4059  // 4 bytes of CMP [rbp], imm comes here
4060  // 0x84: JMP 0x89
4061  0xE9, 0x00, 0x00, 0x00, 0x00
4062  },
4063  .HypercallOffset = 0xFF,
4064  .RelocatedCodeOffset = 0x84,
4065  },
4066  },
4067  },
4068 
4069  {
4070  .ModuleName = u"ntoskrnl.exe",
4071  .FunctionName = "RtlpVirtualUnwind6",
4072  .MinVersion = 7600,
4073  .MaxVersion = 7602,
4074  .Callback = NULL,
4075  .Tag = detTagRtlVirtualUnwind6,
4076  .Exported = FALSE,
4077  .NotCritical = TRUE,
4078  .DisableFlags = 0,
4079  .EnableFlags = DETOUR_ENABLE_ALWAYS,
4080  .Arguments = DET_ARGS_DEFAULT_WIN64,
4081  .HandlersCount = 1,
4082  .Handlers =
4083  {
4084  {
4085  .MinVersion = 7600,
4086  .MaxVersion = 7602,
4087  .HypercallType = hypercallTypeInt3,
4088 
4089  .CodeLength = 0x81,
4090  .Code =
4091  {
4092  // 0x00: CLI
4093  0xFA,
4094  // 0x01: MOV al, 0x00
4095  0xB0, 0x00,
4096  // 0x03: CMP ebp, 0x00000000
4097  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4098  // 0x09: JZ 0x79
4099  0x74, 0x6E,
4100  // 0x0B: MOV al, 0x00
4101  0xB0, 0x00,
4102  // 0x0D: CMP ebp, 0x00000000
4103  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4104  // 0x13: JZ 0x79
4105  0x74, 0x64,
4106  // 0x15: MOV al, 0x00
4107  0xB0, 0x00,
4108  // 0x17: CMP ebp, 0x00000000
4109  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4110  // 0x1D: JZ 0x79
4111  0x74, 0x5A,
4112  // 0x1F: MOV al, 0x00
4113  0xB0, 0x00,
4114  // 0x21: CMP ebp, 0x00000000
4115  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4116  // 0x27: JZ 0x79
4117  0x74, 0x50,
4118  // 0x29: MOV al, 0x00
4119  0xB0, 0x00,
4120  // 0x2B: CMP ebp, 0x00000000
4121  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4122  // 0x31: JZ 0x79
4123  0x74, 0x46,
4124  // 0x33: MOV al, 0x00
4125  0xB0, 0x00,
4126  // 0x35: CMP ebp, 0x00000000
4127  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4128  // 0x3B: JZ 0x79
4129  0x74, 0x3C,
4130  // 0x3D: MOV al, 0x00
4131  0xB0, 0x00,
4132  // 0x3F: CMP ebp, 0x00000000
4133  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4134  // 0x45: JZ 0x79
4135  0x74, 0x32,
4136  // 0x47: MOV al, 0x00
4137  0xB0, 0x00,
4138  // 0x49: CMP ebp, 0x00000000
4139  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4140  // 0x4F: JZ 0x79
4141  0x74, 0x28,
4142  // 0x51: MOV al, 0x00
4143  0xB0, 0x00,
4144  // 0x53: CMP ebp, 0x00000000
4145  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4146  // 0x59: JZ 0x79
4147  0x74, 0x1E,
4148  // 0x5B: MOV al, 0x00
4149  0xB0, 0x00,
4150  // 0x5D: CMP ebp, 0x00000000
4151  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4152  // 0x63: JZ 0x79
4153  0x74, 0x14,
4154  // 0x65: MOV al, 0x00
4155  0xB0, 0x00,
4156  // 0x67: CMP ebp, 0x00000000
4157  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4158  // 0x6D: JZ 0x79
4159  0x74, 0x0A,
4160  // 0x6F: MOV al, 0x00
4161  0xB0, 0x00,
4162  // 0x71: CMP ebp, 0x00000000
4163  0x81, 0xFD, 0x00, 0x00, 0x00, 0x00,
4164  // 0x77: JZ 0x79
4165  0x74, 0x00,
4166  // 0x79: STI
4167  0xFB,
4168  // 0x7A: JZ 0x7f
4169  0x74, 0x03,
4170  // mov al, [rbp + 0]
4171  // 0x7C: JMP 0x81
4172  0xE9, 0x00, 0x00, 0x00, 0x00
4173  },
4174  .HypercallOffset = 0xFF,
4175  .RelocatedCodeOffset = 0x7C,
4176  },
4177  },
4178  },
4179 
4180  {
4181  .ModuleName = u"ntoskrnl.exe",
4182  .FunctionName = "RtlpVirtualUnwind7",
4183  .MinVersion = 7600,
4184  .MaxVersion = 7602,
4185  .Callback = NULL,
4186  .Tag = detTagRtlVirtualUnwind7,
4187  .Exported = FALSE,
4188  .NotCritical = TRUE,
4189  .DisableFlags = 0,
4190  .EnableFlags = DETOUR_ENABLE_ALWAYS,
4191  .Arguments = DET_ARGS_DEFAULT_WIN64,
4192  .HandlersCount = 1,
4193  .Handlers =
4194  {
4195  {
4196  .MinVersion = 7600,
4197  .MaxVersion = 7602,
4198  .HypercallType = hypercallTypeInt3,
4199 
4200  .CodeLength = 0x89,
4201  .Code =
4202  {
4203  // 0x00: PUSH rax
4204  0x50,
4205  // 0x01: CLI
4206  0xFA,
4207  // 0x02: CMP ebp, 0xbdbdbdbd
4208  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4209  // 0x08: JNZ 0x12
4210  0x75, 0x08,
4211  // 0x0A: MOV al, 0xbd
4212  0xB0, 0xBD,
4213  // 0x0C: CMP al, 0x8d
4214  0x3C, 0x8D,
4215  // 0x0E: STI
4216  0xFB,
4217  // 0x0F: POP rax
4218  0x58,
4219  // 0x10: JMP 0x88
4220  0xEB, 0x76,
4221  // 0x12: CMP ebp, 0xbdbdbdbd
4222  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4223  // 0x18: JNZ 0x22
4224  0x75, 0x08,
4225  // 0x1A: MOV al, 0xbd
4226  0xB0, 0xBD,
4227  // 0x1C: CMP al, 0x8d
4228  0x3C, 0x8D,
4229  // 0x1E: STI
4230  0xFB,
4231  // 0x1F: POP rax
4232  0x58,
4233  // 0x20: JMP 0x88
4234  0xEB, 0x66,
4235  // 0x22: CMP ebp, 0xbdbdbdbd
4236  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4237  // 0x28: JNZ 0x32
4238  0x75, 0x08,
4239  // 0x2A: MOV al, 0xbd
4240  0xB0, 0xBD,
4241  // 0x2C: CMP al, 0x8d
4242  0x3C, 0x8D,
4243  // 0x2E: STI
4244  0xFB,
4245  // 0x2F: POP rax
4246  0x58,
4247  // 0x30: JMP 0x88
4248  0xEB, 0x56,
4249  // 0x32: CMP ebp, 0xbdbdbdbd
4250  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4251  // 0x38: JNZ 0x42
4252  0x75, 0x08,
4253  // 0x3A: MOV al, 0xbd
4254  0xB0, 0xBD,
4255  // 0x3C: CMP al, 0x8d
4256  0x3C, 0x8D,
4257  // 0x3E: STI
4258  0xFB,
4259  // 0x3F: POP rax
4260  0x58,
4261  // 0x40: JMP 0x88
4262  0xEB, 0x46,
4263  // 0x42: CMP ebp, 0xbdbdbdbd
4264  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4265  // 0x48: JNZ 0x52
4266  0x75, 0x08,
4267  // 0x4A: MOV al, 0xbd
4268  0xB0, 0xBD,
4269  // 0x4C: CMP al, 0x8d
4270  0x3C, 0x8D,
4271  // 0x4E: STI
4272  0xFB,
4273  // 0x4F: POP rax
4274  0x58,
4275  // 0x50: JMP 0x88
4276  0xEB, 0x36,
4277  // 0x52: CMP ebp, 0xbdbdbdbd
4278  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4279  // 0x58: JNZ 0x62
4280  0x75, 0x08,
4281  // 0x5A: MOV al, 0xbd
4282  0xB0, 0xBD,
4283  // 0x5C: CMP al, 0x8d
4284  0x3C, 0x8D,
4285  // 0x5E: STI
4286  0xFB,
4287  // 0x5F: POP rax
4288  0x58,
4289  // 0x60: JMP 0x88
4290  0xEB, 0x26,
4291  // 0x62: CMP ebp, 0xbdbdbdbd
4292  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4293  // 0x68: JNZ 0x72
4294  0x75, 0x08,
4295  // 0x6A: MOV al, 0xbd
4296  0xB0, 0xBD,
4297  // 0x6C: CMP al, 0x8d
4298  0x3C, 0x8D,
4299  // 0x6E: STI
4300  0xFB,
4301  // 0x6F: POP rax
4302  0x58,
4303  // 0x70: JMP 0x88
4304  0xEB, 0x16,
4305  // 0x72: CMP ebp, 0xbdbdbdbd
4306  0x81, 0xFD, 0xBD, 0xBD, 0xBD, 0xBD,
4307  // 0x78: JNZ 0x82
4308  0x75, 0x08,
4309  // 0x7A: MOV al, 0xbd
4310  0xB0, 0xBD,
4311  // 0x7C: CMP al, 0x8d
4312  0x3C, 0x8D,
4313  // 0x7E: STI
4314  0xFB,
4315  // 0x7F: POP rax
4316  0x58,
4317  // 0x80: JMP 0x88
4318  0xEB, 0x06,
4319  // 0x82: STI
4320  0xFB,
4321  // 0x83: POP rax
4322  0x58,
4323  // 4 bytes of CMP [rbp], imm comes here
4324  // 0x84: JMP 0x89
4325  0xE9, 0x00, 0x00, 0x00, 0x00
4326  },
4327  .HypercallOffset = 0xFF,
4328  .RelocatedCodeOffset = 0x84,
4329  },
4330  },
4331  },
4332 
4333  {
4334  .ModuleName = u"ntoskrnl.exe",
4335  .FunctionName = "RtlpVirtualUnwind8",
4336  .MinVersion = 7600,
4337  .MaxVersion = 7602,
4338  .Callback = NULL,
4339  .Tag = detTagRtlVirtualUnwind8,
4340  .Exported = FALSE,
4341  .NotCritical = TRUE,
4342  .DisableFlags = 0,
4343  .EnableFlags = DETOUR_ENABLE_ALWAYS,
4344  .Arguments = DET_ARGS_DEFAULT_WIN64,
4345  .HandlersCount = 1,
4346  .Handlers =
4347  {
4348  {
4349  .MinVersion = 7600,
4350  .MaxVersion = 7602,
4351  .HypercallType = hypercallTypeInt3,
4352 
4353  .CodeLength = 0x89,
4354  .Code =
4355  {
4356  // 0x00: PUSH rax
4357  0x50,
4358  // 0x01: CLI
4359  0xFA,
4360  // 0x02: CMP ecx, 0xbdbdbdbd
4361  0x81, 0xF9, 0xBD, 0xBD, 0xBD, 0xBD,
4362  // 0x08: JNZ 0x12
4363  0x75, 0x08,
4364  // 0x0A: MOV al, 0xbd
4365  0xB0, 0xBD,
4366  // 0x0C: CMP al, 0xff
4367  0x3C, 0xFF,
4368  // 0x0E: STI
4369  0xFB,
4370  // 0x0F: POP rax
4371  0x58,
4372  // 0x10: JMP 0x88
4373  0xEB, 0x76,
4374  // 0x12: CMP ecx, 0xbdbdbdbd
4375  0x81, 0xF9, 0xBD, 0xBD, 0xBD, 0xBD,
4376  // 0x18: JNZ 0x22
4377  0x75, 0x08,
4378  // 0x1A: MOV al, 0xbd
4379  0xB0, 0xBD,
4380  // 0x1C: CMP al, 0xff
4381  0x3C, 0xFF,
4382  // 0x1E: STI
4383  0xFB,
4384  // 0x1F: POP rax
4385  0x58,
4386  // 0x20: JMP 0x88
4387  0xEB, 0x66,
4388  // 0x22: CMP ecx, 0xbdbdbdbd
4389  0x81, 0xF9, 0xBD, 0xBD, 0xBD, 0xBD,
4390  // 0x28: JNZ 0x32
4391  0x75, 0x08,
4392  // 0x2A: MOV al, 0xbd
4393  0xB0, 0xBD,
4394  // 0x2C: CMP al, 0xff
4395  0x3C, 0xFF,
4396  // 0x2E: STI
4397  0xFB,
4398  // 0x2F: POP rax
4399  0x58,
4400  // 0x30: JMP 0x88
4401  0xEB, 0x56,
4402  // 0x32: CMP ecx, 0xbdbdbdbd
4403  0x81, 0xF9, 0xBD, 0xBD, 0xBD, 0xBD,
4404  // 0x38: JNZ 0x42
4405  0x75, 0x08,
4406  // 0x3A: MOV al, 0xbd
4407  0xB0, 0xBD,
4408  // 0x3C: CMP al, 0xff
4409  0x3C, 0xFF,
4410  // 0x3E: STI
4411  0xFB,
4412  // 0x3F: POP rax
4413  0x58,
4414  // 0x40: JMP 0x88
4415  0xEB, 0x46,
4416  // 0x42: CMP ecx, 0xbdbdbdbd
4417  0x81, 0xF9, 0xBD, 0xBD, 0xBD, 0xBD,
4418  // 0x48: JNZ 0x52
4419  0x75, 0x08,
4420  // 0x4A: MOV al, 0xbd
4421  0xB0, 0xBD,
4422  // 0x4C: CMP al, 0xff
4423  0x3C, 0xFF,
4424  // 0x4E: STI
4425  0xFB,
4426  // 0x4F: POP rax
4427  0x58,
4428  // 0x50: JMP 0x88
4429  0xEB, 0x36,
4430  // 0x52: CMP ecx, 0xbdbdbdbd
4431  0x81, 0xF9, 0xBD, 0xBD, 0xBD, 0xBD,
4432  // 0x58: JNZ 0x62
4433  0x75, 0x08,
4434  // 0x5A: MOV al, 0xbd
4435  0xB0, 0xBD,
4436  // 0x5C: CMP al, 0xff
4437  0x3C, 0xFF,
4438  // 0x5E: STI
4439  0xFB,
4440  // 0x5F: POP rax
4441  0x58,
4442  // 0x60: JMP 0x88
4443  0xEB, 0x26,
4444  // 0x62: CMP ecx, 0xbdbdbdbd
4445  0x81, 0xF9, 0xBD, 0xBD, 0xBD, 0xBD,
4446  // 0x68: JNZ 0x72
4447  0x75, 0x08,
4448  // 0x6A: MOV al, 0xbd
4449  0xB0, 0xBD,
4450  // 0x6C: CMP al, 0xff
4451  0x3C, 0xFF,
4452  // 0x6E: STI
4453  0xFB,
4454  // 0x6F: POP rax
4455  0x58,
4456  // 0x70: JMP 0x88
4457  0xEB, 0x16,
4458  // 0x72: CMP ecx, 0xbdbdbdbd
4459  0x81, 0xF9, 0xBD, 0xBD, 0xBD, 0xBD,
4460  // 0x78: JNZ 0x82
4461  0x75, 0x08,
4462  // 0x7A: MOV al, 0xbd
4463  0xB0, 0xBD,
4464  // 0x7C: CMP al, 0xff
4465  0x3C, 0xFF,
4466  // 0x7E: STI
4467  0xFB,
4468  // 0x7F: POP rax
4469  0x58,
4470  // 0x80: JMP 0x88
4471  0xEB, 0x06,
4472  // 0x82: STI
4473  0xFB,
4474  // 0x83: POP rax
4475  0x58,
4476  // 4 bytes of CMP [rbp], imm comes here
4477  // 0x84: JMP 0x89
4478  0xE9, 0x00, 0x00, 0x00, 0x00
4479  },
4480  .HypercallOffset = 0xFF,
4481  .RelocatedCodeOffset = 0x84,
4482  },
4483  },
4484  },
4485 
4486  {
4487  .ModuleName = u"ntoskrnl.exe",
4488  .FunctionName = "KiDisplayBlueScreen",
4489  .MinVersion = DETOUR_MIN_VERSION_ANY,
4490  .MaxVersion = DETOUR_MAX_VERSION_ANY,
4491  .Callback = IntGuestUninitOnBugcheck,
4492  .Tag = detTagCleanupMemDump,
4493  .Exported = FALSE,
4494  .NotCritical = TRUE,
4495  .DisableFlags = 0,
4496  .EnableFlags = INTRO_OPT_BUGCHECK_CLEANUP,
4497  .Arguments = DET_ARGS_DEFAULT_WIN64,
4498  .HandlersCount = 1,
4499  .Handlers =
4500  {
4501  {
4502  .MinVersion = DETOUR_MIN_VERSION_ANY,
4503  .MaxVersion = DETOUR_MAX_VERSION_ANY,
4504  .HypercallType = hypercallTypeInt3,
4505 
4506  .CodeLength = 0x8,
4507  .Code =
4508  {
4509  // 0x00: INT3
4510  0xCC,
4511  // 0x01: NOP
4512  0x90,
4513  // 0x02: NOP
4514  0x90,
4515  // 0x03: JMP 0x8
4516  0xE9, 0x00, 0x00, 0x00, 0x00
4517  },
4518  .HypercallOffset = 0x0,
4519  .RelocatedCodeOffset = 0x3,
4520  },
4521  },
4522  },
4523 };
4524 
4527 
#define DETOUR_ENABLE_ALWAYS
Can be used as the API_HOOK_DESCRIPTOR.EnableFlags to always enable the detour.
Definition: detours.h:425
INTSTATUS IntWinPowHandlePowerStateChange(void *Detour)
Detour callback which is called whenever NtSetSystemPowerState is called, resulting in a hypercall to...
Definition: winpower.c:273
INTSTATUS IntWinVadHandleInsert(void const *Detour)
The detour handler that will be invoked when the guest inserts a new VAD in the tree.This is the detour handler for the MiInsertVad guest API.
Definition: winvad.c:2809
INTSTATUS IntWinVadHandleDeleteVaRange(void const *Detour)
The detour handler that will be invoked when a memory range contained by a VAD is deleted...
Definition: winvad.c:3181
INTSTATUS IntWinHandleException(void *Detour)
Handles a hardware exception triggered inside the guestThis is the detour handler for the guest KiDis...
Definition: winumcrash.c:544
INTSTATUS IntWinVadPatchInsertMap(QWORD FunctionAddress, API_HOOK_HANDLER *Handler, QWORD HandlerAddress)
This is the PFUNC_PreDetourCallback for the MiGetWsAndInsertVad guest API detour.It will be invoked b...
Definition: winvad.c:3555
INTSTATUS IntWinVadPatchVirtualProtect(QWORD FunctionAddress, API_HOOK_HANDLER *Handler, QWORD HandlerAddress)
This is the PFUNC_PreDetourCallback for the MiProtectVirtualMemory guest API detour.It will be invoked before the detour is placed inside the guest and will patch the detour handler with the value of winKmFieldProcessSpare.
Definition: winvad.c:3604
INTSTATUS IntWinThrHandleQueueApc(void *Detour)
Handles a NtQueueApcThreadEx call - blocking process injections.Asynchronous Procedure Call (APC) inj...
Definition: winthread.c:766
#define ARRAYSIZE(A)
Definition: introdefs.h:101
INTSTATUS IntWinVadHandleVirtualProtect(void const *Detour)
The detour handler that will be invoked when a memory range contained by a VAD has the protection rig...
Definition: winvad.c:3323
INTSTATUS IntWinPatchVadHandleCommit(QWORD FunctionAddress, API_HOOK_HANDLER *Handler, QWORD HandlerAddress)
This is the PFUNC_PreDetourCallback for the MiCommitExistingVad guest API detour.It will be invoked b...
Definition: winvad.c:2944
INTSTATUS IntDriverUnloadHandler(void const *Detour)
The detour handler that will be invoked when a guest driver is unloaded.This handles driver unloading...
Definition: drivers.c:110
INTSTATUS IntWinProcHandleTerminate(void *Detour)
This functions handles the termination of a Windows process.This function is invoked every time "MmCl...
Definition: winprocess.c:2506
#define DETOUR_MAX_VERSION_ANY
Specifies that the first OS version for which a detour handler is available is the latest OS version ...
Definition: detours.h:313
INTSTATUS IntWinVadPatchInsert(QWORD FunctionAddress, API_HOOK_HANDLER *Handler, QWORD HandlerAddress)
This is the PFUNC_PreDetourCallback for the MiInsertVad guest API detour.It will be invoked before th...
Definition: winvad.c:3753
INTSTATUS IntWinVadHandleCommit(void const *Detour)
The detour handler that will be invoked when an existing VAD is committed by the guest.This is the detour handler for the MiCommitExistingVad guest API. Due to the way we ignore certain VADs, this can be invoked either when protection is changed for a known VAD, in which case we have to adjust our protection; or, when protection is changed for a previously unknown VAD in a way that makes it relevant for Introcore, in which case we treat as a newly created VAD.
Definition: winvad.c:3010
The detour will use a INT3 instruction in order to notify introcore about an event.
Definition: detours.h:185
const size_t gHookableApisX64Size
The number of functions to be hooked for 64-bit Windows guests.
Definition: winhkhnd.c:4526
#define INTRO_OPT_EVENT_PROCESS_CRASH
Enable application crash events (generates introEventExceptionEvent).
Definition: intro_types.h:433
INTSTATUS IntWinPoolHandleAlloc(void *Detour)
Detour callback for ExAllocatePoolWithTag.Handles allocations within a Windows guest, executed using the ExAllocatePoolWithTag API. Basically, it will check the tag of the allocation, and if it identifies an allocation for a driver object or a fast I/O dispatch, it will patch the Size argument of the call so that it&#39;s almost a page. This ensures us that critical structures protected by the introspection will be allocated alone in each page, which gives us an enormous performance boost.
Definition: winpool.c:13
INTSTATUS IntWinThrHandleThreadHijack(void *Detour)
Handles a SetContextThread call - blocking thread hijacking.Thread hijacking (amongst others) is an a...
Definition: winthread.c:429
INTSTATUS IntDriverLoadHandler(void const *Detour)
The detour handler that will be invoked when a guest loads a new driver.This handles driver loading i...
Definition: drivers.c:45
INTSTATUS IntGuestUninitOnBugcheck(void const *Detour)
Prepares Introcore unload in case of a guest crash in order to clean up the code and data injected in...
Definition: introcore.c:2522
INTSTATUS IntWinThrPatchThreadHijackHandler(QWORD FunctionAddress, void *Handler, QWORD HandlerAddress)
This functions is responsible for patching the detour that handles the "PspSetContextThreadInternal"...
Definition: winthread.c:1059
Exposes the functions used to provide Windows Threads related support.
const size_t gHookableApisX86Size
The number of functions to be hooked for 32-bit Windows guests.
Definition: winhkhnd.c:1584
INTSTATUS IntWinVadPatchDeleteVaRange(QWORD FunctionAddress, API_HOOK_HANDLER *Handler, QWORD HandlerAddress)
This is the PFUNC_PreDetourCallback for the MiDeleteVirtualAddresses guest API detour.It will be invoked before the detour is placed inside the guest and will patch the detour handler with the value of winKmFieldProcessSpare.
Definition: winvad.c:3661
#define DETOUR_MIN_VERSION_ANY
Specifies that the first OS version for which a detour handler is available is the first OS version s...
Definition: detours.h:310
Information about Windows kernel crashes.
#define DET_ARGS_DEFAULT_WIN86
Default argument passing convention for 32-bit Windows guests.
Definition: detours.h:86
#define INTRO_OPT_ENABLE_MISC_EVENTS
Aggregates all the miscellaneous protection flags.
Definition: intro_types.h:566
#define __section(S)
Definition: common.h:59
#define TRUE
Definition: intro_types.h:30
INTSTATUS IntWinVadHandleInsertPrivate(void const *Detour)
The detour handler that will be invoked when the guest inserts a new VAD in the tree.This is the detour handler for the MiInsertPrivateVad guest API.
Definition: winvad.c:2881
INTSTATUS IntWinBcHandleBugCheck(void const *Detour)
Handles a Windows OS crash.This is the detour handle for the KeBugCheck2 32-bit Windows kernel API an...
Definition: winbugcheck.c:928
INTSTATUS IntWinPoolHandleFree(void *Detour)
Detour callback for ExFreePoolWithTag.This function handles de-allocation requests executed by the gu...
Definition: winpool.c:106
INTSTATUS IntWinProcPatchCopyMemoryDetour(QWORD FunctionAddress, void *Handler, QWORD HandlerAddress)
This functions is responsible for patching the detour that handles the "MmCopyVirtualMemory".This function is invoked every time "MmCopyVirtualMemory" is called (a process is writing/reading another process) but before the actual handler IntWinProcHandleCopyMemory, its purpose being to modify the hook code (see winhkhnd.c).
Definition: winprocess.c:2570
INTSTATUS IntWinVadPatchInsertPrivate(QWORD FunctionAddress, API_HOOK_HANDLER *Handler, QWORD HandlerAddress)
This is the PFUNC_PreDetourCallback for the MiInsertPrivateVad guest API detour.It will be invoked be...
Definition: winvad.c:3495
#define INTRO_OPT_ENABLE_UM_PROTECTION
Aggregates all the user mode protection flags.
Definition: intro_types.h:527
INTSTATUS IntWinVadHandleInsertMap(void const *Detour)
The detour handler that will be invoked when a VAD is inserted in the guest VAD tree.This is the detour handler for the MiGetWsAndInsertVad guest API.
Definition: winvad.c:3126
INTSTATUS IntWinVadPatchFinishVadDeletion(QWORD FunctionAddress, API_HOOK_HANDLER *Handler, QWORD HandlerAddress)
This is the PFUNC_PreDetourCallback for the MiFinishVadDeletion guest API detour.It will be invoked b...
Definition: winvad.c:3709
INTSTATUS IntWinVadHandleFinishVadDeletion(void const *Detour)
The detour handler that will be invoked when a memory range contained by a VAD is deleted...
Definition: winvad.c:3252
API_HOOK_DESCRIPTOR gHookableApisX64[]
The functions to be hooked for 64-bit Windows guests.
Definition: winhkhnd.c:1590
INTSTATUS IntWinProcHandleCopyMemory(void *Detour)
This functions is responsible handling process read/write operations.This function is invoked every t...
Definition: winprocess.c:2694
#define INTRO_OPT_BUGCHECK_CLEANUP
Enable memory cleanup after an OS crash (Windows).
Definition: intro_types.h:450
#define INTRO_OPT_EVENT_OS_CRASH
Enable OS crash events (generates introEventCrashEvent events).
Definition: intro_types.h:431
INTSTATUS IntWinProcHandleCreate(void *Detour)
Detour handler for the PspInsertProcess Windows kernel API.The actual process creation is handled by ...
Definition: winprocess.c:2434
#define DET_ARGS_DEFAULT_WIN64
Default argument passing convention for 64-bit Windows guests.
Definition: detours.h:80
API_HOOK_DESCRIPTOR gHookableApisX86[]
The functions to be hooked for 32-bit Windows guests.
Definition: winhkhnd.c:61
INTSTATUS IntWinProcPatchPspInsertProcess86(QWORD FunctionAddress, void *Handler, QWORD HandlerAddress)
This functions is responsible for patching the detour that handles the "PspInsertProcess".
Definition: winprocess.c:2277
Describes a function to be hooked.
Definition: detours.h:325
#define FALSE
Definition: intro_types.h:34
INTSTATUS IntWinThrPrepareApcHandler(QWORD FunctionAddress, void *Handler, QWORD HandlerAddress)
This functions is responsible for patching the detour that handles the "NtQueueApcThreadEx".This function is invoked every time "NtQueueApcThreadEx" is called (and APC has been queued) but before the actual handler IntWinThrHandleQueueApc, its purpose being to modify the hook code (see winhkhnd.h).
Definition: winthread.c:1131