121{
123 SIZE_T NumCPU;
125 ULONG ReturnedLength;
126 UINT64 Msr;
131
132 if (CommandTokens.size() >= 5)
133 {
134 ShowMessages("incorrect use of the '%s'\n\n",
137 return;
138 }
139
140 for (auto Section : CommandTokens)
141 {
142 if (IsFirstCommand ==
TRUE)
143 {
144 IsFirstCommand =
FALSE;
145 continue;
146 }
147
148 if (IsNextCoreId)
149 {
151 {
152 ShowMessages("please specify a correct hex value for core id\n\n");
154 return;
155 }
156 IsNextCoreId =
FALSE;
157 continue;
158 }
159
161 {
163 continue;
164 }
165
167 {
168 ShowMessages("please specify a correct hex value to be read\n\n");
170 return;
171 }
173 }
174
175
176
177
178 if (!SetMsr)
179 {
180 ShowMessages("please specify a correct hex value to be read\n\n");
182 return;
183 }
184 if (IsNextCoreId)
185 {
186 ShowMessages("please specify a correct hex value for core\n\n");
188 return;
189 }
190
192
194 MsrReadRequest.
Msr = Msr;
196
197
198
199
200 SIZE_T NumCores = GetWindowsNumaNumberOfCores();
201 NumCPU = NumCores > 0 ? NumCores : GetWindowsCompatibleNumberOfCores();
202
203
204
205
206 UINT64 * OutputBuffer = (UINT64 *)malloc(sizeof(UINT64) * NumCPU);
207
208 ZeroMemory(OutputBuffer, sizeof(UINT64) * NumCPU);
209
210 Status = DeviceIoControl(
213 &MsrReadRequest,
215 OutputBuffer,
216 (
DWORD)(
sizeof(UINT64) * NumCPU),
217 &ReturnedLength,
218 NULL
219 );
220
221 if (!Status)
222 {
223 ShowMessages("ioctl failed with code (%x), either msr index or core id is invalid\n",
224 GetLastError());
225 free(OutputBuffer);
226 return;
227 }
228
229
230
231
233 {
234
235
236
237 for (SIZE_T i = 0; i < NumCPU; i++)
238 {
239 ShowMessages(
"core : 0x%x - msr[%llx] = %s\n", i, Msr,
SeparateTo64BitValue((OutputBuffer[i])).c_str());
240 }
241 }
242 else
243 {
244
245
246
247 ShowMessages(
"core : 0x%x - msr[%llx] = %s\n", CoreNumer, Msr,
SeparateTo64BitValue((OutputBuffer[0])).c_str());
248 }
249
250
251
252
253 free(OutputBuffer);
254}
string SeparateTo64BitValue(UINT64 Value)
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
BOOLEAN ConvertTokenToUInt32(CommandToken TargetToken, PUINT32 Result)
check and convert command token to a 32 bit unsigned integer
Definition common.cpp:546
HANDLE g_DeviceHandle
Holds the global handle of device which is used to send the request to the kernel by IOCTL,...
Definition globals.h:481
BOOLEAN g_IsKdModuleLoaded
shows whether the kernel debugger (KD) module is loaded or not
Definition globals.h:22
VOID CommandRdmsrHelp()
help of the rdmsr command
Definition rdmsr.cpp:25
UINT32 CoreNumber
Definition RequestStructures.h:461
DEBUGGER_MSR_ACTION_TYPE ActionType
Definition RequestStructures.h:464
UINT64 Msr
Definition RequestStructures.h:460