1
2
3 package windows
4
5 import (
6 "internal/syscall/windows/sysdll"
7 "syscall"
8 "unsafe"
9 )
10
11 var _ unsafe.Pointer
12
13
14
15 const (
16 errnoERROR_IO_PENDING = 997
17 )
18
19 var (
20 errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
21 errERROR_EINVAL error = syscall.EINVAL
22 )
23
24
25
26 func errnoErr(e syscall.Errno) error {
27 switch e {
28 case 0:
29 return errERROR_EINVAL
30 case errnoERROR_IO_PENDING:
31 return errERROR_IO_PENDING
32 }
33
34
35
36 return e
37 }
38
39 var (
40 modadvapi32 = syscall.NewLazyDLL(sysdll.Add("advapi32.dll"))
41 modbcryptprimitives = syscall.NewLazyDLL(sysdll.Add("bcryptprimitives.dll"))
42 modiphlpapi = syscall.NewLazyDLL(sysdll.Add("iphlpapi.dll"))
43 modkernel32 = syscall.NewLazyDLL(sysdll.Add("kernel32.dll"))
44 modnetapi32 = syscall.NewLazyDLL(sysdll.Add("netapi32.dll"))
45 modntdll = syscall.NewLazyDLL(sysdll.Add("ntdll.dll"))
46 modpsapi = syscall.NewLazyDLL(sysdll.Add("psapi.dll"))
47 moduserenv = syscall.NewLazyDLL(sysdll.Add("userenv.dll"))
48 modws2_32 = syscall.NewLazyDLL(sysdll.Add("ws2_32.dll"))
49
50 procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges")
51 procDuplicateTokenEx = modadvapi32.NewProc("DuplicateTokenEx")
52 procImpersonateLoggedOnUser = modadvapi32.NewProc("ImpersonateLoggedOnUser")
53 procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf")
54 procLogonUserW = modadvapi32.NewProc("LogonUserW")
55 procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW")
56 procOpenSCManagerW = modadvapi32.NewProc("OpenSCManagerW")
57 procOpenServiceW = modadvapi32.NewProc("OpenServiceW")
58 procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
59 procQueryServiceStatus = modadvapi32.NewProc("QueryServiceStatus")
60 procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
61 procSetTokenInformation = modadvapi32.NewProc("SetTokenInformation")
62 procProcessPrng = modbcryptprimitives.NewProc("ProcessPrng")
63 procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
64 procCreateEventW = modkernel32.NewProc("CreateEventW")
65 procGetACP = modkernel32.NewProc("GetACP")
66 procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
67 procGetConsoleCP = modkernel32.NewProc("GetConsoleCP")
68 procGetCurrentThread = modkernel32.NewProc("GetCurrentThread")
69 procGetFileInformationByHandleEx = modkernel32.NewProc("GetFileInformationByHandleEx")
70 procGetFinalPathNameByHandleW = modkernel32.NewProc("GetFinalPathNameByHandleW")
71 procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW")
72 procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW")
73 procGetTempPath2W = modkernel32.NewProc("GetTempPath2W")
74 procGetVolumeInformationByHandleW = modkernel32.NewProc("GetVolumeInformationByHandleW")
75 procGetVolumeNameForVolumeMountPointW = modkernel32.NewProc("GetVolumeNameForVolumeMountPointW")
76 procLockFileEx = modkernel32.NewProc("LockFileEx")
77 procModule32FirstW = modkernel32.NewProc("Module32FirstW")
78 procModule32NextW = modkernel32.NewProc("Module32NextW")
79 procMoveFileExW = modkernel32.NewProc("MoveFileExW")
80 procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
81 procRtlLookupFunctionEntry = modkernel32.NewProc("RtlLookupFunctionEntry")
82 procRtlVirtualUnwind = modkernel32.NewProc("RtlVirtualUnwind")
83 procSetFileInformationByHandle = modkernel32.NewProc("SetFileInformationByHandle")
84 procUnlockFileEx = modkernel32.NewProc("UnlockFileEx")
85 procVirtualQuery = modkernel32.NewProc("VirtualQuery")
86 procNetShareAdd = modnetapi32.NewProc("NetShareAdd")
87 procNetShareDel = modnetapi32.NewProc("NetShareDel")
88 procNetUserAdd = modnetapi32.NewProc("NetUserAdd")
89 procNetUserDel = modnetapi32.NewProc("NetUserDel")
90 procNetUserGetLocalGroups = modnetapi32.NewProc("NetUserGetLocalGroups")
91 procNtCreateFile = modntdll.NewProc("NtCreateFile")
92 procRtlGetVersion = modntdll.NewProc("RtlGetVersion")
93 procRtlNtStatusToDosErrorNoTeb = modntdll.NewProc("RtlNtStatusToDosErrorNoTeb")
94 procGetProcessMemoryInfo = modpsapi.NewProc("GetProcessMemoryInfo")
95 procCreateEnvironmentBlock = moduserenv.NewProc("CreateEnvironmentBlock")
96 procDestroyEnvironmentBlock = moduserenv.NewProc("DestroyEnvironmentBlock")
97 procGetProfilesDirectoryW = moduserenv.NewProc("GetProfilesDirectoryW")
98 procWSAGetOverlappedResult = modws2_32.NewProc("WSAGetOverlappedResult")
99 procWSASocketW = modws2_32.NewProc("WSASocketW")
100 )
101
102 func adjustTokenPrivileges(token syscall.Token, disableAllPrivileges bool, newstate *TOKEN_PRIVILEGES, buflen uint32, prevstate *TOKEN_PRIVILEGES, returnlen *uint32) (ret uint32, err error) {
103 var _p0 uint32
104 if disableAllPrivileges {
105 _p0 = 1
106 }
107 r0, _, e1 := syscall.Syscall6(procAdjustTokenPrivileges.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen)))
108 ret = uint32(r0)
109 if true {
110 err = errnoErr(e1)
111 }
112 return
113 }
114
115 func DuplicateTokenEx(hExistingToken syscall.Token, dwDesiredAccess uint32, lpTokenAttributes *syscall.SecurityAttributes, impersonationLevel uint32, tokenType TokenType, phNewToken *syscall.Token) (err error) {
116 r1, _, e1 := syscall.Syscall6(procDuplicateTokenEx.Addr(), 6, uintptr(hExistingToken), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpTokenAttributes)), uintptr(impersonationLevel), uintptr(tokenType), uintptr(unsafe.Pointer(phNewToken)))
117 if r1 == 0 {
118 err = errnoErr(e1)
119 }
120 return
121 }
122
123 func ImpersonateLoggedOnUser(token syscall.Token) (err error) {
124 r1, _, e1 := syscall.Syscall(procImpersonateLoggedOnUser.Addr(), 1, uintptr(token), 0, 0)
125 if r1 == 0 {
126 err = errnoErr(e1)
127 }
128 return
129 }
130
131 func ImpersonateSelf(impersonationlevel uint32) (err error) {
132 r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0)
133 if r1 == 0 {
134 err = errnoErr(e1)
135 }
136 return
137 }
138
139 func LogonUser(username *uint16, domain *uint16, password *uint16, logonType uint32, logonProvider uint32, token *syscall.Token) (err error) {
140 r1, _, e1 := syscall.Syscall6(procLogonUserW.Addr(), 6, uintptr(unsafe.Pointer(username)), uintptr(unsafe.Pointer(domain)), uintptr(unsafe.Pointer(password)), uintptr(logonType), uintptr(logonProvider), uintptr(unsafe.Pointer(token)))
141 if r1 == 0 {
142 err = errnoErr(e1)
143 }
144 return
145 }
146
147 func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) {
148 r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid)))
149 if r1 == 0 {
150 err = errnoErr(e1)
151 }
152 return
153 }
154
155 func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle syscall.Handle, err error) {
156 r0, _, e1 := syscall.Syscall(procOpenSCManagerW.Addr(), 3, uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(databaseName)), uintptr(access))
157 handle = syscall.Handle(r0)
158 if handle == 0 {
159 err = errnoErr(e1)
160 }
161 return
162 }
163
164 func OpenService(mgr syscall.Handle, serviceName *uint16, access uint32) (handle syscall.Handle, err error) {
165 r0, _, e1 := syscall.Syscall(procOpenServiceW.Addr(), 3, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(access))
166 handle = syscall.Handle(r0)
167 if handle == 0 {
168 err = errnoErr(e1)
169 }
170 return
171 }
172
173 func OpenThreadToken(h syscall.Handle, access uint32, openasself bool, token *syscall.Token) (err error) {
174 var _p0 uint32
175 if openasself {
176 _p0 = 1
177 }
178 r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(h), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0)
179 if r1 == 0 {
180 err = errnoErr(e1)
181 }
182 return
183 }
184
185 func QueryServiceStatus(hService syscall.Handle, lpServiceStatus *SERVICE_STATUS) (err error) {
186 r1, _, e1 := syscall.Syscall(procQueryServiceStatus.Addr(), 2, uintptr(hService), uintptr(unsafe.Pointer(lpServiceStatus)), 0)
187 if r1 == 0 {
188 err = errnoErr(e1)
189 }
190 return
191 }
192
193 func RevertToSelf() (err error) {
194 r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0)
195 if r1 == 0 {
196 err = errnoErr(e1)
197 }
198 return
199 }
200
201 func SetTokenInformation(tokenHandle syscall.Token, tokenInformationClass uint32, tokenInformation uintptr, tokenInformationLength uint32) (err error) {
202 r1, _, e1 := syscall.Syscall6(procSetTokenInformation.Addr(), 4, uintptr(tokenHandle), uintptr(tokenInformationClass), uintptr(tokenInformation), uintptr(tokenInformationLength), 0, 0)
203 if r1 == 0 {
204 err = errnoErr(e1)
205 }
206 return
207 }
208
209 func ProcessPrng(buf []byte) (err error) {
210 var _p0 *byte
211 if len(buf) > 0 {
212 _p0 = &buf[0]
213 }
214 r1, _, e1 := syscall.Syscall(procProcessPrng.Addr(), 2, uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), 0)
215 if r1 == 0 {
216 err = errnoErr(e1)
217 }
218 return
219 }
220
221 func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
222 r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
223 if r0 != 0 {
224 errcode = syscall.Errno(r0)
225 }
226 return
227 }
228
229 func CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle syscall.Handle, err error) {
230 r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name)), 0, 0)
231 handle = syscall.Handle(r0)
232 if handle == 0 {
233 err = errnoErr(e1)
234 }
235 return
236 }
237
238 func GetACP() (acp uint32) {
239 r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
240 acp = uint32(r0)
241 return
242 }
243
244 func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) {
245 r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
246 if r1 == 0 {
247 err = errnoErr(e1)
248 }
249 return
250 }
251
252 func GetConsoleCP() (ccp uint32) {
253 r0, _, _ := syscall.Syscall(procGetConsoleCP.Addr(), 0, 0, 0, 0)
254 ccp = uint32(r0)
255 return
256 }
257
258 func GetCurrentThread() (pseudoHandle syscall.Handle, err error) {
259 r0, _, e1 := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0)
260 pseudoHandle = syscall.Handle(r0)
261 if pseudoHandle == 0 {
262 err = errnoErr(e1)
263 }
264 return
265 }
266
267 func GetFileInformationByHandleEx(handle syscall.Handle, class uint32, info *byte, bufsize uint32) (err error) {
268 r1, _, e1 := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(), 4, uintptr(handle), uintptr(class), uintptr(unsafe.Pointer(info)), uintptr(bufsize), 0, 0)
269 if r1 == 0 {
270 err = errnoErr(e1)
271 }
272 return
273 }
274
275 func GetFinalPathNameByHandle(file syscall.Handle, filePath *uint16, filePathSize uint32, flags uint32) (n uint32, err error) {
276 r0, _, e1 := syscall.Syscall6(procGetFinalPathNameByHandleW.Addr(), 4, uintptr(file), uintptr(unsafe.Pointer(filePath)), uintptr(filePathSize), uintptr(flags), 0, 0)
277 n = uint32(r0)
278 if n == 0 {
279 err = errnoErr(e1)
280 }
281 return
282 }
283
284 func GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32, err error) {
285 r0, _, e1 := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, uintptr(module), uintptr(unsafe.Pointer(fn)), uintptr(len))
286 n = uint32(r0)
287 if n == 0 {
288 err = errnoErr(e1)
289 }
290 return
291 }
292
293 func GetModuleHandle(modulename *uint16) (handle syscall.Handle, err error) {
294 r0, _, e1 := syscall.Syscall(procGetModuleHandleW.Addr(), 1, uintptr(unsafe.Pointer(modulename)), 0, 0)
295 handle = syscall.Handle(r0)
296 if handle == 0 {
297 err = errnoErr(e1)
298 }
299 return
300 }
301
302 func GetTempPath2(buflen uint32, buf *uint16) (n uint32, err error) {
303 r0, _, e1 := syscall.Syscall(procGetTempPath2W.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
304 n = uint32(r0)
305 if n == 0 {
306 err = errnoErr(e1)
307 }
308 return
309 }
310
311 func GetVolumeInformationByHandle(file syscall.Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
312 r1, _, e1 := syscall.Syscall9(procGetVolumeInformationByHandleW.Addr(), 8, uintptr(file), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize), 0)
313 if r1 == 0 {
314 err = errnoErr(e1)
315 }
316 return
317 }
318
319 func GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) {
320 r1, _, e1 := syscall.Syscall(procGetVolumeNameForVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferlength))
321 if r1 == 0 {
322 err = errnoErr(e1)
323 }
324 return
325 }
326
327 func LockFileEx(file syscall.Handle, flags uint32, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *syscall.Overlapped) (err error) {
328 r1, _, e1 := syscall.Syscall6(procLockFileEx.Addr(), 6, uintptr(file), uintptr(flags), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped)))
329 if r1 == 0 {
330 err = errnoErr(e1)
331 }
332 return
333 }
334
335 func Module32First(snapshot syscall.Handle, moduleEntry *ModuleEntry32) (err error) {
336 r1, _, e1 := syscall.Syscall(procModule32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(moduleEntry)), 0)
337 if r1 == 0 {
338 err = errnoErr(e1)
339 }
340 return
341 }
342
343 func Module32Next(snapshot syscall.Handle, moduleEntry *ModuleEntry32) (err error) {
344 r1, _, e1 := syscall.Syscall(procModule32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(moduleEntry)), 0)
345 if r1 == 0 {
346 err = errnoErr(e1)
347 }
348 return
349 }
350
351 func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
352 r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
353 if r1 == 0 {
354 err = errnoErr(e1)
355 }
356 return
357 }
358
359 func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
360 r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
361 nwrite = int32(r0)
362 if nwrite == 0 {
363 err = errnoErr(e1)
364 }
365 return
366 }
367
368 func RtlLookupFunctionEntry(pc uintptr, baseAddress *uintptr, table *byte) (ret uintptr) {
369 r0, _, _ := syscall.Syscall(procRtlLookupFunctionEntry.Addr(), 3, uintptr(pc), uintptr(unsafe.Pointer(baseAddress)), uintptr(unsafe.Pointer(table)))
370 ret = uintptr(r0)
371 return
372 }
373
374 func RtlVirtualUnwind(handlerType uint32, baseAddress uintptr, pc uintptr, entry uintptr, ctxt uintptr, data *uintptr, frame *uintptr, ctxptrs *byte) (ret uintptr) {
375 r0, _, _ := syscall.Syscall9(procRtlVirtualUnwind.Addr(), 8, uintptr(handlerType), uintptr(baseAddress), uintptr(pc), uintptr(entry), uintptr(ctxt), uintptr(unsafe.Pointer(data)), uintptr(unsafe.Pointer(frame)), uintptr(unsafe.Pointer(ctxptrs)), 0)
376 ret = uintptr(r0)
377 return
378 }
379
380 func SetFileInformationByHandle(handle syscall.Handle, fileInformationClass uint32, buf unsafe.Pointer, bufsize uint32) (err error) {
381 r1, _, e1 := syscall.Syscall6(procSetFileInformationByHandle.Addr(), 4, uintptr(handle), uintptr(fileInformationClass), uintptr(buf), uintptr(bufsize), 0, 0)
382 if r1 == 0 {
383 err = errnoErr(e1)
384 }
385 return
386 }
387
388 func UnlockFileEx(file syscall.Handle, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *syscall.Overlapped) (err error) {
389 r1, _, e1 := syscall.Syscall6(procUnlockFileEx.Addr(), 5, uintptr(file), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped)), 0)
390 if r1 == 0 {
391 err = errnoErr(e1)
392 }
393 return
394 }
395
396 func VirtualQuery(address uintptr, buffer *MemoryBasicInformation, length uintptr) (err error) {
397 r1, _, e1 := syscall.Syscall(procVirtualQuery.Addr(), 3, uintptr(address), uintptr(unsafe.Pointer(buffer)), uintptr(length))
398 if r1 == 0 {
399 err = errnoErr(e1)
400 }
401 return
402 }
403
404 func NetShareAdd(serverName *uint16, level uint32, buf *byte, parmErr *uint16) (neterr error) {
405 r0, _, _ := syscall.Syscall6(procNetShareAdd.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(parmErr)), 0, 0)
406 if r0 != 0 {
407 neterr = syscall.Errno(r0)
408 }
409 return
410 }
411
412 func NetShareDel(serverName *uint16, netName *uint16, reserved uint32) (neterr error) {
413 r0, _, _ := syscall.Syscall(procNetShareDel.Addr(), 3, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(netName)), uintptr(reserved))
414 if r0 != 0 {
415 neterr = syscall.Errno(r0)
416 }
417 return
418 }
419
420 func NetUserAdd(serverName *uint16, level uint32, buf *byte, parmErr *uint32) (neterr error) {
421 r0, _, _ := syscall.Syscall6(procNetUserAdd.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(parmErr)), 0, 0)
422 if r0 != 0 {
423 neterr = syscall.Errno(r0)
424 }
425 return
426 }
427
428 func NetUserDel(serverName *uint16, userName *uint16) (neterr error) {
429 r0, _, _ := syscall.Syscall(procNetUserDel.Addr(), 2, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), 0)
430 if r0 != 0 {
431 neterr = syscall.Errno(r0)
432 }
433 return
434 }
435
436 func NetUserGetLocalGroups(serverName *uint16, userName *uint16, level uint32, flags uint32, buf **byte, prefMaxLen uint32, entriesRead *uint32, totalEntries *uint32) (neterr error) {
437 r0, _, _ := syscall.Syscall9(procNetUserGetLocalGroups.Addr(), 8, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(flags), uintptr(unsafe.Pointer(buf)), uintptr(prefMaxLen), uintptr(unsafe.Pointer(entriesRead)), uintptr(unsafe.Pointer(totalEntries)), 0)
438 if r0 != 0 {
439 neterr = syscall.Errno(r0)
440 }
441 return
442 }
443
444 func NtCreateFile(handle *syscall.Handle, access uint32, oa *OBJECT_ATTRIBUTES, iosb *IO_STATUS_BLOCK, allocationSize *int64, attributes uint32, share uint32, disposition uint32, options uint32, eabuffer uintptr, ealength uint32) (ntstatus error) {
445 r0, _, _ := syscall.Syscall12(procNtCreateFile.Addr(), 11, uintptr(unsafe.Pointer(handle)), uintptr(access), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(unsafe.Pointer(allocationSize)), uintptr(attributes), uintptr(share), uintptr(disposition), uintptr(options), uintptr(eabuffer), uintptr(ealength), 0)
446 if r0 != 0 {
447 ntstatus = NTStatus(r0)
448 }
449 return
450 }
451
452 func rtlGetVersion(info *_OSVERSIONINFOW) {
453 syscall.Syscall(procRtlGetVersion.Addr(), 1, uintptr(unsafe.Pointer(info)), 0, 0)
454 return
455 }
456
457 func rtlNtStatusToDosErrorNoTeb(ntstatus NTStatus) (ret syscall.Errno) {
458 r0, _, _ := syscall.Syscall(procRtlNtStatusToDosErrorNoTeb.Addr(), 1, uintptr(ntstatus), 0, 0)
459 ret = syscall.Errno(r0)
460 return
461 }
462
463 func GetProcessMemoryInfo(handle syscall.Handle, memCounters *PROCESS_MEMORY_COUNTERS, cb uint32) (err error) {
464 r1, _, e1 := syscall.Syscall(procGetProcessMemoryInfo.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(memCounters)), uintptr(cb))
465 if r1 == 0 {
466 err = errnoErr(e1)
467 }
468 return
469 }
470
471 func CreateEnvironmentBlock(block **uint16, token syscall.Token, inheritExisting bool) (err error) {
472 var _p0 uint32
473 if inheritExisting {
474 _p0 = 1
475 }
476 r1, _, e1 := syscall.Syscall(procCreateEnvironmentBlock.Addr(), 3, uintptr(unsafe.Pointer(block)), uintptr(token), uintptr(_p0))
477 if r1 == 0 {
478 err = errnoErr(e1)
479 }
480 return
481 }
482
483 func DestroyEnvironmentBlock(block *uint16) (err error) {
484 r1, _, e1 := syscall.Syscall(procDestroyEnvironmentBlock.Addr(), 1, uintptr(unsafe.Pointer(block)), 0, 0)
485 if r1 == 0 {
486 err = errnoErr(e1)
487 }
488 return
489 }
490
491 func GetProfilesDirectory(dir *uint16, dirLen *uint32) (err error) {
492 r1, _, e1 := syscall.Syscall(procGetProfilesDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)), 0)
493 if r1 == 0 {
494 err = errnoErr(e1)
495 }
496 return
497 }
498
499 func WSAGetOverlappedResult(h syscall.Handle, o *syscall.Overlapped, bytes *uint32, wait bool, flags *uint32) (err error) {
500 var _p0 uint32
501 if wait {
502 _p0 = 1
503 }
504 r1, _, e1 := syscall.Syscall6(procWSAGetOverlappedResult.Addr(), 5, uintptr(h), uintptr(unsafe.Pointer(o)), uintptr(unsafe.Pointer(bytes)), uintptr(_p0), uintptr(unsafe.Pointer(flags)), 0)
505 if r1 == 0 {
506 err = errnoErr(e1)
507 }
508 return
509 }
510
511 func WSASocket(af int32, typ int32, protocol int32, protinfo *syscall.WSAProtocolInfo, group uint32, flags uint32) (handle syscall.Handle, err error) {
512 r0, _, e1 := syscall.Syscall6(procWSASocketW.Addr(), 6, uintptr(af), uintptr(typ), uintptr(protocol), uintptr(unsafe.Pointer(protinfo)), uintptr(group), uintptr(flags))
513 handle = syscall.Handle(r0)
514 if handle == syscall.InvalidHandle {
515 err = errnoErr(e1)
516 }
517 return
518 }
519
View as plain text