summaryrefslogtreecommitdiffstats
path: root/src/common/impl/kmod_windows.c
blob: 081e5a788cd8133190cf52e7e9caa6faa2690cf1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "common/kmod.h"
#include "common/windows/nt.h"
#include "common/mallocHelper.h"
#include "common/strutil.h"

bool ffKmodLoaded(const char* modName) {
    ULONG bufferSize = 0;
    NtQuerySystemInformation(SystemModuleInformation, NULL, 0, &bufferSize);
    if (bufferSize == 0) {
        return true; // ignore errors
    }

    FF_AUTO_FREE RTL_PROCESS_MODULES* buffer = malloc(bufferSize);

    if (!NT_SUCCESS(NtQuerySystemInformation(SystemModuleInformation, buffer, bufferSize, &bufferSize))) {
        return true; // ignore errors
    }

    for (ULONG i = 0; i < buffer->NumberOfModules; i++) {
        const char* name = (const char*) buffer->Modules[i].FullPathName + buffer->Modules[i].OffsetToFileName;

        if (ffStrEqualsIgnCase(name, modName)) {
            return true;
        }
    }

    return false;
}