zsyscall_windows.go 98 KB

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