aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-26 13:04:00 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-26 14:48:41 -0600
commit1ed55c66cb5e246ca657398299cb490bc7d21f37 (patch)
tree84a72782b37f8e3db3675d981846299a1855bed8
parentui: enable priority boost (diff)
downloadwireguard-windows-1ed55c66cb5e246ca657398299cb490bc7d21f37.tar.xz
wireguard-windows-1ed55c66cb5e246ca657398299cb490bc7d21f37.zip
elevate: use upstream windows directory function
-rw-r--r--elevate/shellexecute.go6
-rw-r--r--elevate/syscall_windows.go2
-rw-r--r--elevate/zsyscall_windows.go29
3 files changed, 10 insertions, 27 deletions
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