aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/driver
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 /driver
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>
Diffstat (limited to 'driver')
-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
5 files changed, 35 insertions, 71 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
-}