aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/elevate/zsyscall_windows.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--elevate/zsyscall_windows.go43
1 files changed, 20 insertions, 23 deletions
diff --git a/elevate/zsyscall_windows.go b/elevate/zsyscall_windows.go
index afff428f..bd22f6dc 100644
--- a/elevate/zsyscall_windows.go
+++ b/elevate/zsyscall_windows.go
@@ -19,6 +19,7 @@ const (
var (
errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
+ errERROR_EINVAL error = syscall.EINVAL
)
// errnoErr returns common boxed Errno values, to prevent
@@ -26,7 +27,7 @@ var (
func errnoErr(e syscall.Errno) error {
switch e {
case 0:
- return nil
+ return errERROR_EINVAL
case errnoERROR_IO_PENDING:
return errERROR_IO_PENDING
}
@@ -41,23 +42,31 @@ var (
modole32 = windows.NewLazySystemDLL("ole32.dll")
moduser32 = windows.NewLazySystemDLL("user32.dll")
- procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString")
procRtlGetCurrentPeb = modntdll.NewProc("RtlGetCurrentPeb")
+ procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString")
+ procCoGetObject = modole32.NewProc("CoGetObject")
procCoInitializeEx = modole32.NewProc("CoInitializeEx")
procCoUninitialize = modole32.NewProc("CoUninitialize")
- procCoGetObject = modole32.NewProc("CoGetObject")
- procGetWindowThreadProcessId = moduser32.NewProc("GetWindowThreadProcessId")
procGetShellWindow = moduser32.NewProc("GetShellWindow")
+ procGetWindowThreadProcessId = moduser32.NewProc("GetWindowThreadProcessId")
)
+func rtlGetCurrentPeb() (peb *cPEB) {
+ r0, _, _ := syscall.Syscall(procRtlGetCurrentPeb.Addr(), 0, 0, 0, 0)
+ peb = (*cPEB)(unsafe.Pointer(r0))
+ return
+}
+
func rtlInitUnicodeString(destinationString *cUNICODE_STRING, sourceString *uint16) {
syscall.Syscall(procRtlInitUnicodeString.Addr(), 2, uintptr(unsafe.Pointer(destinationString)), uintptr(unsafe.Pointer(sourceString)), 0)
return
}
-func rtlGetCurrentPeb() (peb *cPEB) {
- r0, _, _ := syscall.Syscall(procRtlGetCurrentPeb.Addr(), 0, 0, 0, 0)
- peb = (*cPEB)(unsafe.Pointer(r0))
+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
}
@@ -74,11 +83,9 @@ func coUninitialize() {
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)
- }
+func getShellWindow() (hwnd uintptr) {
+ r0, _, _ := syscall.Syscall(procGetShellWindow.Addr(), 0, 0, 0, 0)
+ hwnd = uintptr(r0)
return
}
@@ -86,17 +93,7 @@ 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
- }
+ err = errnoErr(e1)
}
return
}
-
-func getShellWindow() (hwnd uintptr) {
- r0, _, _ := syscall.Syscall(procGetShellWindow.Addr(), 0, 0, 0, 0)
- hwnd = uintptr(r0)
- return
-}