Add skeleton of NE to Models project

This commit is contained in:
Matt Nadareski
2022-11-03 23:32:35 -07:00
parent 610e25b98a
commit abec45c492
4 changed files with 283 additions and 1 deletions

View File

@@ -22,7 +22,6 @@
<ItemGroup>
<Folder Include="LinearExecutable\" />
<Folder Include="NewExecutable\" />
<Folder Include="PortableExecutable\" />
</ItemGroup>

View File

@@ -0,0 +1,51 @@
using System;
namespace BurnOutSharp.Models.NewExecutable
{
[Flags]
public enum HeaderFlag : ushort
{
NOAUTODATA = 0x0000,
/// <summary>
/// Shared automatic data segment
/// </summary>
SINGLEDATA = 0x0001,
/// <summary>
/// Instanced automatic data segment
/// </summary>
MULTIPLEDATA = 0x0002,
/// <summary>
/// Errors detected at link time, module will not load
/// </summary>
ErrorsDetectedAtLinkTime = 0x2000,
/// <summary>
/// Library module.
/// The SS:SP information is invalid, CS:IP points
/// to an initialization procedure that is called
/// with AX equal to the module handle. This
/// initialization procedure must perform a far
/// return to the caller, with AX not equal to
/// zero to indicate success, or AX equal to zero
/// to indicate failure to initialize. DS is set
/// to the library's data segment if the
/// SINGLEDATA flag is set. Otherwise, DS is set
/// to the caller's data segment.
/// </summary>
/// <remarks>
/// A program or DLL can only contain dynamic
/// links to executable files that have this
/// library module flag set. One program cannot
/// dynamic-link to another program.
/// </remarks>
LibraryModule = 0x8000,
}
public enum OperatingSystem : byte
{
WINDOWS = 0x02,
}
}

View File

@@ -0,0 +1,33 @@
namespace BurnOutSharp.Models.NewExecutable
{
/// <summary>
/// The segmented EXE header contains general information about the EXE
/// file and contains information on the location and size of the other
/// sections. The Windows loader copies this section, along with other
/// data, into the module table in the system data. The module table is
/// internal data used by the loader to manage the loaded executable
/// modules in the system and to support dynamic linking.
/// </summary>
/// <see href="http://bytepointer.com/resources/win16_ne_exe_format_win3.0.htm"/>
public class Executable
{
/// <summary>
/// MS-DOS executable header
/// </summary>
public MSDOS.ExecutableHeader Stub { get; set; }
/// <summary>
/// New Executable header
/// </summary>
public ExecutableHeader Header { get; set; }
// TODO: Segment Table
// TODO: Resource Table
// TODO: Resident-Name Table
// TODO: Module-Reference Table
// TODO: Imported-Name Table
// TODO: Entry Table
// TODO: Nonresident-Name Table
// TODO: Per Segment Data
}
}

View File

@@ -0,0 +1,199 @@
using System.IO;
using System.Runtime.InteropServices;
namespace BurnOutSharp.Models.NewExecutable
{
/// <summary>
/// The NE header is a relatively large structure with multiple characteristics.
/// Because of the age of the format some items are unclear in meaning.
/// </summary>
/// <see href="http://bytepointer.com/resources/win16_ne_exe_format_win3.0.htm"/>
/// <see href="https://github.com/libyal/libexe/blob/main/documentation/Executable%20(EXE)%20file%20format.asciidoc#24-ne-extended-header"/>
[StructLayout(LayoutKind.Sequential)]
public class ExecutableHeader
{
/// <summary>
/// Signature word.
/// "N" is low-order byte.
/// "E" is high-order byte.
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public char[] Magic;
/// <summary>
/// Version number of the linker.
/// </summary>
public byte LinkerVersion;
/// <summary>
/// Revision number of the linker.
/// </summary>
public byte LinkerRevision;
/// <summary>
/// Entry Table file offset, relative to the beginning of the segmented EXE header.
/// </summary>
public ushort EntryTableOffset;
/// <summary>
/// Number of bytes in the entry table.
/// </summary>
public ushort EntryTableSize;
/// <summary>
/// 32-bit CRC of entire contents of file.
/// </summary>
/// <remarks>These words are taken as 00 during the calculation.</remarks>
public uint CrcChecksum;
/// <summary>
/// Flag word
/// </summary>
public HeaderFlag FlagWord;
/// <summary>
/// Segment number of automatic data segment.
/// This value is set to zero if SINGLEDATA and
/// MULTIPLEDATA flag bits are clear, NOAUTODATA is
/// indicated in the flags word.
/// </summary>
/// <remarks>
/// A Segment number is an index into the module's segment
/// table. The first entry in the segment table is segment
/// number 1.
/// </remarks>
public ushort AutomaticDataSegmentNumber;
/// <summary>
/// Initial size, in bytes, of dynamic heap added to the
/// data segment. This value is zero if no initial local
/// heap is allocated.
/// </summary>
public ushort InitialHeapAlloc;
/// <summary>
/// Initial size, in bytes, of stack added to the data
/// segment. This value is zero to indicate no initial
/// stack allocation, or when SS is not equal to DS.
/// </summary>
public ushort InitialStackAlloc;
/// <summary>
/// Segment number:offset of CS:IP.
/// </summary>
public uint InitialCSIPSetting;
/// <summary>
/// Segment number:offset of SS:SP.
/// </summary>
/// <remarks>
/// If SS equals the automatic data segment and SP equals
/// zero, the stack pointer is set to the top of the
/// automatic data segment just below the additional heap
/// area.
/// </remarks>
public uint InitialSSSPSetting;
/// <summary>
/// Number of entries in the Segment Table.
/// </summary>
public ushort FileSegmentCount;
/// <summary>
/// Number of entries in the Module Reference Table.
/// </summary>
public ushort ModuleReferenceTableSize;
/// <summary>
/// Number of bytes in the Non-Resident Name Table.
/// </summary>
public ushort NonResidentNameTableSize;
/// <summary>
/// Segment Table file offset, relative to the beginning
/// of the segmented EXE header.
/// </summary>
public ushort SegmentTableOffset;
/// <summary>
/// Resource Table file offset, relative to the beginning
/// of the segmented EXE header.
/// </summary>
public ushort ResourceTableOffset;
/// <summary>
/// Resident Name Table file offset, relative to the
/// beginning of the segmented EXE header.
/// </summary>
public ushort ResidentNameTableOffset;
/// <summary>
/// Module Reference Table file offset, relative to the
/// beginning of the segmented EXE header.
/// </summary>
public ushort ModuleReferenceTableOffset;
/// <summary>
/// Imported Names Table file offset, relative to the
/// beginning of the segmented EXE header.
/// </summary>
public ushort ImportedNamesTableOffset;
/// <summary>
/// Non-Resident Name Table offset, relative to the
/// beginning of the file.
/// </summary>
public uint NonResidentNamesTableOffset;
/// <summary>
/// Number of movable entries in the Entry Table.
/// </summary>
public ushort MovableEntriesCount;
/// <summary>
/// Logical sector alignment shift count, log(base 2) of
/// the segment sector size (default 9).
/// </summary>
public ushort SegmentAlignmentShiftCount;
/// <summary>
/// Number of resource entries.
/// </summary>
public ushort ResourceEntriesCount;
/// <summary>
/// Executable type, used by loader.
/// </summary>
public OperatingSystem TargetOperatingSystem;
/// <summary>
/// Other OS/2 flags
/// </summary>
public byte AdditionalFlags;
/// <summary>
/// Offset to return thunks or start of gangload area
/// </summary>
public ushort ReturnThunkOffset;
/// <summary>
/// Offset to segment reference thunks or size of gangload area
/// </summary>
public ushort SegmentReferenceThunkOffset;
/// <summary>
/// Minimum code swap area size
/// </summary>
public ushort MinCodeSwapAreaSize;
/// <summary>
/// Windows SDK revison number
/// </summary>
public byte WindowsSDKRevision;
/// <summary>
/// Windows SDK version number
/// </summary>
public byte WindowsSDKVersion;
}
}