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 procGetSidIdentifierAuthority = modadvapi32.NewProc("GetSidIdentifierAuthority")
53 procGetSidSubAuthority = modadvapi32.NewProc("GetSidSubAuthority")
54 procGetSidSubAuthorityCount = modadvapi32.NewProc("GetSidSubAuthorityCount")
55 procImpersonateLoggedOnUser = modadvapi32.NewProc("ImpersonateLoggedOnUser")
56 procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf")
57 procIsValidSid = modadvapi32.NewProc("IsValidSid")
58 procLogonUserW = modadvapi32.NewProc("LogonUserW")
59 procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW")
60 procOpenSCManagerW = modadvapi32.NewProc("OpenSCManagerW")
61 procOpenServiceW = modadvapi32.NewProc("OpenServiceW")
62 procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
63 procQueryServiceStatus = modadvapi32.NewProc("QueryServiceStatus")
64 procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
65 procSetEntriesInAclW = modadvapi32.NewProc("SetEntriesInAclW")
66 procSetNamedSecurityInfoW = modadvapi32.NewProc("SetNamedSecurityInfoW")
67 procSetTokenInformation = modadvapi32.NewProc("SetTokenInformation")
68 procProcessPrng = modbcryptprimitives.NewProc("ProcessPrng")
69 procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
70 procCreateEventW = modkernel32.NewProc("CreateEventW")
71 procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort")
72 procCreateNamedPipeW = modkernel32.NewProc("CreateNamedPipeW")
73 procGetACP = modkernel32.NewProc("GetACP")
74 procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
75 procGetConsoleCP = modkernel32.NewProc("GetConsoleCP")
76 procGetCurrentThread = modkernel32.NewProc("GetCurrentThread")
77 procGetFileInformationByHandleEx = modkernel32.NewProc("GetFileInformationByHandleEx")
78 procGetFileSizeEx = modkernel32.NewProc("GetFileSizeEx")
79 procGetFinalPathNameByHandleW = modkernel32.NewProc("GetFinalPathNameByHandleW")
80 procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW")
81 procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW")
82 procGetOverlappedResult = modkernel32.NewProc("GetOverlappedResult")
83 procGetTempPath2W = modkernel32.NewProc("GetTempPath2W")
84 procGetVolumeInformationByHandleW = modkernel32.NewProc("GetVolumeInformationByHandleW")
85 procGetVolumeNameForVolumeMountPointW = modkernel32.NewProc("GetVolumeNameForVolumeMountPointW")
86 procIsProcessorFeaturePresent = modkernel32.NewProc("IsProcessorFeaturePresent")
87 procLockFileEx = modkernel32.NewProc("LockFileEx")
88 procModule32FirstW = modkernel32.NewProc("Module32FirstW")
89 procModule32NextW = modkernel32.NewProc("Module32NextW")
90 procMoveFileExW = modkernel32.NewProc("MoveFileExW")
91 procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
92 procReOpenFile = modkernel32.NewProc("ReOpenFile")
93 procRtlLookupFunctionEntry = modkernel32.NewProc("RtlLookupFunctionEntry")
94 procRtlVirtualUnwind = modkernel32.NewProc("RtlVirtualUnwind")
95 procSetFileInformationByHandle = modkernel32.NewProc("SetFileInformationByHandle")
96 procUnlockFileEx = modkernel32.NewProc("UnlockFileEx")
97 procVirtualQuery = modkernel32.NewProc("VirtualQuery")
98 procNetShareAdd = modnetapi32.NewProc("NetShareAdd")
99 procNetShareDel = modnetapi32.NewProc("NetShareDel")
100 procNetUserAdd = modnetapi32.NewProc("NetUserAdd")
101 procNetUserDel = modnetapi32.NewProc("NetUserDel")
102 procNetUserGetLocalGroups = modnetapi32.NewProc("NetUserGetLocalGroups")
103 procNtCreateFile = modntdll.NewProc("NtCreateFile")
104 procNtOpenFile = modntdll.NewProc("NtOpenFile")
105 procNtQueryInformationFile = modntdll.NewProc("NtQueryInformationFile")
106 procNtSetInformationFile = modntdll.NewProc("NtSetInformationFile")
107 procRtlGetVersion = modntdll.NewProc("RtlGetVersion")
108 procRtlIsDosDeviceName_U = modntdll.NewProc("RtlIsDosDeviceName_U")
109 procRtlNtStatusToDosErrorNoTeb = modntdll.NewProc("RtlNtStatusToDosErrorNoTeb")
110 procGetProcessMemoryInfo = modpsapi.NewProc("GetProcessMemoryInfo")
111 procCreateEnvironmentBlock = moduserenv.NewProc("CreateEnvironmentBlock")
112 procDestroyEnvironmentBlock = moduserenv.NewProc("DestroyEnvironmentBlock")
113 procGetProfilesDirectoryW = moduserenv.NewProc("GetProfilesDirectoryW")
114 procWSADuplicateSocketW = modws2_32.NewProc("WSADuplicateSocketW")
115 procWSAGetOverlappedResult = modws2_32.NewProc("WSAGetOverlappedResult")
116 procWSASocketW = modws2_32.NewProc("WSASocketW")
117 )
118
119 func adjustTokenPrivileges(token syscall.Token, disableAllPrivileges bool, newstate *TOKEN_PRIVILEGES, buflen uint32, prevstate *TOKEN_PRIVILEGES, returnlen *uint32) (ret uint32, err error) {
120 var _p0 uint32
121 if disableAllPrivileges {
122 _p0 = 1
123 }
124 r0, _, e1 := syscall.SyscallN(procAdjustTokenPrivileges.Addr(), uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen)))
125 ret = uint32(r0)
126 if true {
127 err = errnoErr(e1)
128 }
129 return
130 }
131
132 func DuplicateTokenEx(hExistingToken syscall.Token, dwDesiredAccess uint32, lpTokenAttributes *syscall.SecurityAttributes, impersonationLevel uint32, tokenType TokenType, phNewToken *syscall.Token) (err error) {
133 r1, _, e1 := syscall.SyscallN(procDuplicateTokenEx.Addr(), uintptr(hExistingToken), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpTokenAttributes)), uintptr(impersonationLevel), uintptr(tokenType), uintptr(unsafe.Pointer(phNewToken)))
134 if r1 == 0 {
135 err = errnoErr(e1)
136 }
137 return
138 }
139
140 func getSidIdentifierAuthority(sid *syscall.SID) (idauth uintptr) {
141 r0, _, _ := syscall.SyscallN(procGetSidIdentifierAuthority.Addr(), uintptr(unsafe.Pointer(sid)))
142 idauth = uintptr(r0)
143 return
144 }
145
146 func getSidSubAuthority(sid *syscall.SID, subAuthorityIdx uint32) (subAuth uintptr) {
147 r0, _, _ := syscall.SyscallN(procGetSidSubAuthority.Addr(), uintptr(unsafe.Pointer(sid)), uintptr(subAuthorityIdx))
148 subAuth = uintptr(r0)
149 return
150 }
151
152 func getSidSubAuthorityCount(sid *syscall.SID) (count uintptr) {
153 r0, _, _ := syscall.SyscallN(procGetSidSubAuthorityCount.Addr(), uintptr(unsafe.Pointer(sid)))
154 count = uintptr(r0)
155 return
156 }
157
158 func ImpersonateLoggedOnUser(token syscall.Token) (err error) {
159 r1, _, e1 := syscall.SyscallN(procImpersonateLoggedOnUser.Addr(), uintptr(token))
160 if r1 == 0 {
161 err = errnoErr(e1)
162 }
163 return
164 }
165
166 func ImpersonateSelf(impersonationlevel uint32) (err error) {
167 r1, _, e1 := syscall.SyscallN(procImpersonateSelf.Addr(), uintptr(impersonationlevel))
168 if r1 == 0 {
169 err = errnoErr(e1)
170 }
171 return
172 }
173
174 func IsValidSid(sid *syscall.SID) (valid bool) {
175 r0, _, _ := syscall.SyscallN(procIsValidSid.Addr(), uintptr(unsafe.Pointer(sid)))
176 valid = r0 != 0
177 return
178 }
179
180 func LogonUser(username *uint16, domain *uint16, password *uint16, logonType uint32, logonProvider uint32, token *syscall.Token) (err error) {
181 r1, _, e1 := syscall.SyscallN(procLogonUserW.Addr(), uintptr(unsafe.Pointer(username)), uintptr(unsafe.Pointer(domain)), uintptr(unsafe.Pointer(password)), uintptr(logonType), uintptr(logonProvider), uintptr(unsafe.Pointer(token)))
182 if r1 == 0 {
183 err = errnoErr(e1)
184 }
185 return
186 }
187
188 func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) {
189 r1, _, e1 := syscall.SyscallN(procLookupPrivilegeValueW.Addr(), uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid)))
190 if r1 == 0 {
191 err = errnoErr(e1)
192 }
193 return
194 }
195
196 func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle syscall.Handle, err error) {
197 r0, _, e1 := syscall.SyscallN(procOpenSCManagerW.Addr(), uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(databaseName)), uintptr(access))
198 handle = syscall.Handle(r0)
199 if handle == 0 {
200 err = errnoErr(e1)
201 }
202 return
203 }
204
205 func OpenService(mgr syscall.Handle, serviceName *uint16, access uint32) (handle syscall.Handle, err error) {
206 r0, _, e1 := syscall.SyscallN(procOpenServiceW.Addr(), uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(access))
207 handle = syscall.Handle(r0)
208 if handle == 0 {
209 err = errnoErr(e1)
210 }
211 return
212 }
213
214 func OpenThreadToken(h syscall.Handle, access uint32, openasself bool, token *syscall.Token) (err error) {
215 var _p0 uint32
216 if openasself {
217 _p0 = 1
218 }
219 r1, _, e1 := syscall.SyscallN(procOpenThreadToken.Addr(), uintptr(h), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)))
220 if r1 == 0 {
221 err = errnoErr(e1)
222 }
223 return
224 }
225
226 func QueryServiceStatus(hService syscall.Handle, lpServiceStatus *SERVICE_STATUS) (err error) {
227 r1, _, e1 := syscall.SyscallN(procQueryServiceStatus.Addr(), uintptr(hService), uintptr(unsafe.Pointer(lpServiceStatus)))
228 if r1 == 0 {
229 err = errnoErr(e1)
230 }
231 return
232 }
233
234 func RevertToSelf() (err error) {
235 r1, _, e1 := syscall.SyscallN(procRevertToSelf.Addr())
236 if r1 == 0 {
237 err = errnoErr(e1)
238 }
239 return
240 }
241
242 func SetEntriesInAcl(countExplicitEntries uint32, explicitEntries *EXPLICIT_ACCESS, oldACL *ACL, newACL **ACL) (ret error) {
243 r0, _, _ := syscall.SyscallN(procSetEntriesInAclW.Addr(), uintptr(countExplicitEntries), uintptr(unsafe.Pointer(explicitEntries)), uintptr(unsafe.Pointer(oldACL)), uintptr(unsafe.Pointer(newACL)))
244 if r0 != 0 {
245 ret = syscall.Errno(r0)
246 }
247 return
248 }
249
250 func SetNamedSecurityInfo(objectName string, objectType uint32, securityInformation uint32, owner *syscall.SID, group *syscall.SID, dacl *ACL, sacl *ACL) (ret error) {
251 var _p0 *uint16
252 _p0, ret = syscall.UTF16PtrFromString(objectName)
253 if ret != nil {
254 return
255 }
256 return _SetNamedSecurityInfo(_p0, objectType, securityInformation, owner, group, dacl, sacl)
257 }
258
259 func _SetNamedSecurityInfo(objectName *uint16, objectType uint32, securityInformation uint32, owner *syscall.SID, group *syscall.SID, dacl *ACL, sacl *ACL) (ret error) {
260 r0, _, _ := syscall.SyscallN(procSetNamedSecurityInfoW.Addr(), uintptr(unsafe.Pointer(objectName)), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)))
261 if r0 != 0 {
262 ret = syscall.Errno(r0)
263 }
264 return
265 }
266
267 func SetTokenInformation(tokenHandle syscall.Token, tokenInformationClass uint32, tokenInformation unsafe.Pointer, tokenInformationLength uint32) (err error) {
268 r1, _, e1 := syscall.SyscallN(procSetTokenInformation.Addr(), uintptr(tokenHandle), uintptr(tokenInformationClass), uintptr(tokenInformation), uintptr(tokenInformationLength))
269 if r1 == 0 {
270 err = errnoErr(e1)
271 }
272 return
273 }
274
275 func ProcessPrng(buf []byte) (err error) {
276 var _p0 *byte
277 if len(buf) > 0 {
278 _p0 = &buf[0]
279 }
280 r1, _, e1 := syscall.SyscallN(procProcessPrng.Addr(), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)))
281 if r1 == 0 {
282 err = errnoErr(e1)
283 }
284 return
285 }
286
287 func GetAdaptersAddresses(family uint32, flags uint32, reserved unsafe.Pointer, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
288 r0, _, _ := syscall.SyscallN(procGetAdaptersAddresses.Addr(), uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)))
289 if r0 != 0 {
290 errcode = syscall.Errno(r0)
291 }
292 return
293 }
294
295 func CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle syscall.Handle, err error) {
296 r0, _, e1 := syscall.SyscallN(procCreateEventW.Addr(), uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name)))
297 handle = syscall.Handle(r0)
298 if handle == 0 {
299 err = errnoErr(e1)
300 }
301 return
302 }
303
304 func CreateIoCompletionPort(filehandle syscall.Handle, cphandle syscall.Handle, key uintptr, threadcnt uint32) (handle syscall.Handle, err error) {
305 r0, _, e1 := syscall.SyscallN(procCreateIoCompletionPort.Addr(), uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt))
306 handle = syscall.Handle(r0)
307 if handle == 0 {
308 err = errnoErr(e1)
309 }
310 return
311 }
312
313 func CreateNamedPipe(name *uint16, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) {
314 r0, _, e1 := syscall.SyscallN(procCreateNamedPipeW.Addr(), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(pipeMode), uintptr(maxInstances), uintptr(outSize), uintptr(inSize), uintptr(defaultTimeout), uintptr(unsafe.Pointer(sa)))
315 handle = syscall.Handle(r0)
316 if handle == syscall.InvalidHandle {
317 err = errnoErr(e1)
318 }
319 return
320 }
321
322 func GetACP() (acp uint32) {
323 r0, _, _ := syscall.SyscallN(procGetACP.Addr())
324 acp = uint32(r0)
325 return
326 }
327
328 func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) {
329 r1, _, e1 := syscall.SyscallN(procGetComputerNameExW.Addr(), uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
330 if r1 == 0 {
331 err = errnoErr(e1)
332 }
333 return
334 }
335
336 func GetConsoleCP() (ccp uint32) {
337 r0, _, _ := syscall.SyscallN(procGetConsoleCP.Addr())
338 ccp = uint32(r0)
339 return
340 }
341
342 func GetCurrentThread() (pseudoHandle syscall.Handle, err error) {
343 r0, _, e1 := syscall.SyscallN(procGetCurrentThread.Addr())
344 pseudoHandle = syscall.Handle(r0)
345 if pseudoHandle == 0 {
346 err = errnoErr(e1)
347 }
348 return
349 }
350
351 func GetFileInformationByHandleEx(handle syscall.Handle, class uint32, info *byte, bufsize uint32) (err error) {
352 r1, _, e1 := syscall.SyscallN(procGetFileInformationByHandleEx.Addr(), uintptr(handle), uintptr(class), uintptr(unsafe.Pointer(info)), uintptr(bufsize))
353 if r1 == 0 {
354 err = errnoErr(e1)
355 }
356 return
357 }
358
359 func GetFileSizeEx(handle syscall.Handle, size *int64) (err error) {
360 r1, _, e1 := syscall.SyscallN(procGetFileSizeEx.Addr(), uintptr(handle), uintptr(unsafe.Pointer(size)))
361 if r1 == 0 {
362 err = errnoErr(e1)
363 }
364 return
365 }
366
367 func GetFinalPathNameByHandle(file syscall.Handle, filePath *uint16, filePathSize uint32, flags uint32) (n uint32, err error) {
368 r0, _, e1 := syscall.SyscallN(procGetFinalPathNameByHandleW.Addr(), uintptr(file), uintptr(unsafe.Pointer(filePath)), uintptr(filePathSize), uintptr(flags))
369 n = uint32(r0)
370 if n == 0 {
371 err = errnoErr(e1)
372 }
373 return
374 }
375
376 func GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32, err error) {
377 r0, _, e1 := syscall.SyscallN(procGetModuleFileNameW.Addr(), uintptr(module), uintptr(unsafe.Pointer(fn)), uintptr(len))
378 n = uint32(r0)
379 if n == 0 {
380 err = errnoErr(e1)
381 }
382 return
383 }
384
385 func GetModuleHandle(modulename *uint16) (handle syscall.Handle, err error) {
386 r0, _, e1 := syscall.SyscallN(procGetModuleHandleW.Addr(), uintptr(unsafe.Pointer(modulename)))
387 handle = syscall.Handle(r0)
388 if handle == 0 {
389 err = errnoErr(e1)
390 }
391 return
392 }
393
394 func GetOverlappedResult(handle syscall.Handle, overlapped *syscall.Overlapped, done *uint32, wait bool) (err error) {
395 var _p0 uint32
396 if wait {
397 _p0 = 1
398 }
399 r1, _, e1 := syscall.SyscallN(procGetOverlappedResult.Addr(), uintptr(handle), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(done)), uintptr(_p0))
400 if r1 == 0 {
401 err = errnoErr(e1)
402 }
403 return
404 }
405
406 func GetTempPath2(buflen uint32, buf *uint16) (n uint32, err error) {
407 r0, _, e1 := syscall.SyscallN(procGetTempPath2W.Addr(), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
408 n = uint32(r0)
409 if n == 0 {
410 err = errnoErr(e1)
411 }
412 return
413 }
414
415 func GetVolumeInformationByHandle(file syscall.Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
416 r1, _, e1 := syscall.SyscallN(procGetVolumeInformationByHandleW.Addr(), 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))
417 if r1 == 0 {
418 err = errnoErr(e1)
419 }
420 return
421 }
422
423 func GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) {
424 r1, _, e1 := syscall.SyscallN(procGetVolumeNameForVolumeMountPointW.Addr(), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferlength))
425 if r1 == 0 {
426 err = errnoErr(e1)
427 }
428 return
429 }
430
431 func IsProcessorFeaturePresent(ProcessorFeature uint32) (ret bool) {
432 r0, _, _ := syscall.SyscallN(procIsProcessorFeaturePresent.Addr(), uintptr(ProcessorFeature))
433 ret = r0 != 0
434 return
435 }
436
437 func LockFileEx(file syscall.Handle, flags uint32, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *syscall.Overlapped) (err error) {
438 r1, _, e1 := syscall.SyscallN(procLockFileEx.Addr(), uintptr(file), uintptr(flags), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped)))
439 if r1 == 0 {
440 err = errnoErr(e1)
441 }
442 return
443 }
444
445 func Module32First(snapshot syscall.Handle, moduleEntry *ModuleEntry32) (err error) {
446 r1, _, e1 := syscall.SyscallN(procModule32FirstW.Addr(), uintptr(snapshot), uintptr(unsafe.Pointer(moduleEntry)))
447 if r1 == 0 {
448 err = errnoErr(e1)
449 }
450 return
451 }
452
453 func Module32Next(snapshot syscall.Handle, moduleEntry *ModuleEntry32) (err error) {
454 r1, _, e1 := syscall.SyscallN(procModule32NextW.Addr(), uintptr(snapshot), uintptr(unsafe.Pointer(moduleEntry)))
455 if r1 == 0 {
456 err = errnoErr(e1)
457 }
458 return
459 }
460
461 func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
462 r1, _, e1 := syscall.SyscallN(procMoveFileExW.Addr(), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
463 if r1 == 0 {
464 err = errnoErr(e1)
465 }
466 return
467 }
468
469 func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
470 r0, _, e1 := syscall.SyscallN(procMultiByteToWideChar.Addr(), uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
471 nwrite = int32(r0)
472 if nwrite == 0 {
473 err = errnoErr(e1)
474 }
475 return
476 }
477
478 func ReOpenFile(filehandle syscall.Handle, desiredAccess uint32, shareMode uint32, flagAndAttributes uint32) (handle syscall.Handle, err error) {
479 r0, _, e1 := syscall.SyscallN(procReOpenFile.Addr(), uintptr(filehandle), uintptr(desiredAccess), uintptr(shareMode), uintptr(flagAndAttributes))
480 handle = syscall.Handle(r0)
481 if handle == syscall.InvalidHandle {
482 err = errnoErr(e1)
483 }
484 return
485 }
486
487 func RtlLookupFunctionEntry(pc uintptr, baseAddress *uintptr, table unsafe.Pointer) (ret *RUNTIME_FUNCTION) {
488 r0, _, _ := syscall.SyscallN(procRtlLookupFunctionEntry.Addr(), uintptr(pc), uintptr(unsafe.Pointer(baseAddress)), uintptr(table))
489 ret = (*RUNTIME_FUNCTION)(unsafe.Pointer(r0))
490 return
491 }
492
493 func RtlVirtualUnwind(handlerType uint32, baseAddress uintptr, pc uintptr, entry *RUNTIME_FUNCTION, ctxt unsafe.Pointer, data unsafe.Pointer, frame *uintptr, ctxptrs unsafe.Pointer) (ret uintptr) {
494 r0, _, _ := syscall.SyscallN(procRtlVirtualUnwind.Addr(), uintptr(handlerType), uintptr(baseAddress), uintptr(pc), uintptr(unsafe.Pointer(entry)), uintptr(ctxt), uintptr(data), uintptr(unsafe.Pointer(frame)), uintptr(ctxptrs))
495 ret = uintptr(r0)
496 return
497 }
498
499 func SetFileInformationByHandle(handle syscall.Handle, fileInformationClass uint32, buf unsafe.Pointer, bufsize uint32) (err error) {
500 r1, _, e1 := syscall.SyscallN(procSetFileInformationByHandle.Addr(), uintptr(handle), uintptr(fileInformationClass), uintptr(buf), uintptr(bufsize))
501 if r1 == 0 {
502 err = errnoErr(e1)
503 }
504 return
505 }
506
507 func UnlockFileEx(file syscall.Handle, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *syscall.Overlapped) (err error) {
508 r1, _, e1 := syscall.SyscallN(procUnlockFileEx.Addr(), uintptr(file), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped)))
509 if r1 == 0 {
510 err = errnoErr(e1)
511 }
512 return
513 }
514
515 func VirtualQuery(address uintptr, buffer *MemoryBasicInformation, length uintptr) (err error) {
516 r1, _, e1 := syscall.SyscallN(procVirtualQuery.Addr(), uintptr(address), uintptr(unsafe.Pointer(buffer)), uintptr(length))
517 if r1 == 0 {
518 err = errnoErr(e1)
519 }
520 return
521 }
522
523 func NetShareAdd(serverName *uint16, level uint32, buf *byte, parmErr *uint16) (neterr error) {
524 r0, _, _ := syscall.SyscallN(procNetShareAdd.Addr(), uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(parmErr)))
525 if r0 != 0 {
526 neterr = syscall.Errno(r0)
527 }
528 return
529 }
530
531 func NetShareDel(serverName *uint16, netName *uint16, reserved uint32) (neterr error) {
532 r0, _, _ := syscall.SyscallN(procNetShareDel.Addr(), uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(netName)), uintptr(reserved))
533 if r0 != 0 {
534 neterr = syscall.Errno(r0)
535 }
536 return
537 }
538
539 func NetUserAdd(serverName *uint16, level uint32, buf *byte, parmErr *uint32) (neterr error) {
540 r0, _, _ := syscall.SyscallN(procNetUserAdd.Addr(), uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(parmErr)))
541 if r0 != 0 {
542 neterr = syscall.Errno(r0)
543 }
544 return
545 }
546
547 func NetUserDel(serverName *uint16, userName *uint16) (neterr error) {
548 r0, _, _ := syscall.SyscallN(procNetUserDel.Addr(), uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)))
549 if r0 != 0 {
550 neterr = syscall.Errno(r0)
551 }
552 return
553 }
554
555 func NetUserGetLocalGroups(serverName *uint16, userName *uint16, level uint32, flags uint32, buf **byte, prefMaxLen uint32, entriesRead *uint32, totalEntries *uint32) (neterr error) {
556 r0, _, _ := syscall.SyscallN(procNetUserGetLocalGroups.Addr(), 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)))
557 if r0 != 0 {
558 neterr = syscall.Errno(r0)
559 }
560 return
561 }
562
563 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 unsafe.Pointer, ealength uint32) (ntstatus error) {
564 r0, _, _ := syscall.SyscallN(procNtCreateFile.Addr(), 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))
565 if r0 != 0 {
566 ntstatus = NTStatus(r0)
567 }
568 return
569 }
570
571 func NtOpenFile(handle *syscall.Handle, access uint32, oa *OBJECT_ATTRIBUTES, iosb *IO_STATUS_BLOCK, share uint32, options uint32) (ntstatus error) {
572 r0, _, _ := syscall.SyscallN(procNtOpenFile.Addr(), uintptr(unsafe.Pointer(handle)), uintptr(access), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(share), uintptr(options))
573 if r0 != 0 {
574 ntstatus = NTStatus(r0)
575 }
576 return
577 }
578
579 func NtQueryInformationFile(handle syscall.Handle, iosb *IO_STATUS_BLOCK, inBuffer unsafe.Pointer, inBufferLen uint32, class uint32) (ntstatus error) {
580 r0, _, _ := syscall.SyscallN(procNtQueryInformationFile.Addr(), uintptr(handle), uintptr(unsafe.Pointer(iosb)), uintptr(inBuffer), uintptr(inBufferLen), uintptr(class))
581 if r0 != 0 {
582 ntstatus = NTStatus(r0)
583 }
584 return
585 }
586
587 func NtSetInformationFile(handle syscall.Handle, iosb *IO_STATUS_BLOCK, inBuffer unsafe.Pointer, inBufferLen uint32, class uint32) (ntstatus error) {
588 r0, _, _ := syscall.SyscallN(procNtSetInformationFile.Addr(), uintptr(handle), uintptr(unsafe.Pointer(iosb)), uintptr(inBuffer), uintptr(inBufferLen), uintptr(class))
589 if r0 != 0 {
590 ntstatus = NTStatus(r0)
591 }
592 return
593 }
594
595 func rtlGetVersion(info *_OSVERSIONINFOEXW) {
596 syscall.SyscallN(procRtlGetVersion.Addr(), uintptr(unsafe.Pointer(info)))
597 return
598 }
599
600 func RtlIsDosDeviceName_U(name *uint16) (ret uint32) {
601 r0, _, _ := syscall.SyscallN(procRtlIsDosDeviceName_U.Addr(), uintptr(unsafe.Pointer(name)))
602 ret = uint32(r0)
603 return
604 }
605
606 func rtlNtStatusToDosErrorNoTeb(ntstatus NTStatus) (ret syscall.Errno) {
607 r0, _, _ := syscall.SyscallN(procRtlNtStatusToDosErrorNoTeb.Addr(), uintptr(ntstatus))
608 ret = syscall.Errno(r0)
609 return
610 }
611
612 func GetProcessMemoryInfo(handle syscall.Handle, memCounters *PROCESS_MEMORY_COUNTERS, cb uint32) (err error) {
613 r1, _, e1 := syscall.SyscallN(procGetProcessMemoryInfo.Addr(), uintptr(handle), uintptr(unsafe.Pointer(memCounters)), uintptr(cb))
614 if r1 == 0 {
615 err = errnoErr(e1)
616 }
617 return
618 }
619
620 func CreateEnvironmentBlock(block **uint16, token syscall.Token, inheritExisting bool) (err error) {
621 var _p0 uint32
622 if inheritExisting {
623 _p0 = 1
624 }
625 r1, _, e1 := syscall.SyscallN(procCreateEnvironmentBlock.Addr(), uintptr(unsafe.Pointer(block)), uintptr(token), uintptr(_p0))
626 if r1 == 0 {
627 err = errnoErr(e1)
628 }
629 return
630 }
631
632 func DestroyEnvironmentBlock(block *uint16) (err error) {
633 r1, _, e1 := syscall.SyscallN(procDestroyEnvironmentBlock.Addr(), uintptr(unsafe.Pointer(block)))
634 if r1 == 0 {
635 err = errnoErr(e1)
636 }
637 return
638 }
639
640 func GetProfilesDirectory(dir *uint16, dirLen *uint32) (err error) {
641 r1, _, e1 := syscall.SyscallN(procGetProfilesDirectoryW.Addr(), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)))
642 if r1 == 0 {
643 err = errnoErr(e1)
644 }
645 return
646 }
647
648 func WSADuplicateSocket(s syscall.Handle, processID uint32, info *syscall.WSAProtocolInfo) (err error) {
649 r1, _, e1 := syscall.SyscallN(procWSADuplicateSocketW.Addr(), uintptr(s), uintptr(processID), uintptr(unsafe.Pointer(info)))
650 if r1 != 0 {
651 err = errnoErr(e1)
652 }
653 return
654 }
655
656 func WSAGetOverlappedResult(h syscall.Handle, o *syscall.Overlapped, bytes *uint32, wait bool, flags *uint32) (err error) {
657 var _p0 uint32
658 if wait {
659 _p0 = 1
660 }
661 r1, _, e1 := syscall.SyscallN(procWSAGetOverlappedResult.Addr(), uintptr(h), uintptr(unsafe.Pointer(o)), uintptr(unsafe.Pointer(bytes)), uintptr(_p0), uintptr(unsafe.Pointer(flags)))
662 if r1 == 0 {
663 err = errnoErr(e1)
664 }
665 return
666 }
667
668 func WSASocket(af int32, typ int32, protocol int32, protinfo *syscall.WSAProtocolInfo, group uint32, flags uint32) (handle syscall.Handle, err error) {
669 r0, _, e1 := syscall.SyscallN(procWSASocketW.Addr(), uintptr(af), uintptr(typ), uintptr(protocol), uintptr(unsafe.Pointer(protinfo)), uintptr(group), uintptr(flags))
670 handle = syscall.Handle(r0)
671 if handle == syscall.InvalidHandle {
672 err = errnoErr(e1)
673 }
674 return
675 }
676
View as plain text