diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-11-06 10:25:15 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-11-06 10:25:15 +0100 |
commit | ed0465b8a7730cf022e119d40330469e60e0fc22 (patch) | |
tree | acfb148b042838c3dd6d62e80535c98d97e5eb82 | |
parent | driver: move to subfolder (diff) | |
download | wintun-ed0465b8a7730cf022e119d40330469e60e0fc22.tar.xz wintun-ed0465b8a7730cf022e119d40330469e60e0fc22.zip |
api: avoid loading version.dll if not used
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | api/adapter.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/api/adapter.c b/api/adapter.c index 8a0c772..6c1a5b5 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -1082,8 +1082,8 @@ static _Return_type_success_(return != FALSE) BOOL return TRUE; } -DWORD WINAPI -WintunGetRunningDriverVersion(void) +static DWORD WINAPI +MaybeGetRunningDriverVersion(BOOL ReturnOneIfRunningInsteadOfVersion) { PRTL_PROCESS_MODULES Modules; ULONG BufferSize = 128 * 1024; @@ -1108,6 +1108,11 @@ WintunGetRunningDriverVersion(void) const char *NtPath = (const char *)Modules->Modules[i].FullPathName; if (!_stricmp(&NtPath[Modules->Modules[i].OffsetToFileName], "wintun.sys")) { + if (ReturnOneIfRunningInsteadOfVersion) + { + Version = 1; + goto cleanupModules; + } WCHAR FilePath[MAX_PATH * 3 + 15]; if (_snwprintf_s(FilePath, _countof(FilePath), _TRUNCATE, L"\\\\?\\GLOBALROOT%S", NtPath) == -1) continue; @@ -1123,11 +1128,17 @@ cleanupModules: return RET_ERROR(Version, LastError); } +DWORD WINAPI +WintunGetRunningDriverVersion(void) +{ + return MaybeGetRunningDriverVersion(FALSE); +} + static BOOL EnsureWintunUnloaded(void) { BOOL Loaded; - for (int i = 0; (Loaded = WintunGetRunningDriverVersion() != 0) != FALSE && i < 300; ++i) + for (int i = 0; (Loaded = MaybeGetRunningDriverVersion(TRUE) != 0) != FALSE && i < 300; ++i) Sleep(50); return !Loaded; } |