win32

package
v10.11.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2018 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Examples

Constants

View Source
const (
	LOGON32_PROVIDER_DEFAULT = 0

	LOGON32_LOGON_INTERACTIVE = 2

	PI_NOUI = 1

	KF_FLAG_CREATE uint32 = 0x00008000

	CREATE_BREAKAWAY_FROM_JOB = 0x01000000
	CREATE_NEW_CONSOLE        = 0x00000010
	CREATE_NEW_PROCESS_GROUP  = 0x00000200

	VER_MAJORVERSION     = 0x0000002
	VER_MINORVERSION     = 0x0000001
	VER_SERVICEPACKMAJOR = 0x0000020
	VER_SERVICEPACKMINOR = 0x0000010
	VER_GREATER_EQUAL    = 3

	ERROR_OLD_WIN_VERSION syscall.Errno = 1150

	// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa379626(v=vs.85).aspx
	TokenLinkedToken = 19
)

Variables

View Source
var (
	FOLDERID_LocalAppData   = syscall.GUID{Data1: 0xF1B32785, Data2: 0x6FBA, Data3: 0x4FCF, Data4: [8]byte{0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91}}
	FOLDERID_RoamingAppData = syscall.GUID{Data1: 0x3EB685DB, Data2: 0x65F9, Data3: 0x4CF6, Data4: [8]byte{0xA0, 0x3A, 0xE3, 0xEF, 0x65, 0x72, 0x9F, 0x3D}}
)

Functions

func CloseHandle

func CloseHandle(handle syscall.Handle) (err error)

func CoTaskMemFree

func CoTaskMemFree(pv uintptr)

https://msdn.microsoft.com/en-us/library/windows/desktop/ms680722(v=vs.85).aspx Note: the system call returns no value, so we can't check for an error

func CreateEnvironment

func CreateEnvironment(env *[]string, hUser syscall.Handle) (mergedEnv *[]string, err error)

CreateEnvironment returns an environment block, suitable for use with the CreateProcessAsUser system call. The default environment variables of hUser are overlayed with values in env.

func GetFolder

func GetFolder(hUser syscall.Handle, folder *syscall.GUID, dwFlags uint32) (value string, err error)

func GetLinkedToken

func GetLinkedToken(hToken syscall.Token) (syscall.Token, error)

func GetProfilesDirectory

func GetProfilesDirectory(
	lpProfilesDir *uint16,
	lpcchSize *uint32,
) (err error)

https://msdn.microsoft.com/en-us/library/windows/desktop/bb762278(v=vs.85).aspx BOOL WINAPI GetProfilesDirectory(

_Out_   LPTSTR  lpProfilesDir,
_Inout_ LPDWORD lpcchSize

);

func GetTokenInformation

func GetTokenInformation(
	tokenHandle syscall.Token,
	tokenInformationClass TOKEN_INFORMATION_CLASS,
	tokenInformation uintptr,
	tokenInformationLength uintptr,
	returnLength *uintptr,
) (err error)

https://msdn.microsoft.com/en-us/library/windows/desktop/aa446671(v=vs.85).aspx BOOL WINAPI GetTokenInformation(

_In_      HANDLE                  TokenHandle,
_In_      TOKEN_INFORMATION_CLASS TokenInformationClass,
_Out_opt_ LPVOID                  TokenInformation,
_In_      DWORD                   TokenInformationLength,
_Out_     PDWORD                  ReturnLength

);

func GetUserProfileDirectory

func GetUserProfileDirectory(
	hToken syscall.Handle,
	lpProfileDir *uint16,
	lpcchSize *uint32,
) (err error)

https://msdn.microsoft.com/en-us/library/windows/desktop/bb762280(v=vs.85).aspx BOOL WINAPI GetUserProfileDirectory(

_In_      HANDLE  hToken,
_Out_opt_ LPTSTR  lpProfileDir,
_Inout_   LPDWORD lpcchSize

);

func InteractiveUserToken

func InteractiveUserToken(timeout time.Duration) (hToken syscall.Handle, err error)

InteractiveUserToken returns a user token (security context) for the interactive desktop session attached to the default console (i.e. what would be seen on a display connected directly to the computer, rather than a remote RDP session). It must be called from a process which is running under LocalSystem account in order to have the necessary privileges (typically a Windows service). Since the service might be running before a local logon occurs, a timeout can be specified for waiting for a successful logon (via winlogon) to occur. The returned token can be used in e.g. CreateProcessAsUser system call, which allows e.g. a Windows service to run a process in the interactive desktop session, as if the logged in user had executed the process directly. The function additionally waits for the user profile directory to exist, before returning.

func IsWindows8OrGreater

func IsWindows8OrGreater() bool

func LoadUserProfile

func LoadUserProfile(token syscall.Handle, pinfo *ProfileInfo) error

func LogonUser

func LogonUser(username *uint16, domain *uint16, password *uint16, logonType uint32, logonProvider uint32) (token syscall.Handle, err error)

func MergeEnvLists

func MergeEnvLists(envLists ...*[]string) (*[]string, error)
Example
package main

import (
	"fmt"
	"log"

	"github.com/taskcluster/generic-worker/win32"
)

func main() {
	lists := []*[]string{
		{
			"a=dog",
			"Pete=man",
			"x=ray",
		}, {
			"food=good",
			"PETE=person",
		},
	}
	res, err := win32.MergeEnvLists(lists...)
	if err != nil {
		log.Fatalf("Hit error: %v", err)
	}
	fmt.Println(*res)
}
Output:

[a=dog food=good Pete=person x=ray]

func ProfileDirectory

func ProfileDirectory(hToken syscall.Handle) (string, error)

ProfileDirectory returns the profile directory of the user represented by the given user handle

func ProfilesDirectory

func ProfilesDirectory() string

ProfilesDirectory returns the folder where user profiles get created, typically `C:\Users`

func SetAndCreateFolder

func SetAndCreateFolder(hUser syscall.Handle, folder *syscall.GUID, value string) (err error)

func SetFolder

func SetFolder(hUser syscall.Handle, folder *syscall.GUID, value string) (err error)

func UnloadUserProfile

func UnloadUserProfile(token, profile syscall.Handle) error

func VerSetConditionMask

func VerSetConditionMask(lConditionMask uint64, typeBitMask uint32, conditionMask uint8) uint64

func VerifyWindowsInfoW

func VerifyWindowsInfoW(vi OSVersionInfoEx, typeMask uint32, conditionMask uint64) (bool, error)

func WTSGetActiveConsoleSessionId

func WTSGetActiveConsoleSessionId() (sessionId uint32, err error)

https://msdn.microsoft.com/en-us/library/aa383835(VS.85).aspx DWORD WTSGetActiveConsoleSessionId(void);

func WTSQueryUserToken

func WTSQueryUserToken(
	sessionId uint32,
	phToken *syscall.Handle,
) (err error)

https://msdn.microsoft.com/en-us/library/aa383840(VS.85).aspx BOOL WTSQueryUserToken(

_In_  ULONG   SessionId,
_Out_ PHANDLE phToken

);

Types

type LazyDLLWrapper

type LazyDLLWrapper struct {
	LazyDLL *syscall.LazyDLL
}

These wrappers are used to be able to intercept system calls, and log what is being called...

func NewLazyDLL

func NewLazyDLL(name string) *LazyDLLWrapper

func (*LazyDLLWrapper) NewProc

func (l *LazyDLLWrapper) NewProc(name string) *LazyProcWrapper

type LazyProcWrapper

type LazyProcWrapper struct {
	LazyProc *syscall.LazyProc
}

These wrappers are used to be able to intercept system calls, and log what is being called...

func (*LazyProcWrapper) Call

func (p *LazyProcWrapper) Call(a ...uintptr) (r1, r2 uintptr, lastErr error)

type OSVersionInfoEx

type OSVersionInfoEx struct {
	OSVersionInfoSize uint32
	MajorVersion      uint32
	MinorVersion      uint32
	BuildNumber       uint32
	PlatformId        uint32
	CSDVersion        [128]uint16
	ServicePackMajor  uint16
	ServicePackMinor  uint16
	SuiteMask         uint16
	ProductType       byte
	Reserve           byte
}

type ProfileInfo

type ProfileInfo struct {
	Size        uint32
	Flags       uint32
	Username    *uint16
	ProfilePath *uint16
	DefaultPath *uint16
	ServerName  *uint16
	PolicyPath  *uint16
	Profile     syscall.Handle
}

type TOKEN_INFORMATION_CLASS

type TOKEN_INFORMATION_CLASS uint32

type TOKEN_LINKED_TOKEN

type TOKEN_LINKED_TOKEN struct {
	LinkedToken syscall.Token // HANDLE
}

https://msdn.microsoft.com/en-us/library/windows/desktop/bb530719(v=vs.85).aspx

typedef struct _TOKEN_LINKED_TOKEN {
  HANDLE LinkedToken;
} TOKEN_LINKED_TOKEN, *PTOKEN_LINKED_TOKEN;

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL