HyperDbg Debugger
Loading...
Searching...
No Matches
cpuid.cpp File Reference

!cpuid commands More...

#include "pch.h"

Functions

VOID CommandCpuidHelp ()
 help of the !cpuid command
VOID CommandCpuid (vector< CommandToken > CommandTokens, string Command)
 !cpuid command handler

Detailed Description

!cpuid commands

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

Function Documentation

◆ CommandCpuid()

VOID CommandCpuid ( vector< CommandToken > CommandTokens,
string Command )

!cpuid command handler

Parameters
CommandTokens
Command
Returns
VOID
49{
51 PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger = NULL;
52 PDEBUGGER_GENERAL_ACTION ActionCustomCode = NULL;
53 PDEBUGGER_GENERAL_ACTION ActionScript = NULL;
54 BOOLEAN GetEax = FALSE;
55 UINT32 EventLength;
56 UINT64 SpecialTarget = 0;
57 UINT32 ActionBreakToDebuggerLength = 0;
58 UINT32 ActionCustomCodeLength = 0;
59 UINT32 ActionScriptLength = 0;
60 DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
61
62 //
63 // Interpret and fill the general event and action fields
64 //
65 //
67 &CommandTokens,
69 &Event,
70 &EventLength,
71 &ActionBreakToDebugger,
72 &ActionBreakToDebuggerLength,
73 &ActionCustomCode,
74 &ActionCustomCodeLength,
75 &ActionScript,
76 &ActionScriptLength,
77 &EventParsingErrorCause))
78 {
79 return;
80 }
81
82 //
83 // Interpret command specific details (if any), of CPUID EAX index
84 //
85 for (auto Section : CommandTokens)
86 {
87 if (CompareLowerCaseStrings(Section, "!cpuid"))
88 {
89 continue;
90 }
91 else if (!GetEax)
92 {
93 //
94 // It's probably an index of EAX
95 //
96 if (!ConvertTokenToUInt64(Section, &SpecialTarget))
97 {
98 //
99 // Unknown parameter
100 //
101 ShowMessages("unknown parameter '%s'\n\n",
104
105 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
106 return;
107 }
108 else
109 {
110 //
111 // An special EAX is set
112 //
113 GetEax = TRUE;
114 }
115 }
116 else
117 {
118 //
119 // Unknown parameter
120 //
121 ShowMessages("unknown parameter '%s'\n\n",
123
125
126 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
127 return;
128 }
129 }
130
131 //
132 // Set the target EAX (if not specific then it means all msrs)
133 //
134 Event->Options.OptionalParam1 = GetEax;
135
136 if (GetEax)
137 {
138 Event->Options.OptionalParam2 = SpecialTarget;
139 }
140
141 //
142 // Send the ioctl to the kernel for event registration
143 //
144 if (!SendEventToKernel(Event, EventLength))
145 {
146 //
147 // There was an error, probably the handle was not initialized
148 // we have to free the Action before exit, it is because, we
149 // already freed the Event and string buffers
150 //
151
152 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
153 return;
154 }
155
156 //
157 // Add the event to the kernel
158 //
159 if (!RegisterActionToEvent(Event,
160 ActionBreakToDebugger,
161 ActionBreakToDebuggerLength,
162 ActionCustomCode,
163 ActionCustomCodeLength,
164 ActionScript,
165 ActionScriptLength))
166 {
167 //
168 // There was an error
169 //
170 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
171 return;
172 }
173}
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
unsigned int UINT32
Definition BasicTypes.h:54
@ CPUID_INSTRUCTION_EXECUTION
Definition Events.h:123
struct _DEBUGGER_GENERAL_EVENT_DETAIL * PDEBUGGER_GENERAL_EVENT_DETAIL
struct _DEBUGGER_GENERAL_ACTION * PDEBUGGER_GENERAL_ACTION
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
BOOLEAN CompareLowerCaseStrings(CommandToken TargetToken, const CHAR *StringToCompare)
Compare lower case strings.
Definition common.cpp:503
BOOLEAN ConvertTokenToUInt64(CommandToken TargetToken, PUINT64 Result)
add ` between 64 bit values and convert them to string
Definition common.cpp:447
VOID CommandCpuidHelp()
help of the !cpuid command
Definition cpuid.cpp:20
VOID FreeEventsAndActionsMemory(PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, PDEBUGGER_GENERAL_ACTION ActionCustomCode, PDEBUGGER_GENERAL_ACTION ActionScript)
Deallocate buffers relating to events and actions.
Definition debugger.cpp:1688
BOOLEAN InterpretGeneralEventAndActionsFields(vector< CommandToken > *CommandTokens, VMM_EVENT_TYPE_ENUM EventType, PDEBUGGER_GENERAL_EVENT_DETAIL *EventDetailsToFill, PUINT32 EventBufferLength, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillBreakToDebugger, PUINT32 ActionBufferLengthBreakToDebugger, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillCustomCode, PUINT32 ActionBufferLengthCustomCode, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillScript, PUINT32 ActionBufferLengthScript, PDEBUGGER_EVENT_PARSING_ERROR_CAUSE ReasonForErrorInParsing)
Interpret general event fields.
Definition debugger.cpp:1736
BOOLEAN SendEventToKernel(PDEBUGGER_GENERAL_EVENT_DETAIL Event, UINT32 EventBufferLength)
Register the event to the kernel.
Definition debugger.cpp:1367
BOOLEAN RegisterActionToEvent(PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, UINT32 ActionBreakToDebuggerLength, PDEBUGGER_GENERAL_ACTION ActionCustomCode, UINT32 ActionCustomCodeLength, PDEBUGGER_GENERAL_ACTION ActionScript, UINT32 ActionScriptLength)
Register the action to the event.
Definition debugger.cpp:1483
enum _DEBUGGER_EVENT_PARSING_ERROR_CAUSE DEBUGGER_EVENT_PARSING_ERROR_CAUSE
Reason for error in parsing commands.
NULL()
Definition test-case-generator.py:530
UINT64 OptionalParam2
Definition Events.h:278
UINT64 OptionalParam1
Definition Events.h:277
DEBUGGER_EVENT_OPTIONS Options
Definition Events.h:396

◆ CommandCpuidHelp()

VOID CommandCpuidHelp ( )

help of the !cpuid command

Returns
VOID
21{
22 ShowMessages("!cpuid : monitors execution of a special cpuid index or all "
23 "cpuids instructions.\n\n");
24
25 ShowMessages("syntax : \t!cpuid [Eax (hex)] [pid ProcessId (hex)] [core CoreId (hex)] "
26 "[imm IsImmediate (yesno)] [sc EnableShortCircuiting (onoff)] [stage CallingStage (prepostall)] "
27 "[buffer PreAllocatedBuffer (hex)] [script { Script (string) }] [asm condition { Condition (assembly/hex) }] "
28 "[asm code { Code (assembly/hex) }] [output {OutputName (string)}]\n");
29
30 ShowMessages("\n");
31 ShowMessages("\t\te.g : !cpuid\n");
32 ShowMessages("\t\te.g : !cpuid 1\n");
33 ShowMessages("\t\te.g : !cpuid pid 400\n");
34 ShowMessages("\t\te.g : !cpuid core 2 pid 400\n");
35 ShowMessages("\t\te.g : !cpuid script { printf(\"CPUID instruction is executed with the 'eax' register equal to: %%llx\\n\", @eax); }\n");
36 ShowMessages("\t\te.g : !cpuid asm code { nop; nop; nop }\n");
37}