zsyscall_windows.go 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010
  1. // Code generated by 'go generate'; DO NOT EDIT.
  2. package windows
  3. import (
  4. "syscall"
  5. "unsafe"
  6. )
  7. var _ unsafe.Pointer
  8. // Do the interface allocations only once for common
  9. // Errno values.
  10. const (
  11. errnoERROR_IO_PENDING = 997
  12. )
  13. var (
  14. errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
  15. )
  16. // errnoErr returns common boxed Errno values, to prevent
  17. // allocations at runtime.
  18. func errnoErr(e syscall.Errno) error {
  19. switch e {
  20. case 0:
  21. return nil
  22. case errnoERROR_IO_PENDING:
  23. return errERROR_IO_PENDING
  24. }
  25. // TODO: add more here, after collecting data on the common
  26. // error values see on Windows. (perhaps when running
  27. // all.bat?)
  28. return e
  29. }
  30. var (
  31. modadvapi32 = NewLazySystemDLL("advapi32.dll")
  32. modkernel32 = NewLazySystemDLL("kernel32.dll")
  33. moduserenv = NewLazySystemDLL("userenv.dll")
  34. modshell32 = NewLazySystemDLL("shell32.dll")
  35. modmswsock = NewLazySystemDLL("mswsock.dll")
  36. modcrypt32 = NewLazySystemDLL("crypt32.dll")
  37. modws2_32 = NewLazySystemDLL("ws2_32.dll")
  38. moddnsapi = NewLazySystemDLL("dnsapi.dll")
  39. modiphlpapi = NewLazySystemDLL("iphlpapi.dll")
  40. modsecur32 = NewLazySystemDLL("secur32.dll")
  41. modnetapi32 = NewLazySystemDLL("netapi32.dll")
  42. modwtsapi32 = NewLazySystemDLL("wtsapi32.dll")
  43. procRegisterEventSourceW = modadvapi32.NewProc("RegisterEventSourceW")
  44. procDeregisterEventSource = modadvapi32.NewProc("DeregisterEventSource")
  45. procReportEventW = modadvapi32.NewProc("ReportEventW")
  46. procOpenSCManagerW = modadvapi32.NewProc("OpenSCManagerW")
  47. procCloseServiceHandle = modadvapi32.NewProc("CloseServiceHandle")
  48. procCreateServiceW = modadvapi32.NewProc("CreateServiceW")
  49. procOpenServiceW = modadvapi32.NewProc("OpenServiceW")
  50. procDeleteService = modadvapi32.NewProc("DeleteService")
  51. procStartServiceW = modadvapi32.NewProc("StartServiceW")
  52. procQueryServiceStatus = modadvapi32.NewProc("QueryServiceStatus")
  53. procControlService = modadvapi32.NewProc("ControlService")
  54. procStartServiceCtrlDispatcherW = modadvapi32.NewProc("StartServiceCtrlDispatcherW")
  55. procSetServiceStatus = modadvapi32.NewProc("SetServiceStatus")
  56. procChangeServiceConfigW = modadvapi32.NewProc("ChangeServiceConfigW")
  57. procQueryServiceConfigW = modadvapi32.NewProc("QueryServiceConfigW")
  58. procChangeServiceConfig2W = modadvapi32.NewProc("ChangeServiceConfig2W")
  59. procQueryServiceConfig2W = modadvapi32.NewProc("QueryServiceConfig2W")
  60. procEnumServicesStatusExW = modadvapi32.NewProc("EnumServicesStatusExW")
  61. procQueryServiceStatusEx = modadvapi32.NewProc("QueryServiceStatusEx")
  62. procNotifyServiceStatusChangeW = modadvapi32.NewProc("NotifyServiceStatusChangeW")
  63. procGetLastError = modkernel32.NewProc("GetLastError")
  64. procLoadLibraryW = modkernel32.NewProc("LoadLibraryW")
  65. procLoadLibraryExW = modkernel32.NewProc("LoadLibraryExW")
  66. procFreeLibrary = modkernel32.NewProc("FreeLibrary")
  67. procGetProcAddress = modkernel32.NewProc("GetProcAddress")
  68. procGetVersion = modkernel32.NewProc("GetVersion")
  69. procFormatMessageW = modkernel32.NewProc("FormatMessageW")
  70. procExitProcess = modkernel32.NewProc("ExitProcess")
  71. procCreateFileW = modkernel32.NewProc("CreateFileW")
  72. procReadFile = modkernel32.NewProc("ReadFile")
  73. procWriteFile = modkernel32.NewProc("WriteFile")
  74. procGetOverlappedResult = modkernel32.NewProc("GetOverlappedResult")
  75. procSetFilePointer = modkernel32.NewProc("SetFilePointer")
  76. procCloseHandle = modkernel32.NewProc("CloseHandle")
  77. procGetStdHandle = modkernel32.NewProc("GetStdHandle")
  78. procSetStdHandle = modkernel32.NewProc("SetStdHandle")
  79. procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
  80. procFindNextFileW = modkernel32.NewProc("FindNextFileW")
  81. procFindClose = modkernel32.NewProc("FindClose")
  82. procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle")
  83. procGetFileInformationByHandleEx = modkernel32.NewProc("GetFileInformationByHandleEx")
  84. procGetCurrentDirectoryW = modkernel32.NewProc("GetCurrentDirectoryW")
  85. procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW")
  86. procCreateDirectoryW = modkernel32.NewProc("CreateDirectoryW")
  87. procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
  88. procDeleteFileW = modkernel32.NewProc("DeleteFileW")
  89. procMoveFileW = modkernel32.NewProc("MoveFileW")
  90. procMoveFileExW = modkernel32.NewProc("MoveFileExW")
  91. procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
  92. procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
  93. procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
  94. procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
  95. procGetSystemTimePreciseAsFileTime = modkernel32.NewProc("GetSystemTimePreciseAsFileTime")
  96. procGetTimeZoneInformation = modkernel32.NewProc("GetTimeZoneInformation")
  97. procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort")
  98. procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus")
  99. procPostQueuedCompletionStatus = modkernel32.NewProc("PostQueuedCompletionStatus")
  100. procCancelIo = modkernel32.NewProc("CancelIo")
  101. procCancelIoEx = modkernel32.NewProc("CancelIoEx")
  102. procCreateProcessW = modkernel32.NewProc("CreateProcessW")
  103. procOpenProcess = modkernel32.NewProc("OpenProcess")
  104. procTerminateProcess = modkernel32.NewProc("TerminateProcess")
  105. procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess")
  106. procGetStartupInfoW = modkernel32.NewProc("GetStartupInfoW")
  107. procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess")
  108. procGetCurrentThread = modkernel32.NewProc("GetCurrentThread")
  109. procGetProcessTimes = modkernel32.NewProc("GetProcessTimes")
  110. procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
  111. procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject")
  112. procWaitForMultipleObjects = modkernel32.NewProc("WaitForMultipleObjects")
  113. procGetTempPathW = modkernel32.NewProc("GetTempPathW")
  114. procCreatePipe = modkernel32.NewProc("CreatePipe")
  115. procGetFileType = modkernel32.NewProc("GetFileType")
  116. procCryptAcquireContextW = modadvapi32.NewProc("CryptAcquireContextW")
  117. procCryptReleaseContext = modadvapi32.NewProc("CryptReleaseContext")
  118. procCryptGenRandom = modadvapi32.NewProc("CryptGenRandom")
  119. procGetEnvironmentStringsW = modkernel32.NewProc("GetEnvironmentStringsW")
  120. procFreeEnvironmentStringsW = modkernel32.NewProc("FreeEnvironmentStringsW")
  121. procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW")
  122. procSetEnvironmentVariableW = modkernel32.NewProc("SetEnvironmentVariableW")
  123. procCreateEnvironmentBlock = moduserenv.NewProc("CreateEnvironmentBlock")
  124. procDestroyEnvironmentBlock = moduserenv.NewProc("DestroyEnvironmentBlock")
  125. procSetFileTime = modkernel32.NewProc("SetFileTime")
  126. procGetFileAttributesW = modkernel32.NewProc("GetFileAttributesW")
  127. procSetFileAttributesW = modkernel32.NewProc("SetFileAttributesW")
  128. procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
  129. procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
  130. procCommandLineToArgvW = modshell32.NewProc("CommandLineToArgvW")
  131. procLocalFree = modkernel32.NewProc("LocalFree")
  132. procSetHandleInformation = modkernel32.NewProc("SetHandleInformation")
  133. procFlushFileBuffers = modkernel32.NewProc("FlushFileBuffers")
  134. procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
  135. procGetLongPathNameW = modkernel32.NewProc("GetLongPathNameW")
  136. procGetShortPathNameW = modkernel32.NewProc("GetShortPathNameW")
  137. procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
  138. procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
  139. procUnmapViewOfFile = modkernel32.NewProc("UnmapViewOfFile")
  140. procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile")
  141. procVirtualLock = modkernel32.NewProc("VirtualLock")
  142. procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
  143. procVirtualAlloc = modkernel32.NewProc("VirtualAlloc")
  144. procVirtualFree = modkernel32.NewProc("VirtualFree")
  145. procVirtualProtect = modkernel32.NewProc("VirtualProtect")
  146. procTransmitFile = modmswsock.NewProc("TransmitFile")
  147. procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW")
  148. procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW")
  149. procCertOpenStore = modcrypt32.NewProc("CertOpenStore")
  150. procCertEnumCertificatesInStore = modcrypt32.NewProc("CertEnumCertificatesInStore")
  151. procCertAddCertificateContextToStore = modcrypt32.NewProc("CertAddCertificateContextToStore")
  152. procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
  153. procCertGetCertificateChain = modcrypt32.NewProc("CertGetCertificateChain")
  154. procCertFreeCertificateChain = modcrypt32.NewProc("CertFreeCertificateChain")
  155. procCertCreateCertificateContext = modcrypt32.NewProc("CertCreateCertificateContext")
  156. procCertFreeCertificateContext = modcrypt32.NewProc("CertFreeCertificateContext")
  157. procCertVerifyCertificateChainPolicy = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
  158. procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW")
  159. procRegCloseKey = modadvapi32.NewProc("RegCloseKey")
  160. procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW")
  161. procRegEnumKeyExW = modadvapi32.NewProc("RegEnumKeyExW")
  162. procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW")
  163. procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
  164. procGetConsoleMode = modkernel32.NewProc("GetConsoleMode")
  165. procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
  166. procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo")
  167. procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
  168. procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
  169. procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot")
  170. procProcess32FirstW = modkernel32.NewProc("Process32FirstW")
  171. procProcess32NextW = modkernel32.NewProc("Process32NextW")
  172. procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
  173. procCreateSymbolicLinkW = modkernel32.NewProc("CreateSymbolicLinkW")
  174. procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW")
  175. procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId")
  176. procCreateEventW = modkernel32.NewProc("CreateEventW")
  177. procCreateEventExW = modkernel32.NewProc("CreateEventExW")
  178. procOpenEventW = modkernel32.NewProc("OpenEventW")
  179. procSetEvent = modkernel32.NewProc("SetEvent")
  180. procResetEvent = modkernel32.NewProc("ResetEvent")
  181. procPulseEvent = modkernel32.NewProc("PulseEvent")
  182. procSleepEx = modkernel32.NewProc("SleepEx")
  183. procDefineDosDeviceW = modkernel32.NewProc("DefineDosDeviceW")
  184. procDeleteVolumeMountPointW = modkernel32.NewProc("DeleteVolumeMountPointW")
  185. procFindFirstVolumeW = modkernel32.NewProc("FindFirstVolumeW")
  186. procFindFirstVolumeMountPointW = modkernel32.NewProc("FindFirstVolumeMountPointW")
  187. procFindNextVolumeW = modkernel32.NewProc("FindNextVolumeW")
  188. procFindNextVolumeMountPointW = modkernel32.NewProc("FindNextVolumeMountPointW")
  189. procFindVolumeClose = modkernel32.NewProc("FindVolumeClose")
  190. procFindVolumeMountPointClose = modkernel32.NewProc("FindVolumeMountPointClose")
  191. procGetDriveTypeW = modkernel32.NewProc("GetDriveTypeW")
  192. procGetLogicalDrives = modkernel32.NewProc("GetLogicalDrives")
  193. procGetLogicalDriveStringsW = modkernel32.NewProc("GetLogicalDriveStringsW")
  194. procGetVolumeInformationW = modkernel32.NewProc("GetVolumeInformationW")
  195. procGetVolumeInformationByHandleW = modkernel32.NewProc("GetVolumeInformationByHandleW")
  196. procGetVolumeNameForVolumeMountPointW = modkernel32.NewProc("GetVolumeNameForVolumeMountPointW")
  197. procGetVolumePathNameW = modkernel32.NewProc("GetVolumePathNameW")
  198. procGetVolumePathNamesForVolumeNameW = modkernel32.NewProc("GetVolumePathNamesForVolumeNameW")
  199. procQueryDosDeviceW = modkernel32.NewProc("QueryDosDeviceW")
  200. procSetVolumeLabelW = modkernel32.NewProc("SetVolumeLabelW")
  201. procSetVolumeMountPointW = modkernel32.NewProc("SetVolumeMountPointW")
  202. procWSAStartup = modws2_32.NewProc("WSAStartup")
  203. procWSACleanup = modws2_32.NewProc("WSACleanup")
  204. procWSAIoctl = modws2_32.NewProc("WSAIoctl")
  205. procsocket = modws2_32.NewProc("socket")
  206. procsetsockopt = modws2_32.NewProc("setsockopt")
  207. procgetsockopt = modws2_32.NewProc("getsockopt")
  208. procbind = modws2_32.NewProc("bind")
  209. procconnect = modws2_32.NewProc("connect")
  210. procgetsockname = modws2_32.NewProc("getsockname")
  211. procgetpeername = modws2_32.NewProc("getpeername")
  212. proclisten = modws2_32.NewProc("listen")
  213. procshutdown = modws2_32.NewProc("shutdown")
  214. procclosesocket = modws2_32.NewProc("closesocket")
  215. procAcceptEx = modmswsock.NewProc("AcceptEx")
  216. procGetAcceptExSockaddrs = modmswsock.NewProc("GetAcceptExSockaddrs")
  217. procWSARecv = modws2_32.NewProc("WSARecv")
  218. procWSASend = modws2_32.NewProc("WSASend")
  219. procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
  220. procWSASendTo = modws2_32.NewProc("WSASendTo")
  221. procgethostbyname = modws2_32.NewProc("gethostbyname")
  222. procgetservbyname = modws2_32.NewProc("getservbyname")
  223. procntohs = modws2_32.NewProc("ntohs")
  224. procgetprotobyname = modws2_32.NewProc("getprotobyname")
  225. procDnsQuery_W = moddnsapi.NewProc("DnsQuery_W")
  226. procDnsRecordListFree = moddnsapi.NewProc("DnsRecordListFree")
  227. procDnsNameCompare_W = moddnsapi.NewProc("DnsNameCompare_W")
  228. procGetAddrInfoW = modws2_32.NewProc("GetAddrInfoW")
  229. procFreeAddrInfoW = modws2_32.NewProc("FreeAddrInfoW")
  230. procGetIfEntry = modiphlpapi.NewProc("GetIfEntry")
  231. procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
  232. procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
  233. procWSAEnumProtocolsW = modws2_32.NewProc("WSAEnumProtocolsW")
  234. procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
  235. procGetACP = modkernel32.NewProc("GetACP")
  236. procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
  237. procTranslateNameW = modsecur32.NewProc("TranslateNameW")
  238. procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
  239. procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
  240. procNetGetJoinInformation = modnetapi32.NewProc("NetGetJoinInformation")
  241. procNetApiBufferFree = modnetapi32.NewProc("NetApiBufferFree")
  242. procLookupAccountSidW = modadvapi32.NewProc("LookupAccountSidW")
  243. procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW")
  244. procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
  245. procConvertStringSidToSidW = modadvapi32.NewProc("ConvertStringSidToSidW")
  246. procGetLengthSid = modadvapi32.NewProc("GetLengthSid")
  247. procCopySid = modadvapi32.NewProc("CopySid")
  248. procAllocateAndInitializeSid = modadvapi32.NewProc("AllocateAndInitializeSid")
  249. procCreateWellKnownSid = modadvapi32.NewProc("CreateWellKnownSid")
  250. procFreeSid = modadvapi32.NewProc("FreeSid")
  251. procEqualSid = modadvapi32.NewProc("EqualSid")
  252. procCheckTokenMembership = modadvapi32.NewProc("CheckTokenMembership")
  253. procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
  254. procGetCurrentThreadToken = modadvapi32.NewProc("GetCurrentThreadToken")
  255. procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
  256. procGetCurrentProcessToken = modadvapi32.NewProc("GetCurrentProcessToken")
  257. procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf")
  258. procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
  259. procSetThreadToken = modadvapi32.NewProc("SetThreadToken")
  260. procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW")
  261. procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges")
  262. procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation")
  263. procSetTokenInformation = modadvapi32.NewProc("SetTokenInformation")
  264. procDuplicateTokenEx = modadvapi32.NewProc("DuplicateTokenEx")
  265. procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
  266. procGetSystemDirectoryW = modkernel32.NewProc("GetSystemDirectoryW")
  267. procWTSQueryUserToken = modwtsapi32.NewProc("WTSQueryUserToken")
  268. procWTSEnumerateSessionsW = modwtsapi32.NewProc("WTSEnumerateSessionsW")
  269. procWTSFreeMemory = modwtsapi32.NewProc("WTSFreeMemory")
  270. )
  271. func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) {
  272. r0, _, e1 := syscall.Syscall(procRegisterEventSourceW.Addr(), 2, uintptr(unsafe.Pointer(uncServerName)), uintptr(unsafe.Pointer(sourceName)), 0)
  273. handle = Handle(r0)
  274. if handle == 0 {
  275. if e1 != 0 {
  276. err = errnoErr(e1)
  277. } else {
  278. err = syscall.EINVAL
  279. }
  280. }
  281. return
  282. }
  283. func DeregisterEventSource(handle Handle) (err error) {
  284. r1, _, e1 := syscall.Syscall(procDeregisterEventSource.Addr(), 1, uintptr(handle), 0, 0)
  285. if r1 == 0 {
  286. if e1 != 0 {
  287. err = errnoErr(e1)
  288. } else {
  289. err = syscall.EINVAL
  290. }
  291. }
  292. return
  293. }
  294. func ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrSId uintptr, numStrings uint16, dataSize uint32, strings **uint16, rawData *byte) (err error) {
  295. r1, _, e1 := syscall.Syscall9(procReportEventW.Addr(), 9, uintptr(log), uintptr(etype), uintptr(category), uintptr(eventId), uintptr(usrSId), uintptr(numStrings), uintptr(dataSize), uintptr(unsafe.Pointer(strings)), uintptr(unsafe.Pointer(rawData)))
  296. if r1 == 0 {
  297. if e1 != 0 {
  298. err = errnoErr(e1)
  299. } else {
  300. err = syscall.EINVAL
  301. }
  302. }
  303. return
  304. }
  305. func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) {
  306. r0, _, e1 := syscall.Syscall(procOpenSCManagerW.Addr(), 3, uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(databaseName)), uintptr(access))
  307. handle = Handle(r0)
  308. if handle == 0 {
  309. if e1 != 0 {
  310. err = errnoErr(e1)
  311. } else {
  312. err = syscall.EINVAL
  313. }
  314. }
  315. return
  316. }
  317. func CloseServiceHandle(handle Handle) (err error) {
  318. r1, _, e1 := syscall.Syscall(procCloseServiceHandle.Addr(), 1, uintptr(handle), 0, 0)
  319. if r1 == 0 {
  320. if e1 != 0 {
  321. err = errnoErr(e1)
  322. } else {
  323. err = syscall.EINVAL
  324. }
  325. }
  326. return
  327. }
  328. func CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle Handle, err error) {
  329. r0, _, e1 := syscall.Syscall15(procCreateServiceW.Addr(), 13, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(unsafe.Pointer(displayName)), uintptr(access), uintptr(srvType), uintptr(startType), uintptr(errCtl), uintptr(unsafe.Pointer(pathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), 0, 0)
  330. handle = Handle(r0)
  331. if handle == 0 {
  332. if e1 != 0 {
  333. err = errnoErr(e1)
  334. } else {
  335. err = syscall.EINVAL
  336. }
  337. }
  338. return
  339. }
  340. func OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) {
  341. r0, _, e1 := syscall.Syscall(procOpenServiceW.Addr(), 3, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(access))
  342. handle = Handle(r0)
  343. if handle == 0 {
  344. if e1 != 0 {
  345. err = errnoErr(e1)
  346. } else {
  347. err = syscall.EINVAL
  348. }
  349. }
  350. return
  351. }
  352. func DeleteService(service Handle) (err error) {
  353. r1, _, e1 := syscall.Syscall(procDeleteService.Addr(), 1, uintptr(service), 0, 0)
  354. if r1 == 0 {
  355. if e1 != 0 {
  356. err = errnoErr(e1)
  357. } else {
  358. err = syscall.EINVAL
  359. }
  360. }
  361. return
  362. }
  363. func StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) {
  364. r1, _, e1 := syscall.Syscall(procStartServiceW.Addr(), 3, uintptr(service), uintptr(numArgs), uintptr(unsafe.Pointer(argVectors)))
  365. if r1 == 0 {
  366. if e1 != 0 {
  367. err = errnoErr(e1)
  368. } else {
  369. err = syscall.EINVAL
  370. }
  371. }
  372. return
  373. }
  374. func QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) {
  375. r1, _, e1 := syscall.Syscall(procQueryServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(status)), 0)
  376. if r1 == 0 {
  377. if e1 != 0 {
  378. err = errnoErr(e1)
  379. } else {
  380. err = syscall.EINVAL
  381. }
  382. }
  383. return
  384. }
  385. func ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) {
  386. r1, _, e1 := syscall.Syscall(procControlService.Addr(), 3, uintptr(service), uintptr(control), uintptr(unsafe.Pointer(status)))
  387. if r1 == 0 {
  388. if e1 != 0 {
  389. err = errnoErr(e1)
  390. } else {
  391. err = syscall.EINVAL
  392. }
  393. }
  394. return
  395. }
  396. func StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) {
  397. r1, _, e1 := syscall.Syscall(procStartServiceCtrlDispatcherW.Addr(), 1, uintptr(unsafe.Pointer(serviceTable)), 0, 0)
  398. if r1 == 0 {
  399. if e1 != 0 {
  400. err = errnoErr(e1)
  401. } else {
  402. err = syscall.EINVAL
  403. }
  404. }
  405. return
  406. }
  407. func SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) {
  408. r1, _, e1 := syscall.Syscall(procSetServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(serviceStatus)), 0)
  409. if r1 == 0 {
  410. if e1 != 0 {
  411. err = errnoErr(e1)
  412. } else {
  413. err = syscall.EINVAL
  414. }
  415. }
  416. return
  417. }
  418. func ChangeServiceConfig(service Handle, serviceType uint32, startType uint32, errorControl uint32, binaryPathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16, displayName *uint16) (err error) {
  419. r1, _, e1 := syscall.Syscall12(procChangeServiceConfigW.Addr(), 11, uintptr(service), uintptr(serviceType), uintptr(startType), uintptr(errorControl), uintptr(unsafe.Pointer(binaryPathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), uintptr(unsafe.Pointer(displayName)), 0)
  420. if r1 == 0 {
  421. if e1 != 0 {
  422. err = errnoErr(e1)
  423. } else {
  424. err = syscall.EINVAL
  425. }
  426. }
  427. return
  428. }
  429. func QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) {
  430. r1, _, e1 := syscall.Syscall6(procQueryServiceConfigW.Addr(), 4, uintptr(service), uintptr(unsafe.Pointer(serviceConfig)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), 0, 0)
  431. if r1 == 0 {
  432. if e1 != 0 {
  433. err = errnoErr(e1)
  434. } else {
  435. err = syscall.EINVAL
  436. }
  437. }
  438. return
  439. }
  440. func ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) {
  441. r1, _, e1 := syscall.Syscall(procChangeServiceConfig2W.Addr(), 3, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(info)))
  442. if r1 == 0 {
  443. if e1 != 0 {
  444. err = errnoErr(e1)
  445. } else {
  446. err = syscall.EINVAL
  447. }
  448. }
  449. return
  450. }
  451. func QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) {
  452. r1, _, e1 := syscall.Syscall6(procQueryServiceConfig2W.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0)
  453. if r1 == 0 {
  454. if e1 != 0 {
  455. err = errnoErr(e1)
  456. } else {
  457. err = syscall.EINVAL
  458. }
  459. }
  460. return
  461. }
  462. func EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) {
  463. r1, _, e1 := syscall.Syscall12(procEnumServicesStatusExW.Addr(), 10, uintptr(mgr), uintptr(infoLevel), uintptr(serviceType), uintptr(serviceState), uintptr(unsafe.Pointer(services)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), uintptr(unsafe.Pointer(servicesReturned)), uintptr(unsafe.Pointer(resumeHandle)), uintptr(unsafe.Pointer(groupName)), 0, 0)
  464. if r1 == 0 {
  465. if e1 != 0 {
  466. err = errnoErr(e1)
  467. } else {
  468. err = syscall.EINVAL
  469. }
  470. }
  471. return
  472. }
  473. func QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) {
  474. r1, _, e1 := syscall.Syscall6(procQueryServiceStatusEx.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0)
  475. if r1 == 0 {
  476. if e1 != 0 {
  477. err = errnoErr(e1)
  478. } else {
  479. err = syscall.EINVAL
  480. }
  481. }
  482. return
  483. }
  484. func NotifyServiceStatusChange(service Handle, notifyMask uint32, notifier *SERVICE_NOTIFY) (ret error) {
  485. r0, _, _ := syscall.Syscall(procNotifyServiceStatusChangeW.Addr(), 3, uintptr(service), uintptr(notifyMask), uintptr(unsafe.Pointer(notifier)))
  486. if r0 != 0 {
  487. ret = syscall.Errno(r0)
  488. }
  489. return
  490. }
  491. func GetLastError() (lasterr error) {
  492. r0, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
  493. if r0 != 0 {
  494. lasterr = syscall.Errno(r0)
  495. }
  496. return
  497. }
  498. func LoadLibrary(libname string) (handle Handle, err error) {
  499. var _p0 *uint16
  500. _p0, err = syscall.UTF16PtrFromString(libname)
  501. if err != nil {
  502. return
  503. }
  504. return _LoadLibrary(_p0)
  505. }
  506. func _LoadLibrary(libname *uint16) (handle Handle, err error) {
  507. r0, _, e1 := syscall.Syscall(procLoadLibraryW.Addr(), 1, uintptr(unsafe.Pointer(libname)), 0, 0)
  508. handle = Handle(r0)
  509. if handle == 0 {
  510. if e1 != 0 {
  511. err = errnoErr(e1)
  512. } else {
  513. err = syscall.EINVAL
  514. }
  515. }
  516. return
  517. }
  518. func LoadLibraryEx(libname string, zero Handle, flags uintptr) (handle Handle, err error) {
  519. var _p0 *uint16
  520. _p0, err = syscall.UTF16PtrFromString(libname)
  521. if err != nil {
  522. return
  523. }
  524. return _LoadLibraryEx(_p0, zero, flags)
  525. }
  526. func _LoadLibraryEx(libname *uint16, zero Handle, flags uintptr) (handle Handle, err error) {
  527. r0, _, e1 := syscall.Syscall(procLoadLibraryExW.Addr(), 3, uintptr(unsafe.Pointer(libname)), uintptr(zero), uintptr(flags))
  528. handle = Handle(r0)
  529. if handle == 0 {
  530. if e1 != 0 {
  531. err = errnoErr(e1)
  532. } else {
  533. err = syscall.EINVAL
  534. }
  535. }
  536. return
  537. }
  538. func FreeLibrary(handle Handle) (err error) {
  539. r1, _, e1 := syscall.Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0)
  540. if r1 == 0 {
  541. if e1 != 0 {
  542. err = errnoErr(e1)
  543. } else {
  544. err = syscall.EINVAL
  545. }
  546. }
  547. return
  548. }
  549. func GetProcAddress(module Handle, procname string) (proc uintptr, err error) {
  550. var _p0 *byte
  551. _p0, err = syscall.BytePtrFromString(procname)
  552. if err != nil {
  553. return
  554. }
  555. return _GetProcAddress(module, _p0)
  556. }
  557. func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) {
  558. r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(procname)), 0)
  559. proc = uintptr(r0)
  560. if proc == 0 {
  561. if e1 != 0 {
  562. err = errnoErr(e1)
  563. } else {
  564. err = syscall.EINVAL
  565. }
  566. }
  567. return
  568. }
  569. func GetVersion() (ver uint32, err error) {
  570. r0, _, e1 := syscall.Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
  571. ver = uint32(r0)
  572. if ver == 0 {
  573. if e1 != 0 {
  574. err = errnoErr(e1)
  575. } else {
  576. err = syscall.EINVAL
  577. }
  578. }
  579. return
  580. }
  581. func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
  582. var _p0 *uint16
  583. if len(buf) > 0 {
  584. _p0 = &buf[0]
  585. }
  586. r0, _, e1 := syscall.Syscall9(procFormatMessageW.Addr(), 7, uintptr(flags), uintptr(msgsrc), uintptr(msgid), uintptr(langid), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(args)), 0, 0)
  587. n = uint32(r0)
  588. if n == 0 {
  589. if e1 != 0 {
  590. err = errnoErr(e1)
  591. } else {
  592. err = syscall.EINVAL
  593. }
  594. }
  595. return
  596. }
  597. func ExitProcess(exitcode uint32) {
  598. syscall.Syscall(procExitProcess.Addr(), 1, uintptr(exitcode), 0, 0)
  599. return
  600. }
  601. func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile Handle) (handle Handle, err error) {
  602. r0, _, e1 := syscall.Syscall9(procCreateFileW.Addr(), 7, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0)
  603. handle = Handle(r0)
  604. if handle == InvalidHandle {
  605. if e1 != 0 {
  606. err = errnoErr(e1)
  607. } else {
  608. err = syscall.EINVAL
  609. }
  610. }
  611. return
  612. }
  613. func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
  614. var _p0 *byte
  615. if len(buf) > 0 {
  616. _p0 = &buf[0]
  617. }
  618. r1, _, e1 := syscall.Syscall6(procReadFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
  619. if r1 == 0 {
  620. if e1 != 0 {
  621. err = errnoErr(e1)
  622. } else {
  623. err = syscall.EINVAL
  624. }
  625. }
  626. return
  627. }
  628. func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
  629. var _p0 *byte
  630. if len(buf) > 0 {
  631. _p0 = &buf[0]
  632. }
  633. r1, _, e1 := syscall.Syscall6(procWriteFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
  634. if r1 == 0 {
  635. if e1 != 0 {
  636. err = errnoErr(e1)
  637. } else {
  638. err = syscall.EINVAL
  639. }
  640. }
  641. return
  642. }
  643. func GetOverlappedResult(handle Handle, overlapped *Overlapped, done *uint32, wait bool) (err error) {
  644. var _p0 uint32
  645. if wait {
  646. _p0 = 1
  647. } else {
  648. _p0 = 0
  649. }
  650. r1, _, e1 := syscall.Syscall6(procGetOverlappedResult.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(done)), uintptr(_p0), 0, 0)
  651. if r1 == 0 {
  652. if e1 != 0 {
  653. err = errnoErr(e1)
  654. } else {
  655. err = syscall.EINVAL
  656. }
  657. }
  658. return
  659. }
  660. func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) {
  661. r0, _, e1 := syscall.Syscall6(procSetFilePointer.Addr(), 4, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0)
  662. newlowoffset = uint32(r0)
  663. if newlowoffset == 0xffffffff {
  664. if e1 != 0 {
  665. err = errnoErr(e1)
  666. } else {
  667. err = syscall.EINVAL
  668. }
  669. }
  670. return
  671. }
  672. func CloseHandle(handle Handle) (err error) {
  673. r1, _, e1 := syscall.Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0)
  674. if r1 == 0 {
  675. if e1 != 0 {
  676. err = errnoErr(e1)
  677. } else {
  678. err = syscall.EINVAL
  679. }
  680. }
  681. return
  682. }
  683. func GetStdHandle(stdhandle uint32) (handle Handle, err error) {
  684. r0, _, e1 := syscall.Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0)
  685. handle = Handle(r0)
  686. if handle == InvalidHandle {
  687. if e1 != 0 {
  688. err = errnoErr(e1)
  689. } else {
  690. err = syscall.EINVAL
  691. }
  692. }
  693. return
  694. }
  695. func SetStdHandle(stdhandle uint32, handle Handle) (err error) {
  696. r1, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0)
  697. if r1 == 0 {
  698. if e1 != 0 {
  699. err = errnoErr(e1)
  700. } else {
  701. err = syscall.EINVAL
  702. }
  703. }
  704. return
  705. }
  706. func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
  707. r0, _, e1 := syscall.Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
  708. handle = Handle(r0)
  709. if handle == InvalidHandle {
  710. if e1 != 0 {
  711. err = errnoErr(e1)
  712. } else {
  713. err = syscall.EINVAL
  714. }
  715. }
  716. return
  717. }
  718. func findNextFile1(handle Handle, data *win32finddata1) (err error) {
  719. r1, _, e1 := syscall.Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
  720. if r1 == 0 {
  721. if e1 != 0 {
  722. err = errnoErr(e1)
  723. } else {
  724. err = syscall.EINVAL
  725. }
  726. }
  727. return
  728. }
  729. func FindClose(handle Handle) (err error) {
  730. r1, _, e1 := syscall.Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0)
  731. if r1 == 0 {
  732. if e1 != 0 {
  733. err = errnoErr(e1)
  734. } else {
  735. err = syscall.EINVAL
  736. }
  737. }
  738. return
  739. }
  740. func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error) {
  741. r1, _, e1 := syscall.Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
  742. if r1 == 0 {
  743. if e1 != 0 {
  744. err = errnoErr(e1)
  745. } else {
  746. err = syscall.EINVAL
  747. }
  748. }
  749. return
  750. }
  751. func GetFileInformationByHandleEx(handle Handle, class uint32, outBuffer *byte, outBufferLen uint32) (err error) {
  752. r1, _, e1 := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(), 4, uintptr(handle), uintptr(class), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferLen), 0, 0)
  753. if r1 == 0 {
  754. if e1 != 0 {
  755. err = errnoErr(e1)
  756. } else {
  757. err = syscall.EINVAL
  758. }
  759. }
  760. return
  761. }
  762. func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) {
  763. r0, _, e1 := syscall.Syscall(procGetCurrentDirectoryW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
  764. n = uint32(r0)
  765. if n == 0 {
  766. if e1 != 0 {
  767. err = errnoErr(e1)
  768. } else {
  769. err = syscall.EINVAL
  770. }
  771. }
  772. return
  773. }
  774. func SetCurrentDirectory(path *uint16) (err error) {
  775. r1, _, e1 := syscall.Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
  776. if r1 == 0 {
  777. if e1 != 0 {
  778. err = errnoErr(e1)
  779. } else {
  780. err = syscall.EINVAL
  781. }
  782. }
  783. return
  784. }
  785. func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) {
  786. r1, _, e1 := syscall.Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
  787. if r1 == 0 {
  788. if e1 != 0 {
  789. err = errnoErr(e1)
  790. } else {
  791. err = syscall.EINVAL
  792. }
  793. }
  794. return
  795. }
  796. func RemoveDirectory(path *uint16) (err error) {
  797. r1, _, e1 := syscall.Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
  798. if r1 == 0 {
  799. if e1 != 0 {
  800. err = errnoErr(e1)
  801. } else {
  802. err = syscall.EINVAL
  803. }
  804. }
  805. return
  806. }
  807. func DeleteFile(path *uint16) (err error) {
  808. r1, _, e1 := syscall.Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
  809. if r1 == 0 {
  810. if e1 != 0 {
  811. err = errnoErr(e1)
  812. } else {
  813. err = syscall.EINVAL
  814. }
  815. }
  816. return
  817. }
  818. func MoveFile(from *uint16, to *uint16) (err error) {
  819. r1, _, e1 := syscall.Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
  820. if r1 == 0 {
  821. if e1 != 0 {
  822. err = errnoErr(e1)
  823. } else {
  824. err = syscall.EINVAL
  825. }
  826. }
  827. return
  828. }
  829. func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
  830. r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
  831. if r1 == 0 {
  832. if e1 != 0 {
  833. err = errnoErr(e1)
  834. } else {
  835. err = syscall.EINVAL
  836. }
  837. }
  838. return
  839. }
  840. func GetComputerName(buf *uint16, n *uint32) (err error) {
  841. r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
  842. if r1 == 0 {
  843. if e1 != 0 {
  844. err = errnoErr(e1)
  845. } else {
  846. err = syscall.EINVAL
  847. }
  848. }
  849. return
  850. }
  851. func GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) {
  852. r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nametype), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
  853. if r1 == 0 {
  854. if e1 != 0 {
  855. err = errnoErr(e1)
  856. } else {
  857. err = syscall.EINVAL
  858. }
  859. }
  860. return
  861. }
  862. func SetEndOfFile(handle Handle) (err error) {
  863. r1, _, e1 := syscall.Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0)
  864. if r1 == 0 {
  865. if e1 != 0 {
  866. err = errnoErr(e1)
  867. } else {
  868. err = syscall.EINVAL
  869. }
  870. }
  871. return
  872. }
  873. func GetSystemTimeAsFileTime(time *Filetime) {
  874. syscall.Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
  875. return
  876. }
  877. func GetSystemTimePreciseAsFileTime(time *Filetime) {
  878. syscall.Syscall(procGetSystemTimePreciseAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
  879. return
  880. }
  881. func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) {
  882. r0, _, e1 := syscall.Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0)
  883. rc = uint32(r0)
  884. if rc == 0xffffffff {
  885. if e1 != 0 {
  886. err = errnoErr(e1)
  887. } else {
  888. err = syscall.EINVAL
  889. }
  890. }
  891. return
  892. }
  893. func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error) {
  894. r0, _, e1 := syscall.Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt), 0, 0)
  895. handle = Handle(r0)
  896. if handle == 0 {
  897. if e1 != 0 {
  898. err = errnoErr(e1)
  899. } else {
  900. err = syscall.EINVAL
  901. }
  902. }
  903. return
  904. }
  905. func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error) {
  906. r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0)
  907. if r1 == 0 {
  908. if e1 != 0 {
  909. err = errnoErr(e1)
  910. } else {
  911. err = syscall.EINVAL
  912. }
  913. }
  914. return
  915. }
  916. func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) (err error) {
  917. r1, _, e1 := syscall.Syscall6(procPostQueuedCompletionStatus.Addr(), 4, uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped)), 0, 0)
  918. if r1 == 0 {
  919. if e1 != 0 {
  920. err = errnoErr(e1)
  921. } else {
  922. err = syscall.EINVAL
  923. }
  924. }
  925. return
  926. }
  927. func CancelIo(s Handle) (err error) {
  928. r1, _, e1 := syscall.Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0)
  929. if r1 == 0 {
  930. if e1 != 0 {
  931. err = errnoErr(e1)
  932. } else {
  933. err = syscall.EINVAL
  934. }
  935. }
  936. return
  937. }
  938. func CancelIoEx(s Handle, o *Overlapped) (err error) {
  939. r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0)
  940. if r1 == 0 {
  941. if e1 != 0 {
  942. err = errnoErr(e1)
  943. } else {
  944. err = syscall.EINVAL
  945. }
  946. }
  947. return
  948. }
  949. func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
  950. var _p0 uint32
  951. if inheritHandles {
  952. _p0 = 1
  953. } else {
  954. _p0 = 0
  955. }
  956. r1, _, e1 := syscall.Syscall12(procCreateProcessW.Addr(), 10, uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0, 0)
  957. if r1 == 0 {
  958. if e1 != 0 {
  959. err = errnoErr(e1)
  960. } else {
  961. err = syscall.EINVAL
  962. }
  963. }
  964. return
  965. }
  966. func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err error) {
  967. var _p0 uint32
  968. if inheritHandle {
  969. _p0 = 1
  970. } else {
  971. _p0 = 0
  972. }
  973. r0, _, e1 := syscall.Syscall(procOpenProcess.Addr(), 3, uintptr(da), uintptr(_p0), uintptr(pid))
  974. handle = Handle(r0)
  975. if handle == 0 {
  976. if e1 != 0 {
  977. err = errnoErr(e1)
  978. } else {
  979. err = syscall.EINVAL
  980. }
  981. }
  982. return
  983. }
  984. func TerminateProcess(handle Handle, exitcode uint32) (err error) {
  985. r1, _, e1 := syscall.Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0)
  986. if r1 == 0 {
  987. if e1 != 0 {
  988. err = errnoErr(e1)
  989. } else {
  990. err = syscall.EINVAL
  991. }
  992. }
  993. return
  994. }
  995. func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) {
  996. r1, _, e1 := syscall.Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0)
  997. if r1 == 0 {
  998. if e1 != 0 {
  999. err = errnoErr(e1)
  1000. } else {
  1001. err = syscall.EINVAL
  1002. }
  1003. }
  1004. return
  1005. }
  1006. func GetStartupInfo(startupInfo *StartupInfo) (err error) {
  1007. r1, _, e1 := syscall.Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0)
  1008. if r1 == 0 {
  1009. if e1 != 0 {
  1010. err = errnoErr(e1)
  1011. } else {
  1012. err = syscall.EINVAL
  1013. }
  1014. }
  1015. return
  1016. }
  1017. func GetCurrentProcess() (pseudoHandle Handle, err error) {
  1018. r0, _, e1 := syscall.Syscall(procGetCurrentProcess.Addr(), 0, 0, 0, 0)
  1019. pseudoHandle = Handle(r0)
  1020. if pseudoHandle == 0 {
  1021. if e1 != 0 {
  1022. err = errnoErr(e1)
  1023. } else {
  1024. err = syscall.EINVAL
  1025. }
  1026. }
  1027. return
  1028. }
  1029. func GetCurrentThread() (pseudoHandle Handle, err error) {
  1030. r0, _, e1 := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0)
  1031. pseudoHandle = Handle(r0)
  1032. if pseudoHandle == 0 {
  1033. if e1 != 0 {
  1034. err = errnoErr(e1)
  1035. } else {
  1036. err = syscall.EINVAL
  1037. }
  1038. }
  1039. return
  1040. }
  1041. func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) {
  1042. r1, _, e1 := syscall.Syscall6(procGetProcessTimes.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(creationTime)), uintptr(unsafe.Pointer(exitTime)), uintptr(unsafe.Pointer(kernelTime)), uintptr(unsafe.Pointer(userTime)), 0)
  1043. if r1 == 0 {
  1044. if e1 != 0 {
  1045. err = errnoErr(e1)
  1046. } else {
  1047. err = syscall.EINVAL
  1048. }
  1049. }
  1050. return
  1051. }
  1052. func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) {
  1053. var _p0 uint32
  1054. if bInheritHandle {
  1055. _p0 = 1
  1056. } else {
  1057. _p0 = 0
  1058. }
  1059. r1, _, e1 := syscall.Syscall9(procDuplicateHandle.Addr(), 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0)
  1060. if r1 == 0 {
  1061. if e1 != 0 {
  1062. err = errnoErr(e1)
  1063. } else {
  1064. err = syscall.EINVAL
  1065. }
  1066. }
  1067. return
  1068. }
  1069. func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) {
  1070. r0, _, e1 := syscall.Syscall(procWaitForSingleObject.Addr(), 2, uintptr(handle), uintptr(waitMilliseconds), 0)
  1071. event = uint32(r0)
  1072. if event == 0xffffffff {
  1073. if e1 != 0 {
  1074. err = errnoErr(e1)
  1075. } else {
  1076. err = syscall.EINVAL
  1077. }
  1078. }
  1079. return
  1080. }
  1081. func waitForMultipleObjects(count uint32, handles uintptr, waitAll bool, waitMilliseconds uint32) (event uint32, err error) {
  1082. var _p0 uint32
  1083. if waitAll {
  1084. _p0 = 1
  1085. } else {
  1086. _p0 = 0
  1087. }
  1088. r0, _, e1 := syscall.Syscall6(procWaitForMultipleObjects.Addr(), 4, uintptr(count), uintptr(handles), uintptr(_p0), uintptr(waitMilliseconds), 0, 0)
  1089. event = uint32(r0)
  1090. if event == 0xffffffff {
  1091. if e1 != 0 {
  1092. err = errnoErr(e1)
  1093. } else {
  1094. err = syscall.EINVAL
  1095. }
  1096. }
  1097. return
  1098. }
  1099. func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) {
  1100. r0, _, e1 := syscall.Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
  1101. n = uint32(r0)
  1102. if n == 0 {
  1103. if e1 != 0 {
  1104. err = errnoErr(e1)
  1105. } else {
  1106. err = syscall.EINVAL
  1107. }
  1108. }
  1109. return
  1110. }
  1111. func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) {
  1112. r1, _, e1 := syscall.Syscall6(procCreatePipe.Addr(), 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0)
  1113. if r1 == 0 {
  1114. if e1 != 0 {
  1115. err = errnoErr(e1)
  1116. } else {
  1117. err = syscall.EINVAL
  1118. }
  1119. }
  1120. return
  1121. }
  1122. func GetFileType(filehandle Handle) (n uint32, err error) {
  1123. r0, _, e1 := syscall.Syscall(procGetFileType.Addr(), 1, uintptr(filehandle), 0, 0)
  1124. n = uint32(r0)
  1125. if n == 0 {
  1126. if e1 != 0 {
  1127. err = errnoErr(e1)
  1128. } else {
  1129. err = syscall.EINVAL
  1130. }
  1131. }
  1132. return
  1133. }
  1134. func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) {
  1135. r1, _, e1 := syscall.Syscall6(procCryptAcquireContextW.Addr(), 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0)
  1136. if r1 == 0 {
  1137. if e1 != 0 {
  1138. err = errnoErr(e1)
  1139. } else {
  1140. err = syscall.EINVAL
  1141. }
  1142. }
  1143. return
  1144. }
  1145. func CryptReleaseContext(provhandle Handle, flags uint32) (err error) {
  1146. r1, _, e1 := syscall.Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0)
  1147. if r1 == 0 {
  1148. if e1 != 0 {
  1149. err = errnoErr(e1)
  1150. } else {
  1151. err = syscall.EINVAL
  1152. }
  1153. }
  1154. return
  1155. }
  1156. func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) {
  1157. r1, _, e1 := syscall.Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
  1158. if r1 == 0 {
  1159. if e1 != 0 {
  1160. err = errnoErr(e1)
  1161. } else {
  1162. err = syscall.EINVAL
  1163. }
  1164. }
  1165. return
  1166. }
  1167. func GetEnvironmentStrings() (envs *uint16, err error) {
  1168. r0, _, e1 := syscall.Syscall(procGetEnvironmentStringsW.Addr(), 0, 0, 0, 0)
  1169. envs = (*uint16)(unsafe.Pointer(r0))
  1170. if envs == nil {
  1171. if e1 != 0 {
  1172. err = errnoErr(e1)
  1173. } else {
  1174. err = syscall.EINVAL
  1175. }
  1176. }
  1177. return
  1178. }
  1179. func FreeEnvironmentStrings(envs *uint16) (err error) {
  1180. r1, _, e1 := syscall.Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0)
  1181. if r1 == 0 {
  1182. if e1 != 0 {
  1183. err = errnoErr(e1)
  1184. } else {
  1185. err = syscall.EINVAL
  1186. }
  1187. }
  1188. return
  1189. }
  1190. func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) {
  1191. r0, _, e1 := syscall.Syscall(procGetEnvironmentVariableW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size))
  1192. n = uint32(r0)
  1193. if n == 0 {
  1194. if e1 != 0 {
  1195. err = errnoErr(e1)
  1196. } else {
  1197. err = syscall.EINVAL
  1198. }
  1199. }
  1200. return
  1201. }
  1202. func SetEnvironmentVariable(name *uint16, value *uint16) (err error) {
  1203. r1, _, e1 := syscall.Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0)
  1204. if r1 == 0 {
  1205. if e1 != 0 {
  1206. err = errnoErr(e1)
  1207. } else {
  1208. err = syscall.EINVAL
  1209. }
  1210. }
  1211. return
  1212. }
  1213. func CreateEnvironmentBlock(block **uint16, token Token, inheritExisting bool) (err error) {
  1214. var _p0 uint32
  1215. if inheritExisting {
  1216. _p0 = 1
  1217. } else {
  1218. _p0 = 0
  1219. }
  1220. r1, _, e1 := syscall.Syscall(procCreateEnvironmentBlock.Addr(), 3, uintptr(unsafe.Pointer(block)), uintptr(token), uintptr(_p0))
  1221. if r1 == 0 {
  1222. if e1 != 0 {
  1223. err = errnoErr(e1)
  1224. } else {
  1225. err = syscall.EINVAL
  1226. }
  1227. }
  1228. return
  1229. }
  1230. func DestroyEnvironmentBlock(block *uint16) (err error) {
  1231. r1, _, e1 := syscall.Syscall(procDestroyEnvironmentBlock.Addr(), 1, uintptr(unsafe.Pointer(block)), 0, 0)
  1232. if r1 == 0 {
  1233. if e1 != 0 {
  1234. err = errnoErr(e1)
  1235. } else {
  1236. err = syscall.EINVAL
  1237. }
  1238. }
  1239. return
  1240. }
  1241. func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) {
  1242. r1, _, e1 := syscall.Syscall6(procSetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0)
  1243. if r1 == 0 {
  1244. if e1 != 0 {
  1245. err = errnoErr(e1)
  1246. } else {
  1247. err = syscall.EINVAL
  1248. }
  1249. }
  1250. return
  1251. }
  1252. func GetFileAttributes(name *uint16) (attrs uint32, err error) {
  1253. r0, _, e1 := syscall.Syscall(procGetFileAttributesW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
  1254. attrs = uint32(r0)
  1255. if attrs == INVALID_FILE_ATTRIBUTES {
  1256. if e1 != 0 {
  1257. err = errnoErr(e1)
  1258. } else {
  1259. err = syscall.EINVAL
  1260. }
  1261. }
  1262. return
  1263. }
  1264. func SetFileAttributes(name *uint16, attrs uint32) (err error) {
  1265. r1, _, e1 := syscall.Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
  1266. if r1 == 0 {
  1267. if e1 != 0 {
  1268. err = errnoErr(e1)
  1269. } else {
  1270. err = syscall.EINVAL
  1271. }
  1272. }
  1273. return
  1274. }
  1275. func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) {
  1276. r1, _, e1 := syscall.Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info)))
  1277. if r1 == 0 {
  1278. if e1 != 0 {
  1279. err = errnoErr(e1)
  1280. } else {
  1281. err = syscall.EINVAL
  1282. }
  1283. }
  1284. return
  1285. }
  1286. func GetCommandLine() (cmd *uint16) {
  1287. r0, _, _ := syscall.Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
  1288. cmd = (*uint16)(unsafe.Pointer(r0))
  1289. return
  1290. }
  1291. func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
  1292. r0, _, e1 := syscall.Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
  1293. argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0))
  1294. if argv == nil {
  1295. if e1 != 0 {
  1296. err = errnoErr(e1)
  1297. } else {
  1298. err = syscall.EINVAL
  1299. }
  1300. }
  1301. return
  1302. }
  1303. func LocalFree(hmem Handle) (handle Handle, err error) {
  1304. r0, _, e1 := syscall.Syscall(procLocalFree.Addr(), 1, uintptr(hmem), 0, 0)
  1305. handle = Handle(r0)
  1306. if handle != 0 {
  1307. if e1 != 0 {
  1308. err = errnoErr(e1)
  1309. } else {
  1310. err = syscall.EINVAL
  1311. }
  1312. }
  1313. return
  1314. }
  1315. func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) {
  1316. r1, _, e1 := syscall.Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags))
  1317. if r1 == 0 {
  1318. if e1 != 0 {
  1319. err = errnoErr(e1)
  1320. } else {
  1321. err = syscall.EINVAL
  1322. }
  1323. }
  1324. return
  1325. }
  1326. func FlushFileBuffers(handle Handle) (err error) {
  1327. r1, _, e1 := syscall.Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0)
  1328. if r1 == 0 {
  1329. if e1 != 0 {
  1330. err = errnoErr(e1)
  1331. } else {
  1332. err = syscall.EINVAL
  1333. }
  1334. }
  1335. return
  1336. }
  1337. func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) {
  1338. r0, _, e1 := syscall.Syscall6(procGetFullPathNameW.Addr(), 4, uintptr(unsafe.Pointer(path)), uintptr(buflen), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(fname)), 0, 0)
  1339. n = uint32(r0)
  1340. if n == 0 {
  1341. if e1 != 0 {
  1342. err = errnoErr(e1)
  1343. } else {
  1344. err = syscall.EINVAL
  1345. }
  1346. }
  1347. return
  1348. }
  1349. func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) {
  1350. r0, _, e1 := syscall.Syscall(procGetLongPathNameW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen))
  1351. n = uint32(r0)
  1352. if n == 0 {
  1353. if e1 != 0 {
  1354. err = errnoErr(e1)
  1355. } else {
  1356. err = syscall.EINVAL
  1357. }
  1358. }
  1359. return
  1360. }
  1361. func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) {
  1362. r0, _, e1 := syscall.Syscall(procGetShortPathNameW.Addr(), 3, uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen))
  1363. n = uint32(r0)
  1364. if n == 0 {
  1365. if e1 != 0 {
  1366. err = errnoErr(e1)
  1367. } else {
  1368. err = syscall.EINVAL
  1369. }
  1370. }
  1371. return
  1372. }
  1373. func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) {
  1374. r0, _, e1 := syscall.Syscall6(procCreateFileMappingW.Addr(), 6, uintptr(fhandle), uintptr(unsafe.Pointer(sa)), uintptr(prot), uintptr(maxSizeHigh), uintptr(maxSizeLow), uintptr(unsafe.Pointer(name)))
  1375. handle = Handle(r0)
  1376. if handle == 0 {
  1377. if e1 != 0 {
  1378. err = errnoErr(e1)
  1379. } else {
  1380. err = syscall.EINVAL
  1381. }
  1382. }
  1383. return
  1384. }
  1385. func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error) {
  1386. r0, _, e1 := syscall.Syscall6(procMapViewOfFile.Addr(), 5, uintptr(handle), uintptr(access), uintptr(offsetHigh), uintptr(offsetLow), uintptr(length), 0)
  1387. addr = uintptr(r0)
  1388. if addr == 0 {
  1389. if e1 != 0 {
  1390. err = errnoErr(e1)
  1391. } else {
  1392. err = syscall.EINVAL
  1393. }
  1394. }
  1395. return
  1396. }
  1397. func UnmapViewOfFile(addr uintptr) (err error) {
  1398. r1, _, e1 := syscall.Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0)
  1399. if r1 == 0 {
  1400. if e1 != 0 {
  1401. err = errnoErr(e1)
  1402. } else {
  1403. err = syscall.EINVAL
  1404. }
  1405. }
  1406. return
  1407. }
  1408. func FlushViewOfFile(addr uintptr, length uintptr) (err error) {
  1409. r1, _, e1 := syscall.Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0)
  1410. if r1 == 0 {
  1411. if e1 != 0 {
  1412. err = errnoErr(e1)
  1413. } else {
  1414. err = syscall.EINVAL
  1415. }
  1416. }
  1417. return
  1418. }
  1419. func VirtualLock(addr uintptr, length uintptr) (err error) {
  1420. r1, _, e1 := syscall.Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0)
  1421. if r1 == 0 {
  1422. if e1 != 0 {
  1423. err = errnoErr(e1)
  1424. } else {
  1425. err = syscall.EINVAL
  1426. }
  1427. }
  1428. return
  1429. }
  1430. func VirtualUnlock(addr uintptr, length uintptr) (err error) {
  1431. r1, _, e1 := syscall.Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0)
  1432. if r1 == 0 {
  1433. if e1 != 0 {
  1434. err = errnoErr(e1)
  1435. } else {
  1436. err = syscall.EINVAL
  1437. }
  1438. }
  1439. return
  1440. }
  1441. func VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) {
  1442. r0, _, e1 := syscall.Syscall6(procVirtualAlloc.Addr(), 4, uintptr(address), uintptr(size), uintptr(alloctype), uintptr(protect), 0, 0)
  1443. value = uintptr(r0)
  1444. if value == 0 {
  1445. if e1 != 0 {
  1446. err = errnoErr(e1)
  1447. } else {
  1448. err = syscall.EINVAL
  1449. }
  1450. }
  1451. return
  1452. }
  1453. func VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) {
  1454. r1, _, e1 := syscall.Syscall(procVirtualFree.Addr(), 3, uintptr(address), uintptr(size), uintptr(freetype))
  1455. if r1 == 0 {
  1456. if e1 != 0 {
  1457. err = errnoErr(e1)
  1458. } else {
  1459. err = syscall.EINVAL
  1460. }
  1461. }
  1462. return
  1463. }
  1464. func VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) {
  1465. r1, _, e1 := syscall.Syscall6(procVirtualProtect.Addr(), 4, uintptr(address), uintptr(size), uintptr(newprotect), uintptr(unsafe.Pointer(oldprotect)), 0, 0)
  1466. if r1 == 0 {
  1467. if e1 != 0 {
  1468. err = errnoErr(e1)
  1469. } else {
  1470. err = syscall.EINVAL
  1471. }
  1472. }
  1473. return
  1474. }
  1475. func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
  1476. r1, _, e1 := syscall.Syscall9(procTransmitFile.Addr(), 7, uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags), 0, 0)
  1477. if r1 == 0 {
  1478. if e1 != 0 {
  1479. err = errnoErr(e1)
  1480. } else {
  1481. err = syscall.EINVAL
  1482. }
  1483. }
  1484. return
  1485. }
  1486. func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
  1487. var _p0 uint32
  1488. if watchSubTree {
  1489. _p0 = 1
  1490. } else {
  1491. _p0 = 0
  1492. }
  1493. r1, _, e1 := syscall.Syscall9(procReadDirectoryChangesW.Addr(), 8, uintptr(handle), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(_p0), uintptr(mask), uintptr(unsafe.Pointer(retlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine), 0)
  1494. if r1 == 0 {
  1495. if e1 != 0 {
  1496. err = errnoErr(e1)
  1497. } else {
  1498. err = syscall.EINVAL
  1499. }
  1500. }
  1501. return
  1502. }
  1503. func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) {
  1504. r0, _, e1 := syscall.Syscall(procCertOpenSystemStoreW.Addr(), 2, uintptr(hprov), uintptr(unsafe.Pointer(name)), 0)
  1505. store = Handle(r0)
  1506. if store == 0 {
  1507. if e1 != 0 {
  1508. err = errnoErr(e1)
  1509. } else {
  1510. err = syscall.EINVAL
  1511. }
  1512. }
  1513. return
  1514. }
  1515. func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) {
  1516. r0, _, e1 := syscall.Syscall6(procCertOpenStore.Addr(), 5, uintptr(storeProvider), uintptr(msgAndCertEncodingType), uintptr(cryptProv), uintptr(flags), uintptr(para), 0)
  1517. handle = Handle(r0)
  1518. if handle == InvalidHandle {
  1519. if e1 != 0 {
  1520. err = errnoErr(e1)
  1521. } else {
  1522. err = syscall.EINVAL
  1523. }
  1524. }
  1525. return
  1526. }
  1527. func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) {
  1528. r0, _, e1 := syscall.Syscall(procCertEnumCertificatesInStore.Addr(), 2, uintptr(store), uintptr(unsafe.Pointer(prevContext)), 0)
  1529. context = (*CertContext)(unsafe.Pointer(r0))
  1530. if context == nil {
  1531. if e1 != 0 {
  1532. err = errnoErr(e1)
  1533. } else {
  1534. err = syscall.EINVAL
  1535. }
  1536. }
  1537. return
  1538. }
  1539. func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
  1540. r1, _, e1 := syscall.Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0)
  1541. if r1 == 0 {
  1542. if e1 != 0 {
  1543. err = errnoErr(e1)
  1544. } else {
  1545. err = syscall.EINVAL
  1546. }
  1547. }
  1548. return
  1549. }
  1550. func CertCloseStore(store Handle, flags uint32) (err error) {
  1551. r1, _, e1 := syscall.Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0)
  1552. if r1 == 0 {
  1553. if e1 != 0 {
  1554. err = errnoErr(e1)
  1555. } else {
  1556. err = syscall.EINVAL
  1557. }
  1558. }
  1559. return
  1560. }
  1561. func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, additionalStore Handle, para *CertChainPara, flags uint32, reserved uintptr, chainCtx **CertChainContext) (err error) {
  1562. r1, _, e1 := syscall.Syscall9(procCertGetCertificateChain.Addr(), 8, uintptr(engine), uintptr(unsafe.Pointer(leaf)), uintptr(unsafe.Pointer(time)), uintptr(additionalStore), uintptr(unsafe.Pointer(para)), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(chainCtx)), 0)
  1563. if r1 == 0 {
  1564. if e1 != 0 {
  1565. err = errnoErr(e1)
  1566. } else {
  1567. err = syscall.EINVAL
  1568. }
  1569. }
  1570. return
  1571. }
  1572. func CertFreeCertificateChain(ctx *CertChainContext) {
  1573. syscall.Syscall(procCertFreeCertificateChain.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
  1574. return
  1575. }
  1576. func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) {
  1577. r0, _, e1 := syscall.Syscall(procCertCreateCertificateContext.Addr(), 3, uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen))
  1578. context = (*CertContext)(unsafe.Pointer(r0))
  1579. if context == nil {
  1580. if e1 != 0 {
  1581. err = errnoErr(e1)
  1582. } else {
  1583. err = syscall.EINVAL
  1584. }
  1585. }
  1586. return
  1587. }
  1588. func CertFreeCertificateContext(ctx *CertContext) (err error) {
  1589. r1, _, e1 := syscall.Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
  1590. if r1 == 0 {
  1591. if e1 != 0 {
  1592. err = errnoErr(e1)
  1593. } else {
  1594. err = syscall.EINVAL
  1595. }
  1596. }
  1597. return
  1598. }
  1599. func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) {
  1600. r1, _, e1 := syscall.Syscall6(procCertVerifyCertificateChainPolicy.Addr(), 4, uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status)), 0, 0)
  1601. if r1 == 0 {
  1602. if e1 != 0 {
  1603. err = errnoErr(e1)
  1604. } else {
  1605. err = syscall.EINVAL
  1606. }
  1607. }
  1608. return
  1609. }
  1610. func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
  1611. r0, _, _ := syscall.Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
  1612. if r0 != 0 {
  1613. regerrno = syscall.Errno(r0)
  1614. }
  1615. return
  1616. }
  1617. func RegCloseKey(key Handle) (regerrno error) {
  1618. r0, _, _ := syscall.Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
  1619. if r0 != 0 {
  1620. regerrno = syscall.Errno(r0)
  1621. }
  1622. return
  1623. }
  1624. func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) {
  1625. r0, _, _ := syscall.Syscall12(procRegQueryInfoKeyW.Addr(), 12, uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime)))
  1626. if r0 != 0 {
  1627. regerrno = syscall.Errno(r0)
  1628. }
  1629. return
  1630. }
  1631. func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
  1632. r0, _, _ := syscall.Syscall9(procRegEnumKeyExW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime)), 0)
  1633. if r0 != 0 {
  1634. regerrno = syscall.Errno(r0)
  1635. }
  1636. return
  1637. }
  1638. func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
  1639. r0, _, _ := syscall.Syscall6(procRegQueryValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)))
  1640. if r0 != 0 {
  1641. regerrno = syscall.Errno(r0)
  1642. }
  1643. return
  1644. }
  1645. func getCurrentProcessId() (pid uint32) {
  1646. r0, _, _ := syscall.Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
  1647. pid = uint32(r0)
  1648. return
  1649. }
  1650. func GetConsoleMode(console Handle, mode *uint32) (err error) {
  1651. r1, _, e1 := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0)
  1652. if r1 == 0 {
  1653. if e1 != 0 {
  1654. err = errnoErr(e1)
  1655. } else {
  1656. err = syscall.EINVAL
  1657. }
  1658. }
  1659. return
  1660. }
  1661. func SetConsoleMode(console Handle, mode uint32) (err error) {
  1662. r1, _, e1 := syscall.Syscall(procSetConsoleMode.Addr(), 2, uintptr(console), uintptr(mode), 0)
  1663. if r1 == 0 {
  1664. if e1 != 0 {
  1665. err = errnoErr(e1)
  1666. } else {
  1667. err = syscall.EINVAL
  1668. }
  1669. }
  1670. return
  1671. }
  1672. func GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) {
  1673. r1, _, e1 := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(info)), 0)
  1674. if r1 == 0 {
  1675. if e1 != 0 {
  1676. err = errnoErr(e1)
  1677. } else {
  1678. err = syscall.EINVAL
  1679. }
  1680. }
  1681. return
  1682. }
  1683. func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) {
  1684. r1, _, e1 := syscall.Syscall6(procWriteConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved)), 0)
  1685. if r1 == 0 {
  1686. if e1 != 0 {
  1687. err = errnoErr(e1)
  1688. } else {
  1689. err = syscall.EINVAL
  1690. }
  1691. }
  1692. return
  1693. }
  1694. func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) {
  1695. r1, _, e1 := syscall.Syscall6(procReadConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl)), 0)
  1696. if r1 == 0 {
  1697. if e1 != 0 {
  1698. err = errnoErr(e1)
  1699. } else {
  1700. err = syscall.EINVAL
  1701. }
  1702. }
  1703. return
  1704. }
  1705. func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) {
  1706. r0, _, e1 := syscall.Syscall(procCreateToolhelp32Snapshot.Addr(), 2, uintptr(flags), uintptr(processId), 0)
  1707. handle = Handle(r0)
  1708. if handle == InvalidHandle {
  1709. if e1 != 0 {
  1710. err = errnoErr(e1)
  1711. } else {
  1712. err = syscall.EINVAL
  1713. }
  1714. }
  1715. return
  1716. }
  1717. func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) {
  1718. r1, _, e1 := syscall.Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
  1719. if r1 == 0 {
  1720. if e1 != 0 {
  1721. err = errnoErr(e1)
  1722. } else {
  1723. err = syscall.EINVAL
  1724. }
  1725. }
  1726. return
  1727. }
  1728. func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) {
  1729. r1, _, e1 := syscall.Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
  1730. if r1 == 0 {
  1731. if e1 != 0 {
  1732. err = errnoErr(e1)
  1733. } else {
  1734. err = syscall.EINVAL
  1735. }
  1736. }
  1737. return
  1738. }
  1739. func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBufferSize uint32, outBuffer *byte, outBufferSize uint32, bytesReturned *uint32, overlapped *Overlapped) (err error) {
  1740. r1, _, e1 := syscall.Syscall9(procDeviceIoControl.Addr(), 8, uintptr(handle), uintptr(ioControlCode), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferSize), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferSize), uintptr(unsafe.Pointer(bytesReturned)), uintptr(unsafe.Pointer(overlapped)), 0)
  1741. if r1 == 0 {
  1742. if e1 != 0 {
  1743. err = errnoErr(e1)
  1744. } else {
  1745. err = syscall.EINVAL
  1746. }
  1747. }
  1748. return
  1749. }
  1750. func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) {
  1751. r1, _, e1 := syscall.Syscall(procCreateSymbolicLinkW.Addr(), 3, uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags))
  1752. if r1&0xff == 0 {
  1753. if e1 != 0 {
  1754. err = errnoErr(e1)
  1755. } else {
  1756. err = syscall.EINVAL
  1757. }
  1758. }
  1759. return
  1760. }
  1761. func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) {
  1762. r1, _, e1 := syscall.Syscall(procCreateHardLinkW.Addr(), 3, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved))
  1763. if r1&0xff == 0 {
  1764. if e1 != 0 {
  1765. err = errnoErr(e1)
  1766. } else {
  1767. err = syscall.EINVAL
  1768. }
  1769. }
  1770. return
  1771. }
  1772. func GetCurrentThreadId() (id uint32) {
  1773. r0, _, _ := syscall.Syscall(procGetCurrentThreadId.Addr(), 0, 0, 0, 0)
  1774. id = uint32(r0)
  1775. return
  1776. }
  1777. func CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) {
  1778. r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name)), 0, 0)
  1779. handle = Handle(r0)
  1780. if handle == 0 {
  1781. if e1 != 0 {
  1782. err = errnoErr(e1)
  1783. } else {
  1784. err = syscall.EINVAL
  1785. }
  1786. }
  1787. return
  1788. }
  1789. func CreateEventEx(eventAttrs *SecurityAttributes, name *uint16, flags uint32, desiredAccess uint32) (handle Handle, err error) {
  1790. r0, _, e1 := syscall.Syscall6(procCreateEventExW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(desiredAccess), 0, 0)
  1791. handle = Handle(r0)
  1792. if handle == 0 {
  1793. if e1 != 0 {
  1794. err = errnoErr(e1)
  1795. } else {
  1796. err = syscall.EINVAL
  1797. }
  1798. }
  1799. return
  1800. }
  1801. func OpenEvent(desiredAccess uint32, inheritHandle bool, name *uint16) (handle Handle, err error) {
  1802. var _p0 uint32
  1803. if inheritHandle {
  1804. _p0 = 1
  1805. } else {
  1806. _p0 = 0
  1807. }
  1808. r0, _, e1 := syscall.Syscall(procOpenEventW.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(name)))
  1809. handle = Handle(r0)
  1810. if handle == 0 {
  1811. if e1 != 0 {
  1812. err = errnoErr(e1)
  1813. } else {
  1814. err = syscall.EINVAL
  1815. }
  1816. }
  1817. return
  1818. }
  1819. func SetEvent(event Handle) (err error) {
  1820. r1, _, e1 := syscall.Syscall(procSetEvent.Addr(), 1, uintptr(event), 0, 0)
  1821. if r1 == 0 {
  1822. if e1 != 0 {
  1823. err = errnoErr(e1)
  1824. } else {
  1825. err = syscall.EINVAL
  1826. }
  1827. }
  1828. return
  1829. }
  1830. func ResetEvent(event Handle) (err error) {
  1831. r1, _, e1 := syscall.Syscall(procResetEvent.Addr(), 1, uintptr(event), 0, 0)
  1832. if r1 == 0 {
  1833. if e1 != 0 {
  1834. err = errnoErr(e1)
  1835. } else {
  1836. err = syscall.EINVAL
  1837. }
  1838. }
  1839. return
  1840. }
  1841. func PulseEvent(event Handle) (err error) {
  1842. r1, _, e1 := syscall.Syscall(procPulseEvent.Addr(), 1, uintptr(event), 0, 0)
  1843. if r1 == 0 {
  1844. if e1 != 0 {
  1845. err = errnoErr(e1)
  1846. } else {
  1847. err = syscall.EINVAL
  1848. }
  1849. }
  1850. return
  1851. }
  1852. func SleepEx(milliseconds uint32, alertable bool) (ret uint32) {
  1853. var _p0 uint32
  1854. if alertable {
  1855. _p0 = 1
  1856. } else {
  1857. _p0 = 0
  1858. }
  1859. r0, _, _ := syscall.Syscall(procSleepEx.Addr(), 2, uintptr(milliseconds), uintptr(_p0), 0)
  1860. ret = uint32(r0)
  1861. return
  1862. }
  1863. func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) {
  1864. r1, _, e1 := syscall.Syscall(procDefineDosDeviceW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)))
  1865. if r1 == 0 {
  1866. if e1 != 0 {
  1867. err = errnoErr(e1)
  1868. } else {
  1869. err = syscall.EINVAL
  1870. }
  1871. }
  1872. return
  1873. }
  1874. func DeleteVolumeMountPoint(volumeMountPoint *uint16) (err error) {
  1875. r1, _, e1 := syscall.Syscall(procDeleteVolumeMountPointW.Addr(), 1, uintptr(unsafe.Pointer(volumeMountPoint)), 0, 0)
  1876. if r1 == 0 {
  1877. if e1 != 0 {
  1878. err = errnoErr(e1)
  1879. } else {
  1880. err = syscall.EINVAL
  1881. }
  1882. }
  1883. return
  1884. }
  1885. func FindFirstVolume(volumeName *uint16, bufferLength uint32) (handle Handle, err error) {
  1886. r0, _, e1 := syscall.Syscall(procFindFirstVolumeW.Addr(), 2, uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength), 0)
  1887. handle = Handle(r0)
  1888. if handle == InvalidHandle {
  1889. if e1 != 0 {
  1890. err = errnoErr(e1)
  1891. } else {
  1892. err = syscall.EINVAL
  1893. }
  1894. }
  1895. return
  1896. }
  1897. func FindFirstVolumeMountPoint(rootPathName *uint16, volumeMountPoint *uint16, bufferLength uint32) (handle Handle, err error) {
  1898. r0, _, e1 := syscall.Syscall(procFindFirstVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength))
  1899. handle = Handle(r0)
  1900. if handle == InvalidHandle {
  1901. if e1 != 0 {
  1902. err = errnoErr(e1)
  1903. } else {
  1904. err = syscall.EINVAL
  1905. }
  1906. }
  1907. return
  1908. }
  1909. func FindNextVolume(findVolume Handle, volumeName *uint16, bufferLength uint32) (err error) {
  1910. r1, _, e1 := syscall.Syscall(procFindNextVolumeW.Addr(), 3, uintptr(findVolume), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength))
  1911. if r1 == 0 {
  1912. if e1 != 0 {
  1913. err = errnoErr(e1)
  1914. } else {
  1915. err = syscall.EINVAL
  1916. }
  1917. }
  1918. return
  1919. }
  1920. func FindNextVolumeMountPoint(findVolumeMountPoint Handle, volumeMountPoint *uint16, bufferLength uint32) (err error) {
  1921. r1, _, e1 := syscall.Syscall(procFindNextVolumeMountPointW.Addr(), 3, uintptr(findVolumeMountPoint), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength))
  1922. if r1 == 0 {
  1923. if e1 != 0 {
  1924. err = errnoErr(e1)
  1925. } else {
  1926. err = syscall.EINVAL
  1927. }
  1928. }
  1929. return
  1930. }
  1931. func FindVolumeClose(findVolume Handle) (err error) {
  1932. r1, _, e1 := syscall.Syscall(procFindVolumeClose.Addr(), 1, uintptr(findVolume), 0, 0)
  1933. if r1 == 0 {
  1934. if e1 != 0 {
  1935. err = errnoErr(e1)
  1936. } else {
  1937. err = syscall.EINVAL
  1938. }
  1939. }
  1940. return
  1941. }
  1942. func FindVolumeMountPointClose(findVolumeMountPoint Handle) (err error) {
  1943. r1, _, e1 := syscall.Syscall(procFindVolumeMountPointClose.Addr(), 1, uintptr(findVolumeMountPoint), 0, 0)
  1944. if r1 == 0 {
  1945. if e1 != 0 {
  1946. err = errnoErr(e1)
  1947. } else {
  1948. err = syscall.EINVAL
  1949. }
  1950. }
  1951. return
  1952. }
  1953. func GetDriveType(rootPathName *uint16) (driveType uint32) {
  1954. r0, _, _ := syscall.Syscall(procGetDriveTypeW.Addr(), 1, uintptr(unsafe.Pointer(rootPathName)), 0, 0)
  1955. driveType = uint32(r0)
  1956. return
  1957. }
  1958. func GetLogicalDrives() (drivesBitMask uint32, err error) {
  1959. r0, _, e1 := syscall.Syscall(procGetLogicalDrives.Addr(), 0, 0, 0, 0)
  1960. drivesBitMask = uint32(r0)
  1961. if drivesBitMask == 0 {
  1962. if e1 != 0 {
  1963. err = errnoErr(e1)
  1964. } else {
  1965. err = syscall.EINVAL
  1966. }
  1967. }
  1968. return
  1969. }
  1970. func GetLogicalDriveStrings(bufferLength uint32, buffer *uint16) (n uint32, err error) {
  1971. r0, _, e1 := syscall.Syscall(procGetLogicalDriveStringsW.Addr(), 2, uintptr(bufferLength), uintptr(unsafe.Pointer(buffer)), 0)
  1972. n = uint32(r0)
  1973. if n == 0 {
  1974. if e1 != 0 {
  1975. err = errnoErr(e1)
  1976. } else {
  1977. err = syscall.EINVAL
  1978. }
  1979. }
  1980. return
  1981. }
  1982. func GetVolumeInformation(rootPathName *uint16, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
  1983. r1, _, e1 := syscall.Syscall9(procGetVolumeInformationW.Addr(), 8, uintptr(unsafe.Pointer(rootPathName)), 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)
  1984. if r1 == 0 {
  1985. if e1 != 0 {
  1986. err = errnoErr(e1)
  1987. } else {
  1988. err = syscall.EINVAL
  1989. }
  1990. }
  1991. return
  1992. }
  1993. func GetVolumeInformationByHandle(file Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
  1994. 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)
  1995. if r1 == 0 {
  1996. if e1 != 0 {
  1997. err = errnoErr(e1)
  1998. } else {
  1999. err = syscall.EINVAL
  2000. }
  2001. }
  2002. return
  2003. }
  2004. func GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) {
  2005. r1, _, e1 := syscall.Syscall(procGetVolumeNameForVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferlength))
  2006. if r1 == 0 {
  2007. if e1 != 0 {
  2008. err = errnoErr(e1)
  2009. } else {
  2010. err = syscall.EINVAL
  2011. }
  2012. }
  2013. return
  2014. }
  2015. func GetVolumePathName(fileName *uint16, volumePathName *uint16, bufferLength uint32) (err error) {
  2016. r1, _, e1 := syscall.Syscall(procGetVolumePathNameW.Addr(), 3, uintptr(unsafe.Pointer(fileName)), uintptr(unsafe.Pointer(volumePathName)), uintptr(bufferLength))
  2017. if r1 == 0 {
  2018. if e1 != 0 {
  2019. err = errnoErr(e1)
  2020. } else {
  2021. err = syscall.EINVAL
  2022. }
  2023. }
  2024. return
  2025. }
  2026. func GetVolumePathNamesForVolumeName(volumeName *uint16, volumePathNames *uint16, bufferLength uint32, returnLength *uint32) (err error) {
  2027. r1, _, e1 := syscall.Syscall6(procGetVolumePathNamesForVolumeNameW.Addr(), 4, uintptr(unsafe.Pointer(volumeName)), uintptr(unsafe.Pointer(volumePathNames)), uintptr(bufferLength), uintptr(unsafe.Pointer(returnLength)), 0, 0)
  2028. if r1 == 0 {
  2029. if e1 != 0 {
  2030. err = errnoErr(e1)
  2031. } else {
  2032. err = syscall.EINVAL
  2033. }
  2034. }
  2035. return
  2036. }
  2037. func QueryDosDevice(deviceName *uint16, targetPath *uint16, max uint32) (n uint32, err error) {
  2038. r0, _, e1 := syscall.Syscall(procQueryDosDeviceW.Addr(), 3, uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)), uintptr(max))
  2039. n = uint32(r0)
  2040. if n == 0 {
  2041. if e1 != 0 {
  2042. err = errnoErr(e1)
  2043. } else {
  2044. err = syscall.EINVAL
  2045. }
  2046. }
  2047. return
  2048. }
  2049. func SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) {
  2050. r1, _, e1 := syscall.Syscall(procSetVolumeLabelW.Addr(), 2, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeName)), 0)
  2051. if r1 == 0 {
  2052. if e1 != 0 {
  2053. err = errnoErr(e1)
  2054. } else {
  2055. err = syscall.EINVAL
  2056. }
  2057. }
  2058. return
  2059. }
  2060. func SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err error) {
  2061. r1, _, e1 := syscall.Syscall(procSetVolumeMountPointW.Addr(), 2, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), 0)
  2062. if r1 == 0 {
  2063. if e1 != 0 {
  2064. err = errnoErr(e1)
  2065. } else {
  2066. err = syscall.EINVAL
  2067. }
  2068. }
  2069. return
  2070. }
  2071. func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
  2072. r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
  2073. if r0 != 0 {
  2074. sockerr = syscall.Errno(r0)
  2075. }
  2076. return
  2077. }
  2078. func WSACleanup() (err error) {
  2079. r1, _, e1 := syscall.Syscall(procWSACleanup.Addr(), 0, 0, 0, 0)
  2080. if r1 == socket_error {
  2081. if e1 != 0 {
  2082. err = errnoErr(e1)
  2083. } else {
  2084. err = syscall.EINVAL
  2085. }
  2086. }
  2087. return
  2088. }
  2089. func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
  2090. r1, _, e1 := syscall.Syscall9(procWSAIoctl.Addr(), 9, uintptr(s), uintptr(iocc), uintptr(unsafe.Pointer(inbuf)), uintptr(cbif), uintptr(unsafe.Pointer(outbuf)), uintptr(cbob), uintptr(unsafe.Pointer(cbbr)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine))
  2091. if r1 == socket_error {
  2092. if e1 != 0 {
  2093. err = errnoErr(e1)
  2094. } else {
  2095. err = syscall.EINVAL
  2096. }
  2097. }
  2098. return
  2099. }
  2100. func socket(af int32, typ int32, protocol int32) (handle Handle, err error) {
  2101. r0, _, e1 := syscall.Syscall(procsocket.Addr(), 3, uintptr(af), uintptr(typ), uintptr(protocol))
  2102. handle = Handle(r0)
  2103. if handle == InvalidHandle {
  2104. if e1 != 0 {
  2105. err = errnoErr(e1)
  2106. } else {
  2107. err = syscall.EINVAL
  2108. }
  2109. }
  2110. return
  2111. }
  2112. func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) {
  2113. r1, _, e1 := syscall.Syscall6(procsetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen), 0)
  2114. if r1 == socket_error {
  2115. if e1 != 0 {
  2116. err = errnoErr(e1)
  2117. } else {
  2118. err = syscall.EINVAL
  2119. }
  2120. }
  2121. return
  2122. }
  2123. func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) {
  2124. r1, _, e1 := syscall.Syscall6(procgetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen)), 0)
  2125. if r1 == socket_error {
  2126. if e1 != 0 {
  2127. err = errnoErr(e1)
  2128. } else {
  2129. err = syscall.EINVAL
  2130. }
  2131. }
  2132. return
  2133. }
  2134. func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) {
  2135. r1, _, e1 := syscall.Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
  2136. if r1 == socket_error {
  2137. if e1 != 0 {
  2138. err = errnoErr(e1)
  2139. } else {
  2140. err = syscall.EINVAL
  2141. }
  2142. }
  2143. return
  2144. }
  2145. func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) {
  2146. r1, _, e1 := syscall.Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
  2147. if r1 == socket_error {
  2148. if e1 != 0 {
  2149. err = errnoErr(e1)
  2150. } else {
  2151. err = syscall.EINVAL
  2152. }
  2153. }
  2154. return
  2155. }
  2156. func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
  2157. r1, _, e1 := syscall.Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
  2158. if r1 == socket_error {
  2159. if e1 != 0 {
  2160. err = errnoErr(e1)
  2161. } else {
  2162. err = syscall.EINVAL
  2163. }
  2164. }
  2165. return
  2166. }
  2167. func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
  2168. r1, _, e1 := syscall.Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
  2169. if r1 == socket_error {
  2170. if e1 != 0 {
  2171. err = errnoErr(e1)
  2172. } else {
  2173. err = syscall.EINVAL
  2174. }
  2175. }
  2176. return
  2177. }
  2178. func listen(s Handle, backlog int32) (err error) {
  2179. r1, _, e1 := syscall.Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0)
  2180. if r1 == socket_error {
  2181. if e1 != 0 {
  2182. err = errnoErr(e1)
  2183. } else {
  2184. err = syscall.EINVAL
  2185. }
  2186. }
  2187. return
  2188. }
  2189. func shutdown(s Handle, how int32) (err error) {
  2190. r1, _, e1 := syscall.Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0)
  2191. if r1 == socket_error {
  2192. if e1 != 0 {
  2193. err = errnoErr(e1)
  2194. } else {
  2195. err = syscall.EINVAL
  2196. }
  2197. }
  2198. return
  2199. }
  2200. func Closesocket(s Handle) (err error) {
  2201. r1, _, e1 := syscall.Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0)
  2202. if r1 == socket_error {
  2203. if e1 != 0 {
  2204. err = errnoErr(e1)
  2205. } else {
  2206. err = syscall.EINVAL
  2207. }
  2208. }
  2209. return
  2210. }
  2211. func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (err error) {
  2212. r1, _, e1 := syscall.Syscall9(procAcceptEx.Addr(), 8, uintptr(ls), uintptr(as), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(overlapped)), 0)
  2213. if r1 == 0 {
  2214. if e1 != 0 {
  2215. err = errnoErr(e1)
  2216. } else {
  2217. err = syscall.EINVAL
  2218. }
  2219. }
  2220. return
  2221. }
  2222. func GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) {
  2223. syscall.Syscall9(procGetAcceptExSockaddrs.Addr(), 8, uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(lrsa)), uintptr(unsafe.Pointer(lrsalen)), uintptr(unsafe.Pointer(rrsa)), uintptr(unsafe.Pointer(rrsalen)), 0)
  2224. return
  2225. }
  2226. func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) {
  2227. r1, _, e1 := syscall.Syscall9(procWSARecv.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0)
  2228. if r1 == socket_error {
  2229. if e1 != 0 {
  2230. err = errnoErr(e1)
  2231. } else {
  2232. err = syscall.EINVAL
  2233. }
  2234. }
  2235. return
  2236. }
  2237. func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) {
  2238. r1, _, e1 := syscall.Syscall9(procWSASend.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0)
  2239. if r1 == socket_error {
  2240. if e1 != 0 {
  2241. err = errnoErr(e1)
  2242. } else {
  2243. err = syscall.EINVAL
  2244. }
  2245. }
  2246. return
  2247. }
  2248. func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) {
  2249. r1, _, e1 := syscall.Syscall9(procWSARecvFrom.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
  2250. if r1 == socket_error {
  2251. if e1 != 0 {
  2252. err = errnoErr(e1)
  2253. } else {
  2254. err = syscall.EINVAL
  2255. }
  2256. }
  2257. return
  2258. }
  2259. func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) {
  2260. r1, _, e1 := syscall.Syscall9(procWSASendTo.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(to)), uintptr(tolen), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
  2261. if r1 == socket_error {
  2262. if e1 != 0 {
  2263. err = errnoErr(e1)
  2264. } else {
  2265. err = syscall.EINVAL
  2266. }
  2267. }
  2268. return
  2269. }
  2270. func GetHostByName(name string) (h *Hostent, err error) {
  2271. var _p0 *byte
  2272. _p0, err = syscall.BytePtrFromString(name)
  2273. if err != nil {
  2274. return
  2275. }
  2276. return _GetHostByName(_p0)
  2277. }
  2278. func _GetHostByName(name *byte) (h *Hostent, err error) {
  2279. r0, _, e1 := syscall.Syscall(procgethostbyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
  2280. h = (*Hostent)(unsafe.Pointer(r0))
  2281. if h == nil {
  2282. if e1 != 0 {
  2283. err = errnoErr(e1)
  2284. } else {
  2285. err = syscall.EINVAL
  2286. }
  2287. }
  2288. return
  2289. }
  2290. func GetServByName(name string, proto string) (s *Servent, err error) {
  2291. var _p0 *byte
  2292. _p0, err = syscall.BytePtrFromString(name)
  2293. if err != nil {
  2294. return
  2295. }
  2296. var _p1 *byte
  2297. _p1, err = syscall.BytePtrFromString(proto)
  2298. if err != nil {
  2299. return
  2300. }
  2301. return _GetServByName(_p0, _p1)
  2302. }
  2303. func _GetServByName(name *byte, proto *byte) (s *Servent, err error) {
  2304. r0, _, e1 := syscall.Syscall(procgetservbyname.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(proto)), 0)
  2305. s = (*Servent)(unsafe.Pointer(r0))
  2306. if s == nil {
  2307. if e1 != 0 {
  2308. err = errnoErr(e1)
  2309. } else {
  2310. err = syscall.EINVAL
  2311. }
  2312. }
  2313. return
  2314. }
  2315. func Ntohs(netshort uint16) (u uint16) {
  2316. r0, _, _ := syscall.Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0)
  2317. u = uint16(r0)
  2318. return
  2319. }
  2320. func GetProtoByName(name string) (p *Protoent, err error) {
  2321. var _p0 *byte
  2322. _p0, err = syscall.BytePtrFromString(name)
  2323. if err != nil {
  2324. return
  2325. }
  2326. return _GetProtoByName(_p0)
  2327. }
  2328. func _GetProtoByName(name *byte) (p *Protoent, err error) {
  2329. r0, _, e1 := syscall.Syscall(procgetprotobyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
  2330. p = (*Protoent)(unsafe.Pointer(r0))
  2331. if p == nil {
  2332. if e1 != 0 {
  2333. err = errnoErr(e1)
  2334. } else {
  2335. err = syscall.EINVAL
  2336. }
  2337. }
  2338. return
  2339. }
  2340. func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
  2341. var _p0 *uint16
  2342. _p0, status = syscall.UTF16PtrFromString(name)
  2343. if status != nil {
  2344. return
  2345. }
  2346. return _DnsQuery(_p0, qtype, options, extra, qrs, pr)
  2347. }
  2348. func _DnsQuery(name *uint16, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
  2349. r0, _, _ := syscall.Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(name)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
  2350. if r0 != 0 {
  2351. status = syscall.Errno(r0)
  2352. }
  2353. return
  2354. }
  2355. func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
  2356. syscall.Syscall(procDnsRecordListFree.Addr(), 2, uintptr(unsafe.Pointer(rl)), uintptr(freetype), 0)
  2357. return
  2358. }
  2359. func DnsNameCompare(name1 *uint16, name2 *uint16) (same bool) {
  2360. r0, _, _ := syscall.Syscall(procDnsNameCompare_W.Addr(), 2, uintptr(unsafe.Pointer(name1)), uintptr(unsafe.Pointer(name2)), 0)
  2361. same = r0 != 0
  2362. return
  2363. }
  2364. func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
  2365. r0, _, _ := syscall.Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0)
  2366. if r0 != 0 {
  2367. sockerr = syscall.Errno(r0)
  2368. }
  2369. return
  2370. }
  2371. func FreeAddrInfoW(addrinfo *AddrinfoW) {
  2372. syscall.Syscall(procFreeAddrInfoW.Addr(), 1, uintptr(unsafe.Pointer(addrinfo)), 0, 0)
  2373. return
  2374. }
  2375. func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
  2376. r0, _, _ := syscall.Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
  2377. if r0 != 0 {
  2378. errcode = syscall.Errno(r0)
  2379. }
  2380. return
  2381. }
  2382. func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
  2383. r0, _, _ := syscall.Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
  2384. if r0 != 0 {
  2385. errcode = syscall.Errno(r0)
  2386. }
  2387. return
  2388. }
  2389. func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) {
  2390. r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0)
  2391. if r1 == 0 {
  2392. if e1 != 0 {
  2393. err = errnoErr(e1)
  2394. } else {
  2395. err = syscall.EINVAL
  2396. }
  2397. }
  2398. return
  2399. }
  2400. func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) {
  2401. r0, _, e1 := syscall.Syscall(procWSAEnumProtocolsW.Addr(), 3, uintptr(unsafe.Pointer(protocols)), uintptr(unsafe.Pointer(protocolBuffer)), uintptr(unsafe.Pointer(bufferLength)))
  2402. n = int32(r0)
  2403. if n == -1 {
  2404. if e1 != 0 {
  2405. err = errnoErr(e1)
  2406. } else {
  2407. err = syscall.EINVAL
  2408. }
  2409. }
  2410. return
  2411. }
  2412. func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
  2413. r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
  2414. if r0 != 0 {
  2415. errcode = syscall.Errno(r0)
  2416. }
  2417. return
  2418. }
  2419. func GetACP() (acp uint32) {
  2420. r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
  2421. acp = uint32(r0)
  2422. return
  2423. }
  2424. func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
  2425. r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
  2426. nwrite = int32(r0)
  2427. if nwrite == 0 {
  2428. if e1 != 0 {
  2429. err = errnoErr(e1)
  2430. } else {
  2431. err = syscall.EINVAL
  2432. }
  2433. }
  2434. return
  2435. }
  2436. func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
  2437. r1, _, e1 := syscall.Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0)
  2438. if r1&0xff == 0 {
  2439. if e1 != 0 {
  2440. err = errnoErr(e1)
  2441. } else {
  2442. err = syscall.EINVAL
  2443. }
  2444. }
  2445. return
  2446. }
  2447. func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) {
  2448. r1, _, e1 := syscall.Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize)))
  2449. if r1&0xff == 0 {
  2450. if e1 != 0 {
  2451. err = errnoErr(e1)
  2452. } else {
  2453. err = syscall.EINVAL
  2454. }
  2455. }
  2456. return
  2457. }
  2458. func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
  2459. r0, _, _ := syscall.Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0)
  2460. if r0 != 0 {
  2461. neterr = syscall.Errno(r0)
  2462. }
  2463. return
  2464. }
  2465. func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
  2466. r0, _, _ := syscall.Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType)))
  2467. if r0 != 0 {
  2468. neterr = syscall.Errno(r0)
  2469. }
  2470. return
  2471. }
  2472. func NetApiBufferFree(buf *byte) (neterr error) {
  2473. r0, _, _ := syscall.Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
  2474. if r0 != 0 {
  2475. neterr = syscall.Errno(r0)
  2476. }
  2477. return
  2478. }
  2479. func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
  2480. r1, _, e1 := syscall.Syscall9(procLookupAccountSidW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0)
  2481. if r1 == 0 {
  2482. if e1 != 0 {
  2483. err = errnoErr(e1)
  2484. } else {
  2485. err = syscall.EINVAL
  2486. }
  2487. }
  2488. return
  2489. }
  2490. func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
  2491. r1, _, e1 := syscall.Syscall9(procLookupAccountNameW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0)
  2492. if r1 == 0 {
  2493. if e1 != 0 {
  2494. err = errnoErr(e1)
  2495. } else {
  2496. err = syscall.EINVAL
  2497. }
  2498. }
  2499. return
  2500. }
  2501. func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) {
  2502. r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0)
  2503. if r1 == 0 {
  2504. if e1 != 0 {
  2505. err = errnoErr(e1)
  2506. } else {
  2507. err = syscall.EINVAL
  2508. }
  2509. }
  2510. return
  2511. }
  2512. func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) {
  2513. r1, _, e1 := syscall.Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0)
  2514. if r1 == 0 {
  2515. if e1 != 0 {
  2516. err = errnoErr(e1)
  2517. } else {
  2518. err = syscall.EINVAL
  2519. }
  2520. }
  2521. return
  2522. }
  2523. func GetLengthSid(sid *SID) (len uint32) {
  2524. r0, _, _ := syscall.Syscall(procGetLengthSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
  2525. len = uint32(r0)
  2526. return
  2527. }
  2528. func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) {
  2529. r1, _, e1 := syscall.Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid)))
  2530. if r1 == 0 {
  2531. if e1 != 0 {
  2532. err = errnoErr(e1)
  2533. } else {
  2534. err = syscall.EINVAL
  2535. }
  2536. }
  2537. return
  2538. }
  2539. func AllocateAndInitializeSid(identAuth *SidIdentifierAuthority, subAuth byte, subAuth0 uint32, subAuth1 uint32, subAuth2 uint32, subAuth3 uint32, subAuth4 uint32, subAuth5 uint32, subAuth6 uint32, subAuth7 uint32, sid **SID) (err error) {
  2540. r1, _, e1 := syscall.Syscall12(procAllocateAndInitializeSid.Addr(), 11, uintptr(unsafe.Pointer(identAuth)), uintptr(subAuth), uintptr(subAuth0), uintptr(subAuth1), uintptr(subAuth2), uintptr(subAuth3), uintptr(subAuth4), uintptr(subAuth5), uintptr(subAuth6), uintptr(subAuth7), uintptr(unsafe.Pointer(sid)), 0)
  2541. if r1 == 0 {
  2542. if e1 != 0 {
  2543. err = errnoErr(e1)
  2544. } else {
  2545. err = syscall.EINVAL
  2546. }
  2547. }
  2548. return
  2549. }
  2550. func createWellKnownSid(sidType WELL_KNOWN_SID_TYPE, domainSid *SID, sid *SID, sizeSid *uint32) (err error) {
  2551. r1, _, e1 := syscall.Syscall6(procCreateWellKnownSid.Addr(), 4, uintptr(sidType), uintptr(unsafe.Pointer(domainSid)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sizeSid)), 0, 0)
  2552. if r1 == 0 {
  2553. if e1 != 0 {
  2554. err = errnoErr(e1)
  2555. } else {
  2556. err = syscall.EINVAL
  2557. }
  2558. }
  2559. return
  2560. }
  2561. func FreeSid(sid *SID) (err error) {
  2562. r1, _, e1 := syscall.Syscall(procFreeSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
  2563. if r1 != 0 {
  2564. if e1 != 0 {
  2565. err = errnoErr(e1)
  2566. } else {
  2567. err = syscall.EINVAL
  2568. }
  2569. }
  2570. return
  2571. }
  2572. func EqualSid(sid1 *SID, sid2 *SID) (isEqual bool) {
  2573. r0, _, _ := syscall.Syscall(procEqualSid.Addr(), 2, uintptr(unsafe.Pointer(sid1)), uintptr(unsafe.Pointer(sid2)), 0)
  2574. isEqual = r0 != 0
  2575. return
  2576. }
  2577. func checkTokenMembership(tokenHandle Token, sidToCheck *SID, isMember *int32) (err error) {
  2578. r1, _, e1 := syscall.Syscall(procCheckTokenMembership.Addr(), 3, uintptr(tokenHandle), uintptr(unsafe.Pointer(sidToCheck)), uintptr(unsafe.Pointer(isMember)))
  2579. if r1 == 0 {
  2580. if e1 != 0 {
  2581. err = errnoErr(e1)
  2582. } else {
  2583. err = syscall.EINVAL
  2584. }
  2585. }
  2586. return
  2587. }
  2588. func OpenProcessToken(process Handle, access uint32, token *Token) (err error) {
  2589. r1, _, e1 := syscall.Syscall(procOpenProcessToken.Addr(), 3, uintptr(process), uintptr(access), uintptr(unsafe.Pointer(token)))
  2590. if r1 == 0 {
  2591. if e1 != 0 {
  2592. err = errnoErr(e1)
  2593. } else {
  2594. err = syscall.EINVAL
  2595. }
  2596. }
  2597. return
  2598. }
  2599. func GetCurrentThreadToken() (token Token) {
  2600. r0, _, _ := syscall.Syscall(procGetCurrentThreadToken.Addr(), 0, 0, 0, 0)
  2601. token = Token(r0)
  2602. return
  2603. }
  2604. func OpenThreadToken(thread Handle, access uint32, openAsSelf bool, token *Token) (err error) {
  2605. var _p0 uint32
  2606. if openAsSelf {
  2607. _p0 = 1
  2608. } else {
  2609. _p0 = 0
  2610. }
  2611. r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(thread), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0)
  2612. if r1 == 0 {
  2613. if e1 != 0 {
  2614. err = errnoErr(e1)
  2615. } else {
  2616. err = syscall.EINVAL
  2617. }
  2618. }
  2619. return
  2620. }
  2621. func GetCurrentProcessToken() (token Token) {
  2622. r0, _, _ := syscall.Syscall(procGetCurrentProcessToken.Addr(), 0, 0, 0, 0)
  2623. token = Token(r0)
  2624. return
  2625. }
  2626. func ImpersonateSelf(impersonationlevel uint32) (err error) {
  2627. r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0)
  2628. if r1 == 0 {
  2629. if e1 != 0 {
  2630. err = errnoErr(e1)
  2631. } else {
  2632. err = syscall.EINVAL
  2633. }
  2634. }
  2635. return
  2636. }
  2637. func RevertToSelf() (err error) {
  2638. r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0)
  2639. if r1 == 0 {
  2640. if e1 != 0 {
  2641. err = errnoErr(e1)
  2642. } else {
  2643. err = syscall.EINVAL
  2644. }
  2645. }
  2646. return
  2647. }
  2648. func SetThreadToken(thread *Handle, token Token) (err error) {
  2649. r1, _, e1 := syscall.Syscall(procSetThreadToken.Addr(), 2, uintptr(unsafe.Pointer(thread)), uintptr(token), 0)
  2650. if r1 == 0 {
  2651. if e1 != 0 {
  2652. err = errnoErr(e1)
  2653. } else {
  2654. err = syscall.EINVAL
  2655. }
  2656. }
  2657. return
  2658. }
  2659. func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) {
  2660. r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid)))
  2661. if r1 == 0 {
  2662. if e1 != 0 {
  2663. err = errnoErr(e1)
  2664. } else {
  2665. err = syscall.EINVAL
  2666. }
  2667. }
  2668. return
  2669. }
  2670. func AdjustTokenPrivileges(token Token, disableAllPrivileges bool, newstate *Tokenprivileges, buflen uint32, prevstate *Tokenprivileges, returnlen *uint32) (err error) {
  2671. var _p0 uint32
  2672. if disableAllPrivileges {
  2673. _p0 = 1
  2674. } else {
  2675. _p0 = 0
  2676. }
  2677. r1, _, e1 := syscall.Syscall6(procAdjustTokenPrivileges.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen)))
  2678. if r1 == 0 {
  2679. if e1 != 0 {
  2680. err = errnoErr(e1)
  2681. } else {
  2682. err = syscall.EINVAL
  2683. }
  2684. }
  2685. return
  2686. }
  2687. func GetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) {
  2688. r1, _, e1 := syscall.Syscall6(procGetTokenInformation.Addr(), 5, uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0)
  2689. if r1 == 0 {
  2690. if e1 != 0 {
  2691. err = errnoErr(e1)
  2692. } else {
  2693. err = syscall.EINVAL
  2694. }
  2695. }
  2696. return
  2697. }
  2698. func SetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint32) (err error) {
  2699. r1, _, e1 := syscall.Syscall6(procSetTokenInformation.Addr(), 4, uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), 0, 0)
  2700. if r1 == 0 {
  2701. if e1 != 0 {
  2702. err = errnoErr(e1)
  2703. } else {
  2704. err = syscall.EINVAL
  2705. }
  2706. }
  2707. return
  2708. }
  2709. func DuplicateTokenEx(existingToken Token, desiredAccess uint32, tokenAttributes *SecurityAttributes, impersonationLevel uint32, tokenType uint32, newToken *Token) (err error) {
  2710. r1, _, e1 := syscall.Syscall6(procDuplicateTokenEx.Addr(), 6, uintptr(existingToken), uintptr(desiredAccess), uintptr(unsafe.Pointer(tokenAttributes)), uintptr(impersonationLevel), uintptr(tokenType), uintptr(unsafe.Pointer(newToken)))
  2711. if r1 == 0 {
  2712. if e1 != 0 {
  2713. err = errnoErr(e1)
  2714. } else {
  2715. err = syscall.EINVAL
  2716. }
  2717. }
  2718. return
  2719. }
  2720. func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
  2721. r1, _, e1 := syscall.Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)))
  2722. if r1 == 0 {
  2723. if e1 != 0 {
  2724. err = errnoErr(e1)
  2725. } else {
  2726. err = syscall.EINVAL
  2727. }
  2728. }
  2729. return
  2730. }
  2731. func getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) {
  2732. r0, _, e1 := syscall.Syscall(procGetSystemDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(dirLen), 0)
  2733. len = uint32(r0)
  2734. if len == 0 {
  2735. if e1 != 0 {
  2736. err = errnoErr(e1)
  2737. } else {
  2738. err = syscall.EINVAL
  2739. }
  2740. }
  2741. return
  2742. }
  2743. func WTSQueryUserToken(session uint32, token *Token) (err error) {
  2744. r1, _, e1 := syscall.Syscall(procWTSQueryUserToken.Addr(), 2, uintptr(session), uintptr(unsafe.Pointer(token)), 0)
  2745. if r1 == 0 {
  2746. if e1 != 0 {
  2747. err = errnoErr(e1)
  2748. } else {
  2749. err = syscall.EINVAL
  2750. }
  2751. }
  2752. return
  2753. }
  2754. func WTSEnumerateSessions(handle Handle, reserved uint32, version uint32, sessions **WTS_SESSION_INFO, count *uint32) (err error) {
  2755. r1, _, e1 := syscall.Syscall6(procWTSEnumerateSessionsW.Addr(), 5, uintptr(handle), uintptr(reserved), uintptr(version), uintptr(unsafe.Pointer(sessions)), uintptr(unsafe.Pointer(count)), 0)
  2756. if r1 == 0 {
  2757. if e1 != 0 {
  2758. err = errnoErr(e1)
  2759. } else {
  2760. err = syscall.EINVAL
  2761. }
  2762. }
  2763. return
  2764. }
  2765. func WTSFreeMemory(ptr uintptr) {
  2766. syscall.Syscall(procWTSFreeMemory.Addr(), 1, uintptr(ptr), 0, 0)
  2767. return
  2768. }