add more api
parent
1c10d6c89f
commit
40b9dba9f0
@ -0,0 +1,79 @@
|
|||||||
|
package win32api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DuplicateTokenEx(hExistingToken HANDLE, dwDesiredAccess DWORD,
|
||||||
|
lpTokenAttributes uintptr, ImpersonationLevel int,
|
||||||
|
TokenType TOKEN_TYPE, phNewToken *TOKEN) error {
|
||||||
|
|
||||||
|
advapi32, err := syscall.LoadLibrary("advapi32.dll")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load Advapi32 API")
|
||||||
|
}
|
||||||
|
defer syscall.FreeLibrary(advapi32)
|
||||||
|
Dup, err := syscall.GetProcAddress(syscall.Handle(advapi32), "DuplicateTokenEx")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load WTSQueryUserToken API")
|
||||||
|
}
|
||||||
|
r, _, err := syscall.Syscall6(uintptr(Dup), 6, uintptr(hExistingToken), uintptr(dwDesiredAccess), lpTokenAttributes, uintptr(ImpersonationLevel),
|
||||||
|
uintptr(TokenType), uintptr(unsafe.Pointer(phNewToken)))
|
||||||
|
if r == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateProcessAsUser(hToken TOKEN, lpApplicationName, lpCommandLine string,
|
||||||
|
lpProcessAttributes, lpThreadAttributes, bInheritHandles uintptr,
|
||||||
|
dwCreationFlags uint16, lpEnvironment HANDLE, lpCurrentDirectory string,
|
||||||
|
lpStartupInfo *StartupInfo, lpProcessInformation *ProcessInformation) error {
|
||||||
|
var (
|
||||||
|
commandLine uintptr = 0
|
||||||
|
workingDir uintptr = 0
|
||||||
|
)
|
||||||
|
advapi32, err := syscall.LoadLibrary("advapi32.dll")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load Advapi32 API")
|
||||||
|
}
|
||||||
|
defer syscall.FreeLibrary(advapi32)
|
||||||
|
CPAU, err := syscall.GetProcAddress(syscall.Handle(advapi32), "CreateProcessAsUserW")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load CreateProcessAsUserW API")
|
||||||
|
}
|
||||||
|
if len(lpCommandLine) > 0 {
|
||||||
|
commandLine = uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpCommandLine)))
|
||||||
|
}
|
||||||
|
if len(lpCurrentDirectory) > 0 {
|
||||||
|
workingDir = uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpCurrentDirectory)))
|
||||||
|
}
|
||||||
|
r, _, err := syscall.Syscall12(uintptr(CPAU), 11, uintptr(hToken), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpApplicationName))),
|
||||||
|
commandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, uintptr(dwCreationFlags), uintptr(lpEnvironment),
|
||||||
|
workingDir, uintptr(unsafe.Pointer(lpStartupInfo)), uintptr(unsafe.Pointer(lpProcessInformation)), 0)
|
||||||
|
if r == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func GetTokenInformation(TokenHandle HANDLE, TokenInformationClass, TokenInformation,
|
||||||
|
TokenInformationLength uintptr, ReturnLength *uintptr) error {
|
||||||
|
advapi32, err := syscall.LoadLibrary("advapi32.dll")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load Advapi32 API")
|
||||||
|
}
|
||||||
|
defer syscall.FreeLibrary(advapi32)
|
||||||
|
GTI, err := syscall.GetProcAddress(syscall.Handle(advapi32), "GetTokenInformation")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load GetTokenInformation API")
|
||||||
|
}
|
||||||
|
if r, _, err := syscall.Syscall6(uintptr(GTI), 5, uintptr(TokenHandle), TokenInformationClass,
|
||||||
|
TokenInformation, TokenInformationLength, uintptr(unsafe.Pointer(ReturnLength)), 0); r == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package win32api
|
||||||
|
|
||||||
|
type TOKEN_LINKED_TOKEN struct {
|
||||||
|
LinkedToken TOKEN
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package win32api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WTSGetActiveConsoleSessionId() (DWORD, error) {
|
||||||
|
kernel32, err := syscall.LoadLibrary("kernel32.dll")
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors.New("Can't Load Kernel32 API")
|
||||||
|
}
|
||||||
|
defer syscall.FreeLibrary(kernel32)
|
||||||
|
WTGet, err := syscall.GetProcAddress(syscall.Handle(kernel32), "WTSGetActiveConsoleSessionId")
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors.New("Can't Load WTSGetActiveConsoleSessionId API")
|
||||||
|
}
|
||||||
|
res, _, _ := syscall.Syscall(uintptr(WTGet), 0, 0, 0, 0)
|
||||||
|
return DWORD(res), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CloseHandle(hObject HANDLE) error {
|
||||||
|
kernel32, err := syscall.LoadLibrary("kernel32.dll")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load Kernel32 API")
|
||||||
|
}
|
||||||
|
defer syscall.FreeLibrary(kernel32)
|
||||||
|
CH, err := syscall.GetProcAddress(syscall.Handle(kernel32), "CloseHandle")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load CloseHandle API")
|
||||||
|
}
|
||||||
|
if r, _, err := syscall.Syscall(uintptr(CH), 1, uintptr(hObject), 0, 0); r == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package win32api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
BOOL CreateEnvironmentBlock(
|
||||||
|
LPVOID *lpEnvironment,
|
||||||
|
HANDLE hToken,
|
||||||
|
BOOL bInherit
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
func CreateEnvironmentBlock(lpEnvironment *HANDLE, hToken TOKEN, bInherit uintptr) error {
|
||||||
|
userenv, err := syscall.LoadLibrary("userenv.dll")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load Userenv API")
|
||||||
|
}
|
||||||
|
defer syscall.FreeLibrary(userenv)
|
||||||
|
Dup, err := syscall.GetProcAddress(syscall.Handle(userenv), "CreateEnvironmentBlock")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load WTSQueryUserToken API")
|
||||||
|
}
|
||||||
|
r, _, err := syscall.Syscall6(uintptr(Dup), 3, uintptr(unsafe.Pointer(lpEnvironment)), uintptr(hToken), bInherit, 0, 0, 0)
|
||||||
|
if r == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package win32api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WTSQueryUserToken(SessionId HANDLE, phToken *HANDLE) error {
|
||||||
|
wtsapi32, err := syscall.LoadLibrary("wtsapi32.dll")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load Wtsapi32 API")
|
||||||
|
}
|
||||||
|
defer syscall.FreeLibrary(wtsapi32)
|
||||||
|
WTGet, err := syscall.GetProcAddress(syscall.Handle(wtsapi32), "WTSQueryUserToken")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load WTSQueryUserToken API")
|
||||||
|
}
|
||||||
|
r, _, err := syscall.Syscall(uintptr(WTGet), 2, uintptr(SessionId), uintptr(unsafe.Pointer(phToken)), 0)
|
||||||
|
if r == 0 {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WTSEnumerateSessions(hServer HANDLE, Reserved, Version DWORD, ppSessionInfo *HANDLE, pCount *int) error {
|
||||||
|
wtsapi32, err := syscall.LoadLibrary("wtsapi32.dll")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load Wtsapi32 API")
|
||||||
|
}
|
||||||
|
defer syscall.FreeLibrary(wtsapi32)
|
||||||
|
WT, err := syscall.GetProcAddress(syscall.Handle(wtsapi32), "WTSEnumerateSessionsW")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Can't Load WTSQueryUserToken API")
|
||||||
|
}
|
||||||
|
r, _, err := syscall.Syscall6(uintptr(WT), 5, uintptr(hServer), uintptr(Reserved), uintptr(Version), uintptr(unsafe.Pointer(ppSessionInfo)), uintptr(unsafe.Pointer(pCount)), 0)
|
||||||
|
if r == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue