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