diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-08-28 22:30:35 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-08-30 08:47:21 -0600 |
commit | 931c5eb3637441929634ddbe608acf94b293175e (patch) | |
tree | 2dab80c185282b6cb9270836cef88f852afe5a40 /elevate/zsyscall_windows.go | |
parent | elevate: use more strict check for admin group (diff) | |
download | wireguard-windows-931c5eb3637441929634ddbe608acf94b293175e.tar.xz wireguard-windows-931c5eb3637441929634ddbe608acf94b293175e.zip |
elevate: check for desktop admin ownership
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'elevate/zsyscall_windows.go')
-rw-r--r-- | elevate/zsyscall_windows.go | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/elevate/zsyscall_windows.go b/elevate/zsyscall_windows.go index 0ed13233..afff428f 100644 --- a/elevate/zsyscall_windows.go +++ b/elevate/zsyscall_windows.go @@ -37,14 +37,17 @@ func errnoErr(e syscall.Errno) error { } var ( - modntdll = windows.NewLazySystemDLL("ntdll.dll") - modole32 = windows.NewLazySystemDLL("ole32.dll") - - procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString") - procRtlGetCurrentPeb = modntdll.NewProc("RtlGetCurrentPeb") - procCoInitializeEx = modole32.NewProc("CoInitializeEx") - procCoUninitialize = modole32.NewProc("CoUninitialize") - procCoGetObject = modole32.NewProc("CoGetObject") + modntdll = windows.NewLazySystemDLL("ntdll.dll") + modole32 = windows.NewLazySystemDLL("ole32.dll") + moduser32 = windows.NewLazySystemDLL("user32.dll") + + procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString") + procRtlGetCurrentPeb = modntdll.NewProc("RtlGetCurrentPeb") + procCoInitializeEx = modole32.NewProc("CoInitializeEx") + procCoUninitialize = modole32.NewProc("CoUninitialize") + procCoGetObject = modole32.NewProc("CoGetObject") + procGetWindowThreadProcessId = moduser32.NewProc("GetWindowThreadProcessId") + procGetShellWindow = moduser32.NewProc("GetShellWindow") ) func rtlInitUnicodeString(destinationString *cUNICODE_STRING, sourceString *uint16) { @@ -78,3 +81,22 @@ func coGetObject(name *uint16, bindOpts *cBIND_OPTS3, guid *windows.GUID, functi } return } + +func getWindowThreadProcessId(hwnd uintptr, pid *uint32) (tid uint32, err error) { + r0, _, e1 := syscall.Syscall(procGetWindowThreadProcessId.Addr(), 2, uintptr(hwnd), uintptr(unsafe.Pointer(pid)), 0) + tid = uint32(r0) + if tid == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func getShellWindow() (hwnd uintptr) { + r0, _, _ := syscall.Syscall(procGetShellWindow.Addr(), 0, 0, 0, 0) + hwnd = uintptr(r0) + return +} |