mirror of
https://github.com/HyperDbg/HyperDbg.git
synced 2026-08-22 15:05:38 +00:00
122 lines
3.6 KiB
C++
122 lines
3.6 KiB
C++
/**
|
|
* @file dr.cpp
|
|
* @author Sina Karvandi (sina@hyperdbg.org)
|
|
* @brief !dr commands
|
|
* @details
|
|
* @version 0.1
|
|
* @date 2020-06-11
|
|
*
|
|
* @copyright This project is released under the GNU Public License v3.
|
|
*
|
|
*/
|
|
#include "pch.h"
|
|
|
|
/**
|
|
* @brief help of the !dr command
|
|
*
|
|
* @return VOID
|
|
*/
|
|
VOID
|
|
CommandDrHelp()
|
|
{
|
|
ShowMessages("!dr : monitors any access to debug registers.\n\n");
|
|
|
|
ShowMessages("syntax : \t!dr [pid ProcessId (hex)] [core CoreId (hex)] "
|
|
"[imm IsImmediate (yesno)] [sc EnableShortCircuiting (onoff)] [stage CallingStage (prepostall)] "
|
|
"[buffer PreAllocatedBuffer (hex)] [script { Script (string) }] [condition { Condition (hex) }] "
|
|
"[code { Code (hex) }] [output {OutputName (string)}]\n");
|
|
|
|
ShowMessages("\n");
|
|
ShowMessages("\t\te.g : !dr\n");
|
|
ShowMessages("\t\te.g : !dr pid 400\n");
|
|
ShowMessages("\t\te.g : !dr core 2 pid 400\n");
|
|
}
|
|
|
|
/**
|
|
* @brief !dr command handler
|
|
*
|
|
* @param SplitCommand
|
|
* @param Command
|
|
* @return VOID
|
|
*/
|
|
VOID
|
|
CommandDr(vector<string> SplitCommand, string Command)
|
|
{
|
|
PDEBUGGER_GENERAL_EVENT_DETAIL Event = NULL;
|
|
PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger = NULL;
|
|
PDEBUGGER_GENERAL_ACTION ActionCustomCode = NULL;
|
|
PDEBUGGER_GENERAL_ACTION ActionScript = NULL;
|
|
UINT32 EventLength;
|
|
UINT32 ActionBreakToDebuggerLength = 0;
|
|
UINT32 ActionCustomCodeLength = 0;
|
|
UINT32 ActionScriptLength = 0;
|
|
vector<string> SplitCommandCaseSensitive {Split(Command, ' ')};
|
|
DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
|
|
|
|
//
|
|
// Interpret and fill the general event and action fields
|
|
//
|
|
//
|
|
if (!InterpretGeneralEventAndActionsFields(
|
|
&SplitCommand,
|
|
&SplitCommandCaseSensitive,
|
|
DEBUG_REGISTERS_ACCESSED,
|
|
&Event,
|
|
&EventLength,
|
|
&ActionBreakToDebugger,
|
|
&ActionBreakToDebuggerLength,
|
|
&ActionCustomCode,
|
|
&ActionCustomCodeLength,
|
|
&ActionScript,
|
|
&ActionScriptLength,
|
|
&EventParsingErrorCause))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Check for size
|
|
//
|
|
if (SplitCommand.size() > 1)
|
|
{
|
|
ShowMessages("incorrect use of the '!dr'\n");
|
|
CommandDrHelp();
|
|
|
|
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Send the ioctl to the kernel for event registration
|
|
//
|
|
if (!SendEventToKernel(Event, EventLength))
|
|
{
|
|
//
|
|
// There was an error, probably the handle was not initialized
|
|
// we have to free the Action before exit, it is because, we
|
|
// already freed the Event and string buffers
|
|
//
|
|
|
|
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Add the event to the kernel
|
|
//
|
|
if (!RegisterActionToEvent(Event,
|
|
ActionBreakToDebugger,
|
|
ActionBreakToDebuggerLength,
|
|
ActionCustomCode,
|
|
ActionCustomCodeLength,
|
|
ActionScript,
|
|
ActionScriptLength))
|
|
{
|
|
//
|
|
// There was an error
|
|
//
|
|
|
|
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
|
|
return;
|
|
}
|
|
}
|