zsyscall_windows.go 104 KB

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