Add LE information block

This commit is contained in:
Matt Nadareski
2022-11-04 12:55:43 -07:00
parent 58d453db11
commit 1f5ab45a1e
3 changed files with 417 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
using System;
namespace BurnOutSharp.Models.LinearExecutable
{
public enum ByteOrder : byte
{
/// <summary>
/// little-endian
/// </summary>
LE = 0x00,
/// <summary>
/// big-endian
/// </summary>
/// <remarks>non-zero</remarks>
BE = 0x01,
}
public enum CPUType : ushort
{
/// <summary>
/// Intel 80286 or upwardly compatible
/// </summary>
Intel80286 = 0x01,
/// <summary>
/// Intel 80386 or upwardly compatible
/// </summary>
Intel80386 = 0x02,
/// <summary>
/// Intel 80486 or upwardly compatible
/// </summary>
Intel80486 = 0x03,
/// <summary>
/// Intel 80586 or upwardly compatible
/// </summary>
Intel80586 = 0x04,
/// <summary>
/// Intel i860 (N10) or compatible
/// </summary>
Inteli860 = 0x20,
/// <summary>
/// Intel "N11" or compatible
/// </summary>
IntelN11 = 0x21,
/// <summary>
/// MIPS Mark I (R2000, R3000) or compatible
/// </summary>
MIPSMarkI = 0x40,
/// <summary>
/// MIPS Mark II ( R6000 ) or compatible
/// </summary>
MIPSMarkII = 0x41,
/// <summary>
/// MIPS Mark III ( R4000 ) or compatible
/// </summary>
MIPSMarkIII = 0x42,
}
[Flags]
public enum InformationBlockFlag : uint
{
/// <summary>
/// Initialization (Only for DLL):
/// 0 Global
/// 1 Per-Process
/// </summary>
Initialization = 1 << 2,
/// <summary>
/// No internal fixup in exe image
/// </summary>
NoInternalFixup = 1 << 4,
/// <summary>
/// No internal fixup in exe image
/// </summary>
NoExternalFixup = 1 << 5,
// TODO: Figure out this block of flags
// 8, 9, 10 all have the same note:
// 0 Unknown
// 1 Incompatible with PM windowing
// 2 Compatible with PM windowing
// 3 Uses PM windowing API
/// <summary>
/// Module not loadable
/// </summary>
ModuleNotLoadable = 1 << 13,
/// <summary>
/// Module is DLL rather then program
/// </summary>
IsDLL = 1 << 15,
// Bits 16-31 are all reserved
}
public enum OperatingSystem : ushort
{
/// <summary>
/// OS/2
/// </summary>
OS2 = 0x01,
/// <summary>
/// Windows
/// </summary>
Windows = 0x02,
/// <summary>
/// DOS 4.x
/// </summary>
DOS4x = 0x03,
/// <summary>
/// Windows 386
/// </summary>
Windows386 = 0x04,
}
public enum WordOrder : byte
{
/// <summary>
/// little-endian
/// </summary>
LE = 0x00,
/// <summary>
/// big-endian
/// </summary>
/// <remarks>non-zero</remarks>
BE = 0x01,
}
}

View File

@@ -14,5 +14,27 @@ namespace BurnOutSharp.Models.LinearExecutable
/// MS-DOS executable header
/// </summary>
public MSDOS.ExecutableHeader Stub { get; set; }
/// <summary>
/// Information block
/// </summary>
public InformationBlock InformationBlock { get; set; }
// TODO: Object table
// TODO: Object page map table
// TODO: Object iterate data map table
// TODO: Resource table
// TODO: Resident-names table
// TODO: Entry table
// TODO: Module directives table
// TODO: Fix-up page table
// TODO: Fix-up record table
// TODO: Imported modules name table
// TODO: Imported procedures name table
// TODO: Per-page checksum table
// TODO: Code or Data Segment X
// TODO: Non-resident table
}
}

View File

@@ -0,0 +1,252 @@
using System.Runtime.InteropServices;
namespace BurnOutSharp.Models.LinearExecutable
{
/// <summary>
/// The `information block` in the LE header contains the linker version number,
/// length of various tables that further describe the executable file, the
/// offsets from the beginning of the header to the beginning of these tables,
/// the heap and stack sizes, and so on. The following list summarizes the
/// contents of the header `information block` (the locations are relative to
/// the beginning of the block):
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
[StructLayout(LayoutKind.Sequential)]
public class InformationBlock
{
/// <summary>
/// Specifies the signature word 'LE' (4Ch 45H)
/// </summary>
public char[] Signature;
/// <summary>
/// Byte order
/// </summary>
public ByteOrder ByteOrder;
/// <summary>
/// Word order
/// </summary>
public WordOrder WordOrder;
/// <summary>
/// Executable format level
/// </summary>
public uint ExecutableFormatLevel;
/// <summary>
/// CPU type
/// </summary>
public CPUType CPUType;
/// <summary>
/// Target operating system
/// </summary>
public OperatingSystem TargetOperatingSystem;
/// <summary>
/// Module version
/// </summary>
public uint ModuleVersion;
/// <summary>
/// Module type flags
/// </summary>
public InformationBlockFlag ModuleTypeFlags;
/// <summary>
/// Number of memory pages
/// </summary>
public uint MemoryPageCount;
/// <summary>
/// Initial object CS number
/// </summary>
public uint InitialObjectCS;
/// <summary>
/// Initial EIP
/// </summary>
public uint InitialEIP;
/// <summary>
/// Initial object SS number
/// </summary>
public uint InitialObjectSS;
/// <summary>
/// Initial ESP
/// </summary>
public uint InitialESP;
/// <summary>
/// Memory page size
/// </summary>
public uint MemoryPageSize;
/// <summary>
/// Bytes on last page
/// </summary>
public uint BytesOnLastPage;
/// <summary>
/// Fix-up section size
/// </summary>
public uint FixupSectionSize;
/// <summary>
/// Fix-up section checksum
/// </summary>
public uint FixupSectionChecksum;
/// <summary>
/// Loader section size
/// </summary>
public uint LoaderSectionSize;
/// <summary>
/// Loader section checksum
/// </summary>
public uint LoaderSectionChecksum;
/// <summary>
/// Offset of object table
/// </summary>
public uint ObjectTableOffset;
/// <summary>
/// Object table entries
/// </summary>
public uint ObjectTableCount;
/// <summary>
/// Object page map offset
/// </summary>
public uint ObjectPageMapOffset;
/// <summary>
/// Object iterate data map offset
/// </summary>
public uint ObjectIterateDataMapOffset;
/// <summary>
/// Resource table offset
/// </summary>
public uint ResourceTableOffset;
/// <summary>
/// Resource table entries
/// </summary>
public uint ResourceTableCount;
/// <summary>
/// Resident names table offset
/// </summary>
public uint ResidentNamesTableOffset;
/// <summary>
/// Entry table offset
/// </summary>
public uint EntryTableOffset;
/// <summary>
/// Module directives table offset
/// </summary>
public uint ModuleDirectivesTableOffset;
/// <summary>
/// Module directives entries
/// </summary>
public uint ModuleDirectivesCount;
/// <summary>
/// Fix-up page table offset
/// </summary>
public uint FixupPageTableOffset;
/// <summary>
/// Fix-up record table offset
/// </summary>
public uint FixupRecordTableOffset;
/// <summary>
/// Imported modules name table offset
/// </summary>
public uint ImportedModulesNameTableOffset;
/// <summary>
/// Imported modules count
/// </summary>
public uint ImportedModulesCount;
/// <summary>
/// Imported procedure name table offset
/// </summary>
public uint ImportedProcedureNameTableOffset;
/// <summary>
/// Per-page checksum table offset
/// </summary>
public uint PerPageChecksumTableOffset;
/// <summary>
/// Data pages offset from top of file
/// </summary>
public uint DataPagesOffset;
/// <summary>
/// Preload page count
/// </summary>
public uint PreloadPageCount;
/// <summary>
/// Non-resident names table offset from top of file
/// </summary>
public uint NonresidentNamesTableOffset;
/// <summary>
/// Non-resident names table length
/// </summary>
public uint NonresidentNamesTableLength;
/// <summary>
/// Non-resident names table checksum
/// </summary>
public uint NonresidentNamesTableChecksum;
/// <summary>
/// Automatic data object
/// </summary>
public uint AutomaticDataObject;
/// <summary>
/// Debug information offset
/// </summary>
public uint DebugInformationOffset;
/// <summary>
/// Debug information length
/// </summary>
public uint DebugInformationLength;
/// <summary>
/// Preload instance pages number
/// </summary>
public uint PreloadInstancePagesNumber;
/// <summary>
/// Demand instance pages number
/// </summary>
public uint DemandInstancePagesNumber;
/// <summary>
/// Extra heap allocation
/// </summary>
public uint ExtraHeapAllocation;
/// <summary>
/// ???
/// </summary>
public uint Reserved;
}
}