diff --git a/BurnOutSharp.Models/BurnOutSharp.Models.csproj b/BurnOutSharp.Models/BurnOutSharp.Models.csproj index 7b2dc6fd..5d80ed81 100644 --- a/BurnOutSharp.Models/BurnOutSharp.Models.csproj +++ b/BurnOutSharp.Models/BurnOutSharp.Models.csproj @@ -22,7 +22,6 @@ - diff --git a/BurnOutSharp.Models/NewExecutable/Enums.cs b/BurnOutSharp.Models/NewExecutable/Enums.cs new file mode 100644 index 00000000..72dfd141 --- /dev/null +++ b/BurnOutSharp.Models/NewExecutable/Enums.cs @@ -0,0 +1,51 @@ +using System; + +namespace BurnOutSharp.Models.NewExecutable +{ + [Flags] + public enum HeaderFlag : ushort + { + NOAUTODATA = 0x0000, + + /// + /// Shared automatic data segment + /// + SINGLEDATA = 0x0001, + + /// + /// Instanced automatic data segment + /// + MULTIPLEDATA = 0x0002, + + /// + /// Errors detected at link time, module will not load + /// + ErrorsDetectedAtLinkTime = 0x2000, + + /// + /// 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. + /// + /// + /// 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. + /// + LibraryModule = 0x8000, + } + + public enum OperatingSystem : byte + { + WINDOWS = 0x02, + } +} diff --git a/BurnOutSharp.Models/NewExecutable/Executable.cs b/BurnOutSharp.Models/NewExecutable/Executable.cs new file mode 100644 index 00000000..d75268b4 --- /dev/null +++ b/BurnOutSharp.Models/NewExecutable/Executable.cs @@ -0,0 +1,33 @@ +namespace BurnOutSharp.Models.NewExecutable +{ + /// + /// 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. + /// + /// + public class Executable + { + /// + /// MS-DOS executable header + /// + public MSDOS.ExecutableHeader Stub { get; set; } + + /// + /// New Executable header + /// + 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 + } +} diff --git a/BurnOutSharp.Models/NewExecutable/ExecutableHeader.cs b/BurnOutSharp.Models/NewExecutable/ExecutableHeader.cs new file mode 100644 index 00000000..19680dc8 --- /dev/null +++ b/BurnOutSharp.Models/NewExecutable/ExecutableHeader.cs @@ -0,0 +1,199 @@ +using System.IO; +using System.Runtime.InteropServices; + +namespace BurnOutSharp.Models.NewExecutable +{ + /// + /// The NE header is a relatively large structure with multiple characteristics. + /// Because of the age of the format some items are unclear in meaning. + /// + /// + /// + [StructLayout(LayoutKind.Sequential)] + public class ExecutableHeader + { + /// + /// Signature word. + /// "N" is low-order byte. + /// "E" is high-order byte. + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public char[] Magic; + + /// + /// Version number of the linker. + /// + public byte LinkerVersion; + + /// + /// Revision number of the linker. + /// + public byte LinkerRevision; + + /// + /// Entry Table file offset, relative to the beginning of the segmented EXE header. + /// + public ushort EntryTableOffset; + + /// + /// Number of bytes in the entry table. + /// + public ushort EntryTableSize; + + /// + /// 32-bit CRC of entire contents of file. + /// + /// These words are taken as 00 during the calculation. + public uint CrcChecksum; + + /// + /// Flag word + /// + public HeaderFlag FlagWord; + + /// + /// 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. + /// + /// + /// A Segment number is an index into the module's segment + /// table. The first entry in the segment table is segment + /// number 1. + /// + public ushort AutomaticDataSegmentNumber; + + /// + /// Initial size, in bytes, of dynamic heap added to the + /// data segment. This value is zero if no initial local + /// heap is allocated. + /// + public ushort InitialHeapAlloc; + + /// + /// 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. + /// + public ushort InitialStackAlloc; + + /// + /// Segment number:offset of CS:IP. + /// + public uint InitialCSIPSetting; + + /// + /// Segment number:offset of SS:SP. + /// + /// + /// 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. + /// + public uint InitialSSSPSetting; + + /// + /// Number of entries in the Segment Table. + /// + public ushort FileSegmentCount; + + /// + /// Number of entries in the Module Reference Table. + /// + public ushort ModuleReferenceTableSize; + + /// + /// Number of bytes in the Non-Resident Name Table. + /// + public ushort NonResidentNameTableSize; + + /// + /// Segment Table file offset, relative to the beginning + /// of the segmented EXE header. + /// + public ushort SegmentTableOffset; + + /// + /// Resource Table file offset, relative to the beginning + /// of the segmented EXE header. + /// + public ushort ResourceTableOffset; + + /// + /// Resident Name Table file offset, relative to the + /// beginning of the segmented EXE header. + /// + public ushort ResidentNameTableOffset; + + /// + /// Module Reference Table file offset, relative to the + /// beginning of the segmented EXE header. + /// + public ushort ModuleReferenceTableOffset; + + /// + /// Imported Names Table file offset, relative to the + /// beginning of the segmented EXE header. + /// + public ushort ImportedNamesTableOffset; + + /// + /// Non-Resident Name Table offset, relative to the + /// beginning of the file. + /// + public uint NonResidentNamesTableOffset; + + /// + /// Number of movable entries in the Entry Table. + /// + public ushort MovableEntriesCount; + + /// + /// Logical sector alignment shift count, log(base 2) of + /// the segment sector size (default 9). + /// + public ushort SegmentAlignmentShiftCount; + + /// + /// Number of resource entries. + /// + public ushort ResourceEntriesCount; + + /// + /// Executable type, used by loader. + /// + public OperatingSystem TargetOperatingSystem; + + /// + /// Other OS/2 flags + /// + public byte AdditionalFlags; + + /// + /// Offset to return thunks or start of gangload area + /// + public ushort ReturnThunkOffset; + + /// + /// Offset to segment reference thunks or size of gangload area + /// + public ushort SegmentReferenceThunkOffset; + + /// + /// Minimum code swap area size + /// + public ushort MinCodeSwapAreaSize; + + /// + /// Windows SDK revison number + /// + public byte WindowsSDKRevision; + + /// + /// Windows SDK version number + /// + public byte WindowsSDKVersion; + } +}