115{
117 SIZE_T NumCPU;
119 ULONG ReturnedLength;
125
126 if (SplitCommand.size() >= 5)
127 {
130 return;
131 }
132
133 for (auto Section : SplitCommand)
134 {
135 if (IsFirstCommand ==
TRUE)
136 {
137 IsFirstCommand =
FALSE;
138 continue;
139 }
140
141 if (IsNextCoreId)
142 {
144 {
145 ShowMessages(
"please specify a correct hex value for core id\n\n");
147 return;
148 }
149 IsNextCoreId =
FALSE;
150 continue;
151 }
152
153 if (!Section.compare("core"))
154 {
156 continue;
157 }
158
160 {
161 ShowMessages(
"please specify a correct hex value to be read\n\n");
163 return;
164 }
166 }
167
168
169
170
171 if (!SetMsr)
172 {
173 ShowMessages(
"please specify a correct hex value to be read\n\n");
175 return;
176 }
177 if (IsNextCoreId)
178 {
179 ShowMessages(
"please specify a correct hex value for core\n\n");
181 return;
182 }
183
185
187 MsrReadRequest.
Msr = Msr;
189
190
191
192
193 SIZE_T NumCores = GetWindowsNumaNumberOfCores();
194 NumCPU = NumCores > 0 ? NumCores : GetWindowsCompatibleNumberOfCores();
195
196
197
198
200
201 ZeroMemory(OutputBuffer,
sizeof(
UINT64) * NumCPU);
202
203 Status = DeviceIoControl(
206 &MsrReadRequest,
208 OutputBuffer,
210 &ReturnedLength,
211 NULL
212 );
213
214 if (!Status)
215 {
216 ShowMessages(
"ioctl failed with code (%x), either msr index or core id is invalid\n",
217 GetLastError());
218 free(OutputBuffer);
219 return;
220 }
221
222
223
224
226 {
227
228
229
230 for (SIZE_T i = 0; i < NumCPU; i++)
231 {
233 }
234 }
235 else
236 {
237
238
239
241 }
242
243
244
245
246 free(OutputBuffer);
247}
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 long DWORD
Definition BasicTypes.h:22
unsigned int UINT32
Definition BasicTypes.h:48
unsigned long ULONG
Definition BasicTypes.h:37
#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_READ
Definition RequestStructures.h:431
string SeparateTo64BitValue(UINT64 Value)
add ` between 64 bit values and convert them to string
Definition common.cpp:27
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
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
VOID CommandRdmsrHelp()
help of the rdmsr command
Definition rdmsr.cpp:20
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