Skip to content

Commit 1924cd1

Browse files
committed
Initial implementation of a PortableExecutableInfo parser.
Just up to the section headers for now.
1 parent 66a3830 commit 1924cd1

14 files changed

Lines changed: 1610 additions & 3 deletions
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
using System;
2+
3+
namespace PSADT.Interop
4+
{
5+
/// <summary>
6+
/// Defines flags that specify the characteristics of a Dynamic Link Library (DLL) image, controlling aspects of its
7+
/// loading, execution, and security behavior in the Windows operating system.
8+
/// </summary>
9+
/// <remarks>Use the values of this enumeration to indicate or query specific features and requirements of
10+
/// a DLL, such as support for address space layout randomization (ASLR), data execution prevention (DEP), control
11+
/// flow guard (CFG), application container compatibility, and other security or compatibility options. These flags
12+
/// correspond directly to the IMAGE_DLL_CHARACTERISTICS field in the Windows Portable Executable (PE) file format
13+
/// and are typically set by the linker or examined by system utilities and loaders. Multiple flags can be combined
14+
/// to represent the full set of characteristics for a given DLL.</remarks>
15+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1028:Enum Storage should be Int32", Justification = "The type is correct for the underlying Win32 API.")]
16+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "These values are precisely as they're defined in the Win32 API.")]
17+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "These values are precisely as they're defined in the Win32 API.")]
18+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1712:Do not prefix enum values with type name", Justification = "These values are precisely as they're defined in the Win32 API.")]
19+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1700:Do not name enum values 'Reserved'", Justification = "These values are precisely as they're defined in the Win32 API.")]
20+
[Flags]
21+
public enum IMAGE_DLL_CHARACTERISTICS : ushort
22+
{
23+
/// <summary>
24+
/// Specifies that the DLL supports high entropy virtual addresses, enabling the use of a larger address space
25+
/// and providing enhanced security through improved address space layout randomization (ASLR).
26+
/// </summary>
27+
/// <remarks>This characteristic is primarily relevant for 64-bit applications running on
28+
/// operating systems that support high entropy virtual addresses. Enabling this flag can help mitigate certain
29+
/// types of security vulnerabilities by making it more difficult for attackers to predict the location of code
30+
/// and data in memory.</remarks>
31+
IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA,
32+
33+
/// <summary>
34+
/// Represents the dynamic base address characteristic for a DLL, indicating that the DLL can be relocated at
35+
/// load time.
36+
/// </summary>
37+
/// <remarks>When this characteristic is set, the operating system can load the DLL at a different
38+
/// address than its preferred base address, which helps avoid address space conflicts with other
39+
/// modules.</remarks>
40+
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE,
41+
42+
/// <summary>
43+
/// Specifies that the DLL enforces code and data integrity checks at load time.
44+
/// </summary>
45+
/// <remarks>This flag enhances the security of the DLL by ensuring that its code and data have
46+
/// not been tampered with. It is part of the IMAGE_DLL_CHARACTERISTICS enumeration and is typically used in
47+
/// scenarios where integrity verification is required to prevent unauthorized modifications.</remarks>
48+
IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY,
49+
50+
/// <summary>
51+
/// Specifies that the DLL is compatible with the NX (No eXecute) processor feature, which helps prevent
52+
/// execution of code in certain areas of memory to enhance security.
53+
/// </summary>
54+
/// <remarks>This flag is part of the IMAGE_DLL_CHARACTERISTICS enumeration and indicates that the
55+
/// DLL supports Data Execution Prevention (DEP). Enabling NX compatibility can help mitigate certain types of
56+
/// security vulnerabilities by marking memory regions as non-executable.</remarks>
57+
IMAGE_DLLCHARACTERISTICS_NX_COMPAT = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_NX_COMPAT,
58+
59+
/// <summary>
60+
/// Specifies that the DLL does not use isolation, allowing it to share resources with other DLLs.
61+
/// </summary>
62+
/// <remarks>This value is used in the context of Windows DLLs to indicate that the DLL can
63+
/// operate without isolation from other DLLs. Disabling isolation may affect resource sharing and loading
64+
/// behavior, and is typically relevant when managing application compatibility or resource access across
65+
/// multiple DLLs.</remarks>
66+
IMAGE_DLLCHARACTERISTICS_NO_ISOLATION = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_NO_ISOLATION,
67+
68+
/// <summary>
69+
/// Specifies that the DLL does not use Structured Exception Handling (SEH).
70+
/// </summary>
71+
/// <remarks>This characteristic indicates that the DLL is not designed to handle exceptions using
72+
/// SEH, which may affect how exceptions are managed in applications that load this DLL.</remarks>
73+
IMAGE_DLLCHARACTERISTICS_NO_SEH = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_NO_SEH,
74+
75+
/// <summary>
76+
/// Specifies that the DLL does not require binding to any other DLLs at load time.
77+
/// </summary>
78+
/// <remarks>This characteristic indicates that the DLL can be loaded without needing to resolve
79+
/// dependencies, which may improve load performance in certain scenarios.</remarks>
80+
IMAGE_DLLCHARACTERISTICS_NO_BIND = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_NO_BIND,
81+
82+
/// <summary>
83+
/// Indicates that the DLL is intended to run within an application container, enabling additional security and
84+
/// isolation constraints.
85+
/// </summary>
86+
/// <remarks>This value is part of the IMAGE_DLL_CHARACTERISTICS enumeration and is used to
87+
/// specify that a DLL supports execution in an application container environment. Application containers are
88+
/// commonly used to restrict the capabilities of applications and enhance security by isolating them from the
89+
/// rest of the system.</remarks>
90+
IMAGE_DLLCHARACTERISTICS_APPCONTAINER = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_APPCONTAINER,
91+
92+
/// <summary>
93+
/// Indicates that the image is a Windows Driver Model (WDM) driver.
94+
/// </summary>
95+
/// <remarks>This value is part of the IMAGE_DLL_CHARACTERISTICS enumeration and is used by the
96+
/// operating system to identify DLLs that implement WDM drivers. Setting this characteristic ensures that the
97+
/// image is loaded and managed according to WDM driver requirements.</remarks>
98+
IMAGE_DLLCHARACTERISTICS_WDM_DRIVER = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_WDM_DRIVER,
99+
100+
/// <summary>
101+
/// Represents the Control Flow Guard (CFG) characteristic for a DLL, indicating that the DLL is protected by
102+
/// control flow guard security features.
103+
/// </summary>
104+
/// <remarks>Control Flow Guard is a security feature that helps prevent indirect call hijacking
105+
/// by validating the target of indirect calls at runtime. This characteristic is set by the linker when CFG is
106+
/// enabled for the DLL.</remarks>
107+
IMAGE_DLLCHARACTERISTICS_GUARD_CF = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_GUARD_CF,
108+
109+
/// <summary>
110+
/// Specifies that the DLL is aware of and can operate correctly in terminal server environments.
111+
/// </summary>
112+
/// <remarks>This constant indicates that the DLL is designed to function properly when loaded in
113+
/// a terminal server context, which may affect its behavior and resource management. Use this flag to ensure
114+
/// compatibility with terminal server features such as session isolation and resource redirection.</remarks>
115+
IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE,
116+
117+
/// <summary>
118+
/// Specifies that the DLL is compatible with Control-flow Enforcement Technology (CET), a security feature
119+
/// supported by modern Windows operating systems.
120+
/// </summary>
121+
/// <remarks>This value is part of the IMAGE_DLL_CHARACTERISTICS enumeration and indicates that
122+
/// the DLL supports CET, which helps protect against certain classes of exploits by enforcing control-flow
123+
/// integrity. Use this flag to ensure compatibility with enhanced security environments on Windows.</remarks>
124+
IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT,
125+
126+
/// <summary>
127+
/// Represents the strict mode compatibility setting for Control-flow Enforcement Technology (CET) in DLL
128+
/// characteristics.
129+
/// </summary>
130+
/// <remarks>This constant is used to indicate that a DLL operates in strict CET compatibility
131+
/// mode. Enabling strict mode may affect how the operating system enforces security features related to
132+
/// control-flow integrity for the DLL.</remarks>
133+
IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT_STRICT_MODE = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT_STRICT_MODE,
134+
135+
/// <summary>
136+
/// Specifies the DLL characteristic that enables relaxed instruction pointer (IP) validation when setting the
137+
/// execution context for a DLL.
138+
/// </summary>
139+
/// <remarks>This characteristic allows for more permissive checks on the instruction pointer
140+
/// during context switching, which can be useful in certain debugging or diagnostic scenarios. Use with
141+
/// caution, as relaxed validation may impact security or application stability.</remarks>
142+
IMAGE_DLLCHARACTERISTICS_EX_CET_SET_CONTEXT_IP_VALIDATION_RELAXED_MODE = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_EX_CET_SET_CONTEXT_IP_VALIDATION_RELAXED_MODE,
143+
144+
/// <summary>
145+
/// Specifies that dynamic APIs are permitted to be called in-process by the DLL.
146+
/// </summary>
147+
/// <remarks>This value is part of the IMAGE_DLLCHARACTERISTICS enumeration and indicates that the
148+
/// DLL supports dynamic APIs that can be invoked from within the same process. This characteristic may be
149+
/// relevant for compatibility or security considerations when loading or interacting with DLLs that expose
150+
/// dynamic APIs.</remarks>
151+
IMAGE_DLLCHARACTERISTICS_EX_CET_DYNAMIC_APIS_ALLOW_IN_PROC = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_EX_CET_DYNAMIC_APIS_ALLOW_IN_PROC,
152+
153+
/// <summary>
154+
/// Represents a reserved DLL characteristic flag corresponding to IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_1.
155+
/// </summary>
156+
/// <remarks>This value is reserved for future use and should not be relied upon in current
157+
/// applications. It is defined by the Windows API for potential compatibility or security features related to
158+
/// Control-flow Enforcement Technology (CET).</remarks>
159+
IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_1 = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_1,
160+
161+
/// <summary>
162+
/// Represents a reserved characteristic for the DLL, specifically the
163+
/// IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_2 value.
164+
/// </summary>
165+
/// <remarks>This field is part of the IMAGE_DLL_CHARACTERISTICS enumeration and is reserved for
166+
/// future use by the Windows operating system. It should not be used or modified in application code.</remarks>
167+
IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_2 = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_2,
168+
169+
/// <summary>
170+
/// Specifies that the DLL supports forward control flow integrity (CFI) compatibility.
171+
/// </summary>
172+
/// <remarks>This value is part of the IMAGE_DLL_CHARACTERISTICS enumeration and indicates that
173+
/// the DLL is compatible with forward CFI, which helps enhance security by ensuring that control flow is
174+
/// maintained as intended.</remarks>
175+
IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT,
176+
177+
/// <summary>
178+
/// Specifies that the DLL is compatible with hot patching, allowing it to be updated in memory without
179+
/// requiring an application restart.
180+
/// </summary>
181+
/// <remarks>This value is part of the IMAGE_DLL_CHARACTERISTICS enumeration and indicates that
182+
/// the DLL supports hot patching. Hot patching enables updates to be applied to the DLL while it is loaded,
183+
/// which can be useful for applying security fixes or updates without interrupting running
184+
/// applications.</remarks>
185+
IMAGE_DLLCHARACTERISTICS_EX_HOTPATCH_COMPATIBLE = Windows.Win32.System.Diagnostics.Debug.IMAGE_DLL_CHARACTERISTICS.IMAGE_DLLCHARACTERISTICS_EX_HOTPATCH_COMPATIBLE,
186+
}
187+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
3+
namespace PSADT.Interop
4+
{
5+
/// <summary>
6+
/// Specifies the characteristics of an image file, such as executability, system file status, and various loading
7+
/// or optimization behaviors.
8+
/// </summary>
9+
/// <remarks>This enumeration defines flags that describe how an image file is handled by the operating
10+
/// system. The values correspond to the IMAGE_FILE_CHARACTERISTICS flags used in the Windows Portable Executable
11+
/// (PE) file format. These flags indicate properties such as whether the file is a DLL, if relocation or debugging
12+
/// information has been stripped, or if the file is intended for a specific system configuration. Some values are
13+
/// obsolete and retained for compatibility with the Win32 API.</remarks>
14+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1028:Enum Storage should be Int32", Justification = "The type is correct for the underlying Win32 API.")]
15+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "These values are precisely as they're defined in the Win32 API.")]
16+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1712:Do not prefix enum values with type name", Justification = "These values are precisely as they're defined in the Win32 API.")]
17+
[Flags]
18+
public enum IMAGE_FILE_CHARACTERISTICS : ushort
19+
{
20+
/// <summary>
21+
/// Relocation information was stripped from the file. The file must be loaded at its preferred base address. If the base address is not available, the loader reports an error.
22+
/// </summary>
23+
IMAGE_FILE_RELOCS_STRIPPED = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_RELOCS_STRIPPED,
24+
25+
/// <summary>
26+
/// The file is executable (there are no unresolved external references).
27+
/// </summary>
28+
IMAGE_FILE_EXECUTABLE_IMAGE = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_EXECUTABLE_IMAGE,
29+
30+
/// <summary>
31+
/// COFF line numbers were stripped from the file.
32+
/// </summary>
33+
IMAGE_FILE_LINE_NUMS_STRIPPED = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_LINE_NUMS_STRIPPED,
34+
35+
/// <summary>
36+
/// COFF symbol table entries were stripped from file.
37+
/// </summary>
38+
IMAGE_FILE_LOCAL_SYMS_STRIPPED = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_LOCAL_SYMS_STRIPPED,
39+
40+
/// <summary>
41+
/// Aggressively trim the working set. This value is obsolete.
42+
/// </summary>
43+
IMAGE_FILE_AGGRESIVE_WS_TRIM = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_AGGRESIVE_WS_TRIM,
44+
45+
/// <summary>
46+
/// The application can handle addresses larger than 2 GB.
47+
/// </summary>
48+
IMAGE_FILE_LARGE_ADDRESS_AWARE = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_LARGE_ADDRESS_AWARE,
49+
50+
/// <summary>
51+
/// The bytes of the word are reversed. This flag is obsolete.
52+
/// </summary>
53+
IMAGE_FILE_BYTES_REVERSED_LO = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_BYTES_REVERSED_LO,
54+
55+
/// <summary>
56+
/// The computer supports 32-bit words.
57+
/// </summary>
58+
IMAGE_FILE_32BIT_MACHINE = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_32BIT_MACHINE,
59+
60+
/// <summary>
61+
/// Debugging information was removed and stored separately in another file.
62+
/// </summary>
63+
IMAGE_FILE_DEBUG_STRIPPED = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_DEBUG_STRIPPED,
64+
65+
/// <summary>
66+
/// If the image is on removable media, copy it to and run it from the swap file.
67+
/// </summary>
68+
IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP,
69+
70+
/// <summary>
71+
/// If the image is on the network, copy it to and run it from the swap file.
72+
/// </summary>
73+
IMAGE_FILE_NET_RUN_FROM_SWAP = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_NET_RUN_FROM_SWAP,
74+
75+
/// <summary>
76+
/// The image is a system file.
77+
/// </summary>
78+
IMAGE_FILE_SYSTEM = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_SYSTEM,
79+
80+
/// <summary>
81+
/// The image is a DLL file. While it is an executable file, it cannot be run directly.
82+
/// </summary>
83+
IMAGE_FILE_DLL = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_DLL,
84+
85+
/// <summary>
86+
/// The file should be run only on a uniprocessor computer.
87+
/// </summary>
88+
IMAGE_FILE_UP_SYSTEM_ONLY = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_UP_SYSTEM_ONLY,
89+
90+
/// <summary>
91+
/// The bytes of the word are reversed. This flag is obsolete.
92+
/// </summary>
93+
IMAGE_FILE_BYTES_REVERSED_HI = Windows.Win32.System.Diagnostics.Debug.IMAGE_FILE_CHARACTERISTICS.IMAGE_FILE_BYTES_REVERSED_HI,
94+
}
95+
}

0 commit comments

Comments
 (0)