api: account for nt path to module
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
60ad907b99
commit
b65e35569b
@ -1026,7 +1026,7 @@ RunningWintunVersion(void)
|
|||||||
{
|
{
|
||||||
DWORDLONG Version = 0;
|
DWORDLONG Version = 0;
|
||||||
PRTL_PROCESS_MODULES Modules;
|
PRTL_PROCESS_MODULES Modules;
|
||||||
ULONG BufferSize = 2048;
|
ULONG BufferSize = 128 * 1024;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
Modules = HeapAlloc(ModuleHeap, 0, BufferSize);
|
Modules = HeapAlloc(ModuleHeap, 0, BufferSize);
|
||||||
@ -1044,21 +1044,15 @@ RunningWintunVersion(void)
|
|||||||
LOG(WINTUN_LOG_ERR, L"Failed to enumerate drivers");
|
LOG(WINTUN_LOG_ERR, L"Failed to enumerate drivers");
|
||||||
return Version;
|
return Version;
|
||||||
}
|
}
|
||||||
for (ULONG i = 0; i < Modules->NumberOfModules; ++i)
|
for (ULONG i = Modules->NumberOfModules; i-- > 0;)
|
||||||
{
|
{
|
||||||
if (!_stricmp(
|
const char *NtPath = (const char *)Modules->Modules[i].FullPathName;
|
||||||
(const char *)&Modules->Modules[i].FullPathName[Modules->Modules[i].OffsetToFileName], "wintun.sys"))
|
if (!_stricmp(&NtPath[Modules->Modules[i].OffsetToFileName], "wintun.sys"))
|
||||||
{
|
{
|
||||||
size_t Size = strlen((const char *)Modules->Modules[i].FullPathName) + 1;
|
WCHAR FilePath[MAX_PATH * 3 + 15];
|
||||||
WCHAR *FilePathName = HeapAlloc(ModuleHeap, 0, Size * 2);
|
if (_snwprintf_s(FilePath, _countof(FilePath), _TRUNCATE, L"\\\\?\\GLOBALROOT%S", NtPath) == -1)
|
||||||
if (!FilePathName)
|
continue;
|
||||||
{
|
Version = VersionOfFile(FilePath);
|
||||||
LOG(WINTUN_LOG_ERR, L"Out of memory");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
mbstowcs_s(&Size, FilePathName, Size, (const char *)Modules->Modules[i].FullPathName, _TRUNCATE);
|
|
||||||
Version = VersionOfFile(FilePathName);
|
|
||||||
HeapFree(ModuleHeap, 0, FilePathName);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user