From 94a6b07a058b1a3478ca97eaba43eca594d18372 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 27 Nov 2021 21:51:38 +0800 Subject: [PATCH] [fix] embed_windows --- listener/tun/dev/wintun/dll_windows.go | 39 ++------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/listener/tun/dev/wintun/dll_windows.go b/listener/tun/dev/wintun/dll_windows.go index 0a36c899..4641ea4b 100644 --- a/listener/tun/dev/wintun/dll_windows.go +++ b/listener/tun/dev/wintun/dll_windows.go @@ -11,9 +11,6 @@ import ( "sync" "sync/atomic" "unsafe" - - C "github.com/Dreamacro/clash/constant" - "golang.org/x/sys/windows" ) func newLazyDLL(name string, onLoad func(d *lazyDLL)) *lazyDLL { @@ -65,7 +62,7 @@ func (p *lazyProc) Addr() uintptr { type lazyDLL struct { Name string mu sync.Mutex - module windows.Handle + module *memmod.Module onLoad func(d *lazyDLL) } @@ -75,7 +72,7 @@ func (d *lazyDLL) Load() error { } d.mu.Lock() defer d.mu.Unlock() - if d.module != 0 { + if d.module != nil { return nil } @@ -92,35 +89,5 @@ 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 + return p.dll.module.ProcAddressByName(p.Name) }