diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d1e28152..31bfcac0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -519,6 +519,7 @@ elseif(WIN32) src/detection/swap/swap_windows.cpp src/detection/terminalfont/terminalfont_windows.c src/detection/terminalshell/terminalshell_windows.cpp + src/detection/temps/temps_windows.cpp src/detection/uptime/uptime_windows.c src/detection/users/users_windows.c src/detection/wifi/wifi_windows.c diff --git a/src/detection/cpu/cpu_windows.c b/src/detection/cpu/cpu_windows.c index 84af8ecfb..05116870f 100644 --- a/src/detection/cpu/cpu_windows.c +++ b/src/detection/cpu/cpu_windows.c @@ -1,4 +1,5 @@ #include "cpu.h" +#include "detection/temps/temps_windows.h" #include "util/windows/registry.h" #include "util/mallocHelper.h" @@ -46,4 +47,7 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu) ffRegReadStrbuf(hKey, L"ProcessorNameString", &cpu->name, NULL); ffRegReadStrbuf(hKey, L"VendorIdentifier", &cpu->vendor, NULL); + + if(instance->config.cpuTemp) + ffDetectSmbiosTemp(&cpu->temperature, NULL); } diff --git a/src/detection/temps/temps_windows.cpp b/src/detection/temps/temps_windows.cpp new file mode 100644 index 000000000..9c741b4cd --- /dev/null +++ b/src/detection/temps/temps_windows.cpp @@ -0,0 +1,25 @@ +extern "C" +{ +#include "temps_windows.h" +} +#include "util/windows/wmi.hpp" + +extern "C" +const char* ffDetectSmbiosTemp(double* current, double* critical) +{ + // Requires Administrator priviledges + // https://wutils.com/wmi/root/wmi/msacpi_thermalzonetemperature/#properties + FFWmiQuery query(L"SELECT CurrentTemperature, CriticalTripPoint FROM MSAcpi_ThermalZoneTemperature WHERE Active = TRUE", nullptr, FFWmiNamespace::WMI); + if(!query) + return "Query WMI service failed"; + + if(FFWmiRecord record = query.next()) + { + if (current && record.getReal(L"CurrentTemperature", current)) // In tenth of degrees Kelvin + *current = *current / 10 - 273.15; + if (critical && record.getReal(L"CriticalTripPoint", critical)) // In tenth of degrees Kelvin + *critical = *critical / 10 - 273.15; + } + + return "No WMI result returned"; +} diff --git a/src/detection/temps/temps_windows.h b/src/detection/temps/temps_windows.h new file mode 100644 index 000000000..57e27ba5a --- /dev/null +++ b/src/detection/temps/temps_windows.h @@ -0,0 +1,8 @@ +#pragma once + +#ifndef FF_INCLUDED_detection_temps_windows +#define FF_INCLUDED_detection_temps_windows + +const char* ffDetectSmbiosTemp(double* current, double* critical); + +#endif