1 /* Copyright (c) 2007 Timothy Wall, All Rights Reserved
2  *
3  * The contents of this file is dual-licensed under 2
4  * alternative Open Source/Free licenses: LGPL 2.1 or later and
5  * Apache License 2.0. (starting with JNA version 4.0.0).
6  *
7  * You can freely decide which license you want to apply to
8  * the project.
9  *
10  * You may obtain a copy of the LGPL License at:
11  *
12  * http://www.gnu.org/licenses/licenses.html
13  *
14  * A copy is also included in the downloadable source code package
15  * containing JNA, in file "LGPL2.1".
16  *
17  * You may obtain a copy of the Apache License at:
18  *
19  * http://www.apache.org/licenses/
20  *
21  * A copy is also included in the downloadable source code package
22  * containing JNA, in file "AL2.0".
23  */
24 package com.sun.jna.platform.win32;
25 
26 import com.sun.jna.FromNativeContext;
27 import com.sun.jna.IntegerType;
28 import com.sun.jna.Memory;
29 import com.sun.jna.Native;
30 import com.sun.jna.NativeLong;
31 import com.sun.jna.Pointer;
32 import com.sun.jna.PointerType;
33 import com.sun.jna.Structure;
34 import com.sun.jna.Structure.FieldOrder;
35 import com.sun.jna.platform.win32.WinNT.PSID;
36 import com.sun.jna.Union;
37 import com.sun.jna.ptr.ByReference;
38 import com.sun.jna.win32.StdCallLibrary.StdCallCallback;
39 
40 /**
41  * This module defines the 32-Bit Windows types and constants that are defined
42  * by NT, but exposed through the Win32 API. Ported from WinNT.h Microsoft
43  * Windows SDK 6.0A. Avoid including any NIO Buffer mappings here; put them in a
44  * DLL-derived interface (e.g. kernel32, user32, etc) instead.
45  *
46  * @author dblock[at]dblock.org
47  */
48 @SuppressWarnings("serial")
49 public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {
50 
51     int MINCHAR     = 0x80;
52     int MAXCHAR     = 0x7f;
53     int MINSHORT    = 0x8000;
54     int MAXSHORT    = 0x7fff;
55     int MINLONG     = 0x80000000;
56     int MAXLONG     = 0x7fffffff;
57     int MAXBYTE     = 0xff;
58     int MAXWORD     = 0xffff;
59     int MAXDWORD    = 0xffffffff;
60     //
61     // The following are masks for the predefined standard access types
62     //
63 
64     int DELETE = 0x00010000;
65     int READ_CONTROL = 0x00020000;
66     int WRITE_DAC = 0x00040000;
67     int WRITE_OWNER = 0x00080000;
68     int SYNCHRONIZE = 0x00100000;
69 
70     int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
71     int STANDARD_RIGHTS_READ = READ_CONTROL;
72     int STANDARD_RIGHTS_WRITE = READ_CONTROL;
73     int STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
74     int STANDARD_RIGHTS_ALL = 0x001F0000;
75 
76     int SPECIFIC_RIGHTS_ALL = 0x0000FFFF;
77 
78     int MUTANT_QUERY_STATE = 0x0001;
79     int MUTANT_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE
80             | MUTANT_QUERY_STATE;
81 
82     //
83     // Token Specific Access Rights.
84     //
85 
86     /**
87      * Required to attach a primary token to a process. The
88      * SE_ASSIGNPRIMARYTOKEN_NAME privilege is also required to accomplish this
89      * task.
90      */
91     int TOKEN_ASSIGN_PRIMARY = 0x0001;
92 
93     /**
94      * Required to duplicate an access token.
95      */
96     int TOKEN_DUPLICATE = 0x0002;
97 
98     /**
99      * Required to attach an impersonation access token to a process.
100      */
101     int TOKEN_IMPERSONATE = 0x0004;
102 
103     /**
104      * Required to query an access token.
105      */
106     int TOKEN_QUERY = 0x0008;
107 
108     /**
109      * Required to query the source of an access token.
110      */
111     int TOKEN_QUERY_SOURCE = 0x0010;
112 
113     /**
114      * Required to enable or disable the privileges in an access token.
115      */
116     int TOKEN_ADJUST_PRIVILEGES = 0x0020;
117 
118     /**
119      * Required to adjust the attributes of the groups in an access token.
120      */
121     int TOKEN_ADJUST_GROUPS = 0x0040;
122 
123     /**
124      * Required to change the default owner, primary group, or DACL of an access
125      * token.
126      */
127     int TOKEN_ADJUST_DEFAULT = 0x0080;
128 
129     /**
130      * Required to adjust the session ID of an access token. The SE_TCB_NAME
131      * privilege is required.
132      */
133     int TOKEN_ADJUST_SESSIONID = 0x0100;
134 
135     int TOKEN_ALL_ACCESS_P = STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY
136             | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY
137             | TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES
138             | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT;
139 
140     /**
141      * Combines all possible access rights for a token.
142      */
143     int TOKEN_ALL_ACCESS = TOKEN_ALL_ACCESS_P | TOKEN_ADJUST_SESSIONID;
144 
145     /**
146      * Combines STANDARD_RIGHTS_READ and TOKEN_QUERY.
147      */
148     int TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY;
149 
150     /**
151      * Combines STANDARD_RIGHTS_WRITE, TOKEN_ADJUST_PRIVILEGES,
152      * TOKEN_ADJUST_GROUPS, and TOKEN_ADJUST_DEFAULT.
153      */
154     int TOKEN_WRITE = STANDARD_RIGHTS_WRITE | TOKEN_ADJUST_PRIVILEGES
155             | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT;
156 
157     /**
158      * Combines STANDARD_RIGHTS_EXECUTE and TOKEN_IMPERSONATE.
159      */
160     int TOKEN_EXECUTE = STANDARD_RIGHTS_EXECUTE;
161 
162     int THREAD_TERMINATE = 0x0001;
163     int THREAD_SUSPEND_RESUME = 0x0002;
164     int THREAD_GET_CONTEXT = 0x0008;
165     int THREAD_SET_CONTEXT = 0x0010;
166     int THREAD_QUERY_INFORMATION = 0x0040;
167     int THREAD_SET_INFORMATION = 0x0020;
168     int THREAD_SET_THREAD_TOKEN = 0x0080;
169     int THREAD_IMPERSONATE = 0x0100;
170     int THREAD_DIRECT_IMPERSONATION = 0x0200;
171     int THREAD_SET_LIMITED_INFORMATION = 0x0400;
172     int THREAD_QUERY_LIMITED_INFORMATION = 0x0800;
173     int THREAD_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3FF;
174 
175     /**
176      * Flag identifying hyperthreading / simultaneous multithreading (SMT)
177      */
178     int LTP_PC_SMT = 0x1;
179 
180     /**
181      * The SECURITY_IMPERSONATION_LEVEL enumeration type contains values that
182      * specify security impersonation levels. Security impersonation levels
183      * govern the degree to which a server process can act on behalf of a client
184      * process.
185      */
186     public abstract class SECURITY_IMPERSONATION_LEVEL {
187         /**
188          * The server process cannot obtain identification information about the
189          * client, and it cannot impersonate the client. It is defined with no
190          * value given, and thus, by ANSI C rules, defaults to a value of zero.
191          */
192         public static final int SecurityAnonymous = 0;
193 
194         /**
195          * The server process can obtain information about the client, such as
196          * security identifiers and privileges, but it cannot impersonate the
197          * client. This is useful for servers that export their own objects, for
198          * example, database products that export tables and views. Using the
199          * retrieved client-security information, the server can make
200          * access-validation decisions without being able to use other services
201          * that are using the client's security context.
202          */
203         public static final int SecurityIdentification = 1;
204 
205         /**
206          * The server process can impersonate the client's security context on
207          * its local system. The server cannot impersonate the client on remote
208          * systems.
209          */
210         public static final int SecurityImpersonation = 2;
211 
212         /**
213          * The server process can impersonate the client's security context on
214          * remote systems.
215          */
216         public static final int SecurityDelegation = 3;
217     }
218 
219     /**
220      * The TOKEN_INFORMATION_CLASS enumeration type contains values that specify
221      * the type of information being assigned to or retrieved from an access
222      * token.
223      */
224     public abstract class TOKEN_INFORMATION_CLASS {
225         public static final int TokenUser = 1;
226         public static final int TokenGroups = 2;
227         public static final int TokenPrivileges = 3;
228         public static final int TokenOwner = 4;
229         public static final int TokenPrimaryGroup = 5;
230         public static final int TokenDefaultDacl = 6;
231         public static final int TokenSource = 7;
232         public static final int TokenType = 8;
233         public static final int TokenImpersonationLevel = 9;
234         public static final int TokenStatistics = 10;
235         public static final int TokenRestrictedSids = 11;
236         public static final int TokenSessionId = 12;
237         public static final int TokenGroupsAndPrivileges = 13;
238         public static final int TokenSessionReference = 14;
239         public static final int TokenSandBoxInert = 15;
240         public static final int TokenAuditPolicy = 16;
241         public static final int TokenOrigin = 17;
242         public static final int TokenElevationType = 18;
243         public static final int TokenLinkedToken = 19;
244         public static final int TokenElevation = 20;
245         public static final int TokenHasRestrictions = 21;
246         public static final int TokenAccessInformation = 22;
247         public static final int TokenVirtualizationAllowed = 23;
248         public static final int TokenVirtualizationEnabled = 24;
249         public static final int TokenIntegrityLevel = 25;
250         public static final int TokenUIAccess = 26;
251         public static final int TokenMandatoryPolicy = 27;
252         public static final int TokenLogonSid = 28;
253     }
254 
255     /**
256      * The TOKEN_TYPE enumeration type contains values that differentiate
257      * between a primary token and an impersonation token.
258      */
259     public abstract class TOKEN_TYPE {
260         public static final int TokenPrimary = 1;
261         public static final int TokenImpersonation = 2;
262     }
263 
264     /**
265      * The LUID_AND_ATTRIBUTES structure represents a locally unique identifier
266      * (LUID) and its attributes.
267      */
268     @FieldOrder({"Luid", "Attributes"})
269     public static class LUID_AND_ATTRIBUTES extends Structure {
270         /**
271          * Specifies an LUID value.
272          */
273         public LUID Luid;
274 
275         /**
276          * Specifies attributes of the LUID. This value contains up to 32
277          * one-bit flags. Its meaning is dependent on the definition and use of
278          * the LUID.
279          */
280         public DWORD Attributes;
281 
LUID_AND_ATTRIBUTES()282         public LUID_AND_ATTRIBUTES() {
283             super();
284         }
285 
LUID_AND_ATTRIBUTES(LUID luid, DWORD attributes)286         public LUID_AND_ATTRIBUTES(LUID luid, DWORD attributes) {
287             this.Luid = luid;
288             this.Attributes = attributes;
289         }
290     }
291 
292     /**
293      * The SID_AND_ATTRIBUTES structure represents a security identifier (SID)
294      * and its attributes. SIDs are used to uniquely identify users or groups.
295      */
296     @FieldOrder({"Sid", "Attributes"})
297     public static class SID_AND_ATTRIBUTES extends Structure {
298         /**
299          * Pointer to a SID structure.
300          */
301         public PSID.ByReference Sid;
302 
303         /**
304          * Specifies attributes of the SID. This value contains up to 32 one-bit
305          * flags. Its meaning depends on the definition and use of the SID.
306          */
307         public int Attributes;
308 
SID_AND_ATTRIBUTES()309         public SID_AND_ATTRIBUTES() {
310             super();
311         }
312 
SID_AND_ATTRIBUTES(Pointer memory)313         public SID_AND_ATTRIBUTES(Pointer memory) {
314             super(memory);
315         }
316     }
317 
318     /**
319      * The TOKEN_OWNER structure contains the default owner security identifier
320      * (SID) that will be applied to newly created objects.
321      */
322     @FieldOrder({"Owner"})
323     public static class TOKEN_OWNER extends Structure {
324         /**
325          * Pointer to a SID structure representing a user who will become the
326          * owner of any objects created by a process using this access token.
327          * The SID must be one of the user or group SIDs already in the token.
328          */
329         public PSID.ByReference Owner; // PSID
330 
TOKEN_OWNER()331         public TOKEN_OWNER() {
332             super();
333         }
334 
TOKEN_OWNER(int size)335         public TOKEN_OWNER(int size) {
336             super(new Memory(size));
337         }
338 
TOKEN_OWNER(Pointer memory)339         public TOKEN_OWNER(Pointer memory) {
340             super(memory);
341             read();
342         }
343     }
344 
345     @FieldOrder({"sid"})
346     public static class PSID extends Structure {
347         public static class ByReference extends PSID implements Structure.ByReference { }
348         public Pointer sid;
349 
PSID()350         public PSID() {
351             super();
352         }
353 
PSID(byte[] data)354         public PSID(byte[] data) {
355             super(new Memory(data.length));
356             getPointer().write(0, data, 0, data.length);
357             read();
358         }
359 
PSID(int size)360         public PSID(int size) {
361             super(new Memory(size));
362         }
363 
PSID(Pointer memory)364         public PSID(Pointer memory) {
365             super(memory);
366             read();
367         }
368 
getBytes()369         public byte[] getBytes() {
370             int len = Advapi32.INSTANCE.GetLengthSid(this);
371             return getPointer().getByteArray(0, len);
372         }
373 
getSidString()374         public String getSidString() {
375             return Advapi32Util.convertSidToStringSid(this);
376         }
377     }
378 
379     public static class PSIDByReference extends ByReference {
PSIDByReference()380         public PSIDByReference() {
381             this(null);
382         }
383 
PSIDByReference(PSID h)384         public PSIDByReference(PSID h) {
385             super(Native.POINTER_SIZE);
386             setValue(h);
387         }
388 
setValue(PSID h)389         public void setValue(PSID h) {
390             getPointer().setPointer(0, h != null ? h.getPointer() : null);
391         }
392 
getValue()393         public PSID getValue() {
394             Pointer p = getPointer().getPointer(0);
395             if (p == null) {
396                 return null;
397             }
398             else {
399                 return new PSID(p);
400             }
401         }
402     }
403 
404     /**
405      * The TOKEN_USER structure identifies the user associated with an access
406      * token.
407      */
408     @FieldOrder({"User"})
409     public static class TOKEN_USER extends Structure {
410         /**
411          * Specifies a SID_AND_ATTRIBUTES structure representing the user
412          * associated with the access token. There are currently no attributes
413          * defined for user security identifiers (SIDs).
414          */
415         public SID_AND_ATTRIBUTES User;
416 
TOKEN_USER()417         public TOKEN_USER() {
418             super();
419         }
420 
TOKEN_USER(Pointer memory)421         public TOKEN_USER(Pointer memory) {
422             super(memory);
423             read();
424         }
425 
TOKEN_USER(int size)426         public TOKEN_USER(int size) {
427             super(new Memory(size));
428         }
429     }
430 
431     /**
432      * The TOKEN_PRIMARY_GROUP structure specifies a group security identifier (SID)
433      * for an access token.
434      */
435     @FieldOrder({ "PrimaryGroup" })
436     public static class TOKEN_PRIMARY_GROUP extends Structure {
437         /**
438          * A pointer to a SID structure representing a group that will become the
439          * primary group of any objects created by a process using this access token.
440          * The SID must be one of the group SIDs already in the token.
441          */
442         public PSID.ByReference PrimaryGroup;
443 
TOKEN_PRIMARY_GROUP()444         public TOKEN_PRIMARY_GROUP() {
445             super();
446         }
447 
TOKEN_PRIMARY_GROUP(Pointer memory)448         public TOKEN_PRIMARY_GROUP(Pointer memory) {
449             super(memory);
450             read();
451         }
452 
TOKEN_PRIMARY_GROUP(int size)453         public TOKEN_PRIMARY_GROUP(int size) {
454             super(new Memory(size));
455         }
456     }
457 
458     /**
459      * The TOKEN_GROUPS structure contains information about the group security
460      * identifiers (SIDs) in an access token.
461      */
462     @FieldOrder({"GroupCount", "Group0"})
463     public static class TOKEN_GROUPS extends Structure {
464         /**
465          * Specifies the number of groups in the access token.
466          */
467         public int GroupCount;
468         public SID_AND_ATTRIBUTES Group0;
469 
TOKEN_GROUPS()470         public TOKEN_GROUPS() {
471             super();
472         }
473 
TOKEN_GROUPS(Pointer memory)474         public TOKEN_GROUPS(Pointer memory) {
475             super(memory);
476             read();
477         }
478 
TOKEN_GROUPS(int size)479         public TOKEN_GROUPS(int size) {
480             super(new Memory(size));
481         }
482 
483         /**
484          * Specifies an array of SID_AND_ATTRIBUTES structures that contain a
485          * set of SIDs and corresponding attributes.
486          * @return attributes
487          */
getGroups()488         public SID_AND_ATTRIBUTES[] getGroups() {
489             return (SID_AND_ATTRIBUTES[]) Group0.toArray(GroupCount);
490         }
491     }
492 
493     /**
494      * Specifies a set of privileges. <br>
495      * It is also used to indicate which, if any, privileges are held by a user or group requesting access to an object.
496      */
497     @FieldOrder({"PrivilegeCount", "Control", "Privileges"})
498     public static class PRIVILEGE_SET extends Structure {
499         public DWORD PrivilegeCount;
500         public DWORD Control;
501         public LUID_AND_ATTRIBUTES Privileges[];
502 
PRIVILEGE_SET()503         public PRIVILEGE_SET() {
504             this(0);
505         }
506         /**
507          * @param nbOfPrivileges
508          *            Desired size of the Privileges array
509          */
PRIVILEGE_SET(int nbOfPrivileges)510         public PRIVILEGE_SET(int nbOfPrivileges) {
511             PrivilegeCount = new DWORD(nbOfPrivileges);
512             if(nbOfPrivileges > 0) {
513                 Privileges = new LUID_AND_ATTRIBUTES[nbOfPrivileges];
514             }
515         }
516 
517         /** Initialize a TOKEN_PRIVILEGES instance from initialized memory.
518          * @param p base address
519          */
PRIVILEGE_SET(Pointer p)520         public PRIVILEGE_SET(Pointer p) {
521             super(p);
522             final int count = p.getInt(0);
523             PrivilegeCount = new DWORD(count);
524             if(count > 0) {
525                 Privileges = new LUID_AND_ATTRIBUTES[count];
526             }
527             read();
528         }
529     }
530 
531     /**
532      * The TOKEN_PRIVILEGES structure contains information about a set of
533      * privileges for an access token.
534      */
535     @FieldOrder({"PrivilegeCount", "Privileges"})
536     public static class TOKEN_PRIVILEGES extends Structure {
537         /**
538          * This must be set to the number of entries in the Privileges array.
539          */
540         public DWORD PrivilegeCount;
541 
542         /**
543          * Specifies an array of LUID_AND_ATTRIBUTES structures. Each structure
544          * contains the LUID and attributes of a privilege.
545          */
546         public LUID_AND_ATTRIBUTES Privileges[];
547 
548         /** Creates an empty instance with no privileges. */
TOKEN_PRIVILEGES()549         public TOKEN_PRIVILEGES() {
550             this(0);
551         }
552         /**
553          * @param nbOfPrivileges
554          *            Desired size of the Privileges array
555          */
TOKEN_PRIVILEGES(int nbOfPrivileges)556         public TOKEN_PRIVILEGES(int nbOfPrivileges) {
557             PrivilegeCount = new DWORD(nbOfPrivileges);
558             Privileges = new LUID_AND_ATTRIBUTES[nbOfPrivileges];
559         }
560 
561         /** Initialize a TOKEN_PRIVILEGES instance from initialized memory.
562          * @param p base address
563          */
TOKEN_PRIVILEGES(Pointer p)564         public TOKEN_PRIVILEGES(Pointer p) {
565             super(p);
566             int count = p.getInt(0);
567             PrivilegeCount = new DWORD(count);
568             Privileges = new LUID_AND_ATTRIBUTES[count];
569             read();
570         }
571     }
572 
573     /**
574      * The SID_NAME_USE enumeration type contains values that specify the type
575      * of a security identifier (SID).
576      */
577     public abstract class SID_NAME_USE {
578         /**
579          * Indicates a user SID.
580          */
581         public static final int SidTypeUser = 1;
582 
583         /**
584          * Indicates a group SID.
585          */
586         public static final int SidTypeGroup = 2;
587 
588         /**
589          * Indicates a domain SID.
590          */
591         public static final int SidTypeDomain = 3;
592 
593         /**
594          * Indicates an alias SID.
595          */
596         public static final int SidTypeAlias = 4;
597 
598         /**
599          * Indicates a SID for a well-known group.
600          */
601         public static final int SidTypeWellKnownGroup = 5;
602 
603         /**
604          * Indicates a SID for a deleted account.
605          */
606         public static final int SidTypeDeletedAccount = 6;
607 
608         /**
609          * Indicates an invalid SID.
610          */
611         public static final int SidTypeInvalid = 7;
612 
613         /**
614          * Indicates an unknown SID type.
615          */
616         public static final int SidTypeUnknown = 8;
617 
618         /**
619          * Indicates a SID for a computer.
620          */
621         public static final int SidTypeComputer = 9;
622 
623         /**
624          * ?
625          */
626         public static final int SidTypeLabel = 10;
627     }
628 
629     /* File access rights */
630     int FILE_READ_DATA = 0x00000001;
631     int FILE_LIST_DIRECTORY = 0x00000001;
632     int FILE_WRITE_DATA = 0x00000002;
633     int FILE_ADD_FILE = 0x00000002;
634     int FILE_APPEND_DATA = 0x00000004;
635     int FILE_ADD_SUBDIRECTORY = 0x00000004;
636     int FILE_CREATE_PIPE_INSTANCE = 0x00000004;
637     int FILE_READ_EA = 0x00000008;
638     int FILE_WRITE_EA = 0x00000010;
639     int FILE_EXECUTE = 0x00000020;
640     int FILE_TRAVERSE = 0x00000020;
641     int FILE_DELETE_CHILD = 0x00000040;
642     int FILE_READ_ATTRIBUTES = 0x00000080;
643     int FILE_WRITE_ATTRIBUTES = 0x00000100;
644 
645     int FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x000001FF;
646 
647     int FILE_GENERIC_READ = STANDARD_RIGHTS_READ | SYNCHRONIZE | FILE_READ_DATA
648             | FILE_READ_ATTRIBUTES | FILE_READ_EA;
649 
650     int FILE_GENERIC_WRITE = STANDARD_RIGHTS_WRITE | SYNCHRONIZE
651             | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA
652             | FILE_APPEND_DATA;
653 
654     int FILE_GENERIC_EXECUTE = STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE
655             | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
656 
657     int CREATE_NEW = 1;
658     int CREATE_ALWAYS = 2;
659     int OPEN_EXISTING = 3;
660     int OPEN_ALWAYS = 4;
661     int TRUNCATE_EXISTING = 5;
662 
663     int FILE_FLAG_WRITE_THROUGH = 0x80000000;
664     int FILE_FLAG_OVERLAPPED = 0x40000000;
665     int FILE_FLAG_NO_BUFFERING = 0x20000000;
666     int FILE_FLAG_RANDOM_ACCESS = 0x10000000;
667     int FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
668     int FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
669     int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
670     int FILE_FLAG_POSIX_SEMANTICS = 0x01000000;
671     int FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000;
672     int FILE_FLAG_OPEN_NO_RECALL = 0x00100000;
673 
674     //
675     // These are the generic rights.
676     //
677 
678     int GENERIC_READ = 0x80000000;
679     int GENERIC_WRITE = 0x40000000;
680     int GENERIC_EXECUTE = 0x20000000;
681     int GENERIC_ALL = 0x10000000;
682 
683     //
684     // AccessSystemAcl access type
685     //
686 
687     int ACCESS_SYSTEM_SECURITY             = 0x01000000;
688 
689     /**
690      * Pages in the region become guard pages. <br>
691      * Any attempt to access a guard page causes the system to raise a
692      * STATUS_GUARD_PAGE_VIOLATION exception and turn off the guard page status.
693      * <br>
694      * Guard pages thus act as a one-time access alarm. <br>
695      * For more information, see Creating Guard Pages. <br>
696      * When an access attempt leads the system to turn off guard page status,
697      * the underlying page protection takes over.<br>
698      * If a guard page exception occurs during a system service, the service
699      * typically returns a failure status indicator. <br>
700      * This value cannot be used with PAGE_NOACCESS. This flag is not supported
701      * by the CreateFileMapping function.
702      *
703      * @see <a href=
704      *      "https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx">
705      *      MSDN</a>
706      */
707     int PAGE_GUARD                         = 0x100;
708 
709     /**
710      * Disables all access to the committed region of pages.<br>
711      * An attempt to read from, write to, or execute the committed region
712      * results in an access violation.<br>
713      * This flag is not supported by the CreateFileMapping function.
714      *
715      * @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx">MSDN</a>
716      */
717     int PAGE_NOACCESS                      = 0x01;
718 
719     /**
720      * Enables read-only access to the committed region of pages.<br>
721      * An attempt to write to the committed region results in an access
722      * violation. <br>
723      * If Data Execution Prevention is enabled, an attempt to execute code in
724      * the committed region results in an access violation.
725      *
726      * @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx">MSDN</a>
727      */
728     int PAGE_READONLY                      = 0x02;
729 
730     /**
731      * Enables read-only or read/write access to the committed region of pages. <br>
732      * If Data Execution Prevention is enabled, attempting to execute code in
733      * the committed region results in an access violation.
734      *
735      * @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx">MSDN</a>
736      */
737     int PAGE_READWRITE                     = 0x04;
738 
739     /**
740      * Enables read-only or copy-on-write access to a mapped view of a file
741      * mapping object. An attempt to write to a committed copy-on-write page
742      * results in a private copy of the page being made for the process. The
743      * private page is marked as PAGE_READWRITE, and the change is written to
744      * the new page. If Data Execution Prevention is enabled, attempting to
745      * execute code in the committed region results in an access violation.
746      *
747      * @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx"> MSDN</a>
748      */
749     int PAGE_WRITECOPY = 0x08;
750 
751     /**
752      * Enables execute access to the committed region of pages. An attempt to
753      * write to the committed region results in an access violation. This flag
754      * is not supported by the CreateFileMapping function.
755      *
756      * @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx">MSDN</a>
757      */
758     int PAGE_EXECUTE                       = 0x10;
759 
760     /**
761      * Enables execute or read-only access to the committed region of pages. An
762      * attempt to write to the committed region results in an access violation.
763      * Windows Server 2003 and Windows XP: This attribute is not supported by
764      * the CreateFileMapping function until Windows XP with SP2 and Windows
765      * Server 2003 with SP1.
766      *
767      * @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx">MSDN</a>
768      */
769     int PAGE_EXECUTE_READ                  = 0x20;
770 
771     /**
772      * Enables execute, read-only, or read/write access to the committed region
773      * of pages. Windows Server 2003 and Windows XP: This attribute is not
774      * supported by the CreateFileMapping function until Windows XP with SP2 and
775      * Windows Server 2003 with SP1.
776      *
777      * @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx">MSDN</a>
778      */
779     int PAGE_EXECUTE_READWRITE             = 0x40;
780 
781     int SECTION_QUERY = 0x0001;
782     int SECTION_MAP_WRITE = 0x0002;
783     int SECTION_MAP_READ = 0x0004;
784     int SECTION_MAP_EXECUTE = 0x0008;
785     int SECTION_EXTEND_SIZE = 0x0010;
786 
787     int FILE_SHARE_READ = 0x00000001;
788     int FILE_SHARE_WRITE = 0x00000002;
789     int FILE_SHARE_DELETE = 0x00000004;
790     int FILE_TYPE_CHAR = 0x0002;
791     int FILE_TYPE_DISK = 0x0001;
792     int FILE_TYPE_PIPE = 0x0003;
793     int FILE_TYPE_REMOTE = 0x8000;
794     int FILE_TYPE_UNKNOWN = 0x0000;
795     int FILE_ATTRIBUTE_READONLY = 0x00000001;
796     int FILE_ATTRIBUTE_HIDDEN = 0x00000002;
797     int FILE_ATTRIBUTE_SYSTEM = 0x00000004;
798     int FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
799     int FILE_ATTRIBUTE_ARCHIVE = 0x00000020;
800     int FILE_ATTRIBUTE_DEVICE = 0x00000040;
801     int FILE_ATTRIBUTE_NORMAL = 0x00000080;
802     int FILE_ATTRIBUTE_TEMPORARY = 0x00000100;
803     int FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200;
804     int FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400;
805     int FILE_ATTRIBUTE_COMPRESSED = 0x00000800;
806     int FILE_ATTRIBUTE_OFFLINE = 0x00001000;
807     int FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000;
808     int FILE_ATTRIBUTE_ENCRYPTED = 0x00004000;
809     int FILE_ATTRIBUTE_VIRTUAL = 0x00010000;
810     int FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001;
811     int FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002;
812     int FILE_NOTIFY_CHANGE_NAME = 0x00000003;
813     int FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004;
814     int FILE_NOTIFY_CHANGE_SIZE = 0x00000008;
815     int FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010;
816     int FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020;
817     int FILE_NOTIFY_CHANGE_CREATION = 0x00000040;
818     int FILE_NOTIFY_CHANGE_SECURITY = 0x00000100;
819     int FILE_ACTION_ADDED = 0x00000001;
820     int FILE_ACTION_REMOVED = 0x00000002;
821     int FILE_ACTION_MODIFIED = 0x00000003;
822     int FILE_ACTION_RENAMED_OLD_NAME = 0x00000004;
823     int FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
824     int FILE_CASE_SENSITIVE_SEARCH = 0x00000001;
825     int FILE_CASE_PRESERVED_NAMES = 0x00000002;
826     int FILE_UNICODE_ON_DISK = 0x00000004;
827     int FILE_PERSISTENT_ACLS = 0x00000008;
828     int FILE_FILE_COMPRESSION = 0x00000010;
829     int FILE_VOLUME_QUOTAS = 0x00000020;
830     int FILE_SUPPORTS_SPARSE_FILES = 0x00000040;
831     int FILE_SUPPORTS_REPARSE_POINTS = 0x00000080;
832     int FILE_SUPPORTS_REMOTE_STORAGE = 0x00000100;
833     int FILE_VOLUME_IS_COMPRESSED = 0x00008000;
834     int FILE_SUPPORTS_OBJECT_IDS = 0x00010000;
835     int FILE_SUPPORTS_ENCRYPTION = 0x00020000;
836     int FILE_NAMED_STREAMS = 0x00040000;
837     int FILE_READ_ONLY_VOLUME = 0x00080000;
838     int FILE_SEQUENTIAL_WRITE_ONCE = 0x00100000;
839     int FILE_SUPPORTS_TRANSACTIONS = 0x00200000;
840     // NOTE: These values are not supported until Windows Server 2008 R2 and Windows 7
841     int FILE_SUPPORTS_HARD_LINKS = 0x00400000;
842     int FILE_SUPPORTS_EXTENDED_ATTRIBUTES = 0x00800000;
843     int FILE_SUPPORTS_OPEN_BY_FILE_ID = 0x01000000;
844     int FILE_SUPPORTS_USN_JOURNAL = 0x02000000;
845 
846     // Reparse point tags
847     int IO_REPARSE_TAG_MOUNT_POINT              = 0xA0000003;
848     int IO_REPARSE_TAG_HSM                      = 0xC0000004;
849     int IO_REPARSE_TAG_HSM2                     = 0x80000006;
850     int IO_REPARSE_TAG_SIS                      = 0x80000007;
851     int IO_REPARSE_TAG_WIM                      = 0x80000008;
852     int IO_REPARSE_TAG_CSV                      = 0x80000009;
853     int IO_REPARSE_TAG_DFS                      = 0x8000000A;
854     int IO_REPARSE_TAG_SYMLINK                  = 0xA000000C;
855     int IO_REPARSE_TAG_DFSR                     = 0x80000012;
856 
857     // The controllable aspects of the DefineDosDevice function.
858     // see https://msdn.microsoft.com/en-us/library/windows/desktop/aa363904(v=vs.85).aspx
859     int DDD_RAW_TARGET_PATH = 0x00000001;
860     int DDD_REMOVE_DEFINITION = 0x00000002;
861     int DDD_EXACT_MATCH_ON_REMOVE = 0x00000004;
862     int DDD_NO_BROADCAST_SYSTEM = 0x00000008;
863 
864     int COMPRESSION_FORMAT_NONE          = 0x0000;
865     int COMPRESSION_FORMAT_DEFAULT       = 0x0001;
866     int COMPRESSION_FORMAT_LZNT1         = 0x0002;
867     int COMPRESSION_FORMAT_XPRESS        = 0x0003;
868     int COMPRESSION_FORMAT_XPRESS_HUFF   = 0x0004;
869     int COMPRESSION_ENGINE_STANDARD      = 0x0000;
870     int COMPRESSION_ENGINE_MAXIMUM       = 0x0100;
871     int COMPRESSION_ENGINE_HIBER         = 0x0200;
872 
873     /**
874      * The FILE_NOTIFY_INFORMATION structure describes the changes found by the
875      * ReadDirectoryChangesW function.
876      *
877      * This structure is non-trivial since it is a pattern stamped into a large
878      * block of result memory rather than something that stands alone or is used
879      * for input.
880      */
881     @FieldOrder({"NextEntryOffset", "Action", "FileNameLength", "FileName"})
882     public static class FILE_NOTIFY_INFORMATION extends Structure {
883         public int NextEntryOffset;
884         public int Action;
885         public int FileNameLength;
886         // filename is not nul-terminated, so we can't use a String/WString
887         public char[] FileName = new char[1];
888 
FILE_NOTIFY_INFORMATION()889         private FILE_NOTIFY_INFORMATION() {
890             super();
891         }
892 
FILE_NOTIFY_INFORMATION(int size)893         public FILE_NOTIFY_INFORMATION(int size) {
894             if (size < size()) {
895                 throw new IllegalArgumentException("Size must greater than "
896                         + size() + ", requested " + size);
897             }
898             allocateMemory(size);
899         }
900 
901         /**
902          * WARNING: this filename may be either the short or long form of the
903          * filename.
904          * @return filename
905          */
getFilename()906         public String getFilename() {
907             return new String(FileName, 0, FileNameLength / 2);
908         }
909 
910         @Override
read()911         public void read() {
912             // avoid reading filename until we know how long it is
913             FileName = new char[0];
914             super.read();
915             FileName = getPointer().getCharArray(12, FileNameLength / 2);
916         }
917 
next()918         public FILE_NOTIFY_INFORMATION next() {
919             if (NextEntryOffset == 0) {
920                 return null;
921             }
922             FILE_NOTIFY_INFORMATION next = new FILE_NOTIFY_INFORMATION();
923             next.useMemory(getPointer(), NextEntryOffset);
924             next.read();
925             return next;
926         }
927     }
928 
929     /**
930      * Registry options.
931      */
932     int KEY_QUERY_VALUE = 0x0001;
933     int KEY_SET_VALUE = 0x0002;
934     int KEY_CREATE_SUB_KEY = 0x0004;
935     int KEY_ENUMERATE_SUB_KEYS = 0x0008;
936     int KEY_NOTIFY = 0x0010;
937     int KEY_CREATE_LINK = 0x0020;
938     int KEY_WOW64_32KEY = 0x0200;
939     int KEY_WOW64_64KEY = 0x0100;
940     int KEY_WOW64_RES = 0x0300;
941 
942     int KEY_READ = STANDARD_RIGHTS_READ | KEY_QUERY_VALUE
943             | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY & (~SYNCHRONIZE);
944 
945     int KEY_WRITE = STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY
946             & (~SYNCHRONIZE);
947 
948     int KEY_EXECUTE = KEY_READ & (~SYNCHRONIZE);
949 
950     int KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE
951             | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
952             | KEY_CREATE_LINK) & (~SYNCHRONIZE));
953 
954     //
955     // Open/Create Options
956     //
957 
958     /**
959      * Parameter is reserved.
960      */
961     int REG_OPTION_RESERVED = 0x00000000;
962 
963     /**
964      * Key is preserved when system is rebooted.
965      */
966     int REG_OPTION_NON_VOLATILE = 0x00000000;
967 
968     /**
969      * Key is not preserved when system is rebooted.
970      */
971     int REG_OPTION_VOLATILE = 0x00000001;
972 
973     /**
974      * Created key is a symbolic link.
975      */
976     int REG_OPTION_CREATE_LINK = 0x00000002;
977 
978     /**
979      * Open for backup or restore special access rules privilege required.
980      */
981     int REG_OPTION_BACKUP_RESTORE = 0x00000004;
982 
983     /**
984      * Open symbolic link.
985      */
986     int REG_OPTION_OPEN_LINK = 0x00000008;
987 
988     int REG_LEGAL_OPTION = REG_OPTION_RESERVED | REG_OPTION_NON_VOLATILE
989             | REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK
990             | REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK;
991 
992     //
993     // Key creation/open disposition
994     //
995 
996     /**
997      * New Registry Key created.
998      */
999     int REG_CREATED_NEW_KEY = 0x00000001;
1000 
1001     /**
1002      * Existing Key opened.
1003      */
1004     int REG_OPENED_EXISTING_KEY = 0x00000002;
1005 
1006     int REG_STANDARD_FORMAT = 1;
1007     int REG_LATEST_FORMAT = 2;
1008     int REG_NO_COMPRESSION = 4;
1009 
1010     //
1011     // Key restore & hive load flags
1012     //
1013 
1014     /**
1015      * Restore whole hive volatile.
1016      */
1017     int REG_WHOLE_HIVE_VOLATILE = 0x00000001;
1018 
1019     /**
1020      * Unwind changes to last flush.
1021      */
1022     int REG_REFRESH_HIVE = 0x00000002;
1023 
1024     /**
1025      * Never lazy flush this hive.
1026      */
1027     int REG_NO_LAZY_FLUSH = 0x00000004;
1028 
1029     /**
1030      * Force the restore process even when we have open handles on subkeys.
1031      */
1032     int REG_FORCE_RESTORE = 0x00000008;
1033 
1034     /**
1035      * Loads the hive visible to the calling process.
1036      */
1037     int REG_APP_HIVE = 0x00000010;
1038 
1039     /**
1040      * Hive cannot be mounted by any other process while in use.
1041      */
1042     int REG_PROCESS_PRIVATE = 0x00000020;
1043 
1044     /**
1045      * Starts Hive Journal.
1046      */
1047     int REG_START_JOURNAL = 0x00000040;
1048 
1049     /**
1050      * Grow hive file in exact 4k increments.
1051      */
1052     int REG_HIVE_EXACT_FILE_GROWTH = 0x00000080;
1053 
1054     /**
1055      * No RM is started for this hive = no transactions.
1056      */
1057     int REG_HIVE_NO_RM = 0x00000100;
1058 
1059     /**
1060      * Legacy single logging is used for this hive.
1061      */
1062     int REG_HIVE_SINGLE_LOG = 0x00000200;
1063 
1064     //
1065     // Unload Flags
1066     //
1067 
1068     int REG_FORCE_UNLOAD = 1;
1069 
1070     //
1071     // Notify filter values
1072     //
1073 
1074     int REG_NOTIFY_CHANGE_NAME = 0x00000001;
1075     int REG_NOTIFY_CHANGE_ATTRIBUTES = 0x00000002;
1076     int REG_NOTIFY_CHANGE_LAST_SET = 0x00000004;
1077     int REG_NOTIFY_CHANGE_SECURITY = 0x00000008;
1078 
1079     int REG_LEGAL_CHANGE_FILTER = REG_NOTIFY_CHANGE_NAME
1080             | REG_NOTIFY_CHANGE_ATTRIBUTES | REG_NOTIFY_CHANGE_LAST_SET
1081             | REG_NOTIFY_CHANGE_SECURITY;
1082 
1083     //
1084     // Predefined Value Types.
1085     //
1086 
1087     /**
1088      * No value type.
1089      */
1090     int REG_NONE = 0;
1091 
1092     /**
1093      * Unicode null-terminated string.
1094      */
1095     int REG_SZ = 1;
1096 
1097     /**
1098      * Unicode null-terminated string with environment variable references.
1099      */
1100     int REG_EXPAND_SZ = 2;
1101 
1102     /**
1103      * Free-formed binary.
1104      */
1105     int REG_BINARY = 3;
1106 
1107     /**
1108      * 32-bit number.
1109      */
1110     int REG_DWORD = 4;
1111 
1112     /**
1113      * 32-bit number, same as REG_DWORD.
1114      */
1115     int REG_DWORD_LITTLE_ENDIAN = 4;
1116 
1117     /**
1118      * 32-bit number.
1119      */
1120     int REG_DWORD_BIG_ENDIAN = 5;
1121 
1122     /**
1123      * Symbolic link (unicode).
1124      */
1125     int REG_LINK = 6;
1126 
1127     /**
1128      * Multiple unicode strings.
1129      */
1130     int REG_MULTI_SZ = 7;
1131 
1132     /**
1133      * Resource list in the resource map.
1134      */
1135     int REG_RESOURCE_LIST = 8;
1136 
1137     /**
1138      * Resource list in the hardware description.
1139      */
1140     int REG_FULL_RESOURCE_DESCRIPTOR = 9;
1141 
1142     /**
1143      *
1144      */
1145     int REG_RESOURCE_REQUIREMENTS_LIST = 10;
1146 
1147     /**
1148      * 64-bit number.
1149      */
1150     int REG_QWORD = 11;
1151 
1152     /**
1153      * 64-bit number, same as REG_QWORD.
1154      */
1155     int REG_QWORD_LITTLE_ENDIAN = 11;
1156 
1157     /**
1158      * A 64-bit value that is guaranteed to be unique on the operating system
1159      * that generated it until the system is restarted.
1160      */
1161     @FieldOrder({"LowPart", "HighPart"})
1162     public static class LUID extends Structure {
1163         public int LowPart;
1164         public int HighPart;
1165     }
1166 
1167     /**
1168      * A 64-bit integer;
1169      */
1170     @FieldOrder({"u"})
1171     public static class LARGE_INTEGER extends Structure implements Comparable<LARGE_INTEGER> {
1172         public static class ByReference extends LARGE_INTEGER implements
1173                 Structure.ByReference {
1174         }
1175 
1176         @FieldOrder({"LowPart", "HighPart"})
1177         public static class LowHigh extends Structure {
1178             public DWORD LowPart;
1179             public DWORD HighPart;
1180 
LowHigh()1181             public LowHigh() {
1182                 super();
1183             }
1184 
LowHigh(long value)1185             public LowHigh(long value) {
1186                 this(new DWORD(value & 0xFFFFFFFFL),  new DWORD((value >> 32) & 0xFFFFFFFFL));
1187             }
1188 
LowHigh(DWORD low, DWORD high)1189             public LowHigh(DWORD low, DWORD high) {
1190                 LowPart = low;
1191                 HighPart = high;
1192             }
1193 
longValue()1194             public long longValue() {
1195                 long loValue = LowPart.longValue();
1196                 long hiValue = HighPart.longValue();
1197                 return ((hiValue << 32) & 0xFFFFFFFF00000000L) | (loValue & 0xFFFFFFFFL);
1198             }
1199 
1200             @Override
toString()1201             public String toString() {
1202                 if ((LowPart == null) || (HighPart == null)) {
1203                     return "null";
1204                 } else {
1205                     return Long.toString(longValue());
1206                 }
1207             }
1208         }
1209 
1210         public static class UNION extends Union {
1211             public LowHigh lh;
1212             public long value;
1213 
UNION()1214             public UNION() {
1215                 super();
1216             }
1217 
UNION(long value)1218             public UNION(long value) {
1219                 this.value = value;
1220                 this.lh = new LowHigh(value);
1221             }
1222 
1223             @Override
read()1224             public void read() {
1225                 readField("lh");
1226                 readField("value");
1227             }
1228 
longValue()1229             public long longValue() {
1230                 return value;
1231             }
1232 
1233             @Override
toString()1234             public String toString() {
1235                 return Long.toString(longValue());
1236             }
1237         }
1238 
1239         public UNION u;
1240 
LARGE_INTEGER()1241         public LARGE_INTEGER() {
1242             super();
1243         }
1244 
LARGE_INTEGER(long value)1245         public LARGE_INTEGER(long value) {
1246             this.u = new UNION(value);
1247         }
1248 
1249         /**
1250          * Low DWORD.
1251          *
1252          * @return Low DWORD value
1253          */
getLow()1254         public DWORD getLow() {
1255             return u.lh.LowPart;
1256         }
1257 
1258         /**
1259          * High DWORD.
1260          *
1261          * @return High DWORD value
1262          */
getHigh()1263         public DWORD getHigh() {
1264             return u.lh.HighPart;
1265         }
1266 
1267         /**
1268          * 64-bit value.
1269          *
1270          * @return The 64-bit value.
1271          */
getValue()1272         public long getValue() {
1273             return u.value;
1274         }
1275 
1276         @Override
compareTo(LARGE_INTEGER other)1277         public int compareTo(LARGE_INTEGER other) {
1278             return compare(this, other);
1279         }
1280 
1281         @Override
toString()1282         public String toString() {
1283             return (u == null) ? "null" : Long.toString(getValue());
1284         }
1285 
1286         /**
1287          * Compares 2 LARGE_INTEGER values -  - <B>Note:</B> a {@code null}
1288          * value is considered <U>greater</U> than any non-{@code null} one
1289          * (i.e., {@code null} values are &quot;pushed&quot; to the end
1290          * of a sorted array / list of values)
1291          *
1292          * @param v1 The 1st value
1293          * @param v2 The 2nd value
1294          * @return 0 if values are equal (including if <U>both</U> are {@code null},
1295          * negative if 1st value less than 2nd one, positive otherwise. <B>Note:</B>
1296          * the comparison uses the {@link #getValue()}.
1297          * @see IntegerType#compare(long, long)
1298          */
compare(LARGE_INTEGER v1, LARGE_INTEGER v2)1299         public static int compare(LARGE_INTEGER v1, LARGE_INTEGER v2) {
1300             if (v1 == v2) {
1301                 return 0;
1302             } else if (v1 == null) {
1303                 return 1;   // v2 cannot be null or v1 == v2 would hold
1304             } else if (v2 == null) {
1305                 return (-1);
1306             } else {
1307                 return IntegerType.compare(v1.getValue(), v2.getValue());
1308             }
1309         }
1310 
1311         /**
1312          * Compares a LARGE_INTEGER value with a {@code long} one. <B>Note:</B> if
1313          * the LARGE_INTEGER value is {@code null} then it is consider <U>greater</U>
1314          * than any {@code long} value.
1315          *
1316          * @param v1 The {@link LARGE_INTEGER} value
1317          * @param v2 The {@code long} value
1318          * @return 0 if values are equal, negative if 1st value less than 2nd one,
1319          * positive otherwise. <B>Note:</B> the comparison uses the {@link #getValue()}.
1320          * @see IntegerType#compare(long, long)
1321          */
compare(LARGE_INTEGER v1, long v2)1322         public static int compare(LARGE_INTEGER v1, long v2) {
1323             if (v1 == null) {
1324                 return 1;
1325             } else {
1326                 return IntegerType.compare(v1.getValue(), v2);
1327             }
1328         }
1329     }
1330 
1331     /**
1332      * Handle to an object.
1333      */
1334     public static class HANDLE extends PointerType {
1335         private boolean immutable;
1336 
HANDLE()1337         public HANDLE() {
1338         }
1339 
HANDLE(Pointer p)1340         public HANDLE(Pointer p) {
1341             setPointer(p);
1342             immutable = true;
1343         }
1344 
1345         /** Override to the appropriate object for INVALID_HANDLE_VALUE. */
1346         @Override
fromNative(Object nativeValue, FromNativeContext context)1347         public Object fromNative(Object nativeValue, FromNativeContext context) {
1348             Object o = super.fromNative(nativeValue, context);
1349             if (WinBase.INVALID_HANDLE_VALUE.equals(o)) {
1350                 return WinBase.INVALID_HANDLE_VALUE;
1351             }
1352             return o;
1353         }
1354 
1355         @Override
setPointer(Pointer p)1356         public void setPointer(Pointer p) {
1357             if (immutable) {
1358                 throw new UnsupportedOperationException("immutable reference");
1359             }
1360 
1361             super.setPointer(p);
1362         }
1363 
1364         @Override
toString()1365         public String toString() {
1366             return String.valueOf(getPointer());
1367         }
1368     }
1369 
1370     /**
1371      * LPHANDLE
1372      */
1373     public static class HANDLEByReference extends ByReference {
HANDLEByReference()1374         public HANDLEByReference() {
1375             this(null);
1376         }
1377 
HANDLEByReference(HANDLE h)1378         public HANDLEByReference(HANDLE h) {
1379             super(Native.POINTER_SIZE);
1380             setValue(h);
1381         }
1382 
setValue(HANDLE h)1383         public void setValue(HANDLE h) {
1384             getPointer().setPointer(0, h != null ? h.getPointer() : null);
1385         }
1386 
getValue()1387         public HANDLE getValue() {
1388             Pointer p = getPointer().getPointer(0);
1389             if (p == null) {
1390                 return null;
1391             }
1392             if (WinBase.INVALID_HANDLE_VALUE.getPointer().equals(p)) {
1393                 return WinBase.INVALID_HANDLE_VALUE;
1394             }
1395             HANDLE h = new HANDLE();
1396             h.setPointer(p);
1397             return h;
1398         }
1399     }
1400 
1401     /**
1402      * Return code used by interfaces. It is zero upon success and nonzero to
1403      * represent an error code or status information.
1404      */
1405     class HRESULT extends NativeLong {
HRESULT()1406         public HRESULT() {
1407         }
1408 
HRESULT(int value)1409         public HRESULT(int value) {
1410             super(value);
1411         }
1412     }
1413 
1414     /**
1415      * The WELL_KNOWN_SID_TYPE enumeration type is a list of commonly used
1416      * security identifiers (SIDs). Programs can pass these values to the
1417      * CreateWellKnownSid function to create a SID from this list.
1418      */
1419     public abstract class WELL_KNOWN_SID_TYPE {
1420         /**
1421          * Indicates a null SID.
1422          */
1423         public static final int WinNullSid = 0;
1424 
1425         /**
1426          * Indicates a SID that matches everyone.
1427          */
1428         public static final int WinWorldSid = 1;
1429 
1430         /**
1431          * Indicates a local SID.
1432          */
1433         public static final int WinLocalSid = 2;
1434 
1435         /**
1436          * Indicates a SID that matches the owner or creator of an object.
1437          */
1438         public static final int WinCreatorOwnerSid = 3;
1439 
1440         /**
1441          * Indicates a SID that matches the creator group of an object.
1442          */
1443         public static final int WinCreatorGroupSid = 4;
1444 
1445         /**
1446          * Indicates a creator owner server SID.
1447          */
1448         public static final int WinCreatorOwnerServerSid = 5;
1449 
1450         /**
1451          * Indicates a creator group server SID.
1452          */
1453         public static final int WinCreatorGroupServerSid = 6;
1454 
1455         /**
1456          * Indicates a SID for the Windows NT authority.
1457          */
1458         public static final int WinNtAuthoritySid = 7;
1459 
1460         /**
1461          * Indicates a SID for a dial-up account.
1462          */
1463         public static final int WinDialupSid = 8;
1464 
1465         /**
1466          * Indicates a SID for a network account. This SID is added to the
1467          * process of a token when it logs on across a network. The
1468          * corresponding logon type is LOGON32_LOGON_NETWORK.
1469          */
1470         public static final int WinNetworkSid = 9;
1471 
1472         /**
1473          * Indicates a SID for a batch process. This SID is added to the process
1474          * of a token when it logs on as a batch job. The corresponding logon
1475          * type is LOGON32_LOGON_BATCH.
1476          */
1477         public static final int WinBatchSid = 10;
1478 
1479         /**
1480          * Indicates a SID for an interactive account. This SID is added to the
1481          * process of a token when it logs on interactively. The corresponding
1482          * logon type is LOGON32_LOGON_INTERACTIVE.
1483          */
1484         public static final int WinInteractiveSid = 11;
1485 
1486         /**
1487          * Indicates a SID for a service. This SID is added to the process of a
1488          * token when it logs on as a service. The corresponding logon type is
1489          * LOGON32_LOGON_bSERVICE.
1490          */
1491         public static final int WinServiceSid = 12;
1492 
1493         /**
1494          * Indicates a SID for the anonymous account.
1495          */
1496         public static final int WinAnonymousSid = 13;
1497 
1498         /**
1499          * Indicates a proxy SID.
1500          */
1501         public static final int WinProxySid = 14;
1502 
1503         /**
1504          * Indicates a SID for an enterprise controller.
1505          */
1506         public static final int WinEnterpriseControllersSid = 15;
1507 
1508         /**
1509          * Indicates a SID for self.
1510          */
1511         public static final int WinSelfSid = 16;
1512 
1513         /**
1514          * Indicates a SID that matches any authenticated user.
1515          */
1516         public static final int WinAuthenticatedUserSid = 17;
1517 
1518         /**
1519          * Indicates a SID for restricted code.
1520          */
1521         public static final int WinRestrictedCodeSid = 18;
1522 
1523         /**
1524          * Indicates a SID that matches a terminal server account.
1525          */
1526         public static final int WinTerminalServerSid = 19;
1527 
1528         /**
1529          * Indicates a SID that matches remote logons.
1530          */
1531         public static final int WinRemoteLogonIdSid = 20;
1532 
1533         /**
1534          * Indicates a SID that matches logon IDs.
1535          */
1536         public static final int WinLogonIdsSid = 21;
1537 
1538         /**
1539          * Indicates a SID that matches the local system.
1540          */
1541         public static final int WinLocalSystemSid = 22;
1542 
1543         /**
1544          * Indicates a SID that matches a local service.
1545          */
1546         public static final int WinLocalServiceSid = 23;
1547 
1548         /**
1549          * Indicates a SID that matches a network service.
1550          */
1551         public static final int WinNetworkServiceSid = 24;
1552 
1553         /**
1554          * Indicates a SID that matches the domain account.
1555          */
1556         public static final int WinBuiltinDomainSid = 25;
1557 
1558         /**
1559          * Indicates a SID that matches the administrator account.
1560          */
1561         public static final int WinBuiltinAdministratorsSid = 26;
1562 
1563         /**
1564          * Indicates a SID that matches built-in user accounts.
1565          */
1566         public static final int WinBuiltinUsersSid = 27;
1567 
1568         /**
1569          * Indicates a SID that matches the guest account.
1570          */
1571         public static final int WinBuiltinGuestsSid = 28;
1572 
1573         /**
1574          * Indicates a SID that matches the power users group.
1575          */
1576         public static final int WinBuiltinPowerUsersSid = 29;
1577 
1578         /**
1579          * Indicates a SID that matches the account operators account.
1580          */
1581         public static final int WinBuiltinAccountOperatorsSid = 30;
1582 
1583         /**
1584          * Indicates a SID that matches the system operators group.
1585          */
1586         public static final int WinBuiltinSystemOperatorsSid = 31;
1587 
1588         /**
1589          * Indicates a SID that matches the print operators group.
1590          */
1591         public static final int WinBuiltinPrintOperatorsSid = 32;
1592 
1593         /**
1594          * Indicates a SID that matches the backup operators group.
1595          */
1596         public static final int WinBuiltinBackupOperatorsSid = 33;
1597 
1598         /**
1599          * Indicates a SID that matches the replicator account.
1600          */
1601         public static final int WinBuiltinReplicatorSid = 34;
1602 
1603         /**
1604          * Indicates a SID that matches pre-Windows 2000 compatible accounts.
1605          */
1606         public static final int WinBuiltinPreWindows2000CompatibleAccessSid = 35;
1607 
1608         /**
1609          * Indicates a SID that matches remote desktop users.
1610          */
1611         public static final int WinBuiltinRemoteDesktopUsersSid = 36;
1612 
1613         /**
1614          * Indicates a SID that matches the network operators group.
1615          */
1616         public static final int WinBuiltinNetworkConfigurationOperatorsSid = 37;
1617 
1618         /**
1619          * Indicates a SID that matches the account administrators group.
1620          */
1621         public static final int WinAccountAdministratorSid = 38;
1622 
1623         /**
1624          * Indicates a SID that matches the account guest group.
1625          */
1626         public static final int WinAccountGuestSid = 39;
1627 
1628         /**
1629          * Indicates a SID that matches account Kerberos target group.
1630          */
1631         public static final int WinAccountKrbtgtSid = 40;
1632 
1633         /**
1634          * Indicates a SID that matches the account domain administrator group.
1635          */
1636         public static final int WinAccountDomainAdminsSid = 41;
1637 
1638         /**
1639          * Indicates a SID that matches the account domain users group.
1640          */
1641         public static final int WinAccountDomainUsersSid = 42;
1642 
1643         /**
1644          * Indicates a SID that matches the account domain guests group.
1645          */
1646         public static final int WinAccountDomainGuestsSid = 43;
1647 
1648         /**
1649          * Indicates a SID that matches the account computer group.
1650          */
1651         public static final int WinAccountComputersSid = 44;
1652 
1653         /**
1654          * Indicates a SID that matches the account controller group.
1655          */
1656         public static final int WinAccountControllersSid = 45;
1657 
1658         /**
1659          * Indicates a SID that matches the certificate administrators group.
1660          */
1661         public static final int WinAccountCertAdminsSid = 46;
1662 
1663         /**
1664          * Indicates a SID that matches the schema administrators group.
1665          */
1666         public static final int WinAccountSchemaAdminsSid = 47;
1667 
1668         /**
1669          * Indicates a SID that matches the enterprise administrators group.
1670          */
1671         public static final int WinAccountEnterpriseAdminsSid = 48;
1672 
1673         /**
1674          * Indicates a SID that matches the policy administrators group.
1675          */
1676         public static final int WinAccountPolicyAdminsSid = 49;
1677 
1678         /**
1679          * Indicates a SID that matches the RAS and IAS server account.
1680          */
1681         public static final int WinAccountRasAndIasServersSid = 50;
1682 
1683         /**
1684          * Indicates a SID present when the Microsoft NTLM authentication
1685          * package authenticated the client.
1686          */
1687         public static final int WinNTLMAuthenticationSid = 51;
1688 
1689         /**
1690          * Indicates a SID present when the Microsoft Digest authentication
1691          * package authenticated the client.
1692          */
1693         public static final int WinDigestAuthenticationSid = 52;
1694 
1695         /**
1696          * Indicates a SID present when the Secure Channel (SSL/TLS)
1697          * authentication package authenticated the client.
1698          */
1699         public static final int WinSChannelAuthenticationSid = 53;
1700 
1701         /**
1702          * Indicates a SID present when the user authenticated from within the
1703          * forest or across a trust that does not have the selective
1704          * authentication option enabled. If this SID is present, then
1705          * WinOtherOrganizationSid cannot be present.
1706          */
1707         public static final int WinThisOrganizationSid = 54;
1708 
1709         /**
1710          * Indicates a SID present when the user authenticated across a forest
1711          * with the selective authentication option enabled. If this SID is
1712          * present, then WinThisOrganizationSid cannot be present.
1713          */
1714         public static final int WinOtherOrganizationSid = 55;
1715 
1716         /**
1717          * Indicates a SID that allows a user to create incoming forest trusts.
1718          * It is added to the token of users who are a member of the Incoming
1719          * Forest Trust Builders built-in group in the root domain of the
1720          * forest.
1721          */
1722         public static final int WinBuiltinIncomingForestTrustBuildersSid = 56;
1723 
1724         /**
1725          * Indicates a SID that matches the performance monitor user group.
1726          */
1727         public static final int WinBuiltinPerfMonitoringUsersSid = 57;
1728 
1729         /**
1730          * Indicates a SID that matches the performance log user group.
1731          */
1732         public static final int WinBuiltinPerfLoggingUsersSid = 58;
1733 
1734         /**
1735          * Indicates a SID that matches the Windows Authorization Access group.
1736          */
1737         public static final int WinBuiltinAuthorizationAccessSid = 59;
1738 
1739         /**
1740          * Indicates a SID is present in a server that can issue Terminal Server
1741          * licenses.
1742          */
1743         public static final int WinBuiltinTerminalServerLicenseServersSid = 60;
1744 
1745         /**
1746          *
1747          */
1748         public static final int WinBuiltinDCOMUsersSid = 61;
1749 
1750         /**
1751          *
1752          */
1753         public static final int WinBuiltinIUsersSid = 62;
1754 
1755         /**
1756          *
1757          */
1758         public static final int WinIUserSid = 63;
1759 
1760         /**
1761          *
1762          */
1763         public static final int WinBuiltinCryptoOperatorsSid = 64;
1764 
1765         /**
1766          *
1767          */
1768         public static final int WinUntrustedLabelSid = 65;
1769 
1770         /**
1771          *
1772          */
1773         public static final int WinLowLabelSid = 66;
1774 
1775         /**
1776          *
1777          */
1778         public static final int WinMediumLabelSid = 67;
1779 
1780         /**
1781          *
1782          */
1783         public static final int WinHighLabelSid = 68;
1784 
1785         /**
1786          *
1787          */
1788         public static final int WinSystemLabelSid = 69;
1789 
1790         /**
1791          *
1792          */
1793         public static final int WinWriteRestrictedCodeSid = 70;
1794 
1795         /**
1796          *
1797          */
1798         public static final int WinCreatorOwnerRightsSid = 71;
1799 
1800         /**
1801          *
1802          */
1803         public static final int WinCacheablePrincipalsGroupSid = 72;
1804 
1805         /**
1806          *
1807          */
1808         public static final int WinNonCacheablePrincipalsGroupSid = 73;
1809 
1810         /**
1811          *
1812          */
1813         public static final int WinEnterpriseReadonlyControllersSid = 74;
1814 
1815         /**
1816          * Indicates a SID that matches a read-only enterprise domain
1817          * controller.
1818          */
1819         public static final int WinAccountReadonlyControllersSid = 75;
1820 
1821         /**
1822          * Indicates a SID that matches the built-in DCOM certification services
1823          * access group.
1824          */
1825         public static final int WinBuiltinEventLogReadersGroup = 76;
1826     }
1827 
1828     /**
1829      * Current SID revision level.
1830      */
1831     int SID_REVISION = 1;
1832     int SID_MAX_SUB_AUTHORITIES = 15;
1833     int SID_RECOMMENDED_SUB_AUTHORITIES = 1;
1834 
1835     /**
1836      * Maximum bytes used by a SID. (sizeof(SID) - sizeof(DWORD) +
1837      * (SID_MAX_SUB_AUTHORITIES * sizeof(DWORD)))
1838      */
1839     int SECURITY_MAX_SID_SIZE = 68;
1840 
1841     /**
1842      * The OSVERSIONINFO data structure contains operating system version
1843      * information. The information includes major and minor version numbers, a
1844      * build number, a platform identifier, and descriptive text about the
1845      * operating system. This structure is used with the GetVersionEx function.
1846      */
1847     @FieldOrder({"dwOSVersionInfoSize", "dwMajorVersion", "dwMinorVersion", "dwBuildNumber", "dwPlatformId", "szCSDVersion"})
1848     public static class OSVERSIONINFO extends Structure {
1849         /**
1850          * Size of this data structure, in bytes. Set this member to
1851          * sizeof(OSVERSIONINFO) before calling the GetVersionEx function.
1852          */
1853         public DWORD dwOSVersionInfoSize;
1854 
1855         /**
1856          * Major version number of the operating system.
1857          */
1858         public DWORD dwMajorVersion;
1859 
1860         /**
1861          * Minor version number of the operating system.
1862          */
1863         public DWORD dwMinorVersion;
1864 
1865         /**
1866          * Build number of the operating system.
1867          */
1868         public DWORD dwBuildNumber;
1869 
1870         /**
1871          * Operating system platform.
1872          */
1873         public DWORD dwPlatformId;
1874 
1875         /**
1876          * Pointer to a null-terminated string, such as "Service Pack 3", that
1877          * indicates the latest Service Pack installed on the system.
1878          */
1879         public char szCSDVersion[];
1880 
OSVERSIONINFO()1881         public OSVERSIONINFO() {
1882             szCSDVersion = new char[128];
1883             dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFO)
1884         }
1885 
OSVERSIONINFO(Pointer memory)1886         public OSVERSIONINFO(Pointer memory) {
1887             super(memory);
1888             read();
1889         }
1890     }
1891 
1892     /**
1893      * Contains operating system version information. The information includes
1894      * major and minor version numbers, a build number, a platform identifier,
1895      * and information about product suites and the latest Service Pack
1896      * installed on the system.
1897      */
1898     @FieldOrder({"dwOSVersionInfoSize",
1899                 "dwMajorVersion", "dwMinorVersion", "dwBuildNumber",
1900                 "dwPlatformId",
1901                 "szCSDVersion",
1902                 "wServicePackMajor", "wServicePackMinor",
1903                 "wSuiteMask", "wProductType", "wReserved"})
1904     public static class OSVERSIONINFOEX extends Structure {
1905         /**
1906          * The size of this data structure, in bytes.
1907          */
1908         public DWORD dwOSVersionInfoSize;
1909 
1910         /**
1911          * The major version number of the operating system.
1912          */
1913         public DWORD dwMajorVersion;
1914 
1915         /**
1916          * The minor version number of the operating system.
1917          */
1918         public DWORD dwMinorVersion;
1919 
1920         /**
1921          * The build number of the operating system.
1922          */
1923         public DWORD dwBuildNumber;
1924 
1925         /**
1926          * The operating system platform. This member can be
1927          * VER_PLATFORM_WIN32_NT.
1928          */
1929         public DWORD dwPlatformId;
1930 
1931         /**
1932          * A null-terminated string, such as "Service Pack 3", that indicates
1933          * the latest Service Pack installed on the system. If no Service Pack
1934          * has been installed, the string is empty.
1935          */
1936         public char szCSDVersion[];
1937 
1938         /**
1939          * The major version number of the latest Service Pack installed on the
1940          * system. For example, for Service Pack 3, the major version number is
1941          * 3. If no Service Pack has been installed, the value is zero.
1942          */
1943         public WORD wServicePackMajor;
1944 
1945         /**
1946          * The minor version number of the latest Service Pack installed on the
1947          * system. For example, for Service Pack 3, the minor version number is
1948          * 0.
1949          */
1950         public WORD wServicePackMinor;
1951 
1952         /**
1953          * A bit mask that identifies the product suites available on the
1954          * system.
1955          */
1956         public WORD wSuiteMask;
1957 
1958         /**
1959          * Any additional information about the system.
1960          */
1961         public byte wProductType;
1962 
1963         /**
1964          * Reserved for future use.
1965          */
1966         public byte wReserved;
1967 
OSVERSIONINFOEX()1968         public OSVERSIONINFOEX() {
1969             szCSDVersion = new char[128];
1970             dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFOEX)
1971         }
1972 
OSVERSIONINFOEX(Pointer memory)1973         public OSVERSIONINFOEX(Pointer memory) {
1974             super(memory);
1975             read();
1976         }
1977 
1978         /**
1979          * @return The major version number of the operating system.
1980          */
getMajor()1981         public int getMajor() {
1982             return dwMajorVersion.intValue();
1983         }
1984 
1985         /**
1986          * @return The minor version number of the operating system.
1987          */
getMinor()1988         public int getMinor() {
1989             return dwMinorVersion.intValue();
1990         }
1991 
1992         /**
1993          * @return The build number of the operating system.
1994          */
getBuildNumber()1995         public int getBuildNumber() {
1996             return dwBuildNumber.intValue();
1997         }
1998 
1999         /**
2000          * @return  The operating system platform. This member can be VER_PLATFORM_WIN32_NT.
2001          */
getPlatformId()2002         public int getPlatformId() {
2003             return dwPlatformId.intValue();
2004         }
2005 
2006         /**
2007          * @return String, such as "Service Pack 3", that indicates the latest
2008          *         Service Pack installed on the system.<br>
2009          *         If no Service Pack has been installed, the string is empty.
2010          */
getServicePack()2011         public String getServicePack() {
2012             return Native.toString(szCSDVersion);
2013         }
2014 
2015         /**
2016          * @return A bit mask that identifies the product suites available on the system.
2017          */
getSuiteMask()2018         public int getSuiteMask() {
2019             return wSuiteMask.intValue();
2020         }
2021 
2022         /**
2023          * @return Any additional information about the system.
2024          */
getProductType()2025         public byte getProductType() {
2026             return wProductType;
2027         }
2028     }
2029 
2030     int VER_EQUAL = 1;
2031     int VER_GREATER = 2;
2032     int VER_GREATER_EQUAL = 3;
2033     int VER_LESS = 4;
2034     int VER_LESS_EQUAL = 5;
2035     int VER_AND = 6;
2036     int VER_OR = 7;
2037 
2038     int VER_CONDITION_MASK = 7;
2039     int VER_NUM_BITS_PER_CONDITION_MASK = 3;
2040 
2041     int VER_MINORVERSION = 0x0000001;
2042     int VER_MAJORVERSION = 0x0000002;
2043     int VER_BUILDNUMBER = 0x0000004;
2044     int VER_PLATFORMID = 0x0000008;
2045     int VER_SERVICEPACKMINOR = 0x0000010;
2046     int VER_SERVICEPACKMAJOR = 0x0000020;
2047     int VER_SUITENAME = 0x0000040;
2048     int VER_PRODUCT_TYPE = 0x0000080;
2049 
2050     int VER_NT_WORKSTATION = 0x0000001;
2051     int VER_NT_DOMAIN_CONTROLLER = 0x0000002;
2052     int VER_NT_SERVER = 0x0000003;
2053 
2054     int VER_PLATFORM_WIN32s = 0;
2055     int VER_PLATFORM_WIN32_WINDOWS = 1;
2056     int VER_PLATFORM_WIN32_NT = 2;
2057 
2058     /*
2059      * WIN32_WINNT version constants
2060      */
2061     short WIN32_WINNT_NT4 = 0x0400; // Windows NT 4.0
2062     short WIN32_WINNT_WIN2K = 0x0500; // Windows 2000
2063     short WIN32_WINNT_WINXP = 0x0501; // Windows XP
2064     short WIN32_WINNT_WS03 = 0x0502; // Windows Server 2003
2065     short WIN32_WINNT_WIN6 = 0x0600; // Windows Vista
2066     short WIN32_WINNT_VISTA = 0x0600; // Windows Vista
2067     short WIN32_WINNT_WS08 = 0x0600; // Windows Server 2008
2068     short WIN32_WINNT_LONGHORN = 0x0600; // Windows Vista
2069     short WIN32_WINNT_WIN7 = 0x0601; // Windows 7
2070     short WIN32_WINNT_WIN8 = 0x0602; // Windows 8
2071     short WIN32_WINNT_WINBLUE = 0x0603; // Windows 8.1
2072     short WIN32_WINNT_WINTHRESHOLD = 0x0A00; // Windows 10
2073     short WIN32_WINNT_WIN10 = 0x0A00; // Windows 10
2074 
2075     /**
2076      * Read the records sequentially. If this is the first read operation, the
2077      * EVENTLOG_FORWARDS_READ EVENTLOG_BACKWARDS_READ flags determines which
2078      * record is read first.
2079      */
2080     int EVENTLOG_SEQUENTIAL_READ = 0x0001;
2081 
2082     /**
2083      * Begin reading from the record specified in the dwRecordOffset parameter.
2084      * This option may not work with large log files if the function cannot
2085      * determine the log file's size. For details, see Knowledge Base article,
2086      * 177199.
2087      */
2088     int EVENTLOG_SEEK_READ = 0x0002;
2089 
2090     /**
2091      * The log is read in chronological order (oldest to newest). The default.
2092      */
2093     int EVENTLOG_FORWARDS_READ = 0x0004;
2094 
2095     /**
2096      * The log is read in reverse chronological order (newest to oldest).
2097      */
2098     int EVENTLOG_BACKWARDS_READ = 0x0008;
2099 
2100     /**
2101      * Information event
2102      */
2103     int EVENTLOG_SUCCESS = 0x0000;
2104 
2105     /**
2106      * Error event
2107      */
2108     int EVENTLOG_ERROR_TYPE = 0x0001;
2109 
2110     /**
2111      * Warning event
2112      */
2113     int EVENTLOG_WARNING_TYPE = 0x0002;
2114 
2115     /**
2116      * Information event
2117      */
2118     int EVENTLOG_INFORMATION_TYPE = 0x0004;
2119 
2120     /**
2121      * Success Audit event
2122      */
2123     int EVENTLOG_AUDIT_SUCCESS = 0x0008;
2124 
2125     /**
2126      * Failure Audit event
2127      */
2128     int EVENTLOG_AUDIT_FAILURE = 0x0010;
2129 
2130     /**
2131      * The EVENTLOGRECORD structure contains information about an event record
2132      * returned by the ReadEventLog function.
2133      */
2134     @FieldOrder({"Length", "Reserved", "RecordNumber", "TimeGenerated", "TimeWritten",
2135                 "EventID", "EventType", "NumStrings", "EventCategory", "ReservedFlags",
2136                 "ClosingRecordNumber", "StringOffset", "UserSidLength", "UserSidOffset",
2137                 "DataLength", "DataOffset"})
2138     public static class EVENTLOGRECORD extends Structure {
2139         /**
2140          * Size of this event record, in bytes. Note that this value is stored
2141          * at both ends of the entry to ease moving forward or backward through
2142          * the log. The length includes any pad bytes inserted at the end of the
2143          * record for DWORD alignment.
2144          */
2145         public DWORD Length;
2146 
2147         /**
2148          * Reserved.
2149          */
2150         public DWORD Reserved;
2151 
2152         /**
2153          * Record number of the record. This value can be used with the
2154          * EVENTLOG_SEEK_READ flag in the ReadEventLog function to begin reading
2155          * at a specified record.
2156          */
2157         public DWORD RecordNumber;
2158 
2159         /**
2160          * Time at which this entry was submitted. This time is measured in the
2161          * number of seconds elapsed since 00:00:00 January 1, 1970, Universal
2162          * Coordinated Time.
2163          */
2164         public DWORD TimeGenerated;
2165 
2166         /**
2167          * Time at which this entry was received by the service to be written to
2168          * the log. This time is measured in the number of seconds elapsed since
2169          * 00:00:00 January 1, 1970, Universal Coordinated Time.
2170          */
2171         public DWORD TimeWritten;
2172 
2173         /**
2174          * Event identifier. The value is specific to the event source for the
2175          * event, and is used with source name to locate a description string in
2176          * the message file for the event source.
2177          */
2178         public DWORD EventID;
2179 
2180         /**
2181          * Type of event.
2182          */
2183         public WORD EventType;
2184 
2185         /**
2186          * Number of strings present in the log (at the position indicated by
2187          * StringOffset). These strings are merged into the message before it is
2188          * displayed to the user.
2189          */
2190         public WORD NumStrings;
2191 
2192         /**
2193          * Category for this event. The meaning of this value depends on the
2194          * event source.
2195          */
2196         public WORD EventCategory;
2197 
2198         /**
2199          * Reserved.
2200          */
2201         public WORD ReservedFlags;
2202 
2203         /**
2204          * Reserved.
2205          */
2206         public DWORD ClosingRecordNumber;
2207 
2208         /**
2209          * Offset of the description strings within this event log record.
2210          */
2211         public DWORD StringOffset;
2212 
2213         /**
2214          * Size of the UserSid member, in bytes. This value can be zero if no
2215          * security identifier was provided.
2216          */
2217         public DWORD UserSidLength;
2218 
2219         /**
2220          * Offset of the security identifier (SID) within this event log record.
2221          * To obtain the user name for this SID, use the LookupAccountSid
2222          * function.
2223          */
2224         public DWORD UserSidOffset;
2225 
2226         /**
2227          * Size of the event-specific data (at the position indicated by
2228          * DataOffset), in bytes.
2229          */
2230         public DWORD DataLength;
2231 
2232         /**
2233          * Offset of the event-specific information within this event log
2234          * record, in bytes. This information could be something specific (a
2235          * disk driver might log the number of retries, for example), followed
2236          * by binary information specific to the event being logged and to the
2237          * source that generated the entry.
2238          */
2239         public DWORD DataOffset;
2240 
EVENTLOGRECORD()2241         public EVENTLOGRECORD() {
2242             super();
2243         }
2244 
EVENTLOGRECORD(Pointer p)2245         public EVENTLOGRECORD(Pointer p) {
2246             super(p);
2247             read();
2248         }
2249     }
2250 
2251     //
2252     // Service Types (Bit Mask)
2253     //
2254     int SERVICE_KERNEL_DRIVER = 0x00000001;
2255     int SERVICE_FILE_SYSTEM_DRIVER = 0x00000002;
2256     int SERVICE_ADAPTER = 0x00000004;
2257     int SERVICE_RECOGNIZER_DRIVER = 0x00000008;
2258     int SERVICE_DRIVER = SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER
2259             | SERVICE_RECOGNIZER_DRIVER;
2260     int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
2261     int SERVICE_WIN32_SHARE_PROCESS = 0x00000020;
2262     int SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS;
2263     int SERVICE_INTERACTIVE_PROCESS = 0x00000100;
2264     int SERVICE_TYPE_ALL = SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER
2265             | SERVICE_INTERACTIVE_PROCESS;
2266 
2267     //
2268     // Start Type
2269     //
2270 
2271     int SERVICE_BOOT_START   = 0x00000000;
2272     int SERVICE_SYSTEM_START = 0x00000001;
2273     int SERVICE_AUTO_START   = 0x00000002;
2274     int SERVICE_DEMAND_START = 0x00000003;
2275     int SERVICE_DISABLED     = 0x00000004;
2276 
2277     //
2278     // Error control type
2279     //
2280     int SERVICE_ERROR_IGNORE   = 0x00000000;
2281     int SERVICE_ERROR_NORMAL   = 0x00000001;
2282     int SERVICE_ERROR_SEVERE   = 0x00000002;
2283     int SERVICE_ERROR_CRITICAL = 0x00000003;
2284 
2285     int STATUS_PENDING = 0x00000103;
2286 
2287     // Privilege Constants
2288     String SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege";
2289     String SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege";
2290     String SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege";
2291     String SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege";
2292     String SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege";
2293     String SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege";
2294     String SE_TCB_NAME = "SeTcbPrivilege";
2295     String SE_SECURITY_NAME = "SeSecurityPrivilege";
2296     String SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege";
2297     String SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege";
2298     String SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege";
2299     String SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege";
2300     String SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege";
2301     String SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege";
2302     String SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege";
2303     String SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege";
2304     String SE_BACKUP_NAME = "SeBackupPrivilege";
2305     String SE_RESTORE_NAME = "SeRestorePrivilege";
2306     String SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
2307     String SE_DEBUG_NAME = "SeDebugPrivilege";
2308     String SE_AUDIT_NAME = "SeAuditPrivilege";
2309     String SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege";
2310     String SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege";
2311     String SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege";
2312     String SE_UNDOCK_NAME = "SeUndockPrivilege";
2313     String SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege";
2314     String SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege";
2315     String SE_MANAGE_VOLUME_NAME = "SeManageVolumePrivilege";
2316     String SE_IMPERSONATE_NAME = "SeImpersonatePrivilege";
2317     String SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege";
2318 
2319     int SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001;
2320     int SE_PRIVILEGE_ENABLED = 0x00000002;
2321     int SE_PRIVILEGE_REMOVED = 0X00000004;
2322     int SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000;
2323 
2324     /** Required to create a process. */
2325     int PROCESS_CREATE_PROCESS = 0x0080;
2326 
2327     /** Required to create a thread. */
2328     int PROCESS_CREATE_THREAD = 0x0002;
2329 
2330     /**
2331      * Required to duplicate a handle using
2332      * {@link Kernel32#DuplicateHandle}
2333      * .
2334      */
2335     int PROCESS_DUP_HANDLE = 0x0040;
2336 
2337     /**
2338      * All possible access rights for a process object. Windows Server 2003 and
2339      * Windows XP: The size of the PROCESS_ALL_ACCESS flag increased on Windows
2340      * Server 2008 and Windows Vista. <br>
2341      * If an application compiled for Windows Server 2008 and Windows Vista is
2342      * run on Windows Server 2003 or Windows XP, the PROCESS_ALL_ACCESS flag is
2343      * too large and the function specifying this flag fails with
2344      * ERROR_ACCESS_DENIED.<br>
2345      * To avoid this problem, specify the minimum set of access rights required
2346      * for the operation.<br>
2347      * If PROCESS_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum
2348      * operating system targeted by your application (for example, #define
2349      * _WIN32_WINNT _WIN32_WINNT_WINXP).<br>
2350      * For more information, see Using the Windows Headers.
2351      *
2352      * @see <a href="https://msdn.microsoft.com/en-us/library/ms684880(v=VS.85).aspx">MSDN</a>
2353      */
2354     int PROCESS_ALL_ACCESS = WinNT.PROCESS_CREATE_PROCESS
2355             | WinNT.PROCESS_CREATE_THREAD
2356             | WinNT.PROCESS_DUP_HANDLE
2357             | WinNT.PROCESS_QUERY_INFORMATION
2358             | WinNT.PROCESS_QUERY_LIMITED_INFORMATION
2359             | WinNT.PROCESS_SET_INFORMATION
2360             | WinNT.PROCESS_SET_QUOTA
2361             | WinNT.PROCESS_SUSPEND_RESUME
2362             | WinNT.PROCESS_SYNCHRONIZE
2363             | WinNT.PROCESS_TERMINATE
2364             | WinNT.PROCESS_VM_OPERATION
2365             | WinNT.PROCESS_VM_READ
2366             | WinNT.PROCESS_VM_WRITE
2367             | WinNT.DELETE
2368             | WinNT.READ_CONTROL
2369             | WinNT.WRITE_DAC
2370             | WinNT.WRITE_OWNER
2371             | WinNT.SYNCHRONIZE;
2372 
2373     /**
2374      * Required to retrieve certain information about a process, such as its
2375      * token, exit code, and priority class (see
2376      * {@link Advapi32#OpenProcessToken}).
2377      */
2378     int PROCESS_QUERY_INFORMATION = 0x0400;
2379 
2380     /**
2381      * Required to retrieve certain information about a process (see
2382      * {@link Kernel32#GetExitCodeProcess}
2383      * , {@code Kernel32#GetPriorityClass}, {@code Kernel32#IsProcessInJob},
2384      * {@code Kernel32.QueryFullProcessImageName}). A handle that has the
2385      * {@link #PROCESS_QUERY_INFORMATION} access right is automatically granted
2386      * {@link #PROCESS_QUERY_LIMITED_INFORMATION}.
2387      *
2388      * Windows Server 2003 and Windows XP: This access right is not supported.
2389      */
2390     int PROCESS_QUERY_LIMITED_INFORMATION = 0x1000;
2391 
2392     /**
2393      * Required to set certain information about a process, such as its priority
2394      * class (see {@code Kernel32#SetPriorityClass}).
2395      */
2396     int PROCESS_SET_INFORMATION = 0x0200;
2397 
2398     /**
2399      * Required to set memory limits using
2400      * {@code Kernel32.SetProcessWorkingSetSize()}.
2401      */
2402     int PROCESS_SET_QUOTA = 0x0100;
2403 
2404     /** Required to suspend or resume a process. */
2405     int PROCESS_SUSPEND_RESUME = 0x0800;
2406 
2407     /**
2408      * Required to terminate a process using
2409      * {@link Kernel32#TerminateProcess}.
2410      */
2411     int PROCESS_TERMINATE = 0x00000001;
2412 
2413     /**
2414      * Required for getting process exe path in native system path format
2415      * {@code Kernel32.QueryFullProcessImageName()}.
2416      */
2417     int PROCESS_NAME_NATIVE = 0x00000001;
2418 
2419     /**
2420      * Required to perform an operation on the address space of a process (see
2421      * {@code Kernel32.VirtualProtectEx()} and
2422      * {@link Kernel32#WriteProcessMemory}
2423      * ).
2424      */
2425     int PROCESS_VM_OPERATION = 0x0008;
2426 
2427     /**
2428      * Required to read memory in a process using
2429      * {@link Kernel32#ReadProcessMemory}
2430      * .
2431      */
2432     int PROCESS_VM_READ = 0x0010;
2433 
2434     /**
2435      * Required to write to memory in a process using
2436      * {@link Kernel32#WriteProcessMemory}
2437      * .
2438      */
2439     int PROCESS_VM_WRITE = 0x0020;
2440 
2441     /** Required to wait for the process to terminate using the wait functions. */
2442     int PROCESS_SYNCHRONIZE = 0x00100000;
2443 
2444     /* Security information types */
2445     int OWNER_SECURITY_INFORMATION = 0x00000001;
2446     int GROUP_SECURITY_INFORMATION = 0x00000002;
2447     int DACL_SECURITY_INFORMATION = 0x00000004;
2448     int SACL_SECURITY_INFORMATION = 0x00000008;
2449     int LABEL_SECURITY_INFORMATION = 0x00000010;
2450     int PROTECTED_DACL_SECURITY_INFORMATION = 0x80000000;
2451     int PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000;
2452     int UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000;
2453     int UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000;
2454 
2455     /* Security control bits */
2456     int SE_OWNER_DEFAULTED          = 0x00000001;
2457     int SE_GROUP_DEFAULTED          = 0x00000002;
2458     int SE_DACL_PRESENT             = 0x00000004;
2459     int SE_DACL_DEFAULTED           = 0x00000008;
2460     int SE_SACL_PRESENT             = 0x00000010;
2461     int SE_SACL_DEFAULTED           = 0x00000020;
2462     int SE_DACL_AUTO_INHERIT_REQ    = 0x00000100;
2463     int SE_SACL_AUTO_INHERIT_REQ    = 0x00000200;
2464     int SE_DACL_AUTO_INHERITED      = 0x00000400;
2465     int SE_SACL_AUTO_INHERITED      = 0x00000800;
2466     int SE_DACL_PROTECTED           = 0x00001000;
2467     int SE_SACL_PROTECTED           = 0x00002000;
2468     int SE_RM_CONTROL_VALID         = 0x00004000;
2469     int SE_SELF_RELATIVE            = 0x00008000;
2470 
2471     int SECURITY_DESCRIPTOR_REVISION = 0x00000001;
2472 
2473     @FieldOrder({"data"})
2474     public static class SECURITY_DESCRIPTOR extends Structure {
2475         public static class ByReference extends SECURITY_DESCRIPTOR implements
2476                 Structure.ByReference {
2477         }
2478 
2479         public byte[] data;
2480 
SECURITY_DESCRIPTOR()2481         public SECURITY_DESCRIPTOR() {
2482             super();
2483         }
2484 
SECURITY_DESCRIPTOR(byte[] data)2485         public SECURITY_DESCRIPTOR(byte[] data) {
2486             super();
2487             this.data = data;
2488             useMemory(new Memory(data.length));
2489         }
2490 
SECURITY_DESCRIPTOR(int size)2491         public SECURITY_DESCRIPTOR(int size) {
2492             super();
2493             useMemory(new Memory(size));
2494             data = new byte[size];
2495         }
2496 
SECURITY_DESCRIPTOR(Pointer memory)2497         public SECURITY_DESCRIPTOR(Pointer memory) {
2498             super(memory);
2499             read();
2500         }
2501     }
2502 
2503     int ACL_REVISION        = 2;
2504     int ACL_REVISION_DS     = 4;
2505 
2506     // This is the history of ACL revisions.  Add a new one whenever
2507     // ACL_REVISION is updated
2508     int ACL_REVISION1       = 1;
2509     int ACL_REVISION2       = 2;
2510     int ACL_REVISION3       = 3;
2511     int ACL_REVISION4       = 4;
2512     int MIN_ACL_REVISION    = ACL_REVISION2;
2513     int MAX_ACL_REVISION    = ACL_REVISION4;
2514 
2515     @FieldOrder({"AclRevision", "Sbz1", "AclSize", "AceCount", "Sbz2"})
2516     public static class ACL extends Structure {
2517         /*
2518          * Maximum size chosen based on technet article:
2519          * https://technet.microsoft.com/en-us/library/cc781716.aspx
2520          */
2521         public static int MAX_ACL_SIZE = 64 * 1024;
2522 
2523         public byte AclRevision;
2524         public byte Sbz1;
2525         public short AclSize;
2526         public short AceCount;
2527         public short Sbz2;
2528 
ACL()2529         public ACL() {
2530             super();
2531         }
2532 
ACL(int size)2533         public ACL(int size) {
2534             super();
2535             useMemory(new Memory(size));
2536         }
2537 
ACL(Pointer pointer)2538         public ACL(Pointer pointer) {
2539             super(pointer);
2540             read();
2541         }
2542 
2543         /**
2544          * Extract the contained ACEs from the ACL.
2545          *
2546          * <p>ACE types as decoded to their native JNA counterparts. ACE types,
2547          * that are currently unsupported by JNA are returned as
2548          * {@link WinNT.ACE_HEADER} objects.</p>
2549          *
2550          * @return array holding the contained ACEs
2551          */
getACEs()2552         public ACE_HEADER[] getACEs() {
2553             ACE_HEADER[] ACEs = new ACE_HEADER[AceCount];
2554             final Pointer pointer = this.getPointer();
2555             int offset = size();
2556             for (int i = 0; i < AceCount; i++) {
2557                 final Pointer share = pointer.share(offset);
2558                 final byte aceType = share.getByte(0); // ACE_HEADER.AceType
2559                 switch (aceType) {
2560                     case ACCESS_ALLOWED_ACE_TYPE:
2561                         ACEs[i] = new ACCESS_ALLOWED_ACE(share);
2562                         break;
2563                     case ACCESS_DENIED_ACE_TYPE:
2564                         ACEs[i] = new ACCESS_DENIED_ACE(share);
2565                         break;
2566                     default:
2567                         ACEs[i] = new ACE_HEADER(share);
2568                         break;
2569                 }
2570                 offset += ACEs[i].AceSize;
2571             }
2572             return ACEs;
2573         }
2574     }
2575 
2576     public static class PACLByReference extends ByReference {
PACLByReference()2577         public PACLByReference() {
2578             this(null);
2579         }
2580 
PACLByReference(ACL h)2581         public PACLByReference(ACL h) {
2582             super(Native.POINTER_SIZE);
2583             setValue(h);
2584         }
2585 
setValue(ACL h)2586         public void setValue(ACL h) {
2587             getPointer().setPointer(0, h != null ? h.getPointer() : null);
2588         }
2589 
getValue()2590         public ACL getValue() {
2591             Pointer p = getPointer().getPointer(0);
2592             if (p == null) {
2593                 return null;
2594             }
2595             else {
2596                 return new ACL(p);
2597             }
2598         }
2599     }
2600 
2601     @FieldOrder({"Revision", "Sbz1", "Control", "Owner", "Group", "Sacl", "Dacl"})
2602     public static class SECURITY_DESCRIPTOR_RELATIVE extends Structure {
2603         public static class ByReference extends SECURITY_DESCRIPTOR_RELATIVE
2604                 implements Structure.ByReference {
2605         }
2606 
2607         public byte Revision;
2608         public byte Sbz1;
2609         public short Control;
2610         public int Owner;
2611         public int Group;
2612         public int Sacl;
2613         public int Dacl;
2614 
2615         private PSID OWNER;
2616         private PSID GROUP;
2617         private ACL SACL;
2618         private ACL DACL;
2619 
SECURITY_DESCRIPTOR_RELATIVE()2620         public SECURITY_DESCRIPTOR_RELATIVE() {
2621             super();
2622         }
2623 
SECURITY_DESCRIPTOR_RELATIVE(byte[] data)2624         public SECURITY_DESCRIPTOR_RELATIVE(byte[] data) {
2625             super(new Memory(data.length));
2626             getPointer().write(0, data, 0, data.length);
2627             setMembers();
2628         }
2629 
SECURITY_DESCRIPTOR_RELATIVE(int length)2630         public SECURITY_DESCRIPTOR_RELATIVE(int length) {
2631             super(new Memory(length));
2632         }
2633 
SECURITY_DESCRIPTOR_RELATIVE(Pointer p)2634         public SECURITY_DESCRIPTOR_RELATIVE(Pointer p) {
2635             super(p);
2636             setMembers();
2637         }
2638 
getOwner()2639         public PSID getOwner() {
2640             return OWNER;
2641         }
2642 
getGroup()2643         public PSID getGroup() {
2644             return GROUP;
2645         }
2646 
getDiscretionaryACL()2647         public ACL getDiscretionaryACL() {
2648             return DACL;
2649         }
2650 
getSystemACL()2651         public ACL getSystemACL() {
2652             return SACL;
2653         }
2654 
setMembers()2655         private final void setMembers() {
2656             read();
2657             if (Dacl != 0) {
2658                 DACL = new ACL(getPointer().share(Dacl));
2659             }
2660             if (Sacl != 0) {
2661                 SACL = new ACL(getPointer().share(Sacl));
2662             }
2663             if (Group != 0) {
2664                 GROUP = new PSID(getPointer().share(Group));
2665             }
2666             if (Owner != 0) {
2667                 OWNER = new PSID(getPointer().share(Owner));
2668             }
2669         }
2670     }
2671 
2672     @FieldOrder({"AceType", "AceFlags", "AceSize"})
2673     public static class ACE_HEADER extends Structure {
2674         public byte AceType;
2675         public byte AceFlags;
2676         public short AceSize;
2677 
ACE_HEADER()2678         public ACE_HEADER() {
2679             super();
2680         }
2681 
ACE_HEADER(Pointer p)2682         public ACE_HEADER(Pointer p) {
2683             super(p);
2684             read();
2685         }
2686 
ACE_HEADER(byte AceType, byte AceFlags, short AceSize)2687         public ACE_HEADER(byte AceType, byte AceFlags, short AceSize) {
2688             super();
2689             this.AceType = AceType;
2690             this.AceFlags = AceFlags;
2691             this.AceSize = AceSize;
2692             write();
2693         }
2694     }
2695 
2696     /**
2697      * ACCESS_ALLOWED_ACE and ACCESS_DENIED_ACE have the same structure layout
2698      */
2699     @FieldOrder({"Mask", "SidStart"})
2700     public static abstract class ACCESS_ACEStructure extends ACE_HEADER {
2701         public int Mask;
2702         /**
2703          * First 4 bytes of the SID
2704          * Only used to have a valid field defined - use sid!
2705          */
2706         public byte[] SidStart = new byte[4];
2707 
2708         PSID psid;
2709 
ACCESS_ACEStructure()2710         public ACCESS_ACEStructure() {
2711             super();
2712         }
2713 
ACCESS_ACEStructure(int Mask, byte AceType, byte AceFlags, PSID psid)2714         public ACCESS_ACEStructure(int Mask, byte AceType, byte AceFlags, PSID psid) {
2715             super();
2716             this.calculateSize(true);
2717             this.AceType = AceType;
2718             this.AceFlags = AceFlags;
2719             this.AceSize = (short) (super.fieldOffset("SidStart") + psid.getBytes().length);
2720             this.psid = psid;
2721             this.Mask = Mask;
2722             this.SidStart = psid.getPointer().getByteArray(0, SidStart.length);
2723             this.allocateMemory(AceSize);
2724             write();
2725         }
2726 
ACCESS_ACEStructure(Pointer p)2727         public ACCESS_ACEStructure(Pointer p) {
2728             super(p);
2729             read();
2730         }
2731 
getSidString()2732         public String getSidString() {
2733             return Advapi32Util.convertSidToStringSid(psid);
2734         }
2735 
getSID()2736         public PSID getSID() {
2737             return psid;
2738         }
2739 
2740         /**
2741          * Write override due to psid not being a managed field
2742          */
2743         @Override
write()2744         public void write() {
2745             super.write();
2746             int offsetOfSID = super.fieldOffset("SidStart");
2747             int sizeOfSID = super.AceSize - super.fieldOffset("SidStart");
2748             if(psid != null) {
2749                 // Get bytes from the PSID
2750                 byte[] psidWrite = psid.getBytes();
2751                 assert psidWrite.length <= sizeOfSID;
2752                 // Write those bytes to native memory
2753                 getPointer().write(offsetOfSID, psidWrite, 0, sizeOfSID);
2754             }
2755         }
2756 
2757         @Override
read()2758         public void read() {
2759             if(SidStart == null) {
2760                 SidStart = new byte[4];
2761             }
2762             super.read();
2763             int offsetOfSID = super.fieldOffset("SidStart");
2764             int sizeOfSID = super.AceSize - super.fieldOffset("SidStart");
2765             if(sizeOfSID > 0) {
2766                 psid = new PSID(getPointer().getByteArray(offsetOfSID, sizeOfSID));
2767             } else {
2768                 psid = new PSID();
2769             }
2770         }
2771     }
2772 
2773     /* Access allowed ACE */
2774     public static class ACCESS_ALLOWED_ACE extends ACCESS_ACEStructure {
ACCESS_ALLOWED_ACE()2775         public ACCESS_ALLOWED_ACE() {
2776             super();
2777         }
2778 
ACCESS_ALLOWED_ACE(Pointer p)2779         public ACCESS_ALLOWED_ACE(Pointer p) {
2780             super(p);
2781         }
2782 
ACCESS_ALLOWED_ACE(int Mask, byte AceFlags, PSID psid)2783         public ACCESS_ALLOWED_ACE(int Mask, byte AceFlags, PSID psid) {
2784             super(Mask, ACCESS_ALLOWED_ACE_TYPE, AceFlags, psid);
2785         }
2786     }
2787 
2788     /* Access denied ACE */
2789     public static class ACCESS_DENIED_ACE extends ACCESS_ACEStructure {
ACCESS_DENIED_ACE()2790         public ACCESS_DENIED_ACE() {
2791             super();
2792         }
2793 
ACCESS_DENIED_ACE(Pointer p)2794         public ACCESS_DENIED_ACE(Pointer p) {
2795             super(p);
2796         }
2797 
ACCESS_DENIED_ACE(int Mask, byte AceFlags, PSID psid)2798         public ACCESS_DENIED_ACE(int Mask, byte AceFlags, PSID psid) {
2799             super(Mask, ACCESS_DENIED_ACE_TYPE, AceFlags, psid);
2800         }
2801     }
2802 
2803     /* ACE types */
2804     byte ACCESS_ALLOWED_ACE_TYPE = 0x00;
2805     byte ACCESS_DENIED_ACE_TYPE = 0x01;
2806     byte SYSTEM_AUDIT_ACE_TYPE = 0x02;
2807     byte SYSTEM_ALARM_ACE_TYPE = 0x03;
2808     byte ACCESS_ALLOWED_COMPOUND_ACE_TYPE = 0x04;
2809     byte ACCESS_ALLOWED_OBJECT_ACE_TYPE = 0x05;
2810     byte ACCESS_DENIED_OBJECT_ACE_TYPE = 0x06;
2811     byte SYSTEM_AUDIT_OBJECT_ACE_TYPE = 0x07;
2812     byte SYSTEM_ALARM_OBJECT_ACE_TYPE = 0x08;
2813     byte ACCESS_ALLOWED_CALLBACK_ACE_TYPE = 0x09;
2814     byte ACCESS_DENIED_CALLBACK_ACE_TYPE = 0x0A;
2815     byte ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE = 0x0B;
2816     byte ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE = 0x0C;
2817     byte SYSTEM_AUDIT_CALLBACK_ACE_TYPE = 0x0D;
2818     byte SYSTEM_ALARM_CALLBACK_ACE_TYPE = 0x0E;
2819     byte SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE = 0x0F;
2820     byte SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE = 0x10;
2821     byte SYSTEM_MANDATORY_LABEL_ACE_TYPE = 0x11;
2822 
2823     /* ACE inherit flags */
2824     byte OBJECT_INHERIT_ACE = 0x01;
2825     byte CONTAINER_INHERIT_ACE = 0x02;
2826     byte NO_PROPAGATE_INHERIT_ACE = 0x04;
2827     byte INHERIT_ONLY_ACE = 0x08;
2828     byte INHERITED_ACE = 0x10;
2829     byte VALID_INHERIT_FLAGS = 0x1F;
2830 
2831     // TODO: figure out how OVERLAPPED is used and apply an appropriate mapping
2832     interface OVERLAPPED_COMPLETION_ROUTINE extends StdCallCallback {
callback(int errorCode, int nBytesTransferred, WinBase.OVERLAPPED overlapped)2833         void callback(int errorCode, int nBytesTransferred,
2834                 WinBase.OVERLAPPED overlapped);
2835     }
2836 
2837 
2838     /**
2839      * Defines the mapping of generic access rights to specific and standard access rights for an object
2840      */
2841     @FieldOrder({"genericRead", "genericWrite", "genericExecute", "genericAll"})
2842     public static class GENERIC_MAPPING extends Structure {
2843         public static class ByReference extends GENERIC_MAPPING implements Structure.ByReference {
2844         }
2845 
2846         public DWORD genericRead;
2847         public DWORD genericWrite;
2848         public DWORD genericExecute;
2849         public DWORD genericAll;
2850     }
2851 
2852     /**
2853      * Describes the relationship between the specified processor set. This structure is used with the
2854      * {@link Kernel32#GetLogicalProcessorInformation} function.
2855      */
2856     @FieldOrder({"processorMask", "relationship", "payload"})
2857     public static class SYSTEM_LOGICAL_PROCESSOR_INFORMATION extends Structure {
2858         /**
2859          * The processor mask identifying the processors described by this structure. A processor mask is a bit
2860          * vector in which each set bit represents an active processor in the relationship.
2861          */
2862         public ULONG_PTR processorMask;
2863 
2864         /**
2865          * The relationship between the processors identified by the value of the {@link #processorMask} member.
2866          * This member can be one of
2867          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationCache},
2868          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationNumaNode},
2869          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorCore} or
2870          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorPackage}.
2871          *
2872          * @see LOGICAL_PROCESSOR_RELATIONSHIP
2873          */
2874         public int /* LOGICAL_PROCESSOR_RELATIONSHIP */ relationship;
2875 
2876         /**
2877          * A union of fields which differs depending on {@link #relationship}.
2878          */
2879         public AnonymousUnionPayload payload;
2880 
SYSTEM_LOGICAL_PROCESSOR_INFORMATION()2881         public SYSTEM_LOGICAL_PROCESSOR_INFORMATION() {
2882             super();
2883         }
2884 
SYSTEM_LOGICAL_PROCESSOR_INFORMATION(Pointer memory)2885         public SYSTEM_LOGICAL_PROCESSOR_INFORMATION(Pointer memory) {
2886             super(memory);
2887             read();
2888         }
2889 
2890         public static class AnonymousUnionPayload extends Union {
2891             /**
2892              * Contains valid data only if {@link #relationship} is {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorCore}.
2893              */
2894             public AnonymousStructProcessorCore processorCore;
2895 
2896             /**
2897              * Contains valid data only if {@link #relationship} is {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationNumaNode}.
2898              */
2899             public AnonymousStructNumaNode numaNode;
2900 
2901             /**
2902              * <p>Identifies the characteristics of a particular cache. There is one record returned for each cache
2903              *    reported. Some or all caches may not be reported, depending on how caches are identified. Therefore,
2904              *    do not assume the absence of any particular caches. Caches are not necessarily shared among
2905              *    logical processors.</p>
2906              *
2907              * <p>Contains valid data only if {@link #relationship} is
2908              *    {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationCache}.</p>
2909              *
2910              * <p>This member was not supported until Windows Server 2003 SP1 / Windows XP Professional x64.</p>
2911              */
2912             public CACHE_DESCRIPTOR cache;
2913 
2914             /**
2915              * Reserved. Do not use.
2916              */
2917             public ULONGLONG[] reserved = new ULONGLONG[2];
2918         }
2919 
2920         @FieldOrder({"flags"})
2921         public static class AnonymousStructProcessorCore extends Structure {
2922             /**
2923              * <p>If the value of this mmeber is {@code 1}, the logical processors identified by the value of the
2924              *    {@link #processorMask} member share functional units, as in Hyperthreading or SMT. Otherwise, the
2925              *    identified logical processors do not share functional units.</p>
2926              *
2927              * <p>Note: Prior to Windows Vista, this member is also {@code 1} for cores that share a physical
2928              *    package.</p>
2929              */
2930             public BYTE flags;
2931         }
2932 
2933         @FieldOrder({"nodeNumber"})
2934         public static class AnonymousStructNumaNode extends Structure {
2935             /**
2936              * Identifies the NUMA node. Valid values are {@code 0} to the highest NUMA node number inclusive.
2937              * A non-NUMA multiprocessor system will report that all processors belong to one NUMA node.
2938              */
2939             public DWORD nodeNumber;
2940         }
2941     }
2942 
2943     /**
2944      * Contains information about the relationships of logical processors and
2945      * related hardware. The {@link Kernel32#GetLogicalProcessorInformationEx}
2946      * function uses this structure.
2947      * <p>
2948      * The native structure contains a union, which is mapped to JNA as
2949      * subclasses.
2950      */
2951     @FieldOrder({ "relationship", "size" })
2952     public abstract class SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX extends Structure {
2953 
2954         /**
2955          * The type of relationship between the logical processors. This
2956          * parameter can be one of the following values:
2957          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationCache},
2958          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationGroup},
2959          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationNumaNode},
2960          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorCore}, or
2961          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorPackage}.
2962          * <p>
2963          * This field identifies which subclass will be instantiated by the
2964          * {@link #fromPointer(Pointer)} method.
2965          */
2966         public int /* LOGICAL_PROCESSOR_RELATIONSHIP */ relationship;
2967 
2968         /**
2969          * The size of the structure, in bytes.
2970          */
2971         public int size;
2972 
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX()2973         public SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX() {
2974             super();
2975         }
2976 
2977         /**
2978          * This constructor should only be called by a subclass to ensure memory
2979          * is properly allocated to the subclass fields.
2980          *
2981          * @param memory
2982          *            A pointer to the allocated native memory.
2983          */
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX(Pointer memory)2984         protected SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX(Pointer memory) {
2985             super(memory);
2986         }
2987 
2988         /**
2989          * Create a new instance of the appropriate subclass of
2990          * {@link SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX} from the provided
2991          * {@link Pointer} to native memory. Use this method rather than
2992          * {@link #SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX(Pointer)} to properly
2993          * cast the Pointer to the appropriate subclass and populate variable
2994          * length arrays.
2995          *
2996          * @param memory
2997          *            A pointer to allocated memory to be cast to this class.
2998          * @return An instance of the appropriate subclass depending on the
2999          *         value of the {@link #relationship} field. If the
3000          *         {@link #relationship} member is
3001          *         {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorCore}
3002          *         or
3003          *         {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorPackage},
3004          *         the return type will be {@link PROCESSOR_RELATIONSHIP}. If
3005          *         the {@link #relationship} member is
3006          *         {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationNumaNode}, the
3007          *         return type will be {@link NUMA_NODE_RELATIONSHIP}. If the
3008          *         {@link #relationship} member is
3009          *         {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationCache}, the
3010          *         return type will be {@link CACHE_RELATIONSHIP}. If the
3011          *         {@link #relationship} member is
3012          *         {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationGroup}, the
3013          *         return type will be {@link GROUP_RELATIONSHIP}.
3014          */
fromPointer(Pointer memory)3015         public static SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX fromPointer(Pointer memory) {
3016             int relationship = memory.getInt(0);
3017             SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX result;
3018             switch (relationship) {
3019                 case LOGICAL_PROCESSOR_RELATIONSHIP.RelationProcessorCore:
3020                 case LOGICAL_PROCESSOR_RELATIONSHIP.RelationProcessorPackage:
3021                     result = new PROCESSOR_RELATIONSHIP(memory);
3022                     break;
3023                 case LOGICAL_PROCESSOR_RELATIONSHIP.RelationNumaNode:
3024                     result = new NUMA_NODE_RELATIONSHIP(memory);
3025                     break;
3026                 case LOGICAL_PROCESSOR_RELATIONSHIP.RelationCache:
3027                     result = new CACHE_RELATIONSHIP(memory);
3028                     break;
3029                 case LOGICAL_PROCESSOR_RELATIONSHIP.RelationGroup:
3030                     result = new GROUP_RELATIONSHIP(memory);
3031                     break;
3032                 default:
3033                     throw new IllegalStateException("Unmapped relationship: " + relationship);
3034             }
3035             result.read();
3036             return result;
3037         }
3038     }
3039 
3040     /**
3041      * Describes the logical processors associated with either a processor core
3042      * or a processor package.
3043      */
3044     @FieldOrder({ "flags", "efficiencyClass", "reserved", "groupCount", "groupMask" })
3045     public static class PROCESSOR_RELATIONSHIP extends SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX {
3046 
3047         /**
3048          * If the {@link #relationship} member of the
3049          * {@link SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX} structure is
3050          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorCore}, this
3051          * member is {@link #LTP_PC_SMT} if the core has more than one logical
3052          * processor, or 0 if the core has one logical processor.
3053          * <p>
3054          * If the {@link #relationship} member of the
3055          * {@link SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX} structure is
3056          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorPackage}, this
3057          * member is always 0.
3058          */
3059         public byte flags;
3060 
3061         /**
3062          * If the {@link #relationship} member of the
3063          * {@link SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX} structure is
3064          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorCore},
3065          * EfficiencyClass specifies the intrinsic tradeoff between performance
3066          * and power for the applicable core. A core with a higher value for the
3067          * efficiency class has intrinsically greater performance and less
3068          * efficiency than a core with a lower value for the efficiency class.
3069          * EfficiencyClass is only nonzero on systems with a heterogeneous set
3070          * of cores.
3071          * <p>
3072          * If the {@link #relationship} member of the
3073          * {@link SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX} structure is
3074          * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationProcessorPackage},
3075          * EfficiencyClass is always 0.
3076          * <p>
3077          * The minimum operating system version that supports this member is
3078          * Windows 10.
3079          */
3080         public byte efficiencyClass;
3081 
3082         /**
3083          * This member is reserved.
3084          */
3085         public byte[] reserved = new byte[20];
3086 
3087         /**
3088          * This member specifies the number of entries in the GroupMask array.
3089          * <p>
3090          * If the PROCESSOR_RELATIONSHIP structure represents a processor core,
3091          * the GroupCount member is always 1.
3092          * <p>
3093          * If the {@link PROCESSOR_RELATIONSHIP} structure represents a
3094          * processor package, the {@link #groupCount} member is 1 only if all
3095          * processors are in the same processor group. If the package contains
3096          * more than one NUMA node, the system might assign different NUMA nodes
3097          * to different processor groups. In this case, the {@link #groupCount}
3098          * member is the number of groups to which NUMA nodes in the package are
3099          * assigned.
3100          */
3101         public short groupCount;
3102 
3103         /**
3104          * An array of {@link GROUP_AFFINITY} structures. The
3105          * {@link #groupCount} member specifies the number of structures in the
3106          * array. Each structure in the array specifies a group number and
3107          * processor affinity within the group.
3108          */
3109         public GROUP_AFFINITY[] groupMask = new GROUP_AFFINITY[1];
3110 
PROCESSOR_RELATIONSHIP()3111         public PROCESSOR_RELATIONSHIP() {
3112         }
3113 
PROCESSOR_RELATIONSHIP(Pointer memory)3114         public PROCESSOR_RELATIONSHIP(Pointer memory) {
3115             super(memory);
3116         }
3117 
3118         @Override
read()3119         public void read() {
3120             readField("groupCount");
3121             groupMask = new GROUP_AFFINITY[groupCount];
3122             super.read();
3123         }
3124     }
3125 
3126     /**
3127      * Represents information about a NUMA node in a processor group.
3128      */
3129     @FieldOrder({ "nodeNumber", "reserved", "groupMask" })
3130     public static class NUMA_NODE_RELATIONSHIP extends SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX {
3131 
3132         /**
3133          * Identifies the NUMA node. Valid values are {@code 0} to the highest
3134          * NUMA node number inclusive. A non-NUMA multiprocessor system will
3135          * report that all processors belong to one NUMA node.
3136          */
3137         public int nodeNumber;
3138 
3139         /**
3140          * This member is reserved.
3141          */
3142         public byte[] reserved = new byte[20];
3143 
3144         /**
3145          * A {@link GROUP_AFFINITY} structure that specifies a group number and
3146          * processor affinity within the group.
3147          */
3148         public GROUP_AFFINITY groupMask;
3149 
NUMA_NODE_RELATIONSHIP()3150         public NUMA_NODE_RELATIONSHIP() {
3151         }
3152 
NUMA_NODE_RELATIONSHIP(Pointer memory)3153         public NUMA_NODE_RELATIONSHIP(Pointer memory) {
3154             super(memory);
3155         }
3156     }
3157 
3158     /**
3159      * Describes cache attributes.
3160      */
3161     @FieldOrder({ "level", "associativity", "lineSize", "cacheSize", "type", "reserved", "groupMask" })
3162     public static class CACHE_RELATIONSHIP extends SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX {
3163 
3164         /**
3165          * The cache level. This member can be 1 (L1), 2 (L2), 3 (L3), or 4
3166          * (L4).
3167          */
3168         public byte level;
3169 
3170         /**
3171          * The cache associativity. If this member is
3172          * {@link #CACHE_FULLY_ASSOCIATIVE}, the cache is fully associative.
3173          */
3174         public byte associativity;
3175 
3176         /**
3177          * The cache line size, in bytes.
3178          */
3179         public short lineSize;
3180 
3181         /**
3182          * The cache size, in bytes.
3183          */
3184         public int cacheSize;
3185 
3186         /**
3187          * The cache type. This member is a {@link PROCESSOR_CACHE_TYPE} value.
3188          */
3189         public int /* PROCESSOR_CACHE_TYPE */ type;
3190 
3191         /**
3192          * This member is reserved.
3193          */
3194         public byte[] reserved = new byte[20];
3195 
3196         /**
3197          * A {@link GROUP_AFFINITY} structure that specifies a group number and
3198          * processor affinity within the group.
3199          */
3200         public GROUP_AFFINITY groupMask;
3201 
CACHE_RELATIONSHIP()3202         public CACHE_RELATIONSHIP() {
3203         }
3204 
CACHE_RELATIONSHIP(Pointer memory)3205         public CACHE_RELATIONSHIP(Pointer memory) {
3206             super(memory);
3207         }
3208     }
3209 
3210     /**
3211      * Represents information about processor groups.
3212      */
3213     @FieldOrder({ "maximumGroupCount", "activeGroupCount", "reserved", "groupInfo" })
3214     public static class GROUP_RELATIONSHIP extends SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX {
3215 
3216         /**
3217          * The maximum number of processor groups on the system.
3218          */
3219         public short maximumGroupCount;
3220 
3221         /**
3222          * The number of active groups on the system. This member indicates the
3223          * number of {@link PROCESSOR_GROUP_INFO} structures in the GroupInfo
3224          * array.
3225          */
3226         public short activeGroupCount;
3227 
3228         /**
3229          * This member is reserved.
3230          */
3231         public byte[] reserved = new byte[20];
3232 
3233         /**
3234          * An array of {@link PROCESSOR_GROUP_INFO} structures. The
3235          * {@link #activeGroupCount} member specifies the number of structures
3236          * in the array. Each structure in the array specifies the number and
3237          * affinity of processors in an active group on the system.
3238          */
3239         public PROCESSOR_GROUP_INFO[] groupInfo = new PROCESSOR_GROUP_INFO[1];
3240 
GROUP_RELATIONSHIP()3241         public GROUP_RELATIONSHIP() {
3242         }
3243 
GROUP_RELATIONSHIP(Pointer memory)3244         public GROUP_RELATIONSHIP(Pointer memory) {
3245             super(memory);
3246         }
3247 
3248         @Override
read()3249         public void read() {
3250             readField("activeGroupCount");
3251             groupInfo = new PROCESSOR_GROUP_INFO[activeGroupCount];
3252             super.read();
3253         }
3254     }
3255 
3256     /**
3257      * Represents a processor group-specific affinity, such as the affinity of a
3258      * thread.
3259      */
3260     @FieldOrder({ "mask", "group", "reserved" })
3261     public static class GROUP_AFFINITY extends Structure {
3262 
3263         /**
3264          * A bitmap that specifies the affinity for zero or more processors
3265          * within the specified group.
3266          */
3267         public ULONG_PTR /* KAFFINITY */ mask;
3268 
3269         /**
3270          * The processor group number.
3271          */
3272         public short group;
3273 
3274         /**
3275          * This member is reserved.
3276          */
3277         public short[] reserved = new short[3];
3278 
GROUP_AFFINITY(Pointer memory)3279         public GROUP_AFFINITY(Pointer memory) {
3280             super(memory);
3281         }
3282 
GROUP_AFFINITY()3283         public GROUP_AFFINITY() {
3284             super();
3285         }
3286     }
3287 
3288     /**
3289      * Represents the number and affinity of processors in a processor group.
3290      */
3291     @FieldOrder({ "maximumProcessorCount", "activeProcessorCount", "reserved", "activeProcessorMask" })
3292     public static class PROCESSOR_GROUP_INFO extends Structure {
3293 
3294         /**
3295          * The maximum number of processors in the group.
3296          */
3297         public byte maximumProcessorCount;
3298 
3299         /**
3300          * The number of active processors in the group.
3301          */
3302         public byte activeProcessorCount;
3303 
3304         /**
3305          * This member is reserved.
3306          */
3307         public byte[] reserved = new byte[38];
3308 
3309         /**
3310          * A bitmap that specifies the affinity for zero or more active
3311          * processors within the group.
3312          */
3313         public ULONG_PTR /* KAFFINITY */ activeProcessorMask;
3314 
PROCESSOR_GROUP_INFO(Pointer memory)3315         public PROCESSOR_GROUP_INFO(Pointer memory) {
3316             super(memory);
3317         }
3318 
PROCESSOR_GROUP_INFO()3319         public PROCESSOR_GROUP_INFO() {
3320             super();
3321         }
3322     }
3323 
3324     /**
3325      * Represents the relationship between the processor set identified in the corresponding
3326      * {@link SYSTEM_LOGICAL_PROCESSOR_INFORMATION} or <code>SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX</code> structure.
3327      */
3328     public interface LOGICAL_PROCESSOR_RELATIONSHIP {
3329         /**
3330          * The specified logical processors share a single processor core.
3331          */
3332         int RelationProcessorCore = 0;
3333 
3334         /**
3335          * The specified logical processors are part of the same NUMA node.
3336          */
3337         int RelationNumaNode = 1;
3338 
3339         /**
3340          * <p>The specified logical processors share a cache.</p>
3341          *
3342          * <p>Not supported until Windows Server 2003 SP1 / Windows XP Professional x64.</p>
3343          */
3344         int RelationCache = 2;
3345 
3346         /**
3347          * <p>The specified logical processors share a physical package (a single package socketed or soldered onto a
3348          *    motherboard may contain multiple processor cores or threads, each of which is treated as a separate
3349          *    processor by the operating system.)</p>
3350          *
3351          * <p>Not supported until Windows Server 2003 SP1 / Windows XP Professional x64.</p>
3352          */
3353         int RelationProcessorPackage = 3;
3354 
3355         /**
3356          * <p>The specified logical processors share a single processor group.</p>
3357          *
3358          * <p>Not supported until Windows Server 2008 R2.</p>
3359          */
3360         int RelationGroup = 4;
3361 
3362         /**
3363          * <p>On input, retrieves information about all possible relation types. This value is not used on output.</p>
3364          *
3365          * <p>Not supported until Windows Server 2008 R2.</p>
3366          */
3367         int RelationAll = 0xFFFF;
3368     }
3369 
3370     byte CACHE_FULLY_ASSOCIATIVE = (byte)0xFF;
3371 
3372     /**
3373      * Describes the cache attributes.
3374      */
3375     @FieldOrder({"level", "associativity", "lineSize", "size", "type"})
3376     public static class CACHE_DESCRIPTOR extends Structure {
3377         /**
3378          * The cache level. This member can be 1, 2 or 3, corresponding to L1, L2 or L3 cache, respectively (other
3379          * values may be supported in the future.)
3380          */
3381         public BYTE level;
3382 
3383         /**
3384          * The cache associativity. If this member is {@link #CACHE_FULLY_ASSOCIATIVE}, the cache is fully
3385          * associative.
3386          */
3387         public BYTE associativity;
3388 
3389         /**
3390          * The cache line size, in bytes.
3391          */
3392         public WORD lineSize;
3393 
3394         /**
3395          * The cache size, in bytes.
3396          */
3397         public DWORD size;
3398 
3399         /**
3400          * The cache type.
3401          *
3402          * @see PROCESSOR_CACHE_TYPE
3403          */
3404         public int /* PROCESSOR_CACHE_TYPE */ type;
3405     }
3406 
3407     /**
3408      * Represents the type of processor cache identifier in the corresponding {@link CACHE_DESCRIPTOR} structure.
3409      */
3410     public static abstract class PROCESSOR_CACHE_TYPE {
3411         /**
3412          * The cache is unified.
3413          */
3414         public static int CacheUnified = 0;
3415 
3416         /**
3417          * The cache is for processor instructions.
3418          */
3419         public static int CacheInstruction = 1;
3420 
3421         /**
3422          * The cache is for data.
3423          */
3424         public static int CacheData = 2;
3425 
3426         /**
3427          * The cache is for traces.
3428          */
3429         public static int CacheTrace = 3;
3430     }
3431 
3432     /**
3433      * Defines values that are used to specify system power action types.
3434      */
3435     public interface POWER_ACTION {
3436         int PowerActionNone = 0;
3437         int PowerActionReserved = 1;
3438         int PowerActionSleep = 2;
3439         int PowerActionHibernate = 3;
3440         int PowerActionShutdown = 4;
3441         int PowerActionShutdownReset = 5;
3442         int PowerActionShutdownOff = 6;
3443         int PowerActionWarmEject = 7;
3444         int PowerActionDisplayOff = 8;
3445     }
3446 
3447     /**
3448      * Defines values that are used to specify system power states.
3449      */
3450     public interface SYSTEM_POWER_STATE {
3451         int PowerSystemUnspecified = 0;
3452         int PowerSystemWorking = 1;
3453         int PowerSystemSleeping1 = 2;
3454         int PowerSystemSleeping2 = 3;
3455         int PowerSystemSleeping3 = 4;
3456         int PowerSystemHibernate = 5; // S4
3457         int PowerSystemShutdown = 6; // S5
3458         int PowerSystemMaximum = 7;
3459     }
3460 
3461     /**
3462      * Contains information about the current state of the system battery.
3463      */
3464     @FieldOrder({ "AcOnLine", "BatteryPresent", "Charging", "Discharging", "Spare1", "Tag", "MaxCapacity",
3465             "RemainingCapacity", "Rate", "EstimatedTime", "DefaultAlert1", "DefaultAlert2" })
3466     class SYSTEM_BATTERY_STATE extends Structure {
3467         public byte AcOnLine;
3468         public byte BatteryPresent;
3469         public byte Charging;
3470         public byte Discharging;
3471         public byte[] Spare1 = new byte[3];
3472         public byte Tag;
3473         public int MaxCapacity;
3474         public int RemainingCapacity;
3475         public int Rate;
3476         public int EstimatedTime;
3477         public int DefaultAlert1;
3478         public int DefaultAlert2;
3479 
SYSTEM_BATTERY_STATE(Pointer p)3480         public SYSTEM_BATTERY_STATE(Pointer p) {
3481             super(p);
3482             read();
3483         }
3484 
SYSTEM_BATTERY_STATE()3485         public SYSTEM_BATTERY_STATE() {
3486             super();
3487         }
3488     }
3489 
3490 
3491     /**
3492      * Contains the granularity of the battery capacity.
3493      */
3494     @FieldOrder({ "Granularity", "Capacity" })
3495     class BATTERY_REPORTING_SCALE extends Structure {
3496         public int Granularity;
3497         public int Capacity;
3498     }
3499 
3500     /**
3501      * Contains information about a processor.
3502      */
3503     @FieldOrder({ "Number", "MaxMhz", "CurrentMhz", "MhzLimit", "MaxIdleState", "CurrentIdleState" })
3504     class PROCESSOR_POWER_INFORMATION extends Structure {
3505         public int Number;
3506         public int MaxMhz;
3507         public int CurrentMhz;
3508         public int MhzLimit;
3509         public int MaxIdleState;
3510         public int CurrentIdleState;
3511 
PROCESSOR_POWER_INFORMATION(Pointer p)3512         public PROCESSOR_POWER_INFORMATION(Pointer p) {
3513             super(p);
3514             read();
3515         }
3516 
PROCESSOR_POWER_INFORMATION()3517         public PROCESSOR_POWER_INFORMATION() {
3518             super();
3519         }
3520     }
3521 
3522     /**
3523      * Contains information about the idleness of the system.
3524      */
3525     @FieldOrder({ "MaxIdlenessAllowed", "Idleness", "TimeRemaining", "CoolingMode" })
3526     class SYSTEM_POWER_INFORMATION extends Structure {
3527         public int MaxIdlenessAllowed;
3528         public int Idleness;
3529         public int TimeRemaining;
3530         public byte CoolingMode;
3531 
SYSTEM_POWER_INFORMATION(Pointer p)3532         public SYSTEM_POWER_INFORMATION(Pointer p) {
3533             super(p);
3534             read();
3535         }
3536 
SYSTEM_POWER_INFORMATION()3537         public SYSTEM_POWER_INFORMATION() {
3538             super();
3539         }
3540     }
3541 
3542     /**
3543      * Contains information used to set the system power state.
3544      */
3545     @FieldOrder({ "Action", "Flags", "EventCode" })
3546     class POWER_ACTION_POLICY extends Structure {
3547         public int /* POWER_ACTION */ Action;
3548         public int Flags;
3549         public int EventCode;
3550     }
3551 
3552     /**
3553      * Contains information about system battery drain policy settings.
3554      */
3555     @FieldOrder({ "Enable", "Spare", "BatteryLevel", "PowerPolicy", "MinSystemState" })
3556     class SYSTEM_POWER_LEVEL extends Structure {
3557         public byte Enable;
3558         public byte[] Spare = new byte[3];
3559         public int BatteryLevel;
3560         public POWER_ACTION_POLICY PowerPolicy;
3561         public int /* SYSTEM_POWER_STATE */ MinSystemState;
3562     }
3563 
3564     int NUM_DISCHARGE_POLICIES = 4;
3565 
3566     /**
3567      * Contains information about the current system power policy.
3568      */
3569     @FieldOrder({ "Revision", "PowerButton", "SleepButton", "LidClose", "LidOpenWake", "Reserved", "Idle",
3570             "IdleTimeout", "IdleSensitivity", "DynamicThrottle", "Spare2", "MinSleep", "MaxSleep",
3571             "ReducedLatencySleep", "WinLogonFlags", "Spare3", "DozeS4Timeout", "BroadcastCapacityResolution",
3572             "DischargePolicy", "VideoTimeout", "VideoDimDisplay", "VideoReserved", "SpindownTimeout",
3573             "OptimizeForPower", "FanThrottleTolerance", "ForcedThrottle", "MinThrottle", "OverThrottled" })
3574     class SYSTEM_POWER_POLICY extends Structure {
3575         public int Revision;
3576         public POWER_ACTION_POLICY PowerButton;
3577         public POWER_ACTION_POLICY SleepButton;
3578         public POWER_ACTION_POLICY LidClose;
3579         public int /* SYSTEM_POWER_STATE */ LidOpenWake;
3580         public int Reserved;
3581         public POWER_ACTION_POLICY Idle;
3582         public int IdleTimeout;
3583         public byte IdleSensitivity;
3584         public byte DynamicThrottle;
3585         public byte[] Spare2 = new byte[2];
3586         public int /* SYSTEM_POWER_STATE */ MinSleep;
3587         public int /* SYSTEM_POWER_STATE */ MaxSleep;
3588         public int /* SYSTEM_POWER_STATE */ ReducedLatencySleep;
3589         public int WinLogonFlags;
3590         public int Spare3;
3591         public int DozeS4Timeout;
3592         public int BroadcastCapacityResolution;
3593         public SYSTEM_POWER_LEVEL[] DischargePolicy = new SYSTEM_POWER_LEVEL[NUM_DISCHARGE_POLICIES];
3594         public int VideoTimeout;
3595         public byte VideoDimDisplay;
3596         public int[] VideoReserved = new int[3];
3597         public int SpindownTimeout;
3598         public byte OptimizeForPower;
3599         public byte FanThrottleTolerance;
3600         public byte ForcedThrottle;
3601         public byte MinThrottle;
3602         public POWER_ACTION_POLICY OverThrottled;
3603 
SYSTEM_POWER_POLICY(Pointer p)3604         public SYSTEM_POWER_POLICY(Pointer p) {
3605             super(p);
3606             read();
3607         }
3608 
SYSTEM_POWER_POLICY()3609         public SYSTEM_POWER_POLICY() {
3610             super();
3611         }
3612     }
3613 
3614     /**
3615      * Contains information about the power capabilities of the system.
3616      */
3617     @FieldOrder({ "PowerButtonPresent", "SleepButtonPresent", "LidPresent", "SystemS1", "SystemS2", "SystemS3",
3618             "SystemS4", "SystemS5", "HiberFilePresent", "FullWake", "VideoDimPresent", "ApmPresent", "UpsPresent",
3619             "ThermalControl", "ProcessorThrottle", "ProcessorMinThrottle", "ProcessorMaxThrottle", "FastSystemS4",
3620             "Hiberboot", "WakeAlarmPresent", "AoAc", "DiskSpinDown", "HiberFileType", "AoAcConnectivitySupported",
3621             "spare3", "SystemBatteriesPresent", "BatteriesAreShortTerm", "BatteryScale", "AcOnLineWake", "SoftLidWake",
3622             "RtcWake", "MinDeviceWakeState", "DefaultLowLatencyWake" })
3623     class SYSTEM_POWER_CAPABILITIES extends Structure {
3624         // Misc supported system features
3625         public byte PowerButtonPresent;
3626         public byte SleepButtonPresent;
3627         public byte LidPresent;
3628         public byte SystemS1;
3629         public byte SystemS2;
3630         public byte SystemS3;
3631         public byte SystemS4; // hibernate
3632         public byte SystemS5; // off
3633         public byte HiberFilePresent;
3634         public byte FullWake;
3635         public byte VideoDimPresent;
3636         public byte ApmPresent;
3637         public byte UpsPresent;
3638 
3639         // Processors
3640         public byte ThermalControl;
3641         public byte ProcessorThrottle;
3642         public byte ProcessorMinThrottle;
3643 
3644         // Prior to WinXP, next 5 bytes are ProcessorThrottleScale
3645         // followed by 4 spare bytes
3646         public byte ProcessorMaxThrottle;
3647         public byte FastSystemS4;
3648         public byte Hiberboot;
3649         public byte WakeAlarmPresent;
3650         public byte AoAc;
3651 
3652         // Disk
3653         public byte DiskSpinDown;
3654 
3655         // HiberFile (Pre-Win10 next 2 bytes are spare)
3656         public byte HiberFileType;
3657         public byte AoAcConnectivitySupported;
3658         public byte[] spare3 = new byte[6];
3659 
3660         // System Battery
3661         public byte SystemBatteriesPresent;
3662         public byte BatteriesAreShortTerm;
3663         public BATTERY_REPORTING_SCALE[] BatteryScale = new BATTERY_REPORTING_SCALE[3];
3664 
3665         // Wake
3666         public int /* SYSTEM_POWER_STATE */ AcOnLineWake;
3667         public int /* SYSTEM_POWER_STATE */ SoftLidWake;
3668         public int /* SYSTEM_POWER_STATE */ RtcWake;
3669         public int /* SYSTEM_POWER_STATE */ MinDeviceWakeState;
3670         public int /* SYSTEM_POWER_STATE */ DefaultLowLatencyWake;
3671 
SYSTEM_POWER_CAPABILITIES(Pointer p)3672         public SYSTEM_POWER_CAPABILITIES(Pointer p) {
3673             super(p);
3674             read();
3675         }
3676 
SYSTEM_POWER_CAPABILITIES()3677         public SYSTEM_POWER_CAPABILITIES() {
3678             super();
3679         }
3680     }
3681     /**
3682      * Indicates committed pages for which physical storage has been allocated,
3683      * either in memory or in the paging file on disk.
3684      */
3685     int MEM_COMMIT = 0x1000;
3686 
3687     /**
3688      * Indicates free pages not accessible to the calling process and available to be allocated.
3689      * For free pages, the information in the AllocationBase, AllocationProtect, Protect, and Type members is undefined.
3690      */
3691     int MEM_FREE = 0x10000;
3692 
3693     /**
3694      * Indicates reserved pages where a range of the process's virtual address space is reserved without any physical storage being allocated.
3695      * For reserved pages, the information in the Protect member is undefined.
3696      */
3697     int MEM_RESERVE = 0x2000;
3698 
3699     /**
3700      * Indicates that the memory pages within the region are mapped into the view of an image section.
3701      */
3702     int MEM_IMAGE = 0x1000000;
3703 
3704     /**
3705      * Indicates that the memory pages within the region are mapped into the view of a section.
3706      */
3707     int MEM_MAPPED = 0x40000;
3708 
3709     /**
3710      * Indicates that the memory pages within the region are private (that is, not shared by other processes).
3711      */
3712     int MEM_PRIVATE = 0x20000;
3713 
3714     /**
3715      * Indicates that data in the memory range specified by lpAddress and dwSize
3716      * is no longer of interest. The pages should not be read from or written to
3717      * the paging file. However, the memory block will be used again later, so
3718      * it should not be decommitted.
3719      */
3720     int MEM_RESET = 0x00080000;
3721 
3722     /**
3723      * MEM_RESET_UNDO should only be called on an address range to which
3724      * MEM_RESET was successfully applied earlier. It indicates that the data in
3725      * the specified memory range specified by lpAddress and dwSize is of
3726      * interest to the caller and attempts to reverse the effects of MEM_RESET.
3727      */
3728     int MEM_RESET_UNDO = 0x1000000;
3729 
3730     /**
3731      * Allocates memory using large page support.
3732      * <p>
3733      * The size and alignment must be a multiple of the large-page minimum. To
3734      * obtain this value, use the GetLargePageMinimum function.
3735      * <p>
3736      * If you specify this value, you must also specify MEM_RESERVE and
3737      * MEM_COMMIT.
3738      */
3739     int MEM_LARGE_PAGES = 0x20000000;
3740 
3741     /**
3742      * Reserves an address range that can be used to map Address Windowing
3743      * Extensions (AWE) pages.
3744      * <p>
3745      * This value must be used with MEM_RESERVE and no other values.
3746      */
3747     int MEM_PHYSICAL = 0x00400000;
3748 
3749     /**
3750      * Allocates memory at the highest possible address. This can be slower than
3751      * regular allocations, especially when there are many allocations.
3752      */
3753     int MEM_TOP_DOWN = 0x00100000;
3754 
3755     /**
3756      * To coalesce two adjacent placeholders, specify MEM_RELEASE |
3757      * MEM_COALESCE_PLACEHOLDERS. When you coalesce placeholders, lpAddress and
3758      * dwSize must exactly match those of the placeholder.
3759      */
3760     int MEM_COALESCE_PLACEHOLDERS = 0x00000001;
3761 
3762     /**
3763      * Frees an allocation back to a placeholder (after you've replaced a
3764      * placeholder with a private allocation using VirtualAlloc2 or
3765      * Virtual2AllocFromApp).
3766      * <p>
3767      * To split a placeholder into two placeholders, specify MEM_RELEASE |
3768      * MEM_PRESERVE_PLACEHOLDER.</p>
3769      */
3770     int MEM_PRESERVE_PLACEHOLDER = 0x00000002;
3771 
3772     /**
3773      * Decommits the specified region of committed pages. After the operation,
3774      * the pages are in the reserved state.
3775      * <p>
3776      * The function does not fail if you attempt to decommit an uncommitted
3777      * page. This means that you can decommit a range of pages without first
3778      * determining their current commitment state.
3779      * <p>
3780      * Do not use this value with MEM_RELEASE.
3781      * <p>
3782      * The MEM_DECOMMIT value is not supported when the lpAddress parameter
3783      * provides the base address for an enclave.
3784      */
3785     int MEM_DECOMMIT = 0x4000;
3786 
3787     /**
3788      * Releases the specified region of pages, or placeholder (for a
3789      * placeholder, the address space is released and available for other
3790      * allocations). After the operation, the pages are in the free state.
3791      * <p>
3792      * If you specify this value, dwSize must be 0 (zero), and lpAddress must
3793      * point to the base address returned by the VirtualAllocEx function when
3794      * the region is reserved. The function fails if either of these conditions
3795      * is not met.
3796      * <p>
3797      * If any pages in the region are committed currently, the function first
3798      * decommits, and then releases them.
3799      * <p>
3800      * The function does not fail if you attempt to release pages that are in
3801      * different states, some reserved and some committed. This means that you
3802      * can release a range of pages without first determining the current
3803      * commitment state.
3804      * <p>
3805      * Do not use this value with MEM_DECOMMIT.
3806      */
3807     int MEM_RELEASE = 0x8000;
3808 
3809     @FieldOrder({"baseAddress", "allocationBase", "allocationProtect",
3810                 "regionSize", "state", "protect", "type"})
3811     public static class MEMORY_BASIC_INFORMATION extends Structure {
3812         /**
3813          * A pointer to the base address of the region of pages.
3814          */
3815         public Pointer baseAddress;
3816 
3817         /**
3818          * A pointer to the base address of a range of pages allocated by the VirtualAlloc function.
3819          * The page pointed to by the BaseAddress member is contained within this allocation range.
3820          */
3821         public Pointer allocationBase;
3822 
3823         /**
3824          * The memory protection option when the region was initially allocated.
3825          * This member can be one of the memory protection constants or 0 if the caller does not have access.
3826          */
3827         public DWORD allocationProtect;
3828 
3829         /**
3830          * The size of the region beginning at the base address in which all pages have identical attributes, in bytes.
3831          */
3832         public SIZE_T regionSize;
3833 
3834         /**
3835          * The state of the pages in the region.
3836          * This member can be one of the following values:
3837          *
3838          * MEM_COMMIT,
3839          * MEM_FREE,
3840          * MEM_RESERVE.
3841          */
3842         public DWORD state;
3843 
3844         /**
3845          * The access protection of the pages in the region.
3846          * This member is one of the values listed for the AllocationProtect member.
3847          */
3848         public DWORD protect;
3849 
3850         /**
3851          * The type of pages in the region.
3852          * The following types are defined:
3853          *
3854          * MEM_IMAGE
3855          * MEM_MAPPED
3856          * MEM_PRIVATE
3857          */
3858         public DWORD type;
3859     }
3860 
3861     @FieldOrder({"Length", "ImpersonationLevel", "ContextTrackingMode", "EffectiveOnly"})
3862     public class SECURITY_QUALITY_OF_SERVICE extends Structure {
3863         /** Specifies the size, in bytes, of this structure.
3864          */
3865         public int Length;
3866         /**
3867          * Specifies the information given to the server about the client, and
3868          * how the server may represent, or impersonate, the client. Security
3869          * impersonation levels govern the degree to which a server process can
3870          * act on behalf of a client process. This member is a
3871          * {@link WinNT.SECURITY_IMPERSONATION_LEVEL} enumeration type value.
3872          */
3873         public int ImpersonationLevel;
3874         /**
3875          * Specifies whether the server is to be given a snapshot of the
3876          * client's security context (called static tracking), or is to be
3877          * continually updated to track changes to the client's security context
3878          * (called dynamic tracking). The {@link WinNT#SECURITY_STATIC_TRACKING}
3879          * value specifies static tracking, and the
3880          * {@link WinNT#SECURITY_DYNAMIC_TRACKING} value specifies dynamic
3881          * tracking. Not all communications mechanisms support dynamic tracking;
3882          * those that do not will default to static tracking.
3883          */
3884         public byte ContextTrackingMode;
3885         /**
3886          * Specifies whether the server may enable or disable privileges and
3887          * groups that the client's security context may include.
3888          *
3889          * <p>This is a boolean value. See {@link WinNT#BOOLEAN_TRUE} and
3890          * {@link WinNT#BOOLEAN_FALSE}.</p>
3891          */
3892         public byte EffectiveOnly;
3893 
3894         @Override
write()3895         public void write() {
3896             this.Length = size();
3897             super.write();
3898         }
3899     }
3900 
3901     byte SECURITY_DYNAMIC_TRACKING = (byte) 1;
3902     byte SECURITY_STATIC_TRACKING = (byte) 0;
3903     byte BOOLEAN_TRUE = (byte) 1;
3904     byte BOOLEAN_FALSE = (byte) 0;
3905 
3906     /*
3907      * Primary language IDs.
3908      */
3909     public static final int LANG_NEUTRAL                    = 0x00;
3910     public static final int LANG_INVARIANT                  = 0x7f;
3911 
3912     public static final int LANG_AFRIKAANS                  = 0x36;
3913     public static final int LANG_ALBANIAN                   = 0x1c;
3914     public static final int LANG_ARABIC                     = 0x01;
3915     public static final int LANG_ARMENIAN                   = 0x2b;
3916     public static final int LANG_ASSAMESE                   = 0x4d;
3917     public static final int LANG_AZERI                      = 0x2c;
3918     public static final int LANG_BASQUE                     = 0x2d;
3919     public static final int LANG_BELARUSIAN                 = 0x23;
3920     public static final int LANG_BENGALI                    = 0x45;
3921     public static final int LANG_BULGARIAN                  = 0x02;
3922     public static final int LANG_CATALAN                    = 0x03;
3923     public static final int LANG_CHINESE                    = 0x04;
3924     public static final int LANG_CROATIAN                   = 0x1a;
3925     public static final int LANG_CZECH                      = 0x05;
3926     public static final int LANG_DANISH                     = 0x06;
3927     public static final int LANG_DIVEHI                     = 0x65;
3928     public static final int LANG_DUTCH                      = 0x13;
3929     public static final int LANG_ENGLISH                    = 0x09;
3930     public static final int LANG_ESTONIAN                   = 0x25;
3931     public static final int LANG_FAEROESE                   = 0x38;
3932     public static final int LANG_FARSI                      = 0x29;
3933     public static final int LANG_FINNISH                    = 0x0b;
3934     public static final int LANG_FRENCH                     = 0x0c;
3935     public static final int LANG_GALICIAN                   = 0x56;
3936     public static final int LANG_GEORGIAN                   = 0x37;
3937     public static final int LANG_GERMAN                     = 0x07;
3938     public static final int LANG_GREEK                      = 0x08;
3939     public static final int LANG_GUJARATI                   = 0x47;
3940     public static final int LANG_HEBREW                     = 0x0d;
3941     public static final int LANG_HINDI                      = 0x39;
3942     public static final int LANG_HUNGARIAN                  = 0x0e;
3943     public static final int LANG_ICELANDIC                  = 0x0f;
3944     public static final int LANG_INDONESIAN                 = 0x21;
3945     public static final int LANG_ITALIAN                    = 0x10;
3946     public static final int LANG_JAPANESE                   = 0x11;
3947     public static final int LANG_KANNADA                    = 0x4b;
3948     public static final int LANG_KASHMIRI                   = 0x60;
3949     public static final int LANG_KAZAK                      = 0x3f;
3950     public static final int LANG_KONKANI                    = 0x57;
3951     public static final int LANG_KOREAN                     = 0x12;
3952     public static final int LANG_KYRGYZ                     = 0x40;
3953     public static final int LANG_LATVIAN                    = 0x26;
3954     public static final int LANG_LITHUANIAN                 = 0x27;
3955     public static final int LANG_MACEDONIAN                 = 0x2f;   // the Former Yugoslav Republic of Macedonia
3956     public static final int LANG_MALAY                      = 0x3e;
3957     public static final int LANG_MALAYALAM                  = 0x4c;
3958     public static final int LANG_MANIPURI                   = 0x58;
3959     public static final int LANG_MARATHI                    = 0x4e;
3960     public static final int LANG_MONGOLIAN                  = 0x50;
3961     public static final int LANG_NEPALI                     = 0x61;
3962     public static final int LANG_NORWEGIAN                  = 0x14;
3963     public static final int LANG_ORIYA                      = 0x48;
3964     public static final int LANG_POLISH                     = 0x15;
3965     public static final int LANG_PORTUGUESE                 = 0x16;
3966     public static final int LANG_PUNJABI                    = 0x46;
3967     public static final int LANG_ROMANIAN                   = 0x18;
3968     public static final int LANG_RUSSIAN                    = 0x19;
3969     public static final int LANG_SANSKRIT                   = 0x4f;
3970     public static final int LANG_SERBIAN                    = 0x1a;
3971     public static final int LANG_SINDHI                     = 0x59;
3972     public static final int LANG_SLOVAK                     = 0x1b;
3973     public static final int LANG_SLOVENIAN                  = 0x24;
3974     public static final int LANG_SPANISH                    = 0x0a;
3975     public static final int LANG_SWAHILI                    = 0x41;
3976     public static final int LANG_SWEDISH                    = 0x1d;
3977     public static final int LANG_SYRIAC                     = 0x5a;
3978     public static final int LANG_TAMIL                      = 0x49;
3979     public static final int LANG_TATAR                      = 0x44;
3980     public static final int LANG_TELUGU                     = 0x4a;
3981     public static final int LANG_THAI                       = 0x1e;
3982     public static final int LANG_TURKISH                    = 0x1f;
3983     public static final int LANG_UKRAINIAN                  = 0x22;
3984     public static final int LANG_URDU                       = 0x20;
3985     public static final int LANG_UZBEK                      = 0x43;
3986     public static final int LANG_VIETNAMESE                 = 0x2a;
3987 
3988     /*
3989      * Sublanguage IDs.
3990      *
3991      * The name immediately following SUBLANG_ dictates which primary
3992      * language ID that sublanguage ID can be combined with to form a
3993      * valid language ID.
3994      */
3995     public static final int SUBLANG_NEUTRAL                 = 0x00;    // language neutral
3996     public static final int SUBLANG_DEFAULT                 = 0x01;    // user default
3997     public static final int SUBLANG_SYS_DEFAULT             = 0x02;    // system default
3998 
3999     public static final int SUBLANG_ARABIC_SAUDI_ARABIA     = 0x01;    // Arabic (Saudi Arabia)
4000     public static final int SUBLANG_ARABIC_IRAQ             = 0x02;    // Arabic (Iraq)
4001     public static final int SUBLANG_ARABIC_EGYPT            = 0x03;    // Arabic (Egypt)
4002     public static final int SUBLANG_ARABIC_LIBYA            = 0x04;    // Arabic (Libya)
4003     public static final int SUBLANG_ARABIC_ALGERIA          = 0x05;    // Arabic (Algeria)
4004     public static final int SUBLANG_ARABIC_MOROCCO          = 0x06;    // Arabic (Morocco)
4005     public static final int SUBLANG_ARABIC_TUNISIA          = 0x07;    // Arabic (Tunisia)
4006     public static final int SUBLANG_ARABIC_OMAN             = 0x08;    // Arabic (Oman)
4007     public static final int SUBLANG_ARABIC_YEMEN            = 0x09;    // Arabic (Yemen)
4008     public static final int SUBLANG_ARABIC_SYRIA            = 0x0a;    // Arabic (Syria)
4009     public static final int SUBLANG_ARABIC_JORDAN           = 0x0b;    // Arabic (Jordan)
4010     public static final int SUBLANG_ARABIC_LEBANON          = 0x0c;    // Arabic (Lebanon)
4011     public static final int SUBLANG_ARABIC_KUWAIT           = 0x0d;    // Arabic (Kuwait)
4012     public static final int SUBLANG_ARABIC_UAE              = 0x0e;    // Arabic (U.A.E)
4013     public static final int SUBLANG_ARABIC_BAHRAIN          = 0x0f;    // Arabic (Bahrain)
4014     public static final int SUBLANG_ARABIC_QATAR            = 0x10;    // Arabic (Qatar)
4015     public static final int SUBLANG_AZERI_LATIN             = 0x01;    // Azeri (Latin)
4016     public static final int SUBLANG_AZERI_CYRILLIC          = 0x02;    // Azeri (Cyrillic)
4017     public static final int SUBLANG_CHINESE_TRADITIONAL     = 0x01;    // Chinese (Taiwan)
4018     public static final int SUBLANG_CHINESE_SIMPLIFIED      = 0x02;    // Chinese (PR China)
4019     public static final int SUBLANG_CHINESE_HONGKONG        = 0x03;    // Chinese (Hong Kong S.A.R., P.R.C.)
4020     public static final int SUBLANG_CHINESE_SINGAPORE       = 0x04;    // Chinese (Singapore)
4021     public static final int SUBLANG_CHINESE_MACAU           = 0x05;    // Chinese (Macau S.A.R.)
4022     public static final int SUBLANG_DUTCH                   = 0x01;    // Dutch
4023     public static final int SUBLANG_DUTCH_BELGIAN           = 0x02;    // Dutch (Belgian)
4024     public static final int SUBLANG_ENGLISH_US              = 0x01;    // English (USA)
4025     public static final int SUBLANG_ENGLISH_UK              = 0x02;    // English (UK)
4026     public static final int SUBLANG_ENGLISH_AUS             = 0x03;    // English (Australian)
4027     public static final int SUBLANG_ENGLISH_CAN             = 0x04;    // English (Canadian)
4028     public static final int SUBLANG_ENGLISH_NZ              = 0x05;    // English (New Zealand)
4029     public static final int SUBLANG_ENGLISH_EIRE            = 0x06;    // English (Irish)
4030     public static final int SUBLANG_ENGLISH_SOUTH_AFRICA    = 0x07;    // English (South Africa)
4031     public static final int SUBLANG_ENGLISH_JAMAICA         = 0x08;    // English (Jamaica)
4032     public static final int SUBLANG_ENGLISH_CARIBBEAN       = 0x09;    // English (Caribbean)
4033     public static final int SUBLANG_ENGLISH_BELIZE          = 0x0a;    // English (Belize)
4034     public static final int SUBLANG_ENGLISH_TRINIDAD        = 0x0b;    // English (Trinidad)
4035     public static final int SUBLANG_ENGLISH_ZIMBABWE        = 0x0c;    // English (Zimbabwe)
4036     public static final int SUBLANG_ENGLISH_PHILIPPINES     = 0x0d;    // English (Philippines)
4037     public static final int SUBLANG_FRENCH                  = 0x01;    // French
4038     public static final int SUBLANG_FRENCH_BELGIAN          = 0x02;    // French (Belgian)
4039     public static final int SUBLANG_FRENCH_CANADIAN         = 0x03;    // French (Canadian)
4040     public static final int SUBLANG_FRENCH_SWISS            = 0x04;    // French (Swiss)
4041     public static final int SUBLANG_FRENCH_LUXEMBOURG       = 0x05;    // French (Luxembourg)
4042     public static final int SUBLANG_FRENCH_MONACO           = 0x06;    // French (Monaco)
4043     public static final int SUBLANG_GERMAN                  = 0x01;    // German
4044     public static final int SUBLANG_GERMAN_SWISS            = 0x02;    // German (Swiss)
4045     public static final int SUBLANG_GERMAN_AUSTRIAN         = 0x03;    // German (Austrian)
4046     public static final int SUBLANG_GERMAN_LUXEMBOURG       = 0x04;    // German (Luxembourg)
4047     public static final int SUBLANG_GERMAN_LIECHTENSTEIN    = 0x05;    // German (Liechtenstein)
4048     public static final int SUBLANG_ITALIAN                 = 0x01;    // Italian
4049     public static final int SUBLANG_ITALIAN_SWISS           = 0x02;    // Italian (Swiss)
4050     public static final int SUBLANG_KASHMIRI_SASIA          = 0x02;    // Kashmiri (South Asia)
4051     public static final int SUBLANG_KASHMIRI_INDIA          = 0x02;    // For app compatibility only
4052     public static final int SUBLANG_KOREAN                  = 0x01;    // Korean (Extended Wansung)
4053     public static final int SUBLANG_LITHUANIAN              = 0x01;    // Lithuanian
4054     public static final int SUBLANG_MALAY_MALAYSIA          = 0x01;    // Malay (Malaysia)
4055     public static final int SUBLANG_MALAY_BRUNEI_DARUSSALAM = 0x02;    // Malay (Brunei Darussalam)
4056     public static final int SUBLANG_NEPALI_INDIA            = 0x02;    // Nepali (India)
4057     public static final int SUBLANG_NORWEGIAN_BOKMAL        = 0x01;    // Norwegian (Bokmal)
4058     public static final int SUBLANG_NORWEGIAN_NYNORSK       = 0x02;    // Norwegian (Nynorsk)
4059     public static final int SUBLANG_PORTUGUESE              = 0x02;    // Portuguese
4060     public static final int SUBLANG_PORTUGUESE_BRAZILIAN    = 0x01;    // Portuguese (Brazilian)
4061     public static final int SUBLANG_SERBIAN_LATIN           = 0x02;    // Serbian (Latin)
4062     public static final int SUBLANG_SERBIAN_CYRILLIC        = 0x03;    // Serbian (Cyrillic)
4063     public static final int SUBLANG_SPANISH                 = 0x01;    // Spanish (Castilian)
4064     public static final int SUBLANG_SPANISH_MEXICAN         = 0x02;    // Spanish (Mexican)
4065     public static final int SUBLANG_SPANISH_MODERN          = 0x03;    // Spanish (Spain)
4066     public static final int SUBLANG_SPANISH_GUATEMALA       = 0x04;    // Spanish (Guatemala)
4067     public static final int SUBLANG_SPANISH_COSTA_RICA      = 0x05;    // Spanish (Costa Rica)
4068     public static final int SUBLANG_SPANISH_PANAMA          = 0x06;    // Spanish (Panama)
4069     public static final int SUBLANG_SPANISH_DOMINICAN_REPUBLIC = 0x07; // Spanish (Dominican Republic)
4070     public static final int SUBLANG_SPANISH_VENEZUELA       = 0x08;    // Spanish (Venezuela)
4071     public static final int SUBLANG_SPANISH_COLOMBIA        = 0x09;    // Spanish (Colombia)
4072     public static final int SUBLANG_SPANISH_PERU            = 0x0a;    // Spanish (Peru)
4073     public static final int SUBLANG_SPANISH_ARGENTINA       = 0x0b;    // Spanish (Argentina)
4074     public static final int SUBLANG_SPANISH_ECUADOR         = 0x0c;    // Spanish (Ecuador)
4075     public static final int SUBLANG_SPANISH_CHILE           = 0x0d;    // Spanish (Chile)
4076     public static final int SUBLANG_SPANISH_URUGUAY         = 0x0e;    // Spanish (Uruguay)
4077     public static final int SUBLANG_SPANISH_PARAGUAY        = 0x0f;    // Spanish (Paraguay)
4078     public static final int SUBLANG_SPANISH_BOLIVIA         = 0x10;    // Spanish (Bolivia)
4079     public static final int SUBLANG_SPANISH_EL_SALVADOR     = 0x11;    // Spanish (El Salvador)
4080     public static final int SUBLANG_SPANISH_HONDURAS        = 0x12;    // Spanish (Honduras)
4081     public static final int SUBLANG_SPANISH_NICARAGUA       = 0x13;    // Spanish (Nicaragua)
4082     public static final int SUBLANG_SPANISH_PUERTO_RICO     = 0x14;    // Spanish (Puerto Rico)
4083     public static final int SUBLANG_SWEDISH                 = 0x01;    // Swedish
4084     public static final int SUBLANG_SWEDISH_FINLAND         = 0x02;    // Swedish (Finland)
4085     public static final int SUBLANG_URDU_PAKISTAN           = 0x01;    // Urdu (Pakistan)
4086     public static final int SUBLANG_URDU_INDIA              = 0x02;    // Urdu (India)
4087     public static final int SUBLANG_UZBEK_LATIN             = 0x01;    // Uzbek (Latin)
4088     public static final int SUBLANG_UZBEK_CYRILLIC          = 0x02;    // Uzbek (Cyrillic)
4089 
4090     /*
4091      * Sorting IDs.
4092      */
4093     public static final int SORT_DEFAULT                    = 0x0;     // sorting default
4094 
4095     public static final int SORT_JAPANESE_XJIS              = 0x0;     // Japanese XJIS order
4096     public static final int SORT_JAPANESE_UNICODE           = 0x1;     // Japanese Unicode order
4097 
4098     public static final int SORT_CHINESE_BIG5               = 0x0;     // Chinese BIG5 order
4099     public static final int SORT_CHINESE_PRCP               = 0x0;     // PRC Chinese Phonetic order
4100     public static final int SORT_CHINESE_UNICODE            = 0x1;     // Chinese Unicode order
4101     public static final int SORT_CHINESE_PRC                = 0x2;     // PRC Chinese Stroke Count order
4102     public static final int SORT_CHINESE_BOPOMOFO           = 0x3;     // Traditional Chinese Bopomofo order
4103 
4104     public static final int SORT_KOREAN_KSC                 = 0x0;     // Korean KSC order
4105     public static final int SORT_KOREAN_UNICODE             = 0x1;     // Korean Unicode order
4106 
4107     public static final int SORT_GERMAN_PHONE_BOOK          = 0x1;     // German Phone Book order
4108 
4109     public static final int SORT_HUNGARIAN_DEFAULT          = 0x0;     // Hungarian Default order
4110     public static final int SORT_HUNGARIAN_TECHNICAL        = 0x1;     // Hungarian Technical order
4111 
4112     public static final int SORT_GEORGIAN_TRADITIONAL       = 0x0;     // Georgian Traditional order
4113     public static final int SORT_GEORGIAN_MODERN            = 0x1;     // Georgian Modern order
4114 
4115     public static final int NLS_VALID_LOCALE_MASK = 0x000fffff;
4116 
4117     /**
4118      *  <p>A language ID is a 16 bit value which is the combination of a
4119      *  primary language ID and a secondary language ID.  The bits are
4120      *  allocated as follows:</p>
4121      *
4122      *  <pre>
4123      *       +-----------------------+-------------------------+
4124      *       |     Sublanguage ID    |   Primary Language ID   |
4125      *       +-----------------------+-------------------------+
4126      *        15                   10 9                       0   bit
4127      *  </pre>
4128      *
4129      *  <p>WARNING:  This pattern isn't always follows, Serbina, Bosnian &amp; Croation for example.</p>
4130      *
4131      *  <p>It is recommended that applications test for locale names or actual LCIDs.</p>
4132      *
4133      *  <p>Note that the LANG, SUBLANG construction is not always consistent.
4134      *  The named locale APIs (eg GetLocaleInfoEx) are recommended.</p>
4135      *
4136      *  <p>Language IDs do not exist for all locales</p>
4137      *
4138      *  <p>A locale ID is a 32 bit value which is the combination of a
4139      *  language ID, a sort ID, and a reserved area.  The bits are
4140      * allocated as follows:</p>
4141      *
4142      * <pre>
4143      *   +-------------+---------+-------------------------+
4144      *   |   Reserved  | Sort ID |      Language ID        |
4145      *   +-------------+---------+-------------------------+
4146      *    31         20 19     16 15                      0   bit
4147      * </pre>
4148      *
4149      * <p>WARNING: This pattern isn't always followed (es-ES_tradnl vs es-ES for example)</p>
4150      *
4151      * <p>It is recommended that applications test for locale names or actual LCIDs.</p>
4152      */
4153     public static final class LocaleMacros {
_MAKELCID(int lgid, int srtid)4154         private static final int _MAKELCID(int lgid, int srtid) {
4155             return (srtid << 16) | lgid;
4156         }
4157 
4158         /**
4159          * construct the locale id from a language id and a sort id.
4160          *
4161          * @param lgid language id
4162          * @param srtid sort id
4163          * @return locale id derived from ldig and srtid
4164          */
MAKELCID(int lgid, int srtid)4165         public static final LCID MAKELCID(int lgid, int srtid) {
4166             return new LCID(_MAKELCID(lgid, srtid));
4167         }
4168 
4169         /**
4170          * construct the locale id from a language id, sort id, and sort version.
4171          *
4172          * @param lgid locale id
4173          * @param srtid sort id
4174          * @param ver sort version
4175          * @return locale id derviced from a language id, sort id, and sort version.
4176          */
MAKESORTLCID(int lgid, int srtid, int ver)4177         public static final LCID MAKESORTLCID(int lgid, int srtid, int ver) {
4178             return new LCID(_MAKELCID(lgid, srtid) | (ver << 20));
4179         }
4180 
4181         /**
4182          * extract the language id from a locale id.
4183          *
4184          * @param lcid locale id
4185          * @return extracted language id
4186          */
LANGIDFROMLCID(LCID lcid)4187         public static final int LANGIDFROMLCID(LCID lcid) {
4188             return lcid.intValue() & 0xFFFF;
4189         }
4190 
4191         /**
4192          * extract the sort id from a locale id.
4193          *
4194          * @param lcid locale id
4195          * @return extracted sort id
4196          */
SORTIDFROMLCID(LCID lcid)4197         public static final int SORTIDFROMLCID(LCID lcid) {
4198             return (lcid.intValue() >>> 16) & 0xf;
4199         }
4200 
4201         /**
4202          * extract the sort version from a locale id.
4203          *
4204          * @param lcid locale id
4205          * @return extracted sort version
4206          */
SORTVERSIONFROMLCID(LCID lcid)4207         public static final int SORTVERSIONFROMLCID(LCID lcid) {
4208             return (lcid.intValue() >>> 20) & 0xf;
4209         }
4210 
4211         /**
4212          * Construct language id from a primary language id and a sublanguage id.
4213          *
4214          * @param p primary language ID
4215          * @param s sublanguage ID
4216          * @return constructed language id
4217          */
MAKELANGID(int p, int s)4218         public static final int MAKELANGID(int p, int s) {
4219             return (s << 10) | (p & 0xFFFF);
4220         }
4221 
4222         /**
4223          * Extract primary language id from a language id.
4224          *
4225          * @param lgid language ID
4226          * @return extracted primary language id
4227          */
PRIMARYLANGID(int lgid)4228         public static final int PRIMARYLANGID(int lgid) {
4229             return lgid & 0x3ff;
4230         }
4231 
4232         /**
4233          * Extract sublanguage id from a language id.
4234          *
4235          * @param lgid language ID
4236          * @return extracted sublanguage id
4237          */
SUBLANGID(int lgid)4238         public static final int SUBLANGID(int lgid) {
4239             return (lgid  & 0xFFFF) >>> 10;
4240         }
4241     }
4242 
4243     public static final int  LANG_SYSTEM_DEFAULT   = LocaleMacros.MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT);
4244     public static final int  LANG_USER_DEFAULT     = LocaleMacros.MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
4245 
4246     public static final LCID LOCALE_SYSTEM_DEFAULT = LocaleMacros.MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT);
4247     public static final LCID LOCALE_USER_DEFAULT   = LocaleMacros.MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT);
4248 
4249     public static final LCID LOCALE_NEUTRAL        = LocaleMacros.MAKELCID(LocaleMacros.MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT);
4250 
4251     public static final LCID LOCALE_INVARIANT      = LocaleMacros.MAKELCID(LocaleMacros.MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL), SORT_DEFAULT);
4252 
4253     /**
4254      * The IO_COUNTERS structure contains I/O accounting information for a
4255      * process or a job object. For a job object, the counters include all
4256      * operations performed by all processes that have ever been associated with
4257      * the job, in addition to all processes currently associated with the job.
4258      */
4259     @FieldOrder({"ReadOperationCount", "WriteOperationCount",
4260         "OtherOperationCount", "ReadTransferCount", "WriteTransferCount",
4261         "OtherTransferCount"})
4262     public static class IO_COUNTERS extends Structure {
4263         /**
4264          * The number of read operations performed.
4265          */
4266         public long ReadOperationCount;
4267 
4268         /**
4269          * The number of write operations performed.
4270          */
4271         public long WriteOperationCount;
4272 
4273         /**
4274          * The number of I/O operations performed, other than read and write
4275          * operations.
4276          */
4277         public long OtherOperationCount;
4278 
4279         /**
4280          * The number of bytes read.
4281          */
4282         public long ReadTransferCount;
4283 
4284         /**
4285          * The number of bytes written.
4286          */
4287         public long WriteTransferCount;
4288 
4289         /**
4290          * The number of bytes transferred during operations other than read and
4291          * write operations.
4292          */
4293         public long OtherTransferCount;
4294 
IO_COUNTERS()4295         public IO_COUNTERS() {
4296             super();
4297         }
4298 
IO_COUNTERS(Pointer memory)4299         public IO_COUNTERS(Pointer memory) {
4300             super(memory);
4301         }
4302     }
4303 
4304     public int EVENT_MODIFY_STATE = 0x0002;
4305     public int EVENT_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3);
4306 }
4307