diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-08-03 09:25:35 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-08-05 20:12:19 +0200 |
commit | cea56d3a253408c4915ed3db5a15c499288cb89b (patch) | |
tree | 094f6a07f7619ad83c7679388a32835418fb25bc /elevate/zsyscall_windows.go | |
parent | ui: remove SetFocus hack from EditDialog (diff) | |
download | wireguard-windows-cea56d3a253408c4915ed3db5a15c499288cb89b.tar.xz wireguard-windows-cea56d3a253408c4915ed3db5a15c499288cb89b.zip |
elevate: do not show UAC prompt for frictionless UX
Diffstat (limited to 'elevate/zsyscall_windows.go')
-rw-r--r-- | elevate/zsyscall_windows.go | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/elevate/zsyscall_windows.go b/elevate/zsyscall_windows.go new file mode 100644 index 00000000..b16b5f5d --- /dev/null +++ b/elevate/zsyscall_windows.go @@ -0,0 +1,109 @@ +// Code generated by 'go generate'; DO NOT EDIT. + +package elevate + +import ( + "syscall" + "unsafe" + + "golang.org/x/sys/windows" +) + +var _ unsafe.Pointer + +// Do the interface allocations only once for common +// Errno values. +const ( + errnoERROR_IO_PENDING = 997 +) + +var ( + errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return nil + case errnoERROR_IO_PENDING: + return errERROR_IO_PENDING + } + // TODO: add more here, after collecting data on the common + // error values see on Windows. (perhaps when running + // all.bat?) + return e +} + +var ( + modkernel32 = windows.NewLazySystemDLL("kernel32.dll") + modntdll = windows.NewLazySystemDLL("ntdll.dll") + modole32 = windows.NewLazySystemDLL("ole32.dll") + + procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW") + procGetWindowsDirectoryW = modkernel32.NewProc("GetWindowsDirectoryW") + procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString") + procLdrFindEntryForAddress = modntdll.NewProc("LdrFindEntryForAddress") + procCoInitializeEx = modole32.NewProc("CoInitializeEx") + procCoUninitialize = modole32.NewProc("CoUninitialize") + procCoGetObject = modole32.NewProc("CoGetObject") +) + +func getModuleHandle(moduleName *uint16) (moduleHandle uintptr, err error) { + r0, _, e1 := syscall.Syscall(procGetModuleHandleW.Addr(), 1, uintptr(unsafe.Pointer(moduleName)), 0, 0) + moduleHandle = uintptr(r0) + if moduleHandle == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func getWindowsDirectory(windowsDirectory *uint16, inLen uint32) (outLen uint32, err error) { + r0, _, e1 := syscall.Syscall(procGetWindowsDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(windowsDirectory)), uintptr(inLen), 0) + outLen = uint32(r0) + if outLen == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func rtlInitUnicodeString(destinationString *cUNICODE_STRING, sourceString *uint16) { + syscall.Syscall(procRtlInitUnicodeString.Addr(), 2, uintptr(unsafe.Pointer(destinationString)), uintptr(unsafe.Pointer(sourceString)), 0) + return +} + +func ldrFindEntryForAddress(moduleHandle uintptr, entry **cLDR_DATA_TABLE_ENTRY) (ntstatus uint32) { + r0, _, _ := syscall.Syscall(procLdrFindEntryForAddress.Addr(), 2, uintptr(moduleHandle), uintptr(unsafe.Pointer(entry)), 0) + ntstatus = uint32(r0) + return +} + +func coInitializeEx(reserved uintptr, coInit uint32) (ret error) { + r0, _, _ := syscall.Syscall(procCoInitializeEx.Addr(), 2, uintptr(reserved), uintptr(coInit), 0) + if r0 != 0 { + ret = syscall.Errno(r0) + } + return +} + +func coUninitialize() { + syscall.Syscall(procCoUninitialize.Addr(), 0, 0, 0, 0) + return +} + +func coGetObject(name *uint16, bindOpts *cBIND_OPTS3, guid *windows.GUID, functionTable ***[0xffff]uintptr) (ret error) { + r0, _, _ := syscall.Syscall6(procCoGetObject.Addr(), 4, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bindOpts)), uintptr(unsafe.Pointer(guid)), uintptr(unsafe.Pointer(functionTable)), 0, 0) + if r0 != 0 { + ret = syscall.Errno(r0) + } + return +} |