HyperDbg Debugger
Loading...
Searching...
No Matches
Termination.c File Reference

Implementation of debugger functions for terminating events. More...

#include "pch.h"

Functions

VOID TerminateExternalInterruptEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for external-interrupts.
VOID TerminateHiddenHookReadAndWriteAndExecuteEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for hidden hook read/write/execute.
VOID TerminateHiddenHookExecCcEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for hidden hook (hidden breakpoints).
VOID TerminateHiddenHookExecDetoursEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for hidden hook (detours).
VOID TerminateRdmsrExecutionEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for msr read events.
VOID TerminateWrmsrExecutionEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for msr write events.
VOID TerminateExceptionEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for exception events.
VOID TerminateInInstructionExecutionEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for IN instruction events.
VOID TerminateOutInstructionExecutionEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for OUT Instructions events.
VOID TerminateVmcallExecutionEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for VMCALL Instruction events.
VOID TerminateExecTrapModeChangedEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for user-mode, kernel-mode exec trap events.
VOID TerminateCpuidExecutionEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for CPUID Instruction events.
VOID TerminateTscEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for RDTSC/RDTSCP Instruction events.
VOID TerminatePmcEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for RDPMC Instruction events.
VOID TerminateControlRegistersEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for MOV to control registers events.
VOID TerminateDebugRegistersEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for MOV to debug registers events.
VOID TerminateSyscallHookEferEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for SYSCALL Instruction events.
VOID TerminateSysretHookEferEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for SYSRET Instruction events.
BOOLEAN TerminateQueryDebuggerResourceExceptionBitmap (UINT32 CoreId, UINT32 *BitmapMask, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Check and modify state of exception bitmap.
BOOLEAN TerminateQueryDebuggerResourceExternalInterruptExiting (UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Check and modify state of external interrupt exiting.
BOOLEAN TerminateQueryDebuggerResourceTscExiting (UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Check and modify state of TSC exiting.
BOOLEAN TerminateQueryDebuggerResourceMov2DebugRegExiting (UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Check and modify state of mov 2 debug regs exiting.
BOOLEAN TerminateQueryDebuggerResourceMovControlRegsExiting (UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Check and modify state of move to control register exiting.
BOOLEAN TerminateQueryDebuggerResourceMovToCr3Exiting (UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Check and modify state of move to cr3 control register exiting.
BOOLEAN TerminateQueryDebuggerResourceSaveAndLoadDebugControls (UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Check and modify state of save and load debug controls (DR7 and IA32_DEBUGCTLS) on exit and entry VM controls.
BOOLEAN TerminateEptHookUnHookSingleAddressFromVmxRootAndApplyInvalidation (UINT64 VirtualAddress, UINT64 PhysAddress)
 Remove single hook from the hooked pages list and invalidate TLB.
BOOLEAN TerminateEptHookUnHookAllHooksByHookingTagFromVmxRootAndApplyInvalidation (UINT64 HookingTag)
 Remove all hooks from the hooked pages list and invalidate TLB using hooking tag.
BOOLEAN TerminateQueryDebuggerResource (UINT32 CoreId, PROTECTED_HV_RESOURCES_TYPE ResourceType, PVOID Context, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Termination query state of debugger.
VOID TerminateXsetbvExecutionEvent (PDEBUGGER_EVENT Event, BOOLEAN InputFromVmxRoot)
 Termination function for XSETBV Instruction events.

Detailed Description

Implementation of debugger functions for terminating events.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-08-16

Function Documentation

◆ TerminateControlRegistersEvent()

VOID TerminateControlRegistersEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for MOV to control registers events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
958{
959 PLIST_ENTRY TempList = 0;
960 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
961
962 if (DebuggerEventListCount(&g_Events->ControlRegisterModifiedEventsHead) > 1)
963 {
964 //
965 // There are still other events in the queue (list), we should only remove
966 // this special event (not all events)
967 //
968
969 //
970 // For this purpose, first we disable all the events by
971 // disabling all of them
972 //
973 if (InputFromVmxRoot)
974 {
976 }
977 else
978 {
980 }
981
982 //
983 // Then we iterate through the list of this event to re-apply
984 // the previous events
985 //
986 TempList = &g_Events->ControlRegisterModifiedEventsHead;
987
988 while (&g_Events->ControlRegisterModifiedEventsHead != TempList->Flink)
989 {
990 TempList = TempList->Flink;
991 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
992
993 //
994 // We have to check because we don't want to re-apply
995 // the terminated event
996 //
997 if (CurrentEvent->Tag != Event->Tag)
998 {
999 //
1000 // re-apply the event
1001 //
1002 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
1003
1004 if (!ResultsToReturn.IsSuccessful)
1005 {
1006 LogInfo("Err, unable to re-apply previous events");
1007 }
1008 }
1009 }
1010 }
1011 else
1012 {
1013 //
1014 // Nothing else is in the list, we have to restore everything to default
1015 // as the current event is the only event in the list
1016 //
1017
1018 //
1019 // Disable it on all cores
1020 //
1021 if (InputFromVmxRoot)
1022 {
1024 }
1025 else
1026 {
1028 }
1029 }
1030}
BOOLEAN DebuggerApplyEvent(PDEBUGGER_EVENT Event, PDEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn, BOOLEAN InputFromVmxRoot)
Applying events.
Definition Debugger.c:2922
UINT32 DebuggerEventListCount(PLIST_ENTRY TargetEventList)
Count the list of events in a special list.
Definition Debugger.c:2085
VOID ExtensionCommandDisableMov2ControlRegsExitingForClearingEventsAllCores(PDEBUGGER_EVENT Event)
routines ONLY for disabling !crwrite command
Definition ExtensionCommands.c:485
VOID HaltedBroadcastDisableMov2CrExitingForClearingCrEventsAllCores(DEBUGGER_EVENT_OPTIONS *BroadcastingOption)
This function broadcasts clear mov 2 cr exiting bit ONLY in the case of disabling the events for !...
Definition HaltedBroadcast.c:701
struct _DEBUGGER_EVENT_AND_ACTION_RESULT DEBUGGER_EVENT_AND_ACTION_RESULT
Status of register buffers.
#define LogInfo(format,...)
Define log variables.
Definition HyperDbgHyperLogIntrinsics.h:71
DEBUGGER_CORE_EVENTS * g_Events
events list (for debugger)
Definition Global.h:90
struct _DEBUGGER_EVENT DEBUGGER_EVENT
The structure of events in HyperDbg.
struct _DEBUGGER_EVENT * PDEBUGGER_EVENT
#define CONTAINING_RECORD(address, type, field)
Definition nt-list.h:36
BOOLEAN IsSuccessful
Definition Events.h:433
UINT64 Tag
Definition Debugger.h:110
DEBUGGER_EVENT_OPTIONS Options
Definition Debugger.h:132

◆ TerminateCpuidExecutionEvent()

VOID TerminateCpuidExecutionEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for CPUID Instruction events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
747{
748 UNREFERENCED_PARAMETER(Event);
749 UNREFERENCED_PARAMETER(InputFromVmxRoot);
750
751 if (DebuggerEventListCount(&g_Events->CpuidInstructionExecutionEventsHead) > 1)
752 {
753 //
754 // There are still other events in the queue (list), we should only remove
755 // this special event (not all events)
756 //
757
758 //
759 // Nothing we can do for this event type, let it work because of other events
760 //
761 return;
762 }
763 else
764 {
765 //
766 // Nothing else is in the list, we have to restore everything to default
767 // as the current event is the only event in the list
768 //
769
770 //
771 // We set the global variable related to the cpuid to FALSE
772 // so the vm-exit handler, no longer triggers events related
773 // to the cpuids (still they cause vm-exits as cpuid is an
774 // unconditional instruction for vm-exit)
775 //
777 }
778}
#define FALSE
Definition BasicTypes.h:113
IMPORT_EXPORT_VMM VOID VmFuncSetTriggerEventForCpuids(BOOLEAN Set)
Set triggering events for CPUIDs.
Definition Export.c:837

◆ TerminateDebugRegistersEvent()

VOID TerminateDebugRegistersEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for MOV to debug registers events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
1042{
1043 PLIST_ENTRY TempList = 0;
1044 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
1045
1046 if (DebuggerEventListCount(&g_Events->DebugRegistersAccessedEventsHead) > 1)
1047 {
1048 //
1049 // There are still other events in the queue (list), we should only remove
1050 // this special event (not all events)
1051 //
1052
1053 //
1054 // For this purpose, first we disable all the events by
1055 // disabling all of them
1056 //
1057 if (InputFromVmxRoot)
1058 {
1060 }
1061 else
1062 {
1064 }
1065
1066 //
1067 // Then we iterate through the list of this event to re-apply
1068 // the previous events
1069 //
1070 TempList = &g_Events->DebugRegistersAccessedEventsHead;
1071
1072 while (&g_Events->DebugRegistersAccessedEventsHead != TempList->Flink)
1073 {
1074 TempList = TempList->Flink;
1075 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
1076
1077 //
1078 // We have to check because we don't want to re-apply
1079 // the terminated event
1080 //
1081 if (CurrentEvent->Tag != Event->Tag)
1082 {
1083 //
1084 // re-apply the event
1085 //
1086 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
1087
1088 if (!ResultsToReturn.IsSuccessful)
1089 {
1090 LogInfo("Err, unable to re-apply previous events");
1091 }
1092 }
1093 }
1094 }
1095 else
1096 {
1097 //
1098 // Nothing else is in the list, we have to restore everything to default
1099 // as the current event is the only event in the list
1100 //
1101
1102 //
1103 // Disable it on all cores
1104 //
1105 if (InputFromVmxRoot)
1106 {
1108 }
1109 else
1110 {
1112 }
1113 }
1114}
VOID ExtensionCommandDisableMov2DebugRegsExitingForClearingEventsAllCores()
routines ONLY for disabling !dr command
Definition ExtensionCommands.c:498
VOID HaltedBroadcastDisableMov2DrExitingForClearingDrEventsAllCores()
This function broadcasts clear mov 2 hw dr exiting bit ONLY in the case of disabling the events for !...
Definition HaltedBroadcast.c:671

◆ TerminateEptHookUnHookAllHooksByHookingTagFromVmxRootAndApplyInvalidation()

BOOLEAN TerminateEptHookUnHookAllHooksByHookingTagFromVmxRootAndApplyInvalidation ( UINT64 HookingTag)

Remove all hooks from the hooked pages list and invalidate TLB using hooking tag.

Should be called from vmx root-mode

Parameters
HookingTagThe hooking tag to unhook
Returns
BOOLEAN If unhook was successful it returns true or if it was not successful returns false
1692{
1693 BOOLEAN Result = FALSE;
1694 BOOLEAN IsAtLeastOneHookRemoved = FALSE;
1695 EPT_SINGLE_HOOK_UNHOOKING_DETAILS TargetUnhookingDetails = {0};
1696
1697UnhookNextPossibleTag:
1698 //
1699 // Perform unhooking directly from VMX-root mode using hooking tag
1700 //
1702 &TargetUnhookingDetails);
1703
1704 if (Result == TRUE)
1705 {
1706 //
1707 // At least one hook was removed
1708 //
1709 IsAtLeastOneHookRemoved = TRUE;
1710
1711 //
1712 // It's the responsibility of the caller to restore EPT entries and
1713 // invalidate EPT caches
1714 //
1715 if (TargetUnhookingDetails.CallerNeedsToRestoreEntryAndInvalidateEpt)
1716 {
1717 HaltedBroadcastUnhookSinglePageAllCores(&TargetUnhookingDetails);
1718 }
1719
1720 //
1721 // It's the responsibility of the caller to clear #BPs directly from
1722 // VMX-root mode if applied from VMX-root mode
1723 //
1724 if (TargetUnhookingDetails.RemoveBreakpointInterception)
1725 {
1726 //
1727 // The hook was the last hook and we can broadcast to
1728 // not intercept #BPs anymore
1729 //
1731 }
1732
1733 //
1734 // Keep unhooking until there is no hook with the same hooking tag
1735 //
1736 goto UnhookNextPossibleTag;
1737 }
1738
1739 //
1740 // The result of removing EPT hook
1741 //
1742 return IsAtLeastOneHookRemoved;
1743}
VOID HaltedBroadcastUnhookSinglePageAllCores(EPT_SINGLE_HOOK_UNHOOKING_DETAILS *UnhookingDetail)
This function broadcasts restore a single EPT entry and invalidate EPT cache to all cores.
Definition HaltedBroadcast.c:417
VOID HaltedBroadcastUnSetExceptionBitmapAllCores(UINT64 ExceptionIndex)
This function broadcasts unset exception bitmap on VMCS to all cores.
Definition HaltedBroadcast.c:267
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
struct _EPT_SINGLE_HOOK_UNHOOKING_DETAILS EPT_SINGLE_HOOK_UNHOOKING_DETAILS
Details of unhooking single EPT hooks.
@ EXCEPTION_VECTOR_BREAKPOINT
Definition Events.h:27
IMPORT_EXPORT_VMM BOOLEAN ConfigureEptHookUnHookSingleHookByHookingTagFromVmxRoot(UINT64 HookingTag, EPT_SINGLE_HOOK_UNHOOKING_DETAILS *TargetUnhookingDetails)
Remove single hook from the hooked pages by the given hooking tag.
Definition Configuration.c:172
BOOLEAN CallerNeedsToRestoreEntryAndInvalidateEpt
Definition DataTypes.h:408
BOOLEAN RemoveBreakpointInterception
Definition DataTypes.h:409

◆ TerminateEptHookUnHookSingleAddressFromVmxRootAndApplyInvalidation()

BOOLEAN TerminateEptHookUnHookSingleAddressFromVmxRootAndApplyInvalidation ( UINT64 VirtualAddress,
UINT64 PhysAddress )

Remove single hook from the hooked pages list and invalidate TLB.

Should be called from vmx root-mode

Parameters
VirtualAddressVirtual address to unhook (optional)
PhysAddressPhysical address to unhook (optional)
Returns
BOOLEAN If unhook was successful it returns true or if it was not successful returns false
1638{
1639 BOOLEAN Result = FALSE;
1640 EPT_SINGLE_HOOK_UNHOOKING_DETAILS TargetUnhookingDetails = {0};
1641
1642 //
1643 // Perform unhooking directly from VMX-root mode
1644 //
1645 Result = ConfigureEptHookUnHookSingleAddressFromVmxRoot(VirtualAddress,
1646 PhysAddress,
1647 &TargetUnhookingDetails);
1648
1649 if (Result == TRUE)
1650 {
1651 //
1652 // It's the responsibility of the caller to restore EPT entries and
1653 // invalidate EPT caches
1654 //
1655 if (TargetUnhookingDetails.CallerNeedsToRestoreEntryAndInvalidateEpt)
1656 {
1657 HaltedBroadcastUnhookSinglePageAllCores(&TargetUnhookingDetails);
1658 }
1659
1660 //
1661 // It's the responsibility of the caller to clear #BPs directly from
1662 // VMX-root mode if applied from VMX-root mode
1663 //
1664 if (TargetUnhookingDetails.RemoveBreakpointInterception)
1665 {
1666 //
1667 // The hook was the last hook and we can broadcast to
1668 // not intercept #BPs anymore
1669 //
1671 }
1672
1673 return TRUE;
1674 }
1675
1676 //
1677 // The result of removing EPT hook was not okay
1678 //
1679 return FALSE;
1680}
IMPORT_EXPORT_VMM BOOLEAN ConfigureEptHookUnHookSingleAddressFromVmxRoot(UINT64 VirtualAddress, UINT64 PhysAddress, EPT_SINGLE_HOOK_UNHOOKING_DETAILS *TargetUnhookingDetails)
Remove single hook from the hooked pages list and invalidate TLB.
Definition Configuration.c:211

◆ TerminateExceptionEvent()

VOID TerminateExceptionEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for exception events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
382{
383 PLIST_ENTRY TempList = 0;
384 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
385
386 if (DebuggerEventListCount(&g_Events->ExceptionOccurredEventsHead) > 1)
387 {
388 //
389 // There are still other events in the queue (list), we should only remove
390 // this special event (not all events)
391 //
392
393 //
394 // For this purpose, first we disable all the events by
395 // disabling all of them
396 //
397 if (InputFromVmxRoot)
398 {
400 }
401 else
402 {
404 }
405
406 //
407 // Then we iterate through the list of this event to re-apply
408 // the previous events
409 //
410 TempList = &g_Events->ExceptionOccurredEventsHead;
411
412 while (&g_Events->ExceptionOccurredEventsHead != TempList->Flink)
413 {
414 TempList = TempList->Flink;
415 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
416
417 //
418 // We have to check because we don't want to re-apply
419 // the terminated event
420 //
421 if (CurrentEvent->Tag != Event->Tag)
422 {
423 //
424 // re-apply the event
425 //
426 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
427
428 if (!ResultsToReturn.IsSuccessful)
429 {
430 LogInfo("Err, unable to re-apply previous events");
431 }
432 }
433 }
434 }
435 else
436 {
437 //
438 // Nothing else is in the list, we have to restore everything to default
439 // as the current event is the only event in the list
440 //
441
442 //
443 // Broadcast to reset exception bitmap on all cores
444 //
445 if (InputFromVmxRoot)
446 {
448 }
449 else
450 {
452 }
453 }
454}
VOID ExtensionCommandResetExceptionBitmapAllCores()
routines for reset !exception command
Definition ExtensionCommands.c:570
VOID HaltedBroadcastResetExceptionBitmapOnlyOnClearingExceptionEventsAllCores()
This function broadcasts reset exception bitmap on VMCS to all cores.
Definition HaltedBroadcast.c:532

◆ TerminateExecTrapModeChangedEvent()

VOID TerminateExecTrapModeChangedEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for user-mode, kernel-mode exec trap events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
691{
692 if (DebuggerEventListCount(&g_Events->TrapExecutionModeChangedEventsHead) > 1)
693 {
694 //
695 // There are still other events in the queue (list), we should only remove
696 // this special event (not all events)
697 //
698
699 //
700 // Just remove the process id from the watching list
701 //
703
704 //
705 // Nothing we can do for this event type, let it work because of other events
706 //
707 return;
708 }
709 else
710 {
711 //
712 // Nothing else is in the list, we have to restore everything to default
713 // as the current event is the only event in the list
714 //
715
716 //
717 // We have to uninitialize the event
718 // If the debugger is in the Debugger Mode, we prefer not to uninitialize the
719 // exec mode trap because re-activating it needs a special command (preactivate)
720 // to be used so if the user needs to re-create such a functionality again
721 // after removing it, then it's not needed to re-run the 'preactivate' command
722 // again
723 //
724 if (!InputFromVmxRoot)
725 {
727 }
728
729 //
730 // Remove the process id from the watching list
731 // THIS SHOULD BE DONE AFTER UNINITIALIZING THE TRAPS BECAUSE IT MIGHT END UP TO AN ERROR
732 //
734 }
735}
IMPORT_EXPORT_VMM VOID ConfigureUninitializeExecTrapOnAllProcessors()
routines for uninitializing user-mode, kernel-mode exec trap
Definition Configuration.c:43
IMPORT_EXPORT_VMM BOOLEAN ConfigureExecTrapRemoveProcessFromWatchingList(UINT32 ProcessId)
Remove the target process from the watching list.
Definition Configuration.c:79
UINT32 ProcessId
Definition Debugger.h:118

◆ TerminateExternalInterruptEvent()

VOID TerminateExternalInterruptEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for external-interrupts.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
25{
26 PLIST_ENTRY TempList = 0;
27 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
28
29 if (DebuggerEventListCount(&g_Events->ExternalInterruptOccurredEventsHead) > 1)
30 {
31 //
32 // There are still other events in the queue (list), we should only remove
33 // this special event (not all events)
34 //
35
36 //
37 // For this purpose, first we disable all the events by
38 // disabling all of them
39 //
40 if (InputFromVmxRoot)
41 {
43 }
44 else
45 {
47 }
48
49 //
50 // Then we iterate through the list of this event to re-apply
51 // the previous events
52 //
53 TempList = &g_Events->ExternalInterruptOccurredEventsHead;
54
55 while (&g_Events->ExternalInterruptOccurredEventsHead != TempList->Flink)
56 {
57 TempList = TempList->Flink;
58 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
59
60 //
61 // We have to check because we don't want to re-apply
62 // the terminated event
63 //
64 if (CurrentEvent->Tag != Event->Tag)
65 {
66 //
67 // re-apply the event
68 //
69 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
70
71 if (!ResultsToReturn.IsSuccessful)
72 {
73 LogInfo("Err, unable to re-apply previous events");
74 }
75 }
76 }
77 }
78 else
79 {
80 //
81 // Nothing else is in the list, we have to restore everything to default
82 // as the current event is the only event in the list
83 //
84
85 //
86 // Broadcast to disable on all cores
87 //
88 if (InputFromVmxRoot)
89 {
91 }
92 else
93 {
95 }
96 }
97}
VOID ExtensionCommandUnsetExternalInterruptExitingOnlyOnClearingInterruptEventsAllCores()
routines for ONLY terminate !interrupt command
Definition ExtensionCommands.c:653
VOID HaltedBroadcastSetDisableExternalInterruptExitingOnlyOnClearingInterruptEventsAllCores()
This function broadcasts disable external interrupt exiting only to clear !interrupt commands to all ...
Definition HaltedBroadcast.c:450

◆ TerminateHiddenHookExecCcEvent()

VOID TerminateHiddenHookExecCcEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for hidden hook (hidden breakpoints).

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
136{
137 //
138 // Because there are different EPT hooks, like READ, WRITE, READ WRITE,
139 // DETOURS INLINE HOOK, HIDDEN BREAKPOINT HOOK and all of them are
140 // unhooked with a same routine, we will not check whether the list of
141 // all of them is empty or not and instead, we remove just a single
142 // hook, this way is better as hidden hooks and ept modifications are
143 // not dependent to a single bit and if we remove or add any other hook
144 // then it won't cause any problem for other hooks
145 //
146
147 //
148 // In this hook Event->OptionalParam1 is the virtual address of the
149 // target address that we put hook on it
150 //
151 if (InputFromVmxRoot)
152 {
154 (UINT64)NULL);
155 }
156 else
157 {
159 (UINT64)NULL,
160 Event->ProcessId);
161 }
162}
BOOLEAN TerminateEptHookUnHookSingleAddressFromVmxRootAndApplyInvalidation(UINT64 VirtualAddress, UINT64 PhysAddress)
Remove single hook from the hooked pages list and invalidate TLB.
Definition Termination.c:1636
IMPORT_EXPORT_VMM BOOLEAN ConfigureEptHookUnHookSingleAddress(UINT64 VirtualAddress, UINT64 PhysAddress, UINT32 ProcessId)
Remove single hook from the hooked pages list and invalidate TLB.
Definition Configuration.c:190
UINT64 OptionalParam1
Definition Events.h:277

◆ TerminateHiddenHookExecDetoursEvent()

VOID TerminateHiddenHookExecDetoursEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for hidden hook (detours).

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
174{
175 //
176 // Because there are different EPT hooks, like READ, WRITE, READ WRITE,
177 // DETOURS INLINE HOOK, HIDDEN BREAKPOINT HOOK and all of them are
178 // unhooked with a same routine, we will not check whether the list of
179 // all of them is empty or not and instead, we remove just a single
180 // hook, this way is better as hidden hooks and ept modifications are
181 // not dependent to a single bit and if we remove or add any other hook
182 // then it won't cause any problem for other hooks
183 //
184
185 //
186 // In HIDDEN_HOOK_EXEC_DETOURS, OptionalParam1 points to a physical
187 // address that represent the virtual address, we have to convert
188 // this address to virtual address as the unhook routine works on
189 // virtual addresses
190 //
191 if (InputFromVmxRoot)
192 {
194 Event->Options.OptionalParam1);
195 }
196 else
197 {
199 Event->Options.OptionalParam1,
200 Event->ProcessId);
201 }
202}

◆ TerminateHiddenHookReadAndWriteAndExecuteEvent()

VOID TerminateHiddenHookReadAndWriteAndExecuteEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for hidden hook read/write/execute.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
109{
110 if (InputFromVmxRoot)
111 {
112 //
113 // EPT hooking tag is same as event tag, so we can use it to unhook
114 //
116 }
117 else
118 {
119 //
120 // EPT hooking tag is same as event tag, so we can use it to unhook
121 //
123 }
124}
BOOLEAN TerminateEptHookUnHookAllHooksByHookingTagFromVmxRootAndApplyInvalidation(UINT64 HookingTag)
Remove all hooks from the hooked pages list and invalidate TLB using hooking tag.
Definition Termination.c:1691
IMPORT_EXPORT_VMM BOOLEAN ConfigureEptHookUnHookAllByHookingTag(UINT64 HookingTag)
Remove all hooks from the hooked pages list using Hooking Tag.
Definition Configuration.c:159

◆ TerminateInInstructionExecutionEvent()

VOID TerminateInInstructionExecutionEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for IN instruction events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
466{
467 PLIST_ENTRY TempList = 0;
468 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
469
470 //
471 // For this event we should also check for out instructions events too
472 // because both of them are emulated by a single bit in vmx controls
473 // so if there is anything in out events list then we can remove all
474 // the events
475 //
476 if (DebuggerEventListCount(&g_Events->InInstructionExecutionEventsHead) > 1 ||
477 DebuggerEventListCount(&g_Events->OutInstructionExecutionEventsHead) >= 1)
478 {
479 //
480 // There are still other events in the queue (list), we should only remove
481 // this special event (not all events)
482 //
483
484 //
485 // For this purpose, first we disable all the events by
486 // disabling all of them
487 //
488 if (InputFromVmxRoot)
489 {
491 }
492 else
493 {
495 }
496
497 //
498 // Then we iterate through the list of this event to re-apply
499 // the previous events
500 //
501 TempList = &g_Events->InInstructionExecutionEventsHead;
502
503 while (&g_Events->InInstructionExecutionEventsHead != TempList->Flink)
504 {
505 TempList = TempList->Flink;
506 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
507
508 //
509 // We have to check because we don't want to re-apply
510 // the terminated event
511 //
512 if (CurrentEvent->Tag != Event->Tag)
513 {
514 //
515 // re-apply the event
516 //
517 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
518
519 if (!ResultsToReturn.IsSuccessful)
520 {
521 LogInfo("Err, unable to re-apply previous events");
522 }
523 }
524 }
525 }
526 else
527 {
528 //
529 // Nothing else is in the list, we have to restore everything to default
530 // as the current event is the only event in the list
531 //
532
533 //
534 // Broadcast to reset i/o bitmap on all cores
535 //
536 if (InputFromVmxRoot)
537 {
539 }
540 else
541 {
543 }
544 }
545}
VOID ExtensionCommandIoBitmapResetAllCores()
routines for reset !ioin and !ioout command
Definition ExtensionCommands.c:680
VOID HaltedBroadcastResetIoBitmapAllCores()
This function broadcasts reset I/O Bitmaps (A & B) to all cores.
Definition HaltedBroadcast.c:559

◆ TerminateOutInstructionExecutionEvent()

VOID TerminateOutInstructionExecutionEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for OUT Instructions events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
557{
558 PLIST_ENTRY TempList = 0;
559 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
560
561 //
562 // For this event we should also check for out instructions events too
563 // because both of them are emulated by a single bit in vmx controls
564 // so if there is anything in out events list then we can remove all
565 // the events
566 //
567 if (DebuggerEventListCount(&g_Events->OutInstructionExecutionEventsHead) > 1 ||
568 DebuggerEventListCount(&g_Events->InInstructionExecutionEventsHead) >= 1)
569 {
570 //
571 // There are still other events in the queue (list), we should only remove
572 // this special event (not all events)
573 //
574
575 //
576 // For this purpose, first we disable all the events by
577 // disabling all of them
578 //
579 if (InputFromVmxRoot)
580 {
582 }
583 else
584 {
586 }
587
588 //
589 // Then we iterate through the list of this event to re-apply
590 // the previous events
591 //
592 TempList = &g_Events->OutInstructionExecutionEventsHead;
593
594 while (&g_Events->OutInstructionExecutionEventsHead != TempList->Flink)
595 {
596 TempList = TempList->Flink;
597 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
598
599 //
600 // We have to check because we don't want to re-apply
601 // the terminated event
602 //
603 if (CurrentEvent->Tag != Event->Tag)
604 {
605 //
606 // re-apply the event
607 //
608 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
609
610 if (!ResultsToReturn.IsSuccessful)
611 {
612 LogInfo("Err, unable to re-apply previous events");
613 }
614 }
615 }
616 }
617 else
618 {
619 //
620 // Nothing else is in the list, we have to restore everything to default
621 // as the current event is the only event in the list
622 //
623
624 //
625 // Broadcast to reset i/o bitmap on all cores
626 //
627 if (InputFromVmxRoot)
628 {
630 }
631 else
632 {
634 }
635 }
636}

◆ TerminatePmcEvent()

VOID TerminatePmcEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for RDPMC Instruction events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
874{
875 PLIST_ENTRY TempList = 0;
876 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
877
878 if (DebuggerEventListCount(&g_Events->PmcInstructionExecutionEventsHead) > 1)
879 {
880 //
881 // There are still other events in the queue (list), we should only remove
882 // this special event (not all events)
883 //
884
885 //
886 // For this purpose, first we disable all the events by
887 // disabling all of them
888 //
889 if (InputFromVmxRoot)
890 {
892 }
893 else
894 {
896 }
897
898 //
899 // Then we iterate through the list of this event to re-apply
900 // the previous events
901 //
902 TempList = &g_Events->PmcInstructionExecutionEventsHead;
903
904 while (&g_Events->PmcInstructionExecutionEventsHead != TempList->Flink)
905 {
906 TempList = TempList->Flink;
907 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
908
909 //
910 // We have to check because we don't want to re-apply
911 // the terminated event
912 //
913 if (CurrentEvent->Tag != Event->Tag)
914 {
915 //
916 // re-apply the event
917 //
918 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
919
920 if (!ResultsToReturn.IsSuccessful)
921 {
922 LogInfo("Err, unable to re-apply previous events");
923 }
924 }
925 }
926 }
927 else
928 {
929 //
930 // Nothing else is in the list, we have to restore everything to default
931 // as the current event is the only event in the list
932 //
933
934 //
935 // Disable it on all the cores
936 //
937 if (InputFromVmxRoot)
938 {
940 }
941 else
942 {
944 }
945 }
946}
VOID ExtensionCommandDisableRdpmcExitingAllCores()
routines for disabling !pmc
Definition ExtensionCommands.c:525
VOID HaltedBroadcastDisableRdpmcExitingAllCores()
This function broadcasts disable rdpmc exiting in primary cpu-based controls to all cores.
Definition HaltedBroadcast.c:615

◆ TerminateQueryDebuggerResource()

BOOLEAN TerminateQueryDebuggerResource ( UINT32 CoreId,
PROTECTED_HV_RESOURCES_TYPE ResourceType,
PVOID Context,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Termination query state of debugger.

Parameters
CoreIdCore specific resource
ResourceTypeType of resource
ContextThe context specified to the resource
PassOverThe pass over option
Returns
BOOLEAN If TRUE the caller might terminate the operation
1760{
1761 BOOLEAN Result = FALSE;
1762
1763 switch (ResourceType)
1764 {
1766
1767 Result = TerminateQueryDebuggerResourceExceptionBitmap(CoreId, (UINT32 *)Context, PassOver);
1768
1769 break;
1770
1772
1774
1775 break;
1776
1778
1779 Result = TerminateQueryDebuggerResourceTscExiting(CoreId, PassOver);
1780
1781 break;
1782
1784
1785 Result = TerminateQueryDebuggerResourceMov2DebugRegExiting(CoreId, PassOver);
1786
1787 break;
1788
1790
1791 Result = TerminateQueryDebuggerResourceMovControlRegsExiting(CoreId, PassOver);
1792
1793 break;
1794
1796
1797 Result = TerminateQueryDebuggerResourceMovToCr3Exiting(CoreId, PassOver);
1798
1799 break;
1800
1802
1804
1805 break;
1806
1807 default:
1808
1809 Result = FALSE;
1810
1811 LogError("Err, invalid protected type");
1812
1813 break;
1814 }
1815
1816 //
1817 // Check termination result
1818 //
1819 return Result;
1820}
BOOLEAN TerminateQueryDebuggerResourceMovToCr3Exiting(UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Check and modify state of move to cr3 control register exiting.
Definition Termination.c:1560
BOOLEAN TerminateQueryDebuggerResourceExceptionBitmap(UINT32 CoreId, UINT32 *BitmapMask, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Check and modify state of exception bitmap.
Definition Termination.c:1308
BOOLEAN TerminateQueryDebuggerResourceMov2DebugRegExiting(UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Check and modify state of mov 2 debug regs exiting.
Definition Termination.c:1471
BOOLEAN TerminateQueryDebuggerResourceSaveAndLoadDebugControls(UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Check and modify state of save and load debug controls (DR7 and IA32_DEBUGCTLS) on exit and entry VM ...
Definition Termination.c:1593
BOOLEAN TerminateQueryDebuggerResourceExternalInterruptExiting(UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Check and modify state of external interrupt exiting.
Definition Termination.c:1381
BOOLEAN TerminateQueryDebuggerResourceMovControlRegsExiting(UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Check and modify state of move to control register exiting.
Definition Termination.c:1522
BOOLEAN TerminateQueryDebuggerResourceTscExiting(UINT32 CoreId, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Check and modify state of TSC exiting.
Definition Termination.c:1433
unsigned int UINT32
Definition BasicTypes.h:54
@ PROTECTED_HV_RESOURCES_MOV_CONTROL_REGISTER_EXITING
Definition Events.h:339
@ PROTECTED_HV_RESOURCES_EXCEPTION_BITMAP
Definition Events.h:331
@ PROTECTED_HV_RESOURCES_MOV_TO_DEBUG_REGISTER_EXITING
Definition Events.h:337
@ PROTECTED_HV_RESOURCES_MOV_TO_CR3_EXITING
Definition Events.h:341
@ PROTECTED_HV_RESOURCES_RDTSC_RDTSCP_EXITING
Definition Events.h:335
@ PROTECTED_HV_RESOURCES_SAVE_AND_LOAD_DEBUG_CONTROLS
Definition Events.h:343
@ PROTECTED_HV_RESOURCES_EXTERNAL_INTERRUPT_EXITING
Definition Events.h:333
#define LogError(format,...)
Log in the case of error.
Definition HyperDbgHyperLogIntrinsics.h:113

◆ TerminateQueryDebuggerResourceExceptionBitmap()

BOOLEAN TerminateQueryDebuggerResourceExceptionBitmap ( UINT32 CoreId,
UINT32 * BitmapMask,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Check and modify state of exception bitmap.

Parameters
CoreIdCore specific resource
BitmapMaskThe current bitmask of the resource
PassOverThe pass over option
Returns
BOOLEAN
1311{
1312 //
1313 // Check if the integrity check is because of clearing
1314 // events or not, if it's for clearing events, the debugger
1315 // will automatically set
1316 //
1317 if (!(PassOver & PASSING_OVER_EXCEPTION_EVENTS))
1318 {
1319 //
1320 // we have to check for !exception events and apply the mask
1321 //
1322 *BitmapMask = *BitmapMask | DebuggerExceptionEventBitmapMask(CoreId);
1323 }
1324
1325 //
1326 // Check if it's because of disabling !syscall or !sysret commands
1327 // or not, if it's because of clearing #UD in these events then we
1328 // can ignore the checking for this command, otherwise, we have to
1329 // check it
1330 //
1332 {
1333 //
1334 // Check if the debugger has events relating to syscall or sysret,
1335 // if no, we can safely ignore #UDs, otherwise, #UDs should be
1336 // activated
1337 //
1340 {
1341 //
1342 // #UDs should be activated
1343 //
1344 *BitmapMask = *BitmapMask | (1 << EXCEPTION_VECTOR_UNDEFINED_OPCODE);
1345 }
1346 }
1347
1348 //
1349 // Check for kernel or user debugger's presence
1350 //
1352 {
1353 *BitmapMask = *BitmapMask | (1 << EXCEPTION_VECTOR_BREAKPOINT);
1354 *BitmapMask = *BitmapMask | (1 << EXCEPTION_VECTOR_DEBUG_BREAKPOINT);
1355 }
1356
1357 //
1358 // Check for intercepting #DB by threads tracer
1359 //
1362 {
1363 *BitmapMask = *BitmapMask | (1 << EXCEPTION_VECTOR_DEBUG_BREAKPOINT);
1364 }
1365
1366 //
1367 // Do not terminate the operation
1368 //
1369 return FALSE;
1370}
UINT32 DebuggerEventListCountByEventType(VMM_EVENT_TYPE_ENUM EventType, UINT32 TargetCore)
Count the list of events by a special event type that are activate on a target core.
Definition Debugger.c:2266
BOOLEAN DebuggerQueryDebuggerStatus()
Detect whether the user or kernel debugger is active or not.
Definition Debugger.c:2532
UINT32 DebuggerExceptionEventBitmapMask(UINT32 CoreIndex)
Get the mask related to the !exception command for the target core.
Definition Debugger.c:2304
BOOLEAN KdQueryDebuggerQueryThreadOrProcessTracingDetailsByCoreId(UINT32 CoreId, DEBUGGER_THREAD_PROCESS_TRACING TracingType)
Query for process/thread interception status.
Definition Kd.c:206
@ DEBUGGER_THREAD_PROCESS_TRACING_INTERCEPT_CLOCK_DEBUG_REGISTER_INTERCEPTION
Definition DataTypes.h:141
@ SYSCALL_HOOK_EFER_SYSCALL
Definition Events.h:117
@ SYSCALL_HOOK_EFER_SYSRET
Definition Events.h:118
@ PASSING_OVER_UD_EXCEPTIONS_FOR_SYSCALL_SYSRET_HOOK
Definition Events.h:300
@ PASSING_OVER_EXCEPTION_EVENTS
Definition Events.h:301
@ EXCEPTION_VECTOR_UNDEFINED_OPCODE
Definition Events.h:30
@ EXCEPTION_VECTOR_DEBUG_BREAKPOINT
Definition Events.h:25

◆ TerminateQueryDebuggerResourceExternalInterruptExiting()

BOOLEAN TerminateQueryDebuggerResourceExternalInterruptExiting ( UINT32 CoreId,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Check and modify state of external interrupt exiting.

Parameters
CoreIdCore specific resource
PassOverThe pass over option
Returns
BOOLEAN
1383{
1384 //
1385 // Check if the integrity check is because of clearing
1386 // events or not, if it's for clearing events, the debugger
1387 // will automatically set
1388 //
1389 if (!(PassOver & PASSING_OVER_INTERRUPT_EVENTS))
1390 {
1391 //
1392 // we have to check for !interrupt events and decide whether to
1393 // ignore this event or not
1394 //
1396 {
1397 //
1398 // We should ignore this unset, because !interrupt is enabled for this core
1399 //
1400 return TRUE;
1401 }
1402 }
1403
1404 //
1405 // Check if it should remain active for thread or process changing or not
1406 //
1411 {
1412 //
1413 // Terminate the operation
1414 //
1415 return TRUE;
1416 }
1417
1418 //
1419 // Not terminate it
1420 //
1421 return FALSE;
1422}
@ DEBUGGER_THREAD_PROCESS_TRACING_INTERCEPT_CLOCK_INTERRUPTS_FOR_THREAD_CHANGE
Definition DataTypes.h:139
@ DEBUGGER_THREAD_PROCESS_TRACING_INTERCEPT_CLOCK_INTERRUPTS_FOR_PROCESS_CHANGE
Definition DataTypes.h:140
@ EXTERNAL_INTERRUPT_OCCURRED
Definition Events.h:141
@ PASSING_OVER_INTERRUPT_EVENTS
Definition Events.h:306

◆ TerminateQueryDebuggerResourceMov2DebugRegExiting()

BOOLEAN TerminateQueryDebuggerResourceMov2DebugRegExiting ( UINT32 CoreId,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Check and modify state of mov 2 debug regs exiting.

Parameters
CoreIdCore specific resource
PassOverThe pass over option
Returns
BOOLEAN
1473{
1474 //
1475 // Check if the integrity check is because of clearing
1476 // events or not, if it's for clearing events, the debugger
1477 // will automatically set
1478 //
1480 {
1481 //
1482 // we have to check for !dr events and decide whether to
1483 // ignore this event or not
1484 //
1486 {
1487 //
1488 // We should ignore this unset, because !dr is enabled for this core
1489 //
1490
1491 return TRUE;
1492 }
1493 }
1494
1495 //
1496 // Check if thread switching is enabled or not
1497 //
1500 {
1501 //
1502 // We should ignore it as we want this to switch to new thread
1503 //
1504 return TRUE;
1505 }
1506
1507 //
1508 // Not terminate
1509 //
1510 return FALSE;
1511}
@ DEBUG_REGISTERS_ACCESSED
Definition Events.h:146
@ PASSING_OVER_MOV_TO_HW_DEBUG_REGS_EVENTS
Definition Events.h:316

◆ TerminateQueryDebuggerResourceMovControlRegsExiting()

BOOLEAN TerminateQueryDebuggerResourceMovControlRegsExiting ( UINT32 CoreId,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Check and modify state of move to control register exiting.

Parameters
CoreIdCore specific resource
PassOverThe pass over option
Returns
BOOLEAN
1524{
1525 //
1526 // Check if the integrity check is because of clearing
1527 // events or not, if it's for clearing events, the debugger
1528 // will automatically set
1529 //
1531 {
1532 //
1533 // we have to check for !dr events and decide whether to
1534 // ignore this event or not
1535 //
1537 {
1538 //
1539 // We should ignore this unset, because !crwrite is enabled for this core
1540 //
1541 return TRUE;
1542 }
1543 }
1544
1545 //
1546 // Not terminate
1547 //
1548 return FALSE;
1549}
@ CONTROL_REGISTER_MODIFIED
Definition Events.h:162
@ PASSING_OVER_MOV_TO_CONTROL_REGS_EVENTS
Definition Events.h:321

◆ TerminateQueryDebuggerResourceMovToCr3Exiting()

BOOLEAN TerminateQueryDebuggerResourceMovToCr3Exiting ( UINT32 CoreId,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Check and modify state of move to cr3 control register exiting.

Parameters
CoreIdCore specific resource
PassOverThe pass over option
Returns
BOOLEAN
1562{
1563 UNREFERENCED_PARAMETER(PassOver);
1564
1565 //
1566 // Check if process switching is enabled or not
1567 //
1570 {
1571 //
1572 // We should ignore it as we want this to switch to new process
1573 //
1574 return TRUE;
1575 }
1576
1577 //
1578 // Do not terminate
1579 //
1580 return FALSE;
1581}
@ DEBUGGER_THREAD_PROCESS_TRACING_INTERCEPT_CLOCK_WAITING_FOR_MOV_CR3_VM_EXITS
Definition DataTypes.h:142

◆ TerminateQueryDebuggerResourceSaveAndLoadDebugControls()

BOOLEAN TerminateQueryDebuggerResourceSaveAndLoadDebugControls ( UINT32 CoreId,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Check and modify state of save and load debug controls (DR7 and IA32_DEBUGCTLS) on exit and entry VM controls.

Parameters
CoreIdCore specific resource
PassOverThe pass over option
Returns
BOOLEAN
1595{
1596 UNREFERENCED_PARAMETER(PassOver);
1597
1598 //
1599 // Check if debug register load and save on entry and exit controls are needed for thread interception
1600 //
1602 {
1603 //
1604 // We should ignore it as we want this to interception of thread to work
1605 //
1606 return TRUE;
1607 }
1608
1609 //
1610 // Query the hypertrace project about this controls since there might be using this load and save controls
1611 //
1613 {
1614 //
1615 // We should ignore it since LBR feature of hypertrace is still using it
1616 //
1617 return TRUE;
1618 }
1619
1620 //
1621 // Do not terminate
1622 //
1623 return FALSE;
1624}
BOOLEAN ThreadQueryDebugRegisterInterceptionStateByCoreId(UINT32 CoreId)
Query for deubg register interception state.
Definition Thread.c:553
IMPORT_EXPORT_HYPERTRACE BOOLEAN HyperTraceLbrQueryStateOfLbrSaveAndLoadVmExitAndEntryControls(UINT32 CoreId)
Query the state of LBR save and load VM exit and entry controls.
Definition LbrApi.c:53

◆ TerminateQueryDebuggerResourceTscExiting()

BOOLEAN TerminateQueryDebuggerResourceTscExiting ( UINT32 CoreId,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Check and modify state of TSC exiting.

Parameters
CoreIdCore specific resource
PassOverThe pass over option
Returns
BOOLEAN
1435{
1436 //
1437 // Check if the integrity check is because of clearing
1438 // events or not, if it's for clearing events, the debugger
1439 // will automatically set
1440 //
1441 if (!(PassOver & PASSING_OVER_TSC_EVENTS))
1442 {
1443 //
1444 // we have to check for !tsc events and decide whether to
1445 // ignore this event or not
1446 //
1448 {
1449 //
1450 // We should ignore this unset, because !tsc is enabled for this core
1451 //
1452 return TRUE;
1453 }
1454 }
1455
1456 //
1457 // Not terminate it
1458 //
1459 return FALSE;
1460}
@ TSC_INSTRUCTION_EXECUTION
Definition Events.h:151
@ PASSING_OVER_TSC_EVENTS
Definition Events.h:311

◆ TerminateRdmsrExecutionEvent()

VOID TerminateRdmsrExecutionEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for msr read events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
214{
215 PLIST_ENTRY TempList = 0;
216 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
217
218 if (DebuggerEventListCount(&g_Events->RdmsrInstructionExecutionEventsHead) > 1)
219 {
220 //
221 // There are still other events in the queue (list), we should only remove
222 // this special event (not all events)
223 //
224
225 //
226 // For this purpose, first we disable all the events by
227 // disabling all of them
228 //
229 if (InputFromVmxRoot)
230 {
232 }
233 else
234 {
236 }
237
238 //
239 // Then we iterate through the list of this event to re-apply
240 // the previous events
241 //
242 TempList = &g_Events->RdmsrInstructionExecutionEventsHead;
243
244 while (&g_Events->RdmsrInstructionExecutionEventsHead != TempList->Flink)
245 {
246 TempList = TempList->Flink;
247 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
248
249 //
250 // We have to check because we don't want to re-apply
251 // the terminated event
252 //
253 if (CurrentEvent->Tag != Event->Tag)
254 {
255 //
256 // re-apply the event
257 //
258 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
259
260 if (!ResultsToReturn.IsSuccessful)
261 {
262 LogInfo("Err, unable to re-apply previous events");
263 }
264 }
265 }
266 }
267 else
268 {
269 //
270 // Nothing else is in the list, we have to restore everything to default
271 // as the current event is the only event in the list
272 //
273
274 //
275 // Broadcast to reset msr bitmap on all cores
276 //
277 if (InputFromVmxRoot)
278 {
280 }
281 else
282 {
284 }
285 }
286}
VOID ExtensionCommandResetChangeAllMsrBitmapReadAllCores()
routines for disable (reset) !msrread command
Definition ExtensionCommands.c:404
VOID HaltedBroadcastResetMsrBitmapReadAllCores()
This function broadcasts reset MSR Bitmap Read to all cores.
Definition HaltedBroadcast.c:477

◆ TerminateSyscallHookEferEvent()

VOID TerminateSyscallHookEferEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for SYSCALL Instruction events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
1126{
1127 PLIST_ENTRY TempList = 0;
1128 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
1129
1130 //
1131 // For this event we should also check for sysret instructions events too
1132 // because both of them are emulated by a single bit in vmx controls
1133 // and an MSR so if there is anything in out events list then we can
1134 // remove all the events
1135 //
1136 if (DebuggerEventListCount(&g_Events->SyscallHooksEferSyscallEventsHead) > 1 ||
1137 DebuggerEventListCount(&g_Events->SyscallHooksEferSysretEventsHead) >= 1)
1138 {
1139 //
1140 // There are still other events in the queue (list), we should only remove
1141 // this special event (not all events)
1142 //
1143
1144 //
1145 // For this purpose, first we disable all the events by
1146 // disabling all of them
1147 //
1148 if (InputFromVmxRoot)
1149 {
1151 }
1152 else
1153 {
1155 }
1156
1157 //
1158 // Then we iterate through the list of this event to re-apply
1159 // the previous events
1160 //
1161 TempList = &g_Events->SyscallHooksEferSyscallEventsHead;
1162
1163 while (&g_Events->SyscallHooksEferSyscallEventsHead != TempList->Flink)
1164 {
1165 TempList = TempList->Flink;
1166 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
1167
1168 //
1169 // We have to check because we don't want to re-apply
1170 // the terminated event
1171 //
1172 if (CurrentEvent->Tag != Event->Tag)
1173 {
1174 //
1175 // re-apply the event
1176 //
1177 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
1178
1179 if (!ResultsToReturn.IsSuccessful)
1180 {
1181 LogInfo("Err, unable to re-apply previous events");
1182 }
1183 }
1184 }
1185 }
1186 else
1187 {
1188 //
1189 // Nothing else is in the list, we have to restore everything to default
1190 // as the current event is the only event in the list
1191 //
1192
1193 //
1194 // Disable it on all cores
1195 //
1196 if (InputFromVmxRoot)
1197 {
1199 }
1200 else
1201 {
1203 }
1204 }
1205}
VOID DebuggerEventDisableEferOnAllProcessors()
routines for !syscall command (disable syscall hook)
Definition DebuggerEvents.c:31
VOID HaltedBroadcastDisableEferSyscallEventsAllCores()
This function broadcasts disable syscall hook using EFER SCE bit controls to all cores.
Definition HaltedBroadcast.c:643

◆ TerminateSysretHookEferEvent()

VOID TerminateSysretHookEferEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for SYSRET Instruction events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
1217{
1218 PLIST_ENTRY TempList = 0;
1219 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
1220
1221 //
1222 // For this event we should also check for syscall instructions events too
1223 // because both of them are emulated by a single bit in vmx controls
1224 // and an MSR so if there is anything in out events list then we can
1225 // remove all the events
1226 //
1227 if (DebuggerEventListCount(&g_Events->SyscallHooksEferSysretEventsHead) > 1 ||
1228 DebuggerEventListCount(&g_Events->SyscallHooksEferSyscallEventsHead) > 1)
1229 {
1230 //
1231 // There are still other events in the queue (list), we should only remove
1232 // this special event (not all events)
1233 //
1234
1235 //
1236 // For this purpose, first we disable all the events by
1237 // disabling all of them
1238 //
1239 if (InputFromVmxRoot)
1240 {
1242 }
1243 else
1244 {
1246 }
1247
1248 //
1249 // Then we iterate through the list of this event to re-apply
1250 // the previous events
1251 //
1252 TempList = &g_Events->SyscallHooksEferSysretEventsHead;
1253
1254 while (&g_Events->SyscallHooksEferSysretEventsHead != TempList->Flink)
1255 {
1256 TempList = TempList->Flink;
1257 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
1258
1259 //
1260 // We have to check because we don't want to re-apply
1261 // the terminated event
1262 //
1263 if (CurrentEvent->Tag != Event->Tag)
1264 {
1265 //
1266 // re-apply the event
1267 //
1268 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
1269
1270 if (!ResultsToReturn.IsSuccessful)
1271 {
1272 LogInfo("Err, unable to re-apply previous events");
1273 }
1274 }
1275 }
1276 }
1277 else
1278 {
1279 //
1280 // Nothing else is in the list, we have to restore everything to default
1281 // as the current event is the only event in the list
1282 //
1283
1284 //
1285 // Disable it on all cores
1286 //
1287 if (InputFromVmxRoot)
1288 {
1290 }
1291 else
1292 {
1294 }
1295 }
1296}

◆ TerminateTscEvent()

VOID TerminateTscEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for RDTSC/RDTSCP Instruction events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
790{
791 PLIST_ENTRY TempList = 0;
792 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
793
794 if (DebuggerEventListCount(&g_Events->TscInstructionExecutionEventsHead) > 1)
795 {
796 //
797 // There are still other events in the queue (list), we should only remove
798 // this special event (not all events)
799 //
800
801 //
802 // For this purpose, first we disable all the events by
803 // disabling all of them
804 //
805 if (InputFromVmxRoot)
806 {
808 }
809 else
810 {
812 }
813
814 //
815 // Then we iterate through the list of this event to re-apply
816 // the previous events
817 //
818 TempList = &g_Events->TscInstructionExecutionEventsHead;
819
820 while (&g_Events->TscInstructionExecutionEventsHead != TempList->Flink)
821 {
822 TempList = TempList->Flink;
823 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
824
825 //
826 // We have to check because we don't want to re-apply
827 // the terminated event
828 //
829 if (CurrentEvent->Tag != Event->Tag)
830 {
831 //
832 // re-apply the event
833 //
834 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
835
836 if (!ResultsToReturn.IsSuccessful)
837 {
838 LogInfo("Err, unable to re-apply previous events");
839 }
840 }
841 }
842 }
843 else
844 {
845 //
846 // Nothing else is in the list, we have to restore everything to default
847 // as the current event is the only event in the list
848 //
849
850 //
851 // Disable it on all cores
852 //
853 if (InputFromVmxRoot)
854 {
856 }
857 else
858 {
860 }
861 }
862}
VOID ExtensionCommandDisableRdtscExitingForClearingEventsAllCores()
routines ONLY for disabling !tsc command
Definition ExtensionCommands.c:471
VOID HaltedBroadcastDisableRdtscExitingForClearingTscEventsAllCores()
This function broadcasts clear rdtsc exiting bit ONLY in the case of disabling the events for !...
Definition HaltedBroadcast.c:587

◆ TerminateVmcallExecutionEvent()

VOID TerminateVmcallExecutionEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for VMCALL Instruction events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
648{
649 UNREFERENCED_PARAMETER(Event);
650 UNREFERENCED_PARAMETER(InputFromVmxRoot);
651
652 if (DebuggerEventListCount(&g_Events->VmcallInstructionExecutionEventsHead) > 1)
653 {
654 //
655 // There are still other events in the queue (list), we should only remove
656 // this special event (not all events)
657 //
658
659 //
660 // Nothing we can do for this event type, let it work because of other events
661 //
662 return;
663 }
664 else
665 {
666 //
667 // Nothing else is in the list, we have to restore everything to default
668 // as the current event is the only event in the list
669 //
670
671 //
672 // We set the global variable related to the vmcall to FALSE
673 // so the vm-exit handler, no longer triggers events related
674 // to the vmcalls (still they cause vm-exits as vmcall is an
675 // unconditional instruction for vm-exit)
676 //
678 }
679}
IMPORT_EXPORT_VMM VOID VmFuncSetTriggerEventForVmcalls(BOOLEAN Set)
Set triggering events for VMCALLs.
Definition Export.c:825

◆ TerminateWrmsrExecutionEvent()

VOID TerminateWrmsrExecutionEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for msr write events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
298{
299 PLIST_ENTRY TempList = 0;
300 DEBUGGER_EVENT_AND_ACTION_RESULT ResultsToReturn = {0};
301
302 if (DebuggerEventListCount(&g_Events->WrmsrInstructionExecutionEventsHead) > 1)
303 {
304 //
305 // There are still other events in the queue (list), we should only remove
306 // this special event (not all events)
307 //
308
309 //
310 // For this purpose, first we disable all the events by
311 // disabling all of them
312 //
313 if (InputFromVmxRoot)
314 {
316 }
317 else
318 {
320 }
321
322 //
323 // Then we iterate through the list of this event to re-apply
324 // the previous events
325 //
326 TempList = &g_Events->WrmsrInstructionExecutionEventsHead;
327
328 while (&g_Events->WrmsrInstructionExecutionEventsHead != TempList->Flink)
329 {
330 TempList = TempList->Flink;
331 PDEBUGGER_EVENT CurrentEvent = CONTAINING_RECORD(TempList, DEBUGGER_EVENT, EventsOfSameTypeList);
332
333 //
334 // We have to check because we don't want to re-apply
335 // the terminated event
336 //
337 if (CurrentEvent->Tag != Event->Tag)
338 {
339 //
340 // re-apply the event
341 //
342 DebuggerApplyEvent(CurrentEvent, &ResultsToReturn, InputFromVmxRoot);
343
344 if (!ResultsToReturn.IsSuccessful)
345 {
346 LogInfo("Err, unable to re-apply previous events");
347 }
348 }
349 }
350 }
351 else
352 {
353 //
354 // Nothing else is in the list, we have to restore everything to default
355 // as the current event is the only event in the list
356 //
357
358 //
359 // Broadcast to reset msr bitmap on all cores
360 //
361 if (InputFromVmxRoot)
362 {
364 }
365 else
366 {
368 }
369 }
370}
VOID ExtensionCommandResetAllMsrBitmapWriteAllCores()
routines for reset !msrwrite command which
Definition ExtensionCommands.c:431
VOID HaltedBroadcastResetMsrBitmapWriteAllCores()
This function broadcasts reset MSR Bitmap Write to all cores.
Definition HaltedBroadcast.c:504

◆ TerminateXsetbvExecutionEvent()

VOID TerminateXsetbvExecutionEvent ( PDEBUGGER_EVENT Event,
BOOLEAN InputFromVmxRoot )

Termination function for XSETBV Instruction events.

Parameters
EventTarget Event Object
InputFromVmxRootWhether the input comes from VMX root-mode or IOCTL
Returns
VOID
1832{
1833 UNREFERENCED_PARAMETER(Event);
1834 UNREFERENCED_PARAMETER(InputFromVmxRoot);
1835
1836 if (DebuggerEventListCount(&g_Events->XsetbvInstructionExecutionEventsHead) > 1)
1837 {
1838 //
1839 // There are still other events in the queue (list), we should only remove
1840 // this special event (not all events)
1841 //
1842
1843 //
1844 // Nothing we can do for this event type, let it work because of other events
1845 //
1846 return;
1847 }
1848 else
1849 {
1850 //
1851 // Nothing else is in the list, we have to restore everything to default
1852 // as the current event is the only event in the list
1853 //
1854
1855 //
1856 // We set the global variable related to the xsetbv to FALSE
1857 // so the vm-exit handler, no longer triggers events related
1858 // to the xsetbvs (still they cause vm-exits as xsetbv is an
1859 // unconditional instruction for vm-exit)
1860 //
1862 }
1863}
IMPORT_EXPORT_VMM VOID VmFuncSetTriggerEventForXsetbvs(BOOLEAN Set)
Set trigger event for XSETBVs.
Definition Export.c:849