forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPEOffsets.cs
More file actions
63 lines (54 loc) · 2.14 KB
/
PEOffsets.cs
File metadata and controls
63 lines (54 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.NET.HostModel;
/// <summary>
/// Offsets and constants of PE file. see https://learn.microsoft.com/windows/win32/debug/pe-format
/// </summary>
internal static class PEOffsets
{
private const int PESignatureSize = sizeof(int);
private const int CoffHeaderSize = 20;
public const ushort DosImageSignature = 0x5A4D;
public const int PEHeaderSize = PESignatureSize + CoffHeaderSize;
public const int OneSectionHeaderSize = 40;
public const int DataDirectoryEntrySize = 8;
public const int ResourceTableDataDirectoryIndex = 2;
public static class DosStub
{
public const int PESignatureOffset = 0x3c;
}
/// offsets relative to Lfanew, which is pointer to first byte in header
public static class PEHeader
{
public const int NumberOfSections = PESignatureSize + 2;
private const int OptionalHeaderBase = PESignatureSize + CoffHeaderSize;
public const int InitializedDataSize = OptionalHeaderBase + 8;
public const int SizeOfImage = OptionalHeaderBase + 56;
public const int Subsystem = OptionalHeaderBase + 68;
public const int PE64DataDirectories = OptionalHeaderBase + 112;
public const int PE32DataDirectories = OptionalHeaderBase + 96;
}
/// offsets relative to each section header
public static class SectionHeader
{
public const int VirtualSize = 8;
public const int VirtualAddress = 12;
public const int RawSize = 16;
public const int RawPointer = 20;
public const int RelocationsPointer = 24;
public const int LineNumbersPointer = 28;
public const int NumberOfRelocations = 32;
public const int NumberOfLineNumbers = 34;
public const int SectionCharacteristics = 36;
}
public static class DataDirectoryEntry
{
public const int VirtualAddressOffset = 0;
public const int SizeOffset = 4;
}
public enum Subsystem : ushort
{
WindowsGui = 2,
WindowsCui = 3,
}
}