From 1ed55c66cb5e246ca657398299cb490bc7d21f37 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 26 Aug 2019 13:04:00 -0600 Subject: elevate: use upstream windows directory function --- elevate/shellexecute.go | 6 +++--- elevate/syscall_windows.go | 2 -- elevate/zsyscall_windows.go | 29 +++++++---------------------- 3 files changed, 10 insertions(+), 27 deletions(-) (limited to 'elevate') diff --git a/elevate/shellexecute.go b/elevate/shellexecute.go index c4cd04da..6933c8f5 100644 --- a/elevate/shellexecute.go +++ b/elevate/shellexecute.go @@ -93,12 +93,12 @@ func ShellExecute(program string, arguments string, directory string, show int32 if err != nil { return } - var windowsDirectory [windows.MAX_PATH]uint16 - if _, err = getSystemWindowsDirectory(&windowsDirectory[0], windows.MAX_PATH); err != nil { + windowsDirectory, err := windows.GetSystemWindowsDirectory() + if err != nil { return } originalPath := dataTableEntry.FullDllName.Buffer - explorerPath := windows.StringToUTF16Ptr(filepath.Join(windows.UTF16ToString(windowsDirectory[:]), "explorer.exe")) + explorerPath := windows.StringToUTF16Ptr(filepath.Join(windowsDirectory, "explorer.exe")) rtlInitUnicodeString(&dataTableEntry.FullDllName, explorerPath) defer func() { rtlInitUnicodeString(&dataTableEntry.FullDllName, originalPath) diff --git a/elevate/syscall_windows.go b/elevate/syscall_windows.go index 2ee3587a..dba56375 100644 --- a/elevate/syscall_windows.go +++ b/elevate/syscall_windows.go @@ -78,8 +78,6 @@ const ( cCOINIT_APARTMENTTHREADED = 2 ) -//sys getSystemWindowsDirectory(windowsDirectory *uint16, inLen uint32) (outLen uint32, err error) [failretval==0] = kernel32.GetSystemWindowsDirectoryW - //sys rtlInitUnicodeString(destinationString *cUNICODE_STRING, sourceString *uint16) = ntdll.RtlInitUnicodeString //sys rtlGetCurrentPeb() (peb *cPEB) = ntdll.RtlGetCurrentPeb diff --git a/elevate/zsyscall_windows.go b/elevate/zsyscall_windows.go index 6ce8f0db..0ed13233 100644 --- a/elevate/zsyscall_windows.go +++ b/elevate/zsyscall_windows.go @@ -37,31 +37,16 @@ func errnoErr(e syscall.Errno) error { } var ( - modkernel32 = windows.NewLazySystemDLL("kernel32.dll") - modntdll = windows.NewLazySystemDLL("ntdll.dll") - modole32 = windows.NewLazySystemDLL("ole32.dll") + modntdll = windows.NewLazySystemDLL("ntdll.dll") + modole32 = windows.NewLazySystemDLL("ole32.dll") - procGetSystemWindowsDirectoryW = modkernel32.NewProc("GetSystemWindowsDirectoryW") - procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString") - procRtlGetCurrentPeb = modntdll.NewProc("RtlGetCurrentPeb") - procCoInitializeEx = modole32.NewProc("CoInitializeEx") - procCoUninitialize = modole32.NewProc("CoUninitialize") - procCoGetObject = modole32.NewProc("CoGetObject") + procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString") + procRtlGetCurrentPeb = modntdll.NewProc("RtlGetCurrentPeb") + procCoInitializeEx = modole32.NewProc("CoInitializeEx") + procCoUninitialize = modole32.NewProc("CoUninitialize") + procCoGetObject = modole32.NewProc("CoGetObject") ) -func getSystemWindowsDirectory(windowsDirectory *uint16, inLen uint32) (outLen uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetSystemWindowsDirectoryW.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 -- cgit v1.2.3-59-g8ed1b