1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// found in the LICENSE file.
4d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
5d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)using System;
6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)using System.Collections.Generic;
7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)using System.Linq;
8d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)using System.Runtime.InteropServices;
9d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)using System.Text;
10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)using System.Threading.Tasks;
11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace ChromeDebug.LowLevel {
13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Defines structures, enumerations, and types used by Win32 API calls.  In some cases, the API
14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // calls support (and even document) many more values than what are listed here.  Should
15d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // additional values be required, they can be added to the respective types.
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  public static class LowLevelTypes {
17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    #region Constants and Enums
19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Represents the image format of a DLL or executable.
20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum ImageFormat {
21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      NATIVE,
22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      MANAGED,
23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      UNKNOWN
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Flags used for opening a file handle (e.g. in a call to CreateFile), that determine the
27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // requested permission level.
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    [Flags]
29d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum FileAccessFlags : uint {
30d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      GENERIC_WRITE = 0x40000000,
31d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      GENERIC_READ = 0x80000000
32d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
33d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
34d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Value used for CreateFile to determine how to behave in the presence (or absence) of a
35d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // file with the requested name.  Used only for CreateFile.
36d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum FileCreationDisposition : uint {
37d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      CREATE_NEW = 1,
38d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      CREATE_ALWAYS = 2,
39d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      OPEN_EXISTING = 3,
40d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      OPEN_ALWAYS = 4,
41d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      TRUNCATE_EXISTING = 5
42d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
44d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Flags that determine what level of sharing this application requests on the target file.
45d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Used only for CreateFile.
46d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    [Flags]
47d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum FileShareFlags : uint {
48d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      EXCLUSIVE_ACCESS = 0x0,
49d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      SHARE_READ = 0x1,
50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      SHARE_WRITE = 0x2,
51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      SHARE_DELETE = 0x4
52d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
54d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Flags that control caching and other behavior of the underlying file object.  Used only for
55d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // CreateFile.
56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    [Flags]
57d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum FileFlagsAndAttributes : uint {
58d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      NORMAL = 0x80,
59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      OPEN_REPARSE_POINT = 0x200000,
60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      SEQUENTIAL_SCAN = 0x8000000,
61d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      RANDOM_ACCESS = 0x10000000,
62d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      NO_BUFFERING = 0x20000000,
63d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      OVERLAPPED = 0x40000000
64d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
65d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // The target architecture of a given executable image.  The various values correspond to the
67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // magic numbers defined by the PE Executable Image File Format.
68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum MachineType : ushort {
70d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      UNKNOWN = 0x0,
71d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      X64 = 0x8664,
72d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      X86 = 0x14c,
73d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      IA64 = 0x200
74d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
75d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
76d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // A flag indicating the format of the path string that Windows returns from a call to
77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // QueryFullProcessImageName().
78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum ProcessQueryImageNameMode : uint {
79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      WIN32_FORMAT = 0,
80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      NATIVE_SYSTEM_FORMAT = 1
81d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
83d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Flags indicating the level of permission requested when opening a handle to an external
84d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // process.  Used by OpenProcess().
85d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    [Flags]
86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum ProcessAccessFlags : uint {
87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      NONE = 0x0,
88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      ALL = 0x001F0FFF,
89d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      VM_OPERATION = 0x00000008,
90d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      VM_READ = 0x00000010,
91d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      QUERY_INFORMATION = 0x00000400,
92d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      QUERY_LIMITED_INFORMATION = 0x00001000
93d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
94d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
95d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Defines return value codes used by various Win32 System APIs.
96d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum NTSTATUS : int {
97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      SUCCESS = 0,
98d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
99d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
100d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Determines the amount of information requested (and hence the type of structure returned)
101d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // by a call to NtQueryInformationProcess.
102d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public enum PROCESSINFOCLASS : int {
103d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      PROCESS_BASIC_INFORMATION = 0
104d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    };
1058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    [Flags]
1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    public enum SHGFI : uint {
1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      Icon = 0x000000100,
1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      DisplayName = 0x000000200,
1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      TypeName = 0x000000400,
1118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      Attributes = 0x000000800,
1128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      IconLocation = 0x000001000,
1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      ExeType = 0x000002000,
1148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      SysIconIndex = 0x000004000,
1158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      LinkOverlay = 0x000008000,
1168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      Selected = 0x000010000,
1178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      Attr_Specified = 0x000020000,
1188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      LargeIcon = 0x000000000,
1198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      SmallIcon = 0x000000001,
1208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      OpenIcon = 0x000000002,
1218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      ShellIconSize = 0x000000004,
1228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      PIDL = 0x000000008,
1238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      UseFileAttributes = 0x000000010,
1248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      AddOverlays = 0x000000020,
1258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      OverlayIndex = 0x000000040,
1268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    }
127d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    #endregion
128d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
129d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    #region Structures
130d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // In general, for all structures below which contains a pointer (represented here by IntPtr),
131d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // the pointers refer to memory in the address space of the process from which the original
132d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // structure was read.  While this seems obvious, it means we cannot provide an elegant
133d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // interface to the various fields in the structure due to the de-reference requiring a
134d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // handle to the target process.  Instead, that functionality needs to be provided at a
135d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // higher level.
136d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    //
137d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Additionally, since we usually explicitly define the fields that we're interested in along
138d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // with their respective offsets, we frequently specify the exact size of the native structure.
139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
140d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Win32 UNICODE_STRING structure.
141d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    [StructLayout(LayoutKind.Sequential)]
142d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public struct UNICODE_STRING {
143d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      // The length in bytes of the string pointed to by buffer, not including the null-terminator.
144d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private ushort length;
145d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      // The total allocated size in memory pointed to by buffer.
146d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private ushort maximumLength;
147d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      // A pointer to the buffer containing the string data.
148d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private IntPtr buffer;
149d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
150d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public ushort Length { get { return length; } }
151d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public ushort MaximumLength { get { return maximumLength; } }
152d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public IntPtr Buffer { get { return buffer; } }
153d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
154d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
155d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Win32 RTL_USER_PROCESS_PARAMETERS structure.
156d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    [StructLayout(LayoutKind.Explicit, Size = 72)]
157d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public struct RTL_USER_PROCESS_PARAMETERS {
158d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      [FieldOffset(56)]
159d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private UNICODE_STRING imagePathName;
160d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      [FieldOffset(64)]
161d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private UNICODE_STRING commandLine;
162d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
163d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public UNICODE_STRING ImagePathName { get { return imagePathName; } }
164d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public UNICODE_STRING CommandLine { get { return commandLine; } }
165d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    };
166d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
167d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Win32 PEB structure.  Represents the process environment block of a process.
168d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    [StructLayout(LayoutKind.Explicit, Size = 472)]
169d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public struct PEB {
170d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      [FieldOffset(2), MarshalAs(UnmanagedType.U1)]
171d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private bool isBeingDebugged;
172d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      [FieldOffset(12)]
173d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private IntPtr ldr;
174d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      [FieldOffset(16)]
175d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private IntPtr processParameters;
176d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      [FieldOffset(468)]
177d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private uint sessionId;
178d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
179d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public bool IsBeingDebugged { get { return isBeingDebugged; } }
180d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public IntPtr Ldr { get { return ldr; } }
181d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public IntPtr ProcessParameters { get { return processParameters; } }
182d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public uint SessionId { get { return sessionId; } }
183d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    };
184d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
185d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // Win32 PROCESS_BASIC_INFORMATION.  Contains a pointer to the PEB, and various other
186d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // information about a process.
187d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    [StructLayout(LayoutKind.Explicit, Size = 24)]
188d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    public struct PROCESS_BASIC_INFORMATION {
189d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      [FieldOffset(4)]
190d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private IntPtr pebBaseAddress;
191d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      [FieldOffset(16)]
192d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      private UIntPtr uniqueProcessId;
193d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
194d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public IntPtr PebBaseAddress { get { return pebBaseAddress; } }
195d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      public UIntPtr UniqueProcessId { get { return uniqueProcessId; } }
196d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
1998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    public struct SHFILEINFO {
2008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      // C# doesn't support overriding the default constructor of value types, so we need to use
2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      // a dummy constructor.
2028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      public SHFILEINFO(bool dummy) {
2038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        hIcon = IntPtr.Zero;
2048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        iIcon = 0;
2058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        dwAttributes = 0;
2068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        szDisplayName = "";
2078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        szTypeName = "";
2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      }
2098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      public IntPtr hIcon;
2108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      public int iIcon;
2118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      public uint dwAttributes;
2128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
2138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      public string szDisplayName;
2148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
2158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      public string szTypeName;
2168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    };
217d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    #endregion
218d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
219d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
220