diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-10-20 12:13:44 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-10-20 12:13:44 -0600 |
commit | fdf57a1fa4821c3d82c79325d00f00062ffde699 (patch) | |
tree | f156251f1930e7ba26f01fde60ce2aad3e1173b0 /tun/wintun/dll_windows.go | |
parent | f87e87af0d9a2d41e79770cf1422f01f7e8b303d (diff) |
wintun: allow retrieving DLL version
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tun/wintun/dll_windows.go')
-rw-r--r-- | tun/wintun/dll_windows.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tun/wintun/dll_windows.go b/tun/wintun/dll_windows.go index c96e4a7..3832c1e 100644 --- a/tun/wintun/dll_windows.go +++ b/tun/wintun/dll_windows.go @@ -96,3 +96,33 @@ func (d *lazyDLL) Load() error { func (p *lazyProc) nameToAddr() (uintptr, error) { return windows.GetProcAddress(p.dll.module, p.Name) } + +// Version returns the version of the Wintun DLL. +func Version() string { + if modwintun.Load() != nil { + return "unknown" + } + resInfo, err := windows.FindResource(modwintun.module, windows.ResourceID(1), windows.RT_VERSION) + if err != nil { + return "unknown" + } + data, err := windows.LoadResourceData(modwintun.module, resInfo) + if err != nil { + return "unknown" + } + + var fixedInfo *windows.VS_FIXEDFILEINFO + fixedInfoLen := uint32(unsafe.Sizeof(*fixedInfo)) + err = windows.VerQueryValue(unsafe.Pointer(&data[0]), `\`, unsafe.Pointer(&fixedInfo), &fixedInfoLen) + if err != nil { + return "unknown" + } + version := fmt.Sprintf("%d.%d", (fixedInfo.FileVersionMS>>16)&0xff, (fixedInfo.FileVersionMS>>0)&0xff) + if nextNibble := (fixedInfo.FileVersionLS >> 16) & 0xff; nextNibble != 0 { + version += fmt.Sprintf(".%d", nextNibble) + } + if nextNibble := (fixedInfo.FileVersionLS >> 0) & 0xff; nextNibble != 0 { + version += fmt.Sprintf(".%d", nextNibble) + } + return version +} |