Skip to content

Commit 9f800fc

Browse files
Add documentation for PEHeader (dotnet#8650)
1 parent 124d993 commit 9f800fc

File tree

5 files changed

+109
-35
lines changed

5 files changed

+109
-35
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection.PortableExecutable;
4+
5+
namespace PEHeaderSnippets
6+
{
7+
class PEHeaderSnippets
8+
{
9+
static void ExampleReadPEHeader()
10+
{
11+
//<SnippetReadPEHeader>
12+
// Open the Portable Executable (PE) file
13+
using var fs = new FileStream(@"Example.dll", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
14+
using var peReader = new PEReader(fs);
15+
16+
// Display PE header information
17+
PEHeader header = peReader.PEHeaders.PEHeader;
18+
Console.WriteLine($"Image size, bytes: {header.SizeOfImage}");
19+
Console.WriteLine($"Image base: 0x{header.ImageBase:X}");
20+
Console.WriteLine($"File alignment: 0x{header.FileAlignment:X}");
21+
Console.WriteLine($"Section alignment: 0x{header.SectionAlignment:X}");
22+
Console.WriteLine($"Subsystem: {header.Subsystem}");
23+
Console.WriteLine($"Dll characteristics: {header.DllCharacteristics}");
24+
Console.WriteLine($"Linker version: {header.MajorLinkerVersion}.{header.MinorLinkerVersion}");
25+
Console.WriteLine($"OS version: {header.MajorOperatingSystemVersion}.{header.MinorOperatingSystemVersion}");
26+
//</SnippetReadPEHeader>
27+
}
28+
29+
public static void Run()
30+
{
31+
ExampleReadPEHeader();
32+
}
33+
}
34+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace PEHeaderSnippets
4+
{
5+
class Program
6+
{
7+
static void Main()
8+
{
9+
PEHeaderSnippets.Run();
10+
}
11+
}
12+
}

xml/System.Reflection.PortableExecutable/PEHeader.xml

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,20 @@
2323
</Base>
2424
<Interfaces />
2525
<Docs>
26-
<summary>To be added.</summary>
27-
<remarks>To be added.</remarks>
26+
<summary>Represents the Portable Executable (PE) file header.</summary>
27+
<remarks>
28+
<format type="text/markdown"><![CDATA[
29+
30+
## Remarks
31+
The PE file header format is defined by the [PE specification](/windows/win32/debug/pe-format). This class is used by the <xref:System.Reflection.PortableExecutable.PEHeaders.PEHeader> property.
32+
33+
## Examples
34+
This example shows how to read information from the PE header:
35+
36+
:::code language="csharp" source="~/snippets/csharp/System.Reflection.PortableExecutable/PEHeader/Overview/PEHeaderSnippets.cs" id="SnippetReadPEHeader":::
37+
38+
]]></format>
39+
</remarks>
2840
</Docs>
2941
<Members>
3042
<Member MemberName="AddressOfEntryPoint">
@@ -150,8 +162,8 @@ For program images, this is the starting address. For device drivers, this is th
150162
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
151163
</ReturnValue>
152164
<Docs>
153-
<summary>To be added.</summary>
154-
<value>To be added.</value>
165+
<summary>Gets the Base Relocations Table entry.</summary>
166+
<value>The Base Relocations Table entry.</value>
155167
<remarks>
156168
<format type="text/markdown"><![CDATA[
157169
@@ -188,8 +200,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_BASERELOC`.
188200
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
189201
</ReturnValue>
190202
<Docs>
191-
<summary>To be added.</summary>
192-
<value>To be added.</value>
203+
<summary>Gets the Bound Import Table entry.</summary>
204+
<value>The Bound Import Table entry.</value>
193205
<remarks>
194206
<format type="text/markdown"><![CDATA[
195207
@@ -296,8 +308,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_SECURITY`.
296308
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
297309
</ReturnValue>
298310
<Docs>
299-
<summary>To be added.</summary>
300-
<value>To be added.</value>
311+
<summary>Gets the Copyright Table entry.</summary>
312+
<value>The Copyright Table entry.</value>
301313
<remarks>
302314
<format type="text/markdown"><![CDATA[
303315
@@ -334,14 +346,14 @@ Represents `IMAGE_DIRECTORY_ENTRY_COPYRIGHT` or `IMAGE_DIRECTORY_ENTRY_ARCHITECT
334346
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
335347
</ReturnValue>
336348
<Docs>
337-
<summary>To be added.</summary>
338-
<value>To be added.</value>
349+
<summary>Gets the CLI Header Table entry.</summary>
350+
<value>The CLI Header Table entry.</value>
339351
<remarks>
340352
<format type="text/markdown"><![CDATA[
341353
342354
## Remarks
343355
344-
Represents `IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR`.
356+
The CLI Header contains information and data directories used by the .NET runtime. The CLI Header format is defined by the [ECMA-335 specification](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), section II.25.3.3.
345357
346358
]]></format>
347359
</remarks>
@@ -372,8 +384,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR`.
372384
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
373385
</ReturnValue>
374386
<Docs>
375-
<summary>To be added.</summary>
376-
<value>To be added.</value>
387+
<summary>Gets the Debug Table entry.</summary>
388+
<value>The Debug Table entry.</value>
377389
<remarks>
378390
<format type="text/markdown"><![CDATA[
379391
@@ -410,8 +422,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_DEBUG`.
410422
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
411423
</ReturnValue>
412424
<Docs>
413-
<summary>To be added.</summary>
414-
<value>To be added.</value>
425+
<summary>Gets the Delay-Load Import Table entry.</summary>
426+
<value>The Delay-Load Import Table entry.</value>
415427
<remarks>
416428
<format type="text/markdown"><![CDATA[
417429
@@ -448,8 +460,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT`.
448460
<ReturnType>System.Reflection.PortableExecutable.DllCharacteristics</ReturnType>
449461
</ReturnValue>
450462
<Docs>
451-
<summary>To be added.</summary>
452-
<value>To be added.</value>
463+
<summary>Gets the characteristics of a dynamic link library.</summary>
464+
<value>A bitwise combination of flags that represents the characteristics of a dynamic link library.</value>
453465
<remarks>To be added.</remarks>
454466
</Docs>
455467
</Member>
@@ -478,8 +490,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT`.
478490
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
479491
</ReturnValue>
480492
<Docs>
481-
<summary>To be added.</summary>
482-
<value>To be added.</value>
493+
<summary>Gets the Exception Table entry.</summary>
494+
<value>The Exception Table entry.</value>
483495
<remarks>
484496
<format type="text/markdown"><![CDATA[
485497
@@ -516,8 +528,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_EXCEPTION`.
516528
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
517529
</ReturnValue>
518530
<Docs>
519-
<summary>To be added.</summary>
520-
<value>To be added.</value>
531+
<summary>Gets the Export Table entry.</summary>
532+
<value>The Export Table entry.</value>
521533
<remarks>
522534
<format type="text/markdown"><![CDATA[
523535
@@ -592,8 +604,8 @@ If the <xref:System.Reflection.PortableExecutable.PEHeader.SectionAlignment> is
592604
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
593605
</ReturnValue>
594606
<Docs>
595-
<summary>To be added.</summary>
596-
<value>To be added.</value>
607+
<summary>Gets the Global Pointer Table entry.</summary>
608+
<value>The Global Pointer Table entry.</value>
597609
<remarks>
598610
<format type="text/markdown"><![CDATA[
599611
@@ -660,8 +672,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_GLOBALPTR`.
660672
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
661673
</ReturnValue>
662674
<Docs>
663-
<summary>To be added.</summary>
664-
<value>To be added.</value>
675+
<summary>Gets the Import Address Table entry.</summary>
676+
<value>The Import Address Table entry.</value>
665677
<remarks>
666678
<format type="text/markdown"><![CDATA[
667679
@@ -698,8 +710,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_IAT`.
698710
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
699711
</ReturnValue>
700712
<Docs>
701-
<summary>To be added.</summary>
702-
<value>To be added.</value>
713+
<summary>Gets the Import Table entry.</summary>
714+
<value>The Import Table entry.</value>
703715
<remarks>
704716
<format type="text/markdown"><![CDATA[
705717
@@ -736,8 +748,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_IMPORT`.
736748
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
737749
</ReturnValue>
738750
<Docs>
739-
<summary>To be added.</summary>
740-
<value>To be added.</value>
751+
<summary>Gets the Load Configuration Table entry.</summary>
752+
<value>The Load Configuration Table entry.</value>
741753
<remarks>
742754
<format type="text/markdown"><![CDATA[
743755
@@ -1074,8 +1086,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG`.
10741086
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
10751087
</ReturnValue>
10761088
<Docs>
1077-
<summary>To be added.</summary>
1078-
<value>To be added.</value>
1089+
<summary>Gets the Resource Table entry.</summary>
1090+
<value>The Resource Table entry.</value>
10791091
<remarks>
10801092
<format type="text/markdown"><![CDATA[
10811093
@@ -1413,7 +1425,7 @@ Represents `IMAGE_DIRECTORY_ENTRY_RESOURCE`.
14131425
</ReturnValue>
14141426
<Docs>
14151427
<summary>Gets the name of the subsystem that is required to run this image.</summary>
1416-
<value>the name of the subsystem that is required to run this image.</value>
1428+
<value>The name of the subsystem that is required to run this image.</value>
14171429
<remarks>To be added.</remarks>
14181430
</Docs>
14191431
</Member>
@@ -1442,8 +1454,8 @@ Represents `IMAGE_DIRECTORY_ENTRY_RESOURCE`.
14421454
<ReturnType>System.Reflection.PortableExecutable.DirectoryEntry</ReturnType>
14431455
</ReturnValue>
14441456
<Docs>
1445-
<summary>To be added.</summary>
1446-
<value>To be added.</value>
1457+
<summary>Gets the Thread-Local Storage Table entry.</summary>
1458+
<value>The Thread-Local Storage Table entry.</value>
14471459
<remarks>
14481460
<format type="text/markdown"><![CDATA[
14491461

xml/System.Reflection.PortableExecutable/PEHeaders.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,15 @@
508508
<Docs>
509509
<summary>Gets the image's PE header.</summary>
510510
<value>The image's PE header, or <see langword="null" /> if the image is COFF only.</value>
511-
<remarks>To be added.</remarks>
511+
<remarks>
512+
<format type="text/markdown"><![CDATA[
513+
514+
## Remarks
515+
516+
For more information and an example, see the <xref:System.Reflection.PortableExecutable.PEHeader> class documentation.
517+
518+
]]></format>
519+
</remarks>
512520
</Docs>
513521
</Member>
514522
<Member MemberName="PEHeaderStartOffset">

0 commit comments

Comments
 (0)