[fix] embed_windows

This commit is contained in:
gVisor bot 2021-11-27 21:51:38 +08:00
parent c4e5539d4e
commit 94a6b07a05

View file

@ -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)
}