HyperDbg/hyperdbg/hyperkd/code/debugger/events/DebuggerEvents.c

143 lines
3.5 KiB
C
Raw Permalink Normal View History

2020-05-12 13:12:21 -07:00
/**
* @file DebuggerEvents.c
2022-01-18 22:38:56 +03:30
* @author Sina Karvandi (sina@hyperdbg.org)
2020-05-12 13:12:21 -07:00
* @brief Implementation of Debugger events (triggers and enable events)
*
2020-05-12 13:12:21 -07:00
* @version 0.1
* @date 2020-05-12
*
2020-05-12 13:12:21 -07:00
* @copyright This project is released under the GNU Public License v3.
*
2020-05-12 13:12:21 -07:00
*/
#include "pch.h"
2020-05-12 13:12:21 -07:00
/**
2020-08-28 04:03:12 -07:00
* @brief routines for !syscall command (enable syscall hook)
*
* @return VOID
2020-05-12 13:12:21 -07:00
*/
VOID
DebuggerEventEnableEferOnAllProcessors()
2020-05-12 13:12:21 -07:00
{
ConfigureEnableEferSyscallEventsOnAllProcessors();
2020-05-12 13:12:21 -07:00
}
/**
2020-08-28 04:03:12 -07:00
* @brief routines for !syscall command (disable syscall hook)
*
* @return VOID
2020-05-12 13:12:21 -07:00
*/
VOID
DebuggerEventDisableEferOnAllProcessors()
{
ConfigureDisableEferSyscallEventsOnAllProcessors();
2020-05-12 13:12:21 -07:00
}
2020-08-30 03:11:13 -07:00
/**
* @brief routines for debugging threads (enable mov-to-cr3 exiting)
*
* @return VOID
2020-08-30 03:11:13 -07:00
*/
VOID
DebuggerEventEnableMovToCr3ExitingOnAllProcessors()
{
ConfigureEnableMovToCr3ExitingOnAllProcessors();
2020-08-30 03:11:13 -07:00
}
/**
* @brief routines for debugging threads (disable mov-to-cr3 exiting)
*
* @return VOID
2020-08-30 03:11:13 -07:00
*/
VOID
DebuggerEventDisableMovToCr3ExitingOnAllProcessors()
{
ConfigureDisableMovToCr3ExitingOnAllProcessors();
2020-08-30 03:11:13 -07:00
}
2020-05-12 15:43:34 -07:00
/**
* @brief Apply monitor ept hook events for address
*
* @param HookingDetails
2023-07-07 01:21:07 +09:00
* @param ProcessId
* @param ApplyDirectlyFromVmxRoot
2023-07-07 01:21:07 +09:00
*
* @return VOID
2020-05-12 15:43:34 -07:00
*/
BOOLEAN
DebuggerEventEnableMonitorReadWriteExec(EPT_HOOKS_ADDRESS_DETAILS_FOR_MEMORY_MONITOR * HookingDetails,
UINT32 ProcessId,
BOOLEAN ApplyDirectlyFromVmxRoot)
2020-05-12 15:43:34 -07:00
{
//
// Check if the detail is ok for either read or write or both
//
if (!HookingDetails->SetHookForRead && !HookingDetails->SetHookForWrite && !HookingDetails->SetHookForExec)
2020-05-12 15:43:34 -07:00
{
return FALSE;
}
2020-05-13 05:35:04 -07:00
//
// If the read is FALSE and WRITE is TRUE, then the processor doesn't support
// such a thing, we will enable the Read silently here if, this problem will be
2020-05-13 05:35:04 -07:00
// solved when the trigger works, the trigger routines won't enable reads
//
if (HookingDetails->SetHookForWrite)
2020-05-13 05:35:04 -07:00
{
HookingDetails->SetHookForRead = TRUE;
2020-05-13 05:35:04 -07:00
}
2020-05-12 15:43:34 -07:00
//
// Perform the EPT Hook
//
if (ApplyDirectlyFromVmxRoot)
{
return ConfigureEptHookMonitorFromVmxRoot(KeGetCurrentProcessorNumberEx(NULL),
HookingDetails);
}
else
{
return ConfigureEptHookMonitor(KeGetCurrentProcessorNumberEx(NULL),
HookingDetails,
ProcessId);
}
2020-05-12 15:43:34 -07:00
}
/**
* @brief Handle process or thread switches
*
* @param CoreId
*
* @return BOOLEAN
*/
BOOLEAN
DebuggerCheckProcessOrThreadChange(_In_ UINT32 CoreId)
{
PROCESSOR_DEBUGGING_STATE * DbgState = &g_DbgState[CoreId];
//
// Check whether intercepting this process or thread is active or not
//
if (DbgState->ThreadOrProcessTracingDetails.InterceptClockInterruptsForThreadChange ||
DbgState->ThreadOrProcessTracingDetails.InterceptClockInterruptsForProcessChange)
{
//
// We only handle interrupts that are related to the clock-timer interrupt
//
if (DbgState->ThreadOrProcessTracingDetails.InterceptClockInterruptsForThreadChange)
{
return ThreadHandleThreadChange(DbgState);
}
else
{
return ProcessHandleProcessChange(DbgState);
}
}
//
// Not handled here
//
return FALSE;
}