Add BOS models

This commit is contained in:
Matt Nadareski
2023-09-04 00:11:04 -04:00
parent 68c6f9d61f
commit 1055187865
373 changed files with 23931 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
namespace BinaryObjectScanner.Models.LinearExecutable
{
public static class Constants
{
public static readonly byte[] DebugInformationSignatureBytes = new byte[] { 0x4e, 0x42, 0x30 };
public const string DebugInformationSignatureString = "NB0";
public static readonly byte[] LESignatureBytes = new byte[] { 0x4c, 0x45 };
public const string LESignatureString = "LE";
public const ushort LESignatureUInt16 = 0x454c;
public static readonly byte[] LXSignatureBytes = new byte[] { 0x4c, 0x58 };
public const string LXSignatureString = "LX";
public const ushort LXSignatureUInt16 = 0x584c;
}
}

View File

@@ -0,0 +1,38 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The debug information is defined by the debugger and is not controlled by
/// the linear EXE format or linker. The only data defined by the linear EXE
/// format relative to the debug information is it's offset in the EXE file and
/// length in bytes as defined in the linear EXE header.
///
/// To support multiple debuggers the first word of the debug information is a
/// type field which determines the format of the debug information.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class DebugInformation
{
/// <summary>
/// The signature consists of a string of three (3) ASCII characters: "NB0"
/// </summary>
public string Signature;
/// <summary>
/// This defines the type of debugger data that exists in the remainder of the
/// debug information.
/// </summary>
public DebugFormatType FormatType;
/// <summary>
/// The format of the debugger data is defined by the debugger that is being used.
/// The values defined for the type field are not enforced by the system. It is
/// the responsibility of the linker or debugging tools to follow the convention
/// for the type field that is defined here.
/// </summary>
public byte[] DebuggerData;
}
}

View File

@@ -0,0 +1,59 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The entry table contains object and offset information that is used to resolve
/// fixup references to the entry points within this module. Not all entry points
/// in the entry table will be exported, some entry points will only be used
/// within the module. An ordinal number is used to index into the entry table.
/// The entry table entries are numbered starting from one.
///
/// The list of entries are compressed into 'bundles', where possible. The entries
/// within each bundle are all the same size. A bundle starts with a count field
/// which indicates the number of entries in the bundle. The count is followed by
/// a type field which identifies the bundle format. This provides both a means
/// for saving space as well as a mechanism for extending the bundle types.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class EntryTableBundle
{
/// <summary>
/// Number of entries.
/// </summary>
/// <remarks>
/// This is the number of entries in this bundle.
///
/// A zero value for the number of entries identifies the end of the
/// entry table. There is no further bundle information when the number
/// of entries is zero. In other words the entry table is terminated by
/// a single zero byte.
///
/// For <see cref="BundleType.UnusedEntry"/>, this is the number of unused
/// entries to skip.
/// For <see cref="BundleType.SixteenBitEntry"/>, this is the number of 16-bit
/// entries in this bundle. The flags and offset value are repeated this
/// number of times.
/// For <see cref="BundleType.TwoEightySixCallGateEntry"/>, this is the number
/// of 286 call gate entries in this bundle. The flags, callgate, and offset
/// value are repeated this number of times.
/// For <see cref="BundleType.ThirtyTwoBitEntry"/>, this is the number
/// of 32-bit entries in this bundle. The flags and offset value are repeated
/// this number of times.
/// For <see cref="BundleType.ForwarderEntry"/>, this field is reserved for future use.
/// </remarks>
public byte Entries;
/// <summary>
/// This defines the bundle type which determines the contents of the BUNDLE INFO.
/// </summary>
public BundleType BundleType;
/// <summary>
/// Table entries in the bundle
/// </summary>
public EntryTableEntry[] TableEntries;
}
}

View File

@@ -0,0 +1,190 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Explicit)]
public sealed class EntryTableEntry
{
#region 16-bit Entry
/// <summary>
/// Object number.
/// </summary>
/// <remarks>
/// This is the object number for the entries in this bundle.
/// </remarks>
[FieldOffset(0)] public ushort SixteenBitObjectNumber;
/// <summary>
/// Entry flags.
/// </summary>
/// <remarks>
/// These are the flags for this entry point.
/// </remarks>
[FieldOffset(2)] public EntryFlags SixteenBitEntryFlags;
/// <summary>
/// Offset in object.
/// </summary>
/// <remarks>
/// This is the offset in the object for the entry point defined at this ordinal number.
/// </remarks>
[FieldOffset(3)] public ushort SixteenBitOffset;
#endregion
#region 286 Call Gate Entry
/// <summary>
/// Object number.
/// </summary>
/// <remarks>
/// This is the object number for the entries in this bundle.
/// </remarks>
[FieldOffset(0)] public ushort TwoEightySixObjectNumber;
/// <summary>
/// Entry flags.
/// </summary>
/// <remarks>
/// These are the flags for this entry point.
/// </remarks>
[FieldOffset(2)] public EntryFlags TwoEightySixEntryFlags;
/// <summary>
/// Offset in object.
/// </summary>
/// <remarks>
/// This is the offset in the object for the entry point defined at this ordinal number.
/// </remarks>
[FieldOffset(3)] public ushort TwoEightySixOffset;
/// <summary>
/// Callgate selector.
/// </summary>
/// <remarks>
/// The callgate selector is a reserved field used by the loader to store a call
/// gate selector value for references to ring 2 entry points. When a ring 3
/// reference to a ring 2 entry point is made, the callgate selector with a zero
/// offset is place in the relocation fixup address. The segment number and offset
/// in segment is placed in the LDT callgate.
/// </remarks>
[FieldOffset(5)] public ushort TwoEightySixCallgate;
#endregion
#region 32-bit Entry
/// <summary>
/// Object number.
/// </summary>
/// <remarks>
/// This is the object number for the entries in this bundle.
/// </remarks>
[FieldOffset(0)] public ushort ThirtyTwoBitObjectNumber;
/// <summary>
/// Entry flags.
/// </summary>
/// <remarks>
/// These are the flags for this entry point.
/// </remarks>
[FieldOffset(2)] public EntryFlags ThirtyTwoBitEntryFlags;
/// <summary>
/// Offset in object.
/// </summary>
/// <remarks>
/// This is the offset in the object for the entry point defined at this ordinal number.
/// </remarks>
[FieldOffset(3)] public uint ThirtyTwoBitOffset;
#endregion
#region Forwarder Entry
/// <summary>
/// 0
/// </summary>
/// <remarks>
/// This field is reserved for future use.
/// </remarks>
[FieldOffset(0)] public ushort ForwarderReserved;
/// <summary>
/// Forwarder flags.
/// </summary>
/// <remarks>
/// These are the flags for this entry point.
/// </remarks>
[FieldOffset(2)] public ForwarderFlags ForwarderFlags;
/// <summary>
/// Module Ordinal Number
/// </summary>
/// <remarks>
/// This is the index into the Import Module Name Table for this forwarder.
/// </remarks>
[FieldOffset(3)] public ushort ForwarderModuleOrdinalNumber;
/// <summary>
/// Procedure Name Offset
/// </summary>
/// <remarks>
/// If the FLAGS field indicates import by ordinal, then this field is the
/// ordinal number into the Entry Table of the target module, otherwise this
/// field is the offset into the Procedure Names Table of the target module.
///
/// A Forwarder entry (type = 4) is an entry point whose value is an imported
/// reference. When a load time fixup occurs whose target is a forwarder, the
/// loader obtains the address imported by the forwarder and uses that imported
/// address to resolve the fixup.
///
/// A forwarder may refer to an entry point in another module which is itself a
/// forwarder, so there can be a chain of forwarders. The loader will traverse
/// the chain until it finds a non-forwarded entry point which terminates the
/// chain, and use this to resolve the original fixup. Circular chains are
/// detected by the loader and result in a load time error. A maximum of 1024
/// forwarders is allowed in a chain; more than this results in a load time error.
///
/// Forwarders are useful for merging and recombining API calls into different
/// sets of libraries, while maintaining compatibility with applications. For
/// example, if one wanted to combine MONCALLS, MOUCALLS, and VIOCALLS into a
/// single libraries, one could provide entry points for the three libraries
/// that are forwarders pointing to the common implementation.
/// </remarks>
[FieldOffset(5)] public uint ProcedureNameOffset;
/// <summary>
/// Import Ordinal Number
/// </summary>
/// <remarks>
/// If the FLAGS field indicates import by ordinal, then this field is the
/// ordinal number into the Entry Table of the target module, otherwise this
/// field is the offset into the Procedure Names Table of the target module.
///
/// A Forwarder entry (type = 4) is an entry point whose value is an imported
/// reference. When a load time fixup occurs whose target is a forwarder, the
/// loader obtains the address imported by the forwarder and uses that imported
/// address to resolve the fixup.
///
/// A forwarder may refer to an entry point in another module which is itself a
/// forwarder, so there can be a chain of forwarders. The loader will traverse
/// the chain until it finds a non-forwarded entry point which terminates the
/// chain, and use this to resolve the original fixup. Circular chains are
/// detected by the loader and result in a load time error. A maximum of 1024
/// forwarders is allowed in a chain; more than this results in a load time error.
///
/// Forwarders are useful for merging and recombining API calls into different
/// sets of libraries, while maintaining compatibility with applications. For
/// example, if one wanted to combine MONCALLS, MOUCALLS, and VIOCALLS into a
/// single libraries, one could provide entry points for the three libraries
/// that are forwarders pointing to the common implementation.
/// </remarks>
[FieldOffset(5)] public uint ImportOrdinalNumber;
#endregion
}
}

680
LinearExecutable/Enums.cs Normal file
View File

@@ -0,0 +1,680 @@
using System;
namespace BinaryObjectScanner.Models.LinearExecutable
{
[Flags]
public enum BundleType : byte
{
/// <summary>
/// Unused Entry.
/// </summary>
UnusedEntry = 0x00,
/// <summary>
/// 16-bit Entry.
/// </summary>
SixteenBitEntry = 0x01,
/// <summary>
/// 286 Call Gate Entry.
/// </summary>
TwoEightySixCallGateEntry = 0x02,
/// <summary>
/// 32-bit Entry.
/// </summary>
ThirtyTwoBitEntry = 0x03,
/// <summary>
/// Forwarder Entry.
/// </summary>
ForwarderEntry = 0x04,
/// <summary>
/// Parameter Typing Information Present.
/// </summary>
/// <remarks>
/// This bit signifies that additional information is contained in the
/// linear EXE module and will be used in the future for parameter type checking.
/// </remarks>
ParameterTypingInformationPresent = 0x80,
}
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,
}
public enum DebugFormatType : byte
{
/// <summary>
/// 32-bit CodeView debugger format.
/// </summary>
CodeView32Bit = 0x00,
/// <summary>
/// AIX debugger format.
/// </summary>
AIXDebugger = 0x01,
/// <summary>
/// 16-bit CodeView debugger format.
/// </summary>
CodeView16Bit = 0x02,
/// <summary>
/// 32-bit OS/2 PM debugger (IBM) format.
/// </summary>
OS2PM32Bit = 0x04,
}
public enum DirectiveNumber : ushort
{
/// <summary>
/// Resident Flag Mask.
/// </summary>
/// <remarks>
/// Directive numbers with this bit set indicate that the directive data
/// is in the resident area and will be kept resident in memory when the
/// module is loaded.
/// </remarks>
ResidentFlagMask = 0x8000,
/// <summary>
/// Verify Record Directive. (Verify record is a resident table.)
/// </summary>
VerifyRecordDirective = 0x8001,
/// <summary>
/// Language Information Directive. (This is a non-resident table.)
/// </summary>
LanguageInformationDirective = 0x0002,
/// <summary>
/// Co-Processor Required Support Table.
/// </summary>
CoProcessorRequiredSupportTable = 0x0003,
/// <summary>
/// Thread State Initialization Directive.
/// </summary>
ThreadStateInitializationDirective = 0x0004,
// Additional directives can be added as needed in the future, as long as
// they do not overlap previously defined directive numbers.
}
[Flags]
public enum EntryFlags : byte
{
/// <summary>
/// Exported entry flag.
/// </summary>
ExportedEntry = 0x01,
/// <summary>
/// Parameter word count mask.
/// </summary>
ParameterWordCountMask = 0xF8,
}
[Flags]
public enum FixupRecordSourceType : byte
{
/// <summary>
/// Source mask.
/// </summary>
SourceMask = 0x0F,
/// <summary>
/// Byte fixup (8-bits).
/// </summary>
ByteFixup = 0x00,
/// <summary>
/// (undefined).
/// </summary>
Undefined1 = 0x01,
/// <summary>
/// 16-bit Selector fixup (16-bits).
/// </summary>
SixteenBitSelectorFixup = 0x02,
/// <summary>
/// 16:16 Pointer fixup (32-bits).
/// </summary>
SixteenSixteenPointerFixup = 0x03,
/// <summary>
/// (undefined).
/// </summary>
Undefined4 = 0x04,
/// <summary>
/// 16-bit Offset fixup (16-bits).
/// </summary>
SixteenBitOffsetFixup = 0x05,
/// <summary>
/// 16:32 Pointer fixup (48-bits).
/// </summary>
SixteenThirtyTwoPointerFixup = 0x06,
/// <summary>
/// 32-bit Offset fixup (32-bits).
/// </summary>
ThirtyTwoBitOffsetFixup = 0x07,
/// <summary>
/// 32-bit Self-relative offset fixup (32-bits).
/// </summary>
ThirtyTwoBitSelfRelativeOffsetFixup = 0x08,
/// <summary>
/// Fixup to Alias Flag.
/// </summary>
/// <remarks>
/// When the 'Fixup to Alias' Flag is set, the source fixup refers to
/// the 16:16 alias for the object. This is only valid for source types
/// of 2, 3, and 6. For fixups such as this, the linker and loader will
/// be required to perform additional checks such as ensuring that the
/// target offset for this fixup is less than 64K.
/// </remarks>
FixupToAliasFlag = 0x10,
/// <summary>
/// Source List Flag.
/// </summary>
/// <remarks>
/// When the 'Source List' Flag is set, the SRCOFF field is compressed
/// to a byte and contains the number of source offsets, and a list of source
/// offsets follows the end of fixup record (after the optional additive value).
/// </remarks>
SourceListFlag = 0x20,
}
[Flags]
public enum FixupRecordTargetFlags : byte
{
/// <summary>
/// Fixup target type mask.
/// </summary>
FixupTargetTypeMask = 0x03,
/// <summary>
/// Internal reference.
/// </summary>
InternalReference = 0x00,
/// <summary>
/// Imported reference by ordinal.
/// </summary>
ImportedReferenceByOrdinal = 0x01,
/// <summary>
/// Imported reference by name.
/// </summary>
ImportedReferenceByName = 0x02,
/// <summary>
/// Internal reference via entry table.
/// </summary>
InternalReferenceViaEntryTable = 0x03,
/// <summary>
/// Additive Fixup Flag.
/// </summary>
/// <remarks>
/// When set, an additive value trails the fixup record (before the optional
/// source offset list).
/// </remarks>
AdditiveFixupFlag = 0x04,
/// <summary>
/// Reserved. Must be zero.
/// </summary>
Reserved = 0x08,
/// <summary>
/// 32-bit Target Offset Flag.
/// </summary>
/// <remarks>
/// When set, the target offset is 32-bits, otherwise it is 16-bits.
/// </remarks>
ThirtyTwoBitTargetOffsetFlag = 0x10,
/// <summary>
/// 32-bit Additive Fixup Flag.
/// </summary>
/// When set, the additive value is 32-bits, otherwise it is 16-bits.
/// </remarks>
ThirtyTwoBitAdditiveFixupFlag = 0x20,
/// <summary>
/// 16-bit Object Number/Module Ordinal Flag.
/// </summary>
/// <remarks>
/// When set, the object number or module ordinal number is 16-bits,
/// otherwise it is 8-bits.
/// </remarks>
SixteenBitObjectNumberModuleOrdinalFlag = 0x40,
/// <summary>
/// 8-bit Ordinal Flag.
/// </summary>
/// <remarks>
/// When set, the ordinal number is 8-bits, otherwise it is 16-bits.
/// </remarks>
EightBitOrdinalFlag = 0x80,
}
[Flags]
public enum ForwarderFlags : byte
{
/// <summary>
/// Import by ordinal.
/// </summary>
ImportByOrdinal = 0x01,
/// <summary>
/// Reserved for future use; should be zero.
/// </summary>
Reserved = 0xF7,
}
[Flags]
public enum ModuleFlags : uint
{
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved0 = 0x00000001,
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved1 = 0x00000002,
/// <summary>
/// Per-Process Library Initialization.
/// </summary>
/// <remarks>
/// The setting of this bit requires the EIP Object # and EIP fields
/// to have valid values. If the EIP Object # and EIP fields are
/// valid and this bit is NOT set, then Global Library Initialization
/// is assumed. Setting this bit for an EXE file is invalid.
/// </remarks>
Initialization = 0x00000004,
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved3 = 0x00000008,
/// <summary>
/// Internal fixups for the module have been applied.
/// </summary>
/// <remarks>
/// The setting of this bit in a Linear Executable Module indicates that
/// each object of the module has a preferred load address specified in
/// the Object Table Reloc Base Addr. If the module's objects can not be
/// loaded at these preferred addresses, then the relocation records that
/// have been retained in the file data will be applied.
/// </remarks>
InternalFixupsApplied = 0x00000010,
/// <summary>
/// External fixups for the module have been applied.
/// </summary>
ExternalFixupsApplied = 0x00000020,
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved6 = 0x00000040,
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved7 = 0x00000080,
/// <summary>
/// Incompatible with PM windowing.
/// </summary>
IncompatibleWithPMWindowing = 0x00000100,
/// <summary>
/// Incompatible with PM windowing.
/// </summary>
CompatibleWithPMWindowing = 0x00000200,
/// <summary>
/// Uses PM windowing API.
/// </summary>
UsesPMWindowing = 0x00000300,
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved10 = 0x00000400,
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved11 = 0x00000800,
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved12 = 0x00001000,
/// <summary>
/// Module is not loadable.
/// </summary>
/// <remarks>
/// When the 'Module is not loadable' flag is set, it indicates that
/// either errors were detected at link time or that the module is
/// being incrementally linked and therefore can't be loaded.
/// </remarks>
ModuleNotLoadable = 0x00002000,
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved14 = 0x00004000,
/// <summary>
/// Module type mask.
/// </summary>
ModuleTypeMask = 0x00038000,
/// <summary>
/// Program module.
/// </summary>
/// <remarks>
/// A module can not contain dynamic links to other modules that have
/// the 'program module' type.
/// </remarks>
ProgramModule = 0x00000000,
/// <summary>
/// Library module.
/// </summary>
LibraryModule = 0x00008000,
/// <summary>
/// Protected Memory Library module.
/// </summary>
ProtectedMemoryLibraryModule = 0x00018000,
/// <summary>
/// Physical Device Driver module.
/// </summary>
PhysicalDeviceDriverModule = 0x00020000,
/// <summary>
/// Virtual Device Driver module.
/// </summary>
VirtualDeviceDriverModule = 0x00028000,
/// <summary>
/// Per-process Library Termination.
/// </summary>
/// <remarks>
/// The setting of this bit requires the EIP Object # and EIP fields
/// to have valid values. If the EIP Object # and EIP fields are
/// valid and this bit is NOT set, then Global Library Termination
/// is assumed. Setting this bit for an EXE file is invalid.
/// </remarks>
PerProcessLibraryTermination = 0x40000000,
}
[Flags]
public enum ObjectFlags : ushort
{
/// <summary>
/// Readable Object.
/// </summary>
ReadableObject = 0x0001,
/// <summary>
/// Writable Object.
/// </summary>
WritableObject = 0x0002,
/// <summary>
/// Executable Object.
/// </summary>
ExecutableObject = 0x0004,
// The readable, writable and executable flags provide support for all possible
// protections. In systems where all of these protections are not supported,
// the loader will be responsible for making the appropriate protection match
// for the system.
/// <summary>
/// Resource Object.
/// </summary>
ResourceObject = 0x0008,
/// <summary>
/// Discardable Object.
/// </summary>
DiscardableObject = 0x0010,
/// <summary>
/// Object is Shared.
/// </summary>
Shared = 0x0020,
/// <summary>
/// Object has Preload Pages.
/// </summary>
HasPreloadPages = 0x0040,
/// <summary>
/// Object has Invalid Pages.
/// </summary>
HasInvalidPages = 0x0080,
/// <summary>
/// Object has Zero Filled Pages.
/// </summary>
HasZeroFilledPages = 0x0100,
/// <summary>
/// Object is Resident (valid for VDDs, PDDs only).
/// </summary>
Resident = 0x0200,
/// <summary>
/// Object is Resident & Contiguous (VDDs, PDDs only).
/// </summary>
ResidentAndContiguous = 0x0300,
/// <summary>
/// Object is Resident & 'long-lockable' (VDDs, PDDs only).
/// </summary>
ResidentAndLongLockable = 0x0400,
/// <summary>
/// Reserved for system use.
/// </summary>
Reserved = 0x0800,
/// <summary>
/// 16:16 Alias Required (80x86 Specific).
/// </summary>
AliasRequired = 0x1000,
/// <summary>
/// Big/Default Bit Setting (80x86 Specific).
/// </summary>
BitSetting = 0x2000,
// The 'big/default' bit, for data segments, controls the setting of the
// Big bit in the segment descriptor. (The Big bit, or B-bit, determines
// whether ESP or SP is used as the stack pointer.) For code segments,
// this bit controls the setting of the Default bit in the segment
// descriptor. (The Default bit, or D-bit, determines whether the default
// word size is 32-bits or 16-bits. It also affects the interpretation of
// the instruction stream.)
/// <summary>
/// Object is conforming for code (80x86 Specific).
/// </summary>
Conforming = 0x4000,
/// <summary>
/// Object I/O privilege level (80x86 Specific). Only used for 16:16 Alias Objects.
/// </summary>
PrivilegeLevel = 0x8000,
}
[Flags]
public enum ObjectPageFlags : ushort
{
/// <summary>
/// Legal Physical Page in the module (Offset from Preload Page Section).
/// </summary>
LegalPhysicalPage = 0x0000,
/// <summary>
/// Iterated Data Page (Offset from Iterated Data Pages Section).
/// </summary>
IteratedDataPage = 0x0001,
/// <summary>
/// Invalid Page (zero).
/// </summary>
InvalidPage = 0x0002,
/// <summary>
/// Zero Filled Page (zero).
/// </summary>
ZeroFilledPage = 0x0003,
/// <summary>
/// Range of Pages.
/// </summary>
RangeOfPages = 0x0004,
}
public enum OperatingSystem : ushort
{
/// <summary>
/// Unknown (any "new-format" OS)
/// </summary>
Unknown = 0x00,
/// <summary>
/// OS/2 (default)
/// </summary>
OS2 = 0x01,
/// <summary>
/// Windows
/// </summary>
Windows = 0x02,
/// <summary>
/// DOS 4.x
/// </summary>
DOS4x = 0x03,
/// <summary>
/// Windows 386
/// </summary>
Windows386 = 0x04,
}
public enum ResourceTableEntryType : uint
{
/// <summary>
/// "BTMP" - Bitmap
/// </summary>
BTMP = 0x504d5442,
/// <summary>
/// "EMSG" - Error message string
/// </summary>
EMSG = 0x47534d45,
/// <summary>
/// "FONT" - Fonts
/// </summary>
FONT = 0x544e4f46,
}
public enum WordOrder : byte
{
/// <summary>
/// little-endian
/// </summary>
LE = 0x00,
/// <summary>
/// big-endian
/// </summary>
/// <remarks>non-zero</remarks>
BE = 0x01,
}
}

View File

@@ -0,0 +1,97 @@
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The `LINEAR` executable-file header contains information that the loader requires for
/// segmented executable files. This information includes the linker version number, data
/// specified by linker, data specified by resource compiler, tables of segment data, tables
/// of resource data, and so on. The following illustrations shows the LE file header:
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
public sealed class Executable
{
/// <summary>
/// MS-DOS executable stub
/// </summary>
public MSDOS.Executable Stub { get; set; }
/// <summary>
/// Information block
/// </summary>
public InformationBlock InformationBlock { get; set; }
/// <summary>
/// Object table
/// </summary>
public ObjectTableEntry[] ObjectTable { get; set; }
/// <summary>
/// Object page map
/// </summary>
public ObjectPageMapEntry[] ObjectPageMap { get; set; }
// TODO: Object iterate data map table (Undefined)
/// <summary>
/// Resource table
/// </summary>
public ResourceTableEntry[] ResourceTable { get; set; }
/// <summary>
/// Resident Name table
/// </summary>
public ResidentNamesTableEntry[] ResidentNamesTable { get; set; }
/// <summary>
/// Entry table
/// </summary>
public EntryTableBundle[] EntryTable { get; set; }
/// <summary>
/// Module format directives table (optional)
/// </summary>
public ModuleFormatDirectivesTableEntry[] ModuleFormatDirectivesTable { get; set; }
/// <summary>
/// Verify record directive table (optional)
/// </summary>
public VerifyRecordDirectiveTableEntry[] VerifyRecordDirectiveTable { get; set; }
/// <summary>
/// Fix-up page table
/// </summary>
public FixupPageTableEntry[] FixupPageTable { get; set; }
/// <summary>
/// Fix-up record table
/// </summary>
public FixupRecordTableEntry[] FixupRecordTable { get; set; }
/// <summary>
/// Import module name table
/// </summary>
public ImportModuleNameTableEntry[] ImportModuleNameTable { get; set; }
/// <summary>
/// Import procedure name table
/// </summary>
public ImportModuleProcedureNameTableEntry[] ImportModuleProcedureNameTable { get; set; }
/// <summary>
/// Per-Page checksum table
/// </summary>
public PerPageChecksumTableEntry[] PerPageChecksumTable { get; set; }
/// <summary>
/// Non-Resident Name table
/// </summary>
public NonResidentNamesTableEntry[] NonResidentNamesTable { get; set; }
// TODO: Non-resident directives data (Undefined)
/// <summary>
/// Debug information
/// </summary>
public DebugInformation DebugInformation { get; set; }
}
}

View File

@@ -0,0 +1,36 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The Fixup Page Table provides a simple mapping of a logical page number
/// to an offset into the Fixup Record Table for that page.
///
/// This table is parallel to the Object Page Table, except that there is
/// one additional entry in this table to indicate the end of the Fixup
/// Record Table.
///
/// The fixup records are kept in order by logical page in the fixup record
/// table. This allows the end of each page's fixup records is defined by the
/// offset for the next logical page's fixup records. This last entry provides
/// support of this mechanism for the last page in the fixup page table.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class FixupPageTableEntry
{
/// <summary>
/// Offset for fixup record for this page. (1 to n)
/// Offset to the end of the fixup records. (n + 1)
/// </summary>
/// <remarks>
/// This field specifies the offset, from the beginning of the fixup record
/// table, to the first fixup record for this page. (1 to n)
///
/// This field specifies the offset following the last fixup record in the
/// fixup record table. This is the last entry in the fixup page table. (n + 1)
/// </remarks>
public uint Offset;
}
}

View File

@@ -0,0 +1,363 @@
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The Fixup Record Table contains entries for all fixups in the linear EXE module.
/// The fixup records for a logical page are grouped together and kept in sorted
/// order by logical page number. The fixups for each page are further sorted such
/// that all external fixups and internal selector/pointer fixups come before
/// internal non-selector/non-pointer fixups. This allows the loader to ignore
/// internal fixups if the loader is able to load all objects at the addresses
/// specified in the object table.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
public sealed class FixupRecordTableEntry
{
/// <summary>
/// Source type.
/// </summary>
/// <remarks>
/// The source type specifies the size and type of the fixup to be performed
/// on the fixup source.
/// </remarks>
public FixupRecordSourceType SourceType;
/// <summary>
/// Target Flags.
/// </summary>
/// <remarks>
/// The target flags specify how the target information is interpreted.
/// </remarks>
public FixupRecordTargetFlags TargetFlags;
#region Source List Flag
#region Set
/// <summary>
/// Source offset.
/// </summary>
/// <remarks>
/// This field contains either an offset or a count depending on the Source
/// List Flag. If the Source List Flag is set, a list of source offsets
/// follows the additive field and this field contains the count of the
/// entries in the source offset list. Otherwise, this is the single source
/// offset for the fixup. Source offsets are relative to the beginning of
/// the page where the fixup is to be made.
///
/// Note that for fixups that cross page boundaries, a separate fixup record
/// is specified for each page. An offset is still used for the 2nd page but
/// it now becomes a negative offset since the fixup originated on the
/// preceding page. (For example, if only the last one byte of a 32-bit
/// address is on the page to be fixed up, then the offset would have a value
/// of -3.)
/// </remarks>
public ushort SourceOffset;
#endregion
#region Unset
/// <summary>
/// Source offset list count.
/// </summary>
/// <remarks>
/// This field contains either an offset or a count depending on the Source
/// List Flag. If the Source List Flag is set, a list of source offsets
/// follows the additive field and this field contains the count of the
/// entries in the source offset list. Otherwise, this is the single source
/// offset for the fixup. Source offsets are relative to the beginning of
/// the page where the fixup is to be made.
///
/// Note that for fixups that cross page boundaries, a separate fixup record
/// is specified for each page. An offset is still used for the 2nd page but
/// it now becomes a negative offset since the fixup originated on the
/// preceding page. (For example, if only the last one byte of a 32-bit
/// address is on the page to be fixed up, then the offset would have a value
/// of -3.)
/// </remarks>
public byte SourceOffsetListCount;
#endregion
#endregion
#region OBJECT / TRGOFF
#region 16-bit Object Number/Module Ordinal Flag
#region Set
/// <summary>
/// Target object number.
/// </summary>
/// <remarks>
/// This field is an index into the current module's Object Table to specify
/// the target Object. It is a Byte value when the '16-bit Object Number/Module
/// Ordinal Flag' bit in the target flags field is clear and a Word value when
/// the bit is set.
/// </remarks>
public ushort TargetObjectNumberWORD;
#endregion
#region Unset
/// <summary>
/// Target object number.
/// </summary>
/// <remarks>
/// This field is an index into the current module's Object Table to specify
/// the target Object. It is a Byte value when the '16-bit Object Number/Module
/// Ordinal Flag' bit in the target flags field is clear and a Word value when
/// the bit is set.
/// </remarks>
public byte TargetObjectNumberByte;
#endregion
#endregion
#region 32-bit Target Offset Flag
#region Set
/// <summary>
/// Target offset.
/// </summary>
/// <remarks>
/// This field is an offset into the specified target Object. It is not
/// present when the Source Type specifies a 16-bit Selector fixup. It
/// is a Word value when the '32-bit Target Offset Flag' bit in the target
/// flags field is clear and a Dword value when the bit is set.
/// </remarks>
public uint TargetOffsetDWORD;
#endregion
#region Unset
/// <summary>
/// Target offset.
/// </summary>
/// <remarks>
/// This field is an offset into the specified target Object. It is not
/// present when the Source Type specifies a 16-bit Selector fixup. It
/// is a Word value when the '32-bit Target Offset Flag' bit in the target
/// flags field is clear and a Dword value when the bit is set.
/// </remarks>
public ushort TargetOffsetWORD;
#endregion
#endregion
#endregion
#region 16-bit Object Number/Module Ordinal Flag [Incompatible with OBJECT / TRGOFF]
#region Set
/// <summary>
/// Ordinal index into the Import Module Name Table.
/// </summary>
/// <remarks>
/// This value is an ordered index in to the Import Module Name Table for
/// the module containing the procedure entry point. It is a Byte value
/// when the '16-bit Object Number/Module Ordinal' Flag bit in the target
/// flags field is clear and a Word value when the bit is set. The loader
/// creates a table of pointers with each pointer in the table corresponds
/// to the modules named in the Import Module Name Table. This value is used
/// by the loader to index into this table created by the loader to locate
/// the referenced module.
/// </remarks>
public ushort OrdinalIndexImportModuleNameTableWORD;
#endregion
#region Unset
/// <summary>
/// Ordinal index into the Import Module Name Table.
/// </summary>
/// <remarks>
/// This value is an ordered index in to the Import Module Name Table for
/// the module containing the procedure entry point. It is a Byte value
/// when the '16-bit Object Number/Module Ordinal' Flag bit in the target
/// flags field is clear and a Word value when the bit is set. The loader
/// creates a table of pointers with each pointer in the table corresponds
/// to the modules named in the Import Module Name Table. This value is used
/// by the loader to index into this table created by the loader to locate
/// the referenced module.
/// </remarks>
public byte OrdinalIndexImportModuleNameTableByte;
#endregion
#endregion
#region MOD ORD# / PROCEDURE NAME OFFSET / ADDITIVE
#region 32-bit Target Offset Flag
#region Set
/// <summary>
/// Offset into the Import Procedure Name Table.
/// </summary>
/// <remarks>
/// This field is an offset into the Import Procedure Name Table. It is
/// a Word value when the '32-bit Target Offset Flag' bit in the target
/// flags field is clear and a Dword value when the bit is set.
/// </remarks>
public uint OffsetImportProcedureNameTableDWORD;
#endregion
#region Unset
/// <summary>
/// Offset into the Import Procedure Name Table.
/// </summary>
/// <remarks>
/// This field is an offset into the Import Procedure Name Table. It is
/// a Word value when the '32-bit Target Offset Flag' bit in the target
/// flags field is clear and a Dword value when the bit is set.
/// </remarks>
public ushort OffsetImportProcedureNameTableWORD;
#endregion
#endregion
#endregion
#region MOD ORD# / IMPORT ORD / ADDITIVE
#region 8-bit Ordinal Flag
#region Set
/// <summary>
/// Imported ordinal number.
/// </summary>
/// <remarks>
/// This is the imported procedure's ordinal number. It is a Byte value when the
/// '8-bit Ordinal' bit in the target flags field is set. Otherwise it is a Word value
/// when the '32-bit Target Offset Flag' bit in the target flags field is clear and a
/// Dword value when the bit is set.
/// </remarks>
public byte ImportedOrdinalNumberByte;
#endregion
#region Unset
#region 32-bit Target Offset Flag
#region Set
/// <summary>
/// Imported ordinal number.
/// </summary>
/// <remarks>
/// This is the imported procedure's ordinal number. It is a Byte value when the
/// '8-bit Ordinal' bit in the target flags field is set. Otherwise it is a Word value
/// when the '32-bit Target Offset Flag' bit in the target flags field is clear and a
/// Dword value when the bit is set.
/// </remarks>
public uint ImportedOrdinalNumberDWORD;
#endregion
#region Unset
/// <summary>
/// Imported ordinal number.
/// </summary>
/// <remarks>
/// This is the imported procedure's ordinal number. It is a Byte value when the
/// '8-bit Ordinal' bit in the target flags field is set. Otherwise it is a Word value
/// when the '32-bit Target Offset Flag' bit in the target flags field is clear and a
/// Dword value when the bit is set.
/// </remarks>
public uint ImportedOrdinalNumberWORD;
#endregion
#endregion
#endregion
#endregion
#endregion
#region Additive Fixup Flag [Incompatible with OBJECT / TRGOFF]
#region Set
#region 32-bit Additive Fixup Flag
#region Set
/// <summary>
/// Additive fixup value.
/// </summary>
/// <remarks>
/// This field exists in the fixup record only when the 'Additive Fixup Flag'
/// bit in the target flags field is set. When the 'Additive Fixup Flag' is
/// clear the fixup record does not contain this field and is immediately
/// followed by the next fixup record (or by the source offset list for this
/// fixup record).
///
/// This value is added to the address derived from the target entry point.
/// This field is a Word value when the '32-bit Additive Flag' bit in the
/// target flags field is clear and a Dword value when the bit is set.
/// </remarks>
public uint AdditiveFixupValueDWORD;
#endregion
#region Unset
/// <summary>
/// Additive fixup value.
/// </summary>
/// <remarks>
/// This field exists in the fixup record only when the 'Additive Fixup Flag'
/// bit in the target flags field is set. When the 'Additive Fixup Flag' is
/// clear the fixup record does not contain this field and is immediately
/// followed by the next fixup record (or by the source offset list for this
/// fixup record).
///
/// This value is added to the address derived from the target entry point.
/// This field is a Word value when the '32-bit Additive Flag' bit in the
/// target flags field is clear and a Dword value when the bit is set.
/// </remarks>
public ushort AdditiveFixupValueWORD;
#endregion
#endregion
#endregion
#endregion
#region SCROFFn
/// <summary>
/// Source offset list.
/// </summary>
/// <remarks>
/// This list is present if the Source List Flag is set in the Target Flags field.
/// The number of entries in the source offset list is defined in the SRCOFF/CNT
/// field. The source offsets are relative to the beginning of the page where the
/// fixups are to be made.
/// </remarks>
public ushort[] SourceOffsetList;
#endregion
}
}

View File

@@ -0,0 +1,41 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The import module name table defines the module name strings imported through
/// dynamic link references. These strings are referenced through the imported
/// relocation fixups.
///
/// To determine the length of the import module name table subtract the import
/// module name table offset from the import procedure name table offset. These
/// values are located in the linear EXE header. The end of the import module
/// name table is not terminated by a special character, it is followed directly
/// by the import procedure name table.
///
/// The strings are CASE SENSITIVE and NOT NULL TERMINATED.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ImportModuleNameTableEntry
{
/// <summary>
/// String Length.
/// </summary>
/// <remarks>
/// This defines the length of the string in bytes. The length of each
/// ascii name string is limited to 127 characters.
/// </remarks>
public byte Length;
/// <summary>
/// ASCII String.
/// </summary>
/// <remarks>
/// This is a variable length string with it's length defined in bytes by
/// the LEN field. The string is case sensitive and is not null terminated.
/// </remarks>
public string Name;
}
}

View File

@@ -0,0 +1,49 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The import procedure name table defines the procedure name strings imported
/// by this module through dynamic link references. These strings are referenced
/// through the imported relocation fixups.
///
/// To determine the length of the import procedure name table add the fixup
/// section size to the fixup page table offset, this computes the offset to
/// the end of the fixup section, then subtract the import procedure name table
/// offset. These values are located in the linear EXE header. The import
/// procedure name table is followed by the data pages section. Since the data
/// pages section is aligned on a 'page size' boundary, padded space may exist
/// between the last import name string and the first page in the data pages
/// section. If this padded space exists it will be zero filled.
///
/// The strings are CASE SENSITIVE and NOT NULL TERMINATED.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ImportModuleProcedureNameTableEntry
{
/// <summary>
/// String Length.
/// </summary>
/// <remarks>
/// This defines the length of the string in bytes. The length of each
/// ascii name string is limited to 127 characters.
///
/// The high bit in the LEN field (bit 7) is defined as an Overload bit.
/// This bit signifies that additional information is contained in the
/// linear EXE module and will be used in the future for parameter type
/// checking.
/// </remarks>
public byte Length;
/// <summary>
/// ASCII String.
/// </summary>
/// <remarks>
/// This is a variable length string with it's length defined in bytes by
/// the LEN field. The string is case sensitive and is not null terminated.
/// </remarks>
public string Name;
}
}

View File

@@ -0,0 +1,426 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.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"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class InformationBlock
{
/// <summary>
/// Specifies the signature word
/// 'LE' (4Ch 45H)
/// 'LX' (4Ch 58H)
/// </summary>
/// <remarks>
/// The signature word is used by the loader to identify the EXE
/// file as a valid 32-bit Linear Executable Module Format.
/// </remarks>
public string Signature;
/// <summary>
/// Byte Ordering.
/// </summary>
/// <remarks>
/// This byte specifies the byte ordering for the linear EXE format.
/// </remarks>
public ByteOrder ByteOrder;
/// <summary>
/// Word Ordering.
/// </summary>
/// <remarks>
/// This byte specifies the Word ordering for the linear EXE format.
/// </remarks>
public WordOrder WordOrder;
/// <summary>
/// Linear EXE Format Level.
/// </summary>
/// <remarks>
/// The Linear EXE Format Level is set to 0 for the initial version of the
/// 32-bit linear EXE format. Each incompatible change to the linear EXE
/// format must increment this value. This allows the system to recognized
/// future EXE file versions so that an appropriate error message may be
/// displayed if an attempt is made to load them.
/// </remarks>
public uint ExecutableFormatLevel;
/// <summary>
/// Module CPU Type.
/// </summary>
/// <remarks>
/// This field specifies the type of CPU required by this module to run.
/// </remarks>
public CPUType CPUType;
/// <summary>
/// Module OS Type.
/// </summary>
/// <remarks>
/// This field specifies the type of Operating system required to run this module.
/// </remarks>
public OperatingSystem ModuleOS;
/// <summary>
/// Module version
/// </summary>
/// <remarks>
/// This is useful for differentiating between revisions of dynamic linked modules.
/// This value is specified at link time by the user.
/// </remarks>
public uint ModuleVersion;
/// <summary>
/// Module type flags
/// </summary>
public ModuleFlags ModuleTypeFlags;
/// <summary>
/// Number of pages in module.
/// </summary>
/// <remarks>
/// This field specifies the number of pages physically contained in this module.
/// In other words, pages containing either enumerated or iterated data, or
/// zero-fill pages that have relocations, not invalid or zero-fill pages implied
/// by the Virtual Size in the Object Table being larger than the number of pages
/// actually in the linear EXE file. These pages are contained in the 'preload
/// pages', 'demand load pages' and 'iterated data pages' sections of the linear
/// EXE module. This is used to determine the size of the page information tables
/// in the linear EXE module.
/// </remarks>
public uint ModuleNumberPages;
/// <summary>
/// The Object number to which the Entry Address is relative.
/// </summary>
/// <remarks>
/// This specifies the object to which the Entry Address is relative. This must be
/// a nonzero value for a program module to be correctly loaded. A zero value for
/// a library module indicates that no library entry routine exists. If this value
/// is zero, then both the Per-process Library Initialization bit and the Per-process
/// Library Termination bit must be clear in the module flags, or else the loader
/// will fail to load the module. Further, if the Per-process Library Termination bit
/// is set, then the object to which this field refers must be a 32-bit object (i.e.,
/// the Big/Default bit must be set in the object flags; see below).
/// </remarks>
public uint InitialObjectCS;
/// <summary>
/// Entry Address of module.
/// </summary>
/// <remarks>
/// The Entry Address is the starting address for program modules and the library
/// initialization and Library termination address for library modules.
/// </remarks>
public uint InitialEIP;
/// <summary>
/// The Object number to which the ESP is relative.
/// </summary>
/// <remarks>
/// This specifies the object to which the starting ESP is relative. This must be a
/// nonzero value for a program module to be correctly loaded. This field is ignored
/// for a library module.
/// </remarks>
public uint InitialObjectSS;
/// <summary>
/// Starting stack address of module.
/// </summary>
/// <remarks>
/// The ESP defines the starting stack pointer address for program modules. A zero
/// value in this field indicates that the stack pointer is to be initialized to the
/// highest address/offset in the object. This field is ignored for a library module.
/// </remarks>
public uint InitialESP;
/// <summary>
/// The size of one page for this system.
/// </summary>
/// <remarks>
/// This field specifies the page size used by the linear EXE format and the system.
/// For the initial version of this linear EXE format the page size is 4Kbytes.
/// (The 4K page size is specified by a value of 4096 in this field.)
/// </remarks>
public uint MemoryPageSize;
/// <summary>
/// The shift left bits for page offsets.
/// </summary>
/// <remarks>
/// This field gives the number of bit positions to shift left when interpreting
/// the Object Page Table entries' page offset field. This determines the alignment
/// of the page information in the file. For example, a value of 4 in this field
/// would align all pages in the Data Pages and Iterated Pages sections on 16 byte
/// (paragraph) boundaries. A Page Offset Shift of 9 would align all pages on a
/// 512 byte (disk sector) basis. The default value for this field is 12 (decimal),
/// which give a 4096 byte alignment. All other offsets are byte aligned.
/// </remarks>
public uint BytesOnLastPage;
/// <summary>
/// Total size of the fixup information in bytes.
/// </summary>
/// <remarks>
/// This includes the following 4 tables:
/// - Fixup Page Table
/// - Fixup Record Table
/// - Import Module name Table
/// - Import Procedure Name Table
/// </remarks>
public uint FixupSectionSize;
/// <summary>
/// Checksum for fixup information.
/// </summary>
/// <remarks>
/// This is a cryptographic checksum covering all of the fixup information. The
/// checksum for the fixup information is kept separate because the fixup data is
/// not always loaded into main memory with the 'loader section'. If the checksum
/// feature is not implemented, then the linker will set these fields to zero.
/// </remarks>
public uint FixupSectionChecksum;
/// <summary>
/// Size of memory resident tables.
/// </summary>
/// <remarks>
/// This is the total size in bytes of the tables required to be memory resident
/// for the module, while the module is in use. This total size includes all
/// tables from the Object Table down to and including the Per-Page Checksum Table.
/// </remarks>
public uint LoaderSectionSize;
/// <summary>
/// Checksum for loader section.
/// </summary>
/// <remarks>
/// This is a cryptographic checksum covering all of the loader section information.
/// If the checksum feature is not implemented, then the linker will set these fields
/// to zero.
/// </remarks>
public uint LoaderSectionChecksum;
/// <summary>
/// Object Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint ObjectTableOffset;
/// <summary>
/// Object Table Count.
/// </summary>
/// <remarks>
/// This defines the number of entries in Object Table.
/// </remarks>
public uint ObjectTableCount;
/// <summary>
/// Object Page Table offset
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint ObjectPageMapOffset;
/// <summary>
/// Object Iterated Pages offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint ObjectIterateDataMapOffset;
/// <summary>
/// Resource Table offset
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint ResourceTableOffset;
/// <summary>
/// Number of entries in Resource Table.
/// </summary>
public uint ResourceTableCount;
/// <summary>
/// Resident Name Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint ResidentNamesTableOffset;
/// <summary>
/// Entry Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint EntryTableOffset;
/// <summary>
/// Module Format Directives Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint ModuleDirectivesTableOffset;
/// <summary>
/// Number of Module Format Directives in the Table.
/// </summary>
/// <remarks>
/// This field specifies the number of entries in the
/// Module Format Directives Table.
/// </remarks>
public uint ModuleDirectivesCount;
/// <summary>
/// Fixup Page Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint FixupPageTableOffset;
/// <summary>
/// Fixup Record Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint FixupRecordTableOffset;
/// <summary>
/// Import Module Name Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint ImportedModulesNameTableOffset;
/// <summary>
/// The number of entries in the Import Module Name Table.
/// </summary>
public uint ImportedModulesCount;
/// <summary>
/// Import Procedure Name Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint ImportProcedureNameTableOffset;
/// <summary>
/// Per-page Checksum Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint PerPageChecksumTableOffset;
/// <summary>
/// Data Pages Offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the EXE file.
/// </remarks>
public uint DataPagesOffset;
/// <summary>
/// Number of Preload pages for this module.
/// </summary>
/// <remarks>
/// Note that OS/2 2.0 does not respect the preload of pages as specified
/// in the executable file for performance reasons.
/// </remarks>
public uint PreloadPageCount;
/// <summary>
/// Non-Resident Name Table offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the EXE file.
/// </remarks>
public uint NonResidentNamesTableOffset;
/// <summary>
/// Number of bytes in the Non-resident name table.
/// </summary>
public uint NonResidentNamesTableLength;
/// <summary>
/// Non-Resident Name Table Checksum.
/// </summary>
/// <remarks>
/// This is a cryptographic checksum of the Non-Resident Name Table.
/// </remarks>
public uint NonResidentNamesTableChecksum;
/// <summary>
/// The Auto Data Segment Object number.
/// </summary>
/// <remarks>
/// This is the object number for the Auto Data Segment used by 16-bit modules.
/// This field is supported for 16-bit compatibility only and is not used by
/// 32-bit modules.
/// </remarks>
public uint AutomaticDataObject;
/// <summary>
/// Debug Information offset.
/// </summary>
/// <remarks>
/// This offset is relative to the beginning of the linear EXE header.
/// </remarks>
public uint DebugInformationOffset;
/// <summary>
/// Debug Information length.
/// </summary>
/// <remarks>
/// The length of the debug information in bytes.
/// </remarks>
public uint DebugInformationLength;
/// <summary>
/// Instance pages in preload section.
/// </summary>
/// <remarks>
/// The number of instance data pages found in the preload section.
/// </remarks>
public uint PreloadInstancePagesNumber;
/// <summary>
/// Instance pages in demand section.
/// </summary>
/// <remarks>
/// The number of instance data pages found in the demand section.
/// </remarks>
public uint DemandInstancePagesNumber;
/// <summary>
/// Heap size added to the Auto DS Object.
/// </summary>
/// <remarks>
/// The heap size is the number of bytes added to the Auto Data Segment
/// by the loader. This field is supported for 16-bit compatibility only and
/// is not used by 32-bit modules.
/// </remarks>
public uint ExtraHeapAllocation;
}
}

View File

@@ -0,0 +1,48 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The Module Format Directives Table is an optional table that allows additional
/// options to be specified. It also allows for the extension of the linear EXE
/// format by allowing additional tables of information to be added to the linear
/// EXE module without affecting the format of the linear EXE header. Likewise,
/// module format directives provide a place in the linear EXE module for
/// 'temporary tables' of information, such as incremental linking information
/// and statistic information gathered on the module. When there are no module
/// format directives for a linear EXE module, the fields in the linear EXE header
/// referencing the module format directives table are zero.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ModuleFormatDirectivesTableEntry
{
/// <summary>
/// Directive number.
/// </summary>
/// <remarks>
/// The directive number specifies the type of directive defined. This can be
/// used to determine the format of the information in the directive data.
/// </remarks>
public DirectiveNumber DirectiveNumber;
/// <summary>
/// Directive data length.
/// </summary>
/// <remarks>
/// This specifies the length in byte of the directive data for this directive number.
/// </remarks>
public ushort DirectiveDataLength;
/// <summary>
/// Directive data offset.
/// </summary>
/// <remarks>
/// This is the offset to the directive data for this directive number. It is relative
/// to beginning of linear EXE header for a resident table, and relative to the
/// beginning of the EXE file for non-resident tables.
/// </remarks>
public uint DirectiveDataOffset;
}
}

View File

@@ -0,0 +1,64 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The resident and non-resident name tables define the ASCII names and ordinal
/// numbers for exported entries in the module. In addition the first entry in
/// the resident name table contains the module name. These tables are used to
/// translate a procedure name string into an ordinal number by searching for a
/// matching name string. The ordinal number is used to locate the entry point
/// information in the entry table.
///
/// The resident name table is kept resident in system memory while the module is
/// loaded.It is intended to contain the exported entry point names that are
/// frequently dynamically linked to by name.Non-resident names are not kept in
/// memory and are read from the EXE file when a dynamic link reference is made.
/// Exported entry point names that are infrequently dynamically linked to by name
/// or are commonly referenced by ordinal number should be placed in the
/// non-resident name table.The trade off made for references by name is performance
/// vs memory usage.
///
/// Import references by name require these tables to be searched to obtain the entry
/// point ordinal number.Import references by ordinal number provide the fastest
/// lookup since the search of these tables is not required.
///
/// The strings are CASE SENSITIVE and are NOT NULL TERMINATED.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class NonResidentNamesTableEntry
{
/// <summary>
/// String Length.
/// </summary>
/// <remarks>
/// This defines the length of the string in bytes. A zero length indicates there are
/// no more entries in table. The length of each ascii name string is limited to 127
/// characters.
///
/// The high bit in the LEN field (bit 7) is defined as an Overload bit. This bit
/// signifies that additional information is contained in the linear EXE module and
/// will be used in the future for parameter type checking.
/// </remarks>
public byte Length;
/// <summary>
/// ASCII String.
/// </summary>
/// <remarks>
/// This is a variable length string with it's length defined in bytes by the LEN field.
/// The string is case case sensitive and is not null terminated.
/// </remarks>
public string Name;
/// <summary>
/// Ordinal number.
/// </summary>
/// <remarks>
/// The ordinal number in an ordered index into the entry table for this entry point.
/// </remarks>
public ushort OrdinalNumber;
}
}

View File

@@ -0,0 +1,60 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The Object page table provides information about a logical page in an object.
/// A logical page may be an enumerated page, a pseudo page or an iterated page.
/// The structure of the object page table in conjunction with the structure of
/// the object table allows for efficient access of a page when a page fault occurs,
/// while still allowing the physical page data to be located in the preload page,
/// demand load page or iterated data page sections in the linear EXE module. The
/// logical page entries in the Object Page Table are numbered starting from one.
/// The Object Page Table is parallel to the Fixup Page Table as they are both
/// indexed by the logical page number.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ObjectPageMapEntry
{
/// <summary>
/// Offset to the page data in the EXE file.
/// </summary>
/// <remarks>
/// This field, when bit shifted left by the PAGE OFFSET SHIFT from the module
/// header, specifies the offset from the beginning of the Preload Page section
/// of the physical page data in the EXE file that corresponds to this logical
/// page entry. The page data may reside in the Preload Pages, Demand Load Pages
/// or the Iterated Data Pages sections.
///
/// If the FLAGS field specifies that this is a zero-Filled page then the PAGE
/// DATA OFFSET field will contain a 0.
///
/// If the logical page is specified as an iterated data page, as indicated by
/// the FLAGS field, then this field specifies the offset into the Iterated Data
/// Pages section.
///
/// The logical page number (Object Page Table index), is used to index the Fixup
/// Page Table to find any fixups associated with the logical page.
/// </remarks>
public uint PageDataOffset;
/// <summary>
/// Number of bytes of data for this page.
/// </summary>
/// <remarks>
/// This field specifies the actual number of bytes that represent the page in the
/// file. If the PAGE SIZE field from the module header is greater than the value
/// of this field and the FLAGS field indicates a Legal Physical Page, the remaining
/// bytes are to be filled with zeros. If the FLAGS field indicates an Iterated Data
/// Page, the iterated data records will completely fill out the remainder.
/// </remarks>
public ushort DataSize;
/// <summary>
/// Attributes specifying characteristics of this logical page.
/// </summary>
public ObjectPageFlags Flags;
}
}

View File

@@ -0,0 +1,82 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The object table contains information that describes each segment in
/// an executable file. This information includes segment length, segment
/// type, and segment-relocation data. The following list summarizes the
/// values found in in the segment table (the locations are relative to
/// the beginning of each entry):
/// </summary>
/// <remarks>
/// Entries in the Object Table are numbered starting from one.
/// </remarks>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ObjectTableEntry
{
/// <summary>
/// Virtual memory size.
/// </summary>
/// <remarks>
/// This is the size of the object that will be allocated when the object
/// is loaded. The object's virtual size (rounded up to the page size value)
/// must be greater than or equal to the total size of the pages in the EXE
/// file for the object. This memory size must also be large enough to
/// contain all of the iterated data and uninitialized data in the EXE file.
/// </remarks>
public uint VirtualSegmentSize;
/// <summary>
/// Relocation Base Address.
/// </summary>
/// <remarks>
/// The relocation base address the object is currently relocated to. If the
/// internal relocation fixups for the module have been removed, this is the
/// address the object will be allocated at by the loader.
/// </remarks>
public uint RelocationBaseAddress;
/// <summary>
/// Flag bits for the object.
/// </summary>
public ObjectFlags ObjectFlags;
/// <summary>
/// Object Page Table Index.
/// </summary>
/// <remarks>
/// This specifies the number of the first object page table entry for this object.
/// The object page table specifies where in the EXE file a page can be found for
/// a given object and specifies per-page attributes.
///
/// The object table entries are ordered by logical page in the object table. In
/// other words the object table entries are sorted based on the object page table
/// index value.
/// </remarks>
public uint PageTableIndex;
/// <summary>
/// # of object page table entries for this object.
/// </summary>
/// <remarks>
/// Any logical pages at the end of an object that do not have an entry in the object
/// page table associated with them are handled as zero filled or invalid pages by
/// the loader.
///
/// When the last logical pages of an object are not specified with an object page
/// table entry, they are treated as either zero filled pages or invalid pages based
/// on the last entry in the object page table for that object. If the last entry
/// was neither a zero filled or invalid page, then the additional pages are treated
/// as zero filled pages.
/// </remarks>
public uint PageTableEntries;
/// <summary>
/// Reserved for future use. Must be set to zero.
/// </summary>
public uint Reserved;
}
}

View File

@@ -0,0 +1,24 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The Per-Page Checksum table provides space for a cryptographic checksum for
/// each physical page in the EXE file.
///
/// The checksum table is arranged such that the first entry in the table corresponds
/// to the first logical page of code/data in the EXE file (usually a preload page)
/// and the last entry corresponds to the last logical page in the EXE file (usually
/// a iterated data page).
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class PerPageChecksumTableEntry
{
/// <summary>
/// Cryptographic checksum.
/// </summary>
public uint Checksum;
}
}

View File

@@ -0,0 +1,64 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The resident and non-resident name tables define the ASCII names and ordinal
/// numbers for exported entries in the module. In addition the first entry in
/// the resident name table contains the module name. These tables are used to
/// translate a procedure name string into an ordinal number by searching for a
/// matching name string. The ordinal number is used to locate the entry point
/// information in the entry table.
///
/// The resident name table is kept resident in system memory while the module is
/// loaded. It is intended to contain the exported entry point names that are
/// frequently dynamically linked to by name. Non-resident names are not kept in
/// memory and are read from the EXE file when a dynamic link reference is made.
/// Exported entry point names that are infrequently dynamically linked to by name
/// or are commonly referenced by ordinal number should be placed in the
/// non-resident name table. The trade off made for references by name is performance
/// vs memory usage.
///
/// Import references by name require these tables to be searched to obtain the entry
/// point ordinal number.Import references by ordinal number provide the fastest
/// lookup since the search of these tables is not required.
///
/// The strings are CASE SENSITIVE and are NOT NULL TERMINATED.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ResidentNamesTableEntry
{
/// <summary>
/// String Length.
/// </summary>
/// <remarks>
/// This defines the length of the string in bytes. A zero length indicates there are
/// no more entries in table. The length of each ascii name string is limited to 127
/// characters.
///
/// The high bit in the LEN field (bit 7) is defined as an Overload bit. This bit
/// signifies that additional information is contained in the linear EXE module and
/// will be used in the future for parameter type checking.
/// </remarks>
public byte Length;
/// <summary>
/// ASCII String.
/// </summary>
/// <remarks>
/// This is a variable length string with it's length defined in bytes by the LEN field.
/// The string is case case sensitive and is not null terminated.
/// </remarks>
public string Name;
/// <summary>
/// Ordinal number.
/// </summary>
/// <remarks>
/// The ordinal number in an ordered index into the entry table for this entry point.
/// </remarks>
public ushort OrdinalNumber;
}
}

View File

@@ -0,0 +1,46 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The resource table is an array of resource table entries. Each resource table
/// entry contains a type ID and name ID. These entries are used to locate resource
/// objects contained in the Object table. The number of entries in the resource
/// table is defined by the Resource Table Count located in the linear EXE header.
/// More than one resource may be contained within a single object. Resource table
/// entries are in a sorted order, (ascending, by Resource Name ID within the
/// Resource Type ID). This allows the DosGetResource API function to use a binary
/// search when looking up a resource in a 32-bit module instead of the linear search
/// being used in the current 16-bit module.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ResourceTableEntry
{
/// <summary>
/// Resource type ID.
/// </summary>
public ResourceTableEntryType TypeID;
/// <summary>
/// An ID used as a name for the resource when referred to.
/// </summary>
public ushort NameID;
/// <summary>
/// The number of bytes the resource consists of.
/// </summary>
public uint ResourceSize;
/// <summary>
/// The number of the object which contains the resource.
/// </summary>
public ushort ObjectNumber;
/// <summary>
/// The offset within the specified object where the resource begins.
/// </summary>
public uint Offset;
}
}

View File

@@ -0,0 +1,85 @@
using System.Runtime.InteropServices;
namespace BinaryObjectScanner.Models.LinearExecutable
{
/// <summary>
/// The Verify Record Directive Table is an optional table. It maintains a record
/// of the pages in the EXE file that have been fixed up and written back to the
/// original linear EXE module, along with the module dependencies used to perform
/// these fixups. This table provides an efficient means for verifying the virtual
/// addresses required for the fixed up pages when the module is loaded.
/// </summary>
/// <see href="https://faydoc.tripod.com/formats/exe-LE.htm"/>
/// <see href="http://www.edm2.com/index.php/LX_-_Linear_eXecutable_Module_Format_Description"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class VerifyRecordDirectiveTableEntry
{
/// <summary>
/// Number of module dependencies.
/// </summary>
/// <remarks>
/// This field specifies how many entries there are in the verify record
/// directive table. This is equal to the number of modules referenced by
/// this module.
/// </remarks>
public ushort EntryCount;
/// <summary>
/// Ordinal index into the Import Module Name Table.
/// </summary>
/// <remarks>
/// This value is an ordered index in to the Import Module Name Table for
/// the referenced module.
/// </remarks>
public ushort OrdinalIndex;
/// <summary>
/// Module Version.
/// </summary>
/// <remarks>
/// This is the version of the referenced module that the fixups were
/// originally performed.This is used to insure the same version of the
/// referenced module is loaded that was fixed up in this module and
/// therefore the fixups are still correct. This requires the version
/// number in a module to be incremented anytime the entry point offsets
/// change.
/// </remarks>
public ushort Version;
/// <summary>
/// Module # of Object Entries.
/// </summary>
/// <remarks>
/// This field is used to identify the number of object verify entries
/// that follow for the referenced module.
/// </remarks>
public ushort ObjectEntriesCount;
/// <summary>
/// Object # in Module.
/// </summary>
/// <remarks>
/// This field specifies the object number in the referenced module that
/// is being verified.
/// </remarks>
public ushort ObjectNumberInModule;
/// <summary>
/// Object load base address.
/// </summary>
/// <remarks>
/// This is the address that the object was loaded at when the fixups were
/// performed.
/// </remarks>
public ushort ObjectLoadBaseAddress;
/// <summary>
/// Object virtual address size.
/// </summary>
/// <remarks>
/// This field specifies the total amount of virtual memory required for
/// this object.
/// </remarks>
public ushort ObjectVirtualAddressSize;
}
}