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< string > SplitCommand, 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< string > SplitCommand,
string Command )

!cpuid command handler

Parameters
SplitCommand
Command
Returns
VOID
48{
50 PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger = NULL;
51 PDEBUGGER_GENERAL_ACTION ActionCustomCode = NULL;
52 PDEBUGGER_GENERAL_ACTION ActionScript = NULL;
53 BOOLEAN GetEax = FALSE;
54 UINT32 EventLength;
55 UINT64 SpecialTarget = 0;
56 UINT32 ActionBreakToDebuggerLength = 0;
57 UINT32 ActionCustomCodeLength = 0;
58 UINT32 ActionScriptLength = 0;
59 vector<string> SplitCommandCaseSensitive {Split(Command, ' ')};
60 DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
61
62 //
63 // Interpret and fill the general event and action fields
64 //
65 //
67 &SplitCommand,
68 &SplitCommandCaseSensitive,
70 &Event,
71 &EventLength,
72 &ActionBreakToDebugger,
73 &ActionBreakToDebuggerLength,
74 &ActionCustomCode,
75 &ActionCustomCodeLength,
76 &ActionScript,
77 &ActionScriptLength,
78 &EventParsingErrorCause))
79 {
80 return;
81 }
82
83 //
84 // Interpret command specific details (if any), of CPUID EAX index
85 //
86 for (auto Section : SplitCommand)
87 {
88 if (!Section.compare("!cpuid"))
89 {
90 continue;
91 }
92 else if (!GetEax)
93 {
94 //
95 // It's probably an msr
96 //
97 if (!ConvertStringToUInt64(Section, &SpecialTarget))
98 {
99 //
100 // Unknown parameter
101 //
102 ShowMessages("unknown parameter '%s'\n\n", Section.c_str());
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", Section.c_str());
123
124 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
125 return;
126 }
127 }
128
129 //
130 // Set the target EAX (if not specific then it means all msrs)
131 //
132 Event->Options.OptionalParam1 = GetEax;
133
134 if (GetEax)
135 {
136 Event->Options.OptionalParam2 = SpecialTarget;
137 }
138
139 //
140 // Send the ioctl to the kernel for event registration
141 //
142 if (!SendEventToKernel(Event, EventLength))
143 {
144 //
145 // There was an error, probably the handle was not initialized
146 // we have to free the Action before exit, it is because, we
147 // already freed the Event and string buffers
148 //
149
150 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
151 return;
152 }
153
154 //
155 // Add the event to the kernel
156 //
157 if (!RegisterActionToEvent(Event,
158 ActionBreakToDebugger,
159 ActionBreakToDebuggerLength,
160 ActionCustomCode,
161 ActionCustomCodeLength,
162 ActionScript,
163 ActionScriptLength))
164 {
165 //
166 // There was an error
167 //
168 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
169 return;
170 }
171}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
const vector< string > Split(const string &s, const char &c)
general split command
Definition common.cpp:117
BOOLEAN ConvertStringToUInt64(string TextToConvert, PUINT64 Result)
check and convert string to a 64 bit unsigned integer and also check for special notations like 0x,...
Definition common.cpp:240
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:2292
BOOLEAN InterpretGeneralEventAndActionsFields(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, 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:2342
BOOLEAN SendEventToKernel(PDEBUGGER_GENERAL_EVENT_DETAIL Event, UINT32 EventBufferLength)
Register the event to the kernel.
Definition debugger.cpp:1969
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:2086
@ CPUID_INSTRUCTION_EXECUTION
Definition Events.h:123
enum _DEBUGGER_EVENT_PARSING_ERROR_CAUSE DEBUGGER_EVENT_PARSING_ERROR_CAUSE
Reason for error in parsing commands.
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
NULL()
Definition test-case-generator.py:530
UINT64 OptionalParam2
Definition Events.h:273
UINT64 OptionalParam1
Definition Events.h:272
Each event can have multiple actions.
Definition Events.h:406
Each command is like the following struct, it also used for tracing works in user mode and sending it...
Definition Events.h:350
DEBUGGER_EVENT_OPTIONS Options
Definition Events.h:391

◆ 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}