mirror of
https://github.com/HyperDbg/HyperDbg.git
synced 2026-08-31 10:07:02 +00:00
122 lines
3.6 KiB
C++
122 lines
3.6 KiB
C++
/**
|
|
* @file cpuid.cpp
|
|
* @author Sina Karvandi (sina@hyperdbg.org)
|
|
* @brief !cpuid commands
|
|
* @details
|
|
* @version 0.1
|
|
* @date 2020-05-30
|
|
*
|
|
* @copyright This project is released under the GNU Public License v3.
|
|
*
|
|
*/
|
|
#include "pch.h"
|
|
|
|
/**
|
|
* @brief help of !cpuid command
|
|
*
|
|
* @return VOID
|
|
*/
|
|
VOID
|
|
CommandCpuidHelp()
|
|
{
|
|
ShowMessages("!cpuid : monitors execution of a special cpuid index or all "
|
|
"cpuids instructions.\n\n");
|
|
|
|
ShowMessages("syntax : \t!cpuid [pid ProcessId (hex)] [core CoreId (hex)] "
|
|
"[imm IsImmediate (yesno)] [buffer PreAllocatedBuffer (hex)] "
|
|
"[script { Script (string) }] [condition { Condition (hex) }] "
|
|
"[code { Code (hex) }]\n");
|
|
|
|
ShowMessages("\n");
|
|
ShowMessages("\t\te.g : !cpuid\n");
|
|
ShowMessages("\t\te.g : !cpuid pid 400\n");
|
|
ShowMessages("\t\te.g : !cpuid core 2 pid 400\n");
|
|
}
|
|
|
|
/**
|
|
* @brief !cpuid command handler
|
|
*
|
|
* @param SplittedCommand
|
|
* @param Command
|
|
* @return VOID
|
|
*/
|
|
VOID
|
|
CommandCpuid(vector<string> SplittedCommand, 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> SplittedCommandCaseSensitive {Split(Command, ' ')};
|
|
DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
|
|
|
|
//
|
|
// Interpret and fill the general event and action fields
|
|
//
|
|
//
|
|
if (!InterpretGeneralEventAndActionsFields(
|
|
&SplittedCommand,
|
|
&SplittedCommandCaseSensitive,
|
|
CPUID_INSTRUCTION_EXECUTION,
|
|
&Event,
|
|
&EventLength,
|
|
&ActionBreakToDebugger,
|
|
&ActionBreakToDebuggerLength,
|
|
&ActionCustomCode,
|
|
&ActionCustomCodeLength,
|
|
&ActionScript,
|
|
&ActionScriptLength,
|
|
&EventParsingErrorCause))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Check for size
|
|
//
|
|
if (SplittedCommand.size() > 1)
|
|
{
|
|
ShowMessages("incorrect use of '!cpuid'\n");
|
|
CommandCpuidHelp();
|
|
|
|
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;
|
|
}
|
|
}
|