aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/elevate
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-01-22 18:24:33 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-01-24 00:12:24 +0100
commitfc41f439f573fce3efdd37017f072f86cb7828ff (patch)
tree1889c42f4a4dc5190c88c87ec2a05d172a396459 /elevate
parentembeddable-dll-service: add more robust example for .NET 5 (diff)
downloadwireguard-windows-fc41f439f573fce3efdd37017f072f86cb7828ff.tar.xz
wireguard-windows-fc41f439f573fce3efdd37017f072f86cb7828ff.zip
global: move certain win32 APIs to x/sys/windows
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'elevate')
-rw-r--r--elevate/membership.go4
-rw-r--r--elevate/syscall_windows.go3
-rw-r--r--elevate/zsyscall_windows.go34
3 files changed, 10 insertions, 31 deletions
diff --git a/elevate/membership.go b/elevate/membership.go
index d0fe6bfe..769652c1 100644
--- a/elevate/membership.go
+++ b/elevate/membership.go
@@ -37,12 +37,12 @@ func TokenIsElevatedOrElevatable(token windows.Token) bool {
}
func IsAdminDesktop() (bool, error) {
- hwnd := getShellWindow()
+ hwnd := windows.GetShellWindow()
if hwnd == 0 {
return false, windows.ERROR_INVALID_WINDOW_HANDLE
}
var pid uint32
- _, err := getWindowThreadProcessId(hwnd, &pid)
+ _, err := windows.GetWindowThreadProcessId(hwnd, &pid)
if err != nil {
return false, err
}
diff --git a/elevate/syscall_windows.go b/elevate/syscall_windows.go
index 4f114711..b854fe7e 100644
--- a/elevate/syscall_windows.go
+++ b/elevate/syscall_windows.go
@@ -84,6 +84,3 @@ const (
//sys coInitializeEx(reserved uintptr, coInit uint32) (ret error) = ole32.CoInitializeEx
//sys coUninitialize() = ole32.CoUninitialize
//sys coGetObject(name *uint16, bindOpts *cBIND_OPTS3, guid *windows.GUID, functionTable ***[0xffff]uintptr) (ret error) = ole32.CoGetObject
-
-//sys getWindowThreadProcessId(hwnd uintptr, pid *uint32) (tid uint32, err error) = user32.GetWindowThreadProcessId
-//sys getShellWindow() (hwnd uintptr) = user32.GetShellWindow
diff --git a/elevate/zsyscall_windows.go b/elevate/zsyscall_windows.go
index bd22f6dc..c7f71819 100644
--- a/elevate/zsyscall_windows.go
+++ b/elevate/zsyscall_windows.go
@@ -38,17 +38,14 @@ func errnoErr(e syscall.Errno) error {
}
var (
- modntdll = windows.NewLazySystemDLL("ntdll.dll")
- modole32 = windows.NewLazySystemDLL("ole32.dll")
- moduser32 = windows.NewLazySystemDLL("user32.dll")
-
- procRtlGetCurrentPeb = modntdll.NewProc("RtlGetCurrentPeb")
- procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString")
- procCoGetObject = modole32.NewProc("CoGetObject")
- procCoInitializeEx = modole32.NewProc("CoInitializeEx")
- procCoUninitialize = modole32.NewProc("CoUninitialize")
- procGetShellWindow = moduser32.NewProc("GetShellWindow")
- procGetWindowThreadProcessId = moduser32.NewProc("GetWindowThreadProcessId")
+ modntdll = windows.NewLazySystemDLL("ntdll.dll")
+ modole32 = windows.NewLazySystemDLL("ole32.dll")
+
+ procRtlGetCurrentPeb = modntdll.NewProc("RtlGetCurrentPeb")
+ procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString")
+ procCoGetObject = modole32.NewProc("CoGetObject")
+ procCoInitializeEx = modole32.NewProc("CoInitializeEx")
+ procCoUninitialize = modole32.NewProc("CoUninitialize")
)
func rtlGetCurrentPeb() (peb *cPEB) {
@@ -82,18 +79,3 @@ func coUninitialize() {
syscall.Syscall(procCoUninitialize.Addr(), 0, 0, 0, 0)
return
}
-
-func getShellWindow() (hwnd uintptr) {
- r0, _, _ := syscall.Syscall(procGetShellWindow.Addr(), 0, 0, 0, 0)
- hwnd = uintptr(r0)
- 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 {
- err = errnoErr(e1)
- }
- return
-}