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