aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/version/zsyscall_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-01 11:14:12 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-01 11:14:12 +0200
commitcff4e77bfe62606c19c205e02fd63b3777855392 (patch)
treeec8573073bf68253267ed741b60bf23b8e4554a3 /version/zsyscall_windows.go
parentui: support clipboard copying for log items (diff)
downloadwireguard-windows-cff4e77bfe62606c19c205e02fd63b3777855392.tar.xz
wireguard-windows-cff4e77bfe62606c19c205e02fd63b3777855392.zip
version: dynamically get file version
Diffstat (limited to '')
-rw-r--r--version/zsyscall_windows.go45
1 files changed, 43 insertions, 2 deletions
diff --git a/version/zsyscall_windows.go b/version/zsyscall_windows.go
index 9f11ce70..ef4e11d7 100644
--- a/version/zsyscall_windows.go
+++ b/version/zsyscall_windows.go
@@ -37,9 +37,13 @@ func errnoErr(e syscall.Errno) error {
}
var (
- modntdll = windows.NewLazySystemDLL("ntdll.dll")
+ modntdll = windows.NewLazySystemDLL("ntdll.dll")
+ modversion = windows.NewLazySystemDLL("version.dll")
- procRtlGetVersion = modntdll.NewProc("RtlGetVersion")
+ procRtlGetVersion = modntdll.NewProc("RtlGetVersion")
+ procGetFileVersionInfoSizeW = modversion.NewProc("GetFileVersionInfoSizeW")
+ procGetFileVersionInfoW = modversion.NewProc("GetFileVersionInfoW")
+ procVerQueryValueW = modversion.NewProc("VerQueryValueW")
)
func rtlGetVersion(versionInfo *osVersionInfo) (nterr uint32) {
@@ -47,3 +51,40 @@ func rtlGetVersion(versionInfo *osVersionInfo) (nterr uint32) {
nterr = uint32(r0)
return
}
+
+func GetFileVersionInfoSize(filename *uint16, zero *uint32) (size uint32, err error) {
+ r0, _, e1 := syscall.Syscall(procGetFileVersionInfoSizeW.Addr(), 2, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(zero)), 0)
+ size = uint32(r0)
+ if size == 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}
+
+func GetFileVersionInfo(filename *uint16, zero uint32, size uint32, block *byte) (err error) {
+ r1, _, e1 := syscall.Syscall6(procGetFileVersionInfoW.Addr(), 4, uintptr(unsafe.Pointer(filename)), uintptr(zero), uintptr(size), uintptr(unsafe.Pointer(block)), 0, 0)
+ if r1 == 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}
+
+func VerQueryValue(block *byte, section *uint16, value **byte, size *uint32) (err error) {
+ r1, _, e1 := syscall.Syscall6(procVerQueryValueW.Addr(), 4, uintptr(unsafe.Pointer(block)), uintptr(unsafe.Pointer(section)), uintptr(unsafe.Pointer(value)), uintptr(unsafe.Pointer(size)), 0, 0)
+ if r1 == 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}