2022-11-04 21:05:03 -07:00
|
|
|
namespace BurnOutSharp.Models.PortableExecutable
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The following list describes the Microsoft PE executable format, with the
|
|
|
|
|
/// base of the image header at the top. The section from the MS-DOS 2.0
|
|
|
|
|
/// Compatible EXE Header through to the unused section just before the PE header
|
|
|
|
|
/// is the MS-DOS 2.0 Section, and is used for MS-DOS compatibility only.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <see href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format"/>
|
|
|
|
|
public class Executable
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// MS-DOS executable stub
|
|
|
|
|
/// </summary>
|
|
|
|
|
public MSDOS.Executable Stub { get; set; }
|
2022-11-04 23:25:02 -07:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// After the MS-DOS stub, at the file offset specified at offset 0x3c, is a 4-byte
|
|
|
|
|
/// signature that identifies the file as a PE format image file. This signature is "PE\0\0"
|
|
|
|
|
/// (the letters "P" and "E" followed by two null bytes).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] Signature { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// COFF file header
|
|
|
|
|
/// </summary>
|
|
|
|
|
public COFFFileHeader COFFFileHeader { get; set; }
|
2022-11-04 23:41:31 -07:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Optional header
|
|
|
|
|
/// </summary>
|
2022-11-04 23:56:56 -07:00
|
|
|
public OptionalHeader OptionalHeader { get; set; }
|
|
|
|
|
|
2022-11-09 21:55:15 -08:00
|
|
|
// TODO: Support grouped sections in section reading and parsing
|
|
|
|
|
// https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#grouped-sections-object-only
|
|
|
|
|
// Grouped sections are ordered and mean that the data in the sections contributes
|
|
|
|
|
// to the "base" section (the one without the "$X" suffix). This may negatively impact
|
|
|
|
|
// the use of some of the different types of executables.
|
|
|
|
|
|
2022-11-04 23:56:56 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Section table
|
|
|
|
|
/// </summary>
|
|
|
|
|
public SectionHeader[] SectionTable { get; set; }
|
|
|
|
|
|
2022-11-05 00:17:26 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// COFF symbol table
|
|
|
|
|
/// </summary>
|
|
|
|
|
public COFFSymbolTableEntry[] COFFSymbolTable { get; set; }
|
|
|
|
|
|
2022-11-05 15:40:48 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// COFF string table
|
|
|
|
|
/// </summary>
|
|
|
|
|
public COFFStringTable COFFStringTable { get; set; }
|
|
|
|
|
|
2022-11-05 21:02:30 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Attribute certificate table
|
|
|
|
|
/// </summary>
|
|
|
|
|
public AttributeCertificateTableEntry[] AttributeCertificateTable { get; set; }
|
|
|
|
|
|
2022-11-05 21:12:41 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Delay-load directory table
|
|
|
|
|
/// </summary>
|
2022-11-09 22:02:38 -08:00
|
|
|
public DelayLoadDirectoryTable DelayLoadDirectoryTable { get; set; }
|
2022-11-05 21:12:41 -07:00
|
|
|
|
2022-11-09 11:11:30 -08:00
|
|
|
#region Named Sections
|
|
|
|
|
|
2022-11-10 12:40:18 -08:00
|
|
|
// .cormeta - CLR metadata is stored in this section. It is used to indicate that
|
|
|
|
|
// the object file contains managed code. The format of the metadata is not
|
|
|
|
|
// documented, but can be handed to the CLR interfaces for handling metadata.
|
|
|
|
|
|
2022-11-10 21:24:28 -08:00
|
|
|
/// <summary>
|
|
|
|
|
/// Debug table (.debug*)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DebugTable DebugTable { get; set; }
|
|
|
|
|
|
2022-11-09 23:06:52 -08:00
|
|
|
/// <summary>
|
2022-11-10 10:10:12 -08:00
|
|
|
/// Export table (.edata)
|
2022-11-09 23:06:52 -08:00
|
|
|
/// </summary>
|
|
|
|
|
public ExportTable ExportTable { get; set; }
|
|
|
|
|
|
2022-11-10 10:10:12 -08:00
|
|
|
/// <summary>
|
|
|
|
|
/// Import table (.idata)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ImportTable ImportTable { get; set; }
|
|
|
|
|
|
2022-11-09 11:11:30 -08:00
|
|
|
/// <summary>
|
|
|
|
|
/// Resource directory table (.rsrc)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ResourceDirectoryTable ResourceDirectoryTable { get; set; }
|
|
|
|
|
|
2022-11-10 12:42:34 -08:00
|
|
|
// .sxdata - The valid exception handlers of an object are listed in the .sxdata
|
|
|
|
|
// section of that object. The section is marked IMAGE_SCN_LNK_INFO. It contains
|
|
|
|
|
// the COFF symbol index of each valid handler, using 4 bytes per index.
|
|
|
|
|
//
|
|
|
|
|
// Additionally, the compiler marks a COFF object as registered SEH by emitting
|
|
|
|
|
// the absolute symbol "@feat.00" with the LSB of the value field set to 1. A
|
|
|
|
|
// COFF object with no registered SEH handlers would have the "@feat.00" symbol,
|
|
|
|
|
// but no .sxdata section.
|
|
|
|
|
//
|
|
|
|
|
// TODO: Can we implement reading/parsing the .sxdata section?
|
|
|
|
|
|
2022-11-09 11:11:30 -08:00
|
|
|
#endregion
|
2022-11-05 21:54:36 -07:00
|
|
|
|
|
|
|
|
// TODO: Implement and/or document the following non-modeled parts:
|
|
|
|
|
// - Delay Import Address Table
|
|
|
|
|
// - Delay Import Name Table
|
|
|
|
|
// - Delay Bound Import Address Table
|
|
|
|
|
// - Delay Unload Import Address Table
|
|
|
|
|
// - The .drectve Section (Object Only)
|
2022-11-05 22:03:17 -07:00
|
|
|
// - The .pdata Section [Multiple formats per entry]
|
2022-11-05 22:11:41 -07:00
|
|
|
// - TLS Callback Functions
|
2022-11-05 22:46:50 -07:00
|
|
|
|
|
|
|
|
// TODO: Determine if "Archive (Library) File Format" is worth modelling
|
2022-11-04 21:05:03 -07:00
|
|
|
}
|
|
|
|
|
}
|