Просмотр исходного кода

windows: support SECURITY_DESCRIPTOR and ACL for secured objects

This adds the basic foundation for dealing with security descriptors and
access control lists. The basic creators and getters are included in
this patch. These are some of the most fundamental security objects on NT,
and any work with the security API is fairly limited without it. These
are "core" NT structures.

Change-Id: I9a6399cb6ee41a825de30d5364ab69102d5f6d57
Reviewed-on: https://go-review.googlesource.com/c/sys/+/195498
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Jason A. Donenfeld 6 лет назад
Родитель
Сommit
14da1ac737
4 измененных файлов с 1295 добавлено и 287 удалено
  1. 512 8
      windows/security_windows.go
  2. 136 0
      windows/syscall_windows_test.go
  3. 0 12
      windows/types_windows.go
  4. 647 267
      windows/zsyscall_windows.go

+ 512 - 8
windows/security_windows.go

@@ -9,14 +9,6 @@ import (
 	"unsafe"
 )
 
-const (
-	STANDARD_RIGHTS_REQUIRED = 0xf0000
-	STANDARD_RIGHTS_READ     = 0x20000
-	STANDARD_RIGHTS_WRITE    = 0x20000
-	STANDARD_RIGHTS_EXECUTE  = 0x20000
-	STANDARD_RIGHTS_ALL      = 0x1F0000
-)
-
 const (
 	NameUnknown          = 0
 	NameFullyQualifiedDN = 1
@@ -890,3 +882,515 @@ type WTS_SESSION_INFO struct {
 //sys WTSQueryUserToken(session uint32, token *Token) (err error) = wtsapi32.WTSQueryUserToken
 //sys WTSEnumerateSessions(handle Handle, reserved uint32, version uint32, sessions **WTS_SESSION_INFO, count *uint32) (err error) = wtsapi32.WTSEnumerateSessionsW
 //sys WTSFreeMemory(ptr uintptr) = wtsapi32.WTSFreeMemory
+
+type ACL struct {
+	aclRevision byte
+	sbz1        byte
+	aclSize     uint16
+	aceCount    uint16
+	sbz2        uint16
+}
+
+type SECURITY_DESCRIPTOR struct {
+	revision byte
+	sbz1     byte
+	control  SECURITY_DESCRIPTOR_CONTROL
+	owner    *SID
+	group    *SID
+	sacl     *ACL
+	dacl     *ACL
+}
+
+type SE_OBJECT_TYPE uint32
+
+// Constants for type SE_OBJECT_TYPE
+const (
+	SE_UNKNOWN_OBJECT_TYPE     = 0
+	SE_FILE_OBJECT             = 1
+	SE_SERVICE                 = 2
+	SE_PRINTER                 = 3
+	SE_REGISTRY_KEY            = 4
+	SE_LMSHARE                 = 5
+	SE_KERNEL_OBJECT           = 6
+	SE_WINDOW_OBJECT           = 7
+	SE_DS_OBJECT               = 8
+	SE_DS_OBJECT_ALL           = 9
+	SE_PROVIDER_DEFINED_OBJECT = 10
+	SE_WMIGUID_OBJECT          = 11
+	SE_REGISTRY_WOW64_32KEY    = 12
+	SE_REGISTRY_WOW64_64KEY    = 13
+)
+
+type SECURITY_INFORMATION uint32
+
+// Constants for type SECURITY_INFORMATION
+const (
+	OWNER_SECURITY_INFORMATION            = 0x00000001
+	GROUP_SECURITY_INFORMATION            = 0x00000002
+	DACL_SECURITY_INFORMATION             = 0x00000004
+	SACL_SECURITY_INFORMATION             = 0x00000008
+	LABEL_SECURITY_INFORMATION            = 0x00000010
+	ATTRIBUTE_SECURITY_INFORMATION        = 0x00000020
+	SCOPE_SECURITY_INFORMATION            = 0x00000040
+	BACKUP_SECURITY_INFORMATION           = 0x00010000
+	PROTECTED_DACL_SECURITY_INFORMATION   = 0x80000000
+	PROTECTED_SACL_SECURITY_INFORMATION   = 0x40000000
+	UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000
+	UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000
+)
+
+type SECURITY_DESCRIPTOR_CONTROL uint16
+
+// Constants for type SECURITY_DESCRIPTOR_CONTROL
+const (
+	SE_OWNER_DEFAULTED       = 0x0001
+	SE_GROUP_DEFAULTED       = 0x0002
+	SE_DACL_PRESENT          = 0x0004
+	SE_DACL_DEFAULTED        = 0x0008
+	SE_SACL_PRESENT          = 0x0010
+	SE_SACL_DEFAULTED        = 0x0020
+	SE_DACL_AUTO_INHERIT_REQ = 0x0100
+	SE_SACL_AUTO_INHERIT_REQ = 0x0200
+	SE_DACL_AUTO_INHERITED   = 0x0400
+	SE_SACL_AUTO_INHERITED   = 0x0800
+	SE_DACL_PROTECTED        = 0x1000
+	SE_SACL_PROTECTED        = 0x2000
+	SE_RM_CONTROL_VALID      = 0x4000
+	SE_SELF_RELATIVE         = 0x8000
+)
+
+type ACCESS_MASK uint32
+
+// Constants for type ACCESS_MASK
+const (
+	DELETE                   = 0x00010000
+	READ_CONTROL             = 0x00020000
+	WRITE_DAC                = 0x00040000
+	WRITE_OWNER              = 0x00080000
+	SYNCHRONIZE              = 0x00100000
+	STANDARD_RIGHTS_REQUIRED = 0x000F0000
+	STANDARD_RIGHTS_READ     = READ_CONTROL
+	STANDARD_RIGHTS_WRITE    = READ_CONTROL
+	STANDARD_RIGHTS_EXECUTE  = READ_CONTROL
+	STANDARD_RIGHTS_ALL      = 0x001F0000
+	SPECIFIC_RIGHTS_ALL      = 0x0000FFFF
+	ACCESS_SYSTEM_SECURITY   = 0x01000000
+	MAXIMUM_ALLOWED          = 0x02000000
+	GENERIC_READ             = 0x80000000
+	GENERIC_WRITE            = 0x40000000
+	GENERIC_EXECUTE          = 0x20000000
+	GENERIC_ALL              = 0x10000000
+)
+
+type ACCESS_MODE uint32
+
+// Constants for type ACCESS_MODE
+const (
+	NOT_USED_ACCESS   = 0
+	GRANT_ACCESS      = 1
+	SET_ACCESS        = 2
+	DENY_ACCESS       = 3
+	REVOKE_ACCESS     = 4
+	SET_AUDIT_SUCCESS = 5
+	SET_AUDIT_FAILURE = 6
+)
+
+// Constants for AceFlags and Inheritance fields
+const (
+	NO_INHERITANCE                     = 0x0
+	SUB_OBJECTS_ONLY_INHERIT           = 0x1
+	SUB_CONTAINERS_ONLY_INHERIT        = 0x2
+	SUB_CONTAINERS_AND_OBJECTS_INHERIT = 0x3
+	INHERIT_NO_PROPAGATE               = 0x4
+	INHERIT_ONLY                       = 0x8
+	INHERITED_ACCESS_ENTRY             = 0x10
+	INHERITED_PARENT                   = 0x10000000
+	INHERITED_GRANDPARENT              = 0x20000000
+	OBJECT_INHERIT_ACE                 = 0x1
+	CONTAINER_INHERIT_ACE              = 0x2
+	NO_PROPAGATE_INHERIT_ACE           = 0x4
+	INHERIT_ONLY_ACE                   = 0x8
+	INHERITED_ACE                      = 0x10
+	VALID_INHERIT_FLAGS                = 0x1F
+)
+
+type MULTIPLE_TRUSTEE_OPERATION uint32
+
+// Constants for MULTIPLE_TRUSTEE_OPERATION
+const (
+	NO_MULTIPLE_TRUSTEE    = 0
+	TRUSTEE_IS_IMPERSONATE = 1
+)
+
+type TRUSTEE_FORM uint32
+
+// Constants for TRUSTEE_FORM
+const (
+	TRUSTEE_IS_SID              = 0
+	TRUSTEE_IS_NAME             = 1
+	TRUSTEE_BAD_FORM            = 2
+	TRUSTEE_IS_OBJECTS_AND_SID  = 3
+	TRUSTEE_IS_OBJECTS_AND_NAME = 4
+)
+
+type TRUSTEE_TYPE uint32
+
+// Constants for TRUSTEE_TYPE
+const (
+	TRUSTEE_IS_UNKNOWN          = 0
+	TRUSTEE_IS_USER             = 1
+	TRUSTEE_IS_GROUP            = 2
+	TRUSTEE_IS_DOMAIN           = 3
+	TRUSTEE_IS_ALIAS            = 4
+	TRUSTEE_IS_WELL_KNOWN_GROUP = 5
+	TRUSTEE_IS_DELETED          = 6
+	TRUSTEE_IS_INVALID          = 7
+	TRUSTEE_IS_COMPUTER         = 8
+)
+
+// Constants for ObjectsPresent field
+const (
+	ACE_OBJECT_TYPE_PRESENT           = 0x1
+	ACE_INHERITED_OBJECT_TYPE_PRESENT = 0x2
+)
+
+type EXPLICIT_ACCESS struct {
+	AccessPermissions ACCESS_MASK
+	AccessMode        ACCESS_MODE
+	Inheritance       uint32
+	Trustee           TRUSTEE
+}
+
+// This type is the union inside of TRUSTEE and must be created using one of the TrusteeValueFrom* functions.
+type TrusteeValue uintptr
+
+func TrusteeValueFromString(str string) TrusteeValue {
+	return TrusteeValue(unsafe.Pointer(StringToUTF16Ptr(str)))
+}
+func TrusteeValueFromSID(sid *SID) TrusteeValue {
+	return TrusteeValue(unsafe.Pointer(sid))
+}
+func TrusteeValueFromObjectsAndSid(objectsAndSid *OBJECTS_AND_SID) TrusteeValue {
+	return TrusteeValue(unsafe.Pointer(objectsAndSid))
+}
+func TrusteeValueFromObjectsAndName(objectsAndName *OBJECTS_AND_NAME) TrusteeValue {
+	return TrusteeValue(unsafe.Pointer(objectsAndName))
+}
+
+type TRUSTEE struct {
+	MultipleTrustee          *TRUSTEE
+	MultipleTrusteeOperation MULTIPLE_TRUSTEE_OPERATION
+	TrusteeForm              TRUSTEE_FORM
+	TrusteeType              TRUSTEE_TYPE
+	TrusteeValue             TrusteeValue
+}
+
+type OBJECTS_AND_SID struct {
+	ObjectsPresent          uint32
+	ObjectTypeGuid          GUID
+	InheritedObjectTypeGuid GUID
+	Sid                     *SID
+}
+
+type OBJECTS_AND_NAME struct {
+	ObjectsPresent          uint32
+	ObjectType              SE_OBJECT_TYPE
+	ObjectTypeName          *uint16
+	InheritedObjectTypeName *uint16
+	Name                    *uint16
+}
+
+//sys	getSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner **SID, group **SID, dacl **ACL, sacl **ACL, sd **SECURITY_DESCRIPTOR) (ret error) = advapi32.GetSecurityInfo
+//sys	SetSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner *SID, group *SID, dacl *ACL, sacl *ACL) = advapi32.SetSecurityInfo
+//sys	getNamedSecurityInfo(objectName string, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner **SID, group **SID, dacl **ACL, sacl **ACL, sd **SECURITY_DESCRIPTOR) (ret error) = advapi32.GetNamedSecurityInfoW
+//sys	SetNamedSecurityInfo(objectName string, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner *SID, group *SID, dacl *ACL, sacl *ACL) (ret error) = advapi32.SetNamedSecurityInfoW
+
+//sys	buildSecurityDescriptor(owner *TRUSTEE, group *TRUSTEE, countAccessEntries uint32, accessEntries *EXPLICIT_ACCESS, countAuditEntries uint32, auditEntries *EXPLICIT_ACCESS, oldSecurityDescriptor *SECURITY_DESCRIPTOR, sizeNewSecurityDescriptor *uint32, newSecurityDescriptor **SECURITY_DESCRIPTOR) (ret error) = advapi32.BuildSecurityDescriptorW
+//sys	initializeSecurityDescriptor(absoluteSD *SECURITY_DESCRIPTOR, revision uint32) (err error) = advapi32.InitializeSecurityDescriptor
+
+//sys	getSecurityDescriptorControl(sd *SECURITY_DESCRIPTOR, control *SECURITY_DESCRIPTOR_CONTROL, revision *uint32) (err error) = advapi32.GetSecurityDescriptorControl
+//sys	getSecurityDescriptorDacl(sd *SECURITY_DESCRIPTOR, daclPresent *bool, dacl **ACL, daclDefaulted *bool) (err error) = advapi32.GetSecurityDescriptorDacl
+//sys	getSecurityDescriptorSacl(sd *SECURITY_DESCRIPTOR, saclPresent *bool, sacl **ACL, saclDefaulted *bool) (err error) = advapi32.GetSecurityDescriptorSacl
+//sys	getSecurityDescriptorOwner(sd *SECURITY_DESCRIPTOR, owner **SID, ownerDefaulted *bool) (err error) = advapi32.GetSecurityDescriptorOwner
+//sys	getSecurityDescriptorGroup(sd *SECURITY_DESCRIPTOR, group **SID, groupDefaulted *bool) (err error) = advapi32.GetSecurityDescriptorGroup
+//sys	getSecurityDescriptorLength(sd *SECURITY_DESCRIPTOR) (len uint32) = advapi32.GetSecurityDescriptorLength
+//sys	getSecurityDescriptorRMControl(sd *SECURITY_DESCRIPTOR, rmControl *uint8) (ret error) [failretval!=0] = advapi32.GetSecurityDescriptorRMControl
+//sys	isValidSecurityDescriptor(sd *SECURITY_DESCRIPTOR) (isValid bool) = advapi32.IsValidSecurityDescriptor
+
+//sys	setSecurityDescriptorControl(sd *SECURITY_DESCRIPTOR, controlBitsOfInterest SECURITY_DESCRIPTOR_CONTROL, controlBitsToSet SECURITY_DESCRIPTOR_CONTROL) (err error) = advapi32.SetSecurityDescriptorControl
+//sys	setSecurityDescriptorDacl(sd *SECURITY_DESCRIPTOR, daclPresent bool, dacl *ACL, daclDefaulted bool) (err error) = advapi32.SetSecurityDescriptorDacl
+//sys	setSecurityDescriptorSacl(sd *SECURITY_DESCRIPTOR, saclPresent bool, sacl *ACL, saclDefaulted bool) (err error) = advapi32.SetSecurityDescriptorSacl
+//sys	setSecurityDescriptorOwner(sd *SECURITY_DESCRIPTOR, owner *SID, ownerDefaulted bool) (err error) = advapi32.SetSecurityDescriptorOwner
+//sys	setSecurityDescriptorGroup(sd *SECURITY_DESCRIPTOR, group *SID, groupDefaulted bool) (err error) = advapi32.SetSecurityDescriptorGroup
+//sys	setSecurityDescriptorRMControl(sd *SECURITY_DESCRIPTOR, rmControl *uint8) = advapi32.SetSecurityDescriptorRMControl
+
+//sys	convertStringSecurityDescriptorToSecurityDescriptor(str string, revision uint32, sd **SECURITY_DESCRIPTOR, size *uint32) (err error) = advapi32.ConvertStringSecurityDescriptorToSecurityDescriptorW
+//sys	convertSecurityDescriptorToStringSecurityDescriptor(sd *SECURITY_DESCRIPTOR, revision uint32, securityInformation SECURITY_INFORMATION, str **uint16, strLen *uint32) (err error) = advapi32.ConvertSecurityDescriptorToStringSecurityDescriptorW
+
+//sys	makeAbsoluteSD(selfRelativeSD *SECURITY_DESCRIPTOR, absoluteSD *SECURITY_DESCRIPTOR, absoluteSDSize *uint32, dacl *ACL, daclSize *uint32, sacl *ACL, saclSize *uint32, owner *SID, ownerSize *uint32, group *SID, groupSize *uint32) (err error) = advapi32.MakeAbsoluteSD
+//sys	makeSelfRelativeSD(absoluteSD *SECURITY_DESCRIPTOR, selfRelativeSD *SECURITY_DESCRIPTOR, selfRelativeSDSize *uint32) (err error) = advapi32.MakeSelfRelativeSD
+
+//sys	setEntriesInAcl(countExplicitEntries uint32, explicitEntries *EXPLICIT_ACCESS, oldACL *ACL, newACL **ACL) (ret error) = advapi32.SetEntriesInAclW
+
+// Control returns the security descriptor control bits.
+func (sd *SECURITY_DESCRIPTOR) Control() (control SECURITY_DESCRIPTOR_CONTROL, revision uint32, err error) {
+	err = getSecurityDescriptorControl(sd, &control, &revision)
+	return
+}
+
+// SetControl sets the security descriptor control bits.
+func (sd *SECURITY_DESCRIPTOR) SetControl(controlBitsOfInterest SECURITY_DESCRIPTOR_CONTROL, controlBitsToSet SECURITY_DESCRIPTOR_CONTROL) error {
+	return setSecurityDescriptorControl(sd, controlBitsOfInterest, controlBitsToSet)
+}
+
+// RMControl returns the security descriptor resource manager control bits.
+func (sd *SECURITY_DESCRIPTOR) RMControl() (control uint8, err error) {
+	err = getSecurityDescriptorRMControl(sd, &control)
+	return
+}
+
+// SetRMControl sets the security descriptor resource manager control bits.
+func (sd *SECURITY_DESCRIPTOR) SetRMControl(rmControl uint8) {
+	setSecurityDescriptorRMControl(sd, &rmControl)
+}
+
+// DACL returns the security descriptor DACL and whether it was defaulted. The dacl return value may be nil
+// if a DACL exists but is an "empty DACL", meaning fully permissive. If the DACL does not exist, err returns
+// ERROR_OBJECT_NOT_FOUND.
+func (sd *SECURITY_DESCRIPTOR) DACL() (dacl *ACL, defaulted bool, err error) {
+	var present bool
+	err = getSecurityDescriptorDacl(sd, &present, &dacl, &defaulted)
+	if !present {
+		err = ERROR_OBJECT_NOT_FOUND
+	}
+	return
+}
+
+// SetDACL sets the absolute security descriptor DACL.
+func (absoluteSD *SECURITY_DESCRIPTOR) SetDACL(dacl *ACL, present, defaulted bool) error {
+	return setSecurityDescriptorDacl(absoluteSD, present, dacl, defaulted)
+}
+
+// SACL returns the security descriptor SACL and whether it was defaulted. The sacl return value may be nil
+// if a SACL exists but is an "empty SACL", meaning fully permissive. If the SACL does not exist, err returns
+// ERROR_OBJECT_NOT_FOUND.
+func (sd *SECURITY_DESCRIPTOR) SACL() (sacl *ACL, defaulted bool, err error) {
+	var present bool
+	err = getSecurityDescriptorSacl(sd, &present, &sacl, &defaulted)
+	if !present {
+		err = ERROR_OBJECT_NOT_FOUND
+	}
+	return
+}
+
+// SetSACL sets the absolute security descriptor SACL.
+func (absoluteSD *SECURITY_DESCRIPTOR) SetSACL(sacl *ACL, present, defaulted bool) error {
+	return setSecurityDescriptorSacl(absoluteSD, present, sacl, defaulted)
+}
+
+// Owner returns the security descriptor owner and whether it was defaulted.
+func (sd *SECURITY_DESCRIPTOR) Owner() (owner *SID, defaulted bool, err error) {
+	err = getSecurityDescriptorOwner(sd, &owner, &defaulted)
+	return
+}
+
+// SetOwner sets the absolute security descriptor owner.
+func (absoluteSD *SECURITY_DESCRIPTOR) SetOwner(owner *SID, defaulted bool) error {
+	return setSecurityDescriptorOwner(absoluteSD, owner, defaulted)
+}
+
+// Group returns the security descriptor group and whether it was defaulted.
+func (sd *SECURITY_DESCRIPTOR) Group() (group *SID, defaulted bool, err error) {
+	err = getSecurityDescriptorGroup(sd, &group, &defaulted)
+	return
+}
+
+// SetGroup sets the absolute security descriptor owner.
+func (absoluteSD *SECURITY_DESCRIPTOR) SetGroup(group *SID, defaulted bool) error {
+	return setSecurityDescriptorGroup(absoluteSD, group, defaulted)
+}
+
+// Length returns the length of the security descriptor.
+func (sd *SECURITY_DESCRIPTOR) Length() uint32 {
+	return getSecurityDescriptorLength(sd)
+}
+
+// IsValid returns whether the security descriptor is valid.
+func (sd *SECURITY_DESCRIPTOR) IsValid() bool {
+	return isValidSecurityDescriptor(sd)
+}
+
+// String returns the SDDL form of the security descriptor, with a function signature that can be
+// used with %v formatting directives.
+func (sd *SECURITY_DESCRIPTOR) String() string {
+	var sddl *uint16
+	err := convertSecurityDescriptorToStringSecurityDescriptor(sd, 1, 0xff, &sddl, nil)
+	if err != nil {
+		return ""
+	}
+	defer LocalFree(Handle(unsafe.Pointer(sddl)))
+	return UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(sddl))[:])
+}
+
+// ToAbsolute converts a self-relative security descriptor into an absolute one.
+func (selfRelativeSD *SECURITY_DESCRIPTOR) ToAbsolute() (absoluteSD *SECURITY_DESCRIPTOR, err error) {
+	control, _, err := selfRelativeSD.Control()
+	if err != nil {
+		return
+	}
+	if control&SE_SELF_RELATIVE == 0 {
+		err = ERROR_INVALID_PARAMETER
+		return
+	}
+	var absoluteSDSize, daclSize, saclSize, ownerSize, groupSize uint32
+	err = makeAbsoluteSD(selfRelativeSD, nil, &absoluteSDSize,
+		nil, &daclSize, nil, &saclSize, nil, &ownerSize, nil, &groupSize)
+	switch err {
+	case ERROR_INSUFFICIENT_BUFFER:
+	case nil:
+		// makeAbsoluteSD is expected to fail, but it succeeds.
+		return nil, ERROR_INTERNAL_ERROR
+	default:
+		return nil, err
+	}
+	if absoluteSDSize > 0 {
+		absoluteSD = (*SECURITY_DESCRIPTOR)(unsafe.Pointer(&make([]byte, absoluteSDSize)[0]))
+	}
+	var (
+		dacl  *ACL
+		sacl  *ACL
+		owner *SID
+		group *SID
+	)
+	if daclSize > 0 {
+		dacl = (*ACL)(unsafe.Pointer(&make([]byte, daclSize)[0]))
+	}
+	if saclSize > 0 {
+		sacl = (*ACL)(unsafe.Pointer(&make([]byte, saclSize)[0]))
+	}
+	if ownerSize > 0 {
+		owner = (*SID)(unsafe.Pointer(&make([]byte, ownerSize)[0]))
+	}
+	if groupSize > 0 {
+		group = (*SID)(unsafe.Pointer(&make([]byte, groupSize)[0]))
+	}
+	err = makeAbsoluteSD(selfRelativeSD, absoluteSD, &absoluteSDSize,
+		dacl, &daclSize, sacl, &saclSize, owner, &ownerSize, group, &groupSize)
+	return
+}
+
+// ToSelfRelative converts an absolute security descriptor into a self-relative one.
+func (absoluteSD *SECURITY_DESCRIPTOR) ToSelfRelative() (selfRelativeSD *SECURITY_DESCRIPTOR, err error) {
+	control, _, err := absoluteSD.Control()
+	if err != nil {
+		return
+	}
+	if control&SE_SELF_RELATIVE != 0 {
+		err = ERROR_INVALID_PARAMETER
+		return
+	}
+	var selfRelativeSDSize uint32
+	err = makeSelfRelativeSD(absoluteSD, nil, &selfRelativeSDSize)
+	switch err {
+	case ERROR_INSUFFICIENT_BUFFER:
+	case nil:
+		// makeSelfRelativeSD is expected to fail, but it succeeds.
+		return nil, ERROR_INTERNAL_ERROR
+	default:
+		return nil, err
+	}
+	if selfRelativeSDSize > 0 {
+		selfRelativeSD = (*SECURITY_DESCRIPTOR)(unsafe.Pointer(&make([]byte, selfRelativeSDSize)[0]))
+	}
+	err = makeSelfRelativeSD(absoluteSD, selfRelativeSD, &selfRelativeSDSize)
+	return
+}
+
+func (selfRelativeSD *SECURITY_DESCRIPTOR) copySelfRelativeSecurityDescriptor() *SECURITY_DESCRIPTOR {
+	sdBytes := make([]byte, selfRelativeSD.Length())
+	copy(sdBytes, (*[(1 << 31) - 1]byte)(unsafe.Pointer(selfRelativeSD))[:len(sdBytes)])
+	return (*SECURITY_DESCRIPTOR)(unsafe.Pointer(&sdBytes[0]))
+}
+
+// SecurityDescriptorFromString converts an SDDL string describing a security descriptor into a
+// self-relative security descriptor object allocated on the Go heap.
+func SecurityDescriptorFromString(sddl string) (sd *SECURITY_DESCRIPTOR, err error) {
+	var winHeapSD *SECURITY_DESCRIPTOR
+	err = convertStringSecurityDescriptorToSecurityDescriptor(sddl, 1, &winHeapSD, nil)
+	if err != nil {
+		return
+	}
+	defer LocalFree(Handle(unsafe.Pointer(winHeapSD)))
+	return winHeapSD.copySelfRelativeSecurityDescriptor(), nil
+}
+
+// GetSecurityInfo queries the security information for a given handle and returns the self-relative security
+// descriptor result on the Go heap.
+func GetSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION) (sd *SECURITY_DESCRIPTOR, err error) {
+	var winHeapSD *SECURITY_DESCRIPTOR
+	err = getSecurityInfo(handle, objectType, securityInformation, nil, nil, nil, nil, &winHeapSD)
+	if err != nil {
+		return
+	}
+	defer LocalFree(Handle(unsafe.Pointer(winHeapSD)))
+	return winHeapSD.copySelfRelativeSecurityDescriptor(), nil
+}
+
+// GetNamedSecurityInfo queries the security information for a given named object and returns the self-relative security
+// descriptor result on the Go heap.
+func GetNamedSecurityInfo(objectName string, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION) (sd *SECURITY_DESCRIPTOR, err error) {
+	var winHeapSD *SECURITY_DESCRIPTOR
+	err = getNamedSecurityInfo(objectName, objectType, securityInformation, nil, nil, nil, nil, &winHeapSD)
+	if err != nil {
+		return
+	}
+	defer LocalFree(Handle(unsafe.Pointer(winHeapSD)))
+	return winHeapSD.copySelfRelativeSecurityDescriptor(), nil
+}
+
+// BuildSecurityDescriptor makes a new security descriptor using the input trustees, explicit access lists, and
+// prior security descriptor to be merged, any of which can be nil, returning the self-relative security descriptor
+// result on the Go heap.
+func BuildSecurityDescriptor(owner *TRUSTEE, group *TRUSTEE, accessEntries []EXPLICIT_ACCESS, auditEntries []EXPLICIT_ACCESS, mergedSecurityDescriptor *SECURITY_DESCRIPTOR) (sd *SECURITY_DESCRIPTOR, err error) {
+	var winHeapSD *SECURITY_DESCRIPTOR
+	var winHeapSDSize uint32
+	var firstAccessEntry *EXPLICIT_ACCESS
+	if len(accessEntries) > 0 {
+		firstAccessEntry = &accessEntries[0]
+	}
+	var firstAuditEntry *EXPLICIT_ACCESS
+	if len(auditEntries) > 0 {
+		firstAuditEntry = &auditEntries[0]
+	}
+	err = buildSecurityDescriptor(owner, group, uint32(len(accessEntries)), firstAccessEntry, uint32(len(auditEntries)), firstAuditEntry, mergedSecurityDescriptor, &winHeapSDSize, &winHeapSD)
+	if err != nil {
+		return
+	}
+	defer LocalFree(Handle(unsafe.Pointer(winHeapSD)))
+	return winHeapSD.copySelfRelativeSecurityDescriptor(), nil
+}
+
+// NewSecurityDescriptor creates and initializes a new absolute security descriptor.
+func NewSecurityDescriptor() (absoluteSD *SECURITY_DESCRIPTOR, err error) {
+	absoluteSD = &SECURITY_DESCRIPTOR{}
+	err = initializeSecurityDescriptor(absoluteSD, 1)
+	return
+}
+
+// ACLFromEntries returns a new ACL on the Go heap containing a list of explicit entries as well as those of another ACL.
+// Both explicitEntries and mergedACL are optional and can be nil.
+func ACLFromEntries(explicitEntries []EXPLICIT_ACCESS, mergedACL *ACL) (acl *ACL, err error) {
+	var firstExplicitEntry *EXPLICIT_ACCESS
+	if len(explicitEntries) > 0 {
+		firstExplicitEntry = &explicitEntries[0]
+	}
+	var winHeapACL *ACL
+	err = setEntriesInAcl(uint32(len(explicitEntries)), firstExplicitEntry, mergedACL, &winHeapACL)
+	if err != nil {
+		return
+	}
+	defer LocalFree(Handle(unsafe.Pointer(winHeapACL)))
+	aclBytes := make([]byte, winHeapACL.aclSize)
+	copy(aclBytes, (*[(1 << 31) - 1]byte)(unsafe.Pointer(winHeapACL))[:len(aclBytes)])
+	return (*ACL)(unsafe.Pointer(&aclBytes[0])), nil
+}

+ 136 - 0
windows/syscall_windows_test.go

@@ -10,6 +10,7 @@ import (
 	"os"
 	"path/filepath"
 	"runtime"
+	"strings"
 	"syscall"
 	"testing"
 
@@ -226,3 +227,138 @@ func TestRtlGetVersion(t *testing.T) {
 		t.Fatalf("%d.%d.%d != %d.%d.%d", version.MajorVersion, version.MinorVersion, version.BuildNumber, major, minor, build)
 	}
 }
+
+func TestGetNamedSecurityInfo(t *testing.T) {
+	path, err := windows.GetSystemDirectory()
+	if err != nil {
+		t.Fatal(err)
+	}
+	sd, err := windows.GetNamedSecurityInfo(path, windows.SE_FILE_OBJECT, windows.OWNER_SECURITY_INFORMATION)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if !sd.IsValid() {
+		t.Fatal("Invalid security descriptor")
+	}
+	sdOwner, _, err := sd.Owner()
+	if err != nil {
+		t.Fatal(err)
+	}
+	if !sdOwner.IsValid() {
+		t.Fatal("Invalid security descriptor owner")
+	}
+}
+
+func TestGetSecurityInfo(t *testing.T) {
+	process, _ := windows.GetCurrentProcess()
+	sd, err := windows.GetSecurityInfo(process, windows.SE_KERNEL_OBJECT, windows.DACL_SECURITY_INFORMATION)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if !sd.IsValid() {
+		t.Fatal("Invalid security descriptor")
+	}
+	sdStr := sd.String()
+	if !strings.HasPrefix(sdStr, "D:(A;") {
+		t.Fatalf("DACL = %q; want D:(A;...", sdStr)
+	}
+}
+
+func TestSddlConversion(t *testing.T) {
+	sd, err := windows.SecurityDescriptorFromString("O:BA")
+	if err != nil {
+		t.Fatal(err)
+	}
+	if !sd.IsValid() {
+		t.Fatal("Invalid security descriptor")
+	}
+	sdOwner, _, err := sd.Owner()
+	if err != nil {
+		t.Fatal(err)
+	}
+	if !sdOwner.IsValid() {
+		t.Fatal("Invalid security descriptor owner")
+	}
+	if !sdOwner.IsWellKnown(windows.WinBuiltinAdministratorsSid) {
+		got, _ := sdOwner.String()
+		t.Fatalf("Owner = %q; want S-1-5-32-544", got)
+	}
+}
+
+func TestBuildSecurityDescriptor(t *testing.T) {
+	const want = "O:SYD:(A;;GA;;;BA)"
+
+	adminSid, err := windows.CreateWellKnownSid(windows.WinBuiltinAdministratorsSid)
+	if err != nil {
+		t.Fatal(err)
+	}
+	systemSid, err := windows.CreateWellKnownSid(windows.WinLocalSystemSid)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	access := []windows.EXPLICIT_ACCESS{{
+		AccessPermissions: windows.GENERIC_ALL,
+		AccessMode:        windows.GRANT_ACCESS,
+		Trustee: windows.TRUSTEE{
+			TrusteeForm:  windows.TRUSTEE_IS_SID,
+			TrusteeType:  windows.TRUSTEE_IS_GROUP,
+			TrusteeValue: windows.TrusteeValueFromSID(adminSid),
+		},
+	}}
+	owner := &windows.TRUSTEE{
+		TrusteeForm:  windows.TRUSTEE_IS_SID,
+		TrusteeType:  windows.TRUSTEE_IS_USER,
+		TrusteeValue: windows.TrusteeValueFromSID(systemSid),
+	}
+
+	sd, err := windows.BuildSecurityDescriptor(owner, nil, access, nil, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+	sd, err = sd.ToAbsolute()
+	if err != nil {
+		t.Fatal(err)
+	}
+	err = sd.SetSACL(nil, false, false)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if got := sd.String(); got != want {
+		t.Fatalf("SD = %q; want %q", got, want)
+	}
+	sd, err = sd.ToSelfRelative()
+	if err != nil {
+		t.Fatal(err)
+	}
+	if got := sd.String(); got != want {
+		t.Fatalf("SD = %q; want %q", got, want)
+	}
+
+	sd, err = windows.NewSecurityDescriptor()
+	if err != nil {
+		t.Fatal(err)
+	}
+	acl, err := windows.ACLFromEntries(access, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+	err = sd.SetDACL(acl, true, false)
+	if err != nil {
+		t.Fatal(err)
+	}
+	err = sd.SetOwner(systemSid, false)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if got := sd.String(); got != want {
+		t.Fatalf("SD = %q; want %q", got, want)
+	}
+	sd, err = sd.ToSelfRelative()
+	if err != nil {
+		t.Fatal(err)
+	}
+	if got := sd.String(); got != want {
+		t.Fatalf("SD = %q; want %q", got, want)
+	}
+}

+ 0 - 12
windows/types_windows.go

@@ -62,11 +62,6 @@ var signals = [...]string{
 }
 
 const (
-	GENERIC_READ    = 0x80000000
-	GENERIC_WRITE   = 0x40000000
-	GENERIC_EXECUTE = 0x20000000
-	GENERIC_ALL     = 0x10000000
-
 	FILE_LIST_DIRECTORY   = 0x00000001
 	FILE_APPEND_DATA      = 0x00000004
 	FILE_WRITE_ATTRIBUTES = 0x00000100
@@ -158,13 +153,6 @@ const (
 	WAIT_OBJECT_0  = 0x00000000
 	WAIT_FAILED    = 0xFFFFFFFF
 
-	// Standard access rights.
-	DELETE       = 0x00010000
-	READ_CONTROL = 0x00020000
-	SYNCHRONIZE  = 0x00100000
-	WRITE_DAC    = 0x00040000
-	WRITE_OWNER  = 0x00080000
-
 	// Access rights for process.
 	PROCESS_CREATE_PROCESS            = 0x0080
 	PROCESS_CREATE_THREAD             = 0x0002

+ 647 - 267
windows/zsyscall_windows.go

@@ -51,273 +51,298 @@ var (
 	modnetapi32 = NewLazySystemDLL("netapi32.dll")
 	modwtsapi32 = NewLazySystemDLL("wtsapi32.dll")
 
-	procRegisterEventSourceW               = modadvapi32.NewProc("RegisterEventSourceW")
-	procDeregisterEventSource              = modadvapi32.NewProc("DeregisterEventSource")
-	procReportEventW                       = modadvapi32.NewProc("ReportEventW")
-	procOpenSCManagerW                     = modadvapi32.NewProc("OpenSCManagerW")
-	procCloseServiceHandle                 = modadvapi32.NewProc("CloseServiceHandle")
-	procCreateServiceW                     = modadvapi32.NewProc("CreateServiceW")
-	procOpenServiceW                       = modadvapi32.NewProc("OpenServiceW")
-	procDeleteService                      = modadvapi32.NewProc("DeleteService")
-	procStartServiceW                      = modadvapi32.NewProc("StartServiceW")
-	procQueryServiceStatus                 = modadvapi32.NewProc("QueryServiceStatus")
-	procQueryServiceLockStatusW            = modadvapi32.NewProc("QueryServiceLockStatusW")
-	procControlService                     = modadvapi32.NewProc("ControlService")
-	procStartServiceCtrlDispatcherW        = modadvapi32.NewProc("StartServiceCtrlDispatcherW")
-	procSetServiceStatus                   = modadvapi32.NewProc("SetServiceStatus")
-	procChangeServiceConfigW               = modadvapi32.NewProc("ChangeServiceConfigW")
-	procQueryServiceConfigW                = modadvapi32.NewProc("QueryServiceConfigW")
-	procChangeServiceConfig2W              = modadvapi32.NewProc("ChangeServiceConfig2W")
-	procQueryServiceConfig2W               = modadvapi32.NewProc("QueryServiceConfig2W")
-	procEnumServicesStatusExW              = modadvapi32.NewProc("EnumServicesStatusExW")
-	procQueryServiceStatusEx               = modadvapi32.NewProc("QueryServiceStatusEx")
-	procNotifyServiceStatusChangeW         = modadvapi32.NewProc("NotifyServiceStatusChangeW")
-	procGetLastError                       = modkernel32.NewProc("GetLastError")
-	procLoadLibraryW                       = modkernel32.NewProc("LoadLibraryW")
-	procLoadLibraryExW                     = modkernel32.NewProc("LoadLibraryExW")
-	procFreeLibrary                        = modkernel32.NewProc("FreeLibrary")
-	procGetProcAddress                     = modkernel32.NewProc("GetProcAddress")
-	procGetVersion                         = modkernel32.NewProc("GetVersion")
-	procFormatMessageW                     = modkernel32.NewProc("FormatMessageW")
-	procExitProcess                        = modkernel32.NewProc("ExitProcess")
-	procIsWow64Process                     = modkernel32.NewProc("IsWow64Process")
-	procCreateFileW                        = modkernel32.NewProc("CreateFileW")
-	procReadFile                           = modkernel32.NewProc("ReadFile")
-	procWriteFile                          = modkernel32.NewProc("WriteFile")
-	procGetOverlappedResult                = modkernel32.NewProc("GetOverlappedResult")
-	procSetFilePointer                     = modkernel32.NewProc("SetFilePointer")
-	procCloseHandle                        = modkernel32.NewProc("CloseHandle")
-	procGetStdHandle                       = modkernel32.NewProc("GetStdHandle")
-	procSetStdHandle                       = modkernel32.NewProc("SetStdHandle")
-	procFindFirstFileW                     = modkernel32.NewProc("FindFirstFileW")
-	procFindNextFileW                      = modkernel32.NewProc("FindNextFileW")
-	procFindClose                          = modkernel32.NewProc("FindClose")
-	procGetFileInformationByHandle         = modkernel32.NewProc("GetFileInformationByHandle")
-	procGetFileInformationByHandleEx       = modkernel32.NewProc("GetFileInformationByHandleEx")
-	procGetCurrentDirectoryW               = modkernel32.NewProc("GetCurrentDirectoryW")
-	procSetCurrentDirectoryW               = modkernel32.NewProc("SetCurrentDirectoryW")
-	procCreateDirectoryW                   = modkernel32.NewProc("CreateDirectoryW")
-	procRemoveDirectoryW                   = modkernel32.NewProc("RemoveDirectoryW")
-	procDeleteFileW                        = modkernel32.NewProc("DeleteFileW")
-	procMoveFileW                          = modkernel32.NewProc("MoveFileW")
-	procMoveFileExW                        = modkernel32.NewProc("MoveFileExW")
-	procGetComputerNameW                   = modkernel32.NewProc("GetComputerNameW")
-	procGetComputerNameExW                 = modkernel32.NewProc("GetComputerNameExW")
-	procSetEndOfFile                       = modkernel32.NewProc("SetEndOfFile")
-	procGetSystemTimeAsFileTime            = modkernel32.NewProc("GetSystemTimeAsFileTime")
-	procGetSystemTimePreciseAsFileTime     = modkernel32.NewProc("GetSystemTimePreciseAsFileTime")
-	procGetTimeZoneInformation             = modkernel32.NewProc("GetTimeZoneInformation")
-	procCreateIoCompletionPort             = modkernel32.NewProc("CreateIoCompletionPort")
-	procGetQueuedCompletionStatus          = modkernel32.NewProc("GetQueuedCompletionStatus")
-	procPostQueuedCompletionStatus         = modkernel32.NewProc("PostQueuedCompletionStatus")
-	procCancelIo                           = modkernel32.NewProc("CancelIo")
-	procCancelIoEx                         = modkernel32.NewProc("CancelIoEx")
-	procCreateProcessW                     = modkernel32.NewProc("CreateProcessW")
-	procOpenProcess                        = modkernel32.NewProc("OpenProcess")
-	procShellExecuteW                      = modshell32.NewProc("ShellExecuteW")
-	procSHGetKnownFolderPath               = modshell32.NewProc("SHGetKnownFolderPath")
-	procTerminateProcess                   = modkernel32.NewProc("TerminateProcess")
-	procGetExitCodeProcess                 = modkernel32.NewProc("GetExitCodeProcess")
-	procGetStartupInfoW                    = modkernel32.NewProc("GetStartupInfoW")
-	procGetCurrentProcess                  = modkernel32.NewProc("GetCurrentProcess")
-	procGetCurrentThread                   = modkernel32.NewProc("GetCurrentThread")
-	procGetProcessTimes                    = modkernel32.NewProc("GetProcessTimes")
-	procDuplicateHandle                    = modkernel32.NewProc("DuplicateHandle")
-	procWaitForSingleObject                = modkernel32.NewProc("WaitForSingleObject")
-	procWaitForMultipleObjects             = modkernel32.NewProc("WaitForMultipleObjects")
-	procGetTempPathW                       = modkernel32.NewProc("GetTempPathW")
-	procCreatePipe                         = modkernel32.NewProc("CreatePipe")
-	procGetFileType                        = modkernel32.NewProc("GetFileType")
-	procCryptAcquireContextW               = modadvapi32.NewProc("CryptAcquireContextW")
-	procCryptReleaseContext                = modadvapi32.NewProc("CryptReleaseContext")
-	procCryptGenRandom                     = modadvapi32.NewProc("CryptGenRandom")
-	procGetEnvironmentStringsW             = modkernel32.NewProc("GetEnvironmentStringsW")
-	procFreeEnvironmentStringsW            = modkernel32.NewProc("FreeEnvironmentStringsW")
-	procGetEnvironmentVariableW            = modkernel32.NewProc("GetEnvironmentVariableW")
-	procSetEnvironmentVariableW            = modkernel32.NewProc("SetEnvironmentVariableW")
-	procCreateEnvironmentBlock             = moduserenv.NewProc("CreateEnvironmentBlock")
-	procDestroyEnvironmentBlock            = moduserenv.NewProc("DestroyEnvironmentBlock")
-	procGetTickCount64                     = modkernel32.NewProc("GetTickCount64")
-	procSetFileTime                        = modkernel32.NewProc("SetFileTime")
-	procGetFileAttributesW                 = modkernel32.NewProc("GetFileAttributesW")
-	procSetFileAttributesW                 = modkernel32.NewProc("SetFileAttributesW")
-	procGetFileAttributesExW               = modkernel32.NewProc("GetFileAttributesExW")
-	procGetCommandLineW                    = modkernel32.NewProc("GetCommandLineW")
-	procCommandLineToArgvW                 = modshell32.NewProc("CommandLineToArgvW")
-	procLocalFree                          = modkernel32.NewProc("LocalFree")
-	procSetHandleInformation               = modkernel32.NewProc("SetHandleInformation")
-	procFlushFileBuffers                   = modkernel32.NewProc("FlushFileBuffers")
-	procGetFullPathNameW                   = modkernel32.NewProc("GetFullPathNameW")
-	procGetLongPathNameW                   = modkernel32.NewProc("GetLongPathNameW")
-	procGetShortPathNameW                  = modkernel32.NewProc("GetShortPathNameW")
-	procCreateFileMappingW                 = modkernel32.NewProc("CreateFileMappingW")
-	procMapViewOfFile                      = modkernel32.NewProc("MapViewOfFile")
-	procUnmapViewOfFile                    = modkernel32.NewProc("UnmapViewOfFile")
-	procFlushViewOfFile                    = modkernel32.NewProc("FlushViewOfFile")
-	procVirtualLock                        = modkernel32.NewProc("VirtualLock")
-	procVirtualUnlock                      = modkernel32.NewProc("VirtualUnlock")
-	procVirtualAlloc                       = modkernel32.NewProc("VirtualAlloc")
-	procVirtualFree                        = modkernel32.NewProc("VirtualFree")
-	procVirtualProtect                     = modkernel32.NewProc("VirtualProtect")
-	procTransmitFile                       = modmswsock.NewProc("TransmitFile")
-	procReadDirectoryChangesW              = modkernel32.NewProc("ReadDirectoryChangesW")
-	procCertOpenSystemStoreW               = modcrypt32.NewProc("CertOpenSystemStoreW")
-	procCertOpenStore                      = modcrypt32.NewProc("CertOpenStore")
-	procCertEnumCertificatesInStore        = modcrypt32.NewProc("CertEnumCertificatesInStore")
-	procCertAddCertificateContextToStore   = modcrypt32.NewProc("CertAddCertificateContextToStore")
-	procCertCloseStore                     = modcrypt32.NewProc("CertCloseStore")
-	procCertGetCertificateChain            = modcrypt32.NewProc("CertGetCertificateChain")
-	procCertFreeCertificateChain           = modcrypt32.NewProc("CertFreeCertificateChain")
-	procCertCreateCertificateContext       = modcrypt32.NewProc("CertCreateCertificateContext")
-	procCertFreeCertificateContext         = modcrypt32.NewProc("CertFreeCertificateContext")
-	procCertVerifyCertificateChainPolicy   = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
-	procRegOpenKeyExW                      = modadvapi32.NewProc("RegOpenKeyExW")
-	procRegCloseKey                        = modadvapi32.NewProc("RegCloseKey")
-	procRegQueryInfoKeyW                   = modadvapi32.NewProc("RegQueryInfoKeyW")
-	procRegEnumKeyExW                      = modadvapi32.NewProc("RegEnumKeyExW")
-	procRegQueryValueExW                   = modadvapi32.NewProc("RegQueryValueExW")
-	procGetCurrentProcessId                = modkernel32.NewProc("GetCurrentProcessId")
-	procGetConsoleMode                     = modkernel32.NewProc("GetConsoleMode")
-	procSetConsoleMode                     = modkernel32.NewProc("SetConsoleMode")
-	procGetConsoleScreenBufferInfo         = modkernel32.NewProc("GetConsoleScreenBufferInfo")
-	procWriteConsoleW                      = modkernel32.NewProc("WriteConsoleW")
-	procReadConsoleW                       = modkernel32.NewProc("ReadConsoleW")
-	procCreateToolhelp32Snapshot           = modkernel32.NewProc("CreateToolhelp32Snapshot")
-	procProcess32FirstW                    = modkernel32.NewProc("Process32FirstW")
-	procProcess32NextW                     = modkernel32.NewProc("Process32NextW")
-	procThread32First                      = modkernel32.NewProc("Thread32First")
-	procThread32Next                       = modkernel32.NewProc("Thread32Next")
-	procDeviceIoControl                    = modkernel32.NewProc("DeviceIoControl")
-	procCreateSymbolicLinkW                = modkernel32.NewProc("CreateSymbolicLinkW")
-	procCreateHardLinkW                    = modkernel32.NewProc("CreateHardLinkW")
-	procGetCurrentThreadId                 = modkernel32.NewProc("GetCurrentThreadId")
-	procCreateEventW                       = modkernel32.NewProc("CreateEventW")
-	procCreateEventExW                     = modkernel32.NewProc("CreateEventExW")
-	procOpenEventW                         = modkernel32.NewProc("OpenEventW")
-	procSetEvent                           = modkernel32.NewProc("SetEvent")
-	procResetEvent                         = modkernel32.NewProc("ResetEvent")
-	procPulseEvent                         = modkernel32.NewProc("PulseEvent")
-	procCreateMutexW                       = modkernel32.NewProc("CreateMutexW")
-	procCreateMutexExW                     = modkernel32.NewProc("CreateMutexExW")
-	procOpenMutexW                         = modkernel32.NewProc("OpenMutexW")
-	procReleaseMutex                       = modkernel32.NewProc("ReleaseMutex")
-	procSleepEx                            = modkernel32.NewProc("SleepEx")
-	procCreateJobObjectW                   = modkernel32.NewProc("CreateJobObjectW")
-	procAssignProcessToJobObject           = modkernel32.NewProc("AssignProcessToJobObject")
-	procTerminateJobObject                 = modkernel32.NewProc("TerminateJobObject")
-	procSetErrorMode                       = modkernel32.NewProc("SetErrorMode")
-	procResumeThread                       = modkernel32.NewProc("ResumeThread")
-	procSetPriorityClass                   = modkernel32.NewProc("SetPriorityClass")
-	procGetPriorityClass                   = modkernel32.NewProc("GetPriorityClass")
-	procSetInformationJobObject            = modkernel32.NewProc("SetInformationJobObject")
-	procGenerateConsoleCtrlEvent           = modkernel32.NewProc("GenerateConsoleCtrlEvent")
-	procGetProcessId                       = modkernel32.NewProc("GetProcessId")
-	procOpenThread                         = modkernel32.NewProc("OpenThread")
-	procSetProcessPriorityBoost            = modkernel32.NewProc("SetProcessPriorityBoost")
-	procDefineDosDeviceW                   = modkernel32.NewProc("DefineDosDeviceW")
-	procDeleteVolumeMountPointW            = modkernel32.NewProc("DeleteVolumeMountPointW")
-	procFindFirstVolumeW                   = modkernel32.NewProc("FindFirstVolumeW")
-	procFindFirstVolumeMountPointW         = modkernel32.NewProc("FindFirstVolumeMountPointW")
-	procFindNextVolumeW                    = modkernel32.NewProc("FindNextVolumeW")
-	procFindNextVolumeMountPointW          = modkernel32.NewProc("FindNextVolumeMountPointW")
-	procFindVolumeClose                    = modkernel32.NewProc("FindVolumeClose")
-	procFindVolumeMountPointClose          = modkernel32.NewProc("FindVolumeMountPointClose")
-	procGetDriveTypeW                      = modkernel32.NewProc("GetDriveTypeW")
-	procGetLogicalDrives                   = modkernel32.NewProc("GetLogicalDrives")
-	procGetLogicalDriveStringsW            = modkernel32.NewProc("GetLogicalDriveStringsW")
-	procGetVolumeInformationW              = modkernel32.NewProc("GetVolumeInformationW")
-	procGetVolumeInformationByHandleW      = modkernel32.NewProc("GetVolumeInformationByHandleW")
-	procGetVolumeNameForVolumeMountPointW  = modkernel32.NewProc("GetVolumeNameForVolumeMountPointW")
-	procGetVolumePathNameW                 = modkernel32.NewProc("GetVolumePathNameW")
-	procGetVolumePathNamesForVolumeNameW   = modkernel32.NewProc("GetVolumePathNamesForVolumeNameW")
-	procQueryDosDeviceW                    = modkernel32.NewProc("QueryDosDeviceW")
-	procSetVolumeLabelW                    = modkernel32.NewProc("SetVolumeLabelW")
-	procSetVolumeMountPointW               = modkernel32.NewProc("SetVolumeMountPointW")
-	procMessageBoxW                        = moduser32.NewProc("MessageBoxW")
-	procExitWindowsEx                      = moduser32.NewProc("ExitWindowsEx")
-	procInitiateSystemShutdownExW          = modadvapi32.NewProc("InitiateSystemShutdownExW")
-	procSetProcessShutdownParameters       = modkernel32.NewProc("SetProcessShutdownParameters")
-	procGetProcessShutdownParameters       = modkernel32.NewProc("GetProcessShutdownParameters")
-	procCLSIDFromString                    = modole32.NewProc("CLSIDFromString")
-	procStringFromGUID2                    = modole32.NewProc("StringFromGUID2")
-	procCoCreateGuid                       = modole32.NewProc("CoCreateGuid")
-	procCoTaskMemFree                      = modole32.NewProc("CoTaskMemFree")
-	procRtlGetVersion                      = modntdll.NewProc("RtlGetVersion")
-	procRtlGetNtVersionNumbers             = modntdll.NewProc("RtlGetNtVersionNumbers")
-	procWSAStartup                         = modws2_32.NewProc("WSAStartup")
-	procWSACleanup                         = modws2_32.NewProc("WSACleanup")
-	procWSAIoctl                           = modws2_32.NewProc("WSAIoctl")
-	procsocket                             = modws2_32.NewProc("socket")
-	procsetsockopt                         = modws2_32.NewProc("setsockopt")
-	procgetsockopt                         = modws2_32.NewProc("getsockopt")
-	procbind                               = modws2_32.NewProc("bind")
-	procconnect                            = modws2_32.NewProc("connect")
-	procgetsockname                        = modws2_32.NewProc("getsockname")
-	procgetpeername                        = modws2_32.NewProc("getpeername")
-	proclisten                             = modws2_32.NewProc("listen")
-	procshutdown                           = modws2_32.NewProc("shutdown")
-	procclosesocket                        = modws2_32.NewProc("closesocket")
-	procAcceptEx                           = modmswsock.NewProc("AcceptEx")
-	procGetAcceptExSockaddrs               = modmswsock.NewProc("GetAcceptExSockaddrs")
-	procWSARecv                            = modws2_32.NewProc("WSARecv")
-	procWSASend                            = modws2_32.NewProc("WSASend")
-	procWSARecvFrom                        = modws2_32.NewProc("WSARecvFrom")
-	procWSASendTo                          = modws2_32.NewProc("WSASendTo")
-	procgethostbyname                      = modws2_32.NewProc("gethostbyname")
-	procgetservbyname                      = modws2_32.NewProc("getservbyname")
-	procntohs                              = modws2_32.NewProc("ntohs")
-	procgetprotobyname                     = modws2_32.NewProc("getprotobyname")
-	procDnsQuery_W                         = moddnsapi.NewProc("DnsQuery_W")
-	procDnsRecordListFree                  = moddnsapi.NewProc("DnsRecordListFree")
-	procDnsNameCompare_W                   = moddnsapi.NewProc("DnsNameCompare_W")
-	procGetAddrInfoW                       = modws2_32.NewProc("GetAddrInfoW")
-	procFreeAddrInfoW                      = modws2_32.NewProc("FreeAddrInfoW")
-	procGetIfEntry                         = modiphlpapi.NewProc("GetIfEntry")
-	procGetAdaptersInfo                    = modiphlpapi.NewProc("GetAdaptersInfo")
-	procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
-	procWSAEnumProtocolsW                  = modws2_32.NewProc("WSAEnumProtocolsW")
-	procGetAdaptersAddresses               = modiphlpapi.NewProc("GetAdaptersAddresses")
-	procGetACP                             = modkernel32.NewProc("GetACP")
-	procMultiByteToWideChar                = modkernel32.NewProc("MultiByteToWideChar")
-	procTranslateNameW                     = modsecur32.NewProc("TranslateNameW")
-	procGetUserNameExW                     = modsecur32.NewProc("GetUserNameExW")
-	procNetUserGetInfo                     = modnetapi32.NewProc("NetUserGetInfo")
-	procNetGetJoinInformation              = modnetapi32.NewProc("NetGetJoinInformation")
-	procNetApiBufferFree                   = modnetapi32.NewProc("NetApiBufferFree")
-	procLookupAccountSidW                  = modadvapi32.NewProc("LookupAccountSidW")
-	procLookupAccountNameW                 = modadvapi32.NewProc("LookupAccountNameW")
-	procConvertSidToStringSidW             = modadvapi32.NewProc("ConvertSidToStringSidW")
-	procConvertStringSidToSidW             = modadvapi32.NewProc("ConvertStringSidToSidW")
-	procGetLengthSid                       = modadvapi32.NewProc("GetLengthSid")
-	procCopySid                            = modadvapi32.NewProc("CopySid")
-	procAllocateAndInitializeSid           = modadvapi32.NewProc("AllocateAndInitializeSid")
-	procCreateWellKnownSid                 = modadvapi32.NewProc("CreateWellKnownSid")
-	procIsWellKnownSid                     = modadvapi32.NewProc("IsWellKnownSid")
-	procFreeSid                            = modadvapi32.NewProc("FreeSid")
-	procEqualSid                           = modadvapi32.NewProc("EqualSid")
-	procGetSidIdentifierAuthority          = modadvapi32.NewProc("GetSidIdentifierAuthority")
-	procGetSidSubAuthorityCount            = modadvapi32.NewProc("GetSidSubAuthorityCount")
-	procGetSidSubAuthority                 = modadvapi32.NewProc("GetSidSubAuthority")
-	procIsValidSid                         = modadvapi32.NewProc("IsValidSid")
-	procCheckTokenMembership               = modadvapi32.NewProc("CheckTokenMembership")
-	procOpenProcessToken                   = modadvapi32.NewProc("OpenProcessToken")
-	procOpenThreadToken                    = modadvapi32.NewProc("OpenThreadToken")
-	procImpersonateSelf                    = modadvapi32.NewProc("ImpersonateSelf")
-	procRevertToSelf                       = modadvapi32.NewProc("RevertToSelf")
-	procSetThreadToken                     = modadvapi32.NewProc("SetThreadToken")
-	procLookupPrivilegeValueW              = modadvapi32.NewProc("LookupPrivilegeValueW")
-	procAdjustTokenPrivileges              = modadvapi32.NewProc("AdjustTokenPrivileges")
-	procAdjustTokenGroups                  = modadvapi32.NewProc("AdjustTokenGroups")
-	procGetTokenInformation                = modadvapi32.NewProc("GetTokenInformation")
-	procSetTokenInformation                = modadvapi32.NewProc("SetTokenInformation")
-	procDuplicateTokenEx                   = modadvapi32.NewProc("DuplicateTokenEx")
-	procGetUserProfileDirectoryW           = moduserenv.NewProc("GetUserProfileDirectoryW")
-	procGetSystemDirectoryW                = modkernel32.NewProc("GetSystemDirectoryW")
-	procGetWindowsDirectoryW               = modkernel32.NewProc("GetWindowsDirectoryW")
-	procGetSystemWindowsDirectoryW         = modkernel32.NewProc("GetSystemWindowsDirectoryW")
-	procWTSQueryUserToken                  = modwtsapi32.NewProc("WTSQueryUserToken")
-	procWTSEnumerateSessionsW              = modwtsapi32.NewProc("WTSEnumerateSessionsW")
-	procWTSFreeMemory                      = modwtsapi32.NewProc("WTSFreeMemory")
+	procRegisterEventSourceW                                 = modadvapi32.NewProc("RegisterEventSourceW")
+	procDeregisterEventSource                                = modadvapi32.NewProc("DeregisterEventSource")
+	procReportEventW                                         = modadvapi32.NewProc("ReportEventW")
+	procOpenSCManagerW                                       = modadvapi32.NewProc("OpenSCManagerW")
+	procCloseServiceHandle                                   = modadvapi32.NewProc("CloseServiceHandle")
+	procCreateServiceW                                       = modadvapi32.NewProc("CreateServiceW")
+	procOpenServiceW                                         = modadvapi32.NewProc("OpenServiceW")
+	procDeleteService                                        = modadvapi32.NewProc("DeleteService")
+	procStartServiceW                                        = modadvapi32.NewProc("StartServiceW")
+	procQueryServiceStatus                                   = modadvapi32.NewProc("QueryServiceStatus")
+	procQueryServiceLockStatusW                              = modadvapi32.NewProc("QueryServiceLockStatusW")
+	procControlService                                       = modadvapi32.NewProc("ControlService")
+	procStartServiceCtrlDispatcherW                          = modadvapi32.NewProc("StartServiceCtrlDispatcherW")
+	procSetServiceStatus                                     = modadvapi32.NewProc("SetServiceStatus")
+	procChangeServiceConfigW                                 = modadvapi32.NewProc("ChangeServiceConfigW")
+	procQueryServiceConfigW                                  = modadvapi32.NewProc("QueryServiceConfigW")
+	procChangeServiceConfig2W                                = modadvapi32.NewProc("ChangeServiceConfig2W")
+	procQueryServiceConfig2W                                 = modadvapi32.NewProc("QueryServiceConfig2W")
+	procEnumServicesStatusExW                                = modadvapi32.NewProc("EnumServicesStatusExW")
+	procQueryServiceStatusEx                                 = modadvapi32.NewProc("QueryServiceStatusEx")
+	procNotifyServiceStatusChangeW                           = modadvapi32.NewProc("NotifyServiceStatusChangeW")
+	procGetLastError                                         = modkernel32.NewProc("GetLastError")
+	procLoadLibraryW                                         = modkernel32.NewProc("LoadLibraryW")
+	procLoadLibraryExW                                       = modkernel32.NewProc("LoadLibraryExW")
+	procFreeLibrary                                          = modkernel32.NewProc("FreeLibrary")
+	procGetProcAddress                                       = modkernel32.NewProc("GetProcAddress")
+	procGetVersion                                           = modkernel32.NewProc("GetVersion")
+	procFormatMessageW                                       = modkernel32.NewProc("FormatMessageW")
+	procExitProcess                                          = modkernel32.NewProc("ExitProcess")
+	procIsWow64Process                                       = modkernel32.NewProc("IsWow64Process")
+	procCreateFileW                                          = modkernel32.NewProc("CreateFileW")
+	procReadFile                                             = modkernel32.NewProc("ReadFile")
+	procWriteFile                                            = modkernel32.NewProc("WriteFile")
+	procGetOverlappedResult                                  = modkernel32.NewProc("GetOverlappedResult")
+	procSetFilePointer                                       = modkernel32.NewProc("SetFilePointer")
+	procCloseHandle                                          = modkernel32.NewProc("CloseHandle")
+	procGetStdHandle                                         = modkernel32.NewProc("GetStdHandle")
+	procSetStdHandle                                         = modkernel32.NewProc("SetStdHandle")
+	procFindFirstFileW                                       = modkernel32.NewProc("FindFirstFileW")
+	procFindNextFileW                                        = modkernel32.NewProc("FindNextFileW")
+	procFindClose                                            = modkernel32.NewProc("FindClose")
+	procGetFileInformationByHandle                           = modkernel32.NewProc("GetFileInformationByHandle")
+	procGetFileInformationByHandleEx                         = modkernel32.NewProc("GetFileInformationByHandleEx")
+	procGetCurrentDirectoryW                                 = modkernel32.NewProc("GetCurrentDirectoryW")
+	procSetCurrentDirectoryW                                 = modkernel32.NewProc("SetCurrentDirectoryW")
+	procCreateDirectoryW                                     = modkernel32.NewProc("CreateDirectoryW")
+	procRemoveDirectoryW                                     = modkernel32.NewProc("RemoveDirectoryW")
+	procDeleteFileW                                          = modkernel32.NewProc("DeleteFileW")
+	procMoveFileW                                            = modkernel32.NewProc("MoveFileW")
+	procMoveFileExW                                          = modkernel32.NewProc("MoveFileExW")
+	procGetComputerNameW                                     = modkernel32.NewProc("GetComputerNameW")
+	procGetComputerNameExW                                   = modkernel32.NewProc("GetComputerNameExW")
+	procSetEndOfFile                                         = modkernel32.NewProc("SetEndOfFile")
+	procGetSystemTimeAsFileTime                              = modkernel32.NewProc("GetSystemTimeAsFileTime")
+	procGetSystemTimePreciseAsFileTime                       = modkernel32.NewProc("GetSystemTimePreciseAsFileTime")
+	procGetTimeZoneInformation                               = modkernel32.NewProc("GetTimeZoneInformation")
+	procCreateIoCompletionPort                               = modkernel32.NewProc("CreateIoCompletionPort")
+	procGetQueuedCompletionStatus                            = modkernel32.NewProc("GetQueuedCompletionStatus")
+	procPostQueuedCompletionStatus                           = modkernel32.NewProc("PostQueuedCompletionStatus")
+	procCancelIo                                             = modkernel32.NewProc("CancelIo")
+	procCancelIoEx                                           = modkernel32.NewProc("CancelIoEx")
+	procCreateProcessW                                       = modkernel32.NewProc("CreateProcessW")
+	procOpenProcess                                          = modkernel32.NewProc("OpenProcess")
+	procShellExecuteW                                        = modshell32.NewProc("ShellExecuteW")
+	procSHGetKnownFolderPath                                 = modshell32.NewProc("SHGetKnownFolderPath")
+	procTerminateProcess                                     = modkernel32.NewProc("TerminateProcess")
+	procGetExitCodeProcess                                   = modkernel32.NewProc("GetExitCodeProcess")
+	procGetStartupInfoW                                      = modkernel32.NewProc("GetStartupInfoW")
+	procGetCurrentProcess                                    = modkernel32.NewProc("GetCurrentProcess")
+	procGetCurrentThread                                     = modkernel32.NewProc("GetCurrentThread")
+	procGetProcessTimes                                      = modkernel32.NewProc("GetProcessTimes")
+	procDuplicateHandle                                      = modkernel32.NewProc("DuplicateHandle")
+	procWaitForSingleObject                                  = modkernel32.NewProc("WaitForSingleObject")
+	procWaitForMultipleObjects                               = modkernel32.NewProc("WaitForMultipleObjects")
+	procGetTempPathW                                         = modkernel32.NewProc("GetTempPathW")
+	procCreatePipe                                           = modkernel32.NewProc("CreatePipe")
+	procGetFileType                                          = modkernel32.NewProc("GetFileType")
+	procCryptAcquireContextW                                 = modadvapi32.NewProc("CryptAcquireContextW")
+	procCryptReleaseContext                                  = modadvapi32.NewProc("CryptReleaseContext")
+	procCryptGenRandom                                       = modadvapi32.NewProc("CryptGenRandom")
+	procGetEnvironmentStringsW                               = modkernel32.NewProc("GetEnvironmentStringsW")
+	procFreeEnvironmentStringsW                              = modkernel32.NewProc("FreeEnvironmentStringsW")
+	procGetEnvironmentVariableW                              = modkernel32.NewProc("GetEnvironmentVariableW")
+	procSetEnvironmentVariableW                              = modkernel32.NewProc("SetEnvironmentVariableW")
+	procCreateEnvironmentBlock                               = moduserenv.NewProc("CreateEnvironmentBlock")
+	procDestroyEnvironmentBlock                              = moduserenv.NewProc("DestroyEnvironmentBlock")
+	procGetTickCount64                                       = modkernel32.NewProc("GetTickCount64")
+	procSetFileTime                                          = modkernel32.NewProc("SetFileTime")
+	procGetFileAttributesW                                   = modkernel32.NewProc("GetFileAttributesW")
+	procSetFileAttributesW                                   = modkernel32.NewProc("SetFileAttributesW")
+	procGetFileAttributesExW                                 = modkernel32.NewProc("GetFileAttributesExW")
+	procGetCommandLineW                                      = modkernel32.NewProc("GetCommandLineW")
+	procCommandLineToArgvW                                   = modshell32.NewProc("CommandLineToArgvW")
+	procLocalFree                                            = modkernel32.NewProc("LocalFree")
+	procSetHandleInformation                                 = modkernel32.NewProc("SetHandleInformation")
+	procFlushFileBuffers                                     = modkernel32.NewProc("FlushFileBuffers")
+	procGetFullPathNameW                                     = modkernel32.NewProc("GetFullPathNameW")
+	procGetLongPathNameW                                     = modkernel32.NewProc("GetLongPathNameW")
+	procGetShortPathNameW                                    = modkernel32.NewProc("GetShortPathNameW")
+	procCreateFileMappingW                                   = modkernel32.NewProc("CreateFileMappingW")
+	procMapViewOfFile                                        = modkernel32.NewProc("MapViewOfFile")
+	procUnmapViewOfFile                                      = modkernel32.NewProc("UnmapViewOfFile")
+	procFlushViewOfFile                                      = modkernel32.NewProc("FlushViewOfFile")
+	procVirtualLock                                          = modkernel32.NewProc("VirtualLock")
+	procVirtualUnlock                                        = modkernel32.NewProc("VirtualUnlock")
+	procVirtualAlloc                                         = modkernel32.NewProc("VirtualAlloc")
+	procVirtualFree                                          = modkernel32.NewProc("VirtualFree")
+	procVirtualProtect                                       = modkernel32.NewProc("VirtualProtect")
+	procTransmitFile                                         = modmswsock.NewProc("TransmitFile")
+	procReadDirectoryChangesW                                = modkernel32.NewProc("ReadDirectoryChangesW")
+	procCertOpenSystemStoreW                                 = modcrypt32.NewProc("CertOpenSystemStoreW")
+	procCertOpenStore                                        = modcrypt32.NewProc("CertOpenStore")
+	procCertEnumCertificatesInStore                          = modcrypt32.NewProc("CertEnumCertificatesInStore")
+	procCertAddCertificateContextToStore                     = modcrypt32.NewProc("CertAddCertificateContextToStore")
+	procCertCloseStore                                       = modcrypt32.NewProc("CertCloseStore")
+	procCertGetCertificateChain                              = modcrypt32.NewProc("CertGetCertificateChain")
+	procCertFreeCertificateChain                             = modcrypt32.NewProc("CertFreeCertificateChain")
+	procCertCreateCertificateContext                         = modcrypt32.NewProc("CertCreateCertificateContext")
+	procCertFreeCertificateContext                           = modcrypt32.NewProc("CertFreeCertificateContext")
+	procCertVerifyCertificateChainPolicy                     = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
+	procRegOpenKeyExW                                        = modadvapi32.NewProc("RegOpenKeyExW")
+	procRegCloseKey                                          = modadvapi32.NewProc("RegCloseKey")
+	procRegQueryInfoKeyW                                     = modadvapi32.NewProc("RegQueryInfoKeyW")
+	procRegEnumKeyExW                                        = modadvapi32.NewProc("RegEnumKeyExW")
+	procRegQueryValueExW                                     = modadvapi32.NewProc("RegQueryValueExW")
+	procGetCurrentProcessId                                  = modkernel32.NewProc("GetCurrentProcessId")
+	procGetConsoleMode                                       = modkernel32.NewProc("GetConsoleMode")
+	procSetConsoleMode                                       = modkernel32.NewProc("SetConsoleMode")
+	procGetConsoleScreenBufferInfo                           = modkernel32.NewProc("GetConsoleScreenBufferInfo")
+	procWriteConsoleW                                        = modkernel32.NewProc("WriteConsoleW")
+	procReadConsoleW                                         = modkernel32.NewProc("ReadConsoleW")
+	procCreateToolhelp32Snapshot                             = modkernel32.NewProc("CreateToolhelp32Snapshot")
+	procProcess32FirstW                                      = modkernel32.NewProc("Process32FirstW")
+	procProcess32NextW                                       = modkernel32.NewProc("Process32NextW")
+	procThread32First                                        = modkernel32.NewProc("Thread32First")
+	procThread32Next                                         = modkernel32.NewProc("Thread32Next")
+	procDeviceIoControl                                      = modkernel32.NewProc("DeviceIoControl")
+	procCreateSymbolicLinkW                                  = modkernel32.NewProc("CreateSymbolicLinkW")
+	procCreateHardLinkW                                      = modkernel32.NewProc("CreateHardLinkW")
+	procGetCurrentThreadId                                   = modkernel32.NewProc("GetCurrentThreadId")
+	procCreateEventW                                         = modkernel32.NewProc("CreateEventW")
+	procCreateEventExW                                       = modkernel32.NewProc("CreateEventExW")
+	procOpenEventW                                           = modkernel32.NewProc("OpenEventW")
+	procSetEvent                                             = modkernel32.NewProc("SetEvent")
+	procResetEvent                                           = modkernel32.NewProc("ResetEvent")
+	procPulseEvent                                           = modkernel32.NewProc("PulseEvent")
+	procCreateMutexW                                         = modkernel32.NewProc("CreateMutexW")
+	procCreateMutexExW                                       = modkernel32.NewProc("CreateMutexExW")
+	procOpenMutexW                                           = modkernel32.NewProc("OpenMutexW")
+	procReleaseMutex                                         = modkernel32.NewProc("ReleaseMutex")
+	procSleepEx                                              = modkernel32.NewProc("SleepEx")
+	procCreateJobObjectW                                     = modkernel32.NewProc("CreateJobObjectW")
+	procAssignProcessToJobObject                             = modkernel32.NewProc("AssignProcessToJobObject")
+	procTerminateJobObject                                   = modkernel32.NewProc("TerminateJobObject")
+	procSetErrorMode                                         = modkernel32.NewProc("SetErrorMode")
+	procResumeThread                                         = modkernel32.NewProc("ResumeThread")
+	procSetPriorityClass                                     = modkernel32.NewProc("SetPriorityClass")
+	procGetPriorityClass                                     = modkernel32.NewProc("GetPriorityClass")
+	procSetInformationJobObject                              = modkernel32.NewProc("SetInformationJobObject")
+	procGenerateConsoleCtrlEvent                             = modkernel32.NewProc("GenerateConsoleCtrlEvent")
+	procGetProcessId                                         = modkernel32.NewProc("GetProcessId")
+	procOpenThread                                           = modkernel32.NewProc("OpenThread")
+	procSetProcessPriorityBoost                              = modkernel32.NewProc("SetProcessPriorityBoost")
+	procDefineDosDeviceW                                     = modkernel32.NewProc("DefineDosDeviceW")
+	procDeleteVolumeMountPointW                              = modkernel32.NewProc("DeleteVolumeMountPointW")
+	procFindFirstVolumeW                                     = modkernel32.NewProc("FindFirstVolumeW")
+	procFindFirstVolumeMountPointW                           = modkernel32.NewProc("FindFirstVolumeMountPointW")
+	procFindNextVolumeW                                      = modkernel32.NewProc("FindNextVolumeW")
+	procFindNextVolumeMountPointW                            = modkernel32.NewProc("FindNextVolumeMountPointW")
+	procFindVolumeClose                                      = modkernel32.NewProc("FindVolumeClose")
+	procFindVolumeMountPointClose                            = modkernel32.NewProc("FindVolumeMountPointClose")
+	procGetDriveTypeW                                        = modkernel32.NewProc("GetDriveTypeW")
+	procGetLogicalDrives                                     = modkernel32.NewProc("GetLogicalDrives")
+	procGetLogicalDriveStringsW                              = modkernel32.NewProc("GetLogicalDriveStringsW")
+	procGetVolumeInformationW                                = modkernel32.NewProc("GetVolumeInformationW")
+	procGetVolumeInformationByHandleW                        = modkernel32.NewProc("GetVolumeInformationByHandleW")
+	procGetVolumeNameForVolumeMountPointW                    = modkernel32.NewProc("GetVolumeNameForVolumeMountPointW")
+	procGetVolumePathNameW                                   = modkernel32.NewProc("GetVolumePathNameW")
+	procGetVolumePathNamesForVolumeNameW                     = modkernel32.NewProc("GetVolumePathNamesForVolumeNameW")
+	procQueryDosDeviceW                                      = modkernel32.NewProc("QueryDosDeviceW")
+	procSetVolumeLabelW                                      = modkernel32.NewProc("SetVolumeLabelW")
+	procSetVolumeMountPointW                                 = modkernel32.NewProc("SetVolumeMountPointW")
+	procMessageBoxW                                          = moduser32.NewProc("MessageBoxW")
+	procExitWindowsEx                                        = moduser32.NewProc("ExitWindowsEx")
+	procInitiateSystemShutdownExW                            = modadvapi32.NewProc("InitiateSystemShutdownExW")
+	procSetProcessShutdownParameters                         = modkernel32.NewProc("SetProcessShutdownParameters")
+	procGetProcessShutdownParameters                         = modkernel32.NewProc("GetProcessShutdownParameters")
+	procCLSIDFromString                                      = modole32.NewProc("CLSIDFromString")
+	procStringFromGUID2                                      = modole32.NewProc("StringFromGUID2")
+	procCoCreateGuid                                         = modole32.NewProc("CoCreateGuid")
+	procCoTaskMemFree                                        = modole32.NewProc("CoTaskMemFree")
+	procRtlGetVersion                                        = modntdll.NewProc("RtlGetVersion")
+	procRtlGetNtVersionNumbers                               = modntdll.NewProc("RtlGetNtVersionNumbers")
+	procWSAStartup                                           = modws2_32.NewProc("WSAStartup")
+	procWSACleanup                                           = modws2_32.NewProc("WSACleanup")
+	procWSAIoctl                                             = modws2_32.NewProc("WSAIoctl")
+	procsocket                                               = modws2_32.NewProc("socket")
+	procsetsockopt                                           = modws2_32.NewProc("setsockopt")
+	procgetsockopt                                           = modws2_32.NewProc("getsockopt")
+	procbind                                                 = modws2_32.NewProc("bind")
+	procconnect                                              = modws2_32.NewProc("connect")
+	procgetsockname                                          = modws2_32.NewProc("getsockname")
+	procgetpeername                                          = modws2_32.NewProc("getpeername")
+	proclisten                                               = modws2_32.NewProc("listen")
+	procshutdown                                             = modws2_32.NewProc("shutdown")
+	procclosesocket                                          = modws2_32.NewProc("closesocket")
+	procAcceptEx                                             = modmswsock.NewProc("AcceptEx")
+	procGetAcceptExSockaddrs                                 = modmswsock.NewProc("GetAcceptExSockaddrs")
+	procWSARecv                                              = modws2_32.NewProc("WSARecv")
+	procWSASend                                              = modws2_32.NewProc("WSASend")
+	procWSARecvFrom                                          = modws2_32.NewProc("WSARecvFrom")
+	procWSASendTo                                            = modws2_32.NewProc("WSASendTo")
+	procgethostbyname                                        = modws2_32.NewProc("gethostbyname")
+	procgetservbyname                                        = modws2_32.NewProc("getservbyname")
+	procntohs                                                = modws2_32.NewProc("ntohs")
+	procgetprotobyname                                       = modws2_32.NewProc("getprotobyname")
+	procDnsQuery_W                                           = moddnsapi.NewProc("DnsQuery_W")
+	procDnsRecordListFree                                    = moddnsapi.NewProc("DnsRecordListFree")
+	procDnsNameCompare_W                                     = moddnsapi.NewProc("DnsNameCompare_W")
+	procGetAddrInfoW                                         = modws2_32.NewProc("GetAddrInfoW")
+	procFreeAddrInfoW                                        = modws2_32.NewProc("FreeAddrInfoW")
+	procGetIfEntry                                           = modiphlpapi.NewProc("GetIfEntry")
+	procGetAdaptersInfo                                      = modiphlpapi.NewProc("GetAdaptersInfo")
+	procSetFileCompletionNotificationModes                   = modkernel32.NewProc("SetFileCompletionNotificationModes")
+	procWSAEnumProtocolsW                                    = modws2_32.NewProc("WSAEnumProtocolsW")
+	procGetAdaptersAddresses                                 = modiphlpapi.NewProc("GetAdaptersAddresses")
+	procGetACP                                               = modkernel32.NewProc("GetACP")
+	procMultiByteToWideChar                                  = modkernel32.NewProc("MultiByteToWideChar")
+	procTranslateNameW                                       = modsecur32.NewProc("TranslateNameW")
+	procGetUserNameExW                                       = modsecur32.NewProc("GetUserNameExW")
+	procNetUserGetInfo                                       = modnetapi32.NewProc("NetUserGetInfo")
+	procNetGetJoinInformation                                = modnetapi32.NewProc("NetGetJoinInformation")
+	procNetApiBufferFree                                     = modnetapi32.NewProc("NetApiBufferFree")
+	procLookupAccountSidW                                    = modadvapi32.NewProc("LookupAccountSidW")
+	procLookupAccountNameW                                   = modadvapi32.NewProc("LookupAccountNameW")
+	procConvertSidToStringSidW                               = modadvapi32.NewProc("ConvertSidToStringSidW")
+	procConvertStringSidToSidW                               = modadvapi32.NewProc("ConvertStringSidToSidW")
+	procGetLengthSid                                         = modadvapi32.NewProc("GetLengthSid")
+	procCopySid                                              = modadvapi32.NewProc("CopySid")
+	procAllocateAndInitializeSid                             = modadvapi32.NewProc("AllocateAndInitializeSid")
+	procCreateWellKnownSid                                   = modadvapi32.NewProc("CreateWellKnownSid")
+	procIsWellKnownSid                                       = modadvapi32.NewProc("IsWellKnownSid")
+	procFreeSid                                              = modadvapi32.NewProc("FreeSid")
+	procEqualSid                                             = modadvapi32.NewProc("EqualSid")
+	procGetSidIdentifierAuthority                            = modadvapi32.NewProc("GetSidIdentifierAuthority")
+	procGetSidSubAuthorityCount                              = modadvapi32.NewProc("GetSidSubAuthorityCount")
+	procGetSidSubAuthority                                   = modadvapi32.NewProc("GetSidSubAuthority")
+	procIsValidSid                                           = modadvapi32.NewProc("IsValidSid")
+	procCheckTokenMembership                                 = modadvapi32.NewProc("CheckTokenMembership")
+	procOpenProcessToken                                     = modadvapi32.NewProc("OpenProcessToken")
+	procOpenThreadToken                                      = modadvapi32.NewProc("OpenThreadToken")
+	procImpersonateSelf                                      = modadvapi32.NewProc("ImpersonateSelf")
+	procRevertToSelf                                         = modadvapi32.NewProc("RevertToSelf")
+	procSetThreadToken                                       = modadvapi32.NewProc("SetThreadToken")
+	procLookupPrivilegeValueW                                = modadvapi32.NewProc("LookupPrivilegeValueW")
+	procAdjustTokenPrivileges                                = modadvapi32.NewProc("AdjustTokenPrivileges")
+	procAdjustTokenGroups                                    = modadvapi32.NewProc("AdjustTokenGroups")
+	procGetTokenInformation                                  = modadvapi32.NewProc("GetTokenInformation")
+	procSetTokenInformation                                  = modadvapi32.NewProc("SetTokenInformation")
+	procDuplicateTokenEx                                     = modadvapi32.NewProc("DuplicateTokenEx")
+	procGetUserProfileDirectoryW                             = moduserenv.NewProc("GetUserProfileDirectoryW")
+	procGetSystemDirectoryW                                  = modkernel32.NewProc("GetSystemDirectoryW")
+	procGetWindowsDirectoryW                                 = modkernel32.NewProc("GetWindowsDirectoryW")
+	procGetSystemWindowsDirectoryW                           = modkernel32.NewProc("GetSystemWindowsDirectoryW")
+	procWTSQueryUserToken                                    = modwtsapi32.NewProc("WTSQueryUserToken")
+	procWTSEnumerateSessionsW                                = modwtsapi32.NewProc("WTSEnumerateSessionsW")
+	procWTSFreeMemory                                        = modwtsapi32.NewProc("WTSFreeMemory")
+	procGetSecurityInfo                                      = modadvapi32.NewProc("GetSecurityInfo")
+	procSetSecurityInfo                                      = modadvapi32.NewProc("SetSecurityInfo")
+	procGetNamedSecurityInfoW                                = modadvapi32.NewProc("GetNamedSecurityInfoW")
+	procSetNamedSecurityInfoW                                = modadvapi32.NewProc("SetNamedSecurityInfoW")
+	procBuildSecurityDescriptorW                             = modadvapi32.NewProc("BuildSecurityDescriptorW")
+	procInitializeSecurityDescriptor                         = modadvapi32.NewProc("InitializeSecurityDescriptor")
+	procGetSecurityDescriptorControl                         = modadvapi32.NewProc("GetSecurityDescriptorControl")
+	procGetSecurityDescriptorDacl                            = modadvapi32.NewProc("GetSecurityDescriptorDacl")
+	procGetSecurityDescriptorSacl                            = modadvapi32.NewProc("GetSecurityDescriptorSacl")
+	procGetSecurityDescriptorOwner                           = modadvapi32.NewProc("GetSecurityDescriptorOwner")
+	procGetSecurityDescriptorGroup                           = modadvapi32.NewProc("GetSecurityDescriptorGroup")
+	procGetSecurityDescriptorLength                          = modadvapi32.NewProc("GetSecurityDescriptorLength")
+	procGetSecurityDescriptorRMControl                       = modadvapi32.NewProc("GetSecurityDescriptorRMControl")
+	procIsValidSecurityDescriptor                            = modadvapi32.NewProc("IsValidSecurityDescriptor")
+	procSetSecurityDescriptorControl                         = modadvapi32.NewProc("SetSecurityDescriptorControl")
+	procSetSecurityDescriptorDacl                            = modadvapi32.NewProc("SetSecurityDescriptorDacl")
+	procSetSecurityDescriptorSacl                            = modadvapi32.NewProc("SetSecurityDescriptorSacl")
+	procSetSecurityDescriptorOwner                           = modadvapi32.NewProc("SetSecurityDescriptorOwner")
+	procSetSecurityDescriptorGroup                           = modadvapi32.NewProc("SetSecurityDescriptorGroup")
+	procSetSecurityDescriptorRMControl                       = modadvapi32.NewProc("SetSecurityDescriptorRMControl")
+	procConvertStringSecurityDescriptorToSecurityDescriptorW = modadvapi32.NewProc("ConvertStringSecurityDescriptorToSecurityDescriptorW")
+	procConvertSecurityDescriptorToStringSecurityDescriptorW = modadvapi32.NewProc("ConvertSecurityDescriptorToStringSecurityDescriptorW")
+	procMakeAbsoluteSD                                       = modadvapi32.NewProc("MakeAbsoluteSD")
+	procMakeSelfRelativeSD                                   = modadvapi32.NewProc("MakeSelfRelativeSD")
+	procSetEntriesInAclW                                     = modadvapi32.NewProc("SetEntriesInAclW")
 )
 
 func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) {
@@ -3526,3 +3551,358 @@ func WTSFreeMemory(ptr uintptr) {
 	syscall.Syscall(procWTSFreeMemory.Addr(), 1, uintptr(ptr), 0, 0)
 	return
 }
+
+func getSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner **SID, group **SID, dacl **ACL, sacl **ACL, sd **SECURITY_DESCRIPTOR) (ret error) {
+	r0, _, _ := syscall.Syscall9(procGetSecurityInfo.Addr(), 8, uintptr(handle), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(sd)), 0)
+	if r0 != 0 {
+		ret = syscall.Errno(r0)
+	}
+	return
+}
+
+func SetSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner *SID, group *SID, dacl *ACL, sacl *ACL) {
+	syscall.Syscall9(procSetSecurityInfo.Addr(), 7, uintptr(handle), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), 0, 0)
+	return
+}
+
+func getNamedSecurityInfo(objectName string, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner **SID, group **SID, dacl **ACL, sacl **ACL, sd **SECURITY_DESCRIPTOR) (ret error) {
+	var _p0 *uint16
+	_p0, ret = syscall.UTF16PtrFromString(objectName)
+	if ret != nil {
+		return
+	}
+	return _getNamedSecurityInfo(_p0, objectType, securityInformation, owner, group, dacl, sacl, sd)
+}
+
+func _getNamedSecurityInfo(objectName *uint16, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner **SID, group **SID, dacl **ACL, sacl **ACL, sd **SECURITY_DESCRIPTOR) (ret error) {
+	r0, _, _ := syscall.Syscall9(procGetNamedSecurityInfoW.Addr(), 8, uintptr(unsafe.Pointer(objectName)), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(sd)), 0)
+	if r0 != 0 {
+		ret = syscall.Errno(r0)
+	}
+	return
+}
+
+func SetNamedSecurityInfo(objectName string, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner *SID, group *SID, dacl *ACL, sacl *ACL) (ret error) {
+	var _p0 *uint16
+	_p0, ret = syscall.UTF16PtrFromString(objectName)
+	if ret != nil {
+		return
+	}
+	return _SetNamedSecurityInfo(_p0, objectType, securityInformation, owner, group, dacl, sacl)
+}
+
+func _SetNamedSecurityInfo(objectName *uint16, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner *SID, group *SID, dacl *ACL, sacl *ACL) (ret error) {
+	r0, _, _ := syscall.Syscall9(procSetNamedSecurityInfoW.Addr(), 7, uintptr(unsafe.Pointer(objectName)), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), 0, 0)
+	if r0 != 0 {
+		ret = syscall.Errno(r0)
+	}
+	return
+}
+
+func buildSecurityDescriptor(owner *TRUSTEE, group *TRUSTEE, countAccessEntries uint32, accessEntries *EXPLICIT_ACCESS, countAuditEntries uint32, auditEntries *EXPLICIT_ACCESS, oldSecurityDescriptor *SECURITY_DESCRIPTOR, sizeNewSecurityDescriptor *uint32, newSecurityDescriptor **SECURITY_DESCRIPTOR) (ret error) {
+	r0, _, _ := syscall.Syscall9(procBuildSecurityDescriptorW.Addr(), 9, uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(countAccessEntries), uintptr(unsafe.Pointer(accessEntries)), uintptr(countAuditEntries), uintptr(unsafe.Pointer(auditEntries)), uintptr(unsafe.Pointer(oldSecurityDescriptor)), uintptr(unsafe.Pointer(sizeNewSecurityDescriptor)), uintptr(unsafe.Pointer(newSecurityDescriptor)))
+	if r0 != 0 {
+		ret = syscall.Errno(r0)
+	}
+	return
+}
+
+func initializeSecurityDescriptor(absoluteSD *SECURITY_DESCRIPTOR, revision uint32) (err error) {
+	r1, _, e1 := syscall.Syscall(procInitializeSecurityDescriptor.Addr(), 2, uintptr(unsafe.Pointer(absoluteSD)), uintptr(revision), 0)
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func getSecurityDescriptorControl(sd *SECURITY_DESCRIPTOR, control *SECURITY_DESCRIPTOR_CONTROL, revision *uint32) (err error) {
+	r1, _, e1 := syscall.Syscall(procGetSecurityDescriptorControl.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(control)), uintptr(unsafe.Pointer(revision)))
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func getSecurityDescriptorDacl(sd *SECURITY_DESCRIPTOR, daclPresent *bool, dacl **ACL, daclDefaulted *bool) (err error) {
+	var _p0 uint32
+	if *daclPresent {
+		_p0 = 1
+	} else {
+		_p0 = 0
+	}
+	var _p1 uint32
+	if *daclDefaulted {
+		_p1 = 1
+	} else {
+		_p1 = 0
+	}
+	r1, _, e1 := syscall.Syscall6(procGetSecurityDescriptorDacl.Addr(), 4, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(&_p0)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(&_p1)), 0, 0)
+	*daclPresent = _p0 != 0
+	*daclDefaulted = _p1 != 0
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func getSecurityDescriptorSacl(sd *SECURITY_DESCRIPTOR, saclPresent *bool, sacl **ACL, saclDefaulted *bool) (err error) {
+	var _p0 uint32
+	if *saclPresent {
+		_p0 = 1
+	} else {
+		_p0 = 0
+	}
+	var _p1 uint32
+	if *saclDefaulted {
+		_p1 = 1
+	} else {
+		_p1 = 0
+	}
+	r1, _, e1 := syscall.Syscall6(procGetSecurityDescriptorSacl.Addr(), 4, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(&_p0)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(&_p1)), 0, 0)
+	*saclPresent = _p0 != 0
+	*saclDefaulted = _p1 != 0
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func getSecurityDescriptorOwner(sd *SECURITY_DESCRIPTOR, owner **SID, ownerDefaulted *bool) (err error) {
+	var _p0 uint32
+	if *ownerDefaulted {
+		_p0 = 1
+	} else {
+		_p0 = 0
+	}
+	r1, _, e1 := syscall.Syscall(procGetSecurityDescriptorOwner.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(&_p0)))
+	*ownerDefaulted = _p0 != 0
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func getSecurityDescriptorGroup(sd *SECURITY_DESCRIPTOR, group **SID, groupDefaulted *bool) (err error) {
+	var _p0 uint32
+	if *groupDefaulted {
+		_p0 = 1
+	} else {
+		_p0 = 0
+	}
+	r1, _, e1 := syscall.Syscall(procGetSecurityDescriptorGroup.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(&_p0)))
+	*groupDefaulted = _p0 != 0
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func getSecurityDescriptorLength(sd *SECURITY_DESCRIPTOR) (len uint32) {
+	r0, _, _ := syscall.Syscall(procGetSecurityDescriptorLength.Addr(), 1, uintptr(unsafe.Pointer(sd)), 0, 0)
+	len = uint32(r0)
+	return
+}
+
+func getSecurityDescriptorRMControl(sd *SECURITY_DESCRIPTOR, rmControl *uint8) (ret error) {
+	r0, _, _ := syscall.Syscall(procGetSecurityDescriptorRMControl.Addr(), 2, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(rmControl)), 0)
+	if r0 != 0 {
+		ret = syscall.Errno(r0)
+	}
+	return
+}
+
+func isValidSecurityDescriptor(sd *SECURITY_DESCRIPTOR) (isValid bool) {
+	r0, _, _ := syscall.Syscall(procIsValidSecurityDescriptor.Addr(), 1, uintptr(unsafe.Pointer(sd)), 0, 0)
+	isValid = r0 != 0
+	return
+}
+
+func setSecurityDescriptorControl(sd *SECURITY_DESCRIPTOR, controlBitsOfInterest SECURITY_DESCRIPTOR_CONTROL, controlBitsToSet SECURITY_DESCRIPTOR_CONTROL) (err error) {
+	r1, _, e1 := syscall.Syscall(procSetSecurityDescriptorControl.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(controlBitsOfInterest), uintptr(controlBitsToSet))
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func setSecurityDescriptorDacl(sd *SECURITY_DESCRIPTOR, daclPresent bool, dacl *ACL, daclDefaulted bool) (err error) {
+	var _p0 uint32
+	if daclPresent {
+		_p0 = 1
+	} else {
+		_p0 = 0
+	}
+	var _p1 uint32
+	if daclDefaulted {
+		_p1 = 1
+	} else {
+		_p1 = 0
+	}
+	r1, _, e1 := syscall.Syscall6(procSetSecurityDescriptorDacl.Addr(), 4, uintptr(unsafe.Pointer(sd)), uintptr(_p0), uintptr(unsafe.Pointer(dacl)), uintptr(_p1), 0, 0)
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func setSecurityDescriptorSacl(sd *SECURITY_DESCRIPTOR, saclPresent bool, sacl *ACL, saclDefaulted bool) (err error) {
+	var _p0 uint32
+	if saclPresent {
+		_p0 = 1
+	} else {
+		_p0 = 0
+	}
+	var _p1 uint32
+	if saclDefaulted {
+		_p1 = 1
+	} else {
+		_p1 = 0
+	}
+	r1, _, e1 := syscall.Syscall6(procSetSecurityDescriptorSacl.Addr(), 4, uintptr(unsafe.Pointer(sd)), uintptr(_p0), uintptr(unsafe.Pointer(sacl)), uintptr(_p1), 0, 0)
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func setSecurityDescriptorOwner(sd *SECURITY_DESCRIPTOR, owner *SID, ownerDefaulted bool) (err error) {
+	var _p0 uint32
+	if ownerDefaulted {
+		_p0 = 1
+	} else {
+		_p0 = 0
+	}
+	r1, _, e1 := syscall.Syscall(procSetSecurityDescriptorOwner.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(owner)), uintptr(_p0))
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func setSecurityDescriptorGroup(sd *SECURITY_DESCRIPTOR, group *SID, groupDefaulted bool) (err error) {
+	var _p0 uint32
+	if groupDefaulted {
+		_p0 = 1
+	} else {
+		_p0 = 0
+	}
+	r1, _, e1 := syscall.Syscall(procSetSecurityDescriptorGroup.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(group)), uintptr(_p0))
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func setSecurityDescriptorRMControl(sd *SECURITY_DESCRIPTOR, rmControl *uint8) {
+	syscall.Syscall(procSetSecurityDescriptorRMControl.Addr(), 2, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(rmControl)), 0)
+	return
+}
+
+func convertStringSecurityDescriptorToSecurityDescriptor(str string, revision uint32, sd **SECURITY_DESCRIPTOR, size *uint32) (err error) {
+	var _p0 *uint16
+	_p0, err = syscall.UTF16PtrFromString(str)
+	if err != nil {
+		return
+	}
+	return _convertStringSecurityDescriptorToSecurityDescriptor(_p0, revision, sd, size)
+}
+
+func _convertStringSecurityDescriptorToSecurityDescriptor(str *uint16, revision uint32, sd **SECURITY_DESCRIPTOR, size *uint32) (err error) {
+	r1, _, e1 := syscall.Syscall6(procConvertStringSecurityDescriptorToSecurityDescriptorW.Addr(), 4, uintptr(unsafe.Pointer(str)), uintptr(revision), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(size)), 0, 0)
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func convertSecurityDescriptorToStringSecurityDescriptor(sd *SECURITY_DESCRIPTOR, revision uint32, securityInformation SECURITY_INFORMATION, str **uint16, strLen *uint32) (err error) {
+	r1, _, e1 := syscall.Syscall6(procConvertSecurityDescriptorToStringSecurityDescriptorW.Addr(), 5, uintptr(unsafe.Pointer(sd)), uintptr(revision), uintptr(securityInformation), uintptr(unsafe.Pointer(str)), uintptr(unsafe.Pointer(strLen)), 0)
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func makeAbsoluteSD(selfRelativeSD *SECURITY_DESCRIPTOR, absoluteSD *SECURITY_DESCRIPTOR, absoluteSDSize *uint32, dacl *ACL, daclSize *uint32, sacl *ACL, saclSize *uint32, owner *SID, ownerSize *uint32, group *SID, groupSize *uint32) (err error) {
+	r1, _, e1 := syscall.Syscall12(procMakeAbsoluteSD.Addr(), 11, uintptr(unsafe.Pointer(selfRelativeSD)), uintptr(unsafe.Pointer(absoluteSD)), uintptr(unsafe.Pointer(absoluteSDSize)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(daclSize)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(saclSize)), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(ownerSize)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(groupSize)), 0)
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func makeSelfRelativeSD(absoluteSD *SECURITY_DESCRIPTOR, selfRelativeSD *SECURITY_DESCRIPTOR, selfRelativeSDSize *uint32) (err error) {
+	r1, _, e1 := syscall.Syscall(procMakeSelfRelativeSD.Addr(), 3, uintptr(unsafe.Pointer(absoluteSD)), uintptr(unsafe.Pointer(selfRelativeSD)), uintptr(unsafe.Pointer(selfRelativeSDSize)))
+	if r1 == 0 {
+		if e1 != 0 {
+			err = errnoErr(e1)
+		} else {
+			err = syscall.EINVAL
+		}
+	}
+	return
+}
+
+func setEntriesInAcl(countExplicitEntries uint32, explicitEntries *EXPLICIT_ACCESS, oldACL *ACL, newACL **ACL) (ret error) {
+	r0, _, _ := syscall.Syscall6(procSetEntriesInAclW.Addr(), 4, uintptr(countExplicitEntries), uintptr(unsafe.Pointer(explicitEntries)), uintptr(unsafe.Pointer(oldACL)), uintptr(unsafe.Pointer(newACL)), 0, 0)
+	if r0 != 0 {
+		ret = syscall.Errno(r0)
+	}
+	return
+}