master ohmu/fastfetch-openbsd / src / common / impl / kmod_windows.c
ohmu  ·  2026-10-15
 1#include "common/kmod.h"
 2#include "common/windows/nt.h"
 3#include "common/mallocHelper.h"
 4#include "common/strutil.h"
 5
 6bool ffKmodLoaded(const char* modName) {
 7    ULONG bufferSize = 0;
 8    NtQuerySystemInformation(SystemModuleInformation, nullptr, 0, &bufferSize);
 9    if (bufferSize == 0) {
10        return true; // ignore errors
11    }
12
13    FF_AUTO_FREE RTL_PROCESS_MODULES* buffer = malloc(bufferSize);
14
15    if (!NT_SUCCESS(NtQuerySystemInformation(SystemModuleInformation, buffer, bufferSize, &bufferSize))) {
16        return true; // ignore errors
17    }
18
19    for (ULONG i = 0; i < buffer->NumberOfModules; i++) {
20        const char* name = (const char*) buffer->Modules[i].FullPathName + buffer->Modules[i].OffsetToFileName;
21
22        if (ffStrEqualsIgnCase(name, modName)) {
23            return true;
24        }
25    }
26
27    return false;
28}