From 85a554b60de4e9bd620e80304788ebf2e4a99747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 6 Nov 2022 17:04:34 +0800 Subject: [PATCH] CPU: support Windows 7 --- src/detection/cpu/cpu_windows.cpp | 17 +++++++++++++---- src/util/windows/wmi.hpp | 22 ++++++++++++++-------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/detection/cpu/cpu_windows.cpp b/src/detection/cpu/cpu_windows.cpp index 8740fa4b9..e5939cd60 100644 --- a/src/detection/cpu/cpu_windows.cpp +++ b/src/detection/cpu/cpu_windows.cpp @@ -17,11 +17,21 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached) ffStrbufInit(&cpu->name); ffStrbufInit(&cpu->vendor); - FFWmiQuery query(L"SELECT Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, ThreadCount, CurrentClockSpeed, MaxClockSpeed FROM Win32_Processor WHERE ProcessorType = 3"); + FFWmiQuery query(L"SELECT Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, NumberOfEnabledCore, CurrentClockSpeed, MaxClockSpeed FROM Win32_Processor WHERE ProcessorType = 3"); if(!query) return; - if(FFWmiRecord record = query.next()) + FFWmiRecord record = query.next(); + if(!record) + { + //NumberOfEnabledCore is not supported on Windows 10- + query = FFWmiQuery(L"SELECT Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, CurrentClockSpeed, MaxClockSpeed FROM Win32_Processor WHERE ProcessorType = 3"); + if(!query) + return; + record = query.next(); + } + + if(record) { record.getString(L"Name", &cpu->name); record.getString(L"Manufacturer", &cpu->vendor); @@ -32,8 +42,7 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached) cpu->coresPhysical = (uint16_t)value; record.getUnsigned(L"NumberOfLogicalProcessors", &value); cpu->coresLogical = (uint16_t)value; - record.getUnsigned(L"ThreadCount", &value); - cpu->coresOnline = (uint16_t)value; + cpu->coresOnline = record.getUnsigned(L"NumberOfEnabledCore", &value) ? (uint16_t)value : cpu->coresPhysical; record.getUnsigned(L"CurrentClockSpeed", &value); //There's no MinClockSpeed in Win32_Processor cpu->frequencyMin = (double)value / 1000.0; record.getUnsigned(L"MaxClockSpeed", &value); diff --git a/src/util/windows/wmi.hpp b/src/util/windows/wmi.hpp index 7b27c7590..6f7d214cb 100644 --- a/src/util/windows/wmi.hpp +++ b/src/util/windows/wmi.hpp @@ -23,12 +23,15 @@ struct FFWmiRecord if(!ok) obj = nullptr; } FFWmiRecord(const FFWmiRecord&) = delete; - FFWmiRecord(FFWmiRecord&& other) { - obj = other.obj; - other.obj = nullptr; - } + FFWmiRecord(FFWmiRecord&& other) { *this = (FFWmiRecord&&)other; } ~FFWmiRecord() { if(obj) obj->Release(); } explicit operator bool() { return !!obj; } + FFWmiRecord& operator =(FFWmiRecord&& other) { + if(obj) obj->Release(); + obj = other.obj; + other.obj = nullptr; + return *this; + } bool getString(const wchar_t* key, FFstrbuf* strbuf); bool getSigned(const wchar_t* key, int64_t* integer); @@ -43,13 +46,16 @@ struct FFWmiQuery FFWmiQuery(const wchar_t* queryStr, FFstrbuf* error = nullptr); explicit FFWmiQuery(IEnumWbemClassObject* pEnumerator): pEnumerator(pEnumerator) {} FFWmiQuery(const FFWmiQuery& other) = delete; - FFWmiQuery(FFWmiQuery&& other) { - pEnumerator = other.pEnumerator; - other.pEnumerator = nullptr; - } + FFWmiQuery(FFWmiQuery&& other) { *this = (FFWmiQuery&&)other; } ~FFWmiQuery() { if(pEnumerator) pEnumerator->Release(); } explicit operator bool() { return !!pEnumerator; } + FFWmiQuery& operator =(FFWmiQuery&& other) { + if(pEnumerator) pEnumerator->Release(); + pEnumerator = other.pEnumerator; + other.pEnumerator = nullptr; + return *this; + } FFWmiRecord next() { FFWmiRecord result(pEnumerator);