diff options
Diffstat (limited to 'tun')
-rw-r--r-- | tun/wintun/dll_windows.go | 30 | ||||
-rw-r--r-- | tun/wintun/wintun_windows.go | 2 |
2 files changed, 31 insertions, 1 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 +} diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go index 4edad91..b3aa6e9 100644 --- a/tun/wintun/wintun_windows.go +++ b/tun/wintun/wintun_windows.go @@ -129,7 +129,7 @@ func Uninstall() (err error) { return } -// RunningVersion returns the version of the running Wintun driver. +// RunningVersion returns the version of the loaded driver. func RunningVersion() (version uint32, err error) { r0, _, e1 := syscall.Syscall(procWintunGetRunningDriverVersion.Addr(), 0, 0, 0, 0) version = uint32(r0) |