advapi32.odin 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // +build windows
  2. package sys_windows
  3. foreign import advapi32 "system:Advapi32.lib"
  4. HCRYPTPROV :: distinct HANDLE
  5. @(default_calling_convention="stdcall")
  6. foreign advapi32 {
  7. @(link_name = "SystemFunction036")
  8. RtlGenRandom :: proc(RandomBuffer: ^u8, RandomBufferLength: ULONG) -> BOOLEAN ---
  9. OpenProcessToken :: proc(ProcessHandle: HANDLE,
  10. DesiredAccess: DWORD,
  11. TokenHandle: ^HANDLE) -> BOOL ---
  12. CryptAcquireContextW :: proc(hProv: ^HCRYPTPROV, szContainer, szProvider: wstring, dwProvType, dwFlags: DWORD) -> DWORD ---
  13. CryptGenRandom :: proc(hProv: HCRYPTPROV, dwLen: DWORD, buf: LPVOID) -> DWORD ---
  14. CryptReleaseContext :: proc(hProv: HCRYPTPROV, dwFlags: DWORD) -> DWORD ---
  15. }
  16. // Necessary to create a token to impersonate a user with for CreateProcessAsUser
  17. @(default_calling_convention="stdcall")
  18. foreign advapi32 {
  19. LogonUserW :: proc(
  20. lpszUsername: LPCWSTR,
  21. lpszDomain: LPCWSTR,
  22. lpszPassword: LPCWSTR,
  23. dwLogonType: Logon32_Type,
  24. dwLogonProvider: Logon32_Provider,
  25. phToken: ^HANDLE,
  26. ) -> BOOL ---
  27. // https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-lookupaccountnamew
  28. // To look up the SID to use with DeleteProfileW.
  29. LookupAccountNameW :: proc(
  30. lpSystemName: wstring,
  31. lpAccountName: wstring,
  32. Sid: ^SID,
  33. cbSid: ^DWORD,
  34. ReferencedDomainName: wstring,
  35. cchReferencedDomainName: ^DWORD,
  36. peUse: ^SID_TYPE,
  37. ) -> BOOL ---
  38. CreateProcessWithLogonW :: proc(
  39. lpUsername: wstring,
  40. lpDomain: wstring,
  41. lpPassword: wstring,
  42. dwLogonFlags: DWORD,
  43. lpApplicationName: wstring,
  44. lpCommandLine: wstring,
  45. dwCreationFlags: DWORD,
  46. lpEnvironment: LPVOID,
  47. lpCurrentDirectory: wstring,
  48. lpStartupInfo: LPSTARTUPINFOW,
  49. lpProcessInformation: LPPROCESS_INFORMATION,
  50. ) -> BOOL ---
  51. // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessasuserw
  52. CreateProcessAsUserW :: proc(
  53. hToken: HANDLE,
  54. lpApplicationName: wstring,
  55. lpCommandLine: wstring,
  56. lpProcessAttributes: LPSECURITY_ATTRIBUTES,
  57. lpThreadAttributes: LPSECURITY_ATTRIBUTES,
  58. bInheritHandles: BOOL,
  59. dwCreationFlags: DWORD,
  60. lpEnvironment: LPVOID,
  61. lpCurrentDirectory: wstring,
  62. lpStartupInfo: LPSTARTUPINFOW,
  63. lpProcessInformation: LPPROCESS_INFORMATION,
  64. ) -> BOOL ---
  65. RegCreateKeyExW :: proc(
  66. hKey: HKEY,
  67. lpSubKey: LPCWSTR,
  68. Reserved: DWORD,
  69. lpClass: LPWSTR,
  70. dwOptions: DWORD,
  71. samDesired: REGSAM,
  72. lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
  73. phkResult: PHKEY,
  74. lpdwDisposition: LPDWORD,
  75. ) -> LSTATUS ---
  76. RegOpenKeyW :: proc(
  77. hKey: HKEY,
  78. lpSubKey: LPCWSTR,
  79. phkResult: PHKEY,
  80. ) -> LSTATUS ---
  81. RegOpenKeyExW :: proc(
  82. hKey: HKEY,
  83. lpSubKey: LPCWSTR,
  84. ulOptions: DWORD,
  85. samDesired: REGSAM,
  86. phkResult: PHKEY,
  87. ) -> LSTATUS ---
  88. RegCloseKey :: proc(
  89. hKey: HKEY,
  90. ) -> LSTATUS ---
  91. RegGetValueW :: proc(
  92. hkey: HKEY,
  93. lpSubKey: LPCWSTR,
  94. lpValue: LPCWSTR,
  95. dwFlags: DWORD,
  96. pdwType: LPDWORD,
  97. pvData: PVOID,
  98. pcbData: LPDWORD,
  99. ) -> LSTATUS ---
  100. RegSetValueExW :: proc(
  101. hKey: HKEY,
  102. lpValueName: LPCWSTR,
  103. Reserved: DWORD,
  104. dwType: DWORD,
  105. lpData: ^BYTE,
  106. cbData: DWORD,
  107. ) -> LSTATUS ---
  108. RegSetKeyValueW :: proc(
  109. hKey: HKEY,
  110. lpSubKey: LPCWSTR,
  111. lpValueName: LPCWSTR,
  112. dwType: DWORD,
  113. lpData: LPCVOID,
  114. cbData: DWORD,
  115. ) -> LSTATUS ---
  116. GetFileSecurityW :: proc(
  117. lpFileName: LPCWSTR,
  118. RequestedInformation: SECURITY_INFORMATION,
  119. pSecurityDescriptor: PSECURITY_DESCRIPTOR,
  120. nLength: DWORD,
  121. lpnLengthNeeded: LPDWORD,
  122. ) -> BOOL ---
  123. DuplicateToken :: proc(
  124. ExistingTokenHandle: HANDLE,
  125. ImpersonationLevel: SECURITY_IMPERSONATION_LEVEL,
  126. DuplicateTokenHandle: PHANDLE,
  127. ) -> BOOL ---
  128. MapGenericMask :: proc(
  129. AccessMask: PDWORD,
  130. GenericMapping: PGENERIC_MAPPING,
  131. ) ---
  132. AccessCheck :: proc(
  133. pSecurityDescriptor: PSECURITY_DESCRIPTOR,
  134. ClientToken: HANDLE,
  135. DesiredAccess: DWORD,
  136. GenericMapping: PGENERIC_MAPPING,
  137. PrivilegeSet: PPRIVILEGE_SET,
  138. PrivilegeSetLength: LPDWORD,
  139. GrantedAccess: LPDWORD,
  140. AccessStatus: LPBOOL,
  141. ) -> BOOL ---
  142. }