1// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package windows
6
7import (
8	"net"
9	"syscall"
10	"unsafe"
11)
12
13const (
14	// Invented values to support what package os expects.
15	O_RDONLY   = 0x00000
16	O_WRONLY   = 0x00001
17	O_RDWR     = 0x00002
18	O_CREAT    = 0x00040
19	O_EXCL     = 0x00080
20	O_NOCTTY   = 0x00100
21	O_TRUNC    = 0x00200
22	O_NONBLOCK = 0x00800
23	O_APPEND   = 0x00400
24	O_SYNC     = 0x01000
25	O_ASYNC    = 0x02000
26	O_CLOEXEC  = 0x80000
27)
28
29const (
30	// More invented values for signals
31	SIGHUP  = Signal(0x1)
32	SIGINT  = Signal(0x2)
33	SIGQUIT = Signal(0x3)
34	SIGILL  = Signal(0x4)
35	SIGTRAP = Signal(0x5)
36	SIGABRT = Signal(0x6)
37	SIGBUS  = Signal(0x7)
38	SIGFPE  = Signal(0x8)
39	SIGKILL = Signal(0x9)
40	SIGSEGV = Signal(0xb)
41	SIGPIPE = Signal(0xd)
42	SIGALRM = Signal(0xe)
43	SIGTERM = Signal(0xf)
44)
45
46var signals = [...]string{
47	1:  "hangup",
48	2:  "interrupt",
49	3:  "quit",
50	4:  "illegal instruction",
51	5:  "trace/breakpoint trap",
52	6:  "aborted",
53	7:  "bus error",
54	8:  "floating point exception",
55	9:  "killed",
56	10: "user defined signal 1",
57	11: "segmentation fault",
58	12: "user defined signal 2",
59	13: "broken pipe",
60	14: "alarm clock",
61	15: "terminated",
62}
63
64const (
65	FILE_LIST_DIRECTORY   = 0x00000001
66	FILE_APPEND_DATA      = 0x00000004
67	FILE_WRITE_ATTRIBUTES = 0x00000100
68
69	FILE_SHARE_READ   = 0x00000001
70	FILE_SHARE_WRITE  = 0x00000002
71	FILE_SHARE_DELETE = 0x00000004
72
73	FILE_ATTRIBUTE_READONLY              = 0x00000001
74	FILE_ATTRIBUTE_HIDDEN                = 0x00000002
75	FILE_ATTRIBUTE_SYSTEM                = 0x00000004
76	FILE_ATTRIBUTE_DIRECTORY             = 0x00000010
77	FILE_ATTRIBUTE_ARCHIVE               = 0x00000020
78	FILE_ATTRIBUTE_DEVICE                = 0x00000040
79	FILE_ATTRIBUTE_NORMAL                = 0x00000080
80	FILE_ATTRIBUTE_TEMPORARY             = 0x00000100
81	FILE_ATTRIBUTE_SPARSE_FILE           = 0x00000200
82	FILE_ATTRIBUTE_REPARSE_POINT         = 0x00000400
83	FILE_ATTRIBUTE_COMPRESSED            = 0x00000800
84	FILE_ATTRIBUTE_OFFLINE               = 0x00001000
85	FILE_ATTRIBUTE_NOT_CONTENT_INDEXED   = 0x00002000
86	FILE_ATTRIBUTE_ENCRYPTED             = 0x00004000
87	FILE_ATTRIBUTE_INTEGRITY_STREAM      = 0x00008000
88	FILE_ATTRIBUTE_VIRTUAL               = 0x00010000
89	FILE_ATTRIBUTE_NO_SCRUB_DATA         = 0x00020000
90	FILE_ATTRIBUTE_RECALL_ON_OPEN        = 0x00040000
91	FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x00400000
92
93	INVALID_FILE_ATTRIBUTES = 0xffffffff
94
95	CREATE_NEW        = 1
96	CREATE_ALWAYS     = 2
97	OPEN_EXISTING     = 3
98	OPEN_ALWAYS       = 4
99	TRUNCATE_EXISTING = 5
100
101	FILE_FLAG_OPEN_REQUIRING_OPLOCK = 0x00040000
102	FILE_FLAG_FIRST_PIPE_INSTANCE   = 0x00080000
103	FILE_FLAG_OPEN_NO_RECALL        = 0x00100000
104	FILE_FLAG_OPEN_REPARSE_POINT    = 0x00200000
105	FILE_FLAG_SESSION_AWARE         = 0x00800000
106	FILE_FLAG_POSIX_SEMANTICS       = 0x01000000
107	FILE_FLAG_BACKUP_SEMANTICS      = 0x02000000
108	FILE_FLAG_DELETE_ON_CLOSE       = 0x04000000
109	FILE_FLAG_SEQUENTIAL_SCAN       = 0x08000000
110	FILE_FLAG_RANDOM_ACCESS         = 0x10000000
111	FILE_FLAG_NO_BUFFERING          = 0x20000000
112	FILE_FLAG_OVERLAPPED            = 0x40000000
113	FILE_FLAG_WRITE_THROUGH         = 0x80000000
114
115	HANDLE_FLAG_INHERIT    = 0x00000001
116	STARTF_USESTDHANDLES   = 0x00000100
117	STARTF_USESHOWWINDOW   = 0x00000001
118	DUPLICATE_CLOSE_SOURCE = 0x00000001
119	DUPLICATE_SAME_ACCESS  = 0x00000002
120
121	STD_INPUT_HANDLE  = -10 & (1<<32 - 1)
122	STD_OUTPUT_HANDLE = -11 & (1<<32 - 1)
123	STD_ERROR_HANDLE  = -12 & (1<<32 - 1)
124
125	FILE_BEGIN   = 0
126	FILE_CURRENT = 1
127	FILE_END     = 2
128
129	LANG_ENGLISH       = 0x09
130	SUBLANG_ENGLISH_US = 0x01
131
132	FORMAT_MESSAGE_ALLOCATE_BUFFER = 256
133	FORMAT_MESSAGE_IGNORE_INSERTS  = 512
134	FORMAT_MESSAGE_FROM_STRING     = 1024
135	FORMAT_MESSAGE_FROM_HMODULE    = 2048
136	FORMAT_MESSAGE_FROM_SYSTEM     = 4096
137	FORMAT_MESSAGE_ARGUMENT_ARRAY  = 8192
138	FORMAT_MESSAGE_MAX_WIDTH_MASK  = 255
139
140	MAX_PATH      = 260
141	MAX_LONG_PATH = 32768
142
143	MAX_COMPUTERNAME_LENGTH = 15
144
145	TIME_ZONE_ID_UNKNOWN  = 0
146	TIME_ZONE_ID_STANDARD = 1
147
148	TIME_ZONE_ID_DAYLIGHT = 2
149	IGNORE                = 0
150	INFINITE              = 0xffffffff
151
152	WAIT_ABANDONED = 0x00000080
153	WAIT_OBJECT_0  = 0x00000000
154	WAIT_FAILED    = 0xFFFFFFFF
155
156	// Access rights for process.
157	PROCESS_CREATE_PROCESS            = 0x0080
158	PROCESS_CREATE_THREAD             = 0x0002
159	PROCESS_DUP_HANDLE                = 0x0040
160	PROCESS_QUERY_INFORMATION         = 0x0400
161	PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
162	PROCESS_SET_INFORMATION           = 0x0200
163	PROCESS_SET_QUOTA                 = 0x0100
164	PROCESS_SUSPEND_RESUME            = 0x0800
165	PROCESS_TERMINATE                 = 0x0001
166	PROCESS_VM_OPERATION              = 0x0008
167	PROCESS_VM_READ                   = 0x0010
168	PROCESS_VM_WRITE                  = 0x0020
169
170	// Access rights for thread.
171	THREAD_DIRECT_IMPERSONATION      = 0x0200
172	THREAD_GET_CONTEXT               = 0x0008
173	THREAD_IMPERSONATE               = 0x0100
174	THREAD_QUERY_INFORMATION         = 0x0040
175	THREAD_QUERY_LIMITED_INFORMATION = 0x0800
176	THREAD_SET_CONTEXT               = 0x0010
177	THREAD_SET_INFORMATION           = 0x0020
178	THREAD_SET_LIMITED_INFORMATION   = 0x0400
179	THREAD_SET_THREAD_TOKEN          = 0x0080
180	THREAD_SUSPEND_RESUME            = 0x0002
181	THREAD_TERMINATE                 = 0x0001
182
183	FILE_MAP_COPY    = 0x01
184	FILE_MAP_WRITE   = 0x02
185	FILE_MAP_READ    = 0x04
186	FILE_MAP_EXECUTE = 0x20
187
188	CTRL_C_EVENT        = 0
189	CTRL_BREAK_EVENT    = 1
190	CTRL_CLOSE_EVENT    = 2
191	CTRL_LOGOFF_EVENT   = 5
192	CTRL_SHUTDOWN_EVENT = 6
193
194	// Windows reserves errors >= 1<<29 for application use.
195	APPLICATION_ERROR = 1 << 29
196)
197
198const (
199	// Process creation flags.
200	CREATE_BREAKAWAY_FROM_JOB        = 0x01000000
201	CREATE_DEFAULT_ERROR_MODE        = 0x04000000
202	CREATE_NEW_CONSOLE               = 0x00000010
203	CREATE_NEW_PROCESS_GROUP         = 0x00000200
204	CREATE_NO_WINDOW                 = 0x08000000
205	CREATE_PROTECTED_PROCESS         = 0x00040000
206	CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000
207	CREATE_SEPARATE_WOW_VDM          = 0x00000800
208	CREATE_SHARED_WOW_VDM            = 0x00001000
209	CREATE_SUSPENDED                 = 0x00000004
210	CREATE_UNICODE_ENVIRONMENT       = 0x00000400
211	DEBUG_ONLY_THIS_PROCESS          = 0x00000002
212	DEBUG_PROCESS                    = 0x00000001
213	DETACHED_PROCESS                 = 0x00000008
214	EXTENDED_STARTUPINFO_PRESENT     = 0x00080000
215	INHERIT_PARENT_AFFINITY          = 0x00010000
216)
217
218const (
219	// flags for CreateToolhelp32Snapshot
220	TH32CS_SNAPHEAPLIST = 0x01
221	TH32CS_SNAPPROCESS  = 0x02
222	TH32CS_SNAPTHREAD   = 0x04
223	TH32CS_SNAPMODULE   = 0x08
224	TH32CS_SNAPMODULE32 = 0x10
225	TH32CS_SNAPALL      = TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD
226	TH32CS_INHERIT      = 0x80000000
227)
228
229const (
230	// filters for ReadDirectoryChangesW and FindFirstChangeNotificationW
231	FILE_NOTIFY_CHANGE_FILE_NAME   = 0x001
232	FILE_NOTIFY_CHANGE_DIR_NAME    = 0x002
233	FILE_NOTIFY_CHANGE_ATTRIBUTES  = 0x004
234	FILE_NOTIFY_CHANGE_SIZE        = 0x008
235	FILE_NOTIFY_CHANGE_LAST_WRITE  = 0x010
236	FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x020
237	FILE_NOTIFY_CHANGE_CREATION    = 0x040
238	FILE_NOTIFY_CHANGE_SECURITY    = 0x100
239)
240
241const (
242	// do not reorder
243	FILE_ACTION_ADDED = iota + 1
244	FILE_ACTION_REMOVED
245	FILE_ACTION_MODIFIED
246	FILE_ACTION_RENAMED_OLD_NAME
247	FILE_ACTION_RENAMED_NEW_NAME
248)
249
250const (
251	// wincrypt.h
252	/* certenrolld_begin -- PROV_RSA_*/
253	PROV_RSA_FULL      = 1
254	PROV_RSA_SIG       = 2
255	PROV_DSS           = 3
256	PROV_FORTEZZA      = 4
257	PROV_MS_EXCHANGE   = 5
258	PROV_SSL           = 6
259	PROV_RSA_SCHANNEL  = 12
260	PROV_DSS_DH        = 13
261	PROV_EC_ECDSA_SIG  = 14
262	PROV_EC_ECNRA_SIG  = 15
263	PROV_EC_ECDSA_FULL = 16
264	PROV_EC_ECNRA_FULL = 17
265	PROV_DH_SCHANNEL   = 18
266	PROV_SPYRUS_LYNKS  = 20
267	PROV_RNG           = 21
268	PROV_INTEL_SEC     = 22
269	PROV_REPLACE_OWF   = 23
270	PROV_RSA_AES       = 24
271
272	/* dwFlags definitions for CryptAcquireContext */
273	CRYPT_VERIFYCONTEXT              = 0xF0000000
274	CRYPT_NEWKEYSET                  = 0x00000008
275	CRYPT_DELETEKEYSET               = 0x00000010
276	CRYPT_MACHINE_KEYSET             = 0x00000020
277	CRYPT_SILENT                     = 0x00000040
278	CRYPT_DEFAULT_CONTAINER_OPTIONAL = 0x00000080
279
280	/* Flags for PFXImportCertStore */
281	CRYPT_EXPORTABLE                   = 0x00000001
282	CRYPT_USER_PROTECTED               = 0x00000002
283	CRYPT_USER_KEYSET                  = 0x00001000
284	PKCS12_PREFER_CNG_KSP              = 0x00000100
285	PKCS12_ALWAYS_CNG_KSP              = 0x00000200
286	PKCS12_ALLOW_OVERWRITE_KEY         = 0x00004000
287	PKCS12_NO_PERSIST_KEY              = 0x00008000
288	PKCS12_INCLUDE_EXTENDED_PROPERTIES = 0x00000010
289
290	/* Flags for CryptAcquireCertificatePrivateKey */
291	CRYPT_ACQUIRE_CACHE_FLAG             = 0x00000001
292	CRYPT_ACQUIRE_USE_PROV_INFO_FLAG     = 0x00000002
293	CRYPT_ACQUIRE_COMPARE_KEY_FLAG       = 0x00000004
294	CRYPT_ACQUIRE_NO_HEALING             = 0x00000008
295	CRYPT_ACQUIRE_SILENT_FLAG            = 0x00000040
296	CRYPT_ACQUIRE_WINDOW_HANDLE_FLAG     = 0x00000080
297	CRYPT_ACQUIRE_NCRYPT_KEY_FLAGS_MASK  = 0x00070000
298	CRYPT_ACQUIRE_ALLOW_NCRYPT_KEY_FLAG  = 0x00010000
299	CRYPT_ACQUIRE_PREFER_NCRYPT_KEY_FLAG = 0x00020000
300	CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG   = 0x00040000
301
302	/* pdwKeySpec for CryptAcquireCertificatePrivateKey */
303	AT_KEYEXCHANGE       = 1
304	AT_SIGNATURE         = 2
305	CERT_NCRYPT_KEY_SPEC = 0xFFFFFFFF
306
307	/* Default usage match type is AND with value zero */
308	USAGE_MATCH_TYPE_AND = 0
309	USAGE_MATCH_TYPE_OR  = 1
310
311	/* msgAndCertEncodingType values for CertOpenStore function */
312	X509_ASN_ENCODING   = 0x00000001
313	PKCS_7_ASN_ENCODING = 0x00010000
314
315	/* storeProvider values for CertOpenStore function */
316	CERT_STORE_PROV_MSG               = 1
317	CERT_STORE_PROV_MEMORY            = 2
318	CERT_STORE_PROV_FILE              = 3
319	CERT_STORE_PROV_REG               = 4
320	CERT_STORE_PROV_PKCS7             = 5
321	CERT_STORE_PROV_SERIALIZED        = 6
322	CERT_STORE_PROV_FILENAME_A        = 7
323	CERT_STORE_PROV_FILENAME_W        = 8
324	CERT_STORE_PROV_FILENAME          = CERT_STORE_PROV_FILENAME_W
325	CERT_STORE_PROV_SYSTEM_A          = 9
326	CERT_STORE_PROV_SYSTEM_W          = 10
327	CERT_STORE_PROV_SYSTEM            = CERT_STORE_PROV_SYSTEM_W
328	CERT_STORE_PROV_COLLECTION        = 11
329	CERT_STORE_PROV_SYSTEM_REGISTRY_A = 12
330	CERT_STORE_PROV_SYSTEM_REGISTRY_W = 13
331	CERT_STORE_PROV_SYSTEM_REGISTRY   = CERT_STORE_PROV_SYSTEM_REGISTRY_W
332	CERT_STORE_PROV_PHYSICAL_W        = 14
333	CERT_STORE_PROV_PHYSICAL          = CERT_STORE_PROV_PHYSICAL_W
334	CERT_STORE_PROV_SMART_CARD_W      = 15
335	CERT_STORE_PROV_SMART_CARD        = CERT_STORE_PROV_SMART_CARD_W
336	CERT_STORE_PROV_LDAP_W            = 16
337	CERT_STORE_PROV_LDAP              = CERT_STORE_PROV_LDAP_W
338	CERT_STORE_PROV_PKCS12            = 17
339
340	/* store characteristics (low WORD of flag) for CertOpenStore function */
341	CERT_STORE_NO_CRYPT_RELEASE_FLAG            = 0x00000001
342	CERT_STORE_SET_LOCALIZED_NAME_FLAG          = 0x00000002
343	CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = 0x00000004
344	CERT_STORE_DELETE_FLAG                      = 0x00000010
345	CERT_STORE_UNSAFE_PHYSICAL_FLAG             = 0x00000020
346	CERT_STORE_SHARE_STORE_FLAG                 = 0x00000040
347	CERT_STORE_SHARE_CONTEXT_FLAG               = 0x00000080
348	CERT_STORE_MANIFOLD_FLAG                    = 0x00000100
349	CERT_STORE_ENUM_ARCHIVED_FLAG               = 0x00000200
350	CERT_STORE_UPDATE_KEYID_FLAG                = 0x00000400
351	CERT_STORE_BACKUP_RESTORE_FLAG              = 0x00000800
352	CERT_STORE_MAXIMUM_ALLOWED_FLAG             = 0x00001000
353	CERT_STORE_CREATE_NEW_FLAG                  = 0x00002000
354	CERT_STORE_OPEN_EXISTING_FLAG               = 0x00004000
355	CERT_STORE_READONLY_FLAG                    = 0x00008000
356
357	/* store locations (high WORD of flag) for CertOpenStore function */
358	CERT_SYSTEM_STORE_CURRENT_USER               = 0x00010000
359	CERT_SYSTEM_STORE_LOCAL_MACHINE              = 0x00020000
360	CERT_SYSTEM_STORE_CURRENT_SERVICE            = 0x00040000
361	CERT_SYSTEM_STORE_SERVICES                   = 0x00050000
362	CERT_SYSTEM_STORE_USERS                      = 0x00060000
363	CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY  = 0x00070000
364	CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY = 0x00080000
365	CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE   = 0x00090000
366	CERT_SYSTEM_STORE_UNPROTECTED_FLAG           = 0x40000000
367	CERT_SYSTEM_STORE_RELOCATE_FLAG              = 0x80000000
368
369	/* Miscellaneous high-WORD flags for CertOpenStore function */
370	CERT_REGISTRY_STORE_REMOTE_FLAG      = 0x00010000
371	CERT_REGISTRY_STORE_SERIALIZED_FLAG  = 0x00020000
372	CERT_REGISTRY_STORE_ROAMING_FLAG     = 0x00040000
373	CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG = 0x00080000
374	CERT_REGISTRY_STORE_LM_GPT_FLAG      = 0x01000000
375	CERT_REGISTRY_STORE_CLIENT_GPT_FLAG  = 0x80000000
376	CERT_FILE_STORE_COMMIT_ENABLE_FLAG   = 0x00010000
377	CERT_LDAP_STORE_SIGN_FLAG            = 0x00010000
378	CERT_LDAP_STORE_AREC_EXCLUSIVE_FLAG  = 0x00020000
379	CERT_LDAP_STORE_OPENED_FLAG          = 0x00040000
380	CERT_LDAP_STORE_UNBIND_FLAG          = 0x00080000
381
382	/* addDisposition values for CertAddCertificateContextToStore function */
383	CERT_STORE_ADD_NEW                                 = 1
384	CERT_STORE_ADD_USE_EXISTING                        = 2
385	CERT_STORE_ADD_REPLACE_EXISTING                    = 3
386	CERT_STORE_ADD_ALWAYS                              = 4
387	CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES = 5
388	CERT_STORE_ADD_NEWER                               = 6
389	CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES            = 7
390
391	/* ErrorStatus values for CertTrustStatus struct */
392	CERT_TRUST_NO_ERROR                          = 0x00000000
393	CERT_TRUST_IS_NOT_TIME_VALID                 = 0x00000001
394	CERT_TRUST_IS_REVOKED                        = 0x00000004
395	CERT_TRUST_IS_NOT_SIGNATURE_VALID            = 0x00000008
396	CERT_TRUST_IS_NOT_VALID_FOR_USAGE            = 0x00000010
397	CERT_TRUST_IS_UNTRUSTED_ROOT                 = 0x00000020
398	CERT_TRUST_REVOCATION_STATUS_UNKNOWN         = 0x00000040
399	CERT_TRUST_IS_CYCLIC                         = 0x00000080
400	CERT_TRUST_INVALID_EXTENSION                 = 0x00000100
401	CERT_TRUST_INVALID_POLICY_CONSTRAINTS        = 0x00000200
402	CERT_TRUST_INVALID_BASIC_CONSTRAINTS         = 0x00000400
403	CERT_TRUST_INVALID_NAME_CONSTRAINTS          = 0x00000800
404	CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT = 0x00001000
405	CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT   = 0x00002000
406	CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT = 0x00004000
407	CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT      = 0x00008000
408	CERT_TRUST_IS_PARTIAL_CHAIN                  = 0x00010000
409	CERT_TRUST_CTL_IS_NOT_TIME_VALID             = 0x00020000
410	CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID        = 0x00040000
411	CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE        = 0x00080000
412	CERT_TRUST_HAS_WEAK_SIGNATURE                = 0x00100000
413	CERT_TRUST_IS_OFFLINE_REVOCATION             = 0x01000000
414	CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY          = 0x02000000
415	CERT_TRUST_IS_EXPLICIT_DISTRUST              = 0x04000000
416	CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT    = 0x08000000
417
418	/* InfoStatus values for CertTrustStatus struct */
419	CERT_TRUST_HAS_EXACT_MATCH_ISSUER        = 0x00000001
420	CERT_TRUST_HAS_KEY_MATCH_ISSUER          = 0x00000002
421	CERT_TRUST_HAS_NAME_MATCH_ISSUER         = 0x00000004
422	CERT_TRUST_IS_SELF_SIGNED                = 0x00000008
423	CERT_TRUST_HAS_PREFERRED_ISSUER          = 0x00000100
424	CERT_TRUST_HAS_ISSUANCE_CHAIN_POLICY     = 0x00000400
425	CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS    = 0x00000400
426	CERT_TRUST_IS_PEER_TRUSTED               = 0x00000800
427	CERT_TRUST_HAS_CRL_VALIDITY_EXTENDED     = 0x00001000
428	CERT_TRUST_IS_FROM_EXCLUSIVE_TRUST_STORE = 0x00002000
429	CERT_TRUST_IS_CA_TRUSTED                 = 0x00004000
430	CERT_TRUST_IS_COMPLEX_CHAIN              = 0x00010000
431
432	/* Certificate Information Flags */
433	CERT_INFO_VERSION_FLAG                 = 1
434	CERT_INFO_SERIAL_NUMBER_FLAG           = 2
435	CERT_INFO_SIGNATURE_ALGORITHM_FLAG     = 3
436	CERT_INFO_ISSUER_FLAG                  = 4
437	CERT_INFO_NOT_BEFORE_FLAG              = 5
438	CERT_INFO_NOT_AFTER_FLAG               = 6
439	CERT_INFO_SUBJECT_FLAG                 = 7
440	CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG = 8
441	CERT_INFO_ISSUER_UNIQUE_ID_FLAG        = 9
442	CERT_INFO_SUBJECT_UNIQUE_ID_FLAG       = 10
443	CERT_INFO_EXTENSION_FLAG               = 11
444
445	/* dwFindType for CertFindCertificateInStore  */
446	CERT_COMPARE_MASK                     = 0xFFFF
447	CERT_COMPARE_SHIFT                    = 16
448	CERT_COMPARE_ANY                      = 0
449	CERT_COMPARE_SHA1_HASH                = 1
450	CERT_COMPARE_NAME                     = 2
451	CERT_COMPARE_ATTR                     = 3
452	CERT_COMPARE_MD5_HASH                 = 4
453	CERT_COMPARE_PROPERTY                 = 5
454	CERT_COMPARE_PUBLIC_KEY               = 6
455	CERT_COMPARE_HASH                     = CERT_COMPARE_SHA1_HASH
456	CERT_COMPARE_NAME_STR_A               = 7
457	CERT_COMPARE_NAME_STR_W               = 8
458	CERT_COMPARE_KEY_SPEC                 = 9
459	CERT_COMPARE_ENHKEY_USAGE             = 10
460	CERT_COMPARE_CTL_USAGE                = CERT_COMPARE_ENHKEY_USAGE
461	CERT_COMPARE_SUBJECT_CERT             = 11
462	CERT_COMPARE_ISSUER_OF                = 12
463	CERT_COMPARE_EXISTING                 = 13
464	CERT_COMPARE_SIGNATURE_HASH           = 14
465	CERT_COMPARE_KEY_IDENTIFIER           = 15
466	CERT_COMPARE_CERT_ID                  = 16
467	CERT_COMPARE_CROSS_CERT_DIST_POINTS   = 17
468	CERT_COMPARE_PUBKEY_MD5_HASH          = 18
469	CERT_COMPARE_SUBJECT_INFO_ACCESS      = 19
470	CERT_COMPARE_HASH_STR                 = 20
471	CERT_COMPARE_HAS_PRIVATE_KEY          = 21
472	CERT_FIND_ANY                         = (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
473	CERT_FIND_SHA1_HASH                   = (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
474	CERT_FIND_MD5_HASH                    = (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
475	CERT_FIND_SIGNATURE_HASH              = (CERT_COMPARE_SIGNATURE_HASH << CERT_COMPARE_SHIFT)
476	CERT_FIND_KEY_IDENTIFIER              = (CERT_COMPARE_KEY_IDENTIFIER << CERT_COMPARE_SHIFT)
477	CERT_FIND_HASH                        = CERT_FIND_SHA1_HASH
478	CERT_FIND_PROPERTY                    = (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
479	CERT_FIND_PUBLIC_KEY                  = (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
480	CERT_FIND_SUBJECT_NAME                = (CERT_COMPARE_NAME<<CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
481	CERT_FIND_SUBJECT_ATTR                = (CERT_COMPARE_ATTR<<CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
482	CERT_FIND_ISSUER_NAME                 = (CERT_COMPARE_NAME<<CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
483	CERT_FIND_ISSUER_ATTR                 = (CERT_COMPARE_ATTR<<CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
484	CERT_FIND_SUBJECT_STR_A               = (CERT_COMPARE_NAME_STR_A<<CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
485	CERT_FIND_SUBJECT_STR_W               = (CERT_COMPARE_NAME_STR_W<<CERT_COMPARE_SHIFT | CERT_INFO_SUBJECT_FLAG)
486	CERT_FIND_SUBJECT_STR                 = CERT_FIND_SUBJECT_STR_W
487	CERT_FIND_ISSUER_STR_A                = (CERT_COMPARE_NAME_STR_A<<CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
488	CERT_FIND_ISSUER_STR_W                = (CERT_COMPARE_NAME_STR_W<<CERT_COMPARE_SHIFT | CERT_INFO_ISSUER_FLAG)
489	CERT_FIND_ISSUER_STR                  = CERT_FIND_ISSUER_STR_W
490	CERT_FIND_KEY_SPEC                    = (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
491	CERT_FIND_ENHKEY_USAGE                = (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
492	CERT_FIND_CTL_USAGE                   = CERT_FIND_ENHKEY_USAGE
493	CERT_FIND_SUBJECT_CERT                = (CERT_COMPARE_SUBJECT_CERT << CERT_COMPARE_SHIFT)
494	CERT_FIND_ISSUER_OF                   = (CERT_COMPARE_ISSUER_OF << CERT_COMPARE_SHIFT)
495	CERT_FIND_EXISTING                    = (CERT_COMPARE_EXISTING << CERT_COMPARE_SHIFT)
496	CERT_FIND_CERT_ID                     = (CERT_COMPARE_CERT_ID << CERT_COMPARE_SHIFT)
497	CERT_FIND_CROSS_CERT_DIST_POINTS      = (CERT_COMPARE_CROSS_CERT_DIST_POINTS << CERT_COMPARE_SHIFT)
498	CERT_FIND_PUBKEY_MD5_HASH             = (CERT_COMPARE_PUBKEY_MD5_HASH << CERT_COMPARE_SHIFT)
499	CERT_FIND_SUBJECT_INFO_ACCESS         = (CERT_COMPARE_SUBJECT_INFO_ACCESS << CERT_COMPARE_SHIFT)
500	CERT_FIND_HASH_STR                    = (CERT_COMPARE_HASH_STR << CERT_COMPARE_SHIFT)
501	CERT_FIND_HAS_PRIVATE_KEY             = (CERT_COMPARE_HAS_PRIVATE_KEY << CERT_COMPARE_SHIFT)
502	CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG  = 0x1
503	CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG  = 0x2
504	CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG = 0x4
505	CERT_FIND_NO_ENHKEY_USAGE_FLAG        = 0x8
506	CERT_FIND_OR_ENHKEY_USAGE_FLAG        = 0x10
507	CERT_FIND_VALID_ENHKEY_USAGE_FLAG     = 0x20
508	CERT_FIND_OPTIONAL_CTL_USAGE_FLAG     = CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
509	CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG     = CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
510	CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG    = CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
511	CERT_FIND_NO_CTL_USAGE_FLAG           = CERT_FIND_NO_ENHKEY_USAGE_FLAG
512	CERT_FIND_OR_CTL_USAGE_FLAG           = CERT_FIND_OR_ENHKEY_USAGE_FLAG
513	CERT_FIND_VALID_CTL_USAGE_FLAG        = CERT_FIND_VALID_ENHKEY_USAGE_FLAG
514
515	/* policyOID values for CertVerifyCertificateChainPolicy function */
516	CERT_CHAIN_POLICY_BASE              = 1
517	CERT_CHAIN_POLICY_AUTHENTICODE      = 2
518	CERT_CHAIN_POLICY_AUTHENTICODE_TS   = 3
519	CERT_CHAIN_POLICY_SSL               = 4
520	CERT_CHAIN_POLICY_BASIC_CONSTRAINTS = 5
521	CERT_CHAIN_POLICY_NT_AUTH           = 6
522	CERT_CHAIN_POLICY_MICROSOFT_ROOT    = 7
523	CERT_CHAIN_POLICY_EV                = 8
524	CERT_CHAIN_POLICY_SSL_F12           = 9
525
526	/* flag for dwFindType CertFindChainInStore  */
527	CERT_CHAIN_FIND_BY_ISSUER = 1
528
529	/* dwFindFlags for CertFindChainInStore when dwFindType == CERT_CHAIN_FIND_BY_ISSUER */
530	CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG    = 0x0001
531	CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG  = 0x0002
532	CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG = 0x0004
533	CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG  = 0x0008
534	CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG         = 0x4000
535	CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG     = 0x8000
536
537	/* Certificate Store close flags */
538	CERT_CLOSE_STORE_FORCE_FLAG = 0x00000001
539	CERT_CLOSE_STORE_CHECK_FLAG = 0x00000002
540
541	/* CryptQueryObject object type */
542	CERT_QUERY_OBJECT_FILE = 1
543	CERT_QUERY_OBJECT_BLOB = 2
544
545	/* CryptQueryObject content type flags */
546	CERT_QUERY_CONTENT_CERT                    = 1
547	CERT_QUERY_CONTENT_CTL                     = 2
548	CERT_QUERY_CONTENT_CRL                     = 3
549	CERT_QUERY_CONTENT_SERIALIZED_STORE        = 4
550	CERT_QUERY_CONTENT_SERIALIZED_CERT         = 5
551	CERT_QUERY_CONTENT_SERIALIZED_CTL          = 6
552	CERT_QUERY_CONTENT_SERIALIZED_CRL          = 7
553	CERT_QUERY_CONTENT_PKCS7_SIGNED            = 8
554	CERT_QUERY_CONTENT_PKCS7_UNSIGNED          = 9
555	CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED      = 10
556	CERT_QUERY_CONTENT_PKCS10                  = 11
557	CERT_QUERY_CONTENT_PFX                     = 12
558	CERT_QUERY_CONTENT_CERT_PAIR               = 13
559	CERT_QUERY_CONTENT_PFX_AND_LOAD            = 14
560	CERT_QUERY_CONTENT_FLAG_CERT               = (1 << CERT_QUERY_CONTENT_CERT)
561	CERT_QUERY_CONTENT_FLAG_CTL                = (1 << CERT_QUERY_CONTENT_CTL)
562	CERT_QUERY_CONTENT_FLAG_CRL                = (1 << CERT_QUERY_CONTENT_CRL)
563	CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE   = (1 << CERT_QUERY_CONTENT_SERIALIZED_STORE)
564	CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT    = (1 << CERT_QUERY_CONTENT_SERIALIZED_CERT)
565	CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL     = (1 << CERT_QUERY_CONTENT_SERIALIZED_CTL)
566	CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL     = (1 << CERT_QUERY_CONTENT_SERIALIZED_CRL)
567	CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED       = (1 << CERT_QUERY_CONTENT_PKCS7_SIGNED)
568	CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED     = (1 << CERT_QUERY_CONTENT_PKCS7_UNSIGNED)
569	CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED = (1 << CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED)
570	CERT_QUERY_CONTENT_FLAG_PKCS10             = (1 << CERT_QUERY_CONTENT_PKCS10)
571	CERT_QUERY_CONTENT_FLAG_PFX                = (1 << CERT_QUERY_CONTENT_PFX)
572	CERT_QUERY_CONTENT_FLAG_CERT_PAIR          = (1 << CERT_QUERY_CONTENT_CERT_PAIR)
573	CERT_QUERY_CONTENT_FLAG_PFX_AND_LOAD       = (1 << CERT_QUERY_CONTENT_PFX_AND_LOAD)
574	CERT_QUERY_CONTENT_FLAG_ALL                = (CERT_QUERY_CONTENT_FLAG_CERT | CERT_QUERY_CONTENT_FLAG_CTL | CERT_QUERY_CONTENT_FLAG_CRL | CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE | CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT | CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL | CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL | CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED | CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED | CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED | CERT_QUERY_CONTENT_FLAG_PKCS10 | CERT_QUERY_CONTENT_FLAG_PFX | CERT_QUERY_CONTENT_FLAG_CERT_PAIR)
575	CERT_QUERY_CONTENT_FLAG_ALL_ISSUER_CERT    = (CERT_QUERY_CONTENT_FLAG_CERT | CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE | CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT | CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED | CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED)
576
577	/* CryptQueryObject format type flags */
578	CERT_QUERY_FORMAT_BINARY                     = 1
579	CERT_QUERY_FORMAT_BASE64_ENCODED             = 2
580	CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED      = 3
581	CERT_QUERY_FORMAT_FLAG_BINARY                = (1 << CERT_QUERY_FORMAT_BINARY)
582	CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED        = (1 << CERT_QUERY_FORMAT_BASE64_ENCODED)
583	CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED = (1 << CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED)
584	CERT_QUERY_FORMAT_FLAG_ALL                   = (CERT_QUERY_FORMAT_FLAG_BINARY | CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED | CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED)
585
586	/* CertGetNameString name types */
587	CERT_NAME_EMAIL_TYPE            = 1
588	CERT_NAME_RDN_TYPE              = 2
589	CERT_NAME_ATTR_TYPE             = 3
590	CERT_NAME_SIMPLE_DISPLAY_TYPE   = 4
591	CERT_NAME_FRIENDLY_DISPLAY_TYPE = 5
592	CERT_NAME_DNS_TYPE              = 6
593	CERT_NAME_URL_TYPE              = 7
594	CERT_NAME_UPN_TYPE              = 8
595
596	/* CertGetNameString flags */
597	CERT_NAME_ISSUER_FLAG              = 0x1
598	CERT_NAME_DISABLE_IE4_UTF8_FLAG    = 0x10000
599	CERT_NAME_SEARCH_ALL_NAMES_FLAG    = 0x2
600	CERT_NAME_STR_ENABLE_PUNYCODE_FLAG = 0x00200000
601
602	/* AuthType values for SSLExtraCertChainPolicyPara struct */
603	AUTHTYPE_CLIENT = 1
604	AUTHTYPE_SERVER = 2
605
606	/* Checks values for SSLExtraCertChainPolicyPara struct */
607	SECURITY_FLAG_IGNORE_REVOCATION        = 0x00000080
608	SECURITY_FLAG_IGNORE_UNKNOWN_CA        = 0x00000100
609	SECURITY_FLAG_IGNORE_WRONG_USAGE       = 0x00000200
610	SECURITY_FLAG_IGNORE_CERT_CN_INVALID   = 0x00001000
611	SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000
612
613	/* Flags for Crypt[Un]ProtectData */
614	CRYPTPROTECT_UI_FORBIDDEN      = 0x1
615	CRYPTPROTECT_LOCAL_MACHINE     = 0x4
616	CRYPTPROTECT_CRED_SYNC         = 0x8
617	CRYPTPROTECT_AUDIT             = 0x10
618	CRYPTPROTECT_NO_RECOVERY       = 0x20
619	CRYPTPROTECT_VERIFY_PROTECTION = 0x40
620	CRYPTPROTECT_CRED_REGENERATE   = 0x80
621
622	/* Flags for CryptProtectPromptStruct */
623	CRYPTPROTECT_PROMPT_ON_UNPROTECT   = 1
624	CRYPTPROTECT_PROMPT_ON_PROTECT     = 2
625	CRYPTPROTECT_PROMPT_RESERVED       = 4
626	CRYPTPROTECT_PROMPT_STRONG         = 8
627	CRYPTPROTECT_PROMPT_REQUIRE_STRONG = 16
628)
629
630const (
631	// flags for SetErrorMode
632	SEM_FAILCRITICALERRORS     = 0x0001
633	SEM_NOALIGNMENTFAULTEXCEPT = 0x0004
634	SEM_NOGPFAULTERRORBOX      = 0x0002
635	SEM_NOOPENFILEERRORBOX     = 0x8000
636)
637
638const (
639	// Priority class.
640	ABOVE_NORMAL_PRIORITY_CLASS   = 0x00008000
641	BELOW_NORMAL_PRIORITY_CLASS   = 0x00004000
642	HIGH_PRIORITY_CLASS           = 0x00000080
643	IDLE_PRIORITY_CLASS           = 0x00000040
644	NORMAL_PRIORITY_CLASS         = 0x00000020
645	PROCESS_MODE_BACKGROUND_BEGIN = 0x00100000
646	PROCESS_MODE_BACKGROUND_END   = 0x00200000
647	REALTIME_PRIORITY_CLASS       = 0x00000100
648)
649
650/* wintrust.h constants for WinVerifyTrustEx */
651const (
652	WTD_UI_ALL    = 1
653	WTD_UI_NONE   = 2
654	WTD_UI_NOBAD  = 3
655	WTD_UI_NOGOOD = 4
656
657	WTD_REVOKE_NONE       = 0
658	WTD_REVOKE_WHOLECHAIN = 1
659
660	WTD_CHOICE_FILE    = 1
661	WTD_CHOICE_CATALOG = 2
662	WTD_CHOICE_BLOB    = 3
663	WTD_CHOICE_SIGNER  = 4
664	WTD_CHOICE_CERT    = 5
665
666	WTD_STATEACTION_IGNORE           = 0x00000000
667	WTD_STATEACTION_VERIFY           = 0x00000010
668	WTD_STATEACTION_CLOSE            = 0x00000002
669	WTD_STATEACTION_AUTO_CACHE       = 0x00000003
670	WTD_STATEACTION_AUTO_CACHE_FLUSH = 0x00000004
671
672	WTD_USE_IE4_TRUST_FLAG                  = 0x1
673	WTD_NO_IE4_CHAIN_FLAG                   = 0x2
674	WTD_NO_POLICY_USAGE_FLAG                = 0x4
675	WTD_REVOCATION_CHECK_NONE               = 0x10
676	WTD_REVOCATION_CHECK_END_CERT           = 0x20
677	WTD_REVOCATION_CHECK_CHAIN              = 0x40
678	WTD_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT = 0x80
679	WTD_SAFER_FLAG                          = 0x100
680	WTD_HASH_ONLY_FLAG                      = 0x200
681	WTD_USE_DEFAULT_OSVER_CHECK             = 0x400
682	WTD_LIFETIME_SIGNING_FLAG               = 0x800
683	WTD_CACHE_ONLY_URL_RETRIEVAL            = 0x1000
684	WTD_DISABLE_MD2_MD4                     = 0x2000
685	WTD_MOTW                                = 0x4000
686
687	WTD_UICONTEXT_EXECUTE = 0
688	WTD_UICONTEXT_INSTALL = 1
689)
690
691var (
692	OID_PKIX_KP_SERVER_AUTH = []byte("1.3.6.1.5.5.7.3.1\x00")
693	OID_SERVER_GATED_CRYPTO = []byte("1.3.6.1.4.1.311.10.3.3\x00")
694	OID_SGC_NETSCAPE        = []byte("2.16.840.1.113730.4.1\x00")
695
696	WINTRUST_ACTION_GENERIC_VERIFY_V2 = GUID{
697		Data1: 0xaac56b,
698		Data2: 0xcd44,
699		Data3: 0x11d0,
700		Data4: [8]byte{0x8c, 0xc2, 0x0, 0xc0, 0x4f, 0xc2, 0x95, 0xee},
701	}
702)
703
704// Pointer represents a pointer to an arbitrary Windows type.
705//
706// Pointer-typed fields may point to one of many different types. It's
707// up to the caller to provide a pointer to the appropriate type, cast
708// to Pointer. The caller must obey the unsafe.Pointer rules while
709// doing so.
710type Pointer *struct{}
711
712// Invented values to support what package os expects.
713type Timeval struct {
714	Sec  int32
715	Usec int32
716}
717
718func (tv *Timeval) Nanoseconds() int64 {
719	return (int64(tv.Sec)*1e6 + int64(tv.Usec)) * 1e3
720}
721
722func NsecToTimeval(nsec int64) (tv Timeval) {
723	tv.Sec = int32(nsec / 1e9)
724	tv.Usec = int32(nsec % 1e9 / 1e3)
725	return
726}
727
728type Overlapped struct {
729	Internal     uintptr
730	InternalHigh uintptr
731	Offset       uint32
732	OffsetHigh   uint32
733	HEvent       Handle
734}
735
736type FileNotifyInformation struct {
737	NextEntryOffset uint32
738	Action          uint32
739	FileNameLength  uint32
740	FileName        uint16
741}
742
743type Filetime struct {
744	LowDateTime  uint32
745	HighDateTime uint32
746}
747
748// Nanoseconds returns Filetime ft in nanoseconds
749// since Epoch (00:00:00 UTC, January 1, 1970).
750func (ft *Filetime) Nanoseconds() int64 {
751	// 100-nanosecond intervals since January 1, 1601
752	nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime)
753	// change starting time to the Epoch (00:00:00 UTC, January 1, 1970)
754	nsec -= 116444736000000000
755	// convert into nanoseconds
756	nsec *= 100
757	return nsec
758}
759
760func NsecToFiletime(nsec int64) (ft Filetime) {
761	// convert into 100-nanosecond
762	nsec /= 100
763	// change starting time to January 1, 1601
764	nsec += 116444736000000000
765	// split into high / low
766	ft.LowDateTime = uint32(nsec & 0xffffffff)
767	ft.HighDateTime = uint32(nsec >> 32 & 0xffffffff)
768	return ft
769}
770
771type Win32finddata struct {
772	FileAttributes    uint32
773	CreationTime      Filetime
774	LastAccessTime    Filetime
775	LastWriteTime     Filetime
776	FileSizeHigh      uint32
777	FileSizeLow       uint32
778	Reserved0         uint32
779	Reserved1         uint32
780	FileName          [MAX_PATH - 1]uint16
781	AlternateFileName [13]uint16
782}
783
784// This is the actual system call structure.
785// Win32finddata is what we committed to in Go 1.
786type win32finddata1 struct {
787	FileAttributes    uint32
788	CreationTime      Filetime
789	LastAccessTime    Filetime
790	LastWriteTime     Filetime
791	FileSizeHigh      uint32
792	FileSizeLow       uint32
793	Reserved0         uint32
794	Reserved1         uint32
795	FileName          [MAX_PATH]uint16
796	AlternateFileName [14]uint16
797
798	// The Microsoft documentation for this struct¹ describes three additional
799	// fields: dwFileType, dwCreatorType, and wFinderFlags. However, those fields
800	// are empirically only present in the macOS port of the Win32 API,² and thus
801	// not needed for binaries built for Windows.
802	//
803	// ¹ https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-win32_find_dataw describe
804	// ² https://golang.org/issue/42637#issuecomment-760715755.
805}
806
807func copyFindData(dst *Win32finddata, src *win32finddata1) {
808	dst.FileAttributes = src.FileAttributes
809	dst.CreationTime = src.CreationTime
810	dst.LastAccessTime = src.LastAccessTime
811	dst.LastWriteTime = src.LastWriteTime
812	dst.FileSizeHigh = src.FileSizeHigh
813	dst.FileSizeLow = src.FileSizeLow
814	dst.Reserved0 = src.Reserved0
815	dst.Reserved1 = src.Reserved1
816
817	// The src is 1 element bigger than dst, but it must be NUL.
818	copy(dst.FileName[:], src.FileName[:])
819	copy(dst.AlternateFileName[:], src.AlternateFileName[:])
820}
821
822type ByHandleFileInformation struct {
823	FileAttributes     uint32
824	CreationTime       Filetime
825	LastAccessTime     Filetime
826	LastWriteTime      Filetime
827	VolumeSerialNumber uint32
828	FileSizeHigh       uint32
829	FileSizeLow        uint32
830	NumberOfLinks      uint32
831	FileIndexHigh      uint32
832	FileIndexLow       uint32
833}
834
835const (
836	GetFileExInfoStandard = 0
837	GetFileExMaxInfoLevel = 1
838)
839
840type Win32FileAttributeData struct {
841	FileAttributes uint32
842	CreationTime   Filetime
843	LastAccessTime Filetime
844	LastWriteTime  Filetime
845	FileSizeHigh   uint32
846	FileSizeLow    uint32
847}
848
849// ShowWindow constants
850const (
851	// winuser.h
852	SW_HIDE            = 0
853	SW_NORMAL          = 1
854	SW_SHOWNORMAL      = 1
855	SW_SHOWMINIMIZED   = 2
856	SW_SHOWMAXIMIZED   = 3
857	SW_MAXIMIZE        = 3
858	SW_SHOWNOACTIVATE  = 4
859	SW_SHOW            = 5
860	SW_MINIMIZE        = 6
861	SW_SHOWMINNOACTIVE = 7
862	SW_SHOWNA          = 8
863	SW_RESTORE         = 9
864	SW_SHOWDEFAULT     = 10
865	SW_FORCEMINIMIZE   = 11
866)
867
868type StartupInfo struct {
869	Cb            uint32
870	_             *uint16
871	Desktop       *uint16
872	Title         *uint16
873	X             uint32
874	Y             uint32
875	XSize         uint32
876	YSize         uint32
877	XCountChars   uint32
878	YCountChars   uint32
879	FillAttribute uint32
880	Flags         uint32
881	ShowWindow    uint16
882	_             uint16
883	_             *byte
884	StdInput      Handle
885	StdOutput     Handle
886	StdErr        Handle
887}
888
889type ProcessInformation struct {
890	Process   Handle
891	Thread    Handle
892	ProcessId uint32
893	ThreadId  uint32
894}
895
896type ProcessEntry32 struct {
897	Size            uint32
898	Usage           uint32
899	ProcessID       uint32
900	DefaultHeapID   uintptr
901	ModuleID        uint32
902	Threads         uint32
903	ParentProcessID uint32
904	PriClassBase    int32
905	Flags           uint32
906	ExeFile         [MAX_PATH]uint16
907}
908
909type ThreadEntry32 struct {
910	Size           uint32
911	Usage          uint32
912	ThreadID       uint32
913	OwnerProcessID uint32
914	BasePri        int32
915	DeltaPri       int32
916	Flags          uint32
917}
918
919type Systemtime struct {
920	Year         uint16
921	Month        uint16
922	DayOfWeek    uint16
923	Day          uint16
924	Hour         uint16
925	Minute       uint16
926	Second       uint16
927	Milliseconds uint16
928}
929
930type Timezoneinformation struct {
931	Bias         int32
932	StandardName [32]uint16
933	StandardDate Systemtime
934	StandardBias int32
935	DaylightName [32]uint16
936	DaylightDate Systemtime
937	DaylightBias int32
938}
939
940// Socket related.
941
942const (
943	AF_UNSPEC  = 0
944	AF_UNIX    = 1
945	AF_INET    = 2
946	AF_NETBIOS = 17
947	AF_INET6   = 23
948	AF_IRDA    = 26
949	AF_BTH     = 32
950
951	SOCK_STREAM    = 1
952	SOCK_DGRAM     = 2
953	SOCK_RAW       = 3
954	SOCK_RDM       = 4
955	SOCK_SEQPACKET = 5
956
957	IPPROTO_IP      = 0
958	IPPROTO_ICMP    = 1
959	IPPROTO_IGMP    = 2
960	BTHPROTO_RFCOMM = 3
961	IPPROTO_TCP     = 6
962	IPPROTO_UDP     = 17
963	IPPROTO_IPV6    = 41
964	IPPROTO_ICMPV6  = 58
965	IPPROTO_RM      = 113
966
967	SOL_SOCKET                = 0xffff
968	SO_REUSEADDR              = 4
969	SO_KEEPALIVE              = 8
970	SO_DONTROUTE              = 16
971	SO_BROADCAST              = 32
972	SO_LINGER                 = 128
973	SO_RCVBUF                 = 0x1002
974	SO_RCVTIMEO               = 0x1006
975	SO_SNDBUF                 = 0x1001
976	SO_UPDATE_ACCEPT_CONTEXT  = 0x700b
977	SO_UPDATE_CONNECT_CONTEXT = 0x7010
978
979	IOC_OUT                            = 0x40000000
980	IOC_IN                             = 0x80000000
981	IOC_VENDOR                         = 0x18000000
982	IOC_INOUT                          = IOC_IN | IOC_OUT
983	IOC_WS2                            = 0x08000000
984	SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6
985	SIO_KEEPALIVE_VALS                 = IOC_IN | IOC_VENDOR | 4
986	SIO_UDP_CONNRESET                  = IOC_IN | IOC_VENDOR | 12
987
988	// cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460
989
990	IP_TOS             = 0x3
991	IP_TTL             = 0x4
992	IP_MULTICAST_IF    = 0x9
993	IP_MULTICAST_TTL   = 0xa
994	IP_MULTICAST_LOOP  = 0xb
995	IP_ADD_MEMBERSHIP  = 0xc
996	IP_DROP_MEMBERSHIP = 0xd
997
998	IPV6_V6ONLY         = 0x1b
999	IPV6_UNICAST_HOPS   = 0x4
1000	IPV6_MULTICAST_IF   = 0x9
1001	IPV6_MULTICAST_HOPS = 0xa
1002	IPV6_MULTICAST_LOOP = 0xb
1003	IPV6_JOIN_GROUP     = 0xc
1004	IPV6_LEAVE_GROUP    = 0xd
1005
1006	MSG_OOB       = 0x1
1007	MSG_PEEK      = 0x2
1008	MSG_DONTROUTE = 0x4
1009	MSG_WAITALL   = 0x8
1010
1011	MSG_TRUNC  = 0x0100
1012	MSG_CTRUNC = 0x0200
1013	MSG_BCAST  = 0x0400
1014	MSG_MCAST  = 0x0800
1015
1016	SOMAXCONN = 0x7fffffff
1017
1018	TCP_NODELAY = 1
1019
1020	SHUT_RD   = 0
1021	SHUT_WR   = 1
1022	SHUT_RDWR = 2
1023
1024	WSADESCRIPTION_LEN = 256
1025	WSASYS_STATUS_LEN  = 128
1026)
1027
1028type WSABuf struct {
1029	Len uint32
1030	Buf *byte
1031}
1032
1033type WSAMsg struct {
1034	Name        *syscall.RawSockaddrAny
1035	Namelen     int32
1036	Buffers     *WSABuf
1037	BufferCount uint32
1038	Control     WSABuf
1039	Flags       uint32
1040}
1041
1042// Invented values to support what package os expects.
1043const (
1044	S_IFMT   = 0x1f000
1045	S_IFIFO  = 0x1000
1046	S_IFCHR  = 0x2000
1047	S_IFDIR  = 0x4000
1048	S_IFBLK  = 0x6000
1049	S_IFREG  = 0x8000
1050	S_IFLNK  = 0xa000
1051	S_IFSOCK = 0xc000
1052	S_ISUID  = 0x800
1053	S_ISGID  = 0x400
1054	S_ISVTX  = 0x200
1055	S_IRUSR  = 0x100
1056	S_IWRITE = 0x80
1057	S_IWUSR  = 0x80
1058	S_IXUSR  = 0x40
1059)
1060
1061const (
1062	FILE_TYPE_CHAR    = 0x0002
1063	FILE_TYPE_DISK    = 0x0001
1064	FILE_TYPE_PIPE    = 0x0003
1065	FILE_TYPE_REMOTE  = 0x8000
1066	FILE_TYPE_UNKNOWN = 0x0000
1067)
1068
1069type Hostent struct {
1070	Name     *byte
1071	Aliases  **byte
1072	AddrType uint16
1073	Length   uint16
1074	AddrList **byte
1075}
1076
1077type Protoent struct {
1078	Name    *byte
1079	Aliases **byte
1080	Proto   uint16
1081}
1082
1083const (
1084	DNS_TYPE_A       = 0x0001
1085	DNS_TYPE_NS      = 0x0002
1086	DNS_TYPE_MD      = 0x0003
1087	DNS_TYPE_MF      = 0x0004
1088	DNS_TYPE_CNAME   = 0x0005
1089	DNS_TYPE_SOA     = 0x0006
1090	DNS_TYPE_MB      = 0x0007
1091	DNS_TYPE_MG      = 0x0008
1092	DNS_TYPE_MR      = 0x0009
1093	DNS_TYPE_NULL    = 0x000a
1094	DNS_TYPE_WKS     = 0x000b
1095	DNS_TYPE_PTR     = 0x000c
1096	DNS_TYPE_HINFO   = 0x000d
1097	DNS_TYPE_MINFO   = 0x000e
1098	DNS_TYPE_MX      = 0x000f
1099	DNS_TYPE_TEXT    = 0x0010
1100	DNS_TYPE_RP      = 0x0011
1101	DNS_TYPE_AFSDB   = 0x0012
1102	DNS_TYPE_X25     = 0x0013
1103	DNS_TYPE_ISDN    = 0x0014
1104	DNS_TYPE_RT      = 0x0015
1105	DNS_TYPE_NSAP    = 0x0016
1106	DNS_TYPE_NSAPPTR = 0x0017
1107	DNS_TYPE_SIG     = 0x0018
1108	DNS_TYPE_KEY     = 0x0019
1109	DNS_TYPE_PX      = 0x001a
1110	DNS_TYPE_GPOS    = 0x001b
1111	DNS_TYPE_AAAA    = 0x001c
1112	DNS_TYPE_LOC     = 0x001d
1113	DNS_TYPE_NXT     = 0x001e
1114	DNS_TYPE_EID     = 0x001f
1115	DNS_TYPE_NIMLOC  = 0x0020
1116	DNS_TYPE_SRV     = 0x0021
1117	DNS_TYPE_ATMA    = 0x0022
1118	DNS_TYPE_NAPTR   = 0x0023
1119	DNS_TYPE_KX      = 0x0024
1120	DNS_TYPE_CERT    = 0x0025
1121	DNS_TYPE_A6      = 0x0026
1122	DNS_TYPE_DNAME   = 0x0027
1123	DNS_TYPE_SINK    = 0x0028
1124	DNS_TYPE_OPT     = 0x0029
1125	DNS_TYPE_DS      = 0x002B
1126	DNS_TYPE_RRSIG   = 0x002E
1127	DNS_TYPE_NSEC    = 0x002F
1128	DNS_TYPE_DNSKEY  = 0x0030
1129	DNS_TYPE_DHCID   = 0x0031
1130	DNS_TYPE_UINFO   = 0x0064
1131	DNS_TYPE_UID     = 0x0065
1132	DNS_TYPE_GID     = 0x0066
1133	DNS_TYPE_UNSPEC  = 0x0067
1134	DNS_TYPE_ADDRS   = 0x00f8
1135	DNS_TYPE_TKEY    = 0x00f9
1136	DNS_TYPE_TSIG    = 0x00fa
1137	DNS_TYPE_IXFR    = 0x00fb
1138	DNS_TYPE_AXFR    = 0x00fc
1139	DNS_TYPE_MAILB   = 0x00fd
1140	DNS_TYPE_MAILA   = 0x00fe
1141	DNS_TYPE_ALL     = 0x00ff
1142	DNS_TYPE_ANY     = 0x00ff
1143	DNS_TYPE_WINS    = 0xff01
1144	DNS_TYPE_WINSR   = 0xff02
1145	DNS_TYPE_NBSTAT  = 0xff01
1146)
1147
1148const (
1149	// flags inside DNSRecord.Dw
1150	DnsSectionQuestion   = 0x0000
1151	DnsSectionAnswer     = 0x0001
1152	DnsSectionAuthority  = 0x0002
1153	DnsSectionAdditional = 0x0003
1154)
1155
1156type DNSSRVData struct {
1157	Target   *uint16
1158	Priority uint16
1159	Weight   uint16
1160	Port     uint16
1161	Pad      uint16
1162}
1163
1164type DNSPTRData struct {
1165	Host *uint16
1166}
1167
1168type DNSMXData struct {
1169	NameExchange *uint16
1170	Preference   uint16
1171	Pad          uint16
1172}
1173
1174type DNSTXTData struct {
1175	StringCount uint16
1176	StringArray [1]*uint16
1177}
1178
1179type DNSRecord struct {
1180	Next     *DNSRecord
1181	Name     *uint16
1182	Type     uint16
1183	Length   uint16
1184	Dw       uint32
1185	Ttl      uint32
1186	Reserved uint32
1187	Data     [40]byte
1188}
1189
1190const (
1191	TF_DISCONNECT         = 1
1192	TF_REUSE_SOCKET       = 2
1193	TF_WRITE_BEHIND       = 4
1194	TF_USE_DEFAULT_WORKER = 0
1195	TF_USE_SYSTEM_THREAD  = 16
1196	TF_USE_KERNEL_APC     = 32
1197)
1198
1199type TransmitFileBuffers struct {
1200	Head       uintptr
1201	HeadLength uint32
1202	Tail       uintptr
1203	TailLength uint32
1204}
1205
1206const (
1207	IFF_UP           = 1
1208	IFF_BROADCAST    = 2
1209	IFF_LOOPBACK     = 4
1210	IFF_POINTTOPOINT = 8
1211	IFF_MULTICAST    = 16
1212)
1213
1214const SIO_GET_INTERFACE_LIST = 0x4004747F
1215
1216// TODO(mattn): SockaddrGen is union of sockaddr/sockaddr_in/sockaddr_in6_old.
1217// will be fixed to change variable type as suitable.
1218
1219type SockaddrGen [24]byte
1220
1221type InterfaceInfo struct {
1222	Flags            uint32
1223	Address          SockaddrGen
1224	BroadcastAddress SockaddrGen
1225	Netmask          SockaddrGen
1226}
1227
1228type IpAddressString struct {
1229	String [16]byte
1230}
1231
1232type IpMaskString IpAddressString
1233
1234type IpAddrString struct {
1235	Next      *IpAddrString
1236	IpAddress IpAddressString
1237	IpMask    IpMaskString
1238	Context   uint32
1239}
1240
1241const MAX_ADAPTER_NAME_LENGTH = 256
1242const MAX_ADAPTER_DESCRIPTION_LENGTH = 128
1243const MAX_ADAPTER_ADDRESS_LENGTH = 8
1244
1245type IpAdapterInfo struct {
1246	Next                *IpAdapterInfo
1247	ComboIndex          uint32
1248	AdapterName         [MAX_ADAPTER_NAME_LENGTH + 4]byte
1249	Description         [MAX_ADAPTER_DESCRIPTION_LENGTH + 4]byte
1250	AddressLength       uint32
1251	Address             [MAX_ADAPTER_ADDRESS_LENGTH]byte
1252	Index               uint32
1253	Type                uint32
1254	DhcpEnabled         uint32
1255	CurrentIpAddress    *IpAddrString
1256	IpAddressList       IpAddrString
1257	GatewayList         IpAddrString
1258	DhcpServer          IpAddrString
1259	HaveWins            bool
1260	PrimaryWinsServer   IpAddrString
1261	SecondaryWinsServer IpAddrString
1262	LeaseObtained       int64
1263	LeaseExpires        int64
1264}
1265
1266const MAXLEN_PHYSADDR = 8
1267const MAX_INTERFACE_NAME_LEN = 256
1268const MAXLEN_IFDESCR = 256
1269
1270type MibIfRow struct {
1271	Name            [MAX_INTERFACE_NAME_LEN]uint16
1272	Index           uint32
1273	Type            uint32
1274	Mtu             uint32
1275	Speed           uint32
1276	PhysAddrLen     uint32
1277	PhysAddr        [MAXLEN_PHYSADDR]byte
1278	AdminStatus     uint32
1279	OperStatus      uint32
1280	LastChange      uint32
1281	InOctets        uint32
1282	InUcastPkts     uint32
1283	InNUcastPkts    uint32
1284	InDiscards      uint32
1285	InErrors        uint32
1286	InUnknownProtos uint32
1287	OutOctets       uint32
1288	OutUcastPkts    uint32
1289	OutNUcastPkts   uint32
1290	OutDiscards     uint32
1291	OutErrors       uint32
1292	OutQLen         uint32
1293	DescrLen        uint32
1294	Descr           [MAXLEN_IFDESCR]byte
1295}
1296
1297type CertInfo struct {
1298	Version              uint32
1299	SerialNumber         CryptIntegerBlob
1300	SignatureAlgorithm   CryptAlgorithmIdentifier
1301	Issuer               CertNameBlob
1302	NotBefore            Filetime
1303	NotAfter             Filetime
1304	Subject              CertNameBlob
1305	SubjectPublicKeyInfo CertPublicKeyInfo
1306	IssuerUniqueId       CryptBitBlob
1307	SubjectUniqueId      CryptBitBlob
1308	CountExtensions      uint32
1309	Extensions           *CertExtension
1310}
1311
1312type CertExtension struct {
1313	ObjId    *byte
1314	Critical int32
1315	Value    CryptObjidBlob
1316}
1317
1318type CryptAlgorithmIdentifier struct {
1319	ObjId      *byte
1320	Parameters CryptObjidBlob
1321}
1322
1323type CertPublicKeyInfo struct {
1324	Algorithm CryptAlgorithmIdentifier
1325	PublicKey CryptBitBlob
1326}
1327
1328type DataBlob struct {
1329	Size uint32
1330	Data *byte
1331}
1332type CryptIntegerBlob DataBlob
1333type CryptUintBlob DataBlob
1334type CryptObjidBlob DataBlob
1335type CertNameBlob DataBlob
1336type CertRdnValueBlob DataBlob
1337type CertBlob DataBlob
1338type CrlBlob DataBlob
1339type CryptDataBlob DataBlob
1340type CryptHashBlob DataBlob
1341type CryptDigestBlob DataBlob
1342type CryptDerBlob DataBlob
1343type CryptAttrBlob DataBlob
1344
1345type CryptBitBlob struct {
1346	Size       uint32
1347	Data       *byte
1348	UnusedBits uint32
1349}
1350
1351type CertContext struct {
1352	EncodingType uint32
1353	EncodedCert  *byte
1354	Length       uint32
1355	CertInfo     *CertInfo
1356	Store        Handle
1357}
1358
1359type CertChainContext struct {
1360	Size                       uint32
1361	TrustStatus                CertTrustStatus
1362	ChainCount                 uint32
1363	Chains                     **CertSimpleChain
1364	LowerQualityChainCount     uint32
1365	LowerQualityChains         **CertChainContext
1366	HasRevocationFreshnessTime uint32
1367	RevocationFreshnessTime    uint32
1368}
1369
1370type CertTrustListInfo struct {
1371	// Not implemented
1372}
1373
1374type CertSimpleChain struct {
1375	Size                       uint32
1376	TrustStatus                CertTrustStatus
1377	NumElements                uint32
1378	Elements                   **CertChainElement
1379	TrustListInfo              *CertTrustListInfo
1380	HasRevocationFreshnessTime uint32
1381	RevocationFreshnessTime    uint32
1382}
1383
1384type CertChainElement struct {
1385	Size              uint32
1386	CertContext       *CertContext
1387	TrustStatus       CertTrustStatus
1388	RevocationInfo    *CertRevocationInfo
1389	IssuanceUsage     *CertEnhKeyUsage
1390	ApplicationUsage  *CertEnhKeyUsage
1391	ExtendedErrorInfo *uint16
1392}
1393
1394type CertRevocationCrlInfo struct {
1395	// Not implemented
1396}
1397
1398type CertRevocationInfo struct {
1399	Size             uint32
1400	RevocationResult uint32
1401	RevocationOid    *byte
1402	OidSpecificInfo  Pointer
1403	HasFreshnessTime uint32
1404	FreshnessTime    uint32
1405	CrlInfo          *CertRevocationCrlInfo
1406}
1407
1408type CertTrustStatus struct {
1409	ErrorStatus uint32
1410	InfoStatus  uint32
1411}
1412
1413type CertUsageMatch struct {
1414	Type  uint32
1415	Usage CertEnhKeyUsage
1416}
1417
1418type CertEnhKeyUsage struct {
1419	Length           uint32
1420	UsageIdentifiers **byte
1421}
1422
1423type CertChainPara struct {
1424	Size                         uint32
1425	RequestedUsage               CertUsageMatch
1426	RequstedIssuancePolicy       CertUsageMatch
1427	URLRetrievalTimeout          uint32
1428	CheckRevocationFreshnessTime uint32
1429	RevocationFreshnessTime      uint32
1430	CacheResync                  *Filetime
1431}
1432
1433type CertChainPolicyPara struct {
1434	Size            uint32
1435	Flags           uint32
1436	ExtraPolicyPara Pointer
1437}
1438
1439type SSLExtraCertChainPolicyPara struct {
1440	Size       uint32
1441	AuthType   uint32
1442	Checks     uint32
1443	ServerName *uint16
1444}
1445
1446type CertChainPolicyStatus struct {
1447	Size              uint32
1448	Error             uint32
1449	ChainIndex        uint32
1450	ElementIndex      uint32
1451	ExtraPolicyStatus Pointer
1452}
1453
1454type CertPolicyInfo struct {
1455	Identifier      *byte
1456	CountQualifiers uint32
1457	Qualifiers      *CertPolicyQualifierInfo
1458}
1459
1460type CertPoliciesInfo struct {
1461	Count       uint32
1462	PolicyInfos *CertPolicyInfo
1463}
1464
1465type CertPolicyQualifierInfo struct {
1466	// Not implemented
1467}
1468
1469type CertStrongSignPara struct {
1470	Size                      uint32
1471	InfoChoice                uint32
1472	InfoOrSerializedInfoOrOID unsafe.Pointer
1473}
1474
1475type CryptProtectPromptStruct struct {
1476	Size        uint32
1477	PromptFlags uint32
1478	App         HWND
1479	Prompt      *uint16
1480}
1481
1482type CertChainFindByIssuerPara struct {
1483	Size                   uint32
1484	UsageIdentifier        *byte
1485	KeySpec                uint32
1486	AcquirePrivateKeyFlags uint32
1487	IssuerCount            uint32
1488	Issuer                 Pointer
1489	FindCallback           Pointer
1490	FindArg                Pointer
1491	IssuerChainIndex       *uint32
1492	IssuerElementIndex     *uint32
1493}
1494
1495type WinTrustData struct {
1496	Size                            uint32
1497	PolicyCallbackData              uintptr
1498	SIPClientData                   uintptr
1499	UIChoice                        uint32
1500	RevocationChecks                uint32
1501	UnionChoice                     uint32
1502	FileOrCatalogOrBlobOrSgnrOrCert unsafe.Pointer
1503	StateAction                     uint32
1504	StateData                       Handle
1505	URLReference                    *uint16
1506	ProvFlags                       uint32
1507	UIContext                       uint32
1508	SignatureSettings               *WinTrustSignatureSettings
1509}
1510
1511type WinTrustFileInfo struct {
1512	Size         uint32
1513	FilePath     *uint16
1514	File         Handle
1515	KnownSubject *GUID
1516}
1517
1518type WinTrustSignatureSettings struct {
1519	Size             uint32
1520	Index            uint32
1521	Flags            uint32
1522	SecondarySigs    uint32
1523	VerifiedSigIndex uint32
1524	CryptoPolicy     *CertStrongSignPara
1525}
1526
1527const (
1528	// do not reorder
1529	HKEY_CLASSES_ROOT = 0x80000000 + iota
1530	HKEY_CURRENT_USER
1531	HKEY_LOCAL_MACHINE
1532	HKEY_USERS
1533	HKEY_PERFORMANCE_DATA
1534	HKEY_CURRENT_CONFIG
1535	HKEY_DYN_DATA
1536
1537	KEY_QUERY_VALUE        = 1
1538	KEY_SET_VALUE          = 2
1539	KEY_CREATE_SUB_KEY     = 4
1540	KEY_ENUMERATE_SUB_KEYS = 8
1541	KEY_NOTIFY             = 16
1542	KEY_CREATE_LINK        = 32
1543	KEY_WRITE              = 0x20006
1544	KEY_EXECUTE            = 0x20019
1545	KEY_READ               = 0x20019
1546	KEY_WOW64_64KEY        = 0x0100
1547	KEY_WOW64_32KEY        = 0x0200
1548	KEY_ALL_ACCESS         = 0xf003f
1549)
1550
1551const (
1552	// do not reorder
1553	REG_NONE = iota
1554	REG_SZ
1555	REG_EXPAND_SZ
1556	REG_BINARY
1557	REG_DWORD_LITTLE_ENDIAN
1558	REG_DWORD_BIG_ENDIAN
1559	REG_LINK
1560	REG_MULTI_SZ
1561	REG_RESOURCE_LIST
1562	REG_FULL_RESOURCE_DESCRIPTOR
1563	REG_RESOURCE_REQUIREMENTS_LIST
1564	REG_QWORD_LITTLE_ENDIAN
1565	REG_DWORD = REG_DWORD_LITTLE_ENDIAN
1566	REG_QWORD = REG_QWORD_LITTLE_ENDIAN
1567)
1568
1569const (
1570	EVENT_MODIFY_STATE = 0x0002
1571	EVENT_ALL_ACCESS   = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3
1572
1573	MUTANT_QUERY_STATE = 0x0001
1574	MUTANT_ALL_ACCESS  = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | MUTANT_QUERY_STATE
1575
1576	SEMAPHORE_MODIFY_STATE = 0x0002
1577	SEMAPHORE_ALL_ACCESS   = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3
1578
1579	TIMER_QUERY_STATE  = 0x0001
1580	TIMER_MODIFY_STATE = 0x0002
1581	TIMER_ALL_ACCESS   = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | TIMER_QUERY_STATE | TIMER_MODIFY_STATE
1582
1583	MUTEX_MODIFY_STATE = MUTANT_QUERY_STATE
1584	MUTEX_ALL_ACCESS   = MUTANT_ALL_ACCESS
1585
1586	CREATE_EVENT_MANUAL_RESET  = 0x1
1587	CREATE_EVENT_INITIAL_SET   = 0x2
1588	CREATE_MUTEX_INITIAL_OWNER = 0x1
1589)
1590
1591type AddrinfoW struct {
1592	Flags     int32
1593	Family    int32
1594	Socktype  int32
1595	Protocol  int32
1596	Addrlen   uintptr
1597	Canonname *uint16
1598	Addr      uintptr
1599	Next      *AddrinfoW
1600}
1601
1602const (
1603	AI_PASSIVE     = 1
1604	AI_CANONNAME   = 2
1605	AI_NUMERICHOST = 4
1606)
1607
1608type GUID struct {
1609	Data1 uint32
1610	Data2 uint16
1611	Data3 uint16
1612	Data4 [8]byte
1613}
1614
1615var WSAID_CONNECTEX = GUID{
1616	0x25a207b9,
1617	0xddf3,
1618	0x4660,
1619	[8]byte{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e},
1620}
1621
1622var WSAID_WSASENDMSG = GUID{
1623	0xa441e712,
1624	0x754f,
1625	0x43ca,
1626	[8]byte{0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d},
1627}
1628
1629var WSAID_WSARECVMSG = GUID{
1630	0xf689d7c8,
1631	0x6f1f,
1632	0x436b,
1633	[8]byte{0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22},
1634}
1635
1636const (
1637	FILE_SKIP_COMPLETION_PORT_ON_SUCCESS = 1
1638	FILE_SKIP_SET_EVENT_ON_HANDLE        = 2
1639)
1640
1641const (
1642	WSAPROTOCOL_LEN    = 255
1643	MAX_PROTOCOL_CHAIN = 7
1644	BASE_PROTOCOL      = 1
1645	LAYERED_PROTOCOL   = 0
1646
1647	XP1_CONNECTIONLESS           = 0x00000001
1648	XP1_GUARANTEED_DELIVERY      = 0x00000002
1649	XP1_GUARANTEED_ORDER         = 0x00000004
1650	XP1_MESSAGE_ORIENTED         = 0x00000008
1651	XP1_PSEUDO_STREAM            = 0x00000010
1652	XP1_GRACEFUL_CLOSE           = 0x00000020
1653	XP1_EXPEDITED_DATA           = 0x00000040
1654	XP1_CONNECT_DATA             = 0x00000080
1655	XP1_DISCONNECT_DATA          = 0x00000100
1656	XP1_SUPPORT_BROADCAST        = 0x00000200
1657	XP1_SUPPORT_MULTIPOINT       = 0x00000400
1658	XP1_MULTIPOINT_CONTROL_PLANE = 0x00000800
1659	XP1_MULTIPOINT_DATA_PLANE    = 0x00001000
1660	XP1_QOS_SUPPORTED            = 0x00002000
1661	XP1_UNI_SEND                 = 0x00008000
1662	XP1_UNI_RECV                 = 0x00010000
1663	XP1_IFS_HANDLES              = 0x00020000
1664	XP1_PARTIAL_MESSAGE          = 0x00040000
1665	XP1_SAN_SUPPORT_SDP          = 0x00080000
1666
1667	PFL_MULTIPLE_PROTO_ENTRIES  = 0x00000001
1668	PFL_RECOMMENDED_PROTO_ENTRY = 0x00000002
1669	PFL_HIDDEN                  = 0x00000004
1670	PFL_MATCHES_PROTOCOL_ZERO   = 0x00000008
1671	PFL_NETWORKDIRECT_PROVIDER  = 0x00000010
1672)
1673
1674type WSAProtocolInfo struct {
1675	ServiceFlags1     uint32
1676	ServiceFlags2     uint32
1677	ServiceFlags3     uint32
1678	ServiceFlags4     uint32
1679	ProviderFlags     uint32
1680	ProviderId        GUID
1681	CatalogEntryId    uint32
1682	ProtocolChain     WSAProtocolChain
1683	Version           int32
1684	AddressFamily     int32
1685	MaxSockAddr       int32
1686	MinSockAddr       int32
1687	SocketType        int32
1688	Protocol          int32
1689	ProtocolMaxOffset int32
1690	NetworkByteOrder  int32
1691	SecurityScheme    int32
1692	MessageSize       uint32
1693	ProviderReserved  uint32
1694	ProtocolName      [WSAPROTOCOL_LEN + 1]uint16
1695}
1696
1697type WSAProtocolChain struct {
1698	ChainLen     int32
1699	ChainEntries [MAX_PROTOCOL_CHAIN]uint32
1700}
1701
1702type TCPKeepalive struct {
1703	OnOff    uint32
1704	Time     uint32
1705	Interval uint32
1706}
1707
1708type symbolicLinkReparseBuffer struct {
1709	SubstituteNameOffset uint16
1710	SubstituteNameLength uint16
1711	PrintNameOffset      uint16
1712	PrintNameLength      uint16
1713	Flags                uint32
1714	PathBuffer           [1]uint16
1715}
1716
1717type mountPointReparseBuffer struct {
1718	SubstituteNameOffset uint16
1719	SubstituteNameLength uint16
1720	PrintNameOffset      uint16
1721	PrintNameLength      uint16
1722	PathBuffer           [1]uint16
1723}
1724
1725type reparseDataBuffer struct {
1726	ReparseTag        uint32
1727	ReparseDataLength uint16
1728	Reserved          uint16
1729
1730	// GenericReparseBuffer
1731	reparseBuffer byte
1732}
1733
1734const (
1735	FSCTL_GET_REPARSE_POINT          = 0x900A8
1736	MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024
1737	IO_REPARSE_TAG_MOUNT_POINT       = 0xA0000003
1738	IO_REPARSE_TAG_SYMLINK           = 0xA000000C
1739	SYMBOLIC_LINK_FLAG_DIRECTORY     = 0x1
1740)
1741
1742const (
1743	ComputerNameNetBIOS                   = 0
1744	ComputerNameDnsHostname               = 1
1745	ComputerNameDnsDomain                 = 2
1746	ComputerNameDnsFullyQualified         = 3
1747	ComputerNamePhysicalNetBIOS           = 4
1748	ComputerNamePhysicalDnsHostname       = 5
1749	ComputerNamePhysicalDnsDomain         = 6
1750	ComputerNamePhysicalDnsFullyQualified = 7
1751	ComputerNameMax                       = 8
1752)
1753
1754// For MessageBox()
1755const (
1756	MB_OK                   = 0x00000000
1757	MB_OKCANCEL             = 0x00000001
1758	MB_ABORTRETRYIGNORE     = 0x00000002
1759	MB_YESNOCANCEL          = 0x00000003
1760	MB_YESNO                = 0x00000004
1761	MB_RETRYCANCEL          = 0x00000005
1762	MB_CANCELTRYCONTINUE    = 0x00000006
1763	MB_ICONHAND             = 0x00000010
1764	MB_ICONQUESTION         = 0x00000020
1765	MB_ICONEXCLAMATION      = 0x00000030
1766	MB_ICONASTERISK         = 0x00000040
1767	MB_USERICON             = 0x00000080
1768	MB_ICONWARNING          = MB_ICONEXCLAMATION
1769	MB_ICONERROR            = MB_ICONHAND
1770	MB_ICONINFORMATION      = MB_ICONASTERISK
1771	MB_ICONSTOP             = MB_ICONHAND
1772	MB_DEFBUTTON1           = 0x00000000
1773	MB_DEFBUTTON2           = 0x00000100
1774	MB_DEFBUTTON3           = 0x00000200
1775	MB_DEFBUTTON4           = 0x00000300
1776	MB_APPLMODAL            = 0x00000000
1777	MB_SYSTEMMODAL          = 0x00001000
1778	MB_TASKMODAL            = 0x00002000
1779	MB_HELP                 = 0x00004000
1780	MB_NOFOCUS              = 0x00008000
1781	MB_SETFOREGROUND        = 0x00010000
1782	MB_DEFAULT_DESKTOP_ONLY = 0x00020000
1783	MB_TOPMOST              = 0x00040000
1784	MB_RIGHT                = 0x00080000
1785	MB_RTLREADING           = 0x00100000
1786	MB_SERVICE_NOTIFICATION = 0x00200000
1787)
1788
1789const (
1790	MOVEFILE_REPLACE_EXISTING      = 0x1
1791	MOVEFILE_COPY_ALLOWED          = 0x2
1792	MOVEFILE_DELAY_UNTIL_REBOOT    = 0x4
1793	MOVEFILE_WRITE_THROUGH         = 0x8
1794	MOVEFILE_CREATE_HARDLINK       = 0x10
1795	MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20
1796)
1797
1798const GAA_FLAG_INCLUDE_PREFIX = 0x00000010
1799
1800const (
1801	IF_TYPE_OTHER              = 1
1802	IF_TYPE_ETHERNET_CSMACD    = 6
1803	IF_TYPE_ISO88025_TOKENRING = 9
1804	IF_TYPE_PPP                = 23
1805	IF_TYPE_SOFTWARE_LOOPBACK  = 24
1806	IF_TYPE_ATM                = 37
1807	IF_TYPE_IEEE80211          = 71
1808	IF_TYPE_TUNNEL             = 131
1809	IF_TYPE_IEEE1394           = 144
1810)
1811
1812type SocketAddress struct {
1813	Sockaddr       *syscall.RawSockaddrAny
1814	SockaddrLength int32
1815}
1816
1817// IP returns an IPv4 or IPv6 address, or nil if the underlying SocketAddress is neither.
1818func (addr *SocketAddress) IP() net.IP {
1819	if uintptr(addr.SockaddrLength) >= unsafe.Sizeof(RawSockaddrInet4{}) && addr.Sockaddr.Addr.Family == AF_INET {
1820		return (*RawSockaddrInet4)(unsafe.Pointer(addr.Sockaddr)).Addr[:]
1821	} else if uintptr(addr.SockaddrLength) >= unsafe.Sizeof(RawSockaddrInet6{}) && addr.Sockaddr.Addr.Family == AF_INET6 {
1822		return (*RawSockaddrInet6)(unsafe.Pointer(addr.Sockaddr)).Addr[:]
1823	}
1824	return nil
1825}
1826
1827type IpAdapterUnicastAddress struct {
1828	Length             uint32
1829	Flags              uint32
1830	Next               *IpAdapterUnicastAddress
1831	Address            SocketAddress
1832	PrefixOrigin       int32
1833	SuffixOrigin       int32
1834	DadState           int32
1835	ValidLifetime      uint32
1836	PreferredLifetime  uint32
1837	LeaseLifetime      uint32
1838	OnLinkPrefixLength uint8
1839}
1840
1841type IpAdapterAnycastAddress struct {
1842	Length  uint32
1843	Flags   uint32
1844	Next    *IpAdapterAnycastAddress
1845	Address SocketAddress
1846}
1847
1848type IpAdapterMulticastAddress struct {
1849	Length  uint32
1850	Flags   uint32
1851	Next    *IpAdapterMulticastAddress
1852	Address SocketAddress
1853}
1854
1855type IpAdapterDnsServerAdapter struct {
1856	Length   uint32
1857	Reserved uint32
1858	Next     *IpAdapterDnsServerAdapter
1859	Address  SocketAddress
1860}
1861
1862type IpAdapterPrefix struct {
1863	Length       uint32
1864	Flags        uint32
1865	Next         *IpAdapterPrefix
1866	Address      SocketAddress
1867	PrefixLength uint32
1868}
1869
1870type IpAdapterAddresses struct {
1871	Length                uint32
1872	IfIndex               uint32
1873	Next                  *IpAdapterAddresses
1874	AdapterName           *byte
1875	FirstUnicastAddress   *IpAdapterUnicastAddress
1876	FirstAnycastAddress   *IpAdapterAnycastAddress
1877	FirstMulticastAddress *IpAdapterMulticastAddress
1878	FirstDnsServerAddress *IpAdapterDnsServerAdapter
1879	DnsSuffix             *uint16
1880	Description           *uint16
1881	FriendlyName          *uint16
1882	PhysicalAddress       [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
1883	PhysicalAddressLength uint32
1884	Flags                 uint32
1885	Mtu                   uint32
1886	IfType                uint32
1887	OperStatus            uint32
1888	Ipv6IfIndex           uint32
1889	ZoneIndices           [16]uint32
1890	FirstPrefix           *IpAdapterPrefix
1891	/* more fields might be present here. */
1892}
1893
1894const (
1895	IfOperStatusUp             = 1
1896	IfOperStatusDown           = 2
1897	IfOperStatusTesting        = 3
1898	IfOperStatusUnknown        = 4
1899	IfOperStatusDormant        = 5
1900	IfOperStatusNotPresent     = 6
1901	IfOperStatusLowerLayerDown = 7
1902)
1903
1904// Console related constants used for the mode parameter to SetConsoleMode. See
1905// https://docs.microsoft.com/en-us/windows/console/setconsolemode for details.
1906
1907const (
1908	ENABLE_PROCESSED_INPUT        = 0x1
1909	ENABLE_LINE_INPUT             = 0x2
1910	ENABLE_ECHO_INPUT             = 0x4
1911	ENABLE_WINDOW_INPUT           = 0x8
1912	ENABLE_MOUSE_INPUT            = 0x10
1913	ENABLE_INSERT_MODE            = 0x20
1914	ENABLE_QUICK_EDIT_MODE        = 0x40
1915	ENABLE_EXTENDED_FLAGS         = 0x80
1916	ENABLE_AUTO_POSITION          = 0x100
1917	ENABLE_VIRTUAL_TERMINAL_INPUT = 0x200
1918
1919	ENABLE_PROCESSED_OUTPUT            = 0x1
1920	ENABLE_WRAP_AT_EOL_OUTPUT          = 0x2
1921	ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
1922	DISABLE_NEWLINE_AUTO_RETURN        = 0x8
1923	ENABLE_LVB_GRID_WORLDWIDE          = 0x10
1924)
1925
1926type Coord struct {
1927	X int16
1928	Y int16
1929}
1930
1931type SmallRect struct {
1932	Left   int16
1933	Top    int16
1934	Right  int16
1935	Bottom int16
1936}
1937
1938// Used with GetConsoleScreenBuffer to retrieve information about a console
1939// screen buffer. See
1940// https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str
1941// for details.
1942
1943type ConsoleScreenBufferInfo struct {
1944	Size              Coord
1945	CursorPosition    Coord
1946	Attributes        uint16
1947	Window            SmallRect
1948	MaximumWindowSize Coord
1949}
1950
1951const UNIX_PATH_MAX = 108 // defined in afunix.h
1952
1953const (
1954	// flags for JOBOBJECT_BASIC_LIMIT_INFORMATION.LimitFlags
1955	JOB_OBJECT_LIMIT_ACTIVE_PROCESS             = 0x00000008
1956	JOB_OBJECT_LIMIT_AFFINITY                   = 0x00000010
1957	JOB_OBJECT_LIMIT_BREAKAWAY_OK               = 0x00000800
1958	JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION = 0x00000400
1959	JOB_OBJECT_LIMIT_JOB_MEMORY                 = 0x00000200
1960	JOB_OBJECT_LIMIT_JOB_TIME                   = 0x00000004
1961	JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE          = 0x00002000
1962	JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME          = 0x00000040
1963	JOB_OBJECT_LIMIT_PRIORITY_CLASS             = 0x00000020
1964	JOB_OBJECT_LIMIT_PROCESS_MEMORY             = 0x00000100
1965	JOB_OBJECT_LIMIT_PROCESS_TIME               = 0x00000002
1966	JOB_OBJECT_LIMIT_SCHEDULING_CLASS           = 0x00000080
1967	JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK        = 0x00001000
1968	JOB_OBJECT_LIMIT_SUBSET_AFFINITY            = 0x00004000
1969	JOB_OBJECT_LIMIT_WORKINGSET                 = 0x00000001
1970)
1971
1972type IO_COUNTERS struct {
1973	ReadOperationCount  uint64
1974	WriteOperationCount uint64
1975	OtherOperationCount uint64
1976	ReadTransferCount   uint64
1977	WriteTransferCount  uint64
1978	OtherTransferCount  uint64
1979}
1980
1981type JOBOBJECT_EXTENDED_LIMIT_INFORMATION struct {
1982	BasicLimitInformation JOBOBJECT_BASIC_LIMIT_INFORMATION
1983	IoInfo                IO_COUNTERS
1984	ProcessMemoryLimit    uintptr
1985	JobMemoryLimit        uintptr
1986	PeakProcessMemoryUsed uintptr
1987	PeakJobMemoryUsed     uintptr
1988}
1989
1990const (
1991	// UIRestrictionsClass
1992	JOB_OBJECT_UILIMIT_DESKTOP          = 0x00000040
1993	JOB_OBJECT_UILIMIT_DISPLAYSETTINGS  = 0x00000010
1994	JOB_OBJECT_UILIMIT_EXITWINDOWS      = 0x00000080
1995	JOB_OBJECT_UILIMIT_GLOBALATOMS      = 0x00000020
1996	JOB_OBJECT_UILIMIT_HANDLES          = 0x00000001
1997	JOB_OBJECT_UILIMIT_READCLIPBOARD    = 0x00000002
1998	JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS = 0x00000008
1999	JOB_OBJECT_UILIMIT_WRITECLIPBOARD   = 0x00000004
2000)
2001
2002type JOBOBJECT_BASIC_UI_RESTRICTIONS struct {
2003	UIRestrictionsClass uint32
2004}
2005
2006const (
2007	// JobObjectInformationClass
2008	JobObjectAssociateCompletionPortInformation = 7
2009	JobObjectBasicLimitInformation              = 2
2010	JobObjectBasicUIRestrictions                = 4
2011	JobObjectCpuRateControlInformation          = 15
2012	JobObjectEndOfJobTimeInformation            = 6
2013	JobObjectExtendedLimitInformation           = 9
2014	JobObjectGroupInformation                   = 11
2015	JobObjectGroupInformationEx                 = 14
2016	JobObjectLimitViolationInformation2         = 35
2017	JobObjectNetRateControlInformation          = 32
2018	JobObjectNotificationLimitInformation       = 12
2019	JobObjectNotificationLimitInformation2      = 34
2020	JobObjectSecurityLimitInformation           = 5
2021)
2022
2023const (
2024	KF_FLAG_DEFAULT                          = 0x00000000
2025	KF_FLAG_FORCE_APP_DATA_REDIRECTION       = 0x00080000
2026	KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET = 0x00040000
2027	KF_FLAG_FORCE_PACKAGE_REDIRECTION        = 0x00020000
2028	KF_FLAG_NO_PACKAGE_REDIRECTION           = 0x00010000
2029	KF_FLAG_FORCE_APPCONTAINER_REDIRECTION   = 0x00020000
2030	KF_FLAG_NO_APPCONTAINER_REDIRECTION      = 0x00010000
2031	KF_FLAG_CREATE                           = 0x00008000
2032	KF_FLAG_DONT_VERIFY                      = 0x00004000
2033	KF_FLAG_DONT_UNEXPAND                    = 0x00002000
2034	KF_FLAG_NO_ALIAS                         = 0x00001000
2035	KF_FLAG_INIT                             = 0x00000800
2036	KF_FLAG_DEFAULT_PATH                     = 0x00000400
2037	KF_FLAG_NOT_PARENT_RELATIVE              = 0x00000200
2038	KF_FLAG_SIMPLE_IDLIST                    = 0x00000100
2039	KF_FLAG_ALIAS_ONLY                       = 0x80000000
2040)
2041
2042type OsVersionInfoEx struct {
2043	osVersionInfoSize uint32
2044	MajorVersion      uint32
2045	MinorVersion      uint32
2046	BuildNumber       uint32
2047	PlatformId        uint32
2048	CsdVersion        [128]uint16
2049	ServicePackMajor  uint16
2050	ServicePackMinor  uint16
2051	SuiteMask         uint16
2052	ProductType       byte
2053	_                 byte
2054}
2055
2056const (
2057	EWX_LOGOFF          = 0x00000000
2058	EWX_SHUTDOWN        = 0x00000001
2059	EWX_REBOOT          = 0x00000002
2060	EWX_FORCE           = 0x00000004
2061	EWX_POWEROFF        = 0x00000008
2062	EWX_FORCEIFHUNG     = 0x00000010
2063	EWX_QUICKRESOLVE    = 0x00000020
2064	EWX_RESTARTAPPS     = 0x00000040
2065	EWX_HYBRID_SHUTDOWN = 0x00400000
2066	EWX_BOOTOPTIONS     = 0x01000000
2067
2068	SHTDN_REASON_FLAG_COMMENT_REQUIRED          = 0x01000000
2069	SHTDN_REASON_FLAG_DIRTY_PROBLEM_ID_REQUIRED = 0x02000000
2070	SHTDN_REASON_FLAG_CLEAN_UI                  = 0x04000000
2071	SHTDN_REASON_FLAG_DIRTY_UI                  = 0x08000000
2072	SHTDN_REASON_FLAG_USER_DEFINED              = 0x40000000
2073	SHTDN_REASON_FLAG_PLANNED                   = 0x80000000
2074	SHTDN_REASON_MAJOR_OTHER                    = 0x00000000
2075	SHTDN_REASON_MAJOR_NONE                     = 0x00000000
2076	SHTDN_REASON_MAJOR_HARDWARE                 = 0x00010000
2077	SHTDN_REASON_MAJOR_OPERATINGSYSTEM          = 0x00020000
2078	SHTDN_REASON_MAJOR_SOFTWARE                 = 0x00030000
2079	SHTDN_REASON_MAJOR_APPLICATION              = 0x00040000
2080	SHTDN_REASON_MAJOR_SYSTEM                   = 0x00050000
2081	SHTDN_REASON_MAJOR_POWER                    = 0x00060000
2082	SHTDN_REASON_MAJOR_LEGACY_API               = 0x00070000
2083	SHTDN_REASON_MINOR_OTHER                    = 0x00000000
2084	SHTDN_REASON_MINOR_NONE                     = 0x000000ff
2085	SHTDN_REASON_MINOR_MAINTENANCE              = 0x00000001
2086	SHTDN_REASON_MINOR_INSTALLATION             = 0x00000002
2087	SHTDN_REASON_MINOR_UPGRADE                  = 0x00000003
2088	SHTDN_REASON_MINOR_RECONFIG                 = 0x00000004
2089	SHTDN_REASON_MINOR_HUNG                     = 0x00000005
2090	SHTDN_REASON_MINOR_UNSTABLE                 = 0x00000006
2091	SHTDN_REASON_MINOR_DISK                     = 0x00000007
2092	SHTDN_REASON_MINOR_PROCESSOR                = 0x00000008
2093	SHTDN_REASON_MINOR_NETWORKCARD              = 0x00000009
2094	SHTDN_REASON_MINOR_POWER_SUPPLY             = 0x0000000a
2095	SHTDN_REASON_MINOR_CORDUNPLUGGED            = 0x0000000b
2096	SHTDN_REASON_MINOR_ENVIRONMENT              = 0x0000000c
2097	SHTDN_REASON_MINOR_HARDWARE_DRIVER          = 0x0000000d
2098	SHTDN_REASON_MINOR_OTHERDRIVER              = 0x0000000e
2099	SHTDN_REASON_MINOR_BLUESCREEN               = 0x0000000F
2100	SHTDN_REASON_MINOR_SERVICEPACK              = 0x00000010
2101	SHTDN_REASON_MINOR_HOTFIX                   = 0x00000011
2102	SHTDN_REASON_MINOR_SECURITYFIX              = 0x00000012
2103	SHTDN_REASON_MINOR_SECURITY                 = 0x00000013
2104	SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY     = 0x00000014
2105	SHTDN_REASON_MINOR_WMI                      = 0x00000015
2106	SHTDN_REASON_MINOR_SERVICEPACK_UNINSTALL    = 0x00000016
2107	SHTDN_REASON_MINOR_HOTFIX_UNINSTALL         = 0x00000017
2108	SHTDN_REASON_MINOR_SECURITYFIX_UNINSTALL    = 0x00000018
2109	SHTDN_REASON_MINOR_MMC                      = 0x00000019
2110	SHTDN_REASON_MINOR_SYSTEMRESTORE            = 0x0000001a
2111	SHTDN_REASON_MINOR_TERMSRV                  = 0x00000020
2112	SHTDN_REASON_MINOR_DC_PROMOTION             = 0x00000021
2113	SHTDN_REASON_MINOR_DC_DEMOTION              = 0x00000022
2114	SHTDN_REASON_UNKNOWN                        = SHTDN_REASON_MINOR_NONE
2115	SHTDN_REASON_LEGACY_API                     = SHTDN_REASON_MAJOR_LEGACY_API | SHTDN_REASON_FLAG_PLANNED
2116	SHTDN_REASON_VALID_BIT_MASK                 = 0xc0ffffff
2117
2118	SHUTDOWN_NORETRY = 0x1
2119)
2120
2121// Flags used for GetModuleHandleEx
2122const (
2123	GET_MODULE_HANDLE_EX_FLAG_PIN                = 1
2124	GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT = 2
2125	GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS       = 4
2126)
2127
2128// MUI function flag values
2129const (
2130	MUI_LANGUAGE_ID                    = 0x4
2131	MUI_LANGUAGE_NAME                  = 0x8
2132	MUI_MERGE_SYSTEM_FALLBACK          = 0x10
2133	MUI_MERGE_USER_FALLBACK            = 0x20
2134	MUI_UI_FALLBACK                    = MUI_MERGE_SYSTEM_FALLBACK | MUI_MERGE_USER_FALLBACK
2135	MUI_THREAD_LANGUAGES               = 0x40
2136	MUI_CONSOLE_FILTER                 = 0x100
2137	MUI_COMPLEX_SCRIPT_FILTER          = 0x200
2138	MUI_RESET_FILTERS                  = 0x001
2139	MUI_USER_PREFERRED_UI_LANGUAGES    = 0x10
2140	MUI_USE_INSTALLED_LANGUAGES        = 0x20
2141	MUI_USE_SEARCH_ALL_LANGUAGES       = 0x40
2142	MUI_LANG_NEUTRAL_PE_FILE           = 0x100
2143	MUI_NON_LANG_NEUTRAL_FILE          = 0x200
2144	MUI_MACHINE_LANGUAGE_SETTINGS      = 0x400
2145	MUI_FILETYPE_NOT_LANGUAGE_NEUTRAL  = 0x001
2146	MUI_FILETYPE_LANGUAGE_NEUTRAL_MAIN = 0x002
2147	MUI_FILETYPE_LANGUAGE_NEUTRAL_MUI  = 0x004
2148	MUI_QUERY_TYPE                     = 0x001
2149	MUI_QUERY_CHECKSUM                 = 0x002
2150	MUI_QUERY_LANGUAGE_NAME            = 0x004
2151	MUI_QUERY_RESOURCE_TYPES           = 0x008
2152	MUI_FILEINFO_VERSION               = 0x001
2153
2154	MUI_FULL_LANGUAGE      = 0x01
2155	MUI_PARTIAL_LANGUAGE   = 0x02
2156	MUI_LIP_LANGUAGE       = 0x04
2157	MUI_LANGUAGE_INSTALLED = 0x20
2158	MUI_LANGUAGE_LICENSED  = 0x40
2159)
2160
2161// FILE_INFO_BY_HANDLE_CLASS constants for SetFileInformationByHandle/GetFileInformationByHandleEx
2162const (
2163	FileBasicInfo                  = 0
2164	FileStandardInfo               = 1
2165	FileNameInfo                   = 2
2166	FileRenameInfo                 = 3
2167	FileDispositionInfo            = 4
2168	FileAllocationInfo             = 5
2169	FileEndOfFileInfo              = 6
2170	FileStreamInfo                 = 7
2171	FileCompressionInfo            = 8
2172	FileAttributeTagInfo           = 9
2173	FileIdBothDirectoryInfo        = 10
2174	FileIdBothDirectoryRestartInfo = 11
2175	FileIoPriorityHintInfo         = 12
2176	FileRemoteProtocolInfo         = 13
2177	FileFullDirectoryInfo          = 14
2178	FileFullDirectoryRestartInfo   = 15
2179	FileStorageInfo                = 16
2180	FileAlignmentInfo              = 17
2181	FileIdInfo                     = 18
2182	FileIdExtdDirectoryInfo        = 19
2183	FileIdExtdDirectoryRestartInfo = 20
2184	FileDispositionInfoEx          = 21
2185	FileRenameInfoEx               = 22
2186	FileCaseSensitiveInfo          = 23
2187	FileNormalizedNameInfo         = 24
2188)
2189
2190// LoadLibrary flags for determining from where to search for a DLL
2191const (
2192	DONT_RESOLVE_DLL_REFERENCES               = 0x1
2193	LOAD_LIBRARY_AS_DATAFILE                  = 0x2
2194	LOAD_WITH_ALTERED_SEARCH_PATH             = 0x8
2195	LOAD_IGNORE_CODE_AUTHZ_LEVEL              = 0x10
2196	LOAD_LIBRARY_AS_IMAGE_RESOURCE            = 0x20
2197	LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE        = 0x40
2198	LOAD_LIBRARY_REQUIRE_SIGNED_TARGET        = 0x80
2199	LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR          = 0x100
2200	LOAD_LIBRARY_SEARCH_APPLICATION_DIR       = 0x200
2201	LOAD_LIBRARY_SEARCH_USER_DIRS             = 0x400
2202	LOAD_LIBRARY_SEARCH_SYSTEM32              = 0x800
2203	LOAD_LIBRARY_SEARCH_DEFAULT_DIRS          = 0x1000
2204	LOAD_LIBRARY_SAFE_CURRENT_DIRS            = 0x00002000
2205	LOAD_LIBRARY_SEARCH_SYSTEM32_NO_FORWARDER = 0x00004000
2206	LOAD_LIBRARY_OS_INTEGRITY_CONTINUITY      = 0x00008000
2207)
2208
2209// RegNotifyChangeKeyValue notifyFilter flags.
2210const (
2211	// REG_NOTIFY_CHANGE_NAME notifies the caller if a subkey is added or deleted.
2212	REG_NOTIFY_CHANGE_NAME = 0x00000001
2213
2214	// REG_NOTIFY_CHANGE_ATTRIBUTES notifies the caller of changes to the attributes of the key, such as the security descriptor information.
2215	REG_NOTIFY_CHANGE_ATTRIBUTES = 0x00000002
2216
2217	// REG_NOTIFY_CHANGE_LAST_SET notifies the caller of changes to a value of the key. This can include adding or deleting a value, or changing an existing value.
2218	REG_NOTIFY_CHANGE_LAST_SET = 0x00000004
2219
2220	// REG_NOTIFY_CHANGE_SECURITY notifies the caller of changes to the security descriptor of the key.
2221	REG_NOTIFY_CHANGE_SECURITY = 0x00000008
2222
2223	// REG_NOTIFY_THREAD_AGNOSTIC indicates that the lifetime of the registration must not be tied to the lifetime of the thread issuing the RegNotifyChangeKeyValue call. Note: This flag value is only supported in Windows 8 and later.
2224	REG_NOTIFY_THREAD_AGNOSTIC = 0x10000000
2225)
2226