mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
[fix] embed_windows
This commit is contained in:
parent
353ae30839
commit
e4b30dacd4
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user