diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-08-28 20:38:30 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-08-30 08:47:21 -0600 |
commit | 2f83e4df50d954decf9abe29197aaecb68a2da7b (patch) | |
tree | 8e4cc0d04e49e5a2bfc60c7dfd11434c05b13242 /version | |
parent | version: bump (diff) | |
download | wireguard-windows-2f83e4df50d954decf9abe29197aaecb68a2da7b.tar.xz wireguard-windows-2f83e4df50d954decf9abe29197aaecb68a2da7b.zip |
version: use ProductName and ProductVersion as strings
Diffstat (limited to 'version')
-rw-r--r-- | version/debugging_linux.go | 4 | ||||
-rw-r--r-- | version/useragent.go | 3 | ||||
-rw-r--r-- | version/version_windows.go | 55 |
3 files changed, 20 insertions, 42 deletions
diff --git a/version/debugging_linux.go b/version/debugging_linux.go index 4564b819..7c9c09c5 100644 --- a/version/debugging_linux.go +++ b/version/debugging_linux.go @@ -30,8 +30,8 @@ func OsName() string { return fmt.Sprintf("%s %s %s", utsToStr(utsname.Sysname), utsToStr(utsname.Release), utsToStr(utsname.Version)) } -func RunningVersion() string { - return "0.0.0.0" +func RunningNameVersion() (string, string) { + return "WireGuard", "0.0.0.0" } func VerifyAuthenticode(path string) bool { diff --git a/version/useragent.go b/version/useragent.go index 6fa62d40..52fb5c83 100644 --- a/version/useragent.go +++ b/version/useragent.go @@ -11,5 +11,6 @@ import ( ) func UserAgent() string { - return fmt.Sprintf("WireGuard/%s (%s; %s)", RunningVersion(), OsName(), runtime.GOARCH) + name, ver := RunningNameVersion() + return fmt.Sprintf("%s/%s (%s; %s)", name, ver, OsName(), runtime.GOARCH) } diff --git a/version/version_windows.go b/version/version_windows.go index b8775b7d..b583d160 100644 --- a/version/version_windows.go +++ b/version/version_windows.go @@ -6,11 +6,8 @@ package version import ( - "errors" - "fmt" "os" "runtime" - "strings" "unsafe" "golang.org/x/sys/windows" @@ -20,31 +17,12 @@ import ( //sys GetFileVersionInfo(filename *uint16, zero uint32, size uint32, block *byte) (err error) = version.GetFileVersionInfoW //sys VerQueryValue(block *byte, section *uint16, value **byte, size *uint32) (err error) = version.VerQueryValueW -type vsFixedFileInfo 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 -} - -const vsFixedFileInfoSignature = 0xFEEF04BD - -var cachedVersion string +var cachedVersion, cachedName string -func RunningVersion() string { - if len(cachedVersion) != 0 { - return cachedVersion +func RunningNameVersion() (name, version string) { + if len(cachedVersion) != 0 || len(cachedName) != 0 { + return cachedName, cachedVersion } - key16 := []uint16{'\\', 0x00} self, err := os.Executable() if err != nil { panic(err) @@ -63,22 +41,21 @@ func RunningVersion() string { if err != nil { panic(err) } - var fixedFileInfo *vsFixedFileInfo - err = VerQueryValue(&buffer[0], &key16[0], (**byte)(unsafe.Pointer(&fixedFileInfo)), &size) + + var val16 *uint16 + err = VerQueryValue(&buffer[0], windows.StringToUTF16Ptr(`\StringFileInfo\040904b0\ProductName`), (**byte)(unsafe.Pointer(&val16)), &size) if err != nil { panic(err) } - if uintptr(size) < unsafe.Sizeof(vsFixedFileInfo{}) || fixedFileInfo == nil || fixedFileInfo.Signature != vsFixedFileInfoSignature { - panic(errors.New("Incorrect return of VS_FIXEDFILEINFO")) - } - version := fmt.Sprintf("%d.%d.%d.%d", (fixedFileInfo.FileVersionMS>>16)&0xffff, (fixedFileInfo.FileVersionMS>>0)&0xffff, (fixedFileInfo.FileVersionLS>>16)&0xffff, (fixedFileInfo.FileVersionLS>>0)&0xffff) - runtime.KeepAlive(buffer) // The win32 API aliases it in fixedFileInfo, but Go doesn't know that. - if strings.HasSuffix(version, ".0") { - version = version[:len(version)-2] - } - if strings.HasSuffix(version, ".0") { - version = version[:len(version)-2] + name = windows.UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(val16))[:size]) + err = VerQueryValue(&buffer[0], windows.StringToUTF16Ptr(`\StringFileInfo\040904b0\ProductVersion`), (**byte)(unsafe.Pointer(&val16)), &size) + if err != nil { + panic(err) } + version = windows.UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(val16))[:size]) + runtime.KeepAlive(buffer) + + cachedName = name cachedVersion = version - return version + return } |