📄 win32.c
字号:
return;
if( ( mbmDataPtr = ( SharedData * ) \
MapViewOfFile( hMBMData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
{
MESSAGE_DATA msgData;
static const int quality = 20;
setMessageData( &msgData, ( void * ) mbmDataPtr,
sizeof( SharedData ) );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S,
&msgData, CRYPT_IATTRIBUTE_ENTROPY );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE,
( void * ) &quality,
CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
UnmapViewOfFile( mbmDataPtr );
}
CloseHandle( hMBMData );
}
/* Read data from Everest via the shared-memory interface. Everest returns
information as an enormous XML text string so we have to be careful about
handling of lengths. In general the returned length is 1-3K, so we
hard-limit it at 2K to ensure there are no problems if the trailing null
gets lost */
static void readEverestData( void )
{
HANDLE hEverestData;
const void *everestDataPtr;
int length;
if( ( hEverestData = OpenFileMapping( FILE_MAP_READ, FALSE,
"EVEREST_SensorValues" ) ) == NULL )
return;
if( ( everestDataPtr = MapViewOfFile( hEverestData,
FILE_MAP_READ, 0, 0, 0 ) ) != NULL && \
( length = strlen( everestDataPtr ) ) > 128 )
{
MESSAGE_DATA msgData;
static const int quality = 40;
setMessageData( &msgData, ( void * ) everestDataPtr,
min( length, 2048 ) );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S,
&msgData, CRYPT_IATTRIBUTE_ENTROPY );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE,
( void * ) &quality,
CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
UnmapViewOfFile( everestDataPtr );
}
CloseHandle( hEverestData );
}
/* SysTool data structures, from forums.techpowerup.com. This uses the
standard shared memory interface, but it gets a bit tricky because it
uses the OLE 'VARIANT' data type which we can't access because it's
included via a complex nested inclusion framework in windows.h, and the
use of '#pragma once' when we included it for use in crypt.h means that
we can't re-include any of the necessary files. Since we don't actually
care what's inside a VARIANT, and it has a fixed size of 16 bytes, we
just use it as an opaque blob */
typedef BYTE VARIANT[ 16 ]; /* Kludge for OLE data type */
typedef BYTE UINT8;
typedef WORD UINT16;
#define SH_MEM_MAX_SENSORS 128
typedef enum { sUnknown, sNumber, sTemperature, sVoltage, sRPM, sBytes,
sBytesPerSecond, sMhz, sPercentage, sString, sPWM
} SYSTOOL_SENSOR_TYPE;
typedef struct {
WCHAR m_name[ 255 ]; /* Sensor name */
WCHAR m_section[ 64 ]; /* Section in which this sensor appears */
SYSTOOL_SENSOR_TYPE m_sensorType;
LONG m_updateInProgress;/* Nonzero when sensor is being updated */
UINT32 m_timestamp; /* GetTickCount() of last update */
VARIANT m_value; /* Sensor data */
WCHAR m_unit[ 8 ]; /* Unit for text output */
UINT8 m_nDecimals; /* Default number of decimals for formatted output */
} SYSTOOL_SHMEM_SENSOR;
typedef struct {
UINT32 m_version; /* Version of shared memory structure */
UINT16 m_nSensors; /* Number of records with data in m_sensors */
SYSTOOL_SHMEM_SENSOR m_sensors[ SH_MEM_MAX_SENSORS ];
} SYSTOOL_SHMEM;
static void readSysToolData( void )
{
HANDLE hSysToolData;
const SYSTOOL_SHMEM *sysToolDataPtr;
if( ( hSysToolData = OpenFileMapping( FILE_MAP_READ, FALSE,
"SysToolSensors" ) ) == NULL )
return;
if( ( sysToolDataPtr = ( SYSTOOL_SHMEM * ) \
MapViewOfFile( hSysToolData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL )
{
MESSAGE_DATA msgData;
static const int quality = 40;
setMessageData( &msgData, ( void * ) sysToolDataPtr,
sizeof( SYSTOOL_SHMEM ) );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S,
&msgData, CRYPT_IATTRIBUTE_ENTROPY );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE,
( void * ) &quality,
CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
UnmapViewOfFile( sysToolDataPtr );
}
CloseHandle( hSysToolData );
}
/* RivaTuner data structures via the shared-memory interface, from the
RivaTuner sample source. The DWORD values below are actually (32-bit)
floats, but we overlay them with DWORDs since we don't care about the
values. The information is only accessible when the RivaTuner hardware
monitoring window is open. This one is the easiest of the shared-mem
interfaces to monitor because for fowards-compatibility reasons it
stores a Windows-style indicator of the size of each struct entry in the
data header, so we can get the total size simply by multiplying out the
number of entries by the indicated size. As a safety measure we limit
the maximum data size to 2K in case a value gets corrupted */
typedef struct {
DWORD dwSignature; /* 'RTHM' if active */
DWORD dwVersion; /* Must be 0x10001 or above */
DWORD dwNumEntries; /* No.of RTHM_SHARED_MEMORY_ENTRY entries */
time_t time; /* Last polling time */
DWORD dwEntrySize; /* Size of entries in RTHM_SHARED_MEMORY_ENTRY array */
} RTHM_SHARED_MEMORY_HEADER;
typedef struct {
char czSrc[ 32 ]; /* Source description */
char czDim[ 16 ]; /* Source measurement units */
DWORD /*float*/ data; /* Source data */
DWORD /*float*/ offset; /* Source offset, e.g. temp.compensation */
DWORD /*float*/ dataTransformed;/* Source data in transformed(?) form */
DWORD flags; /* Misc.flags */
} RTHM_SHARED_MEMORY_ENTRY;
static void readRivaTunerData( void )
{
HANDLE hRivaTunerData;
RTHM_SHARED_MEMORY_HEADER *rivaTunerHeaderPtr;
if( ( hRivaTunerData = OpenFileMapping( FILE_MAP_READ, FALSE,
"RTHMSharedMemory" ) ) == NULL )
return;
if( ( rivaTunerHeaderPtr = ( RTHM_SHARED_MEMORY_HEADER * ) \
MapViewOfFile( hRivaTunerData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL && \
( rivaTunerHeaderPtr->dwSignature == 'RTHM' ) && \
( rivaTunerHeaderPtr->dwVersion >= 0x10001 ) )
{
MESSAGE_DATA msgData;
const BYTE *entryPtr = ( ( BYTE * ) rivaTunerHeaderPtr ) + \
sizeof( RTHM_SHARED_MEMORY_HEADER );
const int entryTotalSize = rivaTunerHeaderPtr->dwNumEntries * \
rivaTunerHeaderPtr->dwEntrySize;
static const int quality = 5;
setMessageData( &msgData, ( void * ) entryPtr,
min( entryTotalSize, 2048 ) );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S,
&msgData, CRYPT_IATTRIBUTE_ENTROPY );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE,
( void * ) &quality,
CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
UnmapViewOfFile( rivaTunerHeaderPtr );
}
CloseHandle( hRivaTunerData );
}
/* Read data from HMonitor via the shared-memory interface. The DWORD
values below are actually (32-bit) floats, but we overlay them with
DWORDs since we don't care about the values. Like RivaTuner's data the
info structure contains a length value at the start, so it's fairly easy
to work with */
typedef struct {
WORD length;
WORD version; /* Single 'DWORD length' before version 4.1 */
DWORD /*float*/ temp[ 3 ];
DWORD /*float*/ voltage[ 7 ];
int fan[ 3 ];
} HMONITOR_DATA;
static void readHMonitorData( void )
{
HANDLE hHMonitorData;
HMONITOR_DATA *hMonitorDataPtr;
if( ( hHMonitorData = OpenFileMapping( FILE_MAP_READ, FALSE,
"Hmonitor_Counters_Block" ) ) == NULL )
return;
if( ( hMonitorDataPtr = ( HMONITOR_DATA * ) \
MapViewOfFile( hHMonitorData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL && \
( hMonitorDataPtr->version >= 0x4100 ) && \
( hMonitorDataPtr->length >= 48 && hMonitorDataPtr->length <= 1024 ) )
{
MESSAGE_DATA msgData;
static const int quality = 40;
setMessageData( &msgData, hMonitorDataPtr, hMonitorDataPtr->length );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S,
&msgData, CRYPT_IATTRIBUTE_ENTROPY );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE,
( void * ) &quality,
CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
UnmapViewOfFile( hMonitorDataPtr );
}
CloseHandle( hHMonitorData );
}
/* Read data from ATI Tray Tools via the shared-memory interface. This has
an added twist in that just because it's available to be read doesn't
mean that it contains any data, so we check that at least the GPU speed
and temp-monitoring-supported flag have nonzero values */
typedef struct {
DWORD CurGPU; /* GPU speed */
DWORD CurMEM; /* Video memory speed */
DWORD isGameActive;
DWORD is3DActive; /* Boolean: 3D mode active */
DWORD isTempMonSupported; /* Boolean: Temp monitoring available */
DWORD GPUTemp; /* GPU temp */
DWORD ENVTemp; /* Video card temp */
DWORD FanDuty; /* Fan duty cycle */
DWORD MAXGpuTemp, MINGpuTemp; /* Min/max GPU temp */
DWORD MAXEnvTemp, MINEnvTemp; /* Min/max video card temp */
DWORD CurD3DAA, CurD3DAF; /* Direct3D info */
DWORD CurOGLAA, CurOGLAF; /* OpenGL info */
DWORD IsActive; /* Another 3D boolean */
DWORD CurFPS; /* FPS rate */
DWORD FreeVideo; /* Available video memory */
DWORD FreeTexture; /* Available texture memory */
DWORD Cur3DApi; /* API used (D3D, OpenGL, etc) */
DWORD MemUsed; /* ? */
} TRAY_TOOLS_DATA;
static void readATITrayToolsData( void )
{
HANDLE hTrayToolsData;
TRAY_TOOLS_DATA *trayToolsDataPtr;
if( ( hTrayToolsData = OpenFileMapping( FILE_MAP_READ, FALSE,
"ATITRAY_SMEM" ) ) == NULL )
return;
if( ( trayToolsDataPtr = ( TRAY_TOOLS_DATA * ) \
MapViewOfFile( hTrayToolsData, FILE_MAP_READ, 0, 0, 0 ) ) != NULL && \
( trayToolsDataPtr->CurGPU >= 100 ) && \
( trayToolsDataPtr->isTempMonSupported != 0 ) )
{
MESSAGE_DATA msgData;
static const int quality = 8;
setMessageData( &msgData, trayToolsDataPtr,
sizeof( TRAY_TOOLS_DATA ) );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S,
&msgData, CRYPT_IATTRIBUTE_ENTROPY );
krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE,
( void * ) &quality,
CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
UnmapViewOfFile( trayToolsDataPtr );
}
CloseHandle( hTrayToolsData );
}
/****************************************************************************
* *
* Hardware Configuration Data *
* *
****************************************************************************/
/* Read PnP configuration data. This is mostly static per machine, but
differs somewhat across machines. We have to define the values ourselves
here due to a combination of some of the values and functions not
existing at the time VC++ 6.0 was released and */
typedef void * HDEVINFO;
#define DIGCF_PRESENT 0x02
#define DIGCF_ALLCLASSES 0x04
#define SPDRP_HARDWAREID 0x01
typedef struct _SP_DEVINFO_DATA {
DWORD cbSize;
GUID classGuid;
DWORD devInst;
ULONG *reserved;
} SP_DEVINFO_DATA, *PSP_DEVINFO_DATA;
typedef BOOL ( WINAPI *SETUPDIDESTROYDEVICEINFOLIST )( HDEVINFO DeviceInfoSet );
typedef BOOL ( WINAPI *SETUPDIENUMDEVICEINFO )( HDEVINFO DeviceInfoSet,
DWORD MemberIndex,
PSP_DEVINFO_DATA DeviceInfoData );
typedef HDEVINFO ( WINAPI *SETUPDIGETCLASSDEVS )( /*CONST LPGUID*/ void *ClassGuid,
/*PCTSTR*/ void *Enumerator,
HWND hwndParent, DWORD Flags );
typedef BOOL ( WINAPI *SETUPDIGETDEVICEREGISTRYPROPERTY )( HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData,
DWORD Property, PDWORD PropertyRegDataType,
PBYTE PropertyBuffer,
DWORD PropertyBufferSize, PDWORD RequiredSize );
static void readPnPData( void )
{
HANDLE hSetupAPI;
HDEVINFO hDevInfo;
SETUPDIDESTROYDEVICEINFOLIST pSetupDiDestroyDeviceInfoList = NULL;
SETUPDIENUMDEVICEINFO pSetupDiEnumDeviceInfo = NULL;
SETUPDIGETCLASSDEVS pSetupDiGetClassDevs = NULL;
SETUPDIGETDEVICEREGISTRYPROPERTY pSetupDiGetDeviceRegistryProperty = NULL;
if( ( hSetupAPI = LoadLibrary( "SetupAPI.dll" ) ) == NULL )
return;
/* Get pointers to the PnP functions. Although the get class-devs
and get device registry functions look like standard functions,
they're actually macros that are mapped to (depending on the build
type) xxxA or xxxW, so we access them under the straight-ASCII-
function name */
pSetupDiDestroyDeviceInfoList = ( SETUPDIDESTROYDEVICEINFOLIST ) \
GetProcAddress( hSetupAPI, "SetupDiDestroyDeviceInfoList" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -