aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-10-19 17:39:22 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2021-10-21 01:51:40 -0600
commita8236761c5867c53cbb30559c569dce8194b1a31 (patch)
treea8b24a73f71085548258aaf46f412be6ad4cf3fb
parentui: show driver version in about page (diff)
downloadwireguard-windows-a8236761c5867c53cbb30559c569dce8194b1a31.tar.xz
wireguard-windows-a8236761c5867c53cbb30559c569dce8194b1a31.zip
mod: bump for x/sys changes
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--driver/dll_windows.go32
-rw-r--r--driver/driver_windows.go2
-rw-r--r--driver/memmod/memmod_windows.go5
-rw-r--r--driver/memmod/syscall_windows.go6
-rw-r--r--driver/version_windows.go61
-rw-r--r--go.mod4
-rw-r--r--go.sum6
-rw-r--r--manager/pitfalls.go75
8 files changed, 56 insertions, 135 deletions
diff --git a/driver/dll_windows.go b/driver/dll_windows.go
index 968a90cb..0c4b2ee7 100644
--- a/driver/dll_windows.go
+++ b/driver/dll_windows.go
@@ -10,6 +10,8 @@ import (
"sync"
"sync/atomic"
"unsafe"
+
+ "golang.org/x/sys/windows"
)
func newLazyDLL(name string, onLoad func(d *lazyDLL)) *lazyDLL {
@@ -57,3 +59,33 @@ func (p *lazyProc) Addr() uintptr {
}
return p.addr
}
+
+// Version returns the version of the driver DLL.
+func Version() string {
+ if modwireguard.Load() != nil {
+ return "unknown"
+ }
+ resInfo, err := windows.FindResource(modwireguard.Base, windows.ResourceID(1), windows.RT_VERSION)
+ if err != nil {
+ return "unknown"
+ }
+ data, err := windows.LoadResourceData(modwireguard.Base, 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
+} \ No newline at end of file
diff --git a/driver/driver_windows.go b/driver/driver_windows.go
index 42ba3e2e..ac002feb 100644
--- a/driver/driver_windows.go
+++ b/driver/driver_windows.go
@@ -149,7 +149,7 @@ func (wireguard *Adapter) SetLogging(logState AdapterLogState) (err error) {
return
}
-// RunningVersion returns the version of the running WireGuard driver.
+// RunningVersion returns the version of the loaded driver.
func RunningVersion() (version uint32, err error) {
r0, _, e1 := syscall.Syscall(procWireGuardGetRunningDriverVersion.Addr(), 0, 0, 0, 0)
version = uint32(r0)
diff --git a/driver/memmod/memmod_windows.go b/driver/memmod/memmod_windows.go
index 5ded40ea..424e98b9 100644
--- a/driver/memmod/memmod_windows.go
+++ b/driver/memmod/memmod_windows.go
@@ -164,14 +164,13 @@ func (module *Module) finalizeSection(sectionData *sectionFinalizeData) error {
return nil
}
-var rtlAddFunctionTable = windows.NewLazySystemDLL("ntdll.dll").NewProc("RtlAddFunctionTable")
-
func (module *Module) registerExceptionHandlers() {
directory := module.headerDirectory(IMAGE_DIRECTORY_ENTRY_EXCEPTION)
if directory.Size == 0 || directory.VirtualAddress == 0 {
return
}
- rtlAddFunctionTable.Call(module.codeBase+uintptr(directory.VirtualAddress), uintptr(directory.Size)/unsafe.Sizeof(IMAGE_RUNTIME_FUNCTION_ENTRY{}), module.codeBase)
+ runtimeFuncs := (*windows.RUNTIME_FUNCTION)(unsafe.Pointer(module.codeBase+uintptr(directory.VirtualAddress)))
+ windows.RtlAddFunctionTable(runtimeFuncs, uint32(uintptr(directory.Size)/unsafe.Sizeof(*runtimeFuncs)), module.codeBase)
}
func (module *Module) finalizeSections() error {
diff --git a/driver/memmod/syscall_windows.go b/driver/memmod/syscall_windows.go
index a111f92e..b79be69e 100644
--- a/driver/memmod/syscall_windows.go
+++ b/driver/memmod/syscall_windows.go
@@ -370,12 +370,6 @@ const (
IMAGE_GUARD_CF_FUNCTION_TABLE_SIZE_SHIFT = 28
)
-type IMAGE_RUNTIME_FUNCTION_ENTRY struct {
- BeginAddress uint32
- EndAddress uint32
- UnwindInfoAddress uint32
-}
-
const (
DLL_PROCESS_ATTACH = 1
DLL_THREAD_ATTACH = 2
diff --git a/driver/version_windows.go b/driver/version_windows.go
deleted file mode 100644
index dadd8087..00000000
--- a/driver/version_windows.go
+++ /dev/null
@@ -1,61 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
- */
-
-package driver
-
-import (
- "fmt"
- "unsafe"
-
- "golang.org/x/sys/windows"
-)
-
-/* TODO: put this into x/sys/windows */
-var verQueryValue = windows.NewLazySystemDLL("version.dll").NewProc("VerQueryValueW")
-
-type VS_FIXEDFILEINFO struct {
- Signature uint32
- StrucVersion uint32
- FileVersionMS uint32
- FileVersionLS uint32
- ProductVersionMS uint32
- ProductVersionLS uint32
- FileFlagsMask uint32
- FileFlags uint32
- FileOS uint32
- FileType uint32
- FileSubtype uint32
- FileDateMS uint32
- FileDateLS uint32
-}
-
-func Version() string {
- if modwireguard.Load() != nil {
- return "unknown"
- }
- resInfo, err := windows.FindResource(modwireguard.Base, windows.ResourceID(1), windows.RT_VERSION)
- if err != nil {
- return "unknown"
- }
- data, err := windows.LoadResourceData(modwireguard.Base, resInfo)
- if err != nil {
- return "unknown"
- }
-
- var fixedInfo *VS_FIXEDFILEINFO
- fixedInfoLen := uint32(unsafe.Sizeof(*fixedInfo))
- ret, _, _ := verQueryValue.Call(uintptr(unsafe.Pointer(&data[0])), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(`\`))), uintptr(unsafe.Pointer(&fixedInfo)), uintptr(unsafe.Pointer(&fixedInfoLen)))
- if ret == 0 {
- 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/go.mod b/go.mod
index 476a9f49..af95fd6d 100644
--- a/go.mod
+++ b/go.mod
@@ -6,8 +6,8 @@ require (
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794
github.com/lxn/win v0.0.0-20210218163916-a377121e959e
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
- golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0
- golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac
+ golang.org/x/net v0.0.0-20211020060615-d418f374d309
+ golang.org/x/sys v0.0.0-20211020174200-9d6173849985
golang.org/x/text v0.3.8-0.20211004125949-5bd84dd9b33b
)
diff --git a/go.sum b/go.sum
index 05ef0e52..25088f84 100644
--- a/go.sum
+++ b/go.sum
@@ -6,13 +6,13 @@ golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw=
-golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211020174200-9d6173849985 h1:LOlKVhfDyahgmqa97awczplwkjzNaELFg3zRIJ13RYo=
+golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.8-0.20211004125949-5bd84dd9b33b h1:NXqSWXSRUSCaFuvitrWtU169I3876zRTalMRbfd6LL0=
golang.org/x/text v0.3.8-0.20211004125949-5bd84dd9b33b/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
diff --git a/manager/pitfalls.go b/manager/pitfalls.go
index b178b615..4f738a6d 100644
--- a/manager/pitfalls.go
+++ b/manager/pitfalls.go
@@ -44,66 +44,21 @@ func pitfallDnsCacheDisabled() {
log.Printf("Warning: the %q (dnscache) service is disabled; please re-enable it", cfg.DisplayName)
}
-/* TODO: put this into x/sys/windows */
-
-var versionDll = windows.NewLazySystemDLL("version.dll")
-var getFileVersionInfo = versionDll.NewProc("GetFileVersionInfoW")
-var getFileVersionInfoSize = versionDll.NewProc("GetFileVersionInfoSizeW")
-var verQueryValue = versionDll.NewProc("VerQueryValueW")
-
-type VS_FIXEDFILEINFO struct {
- Signature uint32
- StrucVersion uint32
- FileVersionMS uint32
- FileVersionLS uint32
- ProductVersionMS uint32
- ProductVersionLS uint32
- FileFlagsMask uint32
- FileFlags uint32
- FileOS uint32
- FileType uint32
- FileSubtype uint32
- FileDateMS uint32
- FileDateLS uint32
-}
-
-var ntQuerySystemInformation = windows.NewLazySystemDLL("ntdll.dll").NewProc("NtQuerySystemInformation")
-
-const systemModuleInformation = 11
-
-type RTL_PROCESS_MODULE_INFORMATION struct {
- Section windows.Handle
- MappedBase uintptr
- ImageBase uintptr
- ImageSize uint32
- Flags uint32
- LoadOrderIndex uint16
- InitOrderIndex uint16
- LoadCount uint16
- OffsetToFileName uint16
- FullPathName [256]byte
-}
-
-type RTL_PROCESS_MODULES struct {
- NumberOfModules uint32
- FirstModule RTL_PROCESS_MODULE_INFORMATION
-}
-
func pitfallVirtioNetworkDriver() {
- var modules []RTL_PROCESS_MODULE_INFORMATION
+ var modules []windows.RTL_PROCESS_MODULE_INFORMATION
for bufferSize := uint32(128 * 1024); ; {
moduleBuffer := make([]byte, bufferSize)
- ret, _, _ := ntQuerySystemInformation.Call(systemModuleInformation, uintptr(unsafe.Pointer(&moduleBuffer[0])), uintptr(bufferSize), uintptr(unsafe.Pointer(&bufferSize)))
- switch windows.NTStatus(ret) {
+ err := windows.NtQuerySystemInformation(windows.SystemModuleInformation, unsafe.Pointer(&moduleBuffer[0]), bufferSize, &bufferSize)
+ switch err {
case windows.STATUS_INFO_LENGTH_MISMATCH:
continue
- case windows.STATUS_SUCCESS:
+ case nil:
break
default:
return
}
- mods := (*RTL_PROCESS_MODULES)(unsafe.Pointer(&moduleBuffer[0]))
- modules = unsafe.Slice(&mods.FirstModule, mods.NumberOfModules)
+ mods := (*windows.RTL_PROCESS_MODULES)(unsafe.Pointer(&moduleBuffer[0]))
+ modules = unsafe.Slice(&mods.Modules[0], mods.NumberOfModules)
break
}
for i := range modules {
@@ -111,18 +66,20 @@ func pitfallVirtioNetworkDriver() {
continue
}
driverPath := `\\?\GLOBALROOT` + windows.ByteSliceToString(modules[i].FullPathName[:])
- zero := uint32(0)
- ret, _, _ := getFileVersionInfoSize.Call(uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(driverPath))), uintptr(unsafe.Pointer(&zero)))
- if ret == 0 {
+ var zero windows.Handle
+ infoSize, err := windows.GetFileVersionInfoSize(driverPath, &zero)
+ if err != nil {
return
}
- infoSize := uint32(ret)
versionInfo := make([]byte, infoSize)
- ret, _, _ = getFileVersionInfo.Call(uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(driverPath))), 0, uintptr(infoSize), uintptr(unsafe.Pointer(&versionInfo[0])))
- var fixedInfo *VS_FIXEDFILEINFO
+ err = windows.GetFileVersionInfo(driverPath, 0, infoSize, unsafe.Pointer(&versionInfo[0]))
+ if err != nil {
+ return
+ }
+ var fixedInfo *windows.VS_FIXEDFILEINFO
fixedInfoLen := uint32(unsafe.Sizeof(*fixedInfo))
- ret, _, _ = verQueryValue.Call(uintptr(unsafe.Pointer(&versionInfo[0])), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(`\`))), uintptr(unsafe.Pointer(&fixedInfo)), uintptr(unsafe.Pointer(&fixedInfoLen)))
- if ret == 0 {
+ err = windows.VerQueryValue(unsafe.Pointer(&versionInfo[0]), `\`, unsafe.Pointer(&fixedInfo), &fixedInfoLen)
+ if err != nil {
return
}
const minimumGoodVersion = (100 << 48) | (85 << 32) | (104 << 16) | (20800 << 0)