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

wrmsr command More...

#include "pch.h"

Functions

VOID CommandWrmsrHelp ()
 help of the wrmsr command
 
VOID CommandWrmsr (vector< string > SplitCommand, string Command)
 wrmsr command handler
 

Detailed Description

wrmsr command

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

Function Documentation

◆ CommandWrmsr()

VOID CommandWrmsr ( vector< string > SplitCommand,
string Command )

wrmsr command handler

Parameters
SplitCommand
Command
Returns
VOID
43{
44 BOOL Status;
45 UINT64 Msr;
46 DEBUGGER_READ_AND_WRITE_ON_MSR MsrWriteRequest = {0};
47 BOOL IsNextCoreId = FALSE;
48 BOOL SetMsr = FALSE;
50 UINT64 Value = 0;
52 BOOLEAN IsFirstCommand = TRUE;
53
54 if (SplitCommand.size() >= 6)
55 {
56 ShowMessages("incorrect use of the 'wrmsr'\n\n");
58 return;
59 }
60
61 for (auto Section : SplitCommand)
62 {
63 if (IsFirstCommand == TRUE)
64 {
65 IsFirstCommand = FALSE;
66 continue;
67 }
68
69 if (IsNextCoreId)
70 {
71 if (!ConvertStringToUInt32(Section, &CoreNumer))
72 {
73 ShowMessages("please specify a correct hex value for core id\n\n");
75 return;
76 }
77
78 IsNextCoreId = FALSE;
79 continue;
80 }
81
82 if (!Section.compare("core"))
83 {
84 IsNextCoreId = TRUE;
85 continue;
86 }
87
88 if (!SetMsr)
89 {
90 if (!ConvertStringToUInt64(Section, &Msr))
91 {
92 ShowMessages("please specify a correct hex value to be read\n\n");
94 return;
95 }
96 else
97 {
98 //
99 // Means that the MSR is set, next we should read value
100 //
101 SetMsr = TRUE;
102 continue;
103 }
104 }
105
106 if (SetMsr)
107 {
109 {
111 "please specify a correct hex value or an expression to put on the msr\n\n");
113 return;
114 }
115 else
116 {
117 SetValue = TRUE;
118 continue;
119 }
120 }
121 }
122
123 //
124 // Check if msr is set or not
125 //
126 if (!SetMsr)
127 {
128 ShowMessages("please specify a correct hex value to write\n\n");
130 return;
131 }
132
133 if (!SetValue)
134 {
135 ShowMessages("please specify a correct hex value to put on msr\n\n");
137 return;
138 }
139
140 if (IsNextCoreId)
141 {
142 ShowMessages("please specify a correct hex value for core\n\n");
144 return;
145 }
146
148
149 MsrWriteRequest.ActionType = DEBUGGER_MSR_WRITE;
150 MsrWriteRequest.Msr = Msr;
151 MsrWriteRequest.CoreNumber = CoreNumer;
152 MsrWriteRequest.Value = Value;
153
154 Status = DeviceIoControl(
155 g_DeviceHandle, // Handle to device
156 IOCTL_DEBUGGER_READ_OR_WRITE_MSR, // IO Control Code (IOCTL)
157 &MsrWriteRequest, // Input Buffer to driver.
158 SIZEOF_DEBUGGER_READ_AND_WRITE_ON_MSR, // Input buffer length
159 NULL, // Output Buffer from driver.
160 NULL, // Length of output buffer in bytes.
161 NULL, // Bytes placed in buffer.
162 NULL // synchronous call
163 );
164
165 if (!Status)
166 {
167 ShowMessages("ioctl failed with code (%x), either msr index or core id is invalid\n",
168 GetLastError());
169 return;
170 }
171
172 ShowMessages("\n");
173}
int BOOL
Definition BasicTypes.h:23
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
#define DEBUGGER_READ_AND_WRITE_ON_MSR_APPLY_ALL_CORES
Read and write MSRs to all cores.
Definition Constants.h:599
#define IOCTL_DEBUGGER_READ_OR_WRITE_MSR
ioctl, request to read or write on a special MSR
Definition Ioctls.h:92
#define SIZEOF_DEBUGGER_READ_AND_WRITE_ON_MSR
Definition RequestStructures.h:422
@ DEBUGGER_MSR_WRITE
Definition RequestStructures.h:432
VOID SetValue(PGUEST_REGS GuestRegs, SCRIPT_ENGINE_VARIABLES_LIST *VariablesList, PSYMBOL Symbol, UINT64 Value, SYMBOL_BUFFER *StackBuffer, UINT64 *StackIndx, UINT64 *StackBaseIndx, UINT64 *ReturnValue)
Set the value.
Definition ScriptEngineEval.c:184
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
BOOLEAN ConvertStringToUInt32(string TextToConvert, PUINT32 Result)
check and convert string to a 32 bit unsigned it and also check for special notations like 0x etc.
Definition common.cpp:347
RequestedActionOfThePacket Value(0x1) 00000000
#define AssertShowMessageReturnStmt(expr, message, rc)
Definition common.h:51
#define AssertReturn
Definition common.h:19
#define ASSERT_MESSAGE_DRIVER_NOT_LOADED
Definition common.h:25
HANDLE g_DeviceHandle
Holds the global handle of device which is used to send the request to the kernel by IOCTL,...
Definition globals.h:471
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
request to read or write on MSRs
Definition RequestStructures.h:440
UINT32 CoreNumber
Definition RequestStructures.h:442
DEBUGGER_MSR_ACTION_TYPE ActionType
Definition RequestStructures.h:446
UINT64 Msr
Definition RequestStructures.h:441
UINT64 Value
Definition RequestStructures.h:447
BOOLEAN SymbolConvertNameOrExprToAddress(const string &TextToConvert, PUINT64 Result)
check and convert string to a 64 bit unsigned integer and also check for symbol object names and eval...
Definition symbol.cpp:360
VOID CommandWrmsrHelp()
help of the wrmsr command
Definition wrmsr.cpp:20

◆ CommandWrmsrHelp()

VOID CommandWrmsrHelp ( )

help of the wrmsr command

Returns
VOID
21{
22 ShowMessages("wrmsr : writes on a model-specific register (MSR).\n\n");
23
24 ShowMessages("syntax : \twrmsr [Msr (hex)] [Value (hex)] [core CoreNumber (hex)]\n");
25
26 ShowMessages("\n");
27 ShowMessages("\t\te.g : wrmsr c0000082 fffff8077356f010\n");
28 ShowMessages("\t\te.g : wrmsr c0000082 @rcx\n");
29 ShowMessages("\t\te.g : wrmsr c0000082 @rcx+@rdx+12\n");
30 ShowMessages("\t\te.g : wrmsr c0000082 fffff8077356f010 core 2\n");
31}