📄 procinfo.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// -----------------------------------------------------------------------------
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// -----------------------------------------------------------------------------
#include <windows.h>
#include <cpuid.h>
#include <oal_nkxp.h>
extern LPCWSTR g_pszDfltProcessorName;
BOOL x86IoCtlProcessorInfo (
UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *lpOutBuf,
UINT32 nOutBufSize, UINT32 *lpBytesReturned
) {
if (!lpOutBuf) {
NKSetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (sizeof(PROCESSOR_INFO) > nOutBufSize) {
NKSetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
} else {
CPUID CpuInfo;
DWORD CpuMask;
BOOL CpuId;
char VendorID[13];
PPROCESSOR_INFO pProcInfo = (PPROCESSOR_INFO)lpOutBuf;
if (!pProcInfo)
{
if (lpBytesReturned)
{
*lpBytesReturned = 0;
}
return FALSE;
}
if (lpBytesReturned)
{
*lpBytesReturned = sizeof(PROCESSOR_INFO);
memset(pProcInfo, 0, *lpBytesReturned);
}
// Use CPUID instruction to get information about platform
__try {
_asm {
mov eax, 0
cpuid
mov dword ptr [VendorID], ebx
mov dword ptr [VendorID+4], edx
mov dword ptr [VendorID+8], ecx
mov eax, 1
cpuid
and eax, 03fffh
mov CpuInfo.Register, eax
}
VendorID[12] = '\0';
CpuId = TRUE;
} __except (EXCEPTION_EXECUTE_HANDLER) {
CpuId = FALSE;
}
pProcInfo->wVersion = 1;
if (CpuId) {
int i;
CPUSIG *CpuTable;
int Entries = 0;
// Check vendor ID for manufacturer
if (!NKstrcmpiAandW(VendorID, AMD_VENDOR)) { // We match "AuthenticAMD"
CpuTable = AMDTable;
Entries = AMD_ENTRIES;
CpuMask = AMD_MASK;
NKwcscpy (pProcInfo->szVendor, AMD_NAME);
} else if (!NKstrcmpiAandW(VendorID, INTEL_VENDOR)) { // We match "GenuineIntel"
CpuTable = IntelTable;
Entries = INTEL_ENTRIES;
CpuMask = INTEL_MASK;
NKwcscpy (pProcInfo->szVendor, INTEL_NAME);
} else if (!NKstrcmpiAandW(VendorID, GEODE_VENDOR)) { // We match "Geode by NSC"
CpuTable = GeodeTable;
Entries = GEODE_ENTRIES;
CpuMask = GEODE_MASK;
NKwcscpy (pProcInfo->szVendor, GEODE_NAME);
} else if (!NKstrcmpiAandW(VendorID, VIA_VENDOR)) { // We match "CentaurHauls"
CpuTable = VIATable;
Entries = VIA_ENTRIES;
CpuMask = VIA_MASK;
NKwcscpy (pProcInfo->szVendor, VIA_NAME);
}
// Look for CPU in appropriate table
for (i = 0; i < Entries; i++) {
if ((CpuInfo.Register & CpuMask) == CpuTable[i].CpuId.Register) {
NKwcscpy (pProcInfo->szProcessorName, CpuTable[i].ProcessorName);
pProcInfo->wProcessorRevision = CpuInfo.Field.Stepping;
pProcInfo->dwInstructionSet = CpuTable[i].InstructionSet;
return TRUE;
}
}
}
// No CPUID instruction or unknown processor, use default value
NKwcscpy (pProcInfo->szProcessorName, g_pszDfltProcessorName);
pProcInfo->dwInstructionSet = PROCESSOR_FLOATINGPOINT;
return TRUE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -