aboutsummaryrefslogtreecommitdiffstats
path: root/tun/wintun
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-10-20 12:13:44 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2021-10-20 12:13:44 -0600
commitfdf57a1fa4821c3d82c79325d00f00062ffde699 (patch)
treef156251f1930e7ba26f01fde60ce2aad3e1173b0 /tun/wintun
parentversion: bump snapshot (diff)
downloadwireguard-go-fdf57a1fa4821c3d82c79325d00f00062ffde699.tar.xz
wireguard-go-fdf57a1fa4821c3d82c79325d00f00062ffde699.zip
wintun: allow retrieving DLL version
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tun/wintun')
-rw-r--r--tun/wintun/dll_windows.go30
-rw-r--r--tun/wintun/wintun_windows.go2
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)