From ae1288d087d64e1fc9e09a52943f6a0fbfe2750c Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sat, 3 Oct 2026 11:57:46 +0800 Subject: [PATCH] Global (Windows): adds more FF_DEBUG --- src/common/impl/binary_windows.c | 11 ++++- src/common/impl/io_windows.c | 9 +++- src/common/impl/networking_windows.c | 27 ++++++----- src/common/impl/processing_windows.c | 22 +++++++-- src/common/windows/com.c | 8 ++++ src/detection/battery/battery_windows.c | 1 + src/detection/bios/bios_windows.c | 3 ++ src/detection/bluetooth/bluetooth_windows.c | 5 +++ src/detection/bluetooth/bluetooth_windows.cpp | 18 ++++++-- .../bluetoothradio/bluetoothradio_windows.c | 3 ++ src/detection/board/board_windows.c | 3 ++ src/detection/bootmgr/bootmgr_windows.c | 20 +++++++-- src/detection/camera/camera_windows.cpp | 15 +++++-- src/detection/chassis/chassis_windows.c | 3 ++ src/detection/codec/codec_windows.cpp | 6 ++- src/detection/cpu/cpu_windows.c | 45 +++++++++++++++---- src/detection/cpucache/cpucache_windows.c | 6 ++- src/detection/cpuusage/cpuusage_windows.c | 31 ++++++++++--- src/detection/disk/disk_windows.c | 5 ++- src/detection/dns/dns_windows.c | 9 +++- src/detection/font/font_windows.c | 3 ++ src/detection/gamepad/gamepad_windows.c | 4 ++ src/detection/host/host_windows.c | 3 ++ src/detection/initsystem/initsystem_windows.c | 2 + src/detection/keyboard/keyboard_windows.c | 4 ++ src/detection/locale/locale_windows.c | 2 + src/detection/media/media_windows.cpp | 2 + src/detection/memory/memory_windows.c | 6 ++- src/detection/mouse/mouse_windows.c | 4 ++ src/detection/netio/netio_windows.c | 5 ++- src/detection/opengl/opengl_windows.c | 11 +++++ .../physicaldisk/physicaldisk_windows.c | 1 + src/detection/processes/processes_windows.c | 2 + src/detection/sound/sound_windows.cpp | 33 ++++++++++---- src/detection/swap/swap_windows.c | 5 ++- .../terminalfont/terminalfont_windows.c | 3 ++ src/detection/top/top_windows.c | 2 + src/detection/users/users_windows.c | 2 + src/detection/wallpaper/wallpaper_windows.c | 3 ++ src/detection/wm/wm_windows.c | 4 ++ 40 files changed, 290 insertions(+), 61 deletions(-) diff --git a/src/common/impl/binary_windows.c b/src/common/impl/binary_windows.c index 005389ff0..dfad1d94c 100644 --- a/src/common/impl/binary_windows.c +++ b/src/common/impl/binary_windows.c @@ -1,4 +1,5 @@ #include "common/binary.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" #include "common/windows/nt.h" @@ -17,22 +18,28 @@ const char* ffBinaryExtractStrings(const char* peFile, bool (*cb)(const char* str, uint32_t len, void* userdata), void* userdata, uint32_t minLength) { FF_AUTO_CLOSE_FD HANDLE hFile = CreateFileA(peFile, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile == INVALID_HANDLE_VALUE) { + FF_DEBUG("CreateFileA() failed: %s", ffDebugWin32Error(GetLastError())); return "CreateFileA() failed"; } FF_AUTO_CLOSE_FD HANDLE hSection = nullptr; - if (!NT_SUCCESS(NtCreateSection(&hSection, SECTION_MAP_READ, nullptr, nullptr, PAGE_READONLY, SEC_COMMIT, hFile))) { + NTSTATUS status = NtCreateSection(&hSection, SECTION_MAP_READ, nullptr, nullptr, PAGE_READONLY, SEC_COMMIT, hFile); + if (!NT_SUCCESS(status)) { + FF_DEBUG("NtCreateSection() failed: %s", ffDebugNtStatus(status)); return "NtCreateSection() failed"; } PVOID base = nullptr; SIZE_T viewSize = 0; - if (!NT_SUCCESS(NtMapViewOfSection(hSection, NtCurrentProcess(), &base, 0, 0, nullptr, &viewSize, ViewUnmap, 0, PAGE_READONLY))) { + status = NtMapViewOfSection(hSection, NtCurrentProcess(), &base, 0, 0, nullptr, &viewSize, ViewUnmap, 0, PAGE_READONLY); + if (!NT_SUCCESS(status)) { + FF_DEBUG("NtMapViewOfSection() failed: %s", ffDebugNtStatus(status)); return "NtMapViewOfSection() failed"; } PIMAGE_NT_HEADERS ntHeaders = RtlImageNtHeader(base); if (!ntHeaders) { + FF_DEBUG("RtlImageNtHeader() failed"); NtUnmapViewOfSection(NtCurrentProcess(), base); return "RtlImageNtHeader() failed"; } diff --git a/src/common/impl/io_windows.c b/src/common/impl/io_windows.c index d8fb82960..91f58abce 100644 --- a/src/common/impl/io_windows.c +++ b/src/common/impl/io_windows.c @@ -441,7 +441,9 @@ const char* ffGetTerminalResponse(const char* request, int nParams, const char* } while (true) { - if (NtWaitForSingleObject(hInput, FALSE, &(LARGE_INTEGER) { .QuadPart = (int64_t) FF_IO_TERM_RESP_WAIT_MS * -10000 }) != STATUS_WAIT_0) { + NTSTATUS status = NtWaitForSingleObject(hInput, FALSE, &(LARGE_INTEGER) { .QuadPart = (int64_t) FF_IO_TERM_RESP_WAIT_MS * -10000 }); + if (status != STATUS_WAIT_0) { + FF_DEBUG("NtWaitForSingleObject() failed or timeout: %s", ffDebugNtStatus(status)); SetConsoleMode(hInput, inputMode); return "NtWaitForSingleObject() failed or timeout"; } @@ -471,7 +473,9 @@ const char* ffGetTerminalResponse(const char* request, int nParams, const char* while (true) { DWORD bytes = 0; - if (!ReadFile(hInput, buffer + bytesRead, (DWORD) (sizeof(buffer) - 1 - bytesRead), &bytes, nullptr) || bytes == 0) { + BOOL readOk = ReadFile(hInput, buffer + bytesRead, (DWORD) (sizeof(buffer) - 1 - bytesRead), &bytes, nullptr); + if (!readOk || bytes == 0) { + FF_DEBUG("ReadFile() %s, bytes=%lu: %s", readOk ? "returned no data" : "failed", bytes, readOk ? "no error" : ffDebugWin32Error(GetLastError())); va_end(args); return "ReadFile() failed"; } @@ -490,6 +494,7 @@ const char* ffGetTerminalResponse(const char* request, int nParams, const char* if (ret <= 0) { va_end(args); + FF_DEBUG("vsscanf(buffer, format, args) failed: %s", strerror(errno)); return "vsscanf(buffer, format, args) failed"; } if (ret >= nParams) { diff --git a/src/common/impl/networking_windows.c b/src/common/impl/networking_windows.c index 1b6388c22..6aebe94bd 100644 --- a/src/common/impl/networking_windows.c +++ b/src/common/impl/networking_windows.c @@ -14,8 +14,9 @@ static LPFN_CONNECTEX ConnectEx; static const char* initWsaData(WSADATA* wsaData) { FF_DEBUG("Initializing WinSock"); - if (WSAStartup(MAKEWORD(2, 2), wsaData) != 0) { - FF_DEBUG("WSAStartup() failed"); + int ret = WSAStartup(MAKEWORD(2, 2), wsaData); + if (ret != 0) { + FF_DEBUG("WSAStartup() failed: %s", ffDebugWin32Error((DWORD) ret)); return "WSAStartup() failed"; } @@ -28,7 +29,7 @@ static const char* initWsaData(WSADATA* wsaData) { // Dummy socket needed for WSAIoctl SOCKET sockfd = WSASocketW(AF_INET, SOCK_STREAM, 0, nullptr, 0, 0); if (sockfd == INVALID_SOCKET) { - FF_DEBUG("WSASocketW(AF_INET, SOCK_STREAM) failed"); + FF_DEBUG("WSASocketW(AF_INET, SOCK_STREAM) failed: %s", ffDebugWin32Error((DWORD) WSAGetLastError())); WSACleanup(); return "WSASocketW(AF_INET, SOCK_STREAM) failed"; } @@ -36,7 +37,7 @@ static const char* initWsaData(WSADATA* wsaData) { DWORD dwBytes; GUID guid = WSAID_CONNECTEX; if (WSAIoctl(sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, sizeof(guid), &ConnectEx, sizeof(ConnectEx), &dwBytes, nullptr, nullptr) != 0) { - FF_DEBUG("WSAIoctl(sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER) failed"); + FF_DEBUG("WSAIoctl(sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER) failed: %s", ffDebugWin32Error((DWORD) WSAGetLastError())); closesocket(sockfd); WSACleanup(); return "WSAIoctl(sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER) failed"; @@ -90,8 +91,9 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho }; wchar_t hostW[256]; - if (!NT_SUCCESS(RtlUTF8ToUnicodeN(hostW, (ULONG) sizeof(hostW), nullptr, host, (ULONG) strlen(host) + 1))) { - FF_DEBUG("Failed to convert host to wide string: %s", host); + NTSTATUS status = RtlUTF8ToUnicodeN(hostW, (ULONG) sizeof(hostW), nullptr, host, (ULONG) strlen(host) + 1); + if (!NT_SUCCESS(status)) { + FF_DEBUG("Failed to convert host to wide string: %s: %s", host, ffDebugNtStatus(status)); return "Failed to convert host to wide string"; } @@ -99,14 +101,15 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho _itow(port, portW, 10); FF_DEBUG("Resolving address: %s:%u (%s)", host, port, state->ipv6 ? "IPv6" : "IPv4"); - if (GetAddrInfoW(hostW, portW, &hints, &addr) != 0) { - FF_DEBUG("GetAddrInfoW() failed"); + int ret = GetAddrInfoW(hostW, portW, &hints, &addr); + if (ret != 0) { + FF_DEBUG("GetAddrInfoW() failed: %s", ffDebugWin32Error((DWORD) ret)); return "GetAddrInfoW() failed"; } state->sockfd = WSASocketW(addr->ai_family, addr->ai_socktype, addr->ai_protocol, nullptr, 0, 0); if (state->sockfd == INVALID_SOCKET) { - FF_DEBUG("WSASocketW() failed"); + FF_DEBUG("WSASocketW() failed: %s", ffDebugWin32Error((DWORD) WSAGetLastError())); FreeAddrInfoW(addr); return "WSASocketW() failed"; } @@ -149,8 +152,9 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho // Initialize overlapped structure with WSA event for asynchronous I/O state->overlapped = (OVERLAPPED) {}; - if (!NT_SUCCESS(NtCreateEvent(&state->overlapped.hEvent, EVENT_ALL_ACCESS, nullptr, NotificationEvent, FALSE))) { - FF_DEBUG("NtCreateEvent() failed"); + NTSTATUS eventStatus = NtCreateEvent(&state->overlapped.hEvent, EVENT_ALL_ACCESS, nullptr, NotificationEvent, FALSE); + if (!NT_SUCCESS(eventStatus)) { + FF_DEBUG("NtCreateEvent() failed: %s", ffDebugNtStatus(eventStatus)); closesocket(state->sockfd); FreeAddrInfoW(addr); state->sockfd = INVALID_SOCKET; @@ -417,6 +421,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf } if (chunked && !ffNetworkingDecodeChunked(buffer, &headerEnd)) { + FF_DEBUG("Failed to decode chunked response"); return "Failed to decode chunked response"; } diff --git a/src/common/impl/processing_windows.c b/src/common/impl/processing_windows.c index 5ddcdc236..0eb9ca020 100644 --- a/src/common/impl/processing_windows.c +++ b/src/common/impl/processing_windows.c @@ -1,4 +1,5 @@ #include "fastfetch.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include "common/processing.h" #include "common/io.h" @@ -100,6 +101,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFNativeFD stdinF 0, nullptr); if (hChildPipeRead == INVALID_HANDLE_VALUE) { + FF_DEBUG("CreateNamedPipeW() failed: %s", ffDebugWin32Error(GetLastError())); return "CreateNamedPipeW(L\"\\\\.\\pipe\\FASTFETCH-$(PID)\") failed"; } @@ -116,6 +118,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFNativeFD stdinF 0, nullptr); if (hChildPipeWrite == INVALID_HANDLE_VALUE) { + FF_DEBUG("CreateFileW() failed: %s", ffDebugWin32Error(GetLastError())); return "CreateFileW(L\"\\\\.\\pipe\\FASTFETCH-$(PID)\") failed"; } @@ -141,7 +144,9 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFNativeFD stdinF argvToCmdline(argv, &buf); uint32_t cmdlineBytes = (buf.length + 1) * sizeof(wchar_t); cmdline = malloc(cmdlineBytes); - if (!NT_SUCCESS(RtlUTF8ToUnicodeN(cmdline, cmdlineBytes, nullptr, buf.chars, buf.length + 1))) { + NTSTATUS status = RtlUTF8ToUnicodeN(cmdline, cmdlineBytes, nullptr, buf.chars, buf.length + 1); + if (!NT_SUCCESS(status)) { + FF_DEBUG("RtlUTF8ToUnicodeN() failed: %s", ffDebugNtStatus(status)); return "RtlUTF8ToUnicodeN() failed"; } } @@ -165,6 +170,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFNativeFD stdinF if (GetLastError() == ERROR_FILE_NOT_FOUND) { return "command not found"; } + FF_DEBUG("CreateProcessW() failed: %s", ffDebugWin32Error(GetLastError())); return "CreateProcessW() failed"; } @@ -197,7 +203,9 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) { handle->pid = INVALID_HANDLE_VALUE; handle->pipeRead = INVALID_HANDLE_VALUE; - if (timeout >= 0 && !NT_SUCCESS(NtCreateEvent(&hReadEvent, EVENT_ALL_ACCESS, nullptr, SynchronizationEvent, FALSE))) { + NTSTATUS createStatus = STATUS_SUCCESS; + if (timeout >= 0 && !NT_SUCCESS(createStatus = NtCreateEvent(&hReadEvent, EVENT_ALL_ACCESS, nullptr, SynchronizationEvent, FALSE))) { + FF_DEBUG("NtCreateEvent() failed: %s", ffDebugNtStatus(createStatus)); return "NtCreateEvent() failed"; } @@ -216,7 +224,8 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) { nullptr, nullptr); if (status == STATUS_PENDING) { - switch (NtWaitForSingleObject(hReadEvent, FALSE, &(LARGE_INTEGER) { .QuadPart = (int64_t) timeout * -10000 })) { + NTSTATUS waitStatus = NtWaitForSingleObject(hReadEvent, FALSE, &(LARGE_INTEGER) { .QuadPart = (int64_t) timeout * -10000 }); + switch (waitStatus) { case STATUS_WAIT_0: status = iosb.Status; break; @@ -227,6 +236,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) { } default: + FF_DEBUG("NtWaitForSingleObject(hReadEvent) failed: %s", ffDebugNtStatus(waitStatus)); terminateChildProcess(hProcess, hChildPipeRead, hReadEvent, &iosb); return "NtWaitForSingleObject(hReadEvent) failed"; } @@ -237,6 +247,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) { } if (!NT_SUCCESS(status)) { + FF_DEBUG("NtReadFile(hChildPipeRead) failed: %s", ffDebugNtStatus(status)); terminateChildProcess(hProcess, hChildPipeRead, nullptr, &iosb); return "NtReadFile(hChildPipeRead) failed"; } @@ -248,12 +259,15 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) { exit: { PROCESS_BASIC_INFORMATION info = {}; ULONG size; - if (NT_SUCCESS(NtQueryInformationProcess(hProcess, ProcessBasicInformation, &info, sizeof(info), &size))) { + NTSTATUS status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &info, sizeof(info), &size); + if (NT_SUCCESS(status)) { assert(size == sizeof(info)); if (info.ExitStatus != STILL_ACTIVE && info.ExitStatus != 0) { + FF_DEBUG("Child process exited with an error"); return "Child process exited with an error"; } } else { + FF_DEBUG("NtQueryInformationProcess(ProcessBasicInformation) failed: %s", ffDebugNtStatus(status)); return "NtQueryInformationProcess(ProcessBasicInformation) failed"; } } diff --git a/src/common/windows/com.c b/src/common/windows/com.c index 1dab646cd..08d7f7c81 100644 --- a/src/common/windows/com.c +++ b/src/common/windows/com.c @@ -1,4 +1,5 @@ #include "com.h" +#include "common/debug.h" #include @@ -14,15 +15,19 @@ static const char* doInitCom() { if (FAILED(res)) { switch (res) { case E_INVALIDARG: + FF_DEBUG("RoInitialize() failed: invalid argument: 0x%08lX (%s)", res, ffDebugHResult(res)); return "RoInitialize() failed: invalid argument"; case E_OUTOFMEMORY: + FF_DEBUG("RoInitialize() failed: out of memory: 0x%08lX (%s)", res, ffDebugHResult(res)); return "RoInitialize() failed: out of memory"; case E_UNEXPECTED: + FF_DEBUG("RoInitialize() failed: unexpected error: 0x%08lX (%s)", res, ffDebugHResult(res)); return "RoInitialize() failed: unexpected error"; case RPC_E_CHANGED_MODE: // COM was already initialized with a different concurrency model return nullptr; default: + FF_DEBUG("RoInitialize() failed: unknown error: 0x%08lX (%s)", res, ffDebugHResult(res)); return "RoInitialize() failed: unknown error"; } } @@ -42,13 +47,16 @@ static const char* doInitCom() { if (FAILED(res)) { switch (res) { case E_INVALIDARG: + FF_DEBUG("CoInitializeEx() failed: invalid argument: 0x%08lX (%s)", res, ffDebugHResult(res)); return "CoInitializeEx() failed: invalid argument"; case E_OUTOFMEMORY: + FF_DEBUG("CoInitializeEx() failed: out of memory: 0x%08lX (%s)", res, ffDebugHResult(res)); return "CoInitializeEx() failed: out of memory"; case RPC_E_CHANGED_MODE: // COM was already initialized with a different concurrency model return nullptr; default: + FF_DEBUG("CoInitializeEx() failed: unknown error: 0x%08lX (%s)", res, ffDebugHResult(res)); return "CoInitializeEx() failed: unknown error"; } } diff --git a/src/detection/battery/battery_windows.c b/src/detection/battery/battery_windows.c index 4733b141d..2c61c871d 100644 --- a/src/detection/battery/battery_windows.c +++ b/src/detection/battery/battery_windows.c @@ -66,6 +66,7 @@ static const char* queryWmiAllData(const GUID* guid, [[maybe_unused]] const char } if (*pBufferSize == 0) { + FF_DEBUG("WMI: WmiQueryAllDataW(nullptr) returned no data"); return "WmiQueryAllDataW(nullptr) returned no data"; } diff --git a/src/detection/bios/bios_windows.c b/src/detection/bios/bios_windows.c index b1d309f5e..c367dafd4 100644 --- a/src/detection/bios/bios_windows.c +++ b/src/detection/bios/bios_windows.c @@ -1,4 +1,5 @@ #include "bios.h" +#include "common/debug.h" #include "common/smbios.h" #ifdef _WIN32 @@ -46,11 +47,13 @@ static_assert(offsetof(FFSmbiosBios, ExtendedBiosRomSize) == 0x18, const char* ffDetectBios(FFBiosResult* bios) { const FFSmbiosHeaderTable* smbiosTable = ffGetSmbiosHeaderTable(); if (!smbiosTable) { + FF_DEBUG("BIOS: failed to get SMBIOS data"); return "Failed to get SMBIOS data"; } const FFSmbiosBios* data = (const FFSmbiosBios*) (*smbiosTable)[FF_SMBIOS_TYPE_BIOS]; if (!data) { + FF_DEBUG("BIOS: section is not found in SMBIOS data"); return "BIOS section is not found in SMBIOS data"; } diff --git a/src/detection/bluetooth/bluetooth_windows.c b/src/detection/bluetooth/bluetooth_windows.c index f58a12501..18022abbe 100644 --- a/src/detection/bluetooth/bluetooth_windows.c +++ b/src/detection/bluetooth/bluetooth_windows.c @@ -1,4 +1,5 @@ #include "bluetooth.h" +#include "common/debug.h" #include "common/library.h" #include "common/mallocHelper.h" #include "common/windows/unicode.h" @@ -64,6 +65,7 @@ static const char* detectBattery(FFlist* devices) { // not in the media class at all, so narrowing the filter would lose it. CONFIGRET status = CM_Get_Device_ID_List_SizeW(&idListLength, GUID_DEVCLASS_MEDIA_STRING, CM_GETIDLIST_FILTER_PRESENT); if (status != CR_SUCCESS) { + FF_DEBUG("CM_Get_Device_ID_List_SizeW failed: %s", ffDebugConfigRet(status)); return "CM_Get_Device_ID_List_SizeW failed"; } @@ -73,11 +75,13 @@ static const char* detectBattery(FFlist* devices) { FF_AUTO_FREE wchar_t* idList = (wchar_t*) malloc((size_t) idListLength * sizeof(wchar_t)); if (!idList) { + FF_DEBUG("malloc() failed"); return "malloc() failed"; } status = CM_Get_Device_ID_ListW(GUID_DEVCLASS_MEDIA_STRING, idList, idListLength, CM_GETIDLIST_FILTER_PRESENT); if (status != CR_SUCCESS) { + FF_DEBUG("CM_Get_Device_ID_ListW failed: %s", ffDebugConfigRet(status)); return "CM_Get_Device_ID_ListW failed"; } @@ -137,6 +141,7 @@ static const char* detectClassic(FFBluetoothOptions* options, FFlist* devices /* &btdi); if (!hFind) { if (GetLastError() != ERROR_NO_MORE_ITEMS) { + FF_DEBUG("BluetoothFindFirstDevice() failed: %s", ffDebugWin32Error(GetLastError())); return "BluetoothFindFirstDevice() failed"; } // "Nothing found" is not an error here: this search only ever sees BR/EDR devices, and a diff --git a/src/detection/bluetooth/bluetooth_windows.cpp b/src/detection/bluetooth/bluetooth_windows.cpp index 58863b56c..5c82ed7f5 100644 --- a/src/detection/bluetooth/bluetooth_windows.cpp +++ b/src/detection/bluetooth/bluetooth_windows.cpp @@ -1,5 +1,6 @@ extern "C" { #include "bluetooth.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include "common/percent.h" #include "common/strutil.h" @@ -280,24 +281,32 @@ extern "C" const char* ffBluetoothDetectLe(FFBluetoothOptions* options, FFlist* } FF_AUTO_RELEASE_COM_OBJECT abi_t* ledeviceStatics = nullptr; - if (FAILED(ffGetActivationFactory(L"Windows.Devices.Bluetooth.BluetoothLEDevice", &ledeviceStatics)) || !ledeviceStatics) { + HRESULT ledeviceHr = ffGetActivationFactory(L"Windows.Devices.Bluetooth.BluetoothLEDevice", &ledeviceStatics); + if (FAILED(ledeviceHr) || !ledeviceStatics) { + FF_DEBUG("winrt: RoGetActivationFactory(BluetoothLEDevice) failed: %s", ffDebugHResult(ledeviceHr)); return "winrt: RoGetActivationFactory(BluetoothLEDevice) failed"; } [[gnu::cleanup(ffDeleteHstring)]] HSTRING selector = nullptr; - if (FAILED(ledeviceStatics->GetDeviceSelectorFromPairingState(true, reinterpret_cast(&selector))) || !selector) { + HRESULT selectorHr = ledeviceStatics->GetDeviceSelectorFromPairingState(true, reinterpret_cast(&selector)); + if (FAILED(selectorHr) || !selector) { + FF_DEBUG("winrt: GetDeviceSelectorFromPairingState() failed: %s", ffDebugHResult(selectorHr)); return "winrt: GetDeviceSelectorFromPairingState() failed"; } // Without additional properties the map carries only the eight generic ones, and every AEP key // is absent, so the list is not optional. FF_AUTO_RELEASE_COM_OBJECT abi_t>* properties = nullptr; - if (FAILED(ffWinrtCreateHstringIterable(ffBluetoothLeProperties, (uint32_t) ARRAY_SIZE(ffBluetoothLeProperties), &properties)) || !properties) { + HRESULT propertiesHr = ffWinrtCreateHstringIterable(ffBluetoothLeProperties, (uint32_t) ARRAY_SIZE(ffBluetoothLeProperties), &properties); + if (FAILED(propertiesHr) || !properties) { + FF_DEBUG("winrt: building the additional-properties list failed: %s", ffDebugHResult(propertiesHr)); return "winrt: building the additional-properties list failed"; } FF_AUTO_RELEASE_COM_OBJECT abi_t* enumerationStatics = nullptr; - if (FAILED(ffGetActivationFactory(L"Windows.Devices.Enumeration.DeviceInformation", &enumerationStatics)) || !enumerationStatics) { + HRESULT deviceInfoHr = ffGetActivationFactory(L"Windows.Devices.Enumeration.DeviceInformation", &enumerationStatics); + if (FAILED(deviceInfoHr) || !enumerationStatics) { + FF_DEBUG("winrt: RoGetActivationFactory(DeviceInformation) failed: %s", ffDebugHResult(deviceInfoHr)); return "winrt: RoGetActivationFactory(DeviceInformation) failed"; } @@ -307,6 +316,7 @@ extern "C" const char* ffBluetoothDetectLe(FFBluetoothOptions* options, FFlist* }, &found); if (FAILED(hr) || !found) { + FF_DEBUG("winrt: DeviceInformation::FindAllAsync() failed: %s", ffDebugHResult(hr)); return "winrt: DeviceInformation::FindAllAsync() failed"; } diff --git a/src/detection/bluetoothradio/bluetoothradio_windows.c b/src/detection/bluetoothradio/bluetoothradio_windows.c index 11f7879d5..5d2b3dca3 100644 --- a/src/detection/bluetoothradio/bluetoothradio_windows.c +++ b/src/detection/bluetoothradio/bluetoothradio_windows.c @@ -1,4 +1,5 @@ #include "bluetoothradio.h" +#include "common/debug.h" #include "common/library.h" #include "common/io.h" #include "common/windows/unicode.h" @@ -64,8 +65,10 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */) &hRadio); if (!hFind) { if (GetLastError() == ERROR_NO_MORE_ITEMS) { + FF_DEBUG("No Bluetooth radios found or service disabled"); return "No Bluetooth radios found or service disabled"; } else { + FF_DEBUG("BluetoothFindFirstRadio() failed: %s", ffDebugWin32Error(GetLastError())); return "BluetoothFindFirstRadio() failed"; } } diff --git a/src/detection/board/board_windows.c b/src/detection/board/board_windows.c index 7ce50032d..eb0c7d362 100644 --- a/src/detection/board/board_windows.c +++ b/src/detection/board/board_windows.c @@ -1,4 +1,5 @@ #include "board.h" +#include "common/debug.h" #include "common/smbios.h" typedef struct [[gnu::packed]] FFSmbiosBaseboard { @@ -23,11 +24,13 @@ static_assert(offsetof(FFSmbiosBaseboard, ContainedObjectHandles) == 0x0F, const char* ffDetectBoard(FFBoardResult* board) { const FFSmbiosHeaderTable* smbiosTable = ffGetSmbiosHeaderTable(); if (!smbiosTable) { + FF_DEBUG("Baseboard information: failed to get SMBIOS data"); return "Failed to get SMBIOS data"; } const FFSmbiosBaseboard* data = (const FFSmbiosBaseboard*) (*smbiosTable)[FF_SMBIOS_TYPE_BASEBOARD_INFO]; if (!data) { + FF_DEBUG("Baseboard information: section is not found in SMBIOS data"); return "Baseboard information section is not found in SMBIOS data"; } diff --git a/src/detection/bootmgr/bootmgr_windows.c b/src/detection/bootmgr/bootmgr_windows.c index c7cbdb262..c98d1ef78 100644 --- a/src/detection/bootmgr/bootmgr_windows.c +++ b/src/detection/bootmgr/bootmgr_windows.c @@ -1,4 +1,5 @@ #include "bootmgr.h" +#include "common/debug.h" #include "efi_helper.h" #include "common/io.h" #include "common/windows/nt.h" @@ -8,7 +9,9 @@ const char* enablePrivilege(const wchar_t* privilege) { FF_AUTO_CLOSE_FD HANDLE token = nullptr; - if (!NT_SUCCESS(NtOpenProcessToken(NtCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))) { + NTSTATUS status = NtOpenProcessToken(NtCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token); + if (!NT_SUCCESS(status)) { + FF_DEBUG("NtOpenProcessToken() failed: %s", ffDebugNtStatus(status)); return "NtOpenProcessToken() failed"; } @@ -18,15 +21,18 @@ const char* enablePrivilege(const wchar_t* privilege) { (LUID_AND_ATTRIBUTES) { .Attributes = SE_PRIVILEGE_ENABLED } }, }; if (!LookupPrivilegeValueW(nullptr, privilege, &tp.Privileges[0].Luid)) { + FF_DEBUG("LookupPrivilegeValue() failed: %s", ffDebugWin32Error(GetLastError())); return "LookupPrivilegeValue() failed"; } - NTSTATUS status = NtAdjustPrivilegesToken(token, false, &tp, sizeof(tp), nullptr, nullptr); + status = NtAdjustPrivilegesToken(token, false, &tp, sizeof(tp), nullptr, nullptr); if (!NT_SUCCESS(status)) { + FF_DEBUG("NtAdjustPrivilegesToken() failed: %s", ffDebugNtStatus(status)); return "NtAdjustPrivilegesToken() failed"; } if (status == STATUS_NOT_ALL_ASSIGNED) { + FF_DEBUG("NtAdjustPrivilegesToken() did not assign the privilege: %s", ffDebugNtStatus(status)); return "The token does not have the specified privilege; try sudo please"; } @@ -47,10 +53,13 @@ const char* ffDetectBootmgr(FFBootmgrResult* result) { }; ULONG size = sizeof(result->order); - if (!NT_SUCCESS(NtQuerySystemEnvironmentValueEx(&(UNICODE_STRING) RTL_CONSTANT_STRING(L"BootCurrent"), &efiGlobalGuid, &result->order, &size, nullptr))) { + NTSTATUS status = NtQuerySystemEnvironmentValueEx(&(UNICODE_STRING) RTL_CONSTANT_STRING(L"BootCurrent"), &efiGlobalGuid, &result->order, &size, nullptr); + if (!NT_SUCCESS(status)) { + FF_DEBUG("NtQuerySystemEnvironmentValueEx(BootCurrent) failed: %s", ffDebugNtStatus(status)); return "NtQuerySystemEnvironmentValueEx(BootCurrent) failed"; } if (size != sizeof(result->order)) { + FF_DEBUG("NtQuerySystemEnvironmentValueEx(BootCurrent) returned unexpected size"); return "NtQuerySystemEnvironmentValueEx(BootCurrent) returned unexpected size"; } @@ -58,10 +67,13 @@ const char* ffDetectBootmgr(FFBootmgrResult* result) { wchar_t key[9]; swprintf(key, ARRAY_SIZE(key), L"Boot%04X", result->order); size = sizeof(buffer); - if (!NT_SUCCESS(NtQuerySystemEnvironmentValueEx(&(UNICODE_STRING) RTL_CONSTANT_STRING(key), &efiGlobalGuid, buffer, &size, nullptr))) { + status = NtQuerySystemEnvironmentValueEx(&(UNICODE_STRING) RTL_CONSTANT_STRING(key), &efiGlobalGuid, buffer, &size, nullptr); + if (!NT_SUCCESS(status)) { + FF_DEBUG("NtQuerySystemEnvironmentValueEx(Boot####) failed: %s", ffDebugNtStatus(status)); return "NtQuerySystemEnvironmentValueEx(Boot####) failed"; } if (size < sizeof(FFEfiLoadOption) || size == ARRAY_SIZE(buffer)) { + FF_DEBUG("NtQuerySystemEnvironmentValueEx(Boot####) returned unexpected size"); return "NtQuerySystemEnvironmentValueEx(Boot####) returned unexpected size"; } diff --git a/src/detection/camera/camera_windows.cpp b/src/detection/camera/camera_windows.cpp index 22d2fdec1..d997575c2 100644 --- a/src/detection/camera/camera_windows.cpp +++ b/src/detection/camera/camera_windows.cpp @@ -1,5 +1,6 @@ extern "C" { #include "camera.h" +#include "common/debug.h" #include "common/library.h" #include "common/windows/com.h" } @@ -22,20 +23,26 @@ extern "C" const char* ffDetectCamera([[maybe_unused]] FFlist* result) { } FF_AUTO_RELEASE_COM_OBJECT IMFAttributes* attrs = nullptr; - if (FAILED(ffMFCreateAttributes(&attrs, 1))) { + HRESULT hr = ffMFCreateAttributes(&attrs, 1); + if (FAILED(hr)) { + FF_DEBUG("MFCreateAttributes() failed: %s", ffDebugHResult(hr)); return "MFCreateAttributes() failed"; } - if (FAILED(attrs->SetGUID( + hr = attrs->SetGUID( MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, - MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID))) { + MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID); + if (FAILED(hr)) { + FF_DEBUG("SetGUID(MF_*) failed: %s", ffDebugHResult(hr)); return "SetGUID(MF_*) failed"; } IMFActivate** devices = nullptr; uint32_t count; - if (FAILED(ffMFEnumDeviceSources(attrs, &devices, &count))) { + hr = ffMFEnumDeviceSources(attrs, &devices, &count); + if (FAILED(hr)) { + FF_DEBUG("MFEnumDeviceSources() failed: %s", ffDebugHResult(hr)); return "MFEnumDeviceSources() failed"; } diff --git a/src/detection/chassis/chassis_windows.c b/src/detection/chassis/chassis_windows.c index 25b37f85a..693ccc38e 100644 --- a/src/detection/chassis/chassis_windows.c +++ b/src/detection/chassis/chassis_windows.c @@ -1,4 +1,5 @@ #include "chassis.h" +#include "common/debug.h" #include "common/smbios.h" // 7.4 @@ -32,11 +33,13 @@ static_assert(offsetof(FFSmbiosSystemEnclosure, ContainedElements) == 0x15, const char* ffDetectChassis(FFChassisResult* result) { const FFSmbiosHeaderTable* smbiosTable = ffGetSmbiosHeaderTable(); if (!smbiosTable) { + FF_DEBUG("System enclosure: failed to get SMBIOS data"); return "Failed to get SMBIOS data"; } const FFSmbiosSystemEnclosure* data = (const FFSmbiosSystemEnclosure*) (*smbiosTable)[FF_SMBIOS_TYPE_SYSTEM_ENCLOSURE]; if (!data) { + FF_DEBUG("System enclosure: section is not found in SMBIOS data"); return "System enclosure is not found in SMBIOS data"; } diff --git a/src/detection/codec/codec_windows.cpp b/src/detection/codec/codec_windows.cpp index 1820361df..1a84b9df4 100644 --- a/src/detection/codec/codec_windows.cpp +++ b/src/detection/codec/codec_windows.cpp @@ -1,5 +1,6 @@ extern "C" { #include "codec.h" +#include "common/debug.h" #include "common/library.h" #include "common/windows/com.h" #include "common/windows/unicode.h" @@ -523,6 +524,7 @@ const char* detectD3d12va(FFCodecOptions* options, FFlist* result /*list of FFCo }); if (result->length == resultLengthBefore) { + FF_DEBUG("No D3D12 video acceleration support"); return "No D3D12 video acceleration support"; } @@ -539,7 +541,9 @@ const char* ffDetectCodecNative(FFCodecOptions* options, FFlist* result /*list o } FF_AUTO_RELEASE_COM_OBJECT IDXGIFactory1* factory = nullptr; - if (FAILED(ffCreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**) &factory)) || !factory) { + HRESULT hr = ffCreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**) &factory); + if (FAILED(hr) || !factory) { + FF_DEBUG("CreateDXGIFactory1() failed: %s", ffDebugHResult(hr)); return "CreateDXGIFactory1() failed"; } diff --git a/src/detection/cpu/cpu_windows.c b/src/detection/cpu/cpu_windows.c index 8975775d0..725a3bd12 100644 --- a/src/detection/cpu/cpu_windows.c +++ b/src/detection/cpu/cpu_windows.c @@ -1,4 +1,5 @@ #include "cpu.h" +#include "common/debug.h" #include "common/endian.h" #include "common/windows/registry.h" #include "common/windows/nt.h" @@ -34,23 +35,30 @@ const char* detectThermalTemp(const FFCPUOptions* options, double* result) { }; if (options->tempSensor.length > 0) { - if (!NT_SUCCESS(RtlUTF8ToUnicodeN(querySpec.Name, (ULONG) sizeof(querySpec.Name), nullptr, options->tempSensor.chars, (ULONG) options->tempSensor.length + 1))) { + NTSTATUS status = RtlUTF8ToUnicodeN(querySpec.Name, (ULONG) sizeof(querySpec.Name), nullptr, options->tempSensor.chars, (ULONG) options->tempSensor.length + 1); + if (!NT_SUCCESS(status)) { + FF_DEBUG("Invalid temp sensor string: %s", ffDebugNtStatus(status)); return "Invalid temp sensor string"; } } DWORD dataSize = 0; - if (PerfEnumerateCounterSetInstances(nullptr, &querySpec.Identifier.CounterSetGuid, nullptr, 0, &dataSize) != ERROR_NOT_ENOUGH_MEMORY) { + DWORD ret = PerfEnumerateCounterSetInstances(nullptr, &querySpec.Identifier.CounterSetGuid, nullptr, 0, &dataSize); + if (ret != ERROR_NOT_ENOUGH_MEMORY) { + FF_DEBUG("PerfEnumerateCounterSetInstances() failed: %s", ffDebugWin32Error(ret)); return "PerfEnumerateCounterSetInstances() failed"; } if (dataSize <= sizeof(PERF_INSTANCE_HEADER)) { + FF_DEBUG("No `Thermal Zone Information` instances found"); return "No `Thermal Zone Information` instances found"; } { FF_AUTO_FREE PERF_INSTANCE_HEADER* const pHead = malloc(dataSize); - if (PerfEnumerateCounterSetInstances(nullptr, &querySpec.Identifier.CounterSetGuid, pHead, dataSize, &dataSize) != ERROR_SUCCESS) { + ret = PerfEnumerateCounterSetInstances(nullptr, &querySpec.Identifier.CounterSetGuid, pHead, dataSize, &dataSize); + if (ret != ERROR_SUCCESS) { + FF_DEBUG("PerfEnumerateCounterSetInstances() failed to get instance headers: %s", ffDebugWin32Error(ret)); return "PerfEnumerateCounterSetInstances() failed to get instance headers"; } @@ -70,6 +78,7 @@ const char* detectThermalTemp(const FFCPUOptions* options, double* result) { if (dataSize == 0) { if (options->tempSensor.length > 0) { + FF_DEBUG("Unable to find CPU sensor"); return "Unable to find CPU sensor"; } @@ -81,34 +90,45 @@ const char* detectThermalTemp(const FFCPUOptions* options, double* result) { [[gnu::cleanup(ffPerfCloseQueryHandle)]] HANDLE hQuery = nullptr; - if (PerfOpenQueryHandle(nullptr, &hQuery) != ERROR_SUCCESS) { + ret = PerfOpenQueryHandle(nullptr, &hQuery); + if (ret != ERROR_SUCCESS) { + FF_DEBUG("PerfOpenQueryHandle() failed: %s", ffDebugWin32Error(ret)); return "PerfOpenQueryHandle() failed"; } - if (PerfAddCounters(hQuery, &querySpec.Identifier, sizeof(querySpec)) != ERROR_SUCCESS) { + ret = PerfAddCounters(hQuery, &querySpec.Identifier, sizeof(querySpec)); + if (ret != ERROR_SUCCESS) { + FF_DEBUG("PerfAddCounters() failed: %s", ffDebugWin32Error(ret)); return "PerfAddCounters() failed"; } if (querySpec.Identifier.Status != ERROR_SUCCESS) { + FF_DEBUG("PerfAddCounters() reports invalid identifier: %s", ffDebugWin32Error(querySpec.Identifier.Status)); return "PerfAddCounters() reports invalid identifier"; } - if (PerfQueryCounterData(hQuery, nullptr, 0, &dataSize) != ERROR_NOT_ENOUGH_MEMORY) { + ret = PerfQueryCounterData(hQuery, nullptr, 0, &dataSize); + if (ret != ERROR_NOT_ENOUGH_MEMORY) { + FF_DEBUG("PerfQueryCounterData(nullptr) failed: %s", ffDebugWin32Error(ret)); return "PerfQueryCounterData(nullptr) failed"; } if (dataSize <= sizeof(PERF_DATA_HEADER) + sizeof(PERF_COUNTER_HEADER)) { // PERF_ERROR_RETURN, should not happen + FF_DEBUG("instance doesn't exist"); return "instance doesn't exist"; } FF_AUTO_FREE PERF_DATA_HEADER* const pDataHeader = malloc(dataSize); - if (PerfQueryCounterData(hQuery, pDataHeader, dataSize, &dataSize) != ERROR_SUCCESS) { + ret = PerfQueryCounterData(hQuery, pDataHeader, dataSize, &dataSize); + if (ret != ERROR_SUCCESS) { + FF_DEBUG("PerfQueryCounterData(pDataHeader) failed: %s", ffDebugWin32Error(ret)); return "PerfQueryCounterData(pDataHeader) failed"; } PERF_COUNTER_HEADER* pCounterHeader = (PERF_COUNTER_HEADER*) (pDataHeader + 1); if (pCounterHeader->dwType != PERF_MULTIPLE_COUNTERS) { + FF_DEBUG("Invalid counter type"); return "Invalid counter type"; } @@ -190,18 +210,21 @@ static_assert(offsetof(FFSmbiosProcessorInfo, ThreadEnabled) == 0x30, static const char* detectMaxSpeedBySmbios(FFCPUResult* cpu) { const FFSmbiosHeaderTable* smbiosTable = ffGetSmbiosHeaderTable(); if (!smbiosTable) { + FF_DEBUG("Failed to get SMBIOS data"); return "Failed to get SMBIOS data"; } const FFSmbiosProcessorInfo* data = (const FFSmbiosProcessorInfo*) (*smbiosTable)[FF_SMBIOS_TYPE_PROCESSOR_INFO]; if (!data) { + FF_DEBUG("Processor information is not found in SMBIOS data"); return "Processor information is not found in SMBIOS data"; } while (data->ProcessorType != 0x03 /*Central Processor*/ || (data->Status & 0b00000111) != 1 /*Enabled*/) { data = (const FFSmbiosProcessorInfo*) ffSmbiosNextEntry(&data->Header); if (data->Header.Type != FF_SMBIOS_TYPE_PROCESSOR_INFO) { + FF_DEBUG("No active CPU is found in SMBIOS data"); return "No active CPU is found in SMBIOS data"; } } @@ -209,6 +232,7 @@ static const char* detectMaxSpeedBySmbios(FFCPUResult* cpu) { uint32_t speed = FF_READ_LE(data->MaxSpeed); // Sometimes SMBIOS reports invalid value. We assume that max speed is small than 2x of base if (speed < cpu->frequencyBase || speed > cpu->frequencyBase * 2) { + FF_DEBUG("Possible invalid CPU max speed in SMBIOS data. See #800"); return "Possible invalid CPU max speed in SMBIOS data. See #800"; } @@ -236,13 +260,16 @@ static const char* detectNCores(const FFCPUOptions* options, FFCPUResult* cpu) { ULONG length = 0; NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), nullptr, 0, &length); if (length == 0) { + FF_DEBUG("GetLogicalProcessorInformationEx(RelationAll, nullptr, &length) failed"); return "GetLogicalProcessorInformationEx(RelationAll, nullptr, &length) failed"; } FF_AUTO_FREE SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* pProcessorInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*) malloc(length); - if (!NT_SUCCESS(NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), pProcessorInfo, length, &length))) { + NTSTATUS status = NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), pProcessorInfo, length, &length); + if (!NT_SUCCESS(status)) { + FF_DEBUG("GetLogicalProcessorInformationEx(RelationAll, pProcessorInfo, &length) failed: %s", ffDebugNtStatus(status)); return "GetLogicalProcessorInformationEx(RelationAll, pProcessorInfo, &length) failed"; } @@ -283,6 +310,7 @@ static const char* detectNCores(const FFCPUOptions* options, FFCPUResult* cpu) { static const char* detectByRegistry(FFCPUResult* cpu) { FF_AUTO_CLOSE_FD HANDLE hKey = nullptr; if (!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &hKey, nullptr)) { + FF_DEBUG("ffRegOpenKeyForRead() failed for HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"); return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\", &hKey, nullptr) failed"; } @@ -294,6 +322,7 @@ static const char* detectByRegistry(FFCPUResult* cpu) { nullptr)) { ffStrbufTrimRightSpace(&cpu->vendor); } else { + FF_DEBUG("ffRegReadValues() failed for CPU registry key"); return "ffRegReadValues() failed for CPU registry key"; } diff --git a/src/detection/cpucache/cpucache_windows.c b/src/detection/cpucache/cpucache_windows.c index 0bfc57982..8aee4d47e 100644 --- a/src/detection/cpucache/cpucache_windows.c +++ b/src/detection/cpucache/cpucache_windows.c @@ -1,4 +1,5 @@ #include "cpucache.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include "common/windows/nt.h" @@ -7,13 +8,16 @@ const char* ffDetectCPUCache(FFCPUCacheResult* result) { DWORD length = 0; NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), nullptr, 0, &length); if (length == 0) { + FF_DEBUG("GetLogicalProcessorInformationEx(RelationCache, nullptr, &length) failed"); return "GetLogicalProcessorInformationEx(RelationCache, nullptr, &length) failed"; } FF_AUTO_FREE SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* pProcessorInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*) malloc(length); - if (!NT_SUCCESS(NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), pProcessorInfo, length, &length))) { + NTSTATUS status = NtQuerySystemInformationEx(SystemLogicalProcessorAndGroupInformation, &lpr, sizeof(lpr), pProcessorInfo, length, &length); + if (!NT_SUCCESS(status)) { + FF_DEBUG("GetLogicalProcessorInformationEx(RelationCache, pProcessorInfo, &length) failed: %s", ffDebugNtStatus(status)); return "GetLogicalProcessorInformationEx(RelationCache, pProcessorInfo, &length) failed"; } diff --git a/src/detection/cpuusage/cpuusage_windows.c b/src/detection/cpuusage/cpuusage_windows.c index a208c40f4..ada71a439 100644 --- a/src/detection/cpuusage/cpuusage_windows.c +++ b/src/detection/cpuusage/cpuusage_windows.c @@ -10,12 +10,16 @@ static const char* getInfoByNqsi(FFlist* cpuTimes) { ULONG size = 0; - if (NtQuerySystemInformation(SystemProcessorPerformanceInformation, nullptr, 0, &size) != STATUS_INFO_LENGTH_MISMATCH) { + NTSTATUS status = NtQuerySystemInformation(SystemProcessorPerformanceInformation, nullptr, 0, &size); + if (status != STATUS_INFO_LENGTH_MISMATCH) { + FF_DEBUG("NtQuerySystemInformation(SystemProcessorPerformanceInformation, nullptr) failed: %s", ffDebugNtStatus(status)); return "NtQuerySystemInformation(SystemProcessorPerformanceInformation, nullptr) failed"; } FF_AUTO_FREE SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* pinfo = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*) malloc(size); - if (!NT_SUCCESS(NtQuerySystemInformation(SystemProcessorPerformanceInformation, pinfo, size, &size))) { + status = NtQuerySystemInformation(SystemProcessorPerformanceInformation, pinfo, size, &size); + if (!NT_SUCCESS(status)) { + FF_DEBUG("NtQuerySystemInformation(SystemProcessorPerformanceInformation, size) failed: %s", ffDebugNtStatus(status)); return "NtQuerySystemInformation(SystemProcessorPerformanceInformation, size) failed"; } @@ -57,19 +61,24 @@ static const char* getInfoByPerflib(FFlist* cpuTimes) { .Name = PERF_WILDCARD_INSTANCE, }; - if (PerfOpenQueryHandle(nullptr, &hQuery) != ERROR_SUCCESS) { + DWORD ret = PerfOpenQueryHandle(nullptr, &hQuery); + if (ret != ERROR_SUCCESS) { + FF_DEBUG("PerfOpenQueryHandle() failed: %s", ffDebugWin32Error(ret)); PerfCloseQueryHandle(hQuery); hQuery = INVALID_HANDLE_VALUE; return "PerfOpenQueryHandle() failed"; } - if (PerfAddCounters(hQuery, &querySpec.Identifier, sizeof(querySpec)) != ERROR_SUCCESS) { + ret = PerfAddCounters(hQuery, &querySpec.Identifier, sizeof(querySpec)); + if (ret != ERROR_SUCCESS) { + FF_DEBUG("PerfAddCounters() failed: %s", ffDebugWin32Error(ret)); PerfCloseQueryHandle(hQuery); hQuery = INVALID_HANDLE_VALUE; return "PerfAddCounters() failed"; } if (querySpec.Identifier.Status != ERROR_SUCCESS) { + FF_DEBUG("PerfAddCounters() reports invalid identifier: %s", ffDebugWin32Error(querySpec.Identifier.Status)); PerfCloseQueryHandle(hQuery); hQuery = INVALID_HANDLE_VALUE; return "PerfAddCounters() reports invalid identifier"; @@ -77,35 +86,44 @@ static const char* getInfoByPerflib(FFlist* cpuTimes) { } if (hQuery == INVALID_HANDLE_VALUE) { + FF_DEBUG("Init hQuery failed"); return "Init hQuery failed"; } DWORD dataSize = 0; - if (PerfQueryCounterData(hQuery, nullptr, 0, &dataSize) != ERROR_NOT_ENOUGH_MEMORY) { + DWORD ret = PerfQueryCounterData(hQuery, nullptr, 0, &dataSize); + if (ret != ERROR_NOT_ENOUGH_MEMORY) { + FF_DEBUG("PerfQueryCounterData(nullptr) failed: %s", ffDebugWin32Error(ret)); return "PerfQueryCounterData(nullptr) failed"; } if (dataSize <= sizeof(PERF_DATA_HEADER) + sizeof(PERF_COUNTER_HEADER)) { + FF_DEBUG("instance doesn't exist"); return "instance doesn't exist"; } FF_AUTO_FREE PERF_DATA_HEADER* const pDataHeader = (PERF_DATA_HEADER*) malloc(dataSize); - if (PerfQueryCounterData(hQuery, pDataHeader, dataSize, &dataSize) != ERROR_SUCCESS) { + ret = PerfQueryCounterData(hQuery, pDataHeader, dataSize, &dataSize); + if (ret != ERROR_SUCCESS) { + FF_DEBUG("PerfQueryCounterData(pDataHeader) failed: %s", ffDebugWin32Error(ret)); return "PerfQueryCounterData(pDataHeader) failed"; } PERF_COUNTER_HEADER* pCounterHeader = (PERF_COUNTER_HEADER*) (pDataHeader + 1); if (pCounterHeader->dwType != PERF_COUNTERSET) { + FF_DEBUG("Invalid counter type"); return "Invalid counter type"; } PERF_MULTI_COUNTERS* pMultiCounters = (PERF_MULTI_COUNTERS*) (pCounterHeader + 1); if (pMultiCounters->dwCounters == 0) { + FF_DEBUG("No CPU counters found"); return "No CPU counters found"; } PERF_MULTI_INSTANCES* pMultiInstances = (PERF_MULTI_INSTANCES*) ((BYTE*) pMultiCounters + pMultiCounters->dwSize); if (pMultiInstances->dwInstances == 0) { + FF_DEBUG("No CPU instances found"); return "No CPU instances found"; } @@ -135,6 +153,7 @@ static const char* getInfoByPerflib(FFlist* cpuTimes) { if (wcschr(instanceName, L'_') == nullptr /* ignore `_Total` */) { if (processorUtility == UINT64_MAX) { + FF_DEBUG("Counter \"%% Processor Utility\" are not supported"); return "Counter \"% Processor Utility\" are not supported"; } diff --git a/src/detection/disk/disk_windows.c b/src/detection/disk/disk_windows.c index c5093fed2..b2b41de68 100644 --- a/src/detection/disk/disk_windows.c +++ b/src/detection/disk/disk_windows.c @@ -1,4 +1,5 @@ #include "disk.h" +#include "common/debug.h" #include "common/io.h" #include "common/time.h" #include "common/windows/unicode.h" @@ -12,7 +13,9 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { PROCESS_DEVICEMAP_INFORMATION_EX info = {}; ULONG size = 0; - if (!NT_SUCCESS(NtQueryInformationProcess(NtCurrentProcess(), ProcessDeviceMap, &info, sizeof(info), &size))) { + NTSTATUS status = NtQueryInformationProcess(NtCurrentProcess(), ProcessDeviceMap, &info, sizeof(info), &size); + if (!NT_SUCCESS(status)) { + FF_DEBUG("NtQueryInformationProcess(ProcessDeviceMap) failed: %s", ffDebugNtStatus(status)); return "NtQueryInformationProcess(ProcessDeviceMap) failed"; } diff --git a/src/detection/dns/dns_windows.c b/src/detection/dns/dns_windows.c index ac88042fa..f24029b59 100644 --- a/src/detection/dns/dns_windows.c +++ b/src/detection/dns/dns_windows.c @@ -198,16 +198,21 @@ const char* ffDetectDNS(FFDNSOptions* options, FFlist* results) { ifIndex = (NET_IFINDEX) ffNetifGetDefaultRouteV6()->ifIndex; } if (!ifIndex) { + FF_DEBUG("Failed to detect default route"); return "Failed to detect default route"; } NET_LUID luid; - if (ConvertInterfaceIndexToLuid(ifIndex, &luid) != NO_ERROR) { + DWORD ret = ConvertInterfaceIndexToLuid(ifIndex, &luid); + if (ret != NO_ERROR) { + FF_DEBUG("ConvertInterfaceIndexToLuid() failed: %s", ffDebugWin32Error(ret)); return "ConvertInterfaceIndexToLuid() failed"; } GUID guid; - if (ConvertInterfaceLuidToGuid(&luid, &guid) != NO_ERROR) { + ret = ConvertInterfaceLuidToGuid(&luid, &guid); + if (ret != NO_ERROR) { + FF_DEBUG("ConvertInterfaceLuidToGuid() failed: %s", ffDebugWin32Error(ret)); return "ConvertInterfaceLuidToGuid() failed"; } diff --git a/src/detection/font/font_windows.c b/src/detection/font/font_windows.c index 960a75abd..e1260fde2 100644 --- a/src/detection/font/font_windows.c +++ b/src/detection/font/font_windows.c @@ -1,4 +1,5 @@ #include "font.h" +#include "common/debug.h" #include "common/windows/unicode.h" #include "common/windows/registry.h" @@ -23,6 +24,7 @@ static void generateString(FFFontResult* font) { const char* ffDetectFontImpl(FFFontResult* result) { FF_AUTO_CLOSE_FD HANDLE hKey = nullptr; if (!ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Control Panel\\Desktop\\WindowMetrics", &hKey, nullptr)) { + FF_DEBUG("ffRegOpenKeyForRead(Control Panel\\Desktop\\WindowMetrics) failed"); return "ffRegOpenKeyForRead(HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics) failed"; } @@ -41,6 +43,7 @@ const char* ffDetectFontImpl(FFFontResult* result) { FF_ARG(fontBuffers[3], L"StatusFont"), }, nullptr)) { + FF_DEBUG("ffRegReadValues(CaptionFont/MenuFont/MessageFont/StatusFont) failed"); return "ffRegReadValues(HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics) failed"; } diff --git a/src/detection/gamepad/gamepad_windows.c b/src/detection/gamepad/gamepad_windows.c index 4d4371f1b..e54c5eb67 100644 --- a/src/detection/gamepad/gamepad_windows.c +++ b/src/detection/gamepad/gamepad_windows.c @@ -1,4 +1,5 @@ #include "gamepad.h" +#include "common/debug.h" #include "common/io.h" #include "common/mallocHelper.h" #include "common/time.h" @@ -339,13 +340,16 @@ static FFGamepadBatteryKind detectBatteryKind(uint32_t vendorId, uint32_t produc const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) { UINT nDevices = 0; if (GetRawInputDeviceList(nullptr, &nDevices, sizeof(RAWINPUTDEVICELIST))) { + FF_DEBUG("GetRawInputDeviceList(nullptr) failed: %s", ffDebugWin32Error(GetLastError())); return "GetRawInputDeviceList(nullptr) failed"; } if (nDevices == 0) { + FF_DEBUG("No HID devices found"); return "No HID devices found"; } FF_AUTO_FREE RAWINPUTDEVICELIST* pRawInputDeviceList = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * nDevices); if ((nDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST))) == (UINT) -1) { + FF_DEBUG("GetRawInputDeviceList(pRawInputDeviceList) failed: %s", ffDebugWin32Error(GetLastError())); return "GetRawInputDeviceList(pRawInputDeviceList) failed"; } diff --git a/src/detection/host/host_windows.c b/src/detection/host/host_windows.c index a39a3041e..003a94c11 100644 --- a/src/detection/host/host_windows.c +++ b/src/detection/host/host_windows.c @@ -1,4 +1,5 @@ #include "host.h" +#include "common/debug.h" #include "common/endian.h" #include "common/smbios.h" @@ -32,11 +33,13 @@ static_assert(offsetof(FFSmbiosSystemInfo, Family) == 0x1A, const char* ffDetectHost(FFHostResult* host) { const FFSmbiosHeaderTable* smbiosTable = ffGetSmbiosHeaderTable(); if (!smbiosTable) { + FF_DEBUG("System information: failed to get SMBIOS data"); return "Failed to get SMBIOS data"; } const FFSmbiosSystemInfo* data = (const FFSmbiosSystemInfo*) (*smbiosTable)[FF_SMBIOS_TYPE_SYSTEM_INFO]; if (!data) { + FF_DEBUG("System information: section is not found in SMBIOS data"); return "System information is not found in SMBIOS data"; } diff --git a/src/detection/initsystem/initsystem_windows.c b/src/detection/initsystem/initsystem_windows.c index 561d02449..fa2d9a7e7 100644 --- a/src/detection/initsystem/initsystem_windows.c +++ b/src/detection/initsystem/initsystem_windows.c @@ -1,4 +1,5 @@ #include "initsystem.h" +#include "common/debug.h" #include "common/windows/unicode.h" #include "common/windows/nt.h" #include "common/windows/version.h" @@ -52,6 +53,7 @@ fallback: ULONG size = sizeof(buffer); NTSTATUS status = NtQuerySystemInformation(SystemProcessInformation, buffer, size, &size); if (status != STATUS_INFO_LENGTH_MISMATCH && !NT_SUCCESS(status)) { + FF_DEBUG("NtQuerySystemInformation(SystemProcessInformation) failed: %s", ffDebugNtStatus(status)); return "NtQuerySystemInformation(SystemProcessInformation) failed"; } diff --git a/src/detection/keyboard/keyboard_windows.c b/src/detection/keyboard/keyboard_windows.c index 7d98ac4ed..81217c294 100644 --- a/src/detection/keyboard/keyboard_windows.c +++ b/src/detection/keyboard/keyboard_windows.c @@ -1,6 +1,7 @@ #define INITGUID #include "keyboard.h" +#include "common/debug.h" #include "common/io.h" #include "common/mallocHelper.h" #include "common/windows/unicode.h" @@ -13,14 +14,17 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) { UINT nDevices = 0; if (GetRawInputDeviceList(nullptr, &nDevices, sizeof(RAWINPUTDEVICELIST))) { + FF_DEBUG("GetRawInputDeviceList(nullptr) failed: %s", ffDebugWin32Error(GetLastError())); return "GetRawInputDeviceList(nullptr) failed"; } if (nDevices == 0) { + FF_DEBUG("No HID devices found"); return "No HID devices found"; } FF_AUTO_FREE RAWINPUTDEVICELIST* pRawInputDeviceList = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * nDevices); if ((nDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST))) == (UINT) -1) { + FF_DEBUG("GetRawInputDeviceList(pRawInputDeviceList) failed: %s", ffDebugWin32Error(GetLastError())); return "GetRawInputDeviceList(pRawInputDeviceList) failed"; } diff --git a/src/detection/locale/locale_windows.c b/src/detection/locale/locale_windows.c index 75a0e47f0..c70f3923e 100644 --- a/src/detection/locale/locale_windows.c +++ b/src/detection/locale/locale_windows.c @@ -1,4 +1,5 @@ #include "detection/locale/locale.h" +#include "common/debug.h" #include "common/windows/unicode.h" #include @@ -17,6 +18,7 @@ const char* ffDetectLocale(FFstrbuf* result) { wchar_t name[LOCALE_NAME_MAX_LENGTH]; int size = GetUserDefaultLocaleName(name, LOCALE_NAME_MAX_LENGTH); if (size <= 1) { // including '\0' + FF_DEBUG("GetUserDefaultLocaleName() failed"); return "GetUserDefaultLocaleName() failed"; } ffStrbufAppendNWS(result, (uint32_t) size - 1, name); diff --git a/src/detection/media/media_windows.cpp b/src/detection/media/media_windows.cpp index 3f24f3c8b..6f0d2a1fd 100644 --- a/src/detection/media/media_windows.cpp +++ b/src/detection/media/media_windows.cpp @@ -1,5 +1,6 @@ extern "C" { #include "media.h" +#include "common/debug.h" #include "common/time.h" #include "common/windows/unicode.h" #include "common/windows/com.h" @@ -410,6 +411,7 @@ static const char* getMedia(FFMediaResult* result, bool saveCover) { #else static const char* getMedia(FFMediaResult* media, bool saveCover) { FF_UNUSED(media, saveCover); + FF_DEBUG("Fastfetch is not compiled with WinRT support"); return "Fastfetch is not compiled with WinRT support"; } #endif // FF_HAVE_WINRT diff --git a/src/detection/memory/memory_windows.c b/src/detection/memory/memory_windows.c index 2beeb4b2b..0059a3d86 100644 --- a/src/detection/memory/memory_windows.c +++ b/src/detection/memory/memory_windows.c @@ -1,4 +1,5 @@ #include "memory.h" +#include "common/debug.h" #include "common/windows/nt.h" @@ -6,8 +7,11 @@ const char* ffDetectMemory(FFMemoryResult* ram) { // Note: GlobalMemoryStatusEx() internally uses SystemMemoryUsageInformation in Win 10 SYSTEM_BASIC_PERFORMANCE_INFORMATION sbpi; - if (!NT_SUCCESS(NtQuerySystemInformation(SystemBasicPerformanceInformation, &sbpi, sizeof(sbpi), NULL))) + NTSTATUS status = NtQuerySystemInformation(SystemBasicPerformanceInformation, &sbpi, sizeof(sbpi), NULL); + if (!NT_SUCCESS(status)) { + FF_DEBUG("Failed to query memory information: %s", ffDebugNtStatus(status)); return "Failed to query memory information"; + } uint64_t phyPages = #if _WIN64 diff --git a/src/detection/mouse/mouse_windows.c b/src/detection/mouse/mouse_windows.c index d60028182..3eb16c83a 100644 --- a/src/detection/mouse/mouse_windows.c +++ b/src/detection/mouse/mouse_windows.c @@ -1,6 +1,7 @@ #define INITGUID #include "mouse.h" +#include "common/debug.h" #include "common/io.h" #include "common/mallocHelper.h" #include "common/windows/unicode.h" @@ -13,13 +14,16 @@ const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) { UINT nDevices = 0; if (GetRawInputDeviceList(nullptr, &nDevices, sizeof(RAWINPUTDEVICELIST))) { + FF_DEBUG("GetRawInputDeviceList(nullptr) failed: %s", ffDebugWin32Error(GetLastError())); return "GetRawInputDeviceList(nullptr) failed"; } if (nDevices == 0) { + FF_DEBUG("No HID devices found"); return "No HID devices found"; } FF_AUTO_FREE RAWINPUTDEVICELIST* pRawInputDeviceList = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * nDevices); if ((nDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST))) == (UINT) -1) { + FF_DEBUG("GetRawInputDeviceList(pRawInputDeviceList) failed: %s", ffDebugWin32Error(GetLastError())); return "GetRawInputDeviceList(pRawInputDeviceList) failed"; } diff --git a/src/detection/netio/netio_windows.c b/src/detection/netio/netio_windows.c index 86ff930d6..39cdd803f 100644 --- a/src/detection/netio/netio_windows.c +++ b/src/detection/netio/netio_windows.c @@ -1,5 +1,6 @@ #include "netio.h" +#include "common/debug.h" #include "common/netif.h" #include "common/windows/unicode.h" @@ -54,7 +55,9 @@ const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) { // address at all, and those cannot be told apart from real adapters by any MIB_IF_ROW2 field. // GetUnicastIpAddressTable() costs about 72 us, GetIfTable2() about 860 us. PMIB_UNICASTIPADDRESS_TABLE addressTable = nullptr; - if (!NETIO_SUCCESS(GetUnicastIpAddressTable(AF_UNSPEC, &addressTable))) { + DWORD ret = GetUnicastIpAddressTable(AF_UNSPEC, &addressTable); + if (!NETIO_SUCCESS(ret)) { + FF_DEBUG("GetUnicastIpAddressTable() failed: %s", ffDebugWin32Error(ret)); return "GetUnicastIpAddressTable() failed"; } diff --git a/src/detection/opengl/opengl_windows.c b/src/detection/opengl/opengl_windows.c index 5b2262cbb..61c991cbe 100644 --- a/src/detection/opengl/opengl_windows.c +++ b/src/detection/opengl/opengl_windows.c @@ -1,4 +1,5 @@ #include "opengl.h" +#include "common/debug.h" #include "common/library.h" #include "common/printing.h" #include "common/windows/nt.h" @@ -17,11 +18,13 @@ void ffOpenGLHandleResult(FFOpenGLResult* result, typeof(&glGetString) ffglGetSt static const char* wglHandleContext(WGLData* wglData, FFOpenGLResult* result, HDC hdc, HGLRC context) { if (wglData->ffwglMakeCurrent(hdc, context) == FALSE) { + FF_DEBUG("wglMakeCurrent() failed: %s", ffDebugWin32Error(GetLastError())); return "wglMakeCurrent() failed"; } ffOpenGLHandleResult(result, wglData->ffglGetString); ffStrbufSetStatic(&result->library, "WGL 1.0"); if (wglData->ffwglMakeCurrent(nullptr, nullptr) == FALSE) { + FF_DEBUG("wglMakeCurrent(nullptr, nullptr) failed: %s", ffDebugWin32Error(GetLastError())); return "wglMakeCurrent(nullptr, nullptr) failed"; } return nullptr; @@ -31,6 +34,7 @@ static const char* wglHandlePixelFormat(WGLData* wglData, FFOpenGLResult* result HDC hdc = GetDC(hWnd); if (hdc == nullptr) { + FF_DEBUG("GetDC() failed: %s", ffDebugWin32Error(GetLastError())); return "GetDC() failed"; } @@ -45,17 +49,20 @@ static const char* wglHandlePixelFormat(WGLData* wglData, FFOpenGLResult* result }; int pixelFormat = ChoosePixelFormat(hdc, &pfd); if (pixelFormat == 0) { + FF_DEBUG("ChoosePixelFormat() failed: %s", ffDebugWin32Error(GetLastError())); ReleaseDC(hWnd, hdc); return "ChoosePixelFormat() failed"; } if (SetPixelFormat(hdc, pixelFormat, &pfd) == FALSE) { + FF_DEBUG("SetPixelFormat() failed: %s", ffDebugWin32Error(GetLastError())); ReleaseDC(hWnd, hdc); return "SetPixelFormat() failed"; } HGLRC context = wglData->ffwglCreateContext(hdc); if (context == nullptr) { + FF_DEBUG("wglCreateContext() failed: %s", ffDebugWin32Error(GetLastError())); ReleaseDC(hWnd, hdc); return "wglCreateContext() failed"; } @@ -88,11 +95,13 @@ static const char* wglDetectOpenGL(FFOpenGLResult* result) { .style = CS_OWNDC, }; if (!RegisterClassW(&wc)) { + FF_DEBUG("RegisterClassW() failed: %s", ffDebugWin32Error(GetLastError())); return "RegisterClassW() failed"; } HWND hWnd = CreateWindowW(wc.lpszClassName, L"ogl_version_check", 0, 0, 0, FF_OPENGL_BUFFER_WIDTH, FF_OPENGL_BUFFER_HEIGHT, nullptr, nullptr, hInstance, nullptr); if (!hWnd) { + FF_DEBUG("CreateWindowW() failed: %s", ffDebugWin32Error(GetLastError())); return "CreateWindowW() failed"; } @@ -112,9 +121,11 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) { const char* ffOpenGLDetectByEGL(FFOpenGLResult * result); return ffOpenGLDetectByEGL(result); #else + FF_DEBUG("fastfetch was compiled without egl support"); return "fastfetch was compiled without egl support"; #endif } else { + FF_DEBUG("Unsupported OpenGL library"); return "Unsupported OpenGL library"; } } diff --git a/src/detection/physicaldisk/physicaldisk_windows.c b/src/detection/physicaldisk/physicaldisk_windows.c index 56ae1d314..3d6dccc2f 100644 --- a/src/detection/physicaldisk/physicaldisk_windows.c +++ b/src/detection/physicaldisk/physicaldisk_windows.c @@ -12,6 +12,7 @@ static const char* detectPhysicalDisk(const char* physicalType, const wchar_t* szDevice, FFlist* result, FFPhysicalDiskOptions* options) { FF_AUTO_CLOSE_FD HANDLE hDevice = CreateFileW(szDevice, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); if (hDevice == INVALID_HANDLE_VALUE) { + FF_DEBUG("CreateFileW() failed: %s", ffDebugWin32Error(GetLastError())); return "CreateFileW() failed"; } diff --git a/src/detection/processes/processes_windows.c b/src/detection/processes/processes_windows.c index b5d65b301..09c874135 100644 --- a/src/detection/processes/processes_windows.c +++ b/src/detection/processes/processes_windows.c @@ -1,4 +1,5 @@ #include "processes.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include "common/windows/nt.h" @@ -34,6 +35,7 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResu } else if (status == STATUS_INFO_LENGTH_MISMATCH && attempts < 4) { size += sizeof(SYSTEM_PROCESS_INFORMATION) * 5; } else { + FF_DEBUG("NtQuerySystemInformation(SystemProcessInformation) failed: %s", ffDebugNtStatus(status)); return "NtQuerySystemInformation(SystemProcessInformation) failed"; } } diff --git a/src/detection/sound/sound_windows.cpp b/src/detection/sound/sound_windows.cpp index 59823a0b8..1330037c6 100644 --- a/src/detection/sound/sound_windows.cpp +++ b/src/detection/sound/sound_windows.cpp @@ -1,5 +1,6 @@ extern "C" { #include "sound.h" +#include "common/debug.h" #include "common/windows/com.h" } #include "common/windows/unicode.hpp" @@ -21,17 +22,23 @@ static void ffCoTaskMemFreeWrapper(void* pptr) { static const char* detectSoundDevice(FFlist* devices /* List of FFSoundDevice */, IMMDevice* immDevice, LPWSTR mainDeviceId) { FF_COTASK_AUTO_FREE LPWSTR immDeviceId = nullptr; - if (FAILED(immDevice->GetId(&immDeviceId))) { + HRESULT hr = immDevice->GetId(&immDeviceId); + if (FAILED(hr)) { + FF_DEBUG("immDevice->GetId() failed: %s", ffDebugHResult(hr)); return "immDevice->GetId() failed"; } FF_AUTO_RELEASE_COM_OBJECT IPropertyStore* immPropStore = nullptr; - if (FAILED(immDevice->OpenPropertyStore(STGM_READ, &immPropStore))) { + hr = immDevice->OpenPropertyStore(STGM_READ, &immPropStore); + if (FAILED(hr)) { + FF_DEBUG("immDevice->OpenPropertyStore() failed: %s", ffDebugHResult(hr)); return "immDevice->OpenPropertyStore() failed"; } DWORD immState; - if (FAILED(immDevice->GetState(&immState))) { + hr = immDevice->GetState(&immState); + if (FAILED(hr)) { + FF_DEBUG("immDevice->GetState() failed: %s", ffDebugHResult(hr)); return "immDevice->GetState() failed"; } @@ -76,7 +83,9 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices /* List of FF FF_AUTO_RELEASE_COM_OBJECT IMMDeviceEnumerator* pEnum = nullptr; - if (FAILED(CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pEnum)))) { + HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pEnum)); + if (FAILED(hr)) { + FF_DEBUG("CoCreateInstance(CLSID_MMDeviceEnumerator) failed: %s", ffDebugHResult(hr)); return "CoCreateInstance(CLSID_MMDeviceEnumerator) failed"; } @@ -85,7 +94,9 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices /* List of FF { FF_AUTO_RELEASE_COM_OBJECT IMMDevice* pDefaultDevice = nullptr; - if (FAILED(pEnum->GetDefaultAudioEndpoint(eRender, eMultimedia, &pDefaultDevice))) { + HRESULT hrDefault = pEnum->GetDefaultAudioEndpoint(eRender, eMultimedia, &pDefaultDevice); + if (FAILED(hrDefault)) { + FF_DEBUG("GetDefaultAudioEndpoint() failed: %s", ffDebugHResult(hrDefault)); return "GetDefaultAudioEndpoint() failed"; } @@ -93,19 +104,25 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices /* List of FF return detectSoundDevice(devices, pDefaultDevice, nullptr); } - if (FAILED(pDefaultDevice->GetId(&mainDeviceId))) { + hrDefault = pDefaultDevice->GetId(&mainDeviceId); + if (FAILED(hrDefault)) { + FF_DEBUG("pDefaultDevice->GetId() failed: %s", ffDebugHResult(hrDefault)); return "pDefaultDevice->GetId() failed"; } } FF_AUTO_RELEASE_COM_OBJECT IMMDeviceCollection* pDevices = nullptr; - if (FAILED(pEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE | (options->soundType & FF_SOUND_TYPE_ACTIVE ? 0 : DEVICE_STATE_DISABLED), &pDevices))) { + hr = pEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE | (options->soundType & FF_SOUND_TYPE_ACTIVE ? 0 : DEVICE_STATE_DISABLED), &pDevices); + if (FAILED(hr)) { + FF_DEBUG("EnumAudioEndpoints() failed: %s", ffDebugHResult(hr)); return "EnumAudioEndpoints() failed"; } uint32_t deviceCount; - if (FAILED(pDevices->GetCount(&deviceCount))) { + hr = pDevices->GetCount(&deviceCount); + if (FAILED(hr)) { + FF_DEBUG("pDevices->GetCount() failed: %s", ffDebugHResult(hr)); return "pDevices->GetCount() failed"; } diff --git a/src/detection/swap/swap_windows.c b/src/detection/swap/swap_windows.c index 8ce6904e2..5f78eb150 100644 --- a/src/detection/swap/swap_windows.c +++ b/src/detection/swap/swap_windows.c @@ -1,4 +1,5 @@ #include "swap.h" +#include "common/debug.h" #include "common/windows/unicode.h" #include @@ -10,7 +11,9 @@ const char* ffDetectSwap(FFlist* result) { alignas(SYSTEM_PAGEFILE_INFORMATION) uint8_t buffer[4096]; ULONG size = sizeof(buffer); SYSTEM_PAGEFILE_INFORMATION* pstart = (SYSTEM_PAGEFILE_INFORMATION*) buffer; - if (!NT_SUCCESS(NtQuerySystemInformation(SystemPagefileInformation, pstart, size, &size))) { + NTSTATUS status = NtQuerySystemInformation(SystemPagefileInformation, pstart, size, &size); + if (!NT_SUCCESS(status)) { + FF_DEBUG("NtQuerySystemInformation(SystemPagefileInformation, size) failed: %s", ffDebugNtStatus(status)); return "NtQuerySystemInformation(SystemPagefileInformation, size) failed"; } diff --git a/src/detection/terminalfont/terminalfont_windows.c b/src/detection/terminalfont/terminalfont_windows.c index 75636eaac..a41d4056f 100644 --- a/src/detection/terminalfont/terminalfont_windows.c +++ b/src/detection/terminalfont/terminalfont_windows.c @@ -1,3 +1,4 @@ +#include "common/debug.h" #include "common/library.h" #include "common/io.h" #include "common/path.h" @@ -116,6 +117,7 @@ static inline void wrapYyjsonFree(yyjson_doc** doc) { static const char* detectFromWTSettings(FFstrbuf* content, const FFstrbuf* wtProfileId, FFTerminalFontWT* result) { [[gnu::cleanup(wrapYyjsonFree)]] yyjson_doc* doc = yyjson_read_opts(content->chars, content->length, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS, nullptr, nullptr); if (!doc) { + FF_DEBUG("Failed to parse WT JSON config file"); return "Failed to parse WT JSON config file"; } @@ -124,6 +126,7 @@ static const char* detectFromWTSettings(FFstrbuf* content, const FFstrbuf* wtPro yyjson_val* profiles = yyjson_obj_get(root, "profiles"); if (!profiles) { + FF_DEBUG("yyjson_obj_get(root, \"profiles\") failed"); return "yyjson_obj_get(root, \"profiles\") failed"; } diff --git a/src/detection/top/top_windows.c b/src/detection/top/top_windows.c index 33a430af7..33d1d6dd7 100644 --- a/src/detection/top/top_windows.c +++ b/src/detection/top/top_windows.c @@ -1,5 +1,6 @@ #include "top.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include "common/windows/unicode.h" @@ -24,6 +25,7 @@ const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes) { } else if (status == STATUS_INFO_LENGTH_MISMATCH && attempts < 4) { size += sizeof(SYSTEM_PROCESS_INFORMATION) * 5; } else { + FF_DEBUG("NtQuerySystemInformation(SystemProcessInformation) failed: %s", ffDebugNtStatus(status)); return "NtQuerySystemInformation(SystemProcessInformation) failed"; } } diff --git a/src/detection/users/users_windows.c b/src/detection/users/users_windows.c index 837159a74..df6484807 100644 --- a/src/detection/users/users_windows.c +++ b/src/detection/users/users_windows.c @@ -1,4 +1,5 @@ #include "users.h" +#include "common/debug.h" #include "common/windows/unicode.h" #include "common/time.h" @@ -12,6 +13,7 @@ const char* ffDetectUsers(FFUsersOptions* options, FFlist* users) { DWORD level = 1; if (!WTSEnumerateSessionsExW(WTS_CURRENT_SERVER_HANDLE, &level, 0, &sessionInfo, &sessionCount)) { + FF_DEBUG("WTSEnumerateSessionsExW() failed: %s", ffDebugWin32Error(GetLastError())); return "WTSEnumerateSessionsW(WTS_CURRENT_SERVER_HANDLE) failed"; } diff --git a/src/detection/wallpaper/wallpaper_windows.c b/src/detection/wallpaper/wallpaper_windows.c index 7357d39fd..c5e608146 100644 --- a/src/detection/wallpaper/wallpaper_windows.c +++ b/src/detection/wallpaper/wallpaper_windows.c @@ -1,13 +1,16 @@ #include "wallpaper.h" +#include "common/debug.h" #include "common/windows/registry.h" const char* ffDetectWallpaper(FFstrbuf* result) { FF_AUTO_CLOSE_FD HANDLE hKey = nullptr; if (!ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Control Panel\\Desktop", &hKey, nullptr)) { + FF_DEBUG("ffRegOpenKeyForRead(Control Panel\\Desktop) failed"); return "ffRegOpenKeyForRead(Control Panel\\Desktop) failed"; } if (!ffRegReadStrbuf(hKey, L"WallPaper", result, nullptr)) { + FF_DEBUG("ffRegReadStrbuf(WallPaper) failed"); return "ffRegReadStrbuf(WallPaper) failed"; } diff --git a/src/detection/wm/wm_windows.c b/src/detection/wm/wm_windows.c index fbe74544d..ef1da0308 100644 --- a/src/detection/wm/wm_windows.c +++ b/src/detection/wm/wm_windows.c @@ -1,4 +1,5 @@ #include "wm.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include "common/io.h" #include "common/library.h" @@ -208,6 +209,7 @@ fallback: } else if (status == STATUS_INFO_LENGTH_MISMATCH && attempts < 4) { size += sizeof(SYSTEM_PROCESS_INFORMATION) * 5; } else { + FF_DEBUG("NtQuerySystemInformation(SystemProcessInformation) failed: %s", ffDebugNtStatus(status)); return "NtQuerySystemInformation(SystemProcessInformation) failed"; } } @@ -228,6 +230,7 @@ fallback: const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, [[maybe_unused]] FFWMOptions* options) { if (!wmName) { + FF_DEBUG("No WM detected"); return "No WM detected"; } @@ -238,5 +241,6 @@ const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, [[maybe_ return nullptr; } + FF_DEBUG("Not supported on this platform"); return "Not supported on this platform"; }