using System.Runtime.InteropServices; namespace BurnOutSharp.Models.MSDOS { /// /// MZ executables only consists of 2 structures: the header and the relocation table. /// The header, which is followed by the program image, looks like this. /// /// /// [StructLayout(LayoutKind.Sequential)] public class ExecutableHeader { #region Standard Fields /// /// 0x5A4D (ASCII for 'M' and 'Z') /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] Magic; /// /// Number of bytes in the last page. /// public ushort LastPageBytes; /// /// Number of whole/partial pages. /// /// A page (or block) is 512 bytes long. public ushort Pages; /// /// Number of entries in the relocation table. /// public ushort RelocationItems; /// /// The number of paragraphs taken up by the header. It can be any value, as the loader /// just uses it to find where the actual executable data starts. It may be larger than /// what the "standard" fields take up, and you may use it if you want to include your /// own header metadata, or put the relocation table there, or use it for any other purpose. [08] /// /// A paragraph is 16 bytes in size public ushort HeaderParagraphSize; /// /// The number of paragraphs required by the program, excluding the PSP and program image. /// If no free block is big enough, the loading stops. /// /// A paragraph is 16 bytes in size public ushort MinimumExtraParagraphs; /// /// The number of paragraphs requested by the program. /// If no free block is big enough, the biggest one possible is allocated. /// /// A paragraph is 16 bytes in size public ushort MaximumExtraParagraphs; /// /// Relocatable segment address for SS. /// public ushort InitialSSValue; /// /// Initial value for SP. /// public ushort InitialSPValue; /// /// When added to the sum of all other words in the file, the result should be zero. /// public ushort Checksum; /// /// Initial value for IP. [14] /// public ushort InitialIPValue; /// /// Relocatable segment address for CS. /// public ushort InitialCSValue; /// /// The (absolute) offset to the relocation table. /// public ushort RelocationTableAddr; /// /// Value used for overlay management. /// If zero, this is the main executable. /// public ushort OverlayNumber; #endregion #region PE Extensions /// /// Reserved words /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public ushort[] Reserved1; /// /// Defined by name but no other information is given; typically zeroes /// public ushort OEMIdentifier; /// /// Defined by name but no other information is given; typically zeroes /// public ushort OEMInformation; /// /// Reserved words /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] public ushort[] Reserved2; /// /// Starting address of the PE header /// public uint NewExeHeaderAddr; #endregion } }