HyperDbg/hyperdbg/libhyperdbg/code/debugger/commands/extension-commands/vmcall.cpp

125 lines
3.8 KiB
C++
Raw Permalink Normal View History

2020-07-03 04:50:48 -07:00
/**
* @file vmcall.cpp
2022-01-18 22:38:56 +03:30
* @author Sina Karvandi (sina@hyperdbg.org)
2020-07-03 04:50:48 -07:00
* @brief !vmcall command
* @details
* @version 0.1
* @date 2020-07-03
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
2020-07-03 04:50:48 -07:00
2020-08-28 04:03:12 -07:00
/**
2023-07-13 16:05:42 +09:00
* @brief help of the !vmcall command
*
* @return VOID
2020-08-28 04:03:12 -07:00
*/
2021-03-22 18:19:39 +04:30
VOID
CommandVmcallHelp()
{
2022-04-10 22:24:56 +04:30
ShowMessages("!vmcall : monitors execution of VMCALL instruction.\n\n");
2023-10-11 15:03:51 +09:00
ShowMessages("syntax : \t!vmcall [pid ProcessId (hex)] [core CoreId (hex)] [imm IsImmediate (yesno)] "
"[sc EnableShortCircuiting (onoff)] [stage CallingStage (prepostall)] [buffer PreAllocatedBuffer (hex)] "
2024-07-19 17:03:43 +09:00
"[script { Script (string) }] [asm condition { Condition (assembly/hex) }] [asm code { Code (assembly/hex) }] "
2023-10-11 15:03:51 +09:00
"[output {OutputName (string)}]\n");
2020-07-03 04:50:48 -07:00
ShowMessages("\n");
2021-03-22 18:19:39 +04:30
ShowMessages("\t\te.g : !vmcall\n");
ShowMessages("\t\te.g : !vmcall pid 400\n");
ShowMessages("\t\te.g : !vmcall core 2 pid 400\n");
2024-07-20 22:05:39 +09:00
ShowMessages("\t\te.g : !vmcall script { printf(\"VMCALL executed with context: %%llx\\n\", $context); }\n");
ShowMessages("\t\te.g : !vmcall asm code { nop; nop; nop }\n");
2020-07-03 04:50:48 -07:00
}
2020-08-28 04:03:12 -07:00
/**
* @brief !vmcall command handler
*
2024-07-30 18:44:15 +09:00
* @param CommandTokens
* @param Command
2024-07-30 18:44:15 +09:00
*
* @return VOID
2020-08-28 04:03:12 -07:00
*/
2021-03-22 18:19:39 +04:30
VOID
CommandVmcall(vector<CommandToken> CommandTokens, string Command)
2021-03-22 18:19:39 +04:30
{
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;
DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
2020-08-28 04:03:12 -07:00
//
2021-03-22 18:19:39 +04:30
// Interpret and fill the general event and action fields
//
2020-08-28 04:03:12 -07:00
//
2021-03-22 18:19:39 +04:30
if (!InterpretGeneralEventAndActionsFields(
2024-07-30 18:44:15 +09:00
&CommandTokens,
2021-03-22 18:19:39 +04:30
VMCALL_INSTRUCTION_EXECUTION,
&Event,
&EventLength,
&ActionBreakToDebugger,
&ActionBreakToDebuggerLength,
&ActionCustomCode,
&ActionCustomCodeLength,
&ActionScript,
&ActionScriptLength,
&EventParsingErrorCause))
2021-03-22 18:19:39 +04:30
{
return;
}
2021-03-22 18:19:39 +04:30
//
// Check for size
//
2024-07-30 18:44:15 +09:00
if (CommandTokens.size() > 1)
2021-03-22 18:19:39 +04:30
{
2024-07-30 18:44:15 +09:00
ShowMessages("incorrect use of the '%s'\n\n",
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
2021-03-22 18:19:39 +04:30
CommandVmcallHelp();
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
2021-03-22 18:19:39 +04:30
return;
}
2021-03-22 18:19:39 +04:30
//
2022-05-08 22:13:44 +04:30
// Send the ioctl to the kernel for event registration
2021-03-22 18:19:39 +04:30
//
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
//
2022-05-08 22:13:44 +04:30
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
2021-03-22 18:19:39 +04:30
return;
}
2020-07-03 04:50:48 -07:00
2020-08-28 04:03:12 -07:00
//
2021-03-22 18:19:39 +04:30
// Add the event to the kernel
2020-08-28 04:03:12 -07:00
//
if (!RegisterActionToEvent(Event,
ActionBreakToDebugger,
2022-03-13 01:33:21 +03:30
ActionBreakToDebuggerLength,
ActionCustomCode,
ActionCustomCodeLength,
ActionScript,
ActionScriptLength))
2021-03-22 18:19:39 +04:30
{
//
// There was an error
//
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
2021-03-22 18:19:39 +04:30
return;
}
2020-07-03 04:50:48 -07:00
}