zsyscall_windows.go 97 KB

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