aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-21 23:13:19 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-22 22:00:32 +0100
commitcfde14234176b750da47890866f3d1023aa2e3a5 (patch)
tree1cd1ac5bbad938ddc78465264f72d45723a28fe7
parentconf: always use 64-bit registry view on 64-bit machines (diff)
downloadwireguard-windows-cfde14234176b750da47890866f3d1023aa2e3a5.tar.xz
wireguard-windows-cfde14234176b750da47890866f3d1023aa2e3a5.zip
version: unify architecture string handling
Always report native architecture and use "x86" instead of "386" for all identification strings, except when explicitly stating the Go verison. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--ui/aboutdialog.go2
-rw-r--r--updater/versions.go6
-rw-r--r--updater/versions_arm.go28
-rw-r--r--updater/versions_default.go28
-rw-r--r--version/useragent.go56
5 files changed, 57 insertions, 63 deletions
diff --git a/ui/aboutdialog.go b/ui/aboutdialog.go
index 007ddea6..f266a29c 100644
--- a/ui/aboutdialog.go
+++ b/ui/aboutdialog.go
@@ -95,7 +95,7 @@ func runAboutDialog(owner walk.Form) error {
return err
}
detailsLbl.SetTextAlignment(walk.AlignHCenterVNear)
- detailsLbl.SetText(l18n.Sprintf("App version: %s\nGo backend version: %s\nGo version: %s\nOperating system: %s\nArchitecture: %s", version.Number, device.WireGuardGoVersion, strings.TrimPrefix(runtime.Version(), "go"), version.OsName(), runtime.GOARCH))
+ detailsLbl.SetText(l18n.Sprintf("App version: %s\nGo backend version: %s\nGo version: %s-%s\nOperating system: %s\nArchitecture: %s", version.Number, device.WireGuardGoVersion, strings.TrimPrefix(runtime.Version(), "go"), runtime.GOARCH, version.OsName(), version.NativeArch()))
copyrightLbl, err := walk.NewTextLabel(showingAboutDialog)
if err != nil {
diff --git a/updater/versions.go b/updater/versions.go
index 08830d32..0ac1b5eb 100644
--- a/updater/versions.go
+++ b/updater/versions.go
@@ -54,11 +54,7 @@ func versionNewerThanUs(candidate string) (bool, error) {
}
func findCandidate(candidates fileList) (*UpdateFound, error) {
- arch, err := findArch()
- if err != nil {
- return nil, err
- }
- prefix := fmt.Sprintf(msiArchPrefix, arch)
+ prefix := fmt.Sprintf(msiArchPrefix, version.NativeArch())
suffix := msiSuffix
for name, hash := range candidates {
if strings.HasPrefix(name, prefix) && strings.HasSuffix(name, suffix) {
diff --git a/updater/versions_arm.go b/updater/versions_arm.go
deleted file mode 100644
index 45b53be5..00000000
--- a/updater/versions_arm.go
+++ /dev/null
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019-2020 WireGuard LLC. All Rights Reserved.
- */
-
-package updater
-
-import (
- "debug/pe"
- "errors"
-
- "golang.org/x/sys/windows"
-)
-
-func findArch() (string, error) {
- var processMachine, nativeMachine uint16
- err := windows.IsWow64Process2(windows.CurrentProcess(), &processMachine, &nativeMachine)
- if err != nil {
- return "", err
- }
- switch nativeMachine {
- case pe.IMAGE_FILE_MACHINE_ARM64:
- return "arm64", nil
- case pe.IMAGE_FILE_MACHINE_ARMNT:
- return "arm", nil
- }
- return "", errors.New("Invalid GOARCH")
-}
diff --git a/updater/versions_default.go b/updater/versions_default.go
deleted file mode 100644
index 268e97ce..00000000
--- a/updater/versions_default.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// +build !arm
-
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019-2020 WireGuard LLC. All Rights Reserved.
- */
-
-package updater
-
-import (
- "errors"
- "runtime"
-)
-
-func findArch() (arch string, err error) {
- if runtime.GOARCH == "amd64" {
- arch = "amd64"
- } else if runtime.GOARCH == "386" {
- arch = "x86"
- } else if runtime.GOARCH == "arm" {
- arch = "arm"
- } else if runtime.GOARCH == "arm64" {
- arch = "arm64"
- } else {
- err = errors.New("Invalid GOARCH")
- }
- return
-}
diff --git a/version/useragent.go b/version/useragent.go
index 77633765..e0781e29 100644
--- a/version/useragent.go
+++ b/version/useragent.go
@@ -6,10 +6,64 @@
package version
import (
+ "debug/pe"
+ "errors"
"fmt"
"runtime"
+
+ "golang.org/x/sys/windows"
)
+var arch string
+
+func NativeArch() string {
+ if len(arch) > 0 {
+ return arch
+ }
+ var processMachine, nativeMachine uint16
+ err := windows.IsWow64Process2(windows.CurrentProcess(), &processMachine, &nativeMachine)
+ if err != nil && errors.Is(err, windows.ERROR_PROC_NOT_FOUND) {
+ var b bool
+ err = windows.IsWow64Process(windows.CurrentProcess(), &b)
+ if err != nil {
+ panic(err)
+ }
+ if b && runtime.GOARCH == "x86" {
+ nativeMachine = pe.IMAGE_FILE_MACHINE_AMD64
+ } else if b && runtime.GOARCH == "arm" {
+ nativeMachine = pe.IMAGE_FILE_MACHINE_ARM64
+ } else {
+ switch runtime.GOARCH {
+ case "arm":
+ nativeMachine = pe.IMAGE_FILE_MACHINE_ARMNT
+ case "arm64":
+ nativeMachine = pe.IMAGE_FILE_MACHINE_ARM64
+ case "amd64":
+ nativeMachine = pe.IMAGE_FILE_MACHINE_AMD64
+ case "386":
+ nativeMachine = pe.IMAGE_FILE_MACHINE_I386
+ default:
+ panic("Unrecognized GOARCH")
+ }
+ }
+ } else if err != nil {
+ panic(err)
+ }
+ switch nativeMachine {
+ case pe.IMAGE_FILE_MACHINE_ARMNT:
+ arch = "arm"
+ case pe.IMAGE_FILE_MACHINE_ARM64:
+ arch = "arm64"
+ case pe.IMAGE_FILE_MACHINE_AMD64:
+ arch = "amd64"
+ case pe.IMAGE_FILE_MACHINE_I386:
+ arch = "x86"
+ default:
+ panic("Unrecognized machine type")
+ }
+ return arch
+}
+
func UserAgent() string {
- return fmt.Sprintf("WireGuard/%s (%s; %s)", Number, OsName(), runtime.GOARCH)
+ return fmt.Sprintf("WireGuard/%s (%s; %s)", Number, OsName(), NativeArch())
}