mirror of
https://github.com/DrEm-s/wireguard-windows-portable.git
synced 2021-10-28 23:07:29 +03:00
elevate: use ole32 functions from x/sys
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
/* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package elevate
|
||||
|
||||
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall_windows.go
|
||||
@@ -113,19 +113,19 @@ func ShellExecute(program string, arguments string, directory string, show int32
|
||||
runtime.KeepAlive(explorerPath)
|
||||
}()
|
||||
|
||||
if err = coInitializeEx(0, cCOINIT_APARTMENTTHREADED); err == nil {
|
||||
defer coUninitialize()
|
||||
if err = windows.CoInitializeEx(0, windows.COINIT_APARTMENTTHREADED); err == nil {
|
||||
defer windows.CoUninitialize()
|
||||
}
|
||||
|
||||
var interfacePointer **[0xffff]uintptr
|
||||
if err = coGetObject(
|
||||
if err = windows.CoGetObject(
|
||||
windows.StringToUTF16Ptr("Elevation:Administrator!new:{3E5FC7F9-9A51-4367-9063-A120244FBEC7}"),
|
||||
&cBIND_OPTS3{
|
||||
cbStruct: uint32(unsafe.Sizeof(cBIND_OPTS3{})),
|
||||
dwClassContext: cCLSCTX_LOCAL_SERVER,
|
||||
&windows.BIND_OPTS3{
|
||||
CbStruct: uint32(unsafe.Sizeof(windows.BIND_OPTS3{})),
|
||||
ClassContext: windows.CLSCTX_LOCAL_SERVER,
|
||||
},
|
||||
&windows.GUID{0x6EDD6D74, 0xC007, 0x4E75, [8]byte{0xB7, 0x6A, 0xE5, 0x74, 0x09, 0x95, 0xE2, 0x4C}},
|
||||
&interfacePointer,
|
||||
(**uintptr)(unsafe.Pointer(&interfacePointer)),
|
||||
); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package elevate
|
||||
|
||||
type cBIND_OPTS3 struct {
|
||||
cbStruct uint32
|
||||
grfFlags uint32
|
||||
grfMode uint32
|
||||
dwTickCountDeadline uint32
|
||||
dwTrackFlags uint32
|
||||
dwClassContext uint32
|
||||
locale uint32
|
||||
pServerInfo *uintptr
|
||||
hwnd *uintptr
|
||||
}
|
||||
|
||||
const (
|
||||
cCLSCTX_LOCAL_SERVER = 4
|
||||
cCOINIT_APARTMENTTHREADED = 2
|
||||
)
|
||||
|
||||
//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
|
||||
@@ -1,67 +0,0 @@
|
||||
// Code generated by 'go generate'; DO NOT EDIT.
|
||||
|
||||
package elevate
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
// Do the interface allocations only once for common
|
||||
// Errno values.
|
||||
const (
|
||||
errnoERROR_IO_PENDING = 997
|
||||
)
|
||||
|
||||
var (
|
||||
errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
|
||||
errERROR_EINVAL error = syscall.EINVAL
|
||||
)
|
||||
|
||||
// errnoErr returns common boxed Errno values, to prevent
|
||||
// allocations at runtime.
|
||||
func errnoErr(e syscall.Errno) error {
|
||||
switch e {
|
||||
case 0:
|
||||
return errERROR_EINVAL
|
||||
case errnoERROR_IO_PENDING:
|
||||
return errERROR_IO_PENDING
|
||||
}
|
||||
// TODO: add more here, after collecting data on the common
|
||||
// error values see on Windows. (perhaps when running
|
||||
// all.bat?)
|
||||
return e
|
||||
}
|
||||
|
||||
var (
|
||||
modole32 = windows.NewLazySystemDLL("ole32.dll")
|
||||
|
||||
procCoGetObject = modole32.NewProc("CoGetObject")
|
||||
procCoInitializeEx = modole32.NewProc("CoInitializeEx")
|
||||
procCoUninitialize = modole32.NewProc("CoUninitialize")
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func coInitializeEx(reserved uintptr, coInit uint32) (ret error) {
|
||||
r0, _, _ := syscall.Syscall(procCoInitializeEx.Addr(), 2, uintptr(reserved), uintptr(coInit), 0)
|
||||
if r0 != 0 {
|
||||
ret = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func coUninitialize() {
|
||||
syscall.Syscall(procCoUninitialize.Addr(), 0, 0, 0, 0)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user