├── LICENSE ├── README.md ├── adspn.go ├── adsysinfo.go ├── adtranslate.go ├── bstr.go ├── cmdline.go ├── comerror.go ├── cominit.go ├── console.go ├── critsect.go ├── diskperf.go ├── diskspace.go ├── environment.go ├── error.go ├── eventlog.go ├── file.go ├── fileop.go ├── fileversion.go ├── findfile.go ├── firewall.go ├── fqdn.go ├── geometry.go ├── installer.go ├── installer_test.go ├── internet.go ├── iphlp.go ├── job.go ├── memory.go ├── module.go ├── netstat.go ├── nls.go ├── nterror.go ├── permissions.go ├── policy.go ├── process.go ├── registry.go ├── resource.go ├── security.go ├── service.go ├── shell.go ├── socket.go ├── symlink.go ├── sysdir.go ├── sysinfo.go ├── system.go ├── tempfile.go ├── time.go ├── version.go ├── volume.go ├── window.go ├── wrappers ├── accctrl.go ├── aclapi.go ├── adserr.go ├── guiddef.go ├── iads.go ├── icftypes.go ├── iphlpapi.go ├── knownfolders.go ├── msi.go ├── netfw.go ├── ntdsapi.go ├── ntifs.go ├── ntsecapi.go ├── oaidl.go ├── oaidl_386.go ├── oaidl_amd64.go ├── oaidl_arm.go ├── oaidl_arm64.go ├── objbase.go ├── oleauto.go ├── reason.go ├── sddl.go ├── shellapi.go ├── shlobj.go ├── tcpmib.go ├── tlhelp32.go ├── unknwn.go ├── verrsrc.go ├── winbase.go ├── winbase_386.go ├── winbase_amd64.go ├── winbase_arm.go ├── winbase_arm64.go ├── wincon.go ├── windef.go ├── winerror.go ├── wingdi.go ├── wininet.go ├── winioctl.go ├── winnls.go ├── winnt.go ├── winnt_386.go ├── winnt_amd64.go ├── winnt_arm.go ├── winnt_arm64.go ├── winreg.go ├── winsock2.go ├── winsvc.go ├── winternl.go ├── winuser.go ├── winver.go ├── ws2def.go ├── ws2tcpip.go ├── wtsapi32.go └── wtypes.go └── wts.go /README.md: -------------------------------------------------------------------------------- 1 | gowin32 2 | ======= 3 | 4 | This library provides wrappers to facilitate calling the Win32 API from Go. The `wrappers` package contains wrappers 5 | that directly expose certain portions of the Win32 API in Go, similar to what is provided by the `syscall` package in 6 | the Go runtime. The `gowin32` package contains helper functions and data structures that encapsulate Win32 7 | functionality in a more Go-friendly manner. Developers may elect to use either package or to combine both of them as 8 | they see fit. 9 | 10 | This library is based on the Windows SDK 7.1. 11 | -------------------------------------------------------------------------------- /adspn.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | type ADSPNOperation int32 26 | 27 | const ( 28 | ADSPNOperationAdd ADSPNOperation = wrappers.DS_SPN_ADD_SPN_OP 29 | ADSPNOperationReplace ADSPNOperation = wrappers.DS_SPN_REPLACE_SPN_OP 30 | ADSPNOperationDelete ADSPNOperation = wrappers.DS_SPN_DELETE_SPN_OP 31 | ) 32 | 33 | func RegisterADServerSPN(operation ADSPNOperation, serviceClass string, userObjectDN string) error { 34 | var userObjectDNRaw *uint16 35 | if userObjectDN != "" { 36 | userObjectDNRaw = syscall.StringToUTF16Ptr(userObjectDN) 37 | } 38 | err := wrappers.DsServerRegisterSpn( 39 | int32(operation), 40 | syscall.StringToUTF16Ptr(serviceClass), 41 | userObjectDNRaw) 42 | if err != nil { 43 | return NewWindowsError("DsServerRegisterSpn", err) 44 | } 45 | return nil 46 | } 47 | -------------------------------------------------------------------------------- /adsysinfo.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "unsafe" 23 | ) 24 | 25 | type ADSystemInfo struct { 26 | object *wrappers.IADsADSystemInfo 27 | } 28 | 29 | func NewADSystemInfo() (*ADSystemInfo, error) { 30 | var object uintptr 31 | hr := wrappers.CoCreateInstance( 32 | &wrappers.CLSID_ADSystemInfo, 33 | nil, 34 | wrappers.CLSCTX_INPROC_SERVER, 35 | &wrappers.IID_IADsADSystemInfo, 36 | &object) 37 | if wrappers.FAILED(hr) { 38 | return nil, NewWindowsError("CoCreateInstance", COMError(hr)) 39 | } 40 | return &ADSystemInfo{object: (*wrappers.IADsADSystemInfo)(unsafe.Pointer(object))}, nil 41 | } 42 | 43 | func (self *ADSystemInfo) Close() error { 44 | if self.object != nil { 45 | self.object.Release() 46 | self.object = nil 47 | } 48 | return nil 49 | } 50 | 51 | func (self *ADSystemInfo) GetUserName() (string, error) { 52 | if self.object == nil { 53 | return "", NewWindowsError("IADsADSystemInfo::get_UserName", COMErrorPointer) 54 | } 55 | var retvalRaw *uint16 56 | if hr := self.object.Get_UserName(&retvalRaw); wrappers.FAILED(hr) { 57 | return "", NewWindowsError("IADsADSystemInfo::get_UserName", COMError(hr)) 58 | } 59 | return BstrToString(retvalRaw), nil 60 | } 61 | 62 | func (self *ADSystemInfo) GetComputerName() (string, error) { 63 | if self.object == nil { 64 | return "", NewWindowsError("IADsADSystemInfo::get_ComputerName", COMErrorPointer) 65 | } 66 | var retvalRaw *uint16 67 | if hr := self.object.Get_ComputerName(&retvalRaw); wrappers.FAILED(hr) { 68 | return "", NewWindowsError("IADsADSystemInfo::get_ComputerName", COMError(hr)) 69 | } 70 | return BstrToString(retvalRaw), nil 71 | } 72 | 73 | func (self *ADSystemInfo) GetDomainShortName() (string, error) { 74 | if self.object == nil { 75 | return "", NewWindowsError("IADsADSystemInfo::get_DomainShortName", COMErrorPointer) 76 | } 77 | var retvalRaw *uint16 78 | if hr := self.object.Get_DomainShortName(&retvalRaw); wrappers.FAILED(hr) { 79 | return "", NewWindowsError("IADsADSystemInfo::get_DomainShortName", COMError(hr)) 80 | } 81 | return BstrToString(retvalRaw), nil 82 | } 83 | 84 | func (self *ADSystemInfo) GetDomainDNSName() (string, error) { 85 | if self.object == nil { 86 | return "", NewWindowsError("IADsADSystemInfo::get_DomainDNSName", COMErrorPointer) 87 | } 88 | var retvalRaw *uint16 89 | if hr := self.object.Get_DomainDNSName(&retvalRaw); wrappers.FAILED(hr) { 90 | return "", NewWindowsError("IADsADSystemInfo::get_DomainDNSName", COMError(hr)) 91 | } 92 | return BstrToString(retvalRaw), nil 93 | } 94 | 95 | type ADWinNTSystemInfo struct { 96 | object *wrappers.IADsWinNTSystemInfo 97 | } 98 | 99 | func NewADWinNTSystemInfo() (*ADWinNTSystemInfo, error) { 100 | var object uintptr 101 | hr := wrappers.CoCreateInstance( 102 | &wrappers.CLSID_WinNTSystemInfo, 103 | nil, 104 | wrappers.CLSCTX_INPROC_SERVER, 105 | &wrappers.IID_IADsWinNTSystemInfo, 106 | &object) 107 | if wrappers.FAILED(hr) { 108 | return nil, NewWindowsError("CoCreateInstance", COMError(hr)) 109 | } 110 | return &ADWinNTSystemInfo{object: (*wrappers.IADsWinNTSystemInfo)(unsafe.Pointer(object))}, nil 111 | } 112 | 113 | func (self *ADWinNTSystemInfo) Close() error { 114 | if self.object != nil { 115 | self.object.Release() 116 | self.object = nil 117 | } 118 | return nil 119 | } 120 | 121 | func (self *ADWinNTSystemInfo) GetUserName() (string, error) { 122 | if self.object == nil { 123 | return "", NewWindowsError("IADsWinNTSystemInfo::get_UserName", COMErrorPointer) 124 | } 125 | var retvalRaw *uint16 126 | if hr := self.object.Get_UserName(&retvalRaw); wrappers.FAILED(hr) { 127 | return "", NewWindowsError("IADsWinNTSystemInfo::get_UserName", COMError(hr)) 128 | } 129 | return BstrToString(retvalRaw), nil 130 | } 131 | 132 | func (self *ADWinNTSystemInfo) GetComputerName() (string, error) { 133 | if self.object == nil { 134 | return "", NewWindowsError("IADsWinNTSystemInfo::get_ComputerName", COMErrorPointer) 135 | } 136 | var retvalRaw *uint16 137 | if hr := self.object.Get_ComputerName(&retvalRaw); wrappers.FAILED(hr) { 138 | return "", NewWindowsError("IADsWinNTSystemInfo::get_ComputerName", COMError(hr)) 139 | } 140 | return BstrToString(retvalRaw), nil 141 | } 142 | 143 | func (self *ADWinNTSystemInfo) GetDomainName() (string, error) { 144 | if self.object == nil { 145 | return "", NewWindowsError("IADsWinNTSystemInfo::get_DomainName", COMErrorPointer) 146 | } 147 | var retvalRaw *uint16 148 | if hr := self.object.Get_DomainName(&retvalRaw); wrappers.FAILED(hr) { 149 | return "", NewWindowsError("IADsWinNTSystemInfo::get_DomainName", COMError(hr)) 150 | } 151 | return BstrToString(retvalRaw), nil 152 | } 153 | -------------------------------------------------------------------------------- /adtranslate.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | type ADNameType int32 27 | 28 | const ( 29 | ADNameType1779 ADNameType = wrappers.ADS_NAME_TYPE_1779 30 | ADNameTypeCanonical ADNameType = wrappers.ADS_NAME_TYPE_CANONICAL 31 | ADNameTypeNT4 ADNameType = wrappers.ADS_NAME_TYPE_NT4 32 | ADNameTypeDisplay ADNameType = wrappers.ADS_NAME_TYPE_DISPLAY 33 | ADNameTypeDomainSimple ADNameType = wrappers.ADS_NAME_TYPE_DOMAIN_SIMPLE 34 | ADNameTypeEnterpriseSimple ADNameType = wrappers.ADS_NAME_TYPE_ENTERPRISE_SIMPLE 35 | ADNameTypeGUID ADNameType = wrappers.ADS_NAME_TYPE_GUID 36 | ADNameTypeUnknown ADNameType = wrappers.ADS_NAME_TYPE_UNKNOWN 37 | ADNameTypeUserPrincipalName ADNameType = wrappers.ADS_NAME_TYPE_USER_PRINCIPAL_NAME 38 | ADNameTypeCanonicalEx ADNameType = wrappers.ADS_NAME_TYPE_CANONICAL_EX 39 | ADNameTypeServicePrincipalName ADNameType = wrappers.ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME 40 | ADNameTypeSIDOrSIDHistoryName ADNameType = wrappers.ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME 41 | ) 42 | 43 | func TranslateADName(name string, fromType ADNameType, toType ADNameType) (string, error) { 44 | var object uintptr 45 | hr := wrappers.CoCreateInstance( 46 | &wrappers.CLSID_NameTranslate, 47 | nil, 48 | wrappers.CLSCTX_INPROC_SERVER, 49 | &wrappers.IID_IADsNameTranslate, 50 | &object) 51 | if wrappers.FAILED(hr) { 52 | return "", NewWindowsError("CoCreateInstance", COMError(hr)) 53 | } 54 | trans := (*wrappers.IADsNameTranslate)(unsafe.Pointer(object)) 55 | defer trans.Release() 56 | if hr := trans.Init(wrappers.ADS_NAME_INITTYPE_GC, nil); wrappers.FAILED(hr) { 57 | return "", NewWindowsError("IADsNameTranslate::Init", COMError(hr)) 58 | } 59 | nameRaw := wrappers.SysAllocString(syscall.StringToUTF16Ptr(name)) 60 | defer wrappers.SysFreeString(nameRaw) 61 | if hr := trans.Set(int32(fromType), nameRaw); wrappers.FAILED(hr) { 62 | return "", NewWindowsError("IADsNameTranslate::Set", COMError(hr)) 63 | } 64 | var outRaw *uint16 65 | if hr := trans.Get(int32(toType), &outRaw); wrappers.FAILED(hr) { 66 | return "", NewWindowsError("IADsNameTranslate::Get", COMError(hr)) 67 | } 68 | return BstrToString(outRaw), nil 69 | } 70 | -------------------------------------------------------------------------------- /bstr.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | func BstrToString(bstr *uint16) string { 27 | if bstr == nil { 28 | return "" 29 | } 30 | len := wrappers.SysStringLen(bstr) 31 | buf := make([]uint16, len) 32 | wrappers.RtlMoveMemory( 33 | (*byte)(unsafe.Pointer(&buf[0])), 34 | (*byte)(unsafe.Pointer(bstr)), 35 | uintptr(2*len)) 36 | return syscall.UTF16ToString(buf) 37 | } 38 | 39 | func LpstrToString(lpstr *uint16) string { 40 | if lpstr == nil { 41 | return "" 42 | } 43 | len := wrappers.Lstrlen(lpstr) 44 | if len == 0 { 45 | return "" 46 | } 47 | buf := make([]uint16, len) 48 | wrappers.RtlMoveMemory( 49 | (*byte)(unsafe.Pointer(&buf[0])), 50 | (*byte)(unsafe.Pointer(lpstr)), 51 | uintptr(2*len)) 52 | return syscall.UTF16ToString(buf) 53 | } 54 | 55 | func MakeDoubleNullTerminatedLpstr(items ...string) *uint16 { 56 | chars := []uint16{} 57 | for _, s := range items { 58 | chars = append(chars, syscall.StringToUTF16(s)...) 59 | } 60 | chars = append(chars, 0) 61 | return &chars[0] 62 | } 63 | -------------------------------------------------------------------------------- /cmdline.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | func ParseCommandLine(commandLine string) ([]string, error) { 27 | var numArgs int32 28 | rawArgs, err := wrappers.CommandLineToArgvW( 29 | syscall.StringToUTF16Ptr(commandLine), 30 | &numArgs) 31 | if err != nil { 32 | return nil, NewWindowsError("CommandLineToArgvW", err) 33 | } 34 | args := make([]string, numArgs) 35 | for i, _ := range(args) { 36 | args[i] = LpstrToString(*rawArgs) 37 | rawArgs = (**uint16)(unsafe.Pointer(uintptr(unsafe.Pointer(rawArgs)) + unsafe.Sizeof(*rawArgs))) 38 | } 39 | return args, nil 40 | } 41 | -------------------------------------------------------------------------------- /comerror.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "fmt" 23 | "strings" 24 | "syscall" 25 | "unsafe" 26 | ) 27 | 28 | type Facility uint16 29 | 30 | const ( 31 | FacilityNull Facility = wrappers.FACILITY_NULL 32 | FacilityRPC Facility = wrappers.FACILITY_RPC 33 | FacilityDispatch Facility = wrappers.FACILITY_DISPATCH 34 | FacilityStorage Facility = wrappers.FACILITY_STORAGE 35 | FacilityITF Facility = wrappers.FACILITY_ITF 36 | FacilityWin32 Facility = wrappers.FACILITY_WIN32 37 | FacilityWindows Facility = wrappers.FACILITY_WINDOWS 38 | ) 39 | 40 | type COMError uint32 41 | 42 | const ( 43 | COMErrorUnexpected COMError = wrappers.E_UNEXPECTED 44 | COMErrorNotImplemented COMError = wrappers.E_NOTIMPL 45 | COMErrorOutOfMemory COMError = wrappers.E_OUTOFMEMORY 46 | COMErrorInvalidArgument COMError = wrappers.E_INVALIDARG 47 | COMErrorNoInterface COMError = wrappers.E_NOINTERFACE 48 | COMErrorPointer COMError = wrappers.E_POINTER 49 | COMErrorHandle COMError = wrappers.E_HANDLE 50 | COMErrorAbort COMError = wrappers.E_ABORT 51 | COMErrorFail COMError = wrappers.E_FAIL 52 | COMErrorAccessDenied COMError = wrappers.E_ACCESSDENIED 53 | COMErrorPending COMError = wrappers.E_PENDING 54 | ) 55 | 56 | var ( 57 | COMErrorNoneMapped = COMError(wrappers.HRESULT_FROM_WIN32(wrappers.ERROR_NONE_MAPPED)) 58 | COMErrorCantAccessDomainInfo = COMError(wrappers.HRESULT_FROM_WIN32(wrappers.ERROR_CANT_ACCESS_DOMAIN_INFO)) 59 | COMErrorNoSuchDomain = COMError(wrappers.HRESULT_FROM_WIN32(wrappers.ERROR_NO_SUCH_DOMAIN)) 60 | ) 61 | 62 | func (self COMError) Error() string { 63 | var message *uint16 64 | _, err := wrappers.FormatMessage( 65 | wrappers.FORMAT_MESSAGE_ALLOCATE_BUFFER | wrappers.FORMAT_MESSAGE_IGNORE_INSERTS | wrappers.FORMAT_MESSAGE_FROM_SYSTEM, 66 | 0, 67 | uint32(self), 68 | 0, 69 | (*uint16)(unsafe.Pointer(&message)), 70 | 65536, 71 | nil) 72 | if err != nil { 73 | return fmt.Sprintf("com error 0x%08X", uint32(self)) 74 | } 75 | defer wrappers.LocalFree(syscall.Handle(unsafe.Pointer(message))) 76 | return strings.TrimRight(LpstrToString(message), "\r\n") 77 | } 78 | 79 | func (self COMError) GetFacility() Facility { 80 | return Facility(wrappers.HRESULT_FACILITY(uint32(self))) 81 | } 82 | 83 | func (self COMError) GetCode() uint16 { 84 | return wrappers.HRESULT_CODE(uint32(self)) 85 | } 86 | -------------------------------------------------------------------------------- /cominit.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | ) 22 | 23 | type COMInitFlags uint32 24 | 25 | const ( 26 | COMInitApartmentThreaded COMInitFlags = wrappers.COINIT_APARTMENTTHREADED 27 | COMInitMultithreaded COMInitFlags = wrappers.COINIT_MULTITHREADED 28 | COMInitDisableOLE1DDE COMInitFlags = wrappers.COINIT_DISABLE_OLE1DDE 29 | COMInitSpeedOverMemory COMInitFlags = wrappers.COINIT_SPEED_OVER_MEMORY 30 | ) 31 | 32 | func InitializeCOM(flags COMInitFlags) error { 33 | if hr := wrappers.CoInitializeEx(nil, uint32(flags)); wrappers.FAILED(hr) { 34 | return NewWindowsError("CoInitializeEx", COMError(hr)) 35 | } 36 | return nil 37 | } 38 | 39 | func UninitializeCOM() { 40 | wrappers.CoUninitialize() 41 | } 42 | -------------------------------------------------------------------------------- /console.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2019 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | ) 22 | 23 | func EnableVTSequences() error { 24 | err := addStdConsoleModeFlag( 25 | wrappers.STD_OUTPUT_HANDLE, 26 | wrappers.ENABLE_VIRTUAL_TERMINAL_PROCESSING) 27 | if err != nil { 28 | return err 29 | } 30 | return addStdConsoleModeFlag( 31 | wrappers.STD_ERROR_HANDLE, 32 | wrappers.ENABLE_VIRTUAL_TERMINAL_PROCESSING) 33 | } 34 | 35 | func addStdConsoleModeFlag(stdHandle uint32, modeFlag uint32) error { 36 | hConsole, err := wrappers.GetStdHandle(stdHandle) 37 | if err != nil { 38 | return NewWindowsError("GetStdHandle", err) 39 | } 40 | var mode uint32 41 | if err := wrappers.GetConsoleMode(hConsole, &mode); err != nil { 42 | return NewWindowsError("GetConsoleMode", err) 43 | } 44 | mode |= modeFlag 45 | if err := wrappers.SetConsoleMode(hConsole, mode); err != nil { 46 | return NewWindowsError("SetConsoleMode", err) 47 | } 48 | return nil 49 | } 50 | -------------------------------------------------------------------------------- /critsect.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | ) 22 | 23 | type CriticalSection struct { 24 | nativeCriticalSection wrappers.CRITICAL_SECTION 25 | } 26 | 27 | func NewCriticalSection() *CriticalSection { 28 | cs := CriticalSection{} 29 | wrappers.InitializeCriticalSection(&cs.nativeCriticalSection) 30 | return &cs 31 | } 32 | 33 | func (self *CriticalSection) Close() error { 34 | wrappers.DeleteCriticalSection(&self.nativeCriticalSection) 35 | return nil 36 | } 37 | 38 | func (self *CriticalSection) Lock() { 39 | wrappers.EnterCriticalSection(&self.nativeCriticalSection) 40 | } 41 | 42 | func (self *CriticalSection) Unlock() { 43 | wrappers.LeaveCriticalSection(&self.nativeCriticalSection) 44 | } 45 | 46 | func (self *CriticalSection) TryLock() bool { 47 | return wrappers.TryEnterCriticalSection(&self.nativeCriticalSection) 48 | } 49 | -------------------------------------------------------------------------------- /diskperf.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | type DiskPerformanceInfo struct { 27 | BytesRead int64 28 | BytesWritten int64 29 | ReadTime int64 30 | WriteTime int64 31 | IdleTime int64 32 | ReadCount uint 33 | WriteCount uint 34 | QueueDepth uint 35 | SplitCount uint 36 | QueryTime int64 37 | StorageDeviceNumber uint 38 | StorageManagerName string 39 | } 40 | 41 | func GetDiskPerformanceInfo(rootPathName string) (*DiskPerformanceInfo, error) { 42 | hFile, err := wrappers.CreateFile( 43 | syscall.StringToUTF16Ptr(rootPathName), 44 | 0, 45 | wrappers.FILE_SHARE_READ | wrappers.FILE_SHARE_WRITE, 46 | nil, 47 | wrappers.OPEN_EXISTING, 48 | 0, 49 | 0) 50 | if err != nil { 51 | return nil, NewWindowsError("CreateFile", err) 52 | } 53 | defer wrappers.CloseHandle(hFile) 54 | var diskPerformance wrappers.DISK_PERFORMANCE 55 | var diskPerformanceSize uint32 56 | err = wrappers.DeviceIoControl( 57 | hFile, 58 | wrappers.IOCTL_DISK_PERFORMANCE, 59 | nil, 60 | 0, 61 | (*byte)(unsafe.Pointer(&diskPerformance)), 62 | uint32(unsafe.Sizeof(diskPerformance)), 63 | &diskPerformanceSize, 64 | nil) 65 | if err != nil { 66 | return nil, NewWindowsError("DeviceIoControl", err) 67 | } 68 | return &DiskPerformanceInfo{ 69 | BytesRead: diskPerformance.BytesRead, 70 | BytesWritten: diskPerformance.BytesWritten, 71 | ReadTime: diskPerformance.ReadTime, 72 | WriteTime: diskPerformance.WriteTime, 73 | IdleTime: diskPerformance.IdleTime, 74 | ReadCount: uint(diskPerformance.ReadCount), 75 | WriteCount: uint(diskPerformance.WriteCount), 76 | QueueDepth: uint(diskPerformance.QueueDepth), 77 | SplitCount: uint(diskPerformance.SplitCount), 78 | QueryTime: diskPerformance.QueryTime, 79 | StorageDeviceNumber: uint(diskPerformance.StorageDeviceNumber), 80 | StorageManagerName: syscall.UTF16ToString(diskPerformance.StorageManagerName[:]), 81 | }, nil 82 | } 83 | -------------------------------------------------------------------------------- /diskspace.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | func GetAvailableDiskSpace(root string) (uint64, error) { 26 | availableSpace := uint64(0) 27 | if err := wrappers.GetDiskFreeSpaceEx(syscall.StringToUTF16Ptr(root), &availableSpace, nil, nil); err != nil { 28 | return 0, NewWindowsError("GetDiskFreeSpaceEx", err) 29 | } 30 | return availableSpace, nil 31 | } 32 | 33 | func GetTotalDiskSpace(root string) (uint64, error) { 34 | totalSpace := uint64(0) 35 | if err := wrappers.GetDiskFreeSpaceEx(syscall.StringToUTF16Ptr(root), nil, &totalSpace, nil); err != nil { 36 | return 0, NewWindowsError("GetDiskFreeSpaceEx", err) 37 | } 38 | return totalSpace, nil 39 | } 40 | 41 | func GetFreeDiskSpace(root string) (uint64, error) { 42 | freeSpace := uint64(0) 43 | if err := wrappers.GetDiskFreeSpaceEx(syscall.StringToUTF16Ptr(root), nil, nil, &freeSpace); err != nil { 44 | return 0, NewWindowsError("GetDiskFreeSpaceEx", err) 45 | } 46 | return freeSpace, nil 47 | } 48 | 49 | func GetSectorsAndClusters(root string) (uint32, uint32, uint32, uint32, error) { 50 | var sectorsPerCluster uint32 51 | var bytesPerSector uint32 52 | var numberOfFreeClusters uint32 53 | var totalNumberOfClusters uint32 54 | err := wrappers.GetDiskFreeSpace( 55 | syscall.StringToUTF16Ptr(root), 56 | §orsPerCluster, 57 | &bytesPerSector, 58 | &numberOfFreeClusters, 59 | &totalNumberOfClusters) 60 | if err != nil { 61 | return 0, 0, 0, 0, err 62 | } 63 | return sectorsPerCluster, bytesPerSector, numberOfFreeClusters, totalNumberOfClusters, nil 64 | } 65 | -------------------------------------------------------------------------------- /environment.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "strings" 23 | "syscall" 24 | "unsafe" 25 | ) 26 | 27 | func ExpandEnvironment(text string) (string, error) { 28 | size, err := wrappers.ExpandEnvironmentStrings(syscall.StringToUTF16Ptr(text), nil, 0) 29 | if err != nil { 30 | return "", NewWindowsError("ExpandEnvironmentStrings", err) 31 | } 32 | buf := make([]uint16, size) 33 | if _, err := wrappers.ExpandEnvironmentStrings(syscall.StringToUTF16Ptr(text), &buf[0], size); err != nil { 34 | return "", NewWindowsError("ExpandEnvironmentStrings", err) 35 | } 36 | return syscall.UTF16ToString(buf), nil 37 | } 38 | 39 | func GetAllEnvironment() (map[string]string, error) { 40 | block, err := wrappers.GetEnvironmentStrings() 41 | if err != nil { 42 | return nil, NewWindowsError("GetEnvironmentStrings", err) 43 | } 44 | defer wrappers.FreeEnvironmentStrings(block) 45 | blockMap := make(map[string]string) 46 | item := block 47 | for { 48 | entry := LpstrToString(item) 49 | if len(entry) == 0 { 50 | return blockMap, nil 51 | } 52 | if entry[0] != '=' { 53 | index := strings.Index(entry, "=") 54 | name := entry[0:index] 55 | value := entry[index+1:] 56 | blockMap[name] = value 57 | } 58 | offset := uintptr(2*len(entry) + 2) 59 | item = (*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer(item)) + offset)) 60 | } 61 | } 62 | 63 | func GetEnvironment(name string) (string, error) { 64 | len, err := wrappers.GetEnvironmentVariable(syscall.StringToUTF16Ptr(name), nil, 0) 65 | if err != nil { 66 | return "", NewWindowsError("GetEnvironmentVariable", err) 67 | } 68 | buf := make([]uint16, len) 69 | _, err = wrappers.GetEnvironmentVariable(syscall.StringToUTF16Ptr(name), &buf[0], len) 70 | if err != nil { 71 | return "", NewWindowsError("GetEnvironmentVariable", err) 72 | } 73 | return syscall.UTF16ToString(buf), nil 74 | } 75 | 76 | func SetEnvironment(name string, value string) error { 77 | err := wrappers.SetEnvironmentVariable( 78 | syscall.StringToUTF16Ptr(name), 79 | syscall.StringToUTF16Ptr(value)) 80 | if err != nil { 81 | return NewWindowsError("SetEnvironmentVariable", err) 82 | } 83 | return nil 84 | } 85 | -------------------------------------------------------------------------------- /error.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "fmt" 23 | ) 24 | 25 | const ( 26 | ErrorFileNotFound = wrappers.ERROR_FILE_NOT_FOUND 27 | ErrorAccessDenied = wrappers.ERROR_ACCESS_DENIED 28 | ErrorGeneralFailure = wrappers.ERROR_GEN_FAILURE 29 | ErrorSharingViolation = wrappers.ERROR_SHARING_VIOLATION 30 | ErrorInvalidParameter = wrappers.ERROR_INVALID_PARAMETER 31 | ErrorBrokenPipe = wrappers.ERROR_BROKEN_PIPE 32 | ErrorServiceDoesNotExist = wrappers.ERROR_SERVICE_DOES_NOT_EXIST 33 | ) 34 | 35 | type WindowsError struct { 36 | functionName string 37 | innerError error 38 | } 39 | 40 | func NewWindowsError(functionName string, innerError error) *WindowsError { 41 | return &WindowsError{functionName, innerError} 42 | } 43 | 44 | func (self *WindowsError) FunctionName() string { 45 | return self.functionName 46 | } 47 | 48 | func (self *WindowsError) InnerError() error { 49 | return self.innerError 50 | } 51 | 52 | func (self *WindowsError) Error() string { 53 | return fmt.Sprintf("gowin32: %s failed: %v", self.functionName, self.innerError) 54 | } 55 | -------------------------------------------------------------------------------- /eventlog.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | type EventType uint32 26 | 27 | const ( 28 | EventTypeSuccess EventType = wrappers.EVENTLOG_SUCCESS 29 | EventTypeError EventType = wrappers.EVENTLOG_ERROR_TYPE 30 | EventTypeWarning EventType = wrappers.EVENTLOG_WARNING_TYPE 31 | EventTypeInformation EventType = wrappers.EVENTLOG_INFORMATION_TYPE 32 | EventTypeAuditSuccess EventType = wrappers.EVENTLOG_AUDIT_SUCCESS 33 | EventTypeAuditFailure EventType = wrappers.EVENTLOG_AUDIT_FAILURE 34 | ) 35 | 36 | type EventSourceRegistration struct { 37 | SourceName string 38 | CategoryCount uint 39 | CategoryMessageFile string 40 | EventMessageFile string 41 | ParameterMessageFile string 42 | TypesSupported EventType 43 | } 44 | 45 | func (self *EventSourceRegistration) Install() error { 46 | key, err := CreateRegKey( 47 | RegRootHKLM, 48 | "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" + self.SourceName) 49 | if err != nil { 50 | return err 51 | } 52 | defer key.Close() 53 | if self.CategoryMessageFile != "" { 54 | if err := key.SetValueDWORD("CategoryCount", uint32(self.CategoryCount)); err != nil { 55 | return err 56 | } 57 | if err := key.SetValueString("CategoryMessageFile", self.CategoryMessageFile); err != nil { 58 | return err 59 | } 60 | } 61 | if self.EventMessageFile != "" { 62 | if err := key.SetValueString("EventMessageFile", self.EventMessageFile); err != nil { 63 | return err 64 | } 65 | } 66 | if self.ParameterMessageFile != "" { 67 | if err := key.SetValueString("ParameterMessageFile", self.ParameterMessageFile); err != nil { 68 | return err 69 | } 70 | } 71 | return key.SetValueDWORD("TypesSupported", uint32(self.TypesSupported)) 72 | } 73 | 74 | type EventLogEvent struct { 75 | Type EventType 76 | Category uint 77 | EventID uint 78 | Strings []string 79 | Data []byte 80 | } 81 | 82 | type EventSource struct { 83 | handle syscall.Handle 84 | } 85 | 86 | func NewEventSource(sourceName string) (*EventSource, error) { 87 | hEventLog, err := wrappers.RegisterEventSource(nil, syscall.StringToUTF16Ptr(sourceName)) 88 | if err != nil { 89 | return nil, NewWindowsError("RegisterEventSource", err) 90 | } 91 | return &EventSource{handle: hEventLog}, nil 92 | } 93 | 94 | func (self *EventSource) Close() error { 95 | if self.handle != 0 { 96 | if err := wrappers.DeregisterEventSource(self.handle); err != nil { 97 | return NewWindowsError("DeregisterEventSource", err) 98 | } 99 | self.handle = 0 100 | } 101 | return nil 102 | } 103 | 104 | func (self *EventSource) Report(event *EventLogEvent) error { 105 | var stringPtrsPtr **uint16 106 | var stringCount uint16 107 | if event.Strings != nil && len(event.Strings) > 0 { 108 | stringPtrsArray := make([]*uint16, len(event.Strings)) 109 | for i, s := range event.Strings { 110 | stringPtrsArray[i] = syscall.StringToUTF16Ptr(s) 111 | } 112 | stringPtrsPtr = &stringPtrsArray[0] 113 | stringCount = uint16(len(event.Strings)) 114 | } 115 | var data *byte 116 | var dataSize uint32 117 | if event.Data != nil && len(event.Data) > 0 { 118 | data = &event.Data[0] 119 | dataSize = uint32(len(event.Data)) 120 | } 121 | err := wrappers.ReportEvent( 122 | self.handle, 123 | uint16(event.Type), 124 | uint16(event.Category), 125 | uint32(event.EventID), 126 | nil, 127 | stringCount, 128 | dataSize, 129 | stringPtrsPtr, 130 | data) 131 | if err != nil { 132 | return NewWindowsError("ReportEvent", err) 133 | } 134 | return nil 135 | } 136 | 137 | func (self *EventSource) Error(eventID uint, strings ...string) error { 138 | return self.Report(&EventLogEvent{ 139 | Type: EventTypeError, 140 | EventID: eventID, 141 | Strings: strings, 142 | }) 143 | } 144 | 145 | func (self *EventSource) Warning(eventID uint, strings ...string) error { 146 | return self.Report(&EventLogEvent{ 147 | Type: EventTypeWarning, 148 | EventID: eventID, 149 | Strings: strings, 150 | }) 151 | } 152 | 153 | func (self *EventSource) Info(eventID uint, strings ...string) error { 154 | return self.Report(&EventLogEvent{ 155 | Type: EventTypeInformation, 156 | EventID: eventID, 157 | Strings: strings, 158 | }) 159 | } 160 | -------------------------------------------------------------------------------- /file.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "strings" 21 | 22 | "github.com/winlabs/gowin32/wrappers" 23 | 24 | "os" 25 | "syscall" 26 | ) 27 | 28 | type FileShareMode uint32 29 | 30 | const ( 31 | FileShareExclusive FileShareMode = 0 32 | FileShareRead FileShareMode = wrappers.FILE_SHARE_READ 33 | FileShareWrite FileShareMode = wrappers.FILE_SHARE_WRITE 34 | FileShareDelete FileShareMode = wrappers.FILE_SHARE_DELETE 35 | ) 36 | 37 | type FileCreationDisposition uint32 38 | 39 | const ( 40 | FileCreateNew FileCreationDisposition = wrappers.CREATE_NEW 41 | FileCreateAlways FileCreationDisposition = wrappers.CREATE_ALWAYS 42 | FileOpenExisting FileCreationDisposition = wrappers.OPEN_EXISTING 43 | FileOpenAlways FileCreationDisposition = wrappers.OPEN_ALWAYS 44 | FileTruncateExisting FileCreationDisposition = wrappers.TRUNCATE_EXISTING 45 | ) 46 | 47 | type FileAttributes uint32 48 | 49 | const ( 50 | FileAttributeReadOnly FileAttributes = wrappers.FILE_ATTRIBUTE_READONLY 51 | FileAttributeHidden FileAttributes = wrappers.FILE_ATTRIBUTE_HIDDEN 52 | FileAttributeSystem FileAttributes = wrappers.FILE_ATTRIBUTE_SYSTEM 53 | FileAttributeDirectory FileAttributes = wrappers.FILE_ATTRIBUTE_DIRECTORY 54 | FileAttributeArchive FileAttributes = wrappers.FILE_ATTRIBUTE_ARCHIVE 55 | FileAttributeDevice FileAttributes = wrappers.FILE_ATTRIBUTE_DEVICE 56 | FileAttributeNormal FileAttributes = wrappers.FILE_ATTRIBUTE_NORMAL 57 | FileAttributeTemporary FileAttributes = wrappers.FILE_ATTRIBUTE_TEMPORARY 58 | FileAttributeSparseFile FileAttributes = wrappers.FILE_ATTRIBUTE_SPARSE_FILE 59 | FileAttributeReparsePoint FileAttributes = wrappers.FILE_ATTRIBUTE_REPARSE_POINT 60 | FileAttributeCompressed FileAttributes = wrappers.FILE_ATTRIBUTE_COMPRESSED 61 | FileAttributeOffline FileAttributes = wrappers.FILE_ATTRIBUTE_OFFLINE 62 | FileAttributeNotContentIndexed FileAttributes = wrappers.FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 63 | FileAttributeEncrypted FileAttributes = wrappers.FILE_ATTRIBUTE_ENCRYPTED 64 | FileAttributeVirtual FileAttributes = wrappers.FILE_ATTRIBUTE_VIRTUAL 65 | ) 66 | 67 | type FileFlags uint32 68 | 69 | const ( 70 | FileFlagWriteThrough FileFlags = wrappers.FILE_FLAG_WRITE_THROUGH 71 | FileFlagOverlapped FileFlags = wrappers.FILE_FLAG_OVERLAPPED 72 | FileFlagNoBuffering FileFlags = wrappers.FILE_FLAG_NO_BUFFERING 73 | FileFlagRandomAccess FileFlags = wrappers.FILE_FLAG_RANDOM_ACCESS 74 | FileFlagSequentialScan FileFlags = wrappers.FILE_FLAG_SEQUENTIAL_SCAN 75 | FileFlagDeleteOnClose FileFlags = wrappers.FILE_FLAG_DELETE_ON_CLOSE 76 | FileFlagBackupSemantics FileFlags = wrappers.FILE_FLAG_BACKUP_SEMANTICS 77 | FileFlagPOSIXSemantics FileFlags = wrappers.FILE_FLAG_POSIX_SEMANTICS 78 | FileFlagOpenReparsePoint FileFlags = wrappers.FILE_FLAG_OPEN_REPARSE_POINT 79 | FileFlagOpenNoRecall FileFlags = wrappers.FILE_FLAG_OPEN_NO_RECALL 80 | FileFlagFirstPipeInstance FileFlags = wrappers.FILE_FLAG_FIRST_PIPE_INSTANCE 81 | ) 82 | 83 | func OpenWindowsFile(fileName string, readWrite bool, shareMode FileShareMode, creationDisposition FileCreationDisposition, attributes FileAttributes, flags FileFlags) (*os.File, error) { 84 | var accessMask uint32 = wrappers.GENERIC_READ 85 | if readWrite { 86 | accessMask |= wrappers.GENERIC_WRITE 87 | } 88 | file, err := wrappers.CreateFile( 89 | syscall.StringToUTF16Ptr(fileName), 90 | accessMask, 91 | uint32(shareMode), 92 | nil, 93 | uint32(creationDisposition), 94 | uint32(attributes)|uint32(flags), 95 | 0) 96 | if err != nil { 97 | return nil, NewWindowsError("CreateFile", err) 98 | } 99 | return os.NewFile(uintptr(file), fileName), nil 100 | } 101 | 102 | func ReadFileContents(fileName string) (string, error) { 103 | file, err := wrappers.CreateFile( 104 | syscall.StringToUTF16Ptr(fileName), 105 | wrappers.GENERIC_READ, 106 | wrappers.FILE_SHARE_READ|wrappers.FILE_SHARE_WRITE|wrappers.FILE_SHARE_DELETE, 107 | nil, 108 | wrappers.OPEN_EXISTING, 109 | 0, 110 | 0) 111 | if err != nil { 112 | return "", NewWindowsError("CreateFile", err) 113 | } 114 | defer wrappers.CloseHandle(file) 115 | size, err := wrappers.GetFileSize(file, nil) 116 | if err != nil { 117 | return "", NewWindowsError("GetFileSize", err) 118 | } 119 | if size == 0 { 120 | return "", nil 121 | } 122 | buf := make([]byte, size) 123 | var bytesRead uint32 124 | if err := wrappers.ReadFile(file, &buf[0], size, &bytesRead, nil); err != nil { 125 | return "", NewWindowsError("ReadFile", err) 126 | } 127 | return string(buf[0:bytesRead]), nil 128 | } 129 | 130 | func TouchFile(f *os.File) error { 131 | var now wrappers.FILETIME 132 | wrappers.GetSystemTimeAsFileTime(&now) 133 | if err := wrappers.SetFileTime(syscall.Handle(f.Fd()), nil, &now, &now); err != nil { 134 | return NewWindowsError("SetFileTime", err) 135 | } 136 | return nil 137 | } 138 | 139 | func GetFinalPathName(fileName string, openFlags uint32, finalPathFlags uint32) (result string, err error) { 140 | if isVistaOrGreater, e := IsWindowsVistaOrGreater(); e != nil { 141 | return "", NewWindowsError("IsWindowsVistaOrGreater", e) 142 | } else if !isVistaOrGreater { 143 | // Todo: resolve symlink target on Windows XP, 2003 144 | return fileName, nil 145 | } 146 | 147 | file, e := wrappers.CreateFile( 148 | syscall.StringToUTF16Ptr(fileName), 149 | wrappers.GENERIC_READ, 150 | wrappers.FILE_SHARE_READ, 151 | nil, 152 | wrappers.OPEN_EXISTING, 153 | openFlags, 154 | 0) 155 | if e != nil { 156 | return "", NewWindowsError("CreateFile", e) 157 | } 158 | defer wrappers.CloseHandle(file) 159 | 160 | buf := make([]uint16, wrappers.MAX_PATH) 161 | if _, err = wrappers.GetFinalPathNameByHandle(file, &buf[0], wrappers.MAX_PATH, finalPathFlags); err != nil { 162 | return "", NewWindowsError("GetFinalPathNameByHandle", err) 163 | } 164 | result = syscall.UTF16ToString(buf) 165 | return result, err 166 | } 167 | 168 | // GetFinalPathNameAsDOSName returns symlik target in "DOS" format (c:\dir\name) or source fileName if fileName is normal, 169 | // not symlinked file 170 | func GetFinalPathNameAsDOSName(fileName string) (string, error) { 171 | result, err := GetFinalPathName(fileName, wrappers.FILE_ATTRIBUTE_NORMAL|wrappers.FILE_FLAG_BACKUP_SEMANTICS, wrappers.VOLUME_NAME_DOS) 172 | if err != nil { 173 | return "", err 174 | } 175 | // GetFinalPathName can return path in the \?\ syntax 176 | if strings.HasPrefix(result, "\\\\?\\") { 177 | result = result[4:] 178 | } 179 | return result, nil 180 | } 181 | -------------------------------------------------------------------------------- /fileop.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | func Copy(oldFileName string, newFileName string, overwrite bool) error { 26 | err := wrappers.CopyFile( 27 | syscall.StringToUTF16Ptr(oldFileName), 28 | syscall.StringToUTF16Ptr(newFileName), 29 | !overwrite) 30 | if err != nil { 31 | return NewWindowsError("CopyFile", err) 32 | } 33 | return nil 34 | } 35 | 36 | func Delete(fileName string) error { 37 | if err := wrappers.DeleteFile(syscall.StringToUTF16Ptr(fileName)); err != nil { 38 | return NewWindowsError("DeleteFile", err) 39 | } 40 | return nil 41 | } 42 | 43 | func FileExists(fileName string) (bool, error) { 44 | var wfd wrappers.WIN32_FIND_DATA 45 | handle, err := wrappers.FindFirstFile(syscall.StringToUTF16Ptr(fileName), &wfd) 46 | if err == wrappers.ERROR_FILE_NOT_FOUND { 47 | return false, nil 48 | } else if err != nil { 49 | return false, NewWindowsError("FindFirstFile", err) 50 | } 51 | wrappers.FindClose(handle) 52 | return true, nil 53 | } 54 | 55 | func GetAttributes(fileName string) (FileAttributes, error) { 56 | attributes, err := wrappers.GetFileAttributes(syscall.StringToUTF16Ptr(fileName)) 57 | if err != nil { 58 | return 0, NewWindowsError("GetFileAttributes", err) 59 | } 60 | return FileAttributes(attributes), err 61 | } 62 | 63 | func GetCompressedSize(fileName string) (uint64, error) { 64 | var fileSizeHigh uint32 65 | fileSizeLow, err := wrappers.GetCompressedFileSize(syscall.StringToUTF16Ptr(fileName), &fileSizeHigh) 66 | if err != nil { 67 | return 0, NewWindowsError("GetCompressedFileSize", err) 68 | } 69 | return (uint64(fileSizeHigh) << 32) | uint64(fileSizeLow), nil 70 | } 71 | 72 | func GetVolumePath(fileName string) (string, error) { 73 | buf := make([]uint16, wrappers.MAX_PATH) 74 | if err := wrappers.GetVolumePathName(syscall.StringToUTF16Ptr(fileName), &buf[0], wrappers.MAX_PATH); err != nil { 75 | return "", NewWindowsError("GetVolumePathName", err) 76 | } 77 | return syscall.UTF16ToString(buf), nil 78 | } 79 | 80 | func Move(oldFileName string, newFileName string, overwrite bool) error { 81 | if overwrite { 82 | err := wrappers.MoveFileEx( 83 | syscall.StringToUTF16Ptr(oldFileName), 84 | syscall.StringToUTF16Ptr(newFileName), 85 | wrappers.MOVEFILE_REPLACE_EXISTING) 86 | if err != nil { 87 | return NewWindowsError("MoveFileEx", err) 88 | } 89 | } else { 90 | err := wrappers.MoveFile( 91 | syscall.StringToUTF16Ptr(oldFileName), 92 | syscall.StringToUTF16Ptr(newFileName)) 93 | if err != nil { 94 | return NewWindowsError("MoveFile", err) 95 | } 96 | } 97 | return nil 98 | } 99 | 100 | func SetAttributes(fileName string, attributes FileAttributes) error { 101 | err := wrappers.SetFileAttributes(syscall.StringToUTF16Ptr(fileName), uint32(attributes)) 102 | if err != nil { 103 | return NewWindowsError("SetFileAttributes", err) 104 | } 105 | return nil 106 | } 107 | -------------------------------------------------------------------------------- /fqdn.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | func GetFQDN() (string, error) { 26 | var fqdnLength uint32 27 | err := wrappers.GetComputerNameEx(wrappers.ComputerNameDnsFullyQualified, nil, &fqdnLength) 28 | if err != wrappers.ERROR_MORE_DATA { 29 | return "", NewWindowsError("GetComputerNameEx", err) 30 | } 31 | fqdnBuffer := make([]uint16, fqdnLength) 32 | err = wrappers.GetComputerNameEx(wrappers.ComputerNameDnsFullyQualified, &fqdnBuffer[0], &fqdnLength) 33 | if err != nil { 34 | return "", NewWindowsError("GetComputerNameEx", err) 35 | } 36 | return syscall.UTF16ToString(fqdnBuffer), nil 37 | } 38 | 39 | func GetNetBIOSName() (string, error) { 40 | nbLength := uint32(wrappers.MAX_COMPUTERNAME_LENGTH) 41 | nbBuffer := make([]uint16, nbLength + 1) 42 | if err := wrappers.GetComputerName(&nbBuffer[0], &nbLength); err != nil { 43 | return "", NewWindowsError("GetComputerName", err) 44 | } 45 | return syscall.UTF16ToString(nbBuffer), nil 46 | } 47 | -------------------------------------------------------------------------------- /geometry.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | ) 22 | 23 | type Rectangle struct { 24 | Left int 25 | Top int 26 | Right int 27 | Bottom int 28 | } 29 | 30 | func rectToRectangle(rect wrappers.RECT) Rectangle { 31 | return Rectangle{Left: int(rect.Left), Top: int(rect.Top), Right: int(rect.Right), Bottom: int(rect.Bottom)} 32 | } 33 | -------------------------------------------------------------------------------- /installer_test.go: -------------------------------------------------------------------------------- 1 | package gowin32 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestGetInstalledProducts(t *testing.T) { 8 | products, err := GetInstalledProducts() 9 | if err != nil { 10 | t.Errorf("didn't expect an error, but got %v", err) 11 | } 12 | if len(products) == 0 { 13 | t.Errorf("expected to get some products, but didn't get any!") 14 | } 15 | 16 | for _, pc := range products { 17 | name, err := GetInstalledProductProperty(pc, InstallPropertyProductName) 18 | if err != nil { 19 | t.Errorf("didn't expect an error getting name, but got %v", err) 20 | } 21 | if name == "" { 22 | continue 23 | } 24 | version, err := GetInstalledProductProperty(pc, InstallPropertyVersionString) 25 | if err != nil { 26 | t.Errorf("didn't expect an error getting version for %s, but got %v", name, err) 27 | } 28 | if version == "" { 29 | t.Errorf("expected to get name and version, but got %s %s", name, version) 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /iphlp.go: -------------------------------------------------------------------------------- 1 | package gowin32 2 | 3 | import ( 4 | "encoding/binary" 5 | "fmt" 6 | "net" 7 | "unsafe" 8 | 9 | "github.com/winlabs/gowin32/wrappers" 10 | ) 11 | 12 | // SendARP sends an ARP request. srcIP can be nil 13 | func SendARP(destIP, srcIP net.IP) (net.HardwareAddr, error) { 14 | var s uint32 15 | if len(srcIP) > 0 { 16 | srcIPv4 := srcIP.To4() 17 | if srcIPv4 == nil { 18 | return nil, fmt.Errorf("%s is not valid IPv4 address", srcIP) 19 | } 20 | s = binary.LittleEndian.Uint32(srcIPv4) 21 | } 22 | destIPv4 := destIP.To4() 23 | if destIPv4 == nil { 24 | return nil, fmt.Errorf("%s is not valid IPv4 address", destIP) 25 | } 26 | mac := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff} 27 | macLen := uint32(len(mac)) 28 | 29 | err := wrappers.SendARP( 30 | binary.LittleEndian.Uint32(destIPv4), 31 | s, 32 | (*uint32)(unsafe.Pointer(&mac[0])), 33 | &macLen) 34 | if err != nil { 35 | return nil, err 36 | } 37 | return mac, nil 38 | } 39 | -------------------------------------------------------------------------------- /memory.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "unsafe" 23 | ) 24 | 25 | type MemoryStatus struct { 26 | MemoryLoad uint 27 | TotalPhysicalBytes uint64 28 | AvailablePhysicalBytes uint64 29 | TotalPageFileBytes uint64 30 | AvailablePageFileBytes uint64 31 | TotalVirtualBytes uint64 32 | AvailableVirtualBytes uint64 33 | AvailableExtendedVirtualBytes uint64 34 | } 35 | 36 | func GetMemoryStatus() (*MemoryStatus, error) { 37 | var status wrappers.MEMORYSTATUSEX 38 | status.Length = uint32(unsafe.Sizeof(status)) 39 | if err := wrappers.GlobalMemoryStatusEx(&status); err != nil { 40 | return nil, NewWindowsError("GlobalMemoryStatusEx", err) 41 | } 42 | return &MemoryStatus{ 43 | MemoryLoad: uint(status.MemoryLoad), 44 | TotalPhysicalBytes: status.TotalPhys, 45 | AvailablePhysicalBytes: status.AvailPhys, 46 | TotalPageFileBytes: status.TotalPageFile, 47 | AvailablePageFileBytes: status.AvailPageFile, 48 | TotalVirtualBytes: status.TotalVirtual, 49 | AvailableVirtualBytes: status.AvailVirtual, 50 | AvailableExtendedVirtualBytes: status.AvailExtendedVirtual, 51 | }, nil 52 | } 53 | -------------------------------------------------------------------------------- /module.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | func GetCurrentExePath() (string, error) { 26 | buf := make([]uint16, wrappers.MAX_PATH) 27 | if _, err := wrappers.GetModuleFileName(0, &buf[0], wrappers.MAX_PATH); err != nil { 28 | if err == wrappers.ERROR_INSUFFICIENT_BUFFER { 29 | buf = make([]uint16, syscall.MAX_LONG_PATH) 30 | if _, err := wrappers.GetModuleFileName(0, &buf[0], syscall.MAX_LONG_PATH); err != nil { 31 | return "", NewWindowsError("GetModuleFileName", err) 32 | } 33 | } else { 34 | return "", NewWindowsError("GetModuleFileName", err) 35 | } 36 | } 37 | return syscall.UTF16ToString(buf), nil 38 | } 39 | -------------------------------------------------------------------------------- /netstat.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "unsafe" 23 | ) 24 | 25 | type NetstatTCPState uint32 26 | 27 | const ( 28 | NetstatClosed NetstatTCPState = wrappers.MIB_TCP_STATE_CLOSED 29 | NetstatListen NetstatTCPState = wrappers.MIB_TCP_STATE_LISTEN 30 | NetstatSYNSent NetstatTCPState = wrappers.MIB_TCP_STATE_SYN_SENT 31 | NetstatSYNReceived NetstatTCPState = wrappers.MIB_TCP_STATE_SYN_RCVD 32 | NetstatEstablished NetstatTCPState = wrappers.MIB_TCP_STATE_ESTAB 33 | NetstatFINWait1 NetstatTCPState = wrappers.MIB_TCP_STATE_FIN_WAIT1 34 | NetstatFINWait2 NetstatTCPState = wrappers.MIB_TCP_STATE_FIN_WAIT2 35 | NetstatCloseWait NetstatTCPState = wrappers.MIB_TCP_STATE_CLOSE_WAIT 36 | NetstatClosing NetstatTCPState = wrappers.MIB_TCP_STATE_CLOSING 37 | NetstatLastACK NetstatTCPState = wrappers.MIB_TCP_STATE_LAST_ACK 38 | NetstatTimeWait NetstatTCPState = wrappers.MIB_TCP_STATE_TIME_WAIT 39 | NetstatDeleteTCB NetstatTCPState = wrappers.MIB_TCP_STATE_DELETE_TCB 40 | ) 41 | 42 | type NetstatEntry struct { 43 | State NetstatTCPState 44 | LocalAddress string 45 | LocalPort uint 46 | RemoteAddress string 47 | RemotePort uint 48 | } 49 | 50 | func Netstat() ([]NetstatEntry, error) { 51 | var tcpTable wrappers.MIB_TCPTABLE 52 | bufPtr := (*byte)(unsafe.Pointer(&tcpTable)) 53 | bufLength := uint32(unsafe.Sizeof(tcpTable)) 54 | if err := wrappers.GetTcpTable(&tcpTable, &bufLength, true); err == wrappers.ERROR_INSUFFICIENT_BUFFER { 55 | buf := make([]byte, bufLength) 56 | bufPtr = &buf[0] 57 | if err := wrappers.GetTcpTable((*wrappers.MIB_TCPTABLE)(unsafe.Pointer(bufPtr)), &bufLength, true); err != nil { 58 | return nil, NewWindowsError("GetTcpTable", err) 59 | } 60 | wrappers.RtlMoveMemory((*byte)(unsafe.Pointer(&tcpTable)), bufPtr, unsafe.Sizeof(tcpTable)) 61 | } else if err != nil { 62 | return nil, NewWindowsError("GetTcpTable", err) 63 | } 64 | bufPtr = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(bufPtr)) + unsafe.Sizeof(tcpTable))) 65 | entries := []NetstatEntry{} 66 | for i := uint32(0); i < tcpTable.NumEntries; i++ { 67 | var tcpRow wrappers.MIB_TCPROW 68 | wrappers.RtlMoveMemory((*byte)(unsafe.Pointer(&tcpRow)), bufPtr, unsafe.Sizeof(tcpRow)) 69 | entry := NetstatEntry{ 70 | State: NetstatTCPState(tcpRow.State), 71 | LocalPort: uint(wrappers.Ntohs(uint16(tcpRow.LocalPort))), 72 | RemotePort: uint(wrappers.Ntohs(uint16(tcpRow.RemotePort))), 73 | } 74 | var err error 75 | if entry.LocalAddress, err = convertIPAddress(tcpRow.LocalAddr); err != nil { 76 | return nil, err 77 | } 78 | if entry.RemoteAddress, err = convertIPAddress(tcpRow.RemoteAddr); err != nil { 79 | return nil, err 80 | } 81 | entries = append(entries, entry) 82 | bufPtr = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(bufPtr)) + unsafe.Sizeof(tcpRow))) 83 | } 84 | return entries, nil 85 | } 86 | 87 | func convertIPAddress(ipAddress uint32) (string, error) { 88 | buf := [16]uint16{} 89 | outbuf, err := wrappers.InetNtop( 90 | wrappers.AF_INET, 91 | (*byte)(unsafe.Pointer(&ipAddress)), 92 | &buf[0], 93 | 16) 94 | if err != nil { 95 | return "", NewWindowsError("InetNtop", err) 96 | } 97 | return LpstrToString(outbuf), nil 98 | } 99 | -------------------------------------------------------------------------------- /nls.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | type LocaleNameFlags uint32 26 | 27 | const ( 28 | LocaleNameAllowNeutralNames LocaleNameFlags = wrappers.LOCALE_ALLOW_NEUTRAL_NAMES 29 | ) 30 | 31 | type Language uint16 32 | 33 | var ( 34 | LanguageSystemDefault = Language(wrappers.LANG_SYSTEM_DEFAULT) 35 | LanguageUserDefault = Language(wrappers.LANG_USER_DEFAULT) 36 | ) 37 | 38 | type Locale uint32 39 | 40 | var ( 41 | LocaleSystemDefault = Locale(wrappers.LOCALE_SYSTEM_DEFAULT) 42 | LocaleUserDefault = Locale(wrappers.LOCALE_USER_DEFAULT) 43 | LocaleCustomDefault = Locale(wrappers.LOCALE_CUSTOM_DEFAULT) 44 | LocaleCustomUnspecified = Locale(wrappers.LOCALE_CUSTOM_UNSPECIFIED) 45 | LocaleCustomUIDefault = Locale(wrappers.LOCALE_CUSTOM_UI_DEFAULT) 46 | LocaleNeutral = Locale(wrappers.LOCALE_NEUTRAL) 47 | LocaleInvariant = Locale(wrappers.LOCALE_INVARIANT) 48 | ) 49 | 50 | func (locale Locale) Language() Language { 51 | return Language(wrappers.LANGIDFROMLCID(uint32(locale))) 52 | } 53 | 54 | func LocaleFromLocaleName(localeName string, flags LocaleNameFlags) (Locale, error) { 55 | lcid, err := wrappers.LocaleNameToLCID( 56 | syscall.StringToUTF16Ptr(localeName), 57 | uint32(flags)) 58 | if err != nil { 59 | return 0, NewWindowsError("LocaleNameToLCID", err) 60 | } 61 | return Locale(lcid), nil 62 | } 63 | -------------------------------------------------------------------------------- /nterror.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "fmt" 23 | "strings" 24 | "syscall" 25 | "unsafe" 26 | ) 27 | 28 | type NTError uint32 29 | 30 | func (self NTError) Error() string { 31 | hModule, err := wrappers.LoadLibrary(syscall.StringToUTF16Ptr("ntdll.dll")) 32 | if err != nil { 33 | return fmt.Sprintf("nt error 0x%08X", uint32(self)) 34 | } 35 | defer wrappers.FreeLibrary(hModule) 36 | var message *uint16 37 | _, err = wrappers.FormatMessage( 38 | wrappers.FORMAT_MESSAGE_ALLOCATE_BUFFER | wrappers.FORMAT_MESSAGE_FROM_SYSTEM | wrappers.FORMAT_MESSAGE_FROM_HMODULE, 39 | uintptr(hModule), 40 | uint32(self), 41 | 0, 42 | (*uint16)(unsafe.Pointer(&message)), 43 | 0, 44 | nil) 45 | if err != nil { 46 | return fmt.Sprintf("nt error 0x%08X", uint32(self)) 47 | } 48 | defer wrappers.LocalFree(syscall.Handle(unsafe.Pointer(message))) 49 | return strings.TrimRight(LpstrToString(message), "\r\n") 50 | } 51 | -------------------------------------------------------------------------------- /permissions.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | type Permission uint32 27 | 28 | const ( 29 | GenericRead Permission = wrappers.GENERIC_READ 30 | GenericWrite Permission = wrappers.GENERIC_WRITE 31 | GenericExecute Permission = wrappers.GENERIC_EXECUTE 32 | GenericAll Permission = wrappers.GENERIC_ALL 33 | FileReadData Permission = wrappers.FILE_READ_DATA 34 | FileListDirectory Permission = wrappers.FILE_LIST_DIRECTORY 35 | FileWriteData Permission = wrappers.FILE_WRITE_DATA 36 | FileAddFile Permission = wrappers.FILE_ADD_FILE 37 | FileAppendData Permission = wrappers.FILE_APPEND_DATA 38 | FileAddSubdirectory Permission = wrappers.FILE_ADD_SUBDIRECTORY 39 | FileCreatePipeInstance Permission = wrappers.FILE_CREATE_PIPE_INSTANCE 40 | FileReadEA Permission = wrappers.FILE_READ_EA 41 | FileWriteEA Permission = wrappers.FILE_WRITE_EA 42 | FileExecute Permission = wrappers.FILE_EXECUTE 43 | FileTraverse Permission = wrappers.FILE_TRAVERSE 44 | FileDeleteChild Permission = wrappers.FILE_DELETE_CHILD 45 | FileReadAttributes Permission = wrappers.FILE_READ_ATTRIBUTES 46 | FileWriteAttributes Permission = wrappers.FILE_WRITE_ATTRIBUTES 47 | FileAllAccess Permission = wrappers.FILE_ALL_ACCESS 48 | FileGenericRead Permission = wrappers.FILE_GENERIC_READ 49 | FileGenericWrite Permission = wrappers.FILE_GENERIC_WRITE 50 | FileGenericExecute Permission = wrappers.FILE_GENERIC_EXECUTE 51 | ) 52 | 53 | type AccessMode int32 54 | 55 | const ( 56 | AccessNotUsed AccessMode = wrappers.NOT_USED_ACCESS 57 | AccessGrant AccessMode = wrappers.GRANT_ACCESS 58 | AccessSet AccessMode = wrappers.SET_ACCESS 59 | AccessDeny AccessMode = wrappers.DENY_ACCESS 60 | AccessRevoke AccessMode = wrappers.REVOKE_ACCESS 61 | AccessAuditSuccess AccessMode = wrappers.SET_AUDIT_SUCCESS 62 | AccessAuditFailure AccessMode = wrappers.SET_AUDIT_FAILURE 63 | ) 64 | 65 | type TrusteeType int32 66 | 67 | const ( 68 | TrusteeUnknown TrusteeType = wrappers.TRUSTEE_IS_UNKNOWN 69 | TrusteeUser TrusteeType = wrappers.TRUSTEE_IS_USER 70 | TrusteeGroup TrusteeType = wrappers.TRUSTEE_IS_GROUP 71 | TrusteeDomain TrusteeType = wrappers.TRUSTEE_IS_DOMAIN 72 | TrusteeAlias TrusteeType = wrappers.TRUSTEE_IS_ALIAS 73 | TrusteeWellKnownGroup TrusteeType = wrappers.TRUSTEE_IS_WELL_KNOWN_GROUP 74 | TrusteeDeleted TrusteeType = wrappers.TRUSTEE_IS_DELETED 75 | TrusteeInvalid TrusteeType = wrappers.TRUSTEE_IS_INVALID 76 | TrusteeComputer TrusteeType = wrappers.TRUSTEE_IS_COMPUTER 77 | ) 78 | 79 | type PermissionEntry struct { 80 | TrusteeType TrusteeType 81 | Trustee SecurityID 82 | Permissions Permission 83 | AccessMode AccessMode 84 | } 85 | 86 | func SetFilePermissions(fileName string, permissions []PermissionEntry) error { 87 | explicitAccess := []wrappers.EXPLICIT_ACCESS{} 88 | for _, entry := range permissions { 89 | explicitAccess = append(explicitAccess, wrappers.EXPLICIT_ACCESS{ 90 | AccessPermissions: uint32(entry.Permissions), 91 | AccessMode: int32(entry.AccessMode), 92 | Inheritance: wrappers.NO_INHERITANCE, 93 | Trustee: wrappers.TRUSTEE{ 94 | MultipleTrustee: nil, 95 | MultipleTrusteeOperation: wrappers.NO_MULTIPLE_TRUSTEE, 96 | TrusteeForm: wrappers.TRUSTEE_IS_SID, 97 | TrusteeType: int32(entry.TrusteeType), 98 | Name: (*uint16)(unsafe.Pointer(entry.Trustee.sid)), 99 | }, 100 | }) 101 | } 102 | 103 | var acl *wrappers.ACL 104 | if err := wrappers.SetEntriesInAcl(uint32(len(explicitAccess)), &explicitAccess[0], nil, &acl); err != nil { 105 | return NewWindowsError("SetEntriesInAcl", err) 106 | } 107 | defer wrappers.LocalFree(syscall.Handle(unsafe.Pointer(acl))) 108 | 109 | sd := make([]byte, wrappers.SECURITY_DESCRIPTOR_MIN_LENGTH) 110 | if err := wrappers.InitializeSecurityDescriptor(&sd[0], wrappers.SECURITY_DESCRIPTOR_REVISION); err != nil { 111 | return NewWindowsError("InitializeSecurityDescriptor", err) 112 | } 113 | if err := wrappers.SetSecurityDescriptorDacl(&sd[0], true, acl, false); err != nil { 114 | return NewWindowsError("SetSecurityDescriptorDacl", err) 115 | } 116 | 117 | err := wrappers.SetFileSecurity( 118 | syscall.StringToUTF16Ptr(fileName), 119 | wrappers.DACL_SECURITY_INFORMATION, 120 | &sd[0]) 121 | if err != nil { 122 | return NewWindowsError("SetFileSecurity", err) 123 | } 124 | 125 | return nil 126 | } 127 | -------------------------------------------------------------------------------- /policy.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | type AccountRightName string 27 | 28 | const ( 29 | AccountRightInteractiveLogon AccountRightName = wrappers.SE_INTERACTIVE_LOGON_NAME 30 | AccountRightNetworkLogon AccountRightName = wrappers.SE_NETWORK_LOGON_NAME 31 | AccountRightBatchLogon AccountRightName = wrappers.SE_BATCH_LOGON_NAME 32 | AccountRightServiceLogon AccountRightName = wrappers.SE_SERVICE_LOGON_NAME 33 | AccountRightDenyInteractiveLogon AccountRightName = wrappers.SE_DENY_INTERACTIVE_LOGON_NAME 34 | AccountRightDenyNetworkLogon AccountRightName = wrappers.SE_DENY_NETWORK_LOGON_NAME 35 | AccountRightDenyBatchLogon AccountRightName = wrappers.SE_DENY_BATCH_LOGON_NAME 36 | AccountRightDenyServiceLogon AccountRightName = wrappers.SE_DENY_SERVICE_LOGON_NAME 37 | AccountRightRemoteInteractiveLogon AccountRightName = wrappers.SE_REMOTE_INTERACTIVE_LOGON_NAME 38 | AccountRightDenyRemoteInteractiveLogon AccountRightName = wrappers.SE_DENY_REMOTE_INTERACTIVE_LOGON_NAME 39 | ) 40 | 41 | type SecurityPolicy struct { 42 | handle syscall.Handle 43 | } 44 | 45 | func OpenLocalSecurityPolicy() (*SecurityPolicy, error) { 46 | var handle syscall.Handle 47 | status := wrappers.LsaOpenPolicy( 48 | nil, 49 | &wrappers.OBJECT_ATTRIBUTES{}, 50 | wrappers.POLICY_ALL_ACCESS, 51 | &handle) 52 | if err := wrappers.LsaNtStatusToWinError(status); err != nil { 53 | return nil, err 54 | } 55 | return &SecurityPolicy{handle: handle}, nil 56 | } 57 | 58 | func (self *SecurityPolicy) Close() error { 59 | if self.handle != 0 { 60 | status := wrappers.LsaClose(self.handle) 61 | if err := wrappers.LsaNtStatusToWinError(status); err != nil { 62 | return err 63 | } 64 | self.handle = 0 65 | } 66 | return nil 67 | } 68 | 69 | func (self *SecurityPolicy) GetAccountRights(sid SecurityID) ([]AccountRightName, error) { 70 | var rights *wrappers.UNICODE_STRING 71 | var count uint32 72 | status := wrappers.LsaEnumerateAccountRights(self.handle, sid.sid, &rights, &count) 73 | if err := wrappers.LsaNtStatusToWinError(status); err != nil { 74 | return nil, err 75 | } 76 | defer wrappers.LsaFreeMemory((*byte)(unsafe.Pointer(rights))) 77 | rightNames := make([]AccountRightName, count) 78 | for i := uint32(0); i < count; i++ { 79 | buf := make([]uint16, rights.Length) 80 | wrappers.RtlMoveMemory( 81 | (*byte)(unsafe.Pointer(&buf[0])), 82 | (*byte)(unsafe.Pointer(rights.Buffer)), 83 | uintptr(rights.Length)) 84 | rightNames[i] = AccountRightName(syscall.UTF16ToString(buf)) 85 | rights = (*wrappers.UNICODE_STRING)(unsafe.Pointer(uintptr(unsafe.Pointer(rights)) + unsafe.Sizeof(*rights))) 86 | } 87 | return rightNames, nil 88 | } 89 | 90 | func (self *SecurityPolicy) AddAccountRight(sid SecurityID, right AccountRightName) error { 91 | var rightString wrappers.UNICODE_STRING 92 | wrappers.RtlInitUnicodeString(&rightString, syscall.StringToUTF16Ptr(string(right))) 93 | status := wrappers.LsaAddAccountRights(self.handle, sid.sid, &rightString, 1) 94 | if err := wrappers.LsaNtStatusToWinError(status); err != nil { 95 | return err 96 | } 97 | return nil 98 | } 99 | 100 | func (self *SecurityPolicy) RemoveAccountRight(sid SecurityID, right AccountRightName) error { 101 | var rightString wrappers.UNICODE_STRING 102 | wrappers.RtlInitUnicodeString(&rightString, syscall.StringToUTF16Ptr(string(right))) 103 | status := wrappers.LsaRemoveAccountRights(self.handle, sid.sid, false, &rightString, 1) 104 | if err := wrappers.LsaNtStatusToWinError(status); err != nil { 105 | return err 106 | } 107 | return nil 108 | } 109 | 110 | func (self *SecurityPolicy) RemoveAllAccountRights(sid SecurityID) error { 111 | status := wrappers.LsaRemoveAccountRights(self.handle, sid.sid, true, nil, 0) 112 | if err := wrappers.LsaNtStatusToWinError(status); err != nil { 113 | return err 114 | } 115 | return nil 116 | } 117 | -------------------------------------------------------------------------------- /resource.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | "syscall" 22 | "unsafe" 23 | ) 24 | 25 | type ResourceType uintptr 26 | 27 | func CustomResourceType(resourceTypeName string) ResourceType { 28 | return ResourceType(unsafe.Pointer(syscall.StringToUTF16Ptr(resourceTypeName))) 29 | } 30 | 31 | var ( 32 | ResourceTypeCursor ResourceType = ResourceType(wrappers.RT_CURSOR) 33 | ResourceTypeBitmap ResourceType = ResourceType(wrappers.RT_BITMAP) 34 | ResourceTypeIcon ResourceType = ResourceType(wrappers.RT_ICON) 35 | ResourceTypeMenu ResourceType = ResourceType(wrappers.RT_MENU) 36 | ResourceTypeDialog ResourceType = ResourceType(wrappers.RT_DIALOG) 37 | ResourceTypeString ResourceType = ResourceType(wrappers.RT_STRING) 38 | ResourceTypeFontDir ResourceType = ResourceType(wrappers.RT_FONTDIR) 39 | ResourceTypeFont ResourceType = ResourceType(wrappers.RT_FONT) 40 | ResourceTypeAccelerator ResourceType = ResourceType(wrappers.RT_ACCELERATOR) 41 | ResourceTypeRCData ResourceType = ResourceType(wrappers.RT_RCDATA) 42 | ResourceTypeMessageTable ResourceType = ResourceType(wrappers.RT_MESSAGETABLE) 43 | ResourceTypeGroupCursor ResourceType = ResourceType(wrappers.RT_GROUP_CURSOR) 44 | ResourceTypeGroupIcon ResourceType = ResourceType(wrappers.RT_GROUP_ICON) 45 | ResourceTypeVersion ResourceType = ResourceType(wrappers.RT_VERSION) 46 | ResourceTypeDialogInclude ResourceType = ResourceType(wrappers.RT_DLGINCLUDE) 47 | ResourceTypePlugPlay ResourceType = ResourceType(wrappers.RT_PLUGPLAY) 48 | ResourceTypeVxD ResourceType = ResourceType(wrappers.RT_VXD) 49 | ResourceTypeAniCursor ResourceType = ResourceType(wrappers.RT_ANICURSOR) 50 | ResourceTypeAniIcon ResourceType = ResourceType(wrappers.RT_ANIICON) 51 | ResourceTypeHTML ResourceType = ResourceType(wrappers.RT_HTML) 52 | ResourceTypeManifest ResourceType = ResourceType(wrappers.RT_MANIFEST) 53 | ) 54 | 55 | type ResourceId uintptr 56 | 57 | func IntResourceId(resourceId uint) ResourceId { 58 | return ResourceId(wrappers.MAKEINTRESOURCE(uint16(resourceId))) 59 | } 60 | 61 | func StringResourceId(resourceId string) ResourceId { 62 | return ResourceId(unsafe.Pointer(syscall.StringToUTF16Ptr(resourceId))) 63 | } 64 | 65 | type ResourceUpdate struct { 66 | handle syscall.Handle 67 | } 68 | 69 | func NewResourceUpdate(fileName string, deleteExistingResources bool) (*ResourceUpdate, error) { 70 | hUpdate, err := wrappers.BeginUpdateResource(syscall.StringToUTF16Ptr(fileName), deleteExistingResources) 71 | if err != nil { 72 | return nil, NewWindowsError("BeginUpdateResource", err) 73 | } 74 | return &ResourceUpdate{handle: hUpdate}, nil 75 | } 76 | 77 | func (self *ResourceUpdate) Close() error { 78 | if self.handle != 0 { 79 | if err := wrappers.EndUpdateResource(self.handle, true); err != nil { 80 | return NewWindowsError("EndUpdateResource", err) 81 | } 82 | self.handle = 0 83 | } 84 | return nil 85 | } 86 | 87 | func (self *ResourceUpdate) Save() error { 88 | if err := wrappers.EndUpdateResource(self.handle, false); err != nil { 89 | return NewWindowsError("EndUpdateResource", err) 90 | } 91 | self.handle = 0 92 | return nil 93 | } 94 | 95 | func (self *ResourceUpdate) Update(resourceType ResourceType, resourceId ResourceId, language Language, data []byte) error { 96 | err := wrappers.UpdateResource( 97 | self.handle, 98 | uintptr(resourceType), 99 | uintptr(resourceId), 100 | uint16(language), 101 | &data[0], 102 | uint32(len(data))) 103 | if err != nil { 104 | return NewWindowsError("UpdateResource", err) 105 | } 106 | return nil 107 | } 108 | 109 | func (self *ResourceUpdate) Delete(resourceType ResourceType, resourceId ResourceId, language Language) error { 110 | err := wrappers.UpdateResource( 111 | self.handle, 112 | uintptr(resourceType), 113 | uintptr(resourceId), 114 | uint16(language), 115 | nil, 116 | 0) 117 | if err != nil { 118 | return NewWindowsError("UpdateResource", err) 119 | } 120 | return nil 121 | } 122 | -------------------------------------------------------------------------------- /socket.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | ) 22 | 23 | type AddressFamily uint32 24 | 25 | const ( 26 | AddressFamilyUnspecified AddressFamily = wrappers.AF_UNSPEC 27 | AddressFamilyIP AddressFamily = wrappers.AF_INET 28 | AddressFamilyIPX AddressFamily = wrappers.AF_IPX 29 | AddressFamilyAppleTalk AddressFamily = wrappers.AF_APPLETALK 30 | AddressFamilyNetBIOS AddressFamily = wrappers.AF_NETBIOS 31 | AddressFamilyIPv6 AddressFamily = wrappers.AF_INET6 32 | AddressFamilyIrDA AddressFamily = wrappers.AF_IRDA 33 | AddressFamilyBluetooth AddressFamily = wrappers.AF_BTH 34 | ) 35 | -------------------------------------------------------------------------------- /symlink.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | type SymbolicLinkData struct { 27 | SubstituteName string 28 | PrintName string 29 | Relative bool 30 | } 31 | 32 | func MakeSymbolicLink(symlinkPath string, targetPath string, isDirectory bool) error { 33 | var flags uint32 34 | if isDirectory { 35 | flags |= wrappers.SYMBOLIC_LINK_FLAG_DIRECTORY 36 | } 37 | err := wrappers.CreateSymbolicLink( 38 | syscall.StringToUTF16Ptr(symlinkPath), 39 | syscall.StringToUTF16Ptr(targetPath), 40 | flags) 41 | if err != nil { 42 | return NewWindowsError("CreateSymbolicLink", err) 43 | } 44 | return nil 45 | } 46 | 47 | func GetSymbolicLink(symlinkPath string) (*SymbolicLinkData, error) { 48 | file, err := wrappers.CreateFile( 49 | syscall.StringToUTF16Ptr(symlinkPath), 50 | wrappers.FILE_READ_EA, 51 | wrappers.FILE_SHARE_READ|wrappers.FILE_SHARE_WRITE|wrappers.FILE_SHARE_DELETE, 52 | nil, 53 | wrappers.OPEN_EXISTING, 54 | wrappers.FILE_FLAG_OPEN_REPARSE_POINT|wrappers.FILE_FLAG_BACKUP_SEMANTICS, 55 | 0) 56 | if err != nil { 57 | return nil, NewWindowsError("CreateFile", err) 58 | } 59 | defer wrappers.CloseHandle(file) 60 | buf := make([]byte, wrappers.MAXIMUM_REPARSE_DATA_BUFFER_SIZE) 61 | var bytesReturned uint32 62 | err = wrappers.DeviceIoControl( 63 | file, 64 | wrappers.FSCTL_GET_REPARSE_POINT, 65 | nil, 66 | 0, 67 | &buf[0], 68 | wrappers.MAXIMUM_REPARSE_DATA_BUFFER_SIZE, 69 | &bytesReturned, 70 | nil) 71 | if err != nil { 72 | return nil, NewWindowsError("DeviceIoControl", err) 73 | } 74 | data := (*wrappers.REPARSE_DATA_BUFFER)(unsafe.Pointer(&buf[0])) 75 | if data.ReparseTag != wrappers.IO_REPARSE_TAG_SYMLINK { 76 | return nil, nil 77 | } 78 | substituteNameBuf := make([]uint16, data.SubstituteNameLength/2) 79 | printNameBuf := make([]uint16, data.PrintNameLength/2) 80 | wrappers.RtlMoveMemory( 81 | (*byte)(unsafe.Pointer(&substituteNameBuf[0])), 82 | &buf[unsafe.Sizeof(*data)+uintptr(data.SubstituteNameOffset)], 83 | uintptr(data.SubstituteNameLength)) 84 | wrappers.RtlMoveMemory( 85 | (*byte)(unsafe.Pointer(&printNameBuf[0])), 86 | &buf[unsafe.Sizeof(*data)+uintptr(data.PrintNameOffset)], 87 | uintptr(data.PrintNameLength)) 88 | return &SymbolicLinkData{ 89 | SubstituteName: syscall.UTF16ToString(substituteNameBuf), 90 | PrintName: syscall.UTF16ToString(printNameBuf), 91 | Relative: (data.Flags & wrappers.SYMLINK_FLAG_RELATIVE) != 0, 92 | }, nil 93 | } 94 | -------------------------------------------------------------------------------- /sysdir.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | func GetSharedWindowsPath() (string, error) { 26 | len, err := wrappers.GetSystemWindowsDirectory(nil, 0) 27 | if err != nil { 28 | return "", NewWindowsError("GetSystemWindowsDirectory", err) 29 | } 30 | buf := make([]uint16, len) 31 | if _, err := wrappers.GetSystemWindowsDirectory(&buf[0], len); err != nil { 32 | return "", NewWindowsError("GetSystemWindowsDirectory", err) 33 | } 34 | return syscall.UTF16ToString(buf), nil 35 | } 36 | 37 | func GetWindowsPath() (string, error) { 38 | len, err := wrappers.GetWindowsDirectory(nil, 0) 39 | if err != nil { 40 | return "", NewWindowsError("GetWindowsDirectory", err) 41 | } 42 | buf := make([]uint16, len) 43 | if _, err := wrappers.GetWindowsDirectory(&buf[0], len); err != nil { 44 | return "", NewWindowsError("GetWindowsDirectory", err) 45 | } 46 | return syscall.UTF16ToString(buf), nil 47 | } 48 | 49 | func GetWindowsSystemPath() (string, error) { 50 | len, err := wrappers.GetSystemDirectory(nil, 0) 51 | if err != nil { 52 | return "", NewWindowsError("GetSystemDirectory", err) 53 | } 54 | buf := make([]uint16, len) 55 | if _, err := wrappers.GetSystemDirectory(&buf[0], len); err != nil { 56 | return "", NewWindowsError("GetSystemDirectory", err) 57 | } 58 | return syscall.UTF16ToString(buf), nil 59 | } 60 | 61 | func GetWindowsSystemWOW64Path() (string, error) { 62 | len, err := wrappers.GetSystemWow64Directory(nil, 0) 63 | if err != nil { 64 | return "", NewWindowsError("GetSystemWow64Directory", err) 65 | } 66 | buf := make([]uint16, len) 67 | if _, err := wrappers.GetSystemWow64Directory(&buf[0], len); err != nil { 68 | return "", NewWindowsError("GetSystemWow64Directory", err) 69 | } 70 | return syscall.UTF16ToString(buf), nil 71 | } 72 | -------------------------------------------------------------------------------- /sysinfo.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | 23 | "github.com/winlabs/gowin32/wrappers" 24 | ) 25 | 26 | type ProcessorArchitecture uint16 27 | 28 | const ( 29 | ProcessorArchitectureIntel ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_INTEL 30 | ProcessorArchitectureMIPS ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_MIPS 31 | ProcessorArchitectureAlpha ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_ALPHA 32 | ProcessorArchitecturePowerPC ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_PPC 33 | ProcessorArchitectureARM ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_ARM 34 | ProcessorArchitectureIA64 ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_IA64 35 | ProcessorArchitectureAMD64 ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_AMD64 36 | ) 37 | 38 | type DisplayDevice struct { 39 | DeviceName string 40 | DeviceString string 41 | StateFlags DisplayDeviceStateFlags 42 | DeviceID string 43 | DeviceKey string 44 | } 45 | 46 | type DisplayDeviceStateFlags uint32 47 | 48 | const ( 49 | DisplayDeviceActive DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_ACTIVE 50 | DisplayDevicePrimaryDevice DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_PRIMARY_DEVICE 51 | DisplayDeviceMirroringDriver DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_MIRRORING_DRIVER 52 | DisplayDeviceVGACompatible DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_VGA_COMPATIBLE 53 | DisplayDeviceRemovable DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_REMOVABLE 54 | DisplayDeviceModeSpruned DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_MODESPRUNED 55 | ) 56 | 57 | type DisplayMonitorInfo struct { 58 | Handle syscall.Handle 59 | DeviceContext syscall.Handle 60 | Rectangle Rectangle 61 | } 62 | 63 | type ProcessorInfo struct { 64 | ProcessorArchitecture ProcessorArchitecture 65 | NumberOfProcessors uint 66 | ProcessorLevel uint 67 | ProcessorRevision uint 68 | } 69 | 70 | func GetAllDisplayDevices() []DisplayDevice { 71 | result := make([]DisplayDevice, 0) 72 | var device *uint16 73 | var dd wrappers.DISPLAY_DEVICE 74 | dd.Cb = uint32(unsafe.Sizeof(dd)) 75 | 76 | var i uint32 77 | for i = 0; ; i++ { 78 | if wrappers.EnumDisplayDevices(device, i, &dd, 0) { 79 | result = append(result, 80 | DisplayDevice{DeviceName: syscall.UTF16ToString(dd.DeviceName[:]), 81 | DeviceString: syscall.UTF16ToString(dd.DeviceString[:]), 82 | StateFlags: DisplayDeviceStateFlags(dd.StateFlags), 83 | DeviceID: syscall.UTF16ToString(dd.DeviceID[:]), 84 | DeviceKey: syscall.UTF16ToString(dd.DeviceKey[:]), 85 | }) 86 | } else { 87 | break 88 | } 89 | } 90 | return result 91 | 92 | } 93 | 94 | func GetProcessorInfo() *ProcessorInfo { 95 | var si wrappers.SYSTEM_INFO 96 | wrappers.GetSystemInfo(&si) 97 | return &ProcessorInfo{ 98 | ProcessorArchitecture: ProcessorArchitecture(si.ProcessorArchitecture), 99 | NumberOfProcessors: uint(si.NumberOfProcessors), 100 | ProcessorLevel: uint(si.ProcessorLevel), 101 | ProcessorRevision: uint(si.ProcessorRevision), 102 | } 103 | } 104 | 105 | func GetAllDisplayMonitors() []DisplayMonitorInfo { 106 | 107 | result := []DisplayMonitorInfo{} 108 | wrappers.EnumDisplayMonitors( 109 | syscall.Handle(0), 110 | nil, 111 | func(hmonitor syscall.Handle, hdc syscall.Handle, rect *wrappers.RECT, lparam uintptr) int32 { 112 | result = append(result, DisplayMonitorInfo{Handle: hmonitor, DeviceContext: hdc, Rectangle: rectToRectangle(*rect)}) 113 | return 1 114 | }, 115 | uintptr(0), 116 | ) 117 | 118 | return result 119 | } 120 | -------------------------------------------------------------------------------- /system.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2019 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "syscall" 21 | 22 | "github.com/winlabs/gowin32/wrappers" 23 | ) 24 | 25 | type InitiateShutdownFlags uint32 26 | 27 | const ( 28 | InitiateShutdownFlagForceOthers InitiateShutdownFlags = wrappers.SHUTDOWN_FORCE_OTHERS 29 | InitiateShutdownFlagForceSelf InitiateShutdownFlags = wrappers.SHUTDOWN_FORCE_SELF 30 | InitiateShutdownFlagRestart InitiateShutdownFlags = wrappers.SHUTDOWN_RESTART 31 | InitiateShutdownFlagPowerOff InitiateShutdownFlags = wrappers.SHUTDOWN_POWEROFF 32 | InitiateShutdownFlagNoReboot InitiateShutdownFlags = wrappers.SHUTDOWN_NOREBOOT 33 | InitiateShutdownFlagGraceOverride InitiateShutdownFlags = wrappers.SHUTDOWN_GRACE_OVERRIDE 34 | InitiateShutdownFlagInstallUpdates InitiateShutdownFlags = wrappers.SHUTDOWN_INSTALL_UPDATES 35 | InitiateShutdownFlagRestartApps InitiateShutdownFlags = wrappers.SHUTDOWN_RESTARTAPPS 36 | InitiateShutdownFlagSkipSvcPreshutdown InitiateShutdownFlags = wrappers.SHUTDOWN_SKIP_SVC_PRESHUTDOWN 37 | InitiateShutdownFlagHybrid InitiateShutdownFlags = wrappers.SHUTDOWN_HYBRID 38 | ) 39 | 40 | type InitiateShutdownReason uint32 41 | 42 | const ( 43 | InitiateShutdownReasonUserDefined InitiateShutdownReason = wrappers.SHTDN_REASON_FLAG_USER_DEFINED 44 | InitiateShutdownReasonPlanned InitiateShutdownReason = wrappers.SHTDN_REASON_FLAG_PLANNED 45 | ) 46 | 47 | const ( 48 | InitiateShutdownReasonMajorOther InitiateShutdownReason = wrappers.SHTDN_REASON_MAJOR_OTHER 49 | InitiateShutdownReasonMajorHardware InitiateShutdownReason = wrappers.SHTDN_REASON_MAJOR_HARDWARE 50 | InitiateShutdownReasonMajorOperatingSystem InitiateShutdownReason = wrappers.SHTDN_REASON_MAJOR_OPERATINGSYSTEM 51 | InitiateShutdownReasonMajorSoftware InitiateShutdownReason = wrappers.SHTDN_REASON_MAJOR_SOFTWARE 52 | InitiateShutdownReasonMajorApplication InitiateShutdownReason = wrappers.SHTDN_REASON_MAJOR_APPLICATION 53 | InitiateShutdownReasonMajorSystem InitiateShutdownReason = wrappers.SHTDN_REASON_MAJOR_SYSTEM 54 | InitiateShutdownReasonMajorPower InitiateShutdownReason = wrappers.SHTDN_REASON_MAJOR_POWER 55 | InitiateShutdownReasonMajorLegacyAPI InitiateShutdownReason = wrappers.SHTDN_REASON_MAJOR_LEGACY_API 56 | ) 57 | 58 | const ( 59 | InitiateShutdownReasonMinorOther InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_OTHER 60 | InitiateShutdownReasonMinorMaintenance InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_MAINTENANCE 61 | InitiateShutdownReasonMinorInstallation InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_INSTALLATION 62 | InitiateShutdownReasonMinorUpgrade InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_UPGRADE 63 | InitiateShutdownReasonMinorReconfig InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_RECONFIG 64 | InitiateShutdownReasonMinorHung InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_HUNG 65 | InitiateShutdownReasonMinorUnstable InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_UNSTABLE 66 | InitiateShutdownReasonMinorDisk InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_DISK 67 | InitiateShutdownReasonMinorProcessor InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_PROCESSOR 68 | InitiateShutdownReasonMinorNetwordCard InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_NETWORKCARD 69 | InitiateShutdownReasonMinorPowerSupply InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_POWER_SUPPLY 70 | InitiateShutdownReasonMinorCordUnplugged InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_CORDUNPLUGGED 71 | InitiateShutdownReasonMinorEnvironment InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_ENVIRONMENT 72 | InitiateShutdownReasonMinorHardwareDriver InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_HARDWARE_DRIVER 73 | InitiateShutdownReasonMinorOtherDriver InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_OTHERDRIVER 74 | InitiateShutdownReasonMinorBlueScreen InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_BLUESCREEN 75 | InitiateShutdownReasonMinorServicePack InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_SERVICEPACK 76 | InitiateShutdownReasonMinorHotFix InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_HOTFIX 77 | InitiateShutdownReasonMinorSecurityFix InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_SECURITYFIX 78 | InitiateShutdownReasonMinorSecurity InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_SECURITY 79 | InitiateShutdownReasonMinorConnectivity InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY 80 | InitiateShutdownReasonMinorWMI InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_WMI 81 | InitiateShutdownReasonMinorServicePackUninstall InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_SERVICEPACK_UNINSTALL 82 | InitiateShutdownReasonMinorHotfixUninstall InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_HOTFIX_UNINSTALL 83 | InitiateShutdownReasonMinorSecurityFixUninstall InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_SECURITYFIX_UNINSTALL 84 | InitiateShutdownReasonMinorMMC InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_MMC 85 | InitiateShutdownReasonMinorTermSrv InitiateShutdownReason = wrappers.SHTDN_REASON_MINOR_TERMSRV 86 | ) 87 | 88 | func InitiateShutdown(machineName string, message string, gracePeriod int, shutdownFlags InitiateShutdownFlags, reason InitiateShutdownReason) error { 89 | if err := wrappers.InitiateShutdown( 90 | syscall.StringToUTF16Ptr(machineName), 91 | syscall.StringToUTF16Ptr(message), 92 | uint32(gracePeriod), 93 | uint32(shutdownFlags), 94 | uint32(reason)); err != nil { 95 | return NewWindowsError("InitiateShutdown", err) 96 | } 97 | return nil 98 | } 99 | 100 | func InitiateSystemShutdown(machineName string, message string, timeout int, forceAppsClosed bool, rebootAfterShutdown bool) error { 101 | if err := wrappers.InitiateSystemShutdown( 102 | syscall.StringToUTF16Ptr(machineName), 103 | syscall.StringToUTF16Ptr(message), 104 | uint32(timeout), 105 | forceAppsClosed, 106 | rebootAfterShutdown); err != nil { 107 | return NewWindowsError("InitiateSystemShutdown", err) 108 | } 109 | return nil 110 | } 111 | -------------------------------------------------------------------------------- /tempfile.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | func GenerateTempFileName(pathName string, prefixString string, unique uint) (string, uint, error) { 26 | buf := [wrappers.MAX_PATH]uint16{} 27 | result, err := wrappers.GetTempFileName( 28 | syscall.StringToUTF16Ptr(pathName), 29 | syscall.StringToUTF16Ptr(prefixString), 30 | uint32(unique), 31 | &buf[0]) 32 | if err != nil { 33 | return "", 0, NewWindowsError("GetTempFileName", err) 34 | } 35 | return syscall.UTF16ToString(buf[:]), uint(result), nil 36 | } 37 | 38 | func GetTempFilePath() (string, error) { 39 | len, err := wrappers.GetTempPath(0, nil) 40 | if err != nil { 41 | return "", NewWindowsError("GetTempPath", err) 42 | } 43 | buf := make([]uint16, len) 44 | if _, err := wrappers.GetTempPath(len, &buf[0]); err != nil { 45 | return "", NewWindowsError("GetTempPath", err) 46 | } 47 | return syscall.UTF16ToString(buf), nil 48 | } 49 | -------------------------------------------------------------------------------- /time.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | ) 22 | 23 | type SystemTimeCounters struct { 24 | Idle uint64 25 | Kernel uint64 26 | User uint64 27 | } 28 | 29 | func fileTimeToUint64(fileTime wrappers.FILETIME) uint64 { 30 | return uint64(fileTime.HighDateTime)<<32 | uint64(fileTime.LowDateTime) 31 | } 32 | 33 | func GetSystemTimeCounters() (*SystemTimeCounters, error) { 34 | var idleTime, kernelTime, userTime wrappers.FILETIME 35 | if err := wrappers.GetSystemTimes(&idleTime, &kernelTime, &userTime); err != nil { 36 | return nil, NewWindowsError("GetSystemTimes", err) 37 | } 38 | return &SystemTimeCounters{ 39 | Idle: fileTimeToUint64(idleTime), 40 | Kernel: fileTimeToUint64(kernelTime) - fileTimeToUint64(idleTime), 41 | User: fileTimeToUint64(userTime), 42 | }, nil 43 | } 44 | 45 | func GetTimeCounter() uint64 { 46 | var systemTime wrappers.FILETIME 47 | wrappers.GetSystemTimeAsFileTime(&systemTime) 48 | return fileTimeToUint64(systemTime) 49 | } 50 | -------------------------------------------------------------------------------- /version.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | type VerRelOp uint8 27 | 28 | const ( 29 | VerEqual VerRelOp = wrappers.VER_EQUAL 30 | VerGreater VerRelOp = wrappers.VER_GREATER 31 | VerGreaterEqual VerRelOp = wrappers.VER_GREATER_EQUAL 32 | VerLess VerRelOp = wrappers.VER_LESS 33 | VerLessEqual VerRelOp = wrappers.VER_LESS_EQUAL 34 | ) 35 | 36 | type VerLogOp uint8 37 | 38 | const ( 39 | VerAnd VerLogOp = wrappers.VER_AND 40 | VerOr VerLogOp = wrappers.VER_OR 41 | ) 42 | 43 | type VerPlatform uint32 44 | 45 | const ( 46 | VerPlatformWin32s VerPlatform = wrappers.VER_PLATFORM_WIN32s 47 | VerPlatformWindows9x VerPlatform = wrappers.VER_PLATFORM_WIN32_WINDOWS 48 | VerPlatformWindowsNT VerPlatform = wrappers.VER_PLATFORM_WIN32_NT 49 | ) 50 | 51 | type VerSuite uint16 52 | 53 | const ( 54 | VerSuiteSmallBusiness VerSuite = wrappers.VER_SUITE_SMALLBUSINESS 55 | VerSuiteEnterprise VerSuite = wrappers.VER_SUITE_ENTERPRISE 56 | VerSuiteBackOffice VerSuite = wrappers.VER_SUITE_BACKOFFICE 57 | VerSuiteCommunications VerSuite = wrappers.VER_SUITE_COMMUNICATIONS 58 | VerSuiteTerminal VerSuite = wrappers.VER_SUITE_TERMINAL 59 | VerSuiteSmallBusinessRestricted VerSuite = wrappers.VER_SUITE_SMALLBUSINESS_RESTRICTED 60 | VerSuiteEmbeddedNT VerSuite = wrappers.VER_SUITE_EMBEDDEDNT 61 | VerSuiteDataCenter VerSuite = wrappers.VER_SUITE_DATACENTER 62 | VerSuiteSingleUserTS VerSuite = wrappers.VER_SUITE_SINGLEUSERTS 63 | VerSuitePersonal VerSuite = wrappers.VER_SUITE_PERSONAL 64 | VerSuiteBlade VerSuite = wrappers.VER_SUITE_BLADE 65 | VerSuiteEmbeddedRestricted VerSuite = wrappers.VER_SUITE_EMBEDDED_RESTRICTED 66 | VerSuiteSecurityAppliance VerSuite = wrappers.VER_SUITE_SECURITY_APPLIANCE 67 | VerSuiteStorageServer VerSuite = wrappers.VER_SUITE_STORAGE_SERVER 68 | VerSuiteComputeServer VerSuite = wrappers.VER_SUITE_COMPUTE_SERVER 69 | VerSuiteWHServer VerSuite = wrappers.VER_SUITE_WH_SERVER 70 | ) 71 | 72 | type VerProductType uint8 73 | 74 | const ( 75 | VerProductWorkstation VerProductType = wrappers.VER_NT_WORKSTATION 76 | VerProductDomainController VerProductType = wrappers.VER_NT_DOMAIN_CONTROLLER 77 | VerProductServer VerProductType = wrappers.VER_NT_SERVER 78 | ) 79 | 80 | type VersionCheck struct { 81 | osvi wrappers.OSVERSIONINFOEX 82 | typeMask uint32 83 | conditionMask uint64 84 | } 85 | 86 | func (self *VersionCheck) MajorVersion(op VerRelOp, value uint) { 87 | self.osvi.MajorVersion = uint32(value) 88 | self.typeMask |= wrappers.VER_MAJORVERSION 89 | self.conditionMask = wrappers.VerSetConditionMask(self.conditionMask, wrappers.VER_MAJORVERSION, uint8(op)) 90 | } 91 | 92 | func (self *VersionCheck) MinorVersion(op VerRelOp, value uint) { 93 | self.osvi.MinorVersion = uint32(value) 94 | self.typeMask |= wrappers.VER_MINORVERSION 95 | self.conditionMask = wrappers.VerSetConditionMask(self.conditionMask, wrappers.VER_MINORVERSION, uint8(op)) 96 | } 97 | 98 | func (self *VersionCheck) BuildNumber(op VerRelOp, value uint) { 99 | self.osvi.BuildNumber = uint32(value) 100 | self.typeMask |= wrappers.VER_BUILDNUMBER 101 | self.conditionMask = wrappers.VerSetConditionMask(self.conditionMask, wrappers.VER_BUILDNUMBER, uint8(op)) 102 | } 103 | 104 | func (self *VersionCheck) Platform(op VerRelOp, value VerPlatform) { 105 | self.osvi.PlatformId = uint32(value) 106 | self.typeMask |= wrappers.VER_PLATFORMID 107 | self.conditionMask = wrappers.VerSetConditionMask(self.conditionMask, wrappers.VER_PLATFORMID, uint8(op)) 108 | } 109 | 110 | func (self *VersionCheck) ServicePackMajor(op VerRelOp, value uint) { 111 | self.osvi.ServicePackMajor = uint16(value) 112 | self.typeMask |= wrappers.VER_SERVICEPACKMAJOR 113 | self.conditionMask = wrappers.VerSetConditionMask(self.conditionMask, wrappers.VER_SERVICEPACKMAJOR, uint8(op)) 114 | } 115 | 116 | func (self *VersionCheck) ServicePackMinor(op VerRelOp, value uint) { 117 | self.osvi.ServicePackMinor = uint16(value) 118 | self.typeMask |= wrappers.VER_SERVICEPACKMINOR 119 | self.conditionMask = wrappers.VerSetConditionMask(self.conditionMask, wrappers.VER_SERVICEPACKMINOR, uint8(op)) 120 | } 121 | 122 | func (self *VersionCheck) Suite(op VerLogOp, value VerSuite) { 123 | self.osvi.SuiteMask = uint16(value) 124 | self.typeMask |= wrappers.VER_SUITENAME 125 | self.conditionMask = wrappers.VerSetConditionMask(self.conditionMask, wrappers.VER_SUITENAME, uint8(op)) 126 | } 127 | 128 | func (self *VersionCheck) ProductType(op VerRelOp, value VerProductType) { 129 | self.osvi.ProductType = uint8(value) 130 | self.typeMask |= wrappers.VER_PRODUCT_TYPE 131 | self.conditionMask = wrappers.VerSetConditionMask(self.conditionMask, wrappers.VER_PRODUCT_TYPE, uint8(op)) 132 | } 133 | 134 | func (self *VersionCheck) Verify() (bool, error) { 135 | self.osvi.OSVersionInfoSize = uint32(unsafe.Sizeof(self.osvi)) 136 | if err := wrappers.VerifyVersionInfo(&self.osvi, self.typeMask, self.conditionMask); err != nil { 137 | if err == wrappers.ERROR_OLD_WIN_VERSION { 138 | return false, nil 139 | } 140 | return false, NewWindowsError("VerifyVersionInfo", err) 141 | } 142 | return true, nil 143 | } 144 | 145 | type OSVersionInfo struct { 146 | MajorVersion uint 147 | MinorVersion uint 148 | BuildNumber uint 149 | PlatformId VerPlatform 150 | ServicePackName string 151 | ServicePackMajor uint 152 | ServicePackMinor uint 153 | SuiteMask VerSuite 154 | ProductType VerProductType 155 | } 156 | 157 | func GetWindowsVersion() (*OSVersionInfo, error) { 158 | var osvi wrappers.OSVERSIONINFOEX 159 | osvi.OSVersionInfoSize = uint32(unsafe.Sizeof(osvi)) 160 | if err := wrappers.GetVersionEx(&osvi); err != nil { 161 | return nil, NewWindowsError("GetVersionEx", err) 162 | } 163 | return &OSVersionInfo{ 164 | MajorVersion: uint(osvi.MajorVersion), 165 | MinorVersion: uint(osvi.MinorVersion), 166 | BuildNumber: uint(osvi.BuildNumber), 167 | PlatformId: VerPlatform(osvi.PlatformId), 168 | ServicePackName: syscall.UTF16ToString(osvi.CSDVersion[:]), 169 | ServicePackMajor: uint(osvi.ServicePackMajor), 170 | ServicePackMinor: uint(osvi.ServicePackMinor), 171 | SuiteMask: VerSuite(osvi.SuiteMask), 172 | ProductType: VerProductType(osvi.ProductType), 173 | }, nil 174 | } 175 | 176 | func IsWindowsXP() (bool, error) { 177 | osVer, err := GetWindowsVersion() 178 | if err != nil { 179 | return false, err 180 | } 181 | if osVer.PlatformId == VerPlatformWindowsNT { 182 | if osVer.MajorVersion == 5 && osVer.MinorVersion == 1 { 183 | return true, nil 184 | } 185 | if osVer.MajorVersion == 5 && osVer.MinorVersion == 2 && osVer.ProductType != VerProductWorkstation { 186 | return true, nil 187 | } 188 | } 189 | return false, nil 190 | } 191 | 192 | func IsWindowsVersionOrGreater(majorVersion uint, minorVersion uint, servicePackMajor uint) (bool, error) { 193 | vc := VersionCheck{} 194 | vc.MajorVersion(VerGreaterEqual, majorVersion) 195 | vc.MinorVersion(VerGreaterEqual, minorVersion) 196 | vc.ServicePackMajor(VerGreaterEqual, servicePackMajor) 197 | return vc.Verify() 198 | } 199 | 200 | func IsWindowsXPOrGreater() (bool, error) { 201 | return IsWindowsVersionOrGreater(5, 1, 0) 202 | } 203 | 204 | func IsWindowsXPSP1OrGreater() (bool, error) { 205 | return IsWindowsVersionOrGreater(5, 1, 1) 206 | } 207 | 208 | func IsWindowsXPSP2OrGreater() (bool, error) { 209 | return IsWindowsVersionOrGreater(5, 1, 2) 210 | } 211 | 212 | func IsWindowsXPSP3OrGreater() (bool, error) { 213 | return IsWindowsVersionOrGreater(5, 1, 3) 214 | } 215 | 216 | func IsWindowsVistaOrGreater() (bool, error) { 217 | return IsWindowsVersionOrGreater(6, 0, 0) 218 | } 219 | 220 | func IsWindowsVistaSP1OrGreater() (bool, error) { 221 | return IsWindowsVersionOrGreater(6, 0, 1) 222 | } 223 | 224 | func IsWindowsVistaSP2OrGreater() (bool, error) { 225 | return IsWindowsVersionOrGreater(6, 0, 2) 226 | } 227 | 228 | func IsWindows7OrGreater() (bool, error) { 229 | return IsWindowsVersionOrGreater(6, 1, 0) 230 | } 231 | 232 | func IsWindows7SP1OrGreater() (bool, error) { 233 | return IsWindowsVersionOrGreater(6, 1, 1) 234 | } 235 | 236 | func IsWindows8OrGreater() (bool, error) { 237 | return IsWindowsVersionOrGreater(6, 2, 0) 238 | } 239 | 240 | func IsWindows8Point1OrGreater() (bool, error) { 241 | return IsWindowsVersionOrGreater(6, 3, 0) 242 | } 243 | 244 | func IsWindows10OrGreater() (bool, error) { 245 | return IsWindowsVersionOrGreater(10, 0, 0) 246 | } 247 | -------------------------------------------------------------------------------- /volume.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "github.com/winlabs/gowin32/wrappers" 21 | 22 | "syscall" 23 | ) 24 | 25 | type FileSystemFlags uint32 26 | 27 | const ( 28 | FileSystemCaseSensitiveSearch FileSystemFlags = wrappers.FILE_CASE_SENSITIVE_SEARCH 29 | FileSystemCasePreservedNames FileSystemFlags = wrappers.FILE_CASE_PRESERVED_NAMES 30 | FileSystemUnicodeOnDisk FileSystemFlags = wrappers.FILE_UNICODE_ON_DISK 31 | FileSystemPersistentACLs FileSystemFlags = wrappers.FILE_PERSISTENT_ACLS 32 | FileSystemFileCompression FileSystemFlags = wrappers.FILE_FILE_COMPRESSION 33 | FileSystemVolumeQuotas FileSystemFlags = wrappers.FILE_VOLUME_QUOTAS 34 | FileSystemSupportsSparseFiles FileSystemFlags = wrappers.FILE_SUPPORTS_SPARSE_FILES 35 | FileSystemSupportsReparsePoints FileSystemFlags = wrappers.FILE_SUPPORTS_REPARSE_POINTS 36 | FileSystemSupportsRemoteStorage FileSystemFlags = wrappers.FILE_SUPPORTS_REMOTE_STORAGE 37 | FileSystemVolumeIsCompressed FileSystemFlags = wrappers.FILE_VOLUME_IS_COMPRESSED 38 | FileSystemSupportsObjectIDs FileSystemFlags = wrappers.FILE_SUPPORTS_OBJECT_IDS 39 | FileSystemSupportsEncryption FileSystemFlags = wrappers.FILE_SUPPORTS_ENCRYPTION 40 | FileSystemNamedStreams FileSystemFlags = wrappers.FILE_NAMED_STREAMS 41 | FileSystemReadOnlyVolume FileSystemFlags = wrappers.FILE_READ_ONLY_VOLUME 42 | FileSystemSequentialWriteOnce FileSystemFlags = wrappers.FILE_SEQUENTIAL_WRITE_ONCE 43 | FileSystemSupportsTransactions FileSystemFlags = wrappers.FILE_SUPPORTS_TRANSACTIONS 44 | FileSystemSupportsHardLinks FileSystemFlags = wrappers.FILE_SUPPORTS_HARD_LINKS 45 | FileSystemSupportsExtendedAttributes FileSystemFlags = wrappers.FILE_SUPPORTS_EXTENDED_ATTRIBUTES 46 | FileSystemSupportsOpenByFileID FileSystemFlags = wrappers.FILE_SUPPORTS_OPEN_BY_FILE_ID 47 | FileSystemSupportsUSNJournal FileSystemFlags = wrappers.FILE_SUPPORTS_USN_JOURNAL 48 | ) 49 | 50 | type VolumeInfo struct { 51 | VolumeName string 52 | VolumeSerialNumber uint 53 | MaximumComponentLength uint 54 | FileSystemFlags FileSystemFlags 55 | FileSystemName string 56 | } 57 | 58 | type DriveType uint32 59 | 60 | const ( 61 | DriveTypeUnknown DriveType = wrappers.DRIVE_UNKNOWN 62 | DriveNoRootDir DriveType = wrappers.DRIVE_NO_ROOT_DIR 63 | DriveRemovable DriveType = wrappers.DRIVE_REMOVABLE 64 | DriveFixed DriveType = wrappers.DRIVE_FIXED 65 | DriveRemote DriveType = wrappers.DRIVE_REMOTE 66 | DriveCDROM DriveType = wrappers.DRIVE_CDROM 67 | DriveRAMDisk DriveType = wrappers.DRIVE_RAMDISK 68 | ) 69 | 70 | func GetVolumeInfo(rootPathName string) (*VolumeInfo, error) { 71 | var volumeSerialNumber uint32 72 | var maximumComponentLength uint32 73 | var fileSystemFlags uint32 74 | volumeNameBuffer := make([]uint16, syscall.MAX_PATH+1) 75 | fileSystemNameBuffer := make([]uint16, syscall.MAX_PATH+1) 76 | err := wrappers.GetVolumeInformation( 77 | syscall.StringToUTF16Ptr(rootPathName), 78 | &volumeNameBuffer[0], 79 | syscall.MAX_PATH+1, 80 | &volumeSerialNumber, 81 | &maximumComponentLength, 82 | &fileSystemFlags, 83 | &fileSystemNameBuffer[0], 84 | syscall.MAX_PATH+1) 85 | if err != nil { 86 | return nil, NewWindowsError("GetVolumeInformation", err) 87 | } 88 | return &VolumeInfo{ 89 | VolumeName: syscall.UTF16ToString(volumeNameBuffer), 90 | VolumeSerialNumber: uint(volumeSerialNumber), 91 | MaximumComponentLength: uint(maximumComponentLength), 92 | FileSystemFlags: FileSystemFlags(fileSystemFlags), 93 | FileSystemName: syscall.UTF16ToString(fileSystemNameBuffer), 94 | }, nil 95 | } 96 | 97 | func GetVolumeDriveType(rootPathName string) DriveType { 98 | return DriveType(wrappers.GetDriveType(syscall.StringToUTF16Ptr(rootPathName))) 99 | } 100 | 101 | const ( 102 | MaximumVolumeGUIDPath = 50 103 | ) 104 | 105 | func GetVolumeNameFromMountPoint(volumeMountPoint string) (string, error) { 106 | volumeName := make([]uint16, MaximumVolumeGUIDPath) 107 | 108 | err := wrappers.GetVolumeNameForVolumeMountPoint( 109 | syscall.StringToUTF16Ptr(volumeMountPoint), 110 | &volumeName[0], 111 | MaximumVolumeGUIDPath) 112 | 113 | if err != nil { 114 | return "", NewWindowsError("GetVolumeNameForVolumeMountPoint", err) 115 | } 116 | return syscall.UTF16ToString(volumeName), nil 117 | } 118 | -------------------------------------------------------------------------------- /window.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gowin32 18 | 19 | import ( 20 | "syscall" 21 | 22 | "github.com/winlabs/gowin32/wrappers" 23 | ) 24 | 25 | func EnumDesktops(winsta syscall.Handle) ([]string, error) { 26 | result := make([]string, 0) 27 | callback := func(name *uint16, lparam uintptr) bool { 28 | result = append(result, LpstrToString(name)) 29 | return true 30 | } 31 | if err := wrappers.EnumDesktops(winsta, callback, 0); err != nil { 32 | return result, NewWindowsError("EnumDesktops", err) 33 | } 34 | return result, nil 35 | } 36 | 37 | func GetWindowProcessID(hwnd syscall.Handle) (uint, error) { 38 | var pid uint32 39 | _, err := wrappers.GetWindowThreadProcessId(hwnd, &pid) 40 | if err != nil { 41 | return 0, NewWindowsError("GetWindowThreadProcessId", err) 42 | } 43 | return uint(pid), nil 44 | } 45 | 46 | func GetWindowText(hwnd syscall.Handle) (string, error) { 47 | l, err := wrappers.GetWindowTextLength(hwnd) 48 | if err != nil { 49 | return "", NewWindowsError("GetWindowTextLength", err) 50 | } 51 | if l == 0 { 52 | return "", nil 53 | } 54 | buf := make([]uint16, l+1) 55 | if _, err := wrappers.GetWindowText(hwnd, &buf[0], l+1); err != nil { 56 | return "", NewWindowsError("GetWindowText", err) 57 | } 58 | return syscall.UTF16ToString(buf), nil 59 | } 60 | 61 | func GetWindowThreadID(hwnd syscall.Handle) (uint, error) { 62 | var pid uint32 63 | r, err := wrappers.GetWindowThreadProcessId(hwnd, &pid) 64 | if err != nil { 65 | return 0, NewWindowsError("GetWindowThreadProcessId", err) 66 | } 67 | return uint(r), nil 68 | } 69 | -------------------------------------------------------------------------------- /wrappers/accctrl.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | SE_UNKNOWN_OBJECT_TYPE = 0 21 | SE_FILE_OBJECT = 1 22 | SE_SERVICE = 2 23 | SE_PRINTER = 3 24 | SE_REGISTRY_KEY = 4 25 | SE_LMSHARE = 5 26 | SE_KERNEL_OBJECT = 6 27 | SE_WINDOW_OBJECT = 7 28 | SE_DS_OBJECT = 8 29 | SE_DS_OBJECT_ALL = 9 30 | SE_PROVIDER_DEFINED_OBJECT = 10 31 | SE_WMIGUID_OBJECT = 11 32 | SE_REGISTRY_WOW64_32KEY = 12 33 | ) 34 | 35 | const ( 36 | TRUSTEE_IS_UNKNOWN = 0 37 | TRUSTEE_IS_USER = 1 38 | TRUSTEE_IS_GROUP = 2 39 | TRUSTEE_IS_DOMAIN = 3 40 | TRUSTEE_IS_ALIAS = 4 41 | TRUSTEE_IS_WELL_KNOWN_GROUP = 5 42 | TRUSTEE_IS_DELETED = 6 43 | TRUSTEE_IS_INVALID = 7 44 | TRUSTEE_IS_COMPUTER = 8 45 | ) 46 | 47 | const ( 48 | TRUSTEE_IS_SID = 0 49 | TRUSTEE_IS_NAME = 1 50 | TRUSTEE_BAD_FORM = 2 51 | TRUSTEE_IS_OBJECTS_AND_SID = 3 52 | TRUSTEE_IS_OBJECTS_AND_NAME = 4 53 | ) 54 | 55 | const ( 56 | NO_MULTIPLE_TRUSTEE = 0 57 | TRUSTEE_IS_IMPERSONATE = 1 58 | ) 59 | 60 | type OBJECTS_AND_SID struct { 61 | ObjectsPresent uint32 62 | ObjectTypeGuid GUID 63 | InheritedObjectTypeGuid GUID 64 | Sid *SID 65 | } 66 | 67 | type OBJECTS_AND_NAME struct { 68 | ObjectsPresent uint32 69 | ObjectType int32 70 | ObjectTypeName *uint16 71 | InheritedObjectTypeName *uint16 72 | Name *uint16 73 | } 74 | 75 | type TRUSTEE struct { 76 | MultipleTrustee *TRUSTEE 77 | MultipleTrusteeOperation int32 78 | TrusteeForm int32 79 | TrusteeType int32 80 | Name *uint16 81 | } 82 | 83 | const ( 84 | NOT_USED_ACCESS = 0 85 | GRANT_ACCESS = 1 86 | SET_ACCESS = 2 87 | DENY_ACCESS = 3 88 | REVOKE_ACCESS = 4 89 | SET_AUDIT_SUCCESS = 5 90 | SET_AUDIT_FAILURE = 6 91 | ) 92 | 93 | const ( 94 | NO_INHERITANCE = 0x0 95 | SUB_OBJECTS_ONLY_INHERIT = 0x1 96 | SUB_CONTAINERS_ONLY_INHERIT = 0x2 97 | SUB_CONTAINERS_AND_OBJECTS_INHERIT = 0x3 98 | INHERIT_NO_PROPAGATE = 0x4 99 | INHERIT_ONLY = 0x8 100 | ) 101 | 102 | type EXPLICIT_ACCESS struct { 103 | AccessPermissions uint32 104 | AccessMode int32 105 | Inheritance uint32 106 | Trustee TRUSTEE 107 | } 108 | -------------------------------------------------------------------------------- /wrappers/aclapi.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | var ( 25 | procSetEntriesInAclW = modadvapi32.NewProc("SetEntriesInAclW") 26 | ) 27 | 28 | func SetEntriesInAcl(countOfExplicitEntries uint32, listOfExplicitEntries *EXPLICIT_ACCESS, oldAcl *ACL, newAcl **ACL) error { 29 | r1, _, _ := syscall.Syscall6( 30 | procSetEntriesInAclW.Addr(), 31 | 4, 32 | uintptr(countOfExplicitEntries), 33 | uintptr(unsafe.Pointer(listOfExplicitEntries)), 34 | uintptr(unsafe.Pointer(oldAcl)), 35 | uintptr(unsafe.Pointer(newAcl)), 36 | 0, 37 | 0) 38 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 39 | return err 40 | } 41 | return nil 42 | } 43 | -------------------------------------------------------------------------------- /wrappers/adserr.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | E_ADS_BAD_PATHNAME = 0x80005000 21 | E_ADS_INVALID_DOMAIN_OBJECT = 0x80005001 22 | E_ADS_INVALID_USER_OBJECT = 0x80005002 23 | E_ADS_INVALID_COMPUTER_OBJECT = 0x80005003 24 | E_ADS_INVALID_OBJECT = 0x80005004 25 | E_ADS_PROPERTY_NOT_SET = 0x80005005 26 | E_ADS_PROPERTY_NOT_SUPPORTED = 0x80005006 27 | E_ADS_PROPERTY_INVALID = 0x80005007 28 | E_ADS_BAD_PARAMETER = 0x80005008 29 | E_ADS_OBJECT_UNBOUND = 0x80005009 30 | E_ADS_PROPERTY_NOT_MODIFIED = 0x8000500A 31 | E_ADS_PROPERTY_MODIFIED = 0x8000500B 32 | E_ADS_CANT_CONVERT_DATATYPE = 0x8000500C 33 | E_ADS_PROPERTY_NOT_FOUND = 0x8000500D 34 | E_ADS_OBJECT_EXISTS = 0x8000500E 35 | E_ADS_SCHEMA_VIOLATION = 0x8000500F 36 | E_ADS_COLUMN_NOT_SET = 0x80005010 37 | S_ADS_ERRORSOCCURRED = 0x00005011 38 | S_ADS_NOMORE_ROWS = 0x00005012 39 | S_ADS_NOMORE_COLUMNS = 0x00005013 40 | E_ADS_INVALID_FILTER = 0x80005014 41 | ) 42 | -------------------------------------------------------------------------------- /wrappers/guiddef.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | type GUID struct { 20 | Data1 uint32 21 | Data2 uint16 22 | Data3 uint16 23 | Data4 [8]byte 24 | } 25 | -------------------------------------------------------------------------------- /wrappers/icftypes.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | NET_FW_PROFILE_DOMAIN = 0 21 | NET_FW_PROFILE_STANDARD = 1 22 | NET_FW_PROFILE_CURRENT = 2 23 | NET_FW_PROFILE_TYPE_MAX = 3 24 | ) 25 | 26 | const ( 27 | NET_FW_IP_VERSION_V4 = 0 28 | NET_FW_IP_VERSION_V6 = 1 29 | NET_FW_IP_VERSION_ANY = 2 30 | NET_FW_IP_VERSION_MAX = 3 31 | ) 32 | 33 | const ( 34 | NET_FW_PROTOCOL_TCP = 6 35 | NET_FW_PROTOCOL_UDP = 17 36 | NET_FW_PROTOCOL_ANY = 256 37 | ) 38 | 39 | const ( 40 | NET_FW_RULE_DIR_IN = 1 41 | NET_FW_RULE_DIR_OUT = 2 42 | NET_FW_RULE_DIR_MAX = 3 43 | ) 44 | 45 | const ( 46 | NET_FW_ACTION_BLOCK = 0 47 | NET_FW_ACTION_ALLOW = 1 48 | NET_FW_ACTION_MAX = 2 49 | ) 50 | -------------------------------------------------------------------------------- /wrappers/iphlpapi.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | var ( 25 | modiphlpapi = syscall.NewLazyDLL("iphlpapi.dll") 26 | 27 | procGetTcpTable = modiphlpapi.NewProc("GetTcpTable") 28 | procSendARP = modiphlpapi.NewProc("SendARP") 29 | ) 30 | 31 | func GetTcpTable(tcpTable *MIB_TCPTABLE, size *uint32, order bool) error { 32 | r1, _, _ := syscall.Syscall( 33 | procGetTcpTable.Addr(), 34 | 3, 35 | uintptr(unsafe.Pointer(tcpTable)), 36 | uintptr(unsafe.Pointer(size)), 37 | boolToUintptr(order)) 38 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 39 | return err 40 | } 41 | return nil 42 | } 43 | 44 | func SendARP(destIP, srcIP uint32, macAddr, macAddrLen *uint32) error { 45 | r1, _, _ := syscall.Syscall6( 46 | procSendARP.Addr(), 47 | 4, 48 | uintptr(destIP), 49 | uintptr(srcIP), 50 | uintptr(unsafe.Pointer(macAddr)), 51 | uintptr(unsafe.Pointer(macAddrLen)), 52 | 0, 53 | 0) 54 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 55 | return err 56 | } 57 | return nil 58 | } 59 | -------------------------------------------------------------------------------- /wrappers/ntdsapi.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const ( 25 | DS_SPN_DNS_HOST = 0 26 | DS_SPN_DN_HOST = 1 27 | DS_SPN_NB_HOST = 2 28 | DS_SPN_DOMAIN = 3 29 | DS_SPN_NB_DOMAIN = 4 30 | DS_SPN_SERVICE = 5 31 | ) 32 | 33 | const ( 34 | DS_SPN_ADD_SPN_OP = 0 35 | DS_SPN_REPLACE_SPN_OP = 1 36 | DS_SPN_DELETE_SPN_OP = 2 37 | ) 38 | 39 | var ( 40 | modntdsapi = syscall.NewLazyDLL("ntdsapi.dll") 41 | 42 | procDsBindW = modntdsapi.NewProc("DsBindW") 43 | procDsFreeSpnArrayW = modntdsapi.NewProc("DsFreeSpnArrayW") 44 | procDsGetSpnW = modntdsapi.NewProc("DsGetSpnW") 45 | procDsMakeSpnW = modntdsapi.NewProc("DsMakeSpnW") 46 | procDsServerRegisterSpnW = modntdsapi.NewProc("DsServerRegisterSpnW") 47 | procDsUnBindW = modntdsapi.NewProc("DsUnBindW") 48 | procDsWriteAccountSpnW = modntdsapi.NewProc("DsWriteAccountSpnW") 49 | ) 50 | 51 | func DsBind(domainControllerName *uint16, dnsDomainName *uint16, hDS *syscall.Handle) error { 52 | r1, _, _ := syscall.Syscall( 53 | procDsBindW.Addr(), 54 | 3, 55 | uintptr(unsafe.Pointer(domainControllerName)), 56 | uintptr(unsafe.Pointer(dnsDomainName)), 57 | uintptr(unsafe.Pointer(hDS))) 58 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 59 | return err 60 | } 61 | return nil 62 | } 63 | 64 | func DsFreeSpnArray(cSpn uint32, spn **uint16) { 65 | syscall.Syscall( 66 | procDsFreeSpnArrayW.Addr(), 67 | 2, 68 | uintptr(cSpn), 69 | uintptr(unsafe.Pointer(spn)), 70 | 0) 71 | } 72 | 73 | func DsGetSpn(serviceType int32, serviceClass *uint16, serviceName *uint16, instancePort uint16, cInstanceNames uint16, instanceNames **uint16, instancePorts *uint16, cSpn *uint32, spn ***uint16) error { 74 | r1, _, _ := syscall.Syscall9( 75 | procDsGetSpnW.Addr(), 76 | 9, 77 | uintptr(serviceType), 78 | uintptr(unsafe.Pointer(serviceClass)), 79 | uintptr(unsafe.Pointer(serviceName)), 80 | uintptr(instancePort), 81 | uintptr(cInstanceNames), 82 | uintptr(unsafe.Pointer(instanceNames)), 83 | uintptr(unsafe.Pointer(instancePorts)), 84 | uintptr(unsafe.Pointer(cSpn)), 85 | uintptr(unsafe.Pointer(spn))) 86 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 87 | return err 88 | } 89 | return nil 90 | } 91 | 92 | func DsMakeSpn(serviceClass *uint16, serviceName *uint16, instanceName *uint16, instancePort uint16, referrer *uint16, spnLength *uint32, spn *uint16) error { 93 | r1, _, _ := syscall.Syscall9( 94 | procDsMakeSpnW.Addr(), 95 | 7, 96 | uintptr(unsafe.Pointer(serviceClass)), 97 | uintptr(unsafe.Pointer(serviceName)), 98 | uintptr(unsafe.Pointer(instanceName)), 99 | uintptr(instancePort), 100 | uintptr(unsafe.Pointer(referrer)), 101 | uintptr(unsafe.Pointer(spnLength)), 102 | uintptr(unsafe.Pointer(spn)), 103 | 0, 104 | 0) 105 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 106 | return err 107 | } 108 | return nil 109 | } 110 | 111 | func DsServerRegisterSpn(operation int32, serviceClass *uint16, userObjectDN *uint16) error { 112 | r1, _, _ := syscall.Syscall( 113 | procDsServerRegisterSpnW.Addr(), 114 | 3, 115 | uintptr(operation), 116 | uintptr(unsafe.Pointer(serviceClass)), 117 | uintptr(unsafe.Pointer(userObjectDN))) 118 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 119 | return err 120 | } 121 | return nil 122 | } 123 | 124 | func DsUnBind(hDS *syscall.Handle) error { 125 | r1, _, _ := syscall.Syscall( 126 | procDsUnBindW.Addr(), 127 | 1, 128 | uintptr(unsafe.Pointer(hDS)), 129 | 0, 130 | 0) 131 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 132 | return err 133 | } 134 | return nil 135 | } 136 | 137 | func DsWriteAccountSpn(hDS syscall.Handle, operation int32, account *uint16, cSpn uint32, spn *uint16) error { 138 | r1, _, _ := syscall.Syscall6( 139 | procDsWriteAccountSpnW.Addr(), 140 | 5, 141 | uintptr(hDS), 142 | uintptr(operation), 143 | uintptr(unsafe.Pointer(account)), 144 | uintptr(cSpn), 145 | uintptr(unsafe.Pointer(spn)), 146 | 0) 147 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 148 | return err 149 | } 150 | return nil 151 | } 152 | -------------------------------------------------------------------------------- /wrappers/ntifs.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | SYMLINK_FLAG_RELATIVE = 0x00000001 21 | ) 22 | 23 | type REPARSE_DATA_BUFFER struct { 24 | ReparseTag uint32 25 | ReparseDataLength uint16 26 | Reserved uint16 27 | SubstituteNameOffset uint16 28 | SubstituteNameLength uint16 29 | PrintNameOffset uint16 30 | PrintNameLength uint16 31 | Flags uint32 32 | //PathBuffer []uint16 33 | } 34 | -------------------------------------------------------------------------------- /wrappers/ntsecapi.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const ( 25 | POLICY_VIEW_LOCAL_INFORMATION = 0x0001 26 | POLICY_VIEW_AUDIT_INFORMATION = 0x0002 27 | POLICY_GET_PRIVATE_INFORMATION = 0x0004 28 | POLICY_TRUST_ADMIN = 0x0008 29 | POLICY_CREATE_ACCOUNT = 0x0010 30 | POLICY_CREATE_SECRET = 0x0020 31 | POLICY_CREATE_PRIVILEGE = 0x0040 32 | POLICY_SET_DEFAULT_QUOTA_LIMITS = 0x0080 33 | POLICY_SET_AUDIT_REQUIREMENTS = 0x0100 34 | POLICY_AUDIT_LOG_ADMIN = 0x0200 35 | POLICY_SERVER_ADMIN = 0x0400 36 | POLICY_LOOKUP_NAMES = 0x0800 37 | POLICY_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | POLICY_VIEW_LOCAL_INFORMATION | POLICY_VIEW_AUDIT_INFORMATION | POLICY_GET_PRIVATE_INFORMATION | POLICY_TRUST_ADMIN | POLICY_CREATE_ACCOUNT | POLICY_CREATE_SECRET | POLICY_CREATE_PRIVILEGE | POLICY_SET_DEFAULT_QUOTA_LIMITS | POLICY_SET_AUDIT_REQUIREMENTS | POLICY_AUDIT_LOG_ADMIN | POLICY_SERVER_ADMIN | POLICY_LOOKUP_NAMES 38 | ) 39 | 40 | const ( 41 | SE_INTERACTIVE_LOGON_NAME = "SeInteractiveLogonRight" 42 | SE_NETWORK_LOGON_NAME = "SeNetworkLogonRight" 43 | SE_BATCH_LOGON_NAME = "SeBatchLogonRight" 44 | SE_SERVICE_LOGON_NAME = "SeServiceLogonRight" 45 | SE_DENY_INTERACTIVE_LOGON_NAME = "SeDenyInteractiveLogonRight" 46 | SE_DENY_NETWORK_LOGON_NAME = "SeDenyNetworkLogonRight" 47 | SE_DENY_BATCH_LOGON_NAME = "SeDenyBatchLogonRight" 48 | SE_DENY_SERVICE_LOGON_NAME = "SeDenyServiceLogonRight" 49 | SE_REMOTE_INTERACTIVE_LOGON_NAME = "SeRemoteInteractiveLogonRight" 50 | SE_DENY_REMOTE_INTERACTIVE_LOGON_NAME = "SeDenyRemoteInteractiveLogonRight" 51 | ) 52 | 53 | var ( 54 | procLsaAddAccountRights = modadvapi32.NewProc("LsaAddAccountRights") 55 | procLsaClose = modadvapi32.NewProc("LsaClose") 56 | procLsaEnumerateAccountRights = modadvapi32.NewProc("LsaEnumerateAccountRights") 57 | procLsaFreeMemory = modadvapi32.NewProc("LsaFreeMemory") 58 | procLsaNtStatusToWinError = modadvapi32.NewProc("LsaNtStatusToWinError") 59 | procLsaOpenPolicy = modadvapi32.NewProc("LsaOpenPolicy") 60 | procLsaRemoveAccountRights = modadvapi32.NewProc("LsaRemoveAccountRights") 61 | ) 62 | 63 | func LsaAddAccountRights(policyHandle syscall.Handle, accountSid *SID, userRights *UNICODE_STRING, countOfRights uint32) uint32 { 64 | r1, _, _ := syscall.Syscall6( 65 | procLsaAddAccountRights.Addr(), 66 | 4, 67 | uintptr(policyHandle), 68 | uintptr(unsafe.Pointer(accountSid)), 69 | uintptr(unsafe.Pointer(userRights)), 70 | uintptr(countOfRights), 71 | 0, 72 | 0) 73 | return uint32(r1) 74 | } 75 | 76 | func LsaClose(objectHandle syscall.Handle) uint32 { 77 | r1, _, _ := syscall.Syscall(procLsaClose.Addr(), 1, uintptr(objectHandle), 0, 0) 78 | return uint32(r1) 79 | } 80 | 81 | func LsaEnumerateAccountRights(policyHandle syscall.Handle, accountSid *SID, userRights **UNICODE_STRING, countOfRights *uint32) uint32 { 82 | r1, _, _ := syscall.Syscall6( 83 | procLsaEnumerateAccountRights.Addr(), 84 | 4, 85 | uintptr(policyHandle), 86 | uintptr(unsafe.Pointer(accountSid)), 87 | uintptr(unsafe.Pointer(userRights)), 88 | uintptr(unsafe.Pointer(countOfRights)), 89 | 0, 90 | 0) 91 | return uint32(r1) 92 | } 93 | 94 | func LsaFreeMemory(buffer *byte) uint32 { 95 | r1, _, _ := syscall.Syscall(procLsaFreeMemory.Addr(), 1, uintptr(unsafe.Pointer(buffer)), 0, 0) 96 | return uint32(r1) 97 | } 98 | 99 | func LsaNtStatusToWinError(status uint32) error { 100 | r1, _, _ := syscall.Syscall(procLsaNtStatusToWinError.Addr(), 1, uintptr(status), 0, 0) 101 | err := syscall.Errno(r1) 102 | if err != ERROR_SUCCESS { 103 | return err 104 | } 105 | return nil 106 | } 107 | 108 | func LsaOpenPolicy(systemName *UNICODE_STRING, objectAttributes *OBJECT_ATTRIBUTES, desiredAccess uint32, policyHandle *syscall.Handle) uint32 { 109 | r1, _, _ := syscall.Syscall6( 110 | procLsaOpenPolicy.Addr(), 111 | 4, 112 | uintptr(unsafe.Pointer(systemName)), 113 | uintptr(unsafe.Pointer(objectAttributes)), 114 | uintptr(desiredAccess), 115 | uintptr(unsafe.Pointer(policyHandle)), 116 | 0, 117 | 0) 118 | return uint32(r1) 119 | } 120 | 121 | func LsaRemoveAccountRights(policyHandle syscall.Handle, accountSid *SID, allRights bool, userRights *UNICODE_STRING, countOfRights uint32) uint32 { 122 | var allRightsRaw uint8 123 | if allRights { 124 | allRightsRaw = 1 125 | } else { 126 | allRightsRaw = 0 127 | } 128 | r1, _, _ := syscall.Syscall6( 129 | procLsaRemoveAccountRights.Addr(), 130 | 5, 131 | uintptr(policyHandle), 132 | uintptr(unsafe.Pointer(accountSid)), 133 | uintptr(allRightsRaw), 134 | uintptr(unsafe.Pointer(userRights)), 135 | uintptr(countOfRights), 136 | 0) 137 | return uint32(r1) 138 | } 139 | -------------------------------------------------------------------------------- /wrappers/oaidl.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | type VARIANT struct { 25 | Vt uint16 26 | Reserved1 uint16 27 | Reserved2 uint16 28 | Reserved3 uint16 29 | Val [variantDataBytes/8]uint64 30 | } 31 | 32 | var ( 33 | IID_IDispatch = GUID{0x0020400, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} 34 | IID_IEnumVARIANT = GUID{0x0020404, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} 35 | ) 36 | 37 | type IDispatchVtbl struct { 38 | IUnknownVtbl 39 | GetTypeInfoCount uintptr 40 | GetTypeInfo uintptr 41 | GetIDsOfNames uintptr 42 | Invoke uintptr 43 | } 44 | 45 | type IDispatch struct { 46 | IUnknown 47 | } 48 | 49 | type IEnumVARIANTVtbl struct { 50 | IUnknownVtbl 51 | Next uintptr 52 | Skip uintptr 53 | Reset uintptr 54 | Clone uintptr 55 | } 56 | 57 | type IEnumVARIANT struct { 58 | IUnknown 59 | } 60 | 61 | func (self *IEnumVARIANT) Next(celt uint32, rgVar *VARIANT, celtFetched *uint32) uint32 { 62 | vtbl := (*IEnumVARIANTVtbl)(unsafe.Pointer(self.Vtbl)) 63 | r1, _, _ := syscall.Syscall6( 64 | vtbl.Next, 65 | 4, 66 | uintptr(unsafe.Pointer(self)), 67 | uintptr(celt), 68 | uintptr(unsafe.Pointer(rgVar)), 69 | uintptr(unsafe.Pointer(celtFetched)), 70 | 0, 71 | 0) 72 | return uint32(r1) 73 | } 74 | 75 | func (self *IEnumVARIANT) Skip(celt uint32) uint32 { 76 | vtbl := (*IEnumVARIANTVtbl)(unsafe.Pointer(self.Vtbl)) 77 | r1, _, _ := syscall.Syscall( 78 | vtbl.Skip, 79 | 2, 80 | uintptr(unsafe.Pointer(self)), 81 | uintptr(celt), 82 | 0) 83 | return uint32(r1) 84 | } 85 | 86 | func (self *IEnumVARIANT) Reset() uint32 { 87 | vtbl := (*IEnumVARIANTVtbl)(unsafe.Pointer(self.Vtbl)) 88 | r1, _, _ := syscall.Syscall( 89 | vtbl.Reset, 90 | 1, 91 | uintptr(unsafe.Pointer(self)), 92 | 0, 93 | 0) 94 | return uint32(r1) 95 | } 96 | 97 | func (self *IEnumVARIANT) Clone(ppEnum *IEnumVARIANT) uint32 { 98 | vtbl := (*IEnumVARIANTVtbl)(unsafe.Pointer(self.Vtbl)) 99 | r1, _, _ := syscall.Syscall( 100 | vtbl.Clone, 101 | 2, 102 | uintptr(unsafe.Pointer(self)), 103 | uintptr(unsafe.Pointer(ppEnum)), 104 | 0) 105 | return uint32(r1) 106 | } 107 | -------------------------------------------------------------------------------- /wrappers/oaidl_386.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build 386 18 | 19 | package wrappers 20 | 21 | const variantDataBytes = 8 22 | -------------------------------------------------------------------------------- /wrappers/oaidl_amd64.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build amd64 18 | 19 | package wrappers 20 | 21 | const variantDataBytes = 16 22 | -------------------------------------------------------------------------------- /wrappers/oaidl_arm.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build arm 18 | 19 | package wrappers 20 | 21 | const variantDataBytes = 8 22 | -------------------------------------------------------------------------------- /wrappers/oaidl_arm64.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build arm64 18 | 19 | package wrappers 20 | 21 | const variantDataBytes = 16 22 | -------------------------------------------------------------------------------- /wrappers/objbase.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const ( 25 | COINIT_APARTMENTTHREADED = 0x00000002 26 | COINIT_MULTITHREADED = 0x00000000 27 | COINIT_DISABLE_OLE1DDE = 0x00000004 28 | COINIT_SPEED_OVER_MEMORY = 0x00000008 29 | ) 30 | 31 | var ( 32 | modole32 = syscall.NewLazyDLL("ole32.dll") 33 | 34 | procCoCreateInstance = modole32.NewProc("CoCreateInstance") 35 | procCoInitializeEx = modole32.NewProc("CoInitializeEx") 36 | procCoTaskMemFree = modole32.NewProc("CoTaskMemFree") 37 | procCoUninitialize = modole32.NewProc("CoUninitialize") 38 | ) 39 | 40 | func CoCreateInstance(clsid *GUID, outer *IUnknown, clsContext uint32, iid *GUID, object *uintptr) uint32 { 41 | r1, _, _ := syscall.Syscall6( 42 | procCoCreateInstance.Addr(), 43 | 5, 44 | uintptr(unsafe.Pointer(clsid)), 45 | uintptr(unsafe.Pointer(outer)), 46 | uintptr(clsContext), 47 | uintptr(unsafe.Pointer(iid)), 48 | uintptr(unsafe.Pointer(object)), 49 | 0) 50 | return uint32(r1) 51 | } 52 | 53 | func CoInitializeEx(reserved *byte, flags uint32) uint32 { 54 | r1, _, _ := syscall.Syscall( 55 | procCoInitializeEx.Addr(), 56 | 2, 57 | uintptr(unsafe.Pointer(reserved)), 58 | uintptr(flags), 59 | 0) 60 | return uint32(r1) 61 | } 62 | 63 | func CoTaskMemFree(mem *byte) { 64 | syscall.Syscall(procCoTaskMemFree.Addr(), 1, uintptr(unsafe.Pointer(mem)), 0, 0) 65 | } 66 | 67 | func CoUninitialize() { 68 | syscall.Syscall(procCoUninitialize.Addr(), 0, 0, 0, 0) 69 | } 70 | -------------------------------------------------------------------------------- /wrappers/oleauto.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const ( 25 | VARIANT_NOVALUEPROP = 0x0001 26 | VARIANT_ALPHABOOL = 0x0002 27 | VARIANT_NOUSEROVERRIDE = 0x0004 28 | VARIANT_LOCALBOOL = 0x0010 29 | ) 30 | 31 | var ( 32 | modoleaut32 = syscall.NewLazyDLL("oleaut32.dll") 33 | 34 | procSysAllocString = modoleaut32.NewProc("SysAllocString") 35 | procSysFreeString = modoleaut32.NewProc("SysFreeString") 36 | procSysStringLen = modoleaut32.NewProc("SysStringLen") 37 | procVariantChangeType = modoleaut32.NewProc("VariantChangeType") 38 | procVariantClear = modoleaut32.NewProc("VariantClear") 39 | procVariantInit = modoleaut32.NewProc("VariantInit") 40 | ) 41 | 42 | func SysAllocString(psz *uint16) *uint16 { 43 | r1, _, _ := syscall.Syscall(procSysAllocString.Addr(), 1, uintptr(unsafe.Pointer(psz)), 0, 0) 44 | return (*uint16)(unsafe.Pointer(r1)) 45 | } 46 | 47 | func SysFreeString(bstrString *uint16) { 48 | syscall.Syscall(procSysFreeString.Addr(), 1, uintptr(unsafe.Pointer(bstrString)), 0, 0) 49 | } 50 | 51 | func SysStringLen(bstr *uint16) uint32 { 52 | r1, _, _ := syscall.Syscall(procSysStringLen.Addr(), 1, uintptr(unsafe.Pointer(bstr)), 0, 0) 53 | return uint32(r1) 54 | } 55 | 56 | func VariantChangeType(dest *VARIANT, src *VARIANT, flags uint16, vt uint16) uint32 { 57 | r1, _, _ := syscall.Syscall6( 58 | procVariantChangeType.Addr(), 59 | 4, 60 | uintptr(unsafe.Pointer(dest)), 61 | uintptr(unsafe.Pointer(src)), 62 | uintptr(flags), 63 | uintptr(vt), 64 | 0, 65 | 0) 66 | return uint32(r1) 67 | } 68 | 69 | func VariantClear(variant *VARIANT) uint32 { 70 | r1, _, _ := syscall.Syscall(procVariantClear.Addr(), 1, uintptr(unsafe.Pointer(variant)), 0, 0) 71 | return uint32(r1) 72 | } 73 | 74 | func VariantInit(variant *VARIANT) { 75 | syscall.Syscall(procVariantInit.Addr(), 1, uintptr(unsafe.Pointer(variant)), 0, 0) 76 | } 77 | -------------------------------------------------------------------------------- /wrappers/reason.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2019 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | SHTDN_REASON_FLAG_USER_DEFINED = 0x40000000 21 | SHTDN_REASON_FLAG_PLANNED = 0x80000000 22 | ) 23 | 24 | const ( 25 | SHTDN_REASON_MAJOR_OTHER = 0x00000000 26 | SHTDN_REASON_MAJOR_HARDWARE = 0x00010000 27 | SHTDN_REASON_MAJOR_OPERATINGSYSTEM = 0x00020000 28 | SHTDN_REASON_MAJOR_SOFTWARE = 0x00030000 29 | SHTDN_REASON_MAJOR_APPLICATION = 0x00040000 30 | SHTDN_REASON_MAJOR_SYSTEM = 0x00050000 31 | SHTDN_REASON_MAJOR_POWER = 0x00060000 32 | SHTDN_REASON_MAJOR_LEGACY_API = 0x00070000 33 | ) 34 | 35 | const ( 36 | SHTDN_REASON_MINOR_OTHER = 0x00000000 37 | SHTDN_REASON_MINOR_MAINTENANCE = 0x00000001 38 | SHTDN_REASON_MINOR_INSTALLATION = 0x00000002 39 | SHTDN_REASON_MINOR_UPGRADE = 0x00000003 40 | SHTDN_REASON_MINOR_RECONFIG = 0x00000004 41 | SHTDN_REASON_MINOR_HUNG = 0x00000005 42 | SHTDN_REASON_MINOR_UNSTABLE = 0x00000006 43 | SHTDN_REASON_MINOR_DISK = 0x00000007 44 | SHTDN_REASON_MINOR_PROCESSOR = 0x00000008 45 | SHTDN_REASON_MINOR_NETWORKCARD = 0x00000009 46 | SHTDN_REASON_MINOR_POWER_SUPPLY = 0x0000000a 47 | SHTDN_REASON_MINOR_CORDUNPLUGGED = 0x0000000b 48 | SHTDN_REASON_MINOR_ENVIRONMENT = 0x0000000c 49 | SHTDN_REASON_MINOR_HARDWARE_DRIVER = 0x0000000d 50 | SHTDN_REASON_MINOR_OTHERDRIVER = 0x0000000e 51 | SHTDN_REASON_MINOR_BLUESCREEN = 0x0000000F 52 | SHTDN_REASON_MINOR_SERVICEPACK = 0x00000010 53 | SHTDN_REASON_MINOR_HOTFIX = 0x00000011 54 | SHTDN_REASON_MINOR_SECURITYFIX = 0x00000012 55 | SHTDN_REASON_MINOR_SECURITY = 0x00000013 56 | SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY = 0x00000014 57 | SHTDN_REASON_MINOR_WMI = 0x00000015 58 | SHTDN_REASON_MINOR_SERVICEPACK_UNINSTALL = 0x00000016 59 | SHTDN_REASON_MINOR_HOTFIX_UNINSTALL = 0x00000017 60 | SHTDN_REASON_MINOR_SECURITYFIX_UNINSTALL = 0x00000018 61 | SHTDN_REASON_MINOR_MMC = 0x00000019 62 | SHTDN_REASON_MINOR_TERMSRV = 0x00000020 63 | ) 64 | -------------------------------------------------------------------------------- /wrappers/sddl.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | var ( 25 | procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW") 26 | ) 27 | 28 | func ConvertSidToStringSid(sid *SID, stringSid **uint16) error { 29 | r1, _, e1 := syscall.Syscall( 30 | procConvertSidToStringSidW.Addr(), 31 | 2, 32 | uintptr(unsafe.Pointer(sid)), 33 | uintptr(unsafe.Pointer(stringSid)), 34 | 0) 35 | if r1 == 0 { 36 | if e1 != ERROR_SUCCESS { 37 | return e1 38 | } else { 39 | return syscall.EINVAL 40 | } 41 | } 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /wrappers/shellapi.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const ( 25 | FO_MOVE = 0x0001 26 | FO_COPY = 0x0002 27 | FO_DELETE = 0x0003 28 | FO_RENAME = 0x0004 29 | ) 30 | 31 | const ( 32 | FOF_MULTIDESTFILES = 0x0001 33 | FOF_CONFIRMMOUSE = 0x0002 34 | FOF_SILENT = 0x0004 35 | FOF_RENAMEONCOLLISION = 0x0008 36 | FOF_NOCONFIRMATION = 0x0010 37 | FOF_WANTMAPPINGHANDLE = 0x0020 38 | FOF_ALLOWUNDO = 0x0040 39 | FOF_FILESONLY = 0x0080 40 | FOF_SIMPLEPROGRESS = 0x0100 41 | FOF_NOCONFIRMMKDIR = 0x0200 42 | FOF_NOERRORUI = 0x0400 43 | FOF_NOCOPYSECURITYATTRIBS = 0x0800 44 | FOF_NORECURSION = 0x1000 45 | FOF_NO_CONNECTED_ELEMENTS = 0x2000 46 | FOF_WANTNUKEWARNING = 0x4000 47 | FOF_NORECURSEREPARSE = 0x8000 48 | FOF_NO_UI = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR 49 | ) 50 | 51 | type SHFILEOPSTRUCT struct { 52 | Hwnd syscall.Handle 53 | Func uint32 54 | From *uint16 55 | To *uint16 56 | Flags uint16 57 | AnyOperationsAborted int32 58 | NameMappings *byte 59 | ProgressTitle *uint16 60 | } 61 | 62 | var ( 63 | modshell32 = syscall.NewLazyDLL("shell32.dll") 64 | 65 | procCommandLineToArgvW = modshell32.NewProc("CommandLineToArgvW") 66 | procSHFileOperationW = modshell32.NewProc("SHFileOperationW") 67 | ) 68 | 69 | func CommandLineToArgvW(cmdLine *uint16, numArgs *int32) (**uint16, error) { 70 | r1, _, e1 := syscall.Syscall( 71 | procCommandLineToArgvW.Addr(), 72 | 2, 73 | uintptr(unsafe.Pointer(cmdLine)), 74 | uintptr(unsafe.Pointer(numArgs)), 75 | 0) 76 | if r1 == 0 { 77 | if e1 != ERROR_SUCCESS { 78 | return nil, e1 79 | } else { 80 | return nil, syscall.EINVAL 81 | } 82 | } 83 | return (**uint16)(unsafe.Pointer(r1)), nil 84 | } 85 | 86 | func SHFileOperation(fileOp *SHFILEOPSTRUCT) error { 87 | r1, _, _ := syscall.Syscall(procSHFileOperationW.Addr(), 1, uintptr(unsafe.Pointer(fileOp)), 0, 0) 88 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 89 | return err 90 | } 91 | return nil 92 | } 93 | -------------------------------------------------------------------------------- /wrappers/shlobj.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const ( 25 | CSIDL_DESKTOP = 0x0000 26 | CSIDL_INTERNET = 0x0001 27 | CSIDL_PROGRAMS = 0x0002 28 | CSIDL_CONTROLS = 0x0003 29 | CSIDL_PRINTERS = 0x0004 30 | CSIDL_PERSONAL = 0x0005 31 | CSIDL_FAVORITES = 0x0006 32 | CSIDL_STARTUP = 0x0007 33 | CSIDL_RECENT = 0x0008 34 | CSIDL_SENDTO = 0x0009 35 | CSIDL_BITBUCKET = 0x000a 36 | CSIDL_STARTMENU = 0x000b 37 | CSIDL_MYDOCUMENTS = CSIDL_PERSONAL 38 | CSIDL_MYMUSIC = 0x000d 39 | CSIDL_MYVIDEO = 0x000e 40 | CSIDL_DESKTOPDIRECTORY = 0x0010 41 | CSIDL_DRIVES = 0x0011 42 | CSIDL_NETWORK = 0x0012 43 | CSIDL_NETHOOD = 0x0013 44 | CSIDL_FONTS = 0x0014 45 | CSIDL_TEMPLATES = 0x0015 46 | CSIDL_COMMON_STARTMENU = 0x0016 47 | CSIDL_COMMON_PROGRAMS = 0x0017 48 | CSIDL_COMMON_STARTUP = 0x0018 49 | CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019 50 | CSIDL_APPDATA = 0x001a 51 | CSIDL_PRINTHOOD = 0x001b 52 | CSIDL_LOCAL_APPDATA = 0x001c 53 | CSIDL_ALTSTARTUP = 0x001d 54 | CSIDL_COMMON_ALTSTARTUP = 0x001e 55 | CSIDL_COMMON_FAVORITES = 0x001f 56 | CSIDL_INTERNET_CACHE = 0x0020 57 | CSIDL_COOKIES = 0x0021 58 | CSIDL_HISTORY = 0x0022 59 | CSIDL_COMMON_APPDATA = 0x0023 60 | CSIDL_WINDOWS = 0x0024 61 | CSIDL_SYSTEM = 0x0025 62 | CSIDL_PROGRAM_FILES = 0x0026 63 | CSIDL_MYPICTURES = 0x0027 64 | CSIDL_PROFILE = 0x0028 65 | CSIDL_SYSTEMX86 = 0x0029 66 | CSIDL_PROGRAM_FILESX86 = 0x002a 67 | CSIDL_PROGRAM_FILES_COMMON = 0x002b 68 | CSIDL_PROGRAM_FILES_COMMONX86 = 0x002c 69 | CSIDL_COMMON_TEMPLATES = 0x002d 70 | CSIDL_COMMON_DOCUMENTS = 0x002e 71 | CSIDL_COMMON_ADMINTOOLS = 0x002f 72 | CSIDL_ADMINTOOLS = 0x0030 73 | CSIDL_CONNECTIONS = 0x0031 74 | CSIDL_COMMON_MUSIC = 0x0035 75 | CSIDL_COMMON_PICTURES = 0x0036 76 | CSIDL_COMMON_VIDEO = 0x0037 77 | CSIDL_RESOURCES = 0x0038 78 | CSIDL_RESOURCES_LOCALIZED = 0x0039 79 | CSIDL_COMMON_OEM_LINKS = 0x003a 80 | CSIDL_CDBURN_AREA = 0x003b 81 | CSIDL_COMPUTERSNEARME = 0x003d 82 | 83 | CSIDL_FLAG_CREATE = 0x8000 84 | CSIDL_FLAG_DONT_VERIFY = 0x4000 85 | CSIDL_FLAG_UNEXPAND = 0x2000 86 | CSIDL_FLAG_NO_ALIAS = 0x1000 87 | CSIDL_FLAG_PER_USER_INIT = 0x0800 88 | ) 89 | 90 | const ( 91 | SHGFP_TYPE_CURRENT = 0 92 | SHGFP_TYPE_DEFAULT = 1 93 | ) 94 | 95 | const ( 96 | KF_FLAG_CREATE = 0x00008000 97 | KF_FLAG_DONT_VERIFY = 0x00004000 98 | KF_FLAG_DONT_UNEXPAND = 0x00002000 99 | KF_FLAG_NO_ALIAS = 0x00001000 100 | KF_FLAG_INIT = 0x00000800 101 | KF_FLAG_DEFAULT_PATH = 0x00000400 102 | KF_FLAG_NOT_PARENT_RELATIVE = 0x00000200 103 | KF_FLAG_SIMPLE_IDLIST = 0x00000100 104 | KF_FLAG_ALIAS_ONLY = 0x80000000 105 | ) 106 | 107 | var ( 108 | procSHGetFolderPathW = modshell32.NewProc("SHGetFolderPathW") 109 | procSHGetKnownFolderPath = modshell32.NewProc("SHGetKnownFolderPath") 110 | ) 111 | 112 | func SHGetFolderPath(owner syscall.Handle, folder uint32, token syscall.Handle, flags uint32, path *uint16) uint32 { 113 | r1, _, _ := syscall.Syscall6( 114 | procSHGetFolderPathW.Addr(), 115 | 5, 116 | uintptr(owner), 117 | uintptr(folder), 118 | uintptr(token), 119 | uintptr(flags), 120 | uintptr(unsafe.Pointer(path)), 121 | 0) 122 | return uint32(r1) 123 | } 124 | 125 | func SHGetKnownFolderPath(fid *GUID, flags uint32, token syscall.Handle, path **uint16) uint32 { 126 | r1, _, _ := syscall.Syscall6( 127 | procSHGetKnownFolderPath.Addr(), 128 | 4, 129 | uintptr(unsafe.Pointer(fid)), 130 | uintptr(flags), 131 | uintptr(token), 132 | uintptr(unsafe.Pointer(path)), 133 | 0, 134 | 0) 135 | return uint32(r1) 136 | } 137 | -------------------------------------------------------------------------------- /wrappers/tcpmib.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | MIB_TCP_STATE_CLOSED = 1 21 | MIB_TCP_STATE_LISTEN = 2 22 | MIB_TCP_STATE_SYN_SENT = 3 23 | MIB_TCP_STATE_SYN_RCVD = 4 24 | MIB_TCP_STATE_ESTAB = 5 25 | MIB_TCP_STATE_FIN_WAIT1 = 6 26 | MIB_TCP_STATE_FIN_WAIT2 = 7 27 | MIB_TCP_STATE_CLOSE_WAIT = 8 28 | MIB_TCP_STATE_CLOSING = 9 29 | MIB_TCP_STATE_LAST_ACK = 10 30 | MIB_TCP_STATE_TIME_WAIT = 11 31 | MIB_TCP_STATE_DELETE_TCB = 12 32 | ) 33 | 34 | type MIB_TCPROW struct { 35 | State uint32 36 | LocalAddr uint32 37 | LocalPort uint32 38 | RemoteAddr uint32 39 | RemotePort uint32 40 | } 41 | 42 | type MIB_TCPTABLE struct { 43 | NumEntries uint32 44 | //Table []MIB_TCPROW 45 | } 46 | -------------------------------------------------------------------------------- /wrappers/tlhelp32.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const MAX_MODULE_NAME32 = 255 25 | 26 | const ( 27 | TH32CS_SNAPHEAPLIST = 0x00000001 28 | TH32CS_SNAPPROCESS = 0x00000002 29 | TH32CS_SNAPTHREAD = 0x00000004 30 | TH32CS_SNAPMODULE = 0x00000008 31 | TH32CS_SNAPMODULE32 = 0x00000010 32 | TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD | TH32CS_SNAPMODULE 33 | TH32CS_INHERIT = 0x80000000 34 | ) 35 | 36 | type PROCESSENTRY32 struct { 37 | Size uint32 38 | Usage uint32 39 | ProcessID uint32 40 | DefaultHeapID uintptr 41 | ModuleID uint32 42 | Threads uint32 43 | ParentProcessID uint32 44 | PriClassBase int32 45 | Flags uint32 46 | ExeFile [MAX_PATH]uint16 47 | } 48 | 49 | type MODULEENTRY32 struct { 50 | Size uint32 51 | ModuleID uint32 52 | ProcessID uint32 53 | GlblcntUsage uint32 54 | ProccntUsage uint32 55 | ModBaseAddr *byte 56 | ModBaseSize uint32 57 | Module syscall.Handle 58 | ModuleName [MAX_MODULE_NAME32 + 1]uint16 59 | ExePath [MAX_PATH]uint16 60 | } 61 | 62 | var ( 63 | procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot") 64 | procModule32FirstW = modkernel32.NewProc("Module32FirstW") 65 | procModule32NextW = modkernel32.NewProc("Module32NextW") 66 | procProcess32FirstW = modkernel32.NewProc("Process32FirstW") 67 | procProcess32NextW = modkernel32.NewProc("Process32NextW") 68 | ) 69 | 70 | func CreateToolhelp32Snapshot(flags uint32, processID uint32) (syscall.Handle, error) { 71 | r1, _, e1 := syscall.Syscall( 72 | procCreateToolhelp32Snapshot.Addr(), 73 | 2, 74 | uintptr(flags), 75 | uintptr(processID), 76 | 0) 77 | handle := syscall.Handle(r1) 78 | if handle == INVALID_HANDLE_VALUE { 79 | if e1 != ERROR_SUCCESS { 80 | return handle, e1 81 | } else { 82 | return handle, syscall.EINVAL 83 | } 84 | } 85 | return handle, nil 86 | } 87 | 88 | func Module32First(snapshot syscall.Handle, me *MODULEENTRY32) error { 89 | r1, _, e1 := syscall.Syscall( 90 | procModule32FirstW.Addr(), 91 | 2, 92 | uintptr(snapshot), 93 | uintptr(unsafe.Pointer(me)), 94 | 0) 95 | if r1 == 0 { 96 | if e1 != ERROR_SUCCESS { 97 | return e1 98 | } else { 99 | return syscall.EINVAL 100 | } 101 | } 102 | return nil 103 | } 104 | 105 | func Module32Next(snapshot syscall.Handle, me *MODULEENTRY32) error { 106 | r1, _, e1 := syscall.Syscall( 107 | procModule32NextW.Addr(), 108 | 2, 109 | uintptr(snapshot), 110 | uintptr(unsafe.Pointer(me)), 111 | 0) 112 | if r1 == 0 { 113 | if e1 != ERROR_SUCCESS { 114 | return e1 115 | } else { 116 | return syscall.EINVAL 117 | } 118 | } 119 | return nil 120 | } 121 | 122 | func Process32First(snapshot syscall.Handle, pe *PROCESSENTRY32) error { 123 | r1, _, e1 := syscall.Syscall( 124 | procProcess32FirstW.Addr(), 125 | 2, 126 | uintptr(snapshot), 127 | uintptr(unsafe.Pointer(pe)), 128 | 0) 129 | if r1 == 0 { 130 | if e1 != ERROR_SUCCESS { 131 | return e1 132 | } else { 133 | return syscall.EINVAL 134 | } 135 | } 136 | return nil 137 | } 138 | 139 | func Process32Next(snapshot syscall.Handle, pe *PROCESSENTRY32) error { 140 | r1, _, e1 := syscall.Syscall( 141 | procProcess32NextW.Addr(), 142 | 2, 143 | uintptr(snapshot), 144 | uintptr(unsafe.Pointer(pe)), 145 | 0) 146 | if r1 == 0 { 147 | if e1 != ERROR_SUCCESS { 148 | return e1 149 | } else { 150 | return syscall.EINVAL 151 | } 152 | } 153 | return nil 154 | } 155 | -------------------------------------------------------------------------------- /wrappers/unknwn.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | var ( 25 | IID_IUnknown = GUID{0x00000000, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} 26 | ) 27 | 28 | type IUnknownVtbl struct { 29 | QueryInterface uintptr 30 | AddRef uintptr 31 | Release uintptr 32 | } 33 | 34 | type IUnknown struct { 35 | Vtbl *IUnknownVtbl 36 | } 37 | 38 | func (self *IUnknown) QueryInterface(iid *GUID, object *uintptr) uint32 { 39 | r1, _, _ := syscall.Syscall( 40 | self.Vtbl.QueryInterface, 41 | 3, 42 | uintptr(unsafe.Pointer(self)), 43 | uintptr(unsafe.Pointer(iid)), 44 | uintptr(unsafe.Pointer(object))) 45 | return uint32(r1) 46 | } 47 | 48 | func (self *IUnknown) AddRef() uint32 { 49 | r1, _, _ := syscall.Syscall(self.Vtbl.AddRef, 1, uintptr(unsafe.Pointer(self)), 0, 0) 50 | return uint32(r1) 51 | } 52 | 53 | func (self *IUnknown) Release() uint32 { 54 | r1, _, _ := syscall.Syscall(self.Vtbl.Release, 1, uintptr(unsafe.Pointer(self)), 0, 0) 55 | return uint32(r1) 56 | } 57 | -------------------------------------------------------------------------------- /wrappers/verrsrc.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | VS_FF_DEBUG = 0x00000001 21 | VS_FF_PRERELEASE = 0x00000002 22 | VS_FF_PATCHED = 0x00000004 23 | VS_FF_PRIVATEBUILD = 0x00000008 24 | VS_FF_INFOINFERRED = 0x00000010 25 | VS_FF_SPECIALBUILD = 0x00000020 26 | ) 27 | 28 | const ( 29 | VOS_UNKNOWN = 0x00000000 30 | VOS_DOS = 0x00010000 31 | VOS_OS216 = 0x00020000 32 | VOS_OS232 = 0x00030000 33 | VOS_NT = 0x00040000 34 | VOS__WINDOWS16 = 0x00000001 35 | VOS__PM16 = 0x00000002 36 | VOS__PM32 = 0x00000003 37 | VOS__WINDOWS32 = 0x00000004 38 | VOS_DOS_WINDOWS16 = 0x00010001 39 | VOS_DOS_WINDOWS32 = 0x00010004 40 | VOS_OS216_PM16 = 0x00020002 41 | VOS_OS232_PM32 = 0x00030003 42 | VOS_NT_WINDOWS32 = 0x00040004 43 | ) 44 | 45 | const ( 46 | VFT_UNKNOWN = 0x00000000 47 | VFT_APP = 0x00000001 48 | VFT_DLL = 0x00000002 49 | VFT_DRV = 0x00000003 50 | VFT_FONT = 0x00000004 51 | VFT_VXD = 0x00000005 52 | VFT_STATIC_LIB = 0x00000007 53 | ) 54 | 55 | const ( 56 | VFT2_UNKNOWN = 0x00000000 57 | VFT2_DRV_PRINTER = 0x00000001 58 | VFT2_DRV_KEYBOARD = 0x00000002 59 | VFT2_DRV_LANGUAGE = 0x00000003 60 | VFT2_DRV_DISPLAY = 0x00000004 61 | VFT2_DRV_MOUSE = 0x00000005 62 | VFT2_DRV_NETWORK = 0x00000006 63 | VFT2_DRV_SYSTEM = 0x00000007 64 | VFT2_DRV_INSTALLABLE = 0x00000008 65 | VFT2_DRV_SOUND = 0x00000009 66 | VFT2_DRV_COMM = 0x0000000A 67 | VFT2_DRV_VERSIONED_PRINTER = 0x0000000C 68 | VFT2_FONT_RASTER = 0x00000001 69 | VFT2_FONT_VECTOR = 0x00000002 70 | VFT2_FONT_TRUETYPE = 0x00000003 71 | ) 72 | 73 | type VS_FIXEDFILEINFO struct { 74 | Signature uint32 75 | StrucVersion uint32 76 | FileVersionMS uint32 77 | FileVersionLS uint32 78 | ProductVersionMS uint32 79 | ProductVersionLS uint32 80 | FileFlagsMask uint32 81 | FileFlags uint32 82 | FileOS uint32 83 | FileType uint32 84 | FileSubtype uint32 85 | FileDateMS uint32 86 | FileDateLS uint32 87 | } 88 | -------------------------------------------------------------------------------- /wrappers/winbase_386.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build 386 18 | 19 | package wrappers 20 | 21 | import ( 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | func VerifyVersionInfo(versionInfo *OSVERSIONINFOEX, typeMask uint32, conditionMask uint64) error { 27 | r1, _, e1 := syscall.Syscall6( 28 | procVerifyVersionInfoW.Addr(), 29 | 4, 30 | uintptr(unsafe.Pointer(versionInfo)), 31 | uintptr(typeMask), 32 | uintptr(loUint32(conditionMask)), 33 | uintptr(hiUint32(conditionMask)), 34 | 0, 35 | 0) 36 | if r1 == 0 { 37 | if e1 != ERROR_SUCCESS { 38 | return e1 39 | } else { 40 | return syscall.EINVAL 41 | } 42 | } 43 | return nil 44 | } 45 | -------------------------------------------------------------------------------- /wrappers/winbase_amd64.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build amd64 18 | 19 | package wrappers 20 | 21 | import ( 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | func VerifyVersionInfo(versionInfo *OSVERSIONINFOEX, typeMask uint32, conditionMask uint64) error { 27 | r1, _, e1 := syscall.Syscall( 28 | procVerifyVersionInfoW.Addr(), 29 | 3, 30 | uintptr(unsafe.Pointer(versionInfo)), 31 | uintptr(typeMask), 32 | uintptr(conditionMask)) 33 | if r1 == 0 { 34 | if e1 != ERROR_SUCCESS { 35 | return e1 36 | } else { 37 | return syscall.EINVAL 38 | } 39 | } 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /wrappers/winbase_arm.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build arm 18 | 19 | package wrappers 20 | 21 | import ( 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | func VerifyVersionInfo(versionInfo *OSVERSIONINFOEX, typeMask uint32, conditionMask uint64) error { 27 | r1, _, e1 := syscall.Syscall6( 28 | procVerifyVersionInfoW.Addr(), 29 | 4, 30 | uintptr(unsafe.Pointer(versionInfo)), 31 | uintptr(typeMask), 32 | uintptr(loUint32(conditionMask)), 33 | uintptr(hiUint32(conditionMask)), 34 | 0, 35 | 0) 36 | if r1 == 0 { 37 | if e1 != ERROR_SUCCESS { 38 | return e1 39 | } else { 40 | return syscall.EINVAL 41 | } 42 | } 43 | return nil 44 | } 45 | -------------------------------------------------------------------------------- /wrappers/winbase_arm64.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build arm64 18 | 19 | package wrappers 20 | 21 | import ( 22 | "syscall" 23 | "unsafe" 24 | ) 25 | 26 | func VerifyVersionInfo(versionInfo *OSVERSIONINFOEX, typeMask uint32, conditionMask uint64) error { 27 | r1, _, e1 := syscall.Syscall( 28 | procVerifyVersionInfoW.Addr(), 29 | 3, 30 | uintptr(unsafe.Pointer(versionInfo)), 31 | uintptr(typeMask), 32 | uintptr(conditionMask)) 33 | if r1 == 0 { 34 | if e1 != ERROR_SUCCESS { 35 | return e1 36 | } else { 37 | return syscall.EINVAL 38 | } 39 | } 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /wrappers/wincon.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2019 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const ( 25 | FOREGROUND_BLUE = 0x0001 26 | FOREGROUND_GREEN = 0x0002 27 | FOREGROUND_RED = 0x0004 28 | FOREGROUND_INTENSITY = 0x0008 29 | BACKGROUND_BLUE = 0x0010 30 | BACKGROUND_GREEN = 0x0020 31 | BACKGROUND_RED = 0x0040 32 | BACKGROUND_INTENSITY = 0x0080 33 | ) 34 | 35 | const ( 36 | CTRL_C_EVENT = 0 37 | CTRL_BREAK_EVENT = 1 38 | CTRL_CLOSE_EVENT = 2 39 | CTRL_LOGOFF_EVENT = 5 40 | CTRL_SHUTDOWN_EVENT = 6 41 | ) 42 | 43 | const ( 44 | ENABLE_PROCESSED_INPUT = 0x0001 45 | ENABLE_LINE_INPUT = 0x0002 46 | ENABLE_ECHO_INPUT = 0x0004 47 | ENABLE_WINDOW_INPUT = 0x0008 48 | ENABLE_MOUSE_INPUT = 0x0010 49 | ENABLE_INSERT_MODE = 0x0020 50 | ENABLE_QUICK_EDIT_MODE = 0x0040 51 | ENABLE_EXTENDED_FLAGS = 0x0080 52 | ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200 53 | ) 54 | 55 | const ( 56 | ENABLE_PROCESSED_OUTPUT = 0x0001 57 | ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002 58 | ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004 59 | DISABLE_NEWLINE_AUTO_RETURN = 0x0008 60 | ENABLE_LVB_GRID_WORLDWIDE = 0x0010 61 | ) 62 | 63 | var ( 64 | procGenerateConsoleCtrlEvent = modkernel32.NewProc("GenerateConsoleCtrlEvent") 65 | procGetConsoleMode = modkernel32.NewProc("GetConsoleMode") 66 | procSetConsoleMode = modkernel32.NewProc("SetConsoleMode") 67 | ) 68 | 69 | func GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupId uint32) error { 70 | r1, _, e1 := syscall.Syscall( 71 | procGenerateConsoleCtrlEvent.Addr(), 72 | 2, 73 | uintptr(ctrlEvent), 74 | uintptr(processGroupId), 75 | 0) 76 | if r1 == 0 { 77 | if e1 != ERROR_SUCCESS { 78 | return e1 79 | } else { 80 | return syscall.EINVAL 81 | } 82 | } 83 | return nil 84 | } 85 | 86 | func GetConsoleMode(consoleHandle syscall.Handle, mode *uint32) error { 87 | r1, _, e1 := syscall.Syscall( 88 | procGetConsoleMode.Addr(), 89 | 2, 90 | uintptr(consoleHandle), 91 | uintptr(unsafe.Pointer(mode)), 92 | 0) 93 | if r1 == 0 { 94 | if e1 != ERROR_SUCCESS { 95 | return e1 96 | } else { 97 | return syscall.EINVAL 98 | } 99 | } 100 | return nil 101 | } 102 | 103 | func SetConsoleMode(consoleHandle syscall.Handle, mode uint32) error { 104 | r1, _, e1 := syscall.Syscall( 105 | procSetConsoleMode.Addr(), 106 | 2, 107 | uintptr(consoleHandle), 108 | uintptr(mode), 109 | 0) 110 | if r1 == 0 { 111 | if e1 != ERROR_SUCCESS { 112 | return e1 113 | } else { 114 | return syscall.EINVAL 115 | } 116 | } 117 | return nil 118 | } 119 | -------------------------------------------------------------------------------- /wrappers/windef.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | MAX_PATH = 260 21 | ) 22 | 23 | type RECT struct { 24 | Left int32 25 | Top int32 26 | Right int32 27 | Bottom int32 28 | } 29 | 30 | func MAKELONG(low uint16, high uint16) uint32 { 31 | return uint32(low) | (uint32(high) << 16) 32 | } 33 | 34 | func LOWORD(value uint32) uint16 { 35 | return uint16(value & 0x0000FFFF) 36 | } 37 | 38 | func HIWORD(value uint32) uint16 { 39 | return uint16((value >> 16) & 0x0000FFFF) 40 | } 41 | 42 | func boolToUintptr(value bool) uintptr { 43 | var valueRaw int32 44 | if value { 45 | valueRaw = 1 46 | } else { 47 | valueRaw = 0 48 | } 49 | 50 | return uintptr(valueRaw) 51 | } 52 | 53 | func makeUint64(lo, hi uint32) uint64 { 54 | return uint64(lo) | (uint64(hi) << 32) 55 | } 56 | 57 | func loUint32(value uint64) uint32 { 58 | return uint32(value & 0xffffffff) 59 | } 60 | 61 | func hiUint32(value uint64) uint32 { 62 | return uint32(value >> 32) 63 | } 64 | -------------------------------------------------------------------------------- /wrappers/wingdi.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | CCHDEVICENAME = 32 21 | CCHFORMNAME = 32 22 | ) 23 | 24 | type DEVMODE struct { 25 | DeviceName [CCHDEVICENAME]uint16 26 | SpecVersion uint16 27 | DriverVersion uint16 28 | Size uint16 29 | DriverExtra uint16 30 | Fields uint32 31 | Orientation int16 32 | PaperSize int16 33 | PaperLength int16 34 | PaperWidth int16 35 | Scale int16 36 | Copies int16 37 | DefaultSource int16 38 | PrintQuality int16 39 | Color int16 40 | Duplex int16 41 | YResolution int16 42 | TTOption int16 43 | Collate int16 44 | FormName [CCHFORMNAME]uint16 45 | LogPixels uint16 46 | BitsPerPel uint32 47 | PelsWidth uint32 48 | PelsHeight uint32 49 | DisplayFlags uint32 50 | DisplayFrequency uint32 51 | ICMMethod uint32 52 | ICMIntent uint32 53 | MediaType uint32 54 | DitherType uint32 55 | Reserved1 uint32 56 | Reserved2 uint32 57 | PanningWidth uint32 58 | PanningHeight uint32 59 | } 60 | 61 | type DISPLAY_DEVICE struct { 62 | Cb uint32 63 | DeviceName [32]uint16 64 | DeviceString [128]uint16 65 | StateFlags uint32 66 | DeviceID [128]uint16 67 | DeviceKey [128]uint16 68 | } 69 | 70 | const ( 71 | DISPLAY_DEVICE_ACTIVE = 0x00000001 72 | DISPLAY_DEVICE_PRIMARY_DEVICE = 0x00000004 73 | DISPLAY_DEVICE_MIRRORING_DRIVER = 0x00000008 74 | DISPLAY_DEVICE_VGA_COMPATIBLE = 0x00000010 75 | DISPLAY_DEVICE_REMOVABLE = 0x00000020 76 | DISPLAY_DEVICE_MODESPRUNED = 0x08000000 77 | ) 78 | -------------------------------------------------------------------------------- /wrappers/winioctl.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | FILE_DEVICE_BEEP = 0x00000001 21 | FILE_DEVICE_CD_ROM = 0x00000002 22 | FILE_DEVICE_CD_ROM_FILE_SYSTEM = 0x00000003 23 | FILE_DEVICE_CONTROLLER = 0x00000004 24 | FILE_DEVICE_DATALINK = 0x00000005 25 | FILE_DEVICE_DFS = 0x00000006 26 | FILE_DEVICE_DISK = 0x00000007 27 | FILE_DEVICE_DISK_FILE_SYSTEM = 0x00000008 28 | FILE_DEVICE_FILE_SYSTEM = 0x00000009 29 | FILE_DEVICE_INPUT_PORT = 0x0000000A 30 | FILE_DEVICE_KEYBOARD = 0x0000000B 31 | FILE_DEVICE_MAILSLOT = 0x0000000C 32 | FILE_DEVICE_MIDI_IN = 0x0000000D 33 | FILE_DEVICE_MIDI_OUT = 0x0000000E 34 | FILE_DEVICE_MOUSE = 0x0000000F 35 | FILE_DEVICE_MULTI_UNC_PROVIDER = 0x00000010 36 | FILE_DEVICE_NAMED_PIPE = 0x00000011 37 | FILE_DEVICE_NETWORK = 0x00000012 38 | FILE_DEVICE_NETWORK_BROWSER = 0x00000013 39 | FILE_DEVICE_NETWORK_FILE_SYSTEM = 0x00000014 40 | FILE_DEVICE_NULL = 0x00000015 41 | FILE_DEVICE_PARALLEL_PORT = 0x00000016 42 | FILE_DEVICE_PHYSICAL_NETCARD = 0x00000017 43 | FILE_DEVICE_PRINTER = 0x00000018 44 | FILE_DEVICE_SCANNER = 0x00000019 45 | FILE_DEVICE_SERIAL_MOUSE_PORT = 0x0000001A 46 | FILE_DEVICE_SERIAL_PORT = 0x0000001B 47 | FILE_DEVICE_SCREEN = 0x0000001C 48 | FILE_DEVICE_SOUND = 0x0000001D 49 | FILE_DEVICE_STREAMS = 0x0000001E 50 | FILE_DEVICE_TAPE = 0x0000001F 51 | FILE_DEVICE_TAPE_FILE_SYSTEM = 0x00000020 52 | FILE_DEVICE_TRANSPORT = 0x00000021 53 | FILE_DEVICE_UNKNOWN = 0x00000022 54 | FILE_DEVICE_VIDEO = 0x00000023 55 | FILE_DEVICE_VIRTUAL_DISK = 0x00000024 56 | FILE_DEVICE_WAVE_IN = 0x00000025 57 | FILE_DEVICE_WAVE_OUT = 0x00000026 58 | FILE_DEVICE_8042_PORT = 0x00000027 59 | FILE_DEVICE_NETWORK_REDIRECTOR = 0x00000028 60 | FILE_DEVICE_BATTERY = 0x00000029 61 | FILE_DEVICE_BUS_EXTENDER = 0x0000002A 62 | FILE_DEVICE_MODEM = 0x0000002B 63 | FILE_DEVICE_VDM = 0x0000002C 64 | FILE_DEVICE_MASS_STORAGE = 0x0000002D 65 | FILE_DEVICE_SMB = 0x0000002E 66 | FILE_DEVICE_KS = 0x0000002F 67 | FILE_DEVICE_CHANGER = 0x00000030 68 | FILE_DEVICE_SMARTCARD = 0x00000031 69 | FILE_DEVICE_ACPI = 0x00000032 70 | FILE_DEVICE_DVD = 0x00000033 71 | FILE_DEVICE_FULLSCREEN_VIDEO = 0x00000034 72 | FILE_DEVICE_DFS_FILE_SYSTEM = 0x00000035 73 | FILE_DEVICE_DFS_VOLUME = 0x00000036 74 | FILE_DEVICE_SERENUM = 0x00000037 75 | FILE_DEVICE_TERMSRV = 0x00000038 76 | FILE_DEVICE_KSEC = 0x00000039 77 | FILE_DEVICE_FIPS = 0x0000003A 78 | ) 79 | 80 | func CTL_CODE(deviceType uint32, function uint32, method uint32, access uint32) uint32 { 81 | return (deviceType << 16) | (access << 14) | (function << 2) | method 82 | } 83 | 84 | const ( 85 | METHOD_BUFFERED = 0 86 | METHOD_IN_DIRECT = 1 87 | METHOD_OUT_DIRECT = 2 88 | METHOD_NEITHER = 3 89 | ) 90 | 91 | const ( 92 | FILE_ANY_ACCESS = 0x0000 93 | FILE_SPECIAL_ACCESS = FILE_ANY_ACCESS 94 | FILE_READ_ACCESS = 0x0001 95 | FILE_WRITE_ACCESS = 0x0002 96 | ) 97 | 98 | var ( 99 | IOCTL_DISK_PERFORMANCE = CTL_CODE(FILE_DEVICE_DISK, 0x0008, METHOD_BUFFERED, FILE_ANY_ACCESS) 100 | ) 101 | 102 | var ( 103 | FSCTL_SET_REPARSE_POINT = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) 104 | FSCTL_GET_REPARSE_POINT = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS) 105 | FSCTL_DELETE_REPARSE_POINT = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) 106 | ) 107 | 108 | type DISK_PERFORMANCE struct { 109 | BytesRead int64 110 | BytesWritten int64 111 | ReadTime int64 112 | WriteTime int64 113 | IdleTime int64 114 | ReadCount uint32 115 | WriteCount uint32 116 | QueueDepth uint32 117 | SplitCount uint32 118 | QueryTime int64 119 | StorageDeviceNumber uint32 120 | StorageManagerName [8]uint16 121 | } 122 | -------------------------------------------------------------------------------- /wrappers/winnls.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const ( 25 | LOCALE_NOUSEROVERRIDE = 0x80000000 26 | LOCALE_USE_CP_ACP = 0x40000000 27 | LOCALE_RETURN_NUMBER = 0x20000000 28 | LOCALE_RETURN_GENITIVE_NAMES = 0x10000000 29 | LOCALE_ALLOW_NEUTRAL_NAMES = 0x08000000 30 | ) 31 | 32 | var ( 33 | procLocaleNameToLCID = modkernel32.NewProc("LocaleNameToLCID") 34 | ) 35 | 36 | func LocaleNameToLCID(name *uint16, flags uint32) (uint32, error) { 37 | r1, _, e1 := syscall.Syscall( 38 | procLocaleNameToLCID.Addr(), 39 | 2, 40 | uintptr(unsafe.Pointer(name)), 41 | uintptr(flags), 42 | 0) 43 | if r1 == 0 { 44 | if e1 != ERROR_SUCCESS { 45 | return 0, e1 46 | } else { 47 | return 0, syscall.EINVAL 48 | } 49 | } 50 | return uint32(r1), nil 51 | } 52 | -------------------------------------------------------------------------------- /wrappers/winnt_386.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build 386 18 | 19 | package wrappers 20 | 21 | import ( 22 | "syscall" 23 | ) 24 | 25 | func VerSetConditionMask(conditionMask uint64, typeBitMask uint32, condition uint8) uint64 { 26 | r1, r2, _ := syscall.Syscall6( 27 | procVerSetConditionMask.Addr(), 28 | 4, 29 | uintptr(loUint32(conditionMask)), 30 | uintptr(hiUint32(conditionMask)), 31 | uintptr(typeBitMask), 32 | uintptr(condition), 33 | 0, 34 | 0) 35 | return makeUint64(uint32(r1), uint32(r2)) 36 | } 37 | -------------------------------------------------------------------------------- /wrappers/winnt_amd64.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build amd64 18 | 19 | package wrappers 20 | 21 | import "syscall" 22 | 23 | func VerSetConditionMask(conditionMask uint64, typeBitMask uint32, condition uint8) uint64 { 24 | r1, _, _ := syscall.Syscall( 25 | procVerSetConditionMask.Addr(), 26 | 3, 27 | uintptr(conditionMask), 28 | uintptr(typeBitMask), 29 | uintptr(condition)) 30 | return uint64(r1) 31 | } 32 | -------------------------------------------------------------------------------- /wrappers/winnt_arm.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build arm 18 | 19 | package wrappers 20 | 21 | import ( 22 | "syscall" 23 | ) 24 | 25 | func VerSetConditionMask(conditionMask uint64, typeBitMask uint32, condition uint8) uint64 { 26 | r1, r2, _ := syscall.Syscall6( 27 | procVerSetConditionMask.Addr(), 28 | 4, 29 | uintptr(loUint32(conditionMask)), 30 | uintptr(hiUint32(conditionMask)), 31 | uintptr(typeBitMask), 32 | uintptr(condition), 33 | 0, 34 | 0) 35 | return makeUint64(uint32(r1), uint32(r2)) 36 | } 37 | -------------------------------------------------------------------------------- /wrappers/winnt_arm64.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // +build arm64 18 | 19 | package wrappers 20 | 21 | import "syscall" 22 | 23 | func VerSetConditionMask(conditionMask uint64, typeBitMask uint32, condition uint8) uint64 { 24 | r1, _, _ := syscall.Syscall( 25 | procVerSetConditionMask.Addr(), 26 | 3, 27 | uintptr(conditionMask), 28 | uintptr(typeBitMask), 29 | uintptr(condition)) 30 | return uint64(r1) 31 | } 32 | -------------------------------------------------------------------------------- /wrappers/winreg.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | const ( 25 | HKEY_CLASSES_ROOT = 0x80000000 26 | HKEY_CURRENT_USER = 0x80000001 27 | HKEY_LOCAL_MACHINE = 0x80000002 28 | HKEY_USERS = 0x80000003 29 | HKEY_PERFORMANCE_DATA = 0x80000004 30 | HKEY_PERFORMANCE_TEXT = 0x80000050 31 | HKEY_PERFORMANCE_NLSTEXT = 0x80000060 32 | HKEY_CURRENT_CONFIG = 0x80000005 33 | HKEY_DYN_DATA = 0x80000006 34 | HKEY_CURRENT_USER_LOCAL_SETTINGS = 0x80000007 35 | ) 36 | 37 | const ( 38 | SHUTDOWN_FORCE_OTHERS = 0x00000001 39 | SHUTDOWN_FORCE_SELF = 0x00000002 40 | SHUTDOWN_RESTART = 0x00000004 41 | SHUTDOWN_POWEROFF = 0x00000008 42 | SHUTDOWN_NOREBOOT = 0x00000010 43 | SHUTDOWN_GRACE_OVERRIDE = 0x00000020 44 | SHUTDOWN_INSTALL_UPDATES = 0x00000040 45 | SHUTDOWN_RESTARTAPPS = 0x00000080 46 | SHUTDOWN_SKIP_SVC_PRESHUTDOWN = 0x00000100 47 | SHUTDOWN_HYBRID = 0x00000200 48 | ) 49 | 50 | var ( 51 | procInitiateShutdownW = modadvapi32.NewProc("InitiateShutdownW") 52 | procInitiateSystemShutdownW = modadvapi32.NewProc("InitiateSystemShutdownW") 53 | procRegCloseKey = modadvapi32.NewProc("RegCloseKey") 54 | procRegCreateKeyExW = modadvapi32.NewProc("RegCreateKeyExW") 55 | procRegDeleteKeyW = modadvapi32.NewProc("RegDeleteKeyW") 56 | procRegDeleteValueW = modadvapi32.NewProc("RegDeleteValueW") 57 | procRegEnumKeyExW = modadvapi32.NewProc("RegEnumKeyExW") 58 | procRegEnumValueW = modadvapi32.NewProc("RegEnumValueW") 59 | procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW") 60 | procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW") 61 | procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW") 62 | procRegSetValueExW = modadvapi32.NewProc("RegSetValueExW") 63 | ) 64 | 65 | func RegCloseKey(key syscall.Handle) error { 66 | r1, _, _ := syscall.Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0) 67 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 68 | return err 69 | } 70 | return nil 71 | } 72 | 73 | func RegCreateKeyEx(key syscall.Handle, subKey *uint16, reserved uint32, class *uint16, options uint32, samDesired uint32, securityAttributes *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) error { 74 | r1, _, _ := syscall.Syscall9( 75 | procRegCreateKeyExW.Addr(), 76 | 9, 77 | uintptr(key), 78 | uintptr(unsafe.Pointer(subKey)), 79 | uintptr(reserved), 80 | uintptr(unsafe.Pointer(class)), 81 | uintptr(options), 82 | uintptr(samDesired), 83 | uintptr(unsafe.Pointer(securityAttributes)), 84 | uintptr(unsafe.Pointer(result)), 85 | uintptr(unsafe.Pointer(disposition))) 86 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 87 | return err 88 | } 89 | return nil 90 | } 91 | 92 | func RegDeleteKey(key syscall.Handle, subKey *uint16) error { 93 | r1, _, _ := syscall.Syscall( 94 | procRegDeleteKeyW.Addr(), 95 | 2, 96 | uintptr(key), 97 | uintptr(unsafe.Pointer(subKey)), 98 | 0) 99 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 100 | return err 101 | } 102 | return nil 103 | } 104 | 105 | func RegDeleteValue(key syscall.Handle, valueName *uint16) error { 106 | r1, _, _ := syscall.Syscall( 107 | procRegDeleteValueW.Addr(), 108 | 2, 109 | uintptr(key), 110 | uintptr(unsafe.Pointer(valueName)), 111 | 0) 112 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 113 | return err 114 | } 115 | return nil 116 | } 117 | 118 | func RegEnumKeyEx(key syscall.Handle, index uint32, name *uint16, cName *uint32, reserved *uint32, class *uint16, cClass *uint32, lastWriteTime *FILETIME) error { 119 | r1, _, _ := syscall.Syscall9( 120 | procRegEnumKeyExW.Addr(), 121 | 8, 122 | uintptr(key), 123 | uintptr(index), 124 | uintptr(unsafe.Pointer(name)), 125 | uintptr(unsafe.Pointer(cName)), 126 | uintptr(unsafe.Pointer(reserved)), 127 | uintptr(unsafe.Pointer(class)), 128 | uintptr(unsafe.Pointer(cClass)), 129 | uintptr(unsafe.Pointer(lastWriteTime)), 130 | 0) 131 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 132 | return err 133 | } 134 | return nil 135 | } 136 | 137 | func RegEnumValue(key syscall.Handle, index uint32, valueName *uint16, cchValueName *uint32, reserved *uint32, valueType *uint32, data *byte, cbData *uint32) error { 138 | r1, _, _ := syscall.Syscall9( 139 | procRegEnumValueW.Addr(), 140 | 8, 141 | uintptr(key), 142 | uintptr(index), 143 | uintptr(unsafe.Pointer(valueName)), 144 | uintptr(unsafe.Pointer(cchValueName)), 145 | uintptr(unsafe.Pointer(reserved)), 146 | uintptr(unsafe.Pointer(valueType)), 147 | uintptr(unsafe.Pointer(data)), 148 | uintptr(unsafe.Pointer(cbData)), 149 | 0) 150 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 151 | return err 152 | } 153 | return nil 154 | } 155 | 156 | func RegOpenKeyEx(key syscall.Handle, subKey *uint16, options uint32, samDesired uint32, result *syscall.Handle) error { 157 | r1, _, _ := syscall.Syscall6( 158 | procRegOpenKeyExW.Addr(), 159 | 5, 160 | uintptr(key), 161 | uintptr(unsafe.Pointer(subKey)), 162 | uintptr(options), 163 | uintptr(samDesired), 164 | uintptr(unsafe.Pointer(result)), 165 | 0) 166 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 167 | return err 168 | } 169 | return nil 170 | } 171 | 172 | func RegQueryInfoKey(key syscall.Handle, class *uint16, cClass *uint32, reserved *uint32, subKeys *uint32, maxSubKeyLen *uint32, maxClassLen *uint32, values *uint32, maxValueNameLen *uint32, maxValueLen *uint32, cbSecurityDescriptor *uint32, lastWriteTime *FILETIME) error { 173 | r1, _, _ := syscall.Syscall12( 174 | procRegQueryInfoKeyW.Addr(), 175 | 12, 176 | uintptr(key), 177 | uintptr(unsafe.Pointer(class)), 178 | uintptr(unsafe.Pointer(cClass)), 179 | uintptr(unsafe.Pointer(reserved)), 180 | uintptr(unsafe.Pointer(subKeys)), 181 | uintptr(unsafe.Pointer(maxSubKeyLen)), 182 | uintptr(unsafe.Pointer(maxClassLen)), 183 | uintptr(unsafe.Pointer(values)), 184 | uintptr(unsafe.Pointer(maxValueNameLen)), 185 | uintptr(unsafe.Pointer(maxValueLen)), 186 | uintptr(unsafe.Pointer(cbSecurityDescriptor)), 187 | uintptr(unsafe.Pointer(lastWriteTime))) 188 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 189 | return err 190 | } 191 | return nil 192 | } 193 | 194 | func RegQueryValueEx(key syscall.Handle, valueName *uint16, reserved *uint32, valueType *uint32, data *byte, cbData *uint32) error { 195 | r1, _, _ := syscall.Syscall6( 196 | procRegQueryValueExW.Addr(), 197 | 6, 198 | uintptr(key), 199 | uintptr(unsafe.Pointer(valueName)), 200 | uintptr(unsafe.Pointer(reserved)), 201 | uintptr(unsafe.Pointer(valueType)), 202 | uintptr(unsafe.Pointer(data)), 203 | uintptr(unsafe.Pointer(cbData))) 204 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 205 | return err 206 | } 207 | return nil 208 | } 209 | 210 | func RegSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, valueType uint32, data *byte, cbData uint32) error { 211 | r1, _, _ := syscall.Syscall6( 212 | procRegSetValueExW.Addr(), 213 | 6, 214 | uintptr(key), 215 | uintptr(unsafe.Pointer(valueName)), 216 | uintptr(reserved), 217 | uintptr(valueType), 218 | uintptr(unsafe.Pointer(data)), 219 | uintptr(cbData)) 220 | if err := syscall.Errno(r1); err != ERROR_SUCCESS { 221 | return err 222 | } 223 | return nil 224 | } 225 | 226 | func InitiateShutdown(machineName *uint16, message *uint16, gracePriod uint32, shutdownFlags uint32, reason uint32) error { 227 | r1, _, e1 := syscall.Syscall6( 228 | procInitiateShutdownW.Addr(), 229 | 5, 230 | uintptr(unsafe.Pointer(machineName)), 231 | uintptr(unsafe.Pointer(message)), 232 | uintptr(gracePriod), 233 | uintptr(shutdownFlags), 234 | uintptr(reason), 235 | 0) 236 | 237 | if r1 != 0 { 238 | if e1 != ERROR_SUCCESS { 239 | return e1 240 | } else { 241 | return syscall.EINVAL 242 | } 243 | } 244 | return nil 245 | } 246 | 247 | func InitiateSystemShutdown(machineName *uint16, message *uint16, timeout uint32, forceAppsClosed bool, rebootAfterShutdown bool) error { 248 | r1, _, e1 := syscall.Syscall6( 249 | procInitiateSystemShutdownW.Addr(), 250 | 5, 251 | uintptr(unsafe.Pointer(machineName)), 252 | uintptr(unsafe.Pointer(message)), 253 | uintptr(timeout), 254 | boolToUintptr(forceAppsClosed), 255 | boolToUintptr(rebootAfterShutdown), 256 | 0) 257 | if r1 == 0 { 258 | if e1 != ERROR_SUCCESS { 259 | return e1 260 | } else { 261 | return syscall.EINVAL 262 | } 263 | } 264 | return nil 265 | } 266 | -------------------------------------------------------------------------------- /wrappers/winsock2.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | ) 22 | 23 | const ( 24 | WSA_IO_PENDING = ERROR_IO_PENDING 25 | WSA_IO_INCOMPLETE = ERROR_IO_INCOMPLETE 26 | WSA_INVALID_HANDLE = ERROR_INVALID_HANDLE 27 | WSA_INVALID_PARAMETER = ERROR_INVALID_PARAMETER 28 | WSA_NOT_ENOUGH_MEMORY = ERROR_NOT_ENOUGH_MEMORY 29 | WSA_OPERATION_ABORTED = ERROR_OPERATION_ABORTED 30 | ) 31 | 32 | var ( 33 | modws2_32 = syscall.NewLazyDLL("ws2_32.dll") 34 | 35 | procWSAGetLastError = modws2_32.NewProc("WSAGetLastError") 36 | procWSASetLastError = modws2_32.NewProc("WSASetLastError") 37 | procntohs = modws2_32.NewProc("ntohs") 38 | ) 39 | 40 | func WSAGetLastError() error { 41 | r1, _, _ := syscall.Syscall(procWSAGetLastError.Addr(), 0, 0, 0, 0) 42 | return syscall.Errno(r1) 43 | } 44 | 45 | func WSASetLastError(error syscall.Errno) { 46 | syscall.Syscall(procWSASetLastError.Addr(), 1, uintptr(error), 0, 0) 47 | } 48 | 49 | func Ntohs(netshort uint16) uint16 { 50 | r1, _, _ := syscall.Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0) 51 | return uint16(r1) 52 | } 53 | -------------------------------------------------------------------------------- /wrappers/winternl.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | type UNICODE_STRING struct { 25 | Length uint16 26 | MaximumLength uint16 27 | Buffer uintptr 28 | } 29 | 30 | type RTL_USER_PROCESS_PARAMETERS struct { 31 | Reserved1 [16]byte 32 | Reserved2 [10]uintptr 33 | ImagePathName UNICODE_STRING 34 | CommandLine UNICODE_STRING 35 | } 36 | 37 | type PEB struct { 38 | Reserved1 [2]byte 39 | BeingDebugged byte 40 | Reserved2 [1]byte 41 | Reserved3 [2]uintptr 42 | Ldr uintptr 43 | ProcessParameters uintptr 44 | Reserved4 [104]byte 45 | Reserved5 [52]uintptr 46 | PostProcessInitRoutine uintptr 47 | Reserved6 [128]byte 48 | Reserved7 [1]uintptr 49 | SessionId uint32 50 | } 51 | 52 | type OBJECT_ATTRIBUTES struct { 53 | Length uint32 54 | RootDirectory syscall.Handle 55 | ObjectName *UNICODE_STRING 56 | Attributes uint32 57 | SecurityDescriptor uintptr 58 | SecurityQualityOfService uintptr 59 | } 60 | 61 | type PROCESS_BASIC_INFORMATION struct { 62 | Reserved1 uintptr 63 | PebBaseAddress uintptr 64 | Reserved2 [2]uintptr 65 | UniqueProcessId uintptr 66 | Reserved3 uintptr 67 | } 68 | 69 | const ( 70 | ProcessBasicInformation = 0 71 | ProcessWow64Information = 26 72 | ) 73 | 74 | func NT_SUCCESS(status uint32) bool { 75 | return int32(uintptr(status)) >= 0 76 | } 77 | 78 | func NT_INFORMATION(status uint32) bool { 79 | return (status >> 30) == 1 80 | } 81 | 82 | func NT_WARNING(status uint32) bool { 83 | return (status >> 30) == 2 84 | } 85 | 86 | func NT_ERROR(status uint32) bool { 87 | return (status >> 30) == 3 88 | } 89 | 90 | var ( 91 | modntdll = syscall.NewLazyDLL("ntdll.dll") 92 | 93 | procNtQueryInformationProcess = modntdll.NewProc("NtQueryInformationProcess") 94 | procRtlFreeUnicodeString = modntdll.NewProc("RtlFreeUnicodeString") 95 | procRtlInitUnicodeString = modntdll.NewProc("RtlInitUnicodeString") 96 | ) 97 | 98 | func NtQueryInformationProcess(processHandle syscall.Handle, processInformationClass int32, processInformation *byte, processInformationLength uint32, returnLength *uint32) uint32 { 99 | r1, _, _ := syscall.Syscall6( 100 | procNtQueryInformationProcess.Addr(), 101 | 5, 102 | uintptr(processHandle), 103 | uintptr(processInformationClass), 104 | uintptr(unsafe.Pointer(processInformation)), 105 | uintptr(processInformationLength), 106 | uintptr(unsafe.Pointer(returnLength)), 107 | 0) 108 | return uint32(r1) 109 | } 110 | 111 | func RtlFreeUnicodeString(unicodeString *UNICODE_STRING) { 112 | syscall.Syscall( 113 | procRtlFreeUnicodeString.Addr(), 114 | 1, 115 | uintptr(unsafe.Pointer(unicodeString)), 116 | 0, 117 | 0) 118 | } 119 | 120 | func RtlInitUnicodeString(destinationString *UNICODE_STRING, sourceString *uint16) { 121 | syscall.Syscall( 122 | procRtlInitUnicodeString.Addr(), 123 | 2, 124 | uintptr(unsafe.Pointer(destinationString)), 125 | uintptr(unsafe.Pointer(sourceString)), 126 | 0) 127 | } 128 | -------------------------------------------------------------------------------- /wrappers/winver.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | var ( 25 | modversion = syscall.NewLazyDLL("version.dll") 26 | 27 | procGetFileVersionInfoSizeW = modversion.NewProc("GetFileVersionInfoSizeW") 28 | procGetFileVersionInfoW = modversion.NewProc("GetFileVersionInfoW") 29 | procVerQueryValueW = modversion.NewProc("VerQueryValueW") 30 | ) 31 | 32 | func GetFileVersionInfo(filename *uint16, handle uint32, len uint32, data *byte) error { 33 | r1, _, e1 := syscall.Syscall6( 34 | procGetFileVersionInfoW.Addr(), 35 | 4, 36 | uintptr(unsafe.Pointer(filename)), 37 | uintptr(handle), 38 | uintptr(len), 39 | uintptr(unsafe.Pointer(data)), 40 | 0, 41 | 0) 42 | if r1 == 0 { 43 | if e1 != ERROR_SUCCESS { 44 | return e1 45 | } else { 46 | return syscall.EINVAL 47 | } 48 | } 49 | return nil 50 | } 51 | 52 | func GetFileVersionInfoSize(filename *uint16, handle *uint32) (uint32, error) { 53 | r1, _, e1 := syscall.Syscall( 54 | procGetFileVersionInfoSizeW.Addr(), 55 | 2, 56 | uintptr(unsafe.Pointer(filename)), 57 | uintptr(unsafe.Pointer(handle)), 58 | 0) 59 | if r1 == 0 { 60 | if e1 != ERROR_SUCCESS { 61 | return 0, e1 62 | } else { 63 | return 0, syscall.EINVAL 64 | } 65 | } 66 | return uint32(r1), nil 67 | } 68 | 69 | func VerQueryValue(block *byte, subBlock *uint16, buffer **byte, len *uint32) error { 70 | r1, _, e1 := syscall.Syscall6( 71 | procVerQueryValueW.Addr(), 72 | 4, 73 | uintptr(unsafe.Pointer(block)), 74 | uintptr(unsafe.Pointer(subBlock)), 75 | uintptr(unsafe.Pointer(buffer)), 76 | uintptr(unsafe.Pointer(len)), 77 | 0, 78 | 0) 79 | if r1 == 0 { 80 | if e1 != ERROR_SUCCESS { 81 | return e1 82 | } else { 83 | return syscall.EINVAL 84 | } 85 | } 86 | return nil 87 | } 88 | -------------------------------------------------------------------------------- /wrappers/ws2def.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | AF_UNSPEC = 0 21 | AF_INET = 2 22 | AF_IPX = 6 23 | AF_APPLETALK = 16 24 | AF_NETBIOS = 17 25 | AF_INET6 = 23 26 | AF_IRDA = 26 27 | AF_BTH = 32 28 | ) 29 | -------------------------------------------------------------------------------- /wrappers/ws2tcpip.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | var ( 25 | procInetNtopW = modws2_32.NewProc("InetNtopW") 26 | ) 27 | 28 | func InetNtop(family int32, addr *byte, stringBuf *uint16, stringBufSize uintptr) (*uint16, error) { 29 | WSASetLastError(0) 30 | r1, _, _ := syscall.Syscall6( 31 | procInetNtopW.Addr(), 32 | 4, 33 | uintptr(family), 34 | uintptr(unsafe.Pointer(addr)), 35 | uintptr(unsafe.Pointer(stringBuf)), 36 | stringBufSize, 37 | 0, 38 | 0) 39 | if r1 == 0 { 40 | return nil, WSAGetLastError() 41 | } 42 | return (*uint16)(unsafe.Pointer(r1)), nil 43 | } 44 | -------------------------------------------------------------------------------- /wrappers/wtsapi32.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | import ( 20 | "syscall" 21 | "unsafe" 22 | ) 23 | 24 | // Misc consts from WtsApi32.h 25 | const ( 26 | CLIENTNAME_LENGTH = 20 27 | DOMAIN_LENGTH = 17 28 | USERNAME_LENGTH = 20 29 | CLIENTADDRESS_LENGTH = 30 30 | WINSTATIONNAME_LENGTH = 32 31 | ) 32 | 33 | // WTS_CONNECTSTATE_CLASS enumeration 34 | const ( 35 | WTSActive = 0 36 | WTSConnected = 1 37 | WTSConnectQuery = 2 38 | WTSShadow = 3 39 | WTSDisconnected = 4 40 | WTSIdle = 5 41 | WTSListen = 6 42 | WTSReset = 7 43 | WTSDown = 8 44 | WTSInit = 9 45 | ) 46 | 47 | type WTS_SESSION_INFO struct { 48 | SessionId uint32 49 | WinStationName *uint16 50 | State uint32 51 | } 52 | 53 | // WTS_INFO_CLASS enumeration 54 | const ( 55 | WTSInitialProgram = 0 56 | WTSApplicationName = 1 57 | WTSWorkingDirectory = 2 58 | WTSOEMId = 3 59 | WTSSessionId = 4 60 | WTSUserName = 5 61 | WTSWinStationName = 6 62 | WTSDomainName = 7 63 | WTSConnectState = 8 64 | WTSClientBuildNumber = 9 65 | WTSClientName = 10 66 | WTSClientDirectory = 11 67 | WTSClientProductId = 12 68 | WTSClientHardwareId = 13 69 | WTSClientAddress = 14 70 | WTSClientDisplay = 15 71 | WTSClientProtocolType = 16 72 | WTSIdleTime = 17 73 | WTSLogonTime = 18 74 | WTSIncomingBytes = 19 75 | WTSOutgoingBytes = 20 76 | WTSIncomingFrames = 21 77 | WTSOutgoingFrames = 22 78 | WTSClientInfo = 23 79 | WTSSessionInfo = 24 80 | WTSSessionInfoEx = 25 81 | WTSConfigInfo = 26 82 | WTSValidationInfo = 27 83 | WTSSessionAddressV4 = 28 84 | WTSIsRemoteSession = 29 85 | ) 86 | 87 | type WTSINFO struct { 88 | State uint32 89 | SessionId uint32 90 | IncomingBytes uint32 91 | OutgoingBytes uint32 92 | IncomingFrames uint32 93 | OutgoingFrames uint32 94 | IncomingCompressedBytes uint32 95 | OutgoingCompressedBytes uint32 96 | WinStationName [WINSTATIONNAME_LENGTH]uint16 97 | Domain [DOMAIN_LENGTH]uint16 98 | UserName [USERNAME_LENGTH + 1]uint16 99 | ConnectTime int64 100 | DisconnectTime int64 101 | LastInputTime int64 102 | LogonTime int64 103 | CurrentTime int64 104 | } 105 | 106 | type WTSCLIENT struct { 107 | ClientName [CLIENTNAME_LENGTH + 1]uint16 108 | Domain [DOMAIN_LENGTH + 1]uint16 109 | UserName [USERNAME_LENGTH + 1]uint16 110 | WorkDirectory [MAX_PATH + 1]uint16 111 | InitialProgram [MAX_PATH + 1]uint16 112 | EncryptionLevel byte 113 | ClientAddressFamily uint32 114 | ClientAddress [CLIENTADDRESS_LENGTH + 1]uint16 115 | HRes uint16 116 | VRes uint16 117 | ColorDepth uint16 118 | ClientDirectory [MAX_PATH + 1]uint16 119 | ClientBuildNumber uint32 120 | ClientHardwareId uint32 121 | ClientProductId uint16 122 | OutBufCountHost uint16 123 | OutBufCountClient uint16 124 | OutBufLength uint16 125 | DeviceId [MAX_PATH + 1]uint16 126 | } 127 | 128 | type WTS_CLIENT_ADDRESS struct { 129 | AddressFamily uint32 130 | Address [20]byte 131 | } 132 | 133 | type WTS_CLIENT_DISPLAY struct { 134 | HorizontalResolution uint32 135 | VerticalResolution uint32 136 | ColorDepth uint32 137 | } 138 | 139 | var ( 140 | modwtsapi32 = syscall.NewLazyDLL("wtsapi32.dll") 141 | 142 | procWTSCloseServer = modwtsapi32.NewProc("WTSCloseServer") 143 | procWTSEnumerateSessions = modwtsapi32.NewProc("WTSEnumerateSessionsW") 144 | procWTSFreeMemory = modwtsapi32.NewProc("WTSFreeMemory") 145 | procWTSOpenServer = modwtsapi32.NewProc("WTSOpenServerW") 146 | procWTSLogoffSession = modwtsapi32.NewProc("WTSLogoffSession") 147 | procWTSQuerySessionInformation = modwtsapi32.NewProc("WTSQuerySessionInformationW") 148 | procWTSQueryUserToken = modwtsapi32.NewProc("WTSQueryUserToken") 149 | ) 150 | 151 | func WTSCloseServer(handle syscall.Handle) { 152 | syscall.Syscall6(procWTSCloseServer.Addr(), 1, uintptr(handle), 0, 0, 0, 0, 0) 153 | } 154 | 155 | func WTSEnumerateSessions(server syscall.Handle, reserved uint32, version uint32, pSessionInfo **WTS_SESSION_INFO, count *uint32) error { 156 | r1, _, e1 := syscall.Syscall6( 157 | procWTSEnumerateSessions.Addr(), 158 | 5, 159 | uintptr(server), 160 | uintptr(reserved), 161 | uintptr(version), 162 | uintptr(unsafe.Pointer(pSessionInfo)), 163 | uintptr(unsafe.Pointer(count)), 164 | 0) 165 | 166 | if r1 == 0 { 167 | if e1 != ERROR_SUCCESS { 168 | return e1 169 | } else { 170 | return syscall.EINVAL 171 | } 172 | } 173 | return nil 174 | } 175 | 176 | func WTSFreeMemory(memory *byte) { 177 | syscall.Syscall(procWTSFreeMemory.Addr(), 1, uintptr(unsafe.Pointer(memory)), 0, 0) 178 | } 179 | 180 | func WTSOpenServer(serverName *uint16) syscall.Handle { 181 | r1, _, _ := syscall.Syscall(procWTSOpenServer.Addr(), 1, uintptr(unsafe.Pointer(serverName)), 0, 0) 182 | return syscall.Handle(r1) 183 | } 184 | 185 | func WTSQuerySessionInformation(handle syscall.Handle, sessionId uint32, infoClass uint32, buffer **uint16, bytesReturned *uint32) error { 186 | r1, _, e1 := syscall.Syscall6( 187 | procWTSQuerySessionInformation.Addr(), 188 | 5, 189 | uintptr(handle), 190 | uintptr(sessionId), 191 | uintptr(infoClass), 192 | uintptr(unsafe.Pointer(buffer)), 193 | uintptr(unsafe.Pointer(bytesReturned)), 0) 194 | 195 | if r1 == 0 { 196 | if e1 != ERROR_SUCCESS { 197 | return e1 198 | } else { 199 | return syscall.EINVAL 200 | } 201 | } 202 | return nil 203 | } 204 | 205 | func WTSLogoffSession(handle syscall.Handle, sessionId uint32, wait bool) error { 206 | r1, _, e1 := syscall.Syscall( 207 | procWTSLogoffSession.Addr(), 208 | 3, 209 | uintptr(handle), 210 | uintptr(sessionId), 211 | boolToUintptr(wait)) 212 | 213 | if r1 == 0 { 214 | if e1 != ERROR_SUCCESS { 215 | return e1 216 | } else { 217 | return syscall.EINVAL 218 | } 219 | } 220 | return nil 221 | } 222 | 223 | func WTSQueryUserToken(sessionId uint32, handle *syscall.Handle) error { 224 | r1, _, e1 := syscall.Syscall( 225 | procWTSQueryUserToken.Addr(), 226 | 2, 227 | uintptr(sessionId), 228 | uintptr(unsafe.Pointer(handle)), 229 | 0) 230 | 231 | if r1 == 0 { 232 | if e1 != ERROR_SUCCESS { 233 | return e1 234 | } else { 235 | return syscall.EINVAL 236 | } 237 | } 238 | return nil 239 | } 240 | -------------------------------------------------------------------------------- /wrappers/wtypes.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the license is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wrappers 18 | 19 | const ( 20 | CLSCTX_INPROC_SERVER = 0x00000001 21 | CLSCTX_INPROC_HANDLER = 0x00000002 22 | CLSCTX_LOCAL_SERVER = 0x00000004 23 | CLSCTX_INPROC_SERVER16 = 0x00000008 24 | CLSCTX_REMOTE_SERVER = 0x00000010 25 | CLSCTX_INPROC_HANDLER16 = 0x00000020 26 | CLSCTX_RESERVED1 = 0x00000040 27 | CLSCTX_RESERVED2 = 0x00000080 28 | CLSCTX_RESERVED3 = 0x00000100 29 | CLSCTX_RESERVED4 = 0x00000200 30 | CLSCTX_NO_CODE_DOWNLOAD = 0x00000400 31 | CLSCTX_RESERVED5 = 0x00000800 32 | CLSCTX_NO_CUSTOM_MARSHAL = 0x00001000 33 | CLSCTX_ENABLE_CODE_DOWNLOAD = 0x00002000 34 | CLSCTX_NO_FAILURE_LOG = 0x00004000 35 | CLSCTX_DISABLE_AAA = 0x00008000 36 | CLSCTX_ENABLE_AAA = 0x00010000 37 | CLSCTX_FROM_DEFAULT_CONTEXT = 0x00020000 38 | CLSCTX_ACTIVATE_32_BIT_SERVER = 0x00040000 39 | CLSCTX_ACTIVATE_64_BIT_SERVER = 0x00080000 40 | CLSCTX_ENABLE_CLOAKING = 0x00100000 41 | CLSCTX_PS_DLL = 0x80000000 42 | ) 43 | 44 | const ( 45 | VARIANT_TRUE = -1 46 | VARIANT_FALSE = 0 47 | ) 48 | 49 | const ( 50 | VT_EMPTY = 0 51 | VT_NULL = 1 52 | VT_I2 = 2 53 | VT_I4 = 3 54 | VT_R4 = 4 55 | VT_R8 = 5 56 | VT_CY = 6 57 | VT_DATE = 7 58 | VT_BSTR = 8 59 | VT_DISPATCH = 9 60 | VT_ERROR = 10 61 | VT_BOOL = 11 62 | VT_VARIANT = 12 63 | VT_UNKNOWN = 13 64 | VT_DECIMAL = 14 65 | VT_I1 = 16 66 | VT_UI1 = 17 67 | VT_UI2 = 18 68 | VT_UI4 = 19 69 | VT_I8 = 20 70 | VT_UI8 = 21 71 | VT_INT = 22 72 | VT_UINT = 23 73 | VT_VOID = 24 74 | VT_HRESULT = 25 75 | VT_PTR = 26 76 | VT_SAFEARRAY = 27 77 | VT_CARRAY = 28 78 | VT_USERDEFINED = 29 79 | VT_LPSTR = 30 80 | VT_LPWSTR = 31 81 | VT_RECORD = 36 82 | VT_INT_PTR = 37 83 | VT_UINT_PTR = 38 84 | VT_FILETIME = 64 85 | VT_BLOB = 65 86 | VT_STREAM = 66 87 | VT_STORAGE = 67 88 | VT_STREAMED_OBJECT = 68 89 | VT_STORED_OBJECT = 69 90 | VT_BLOB_OBJECT = 70 91 | VT_CF = 71 92 | VT_CLSID = 72 93 | VT_VERSIONED_STREAM = 73 94 | VT_BSTR_BLOB = 0x0FFF 95 | VT_VECTOR = 0x1000 96 | VT_ARRAY = 0x2000 97 | VT_BYREF = 0x4000 98 | ) 99 | --------------------------------------------------------------------------------