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