Port over executable header code from Wise

This commit is contained in:
Matt Nadareski
2021-03-25 15:53:45 -07:00
parent 1672c73a57
commit c8b271ac76
31 changed files with 1634 additions and 481 deletions

View File

@@ -0,0 +1,99 @@
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// All constant values needed for file header reading
/// </summary>
internal static class Constants
{
public const ushort IMAGE_DOS_SIGNATURE = 0x5A4D; // MZ
public const ushort IMAGE_OS2_SIGNATURE = 0x454E; // NE
public const ushort IMAGE_OS2_SIGNATURE_LE = 0x454C; // LE
public const uint IMAGE_NT_SIGNATURE = 0x00004550; // PE00
#region IMAGE_DOS_HEADER
public const ushort ENEWEXE = 0x40; // Value of E_LFARLC for new .EXEs
public const ushort ENEWHDR = 0x003C; // Offset in old hdr. of ptr. to new
public const ushort ERESWDS = 0x0010; // No. of reserved words (OLD)
public const ushort ERES1WDS = 0x0004; // No. of reserved words in e_res
public const ushort ERES2WDS = 0x000A; // No. of reserved words in e_res2
public const ushort ECP = 0x0004; // Offset in struct of E_CP
public const ushort ECBLP = 0x0002; // Offset in struct of E_CBLP
public const ushort EMINALLOC = 0x000A; // Offset in struct of E_MINALLOC
#endregion
#region IMAGE_OS2_HEADER
public const ushort NERESWORDS = 3; // 6 bytes reserved
public const ushort NECRC = 8; //Offset into new header of NE_CRC
#endregion
#region NewSeg
public const ushort NSALIGN = 9; // Segment data aligned on 512 byte boundaries
public const ushort NSLOADED = 0x0004; // ns_sector field contains memory addr
#endregion
#region RsrcNameInfo
public const ushort RSORDID = 0x8000; /* if high bit of ID set then integer id */
/* otherwise ID is offset of string from
the beginning of the resource table */
/* Ideally these are the same as the */
/* corresponding segment flags */
public const ushort RNMOVE = 0x0010; /* Moveable resource */
public const ushort RNPURE = 0x0020; /* Pure (read-only) resource */
public const ushort RNPRELOAD = 0x0040; /* Preloaded resource */
public const ushort RNDISCARD = 0xF000; /* Discard priority level for resource */
#endregion
#region IMAGE_OPTIONAL_HEADER
public const ushort IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16;
/* Directory Entries */
/* Export Directory */
public const byte IMAGE_DIRECTORY_ENTRY_EXPORT = 0;
/* Import Directory */
public const byte IMAGE_DIRECTORY_ENTRY_IMPORT = 1;
/* Resource Directory */
public const byte IMAGE_DIRECTORY_ENTRY_RESOURCE = 2;
/* Exception Directory */
public const byte IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3;
/* Security Directory */
public const byte IMAGE_DIRECTORY_ENTRY_SECURITY = 4;
/* Base Relocation Table */
public const byte IMAGE_DIRECTORY_ENTRY_BASERELOC = 5;
/* Debug Directory */
public const byte IMAGE_DIRECTORY_ENTRY_DEBUG = 6;
/* Description String */
public const byte IMAGE_DIRECTORY_ENTRY_COPYRIGHT = 7;
/* Machine Value (MIPS GP) */
public const byte IMAGE_DIRECTORY_ENTRY_GLOBALPTR = 8;
/* TLS Directory */
public const byte IMAGE_DIRECTORY_ENTRY_TLS = 9;
/* Load Configuration Directory */
public const byte IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG = 10;
#endregion
#region IMAGE_SECTION_HEADER
public const int IMAGE_SIZEOF_SHORT_NAME = 8;
#endregion
#region IMAGE_RESOURCE_DATA_ENTRY
public const uint IMAGE_RESOURCE_DATA_IS_DIRECTORY = 0x80000000;
public const uint IMAGE_RESOURCE_NAME_IS_STRING = 0x80000000;
#endregion
}
}

View File

@@ -0,0 +1,384 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System;
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal enum ExecutableType
{
Unknown,
NE,
PE,
}
/// <summary>
/// Format of NE_FLAGS(x):
///
/// p Not-a-process
/// x Unused
/// e Errors in image
/// x Unused
/// b Bound as family app
/// ttt Application type
/// f Floating-point instructions
/// 3 386 instructions
/// 2 286 instructions
/// 0 8086 instructions
/// P Protected mode only
/// p Per-process library initialization
/// i Instance data
/// s Solo data
/// </summary>
[Flags]
internal enum NeFlags : ushort
{
/// <summary>
/// Not a process
/// </summary>
NENOTP = 0x8000,
/// <summary>
/// Errors in image
/// </summary>
NEIERR = 0x2000,
/// <summary>
/// Bound as family app
/// </summary>
NEBOUND = 0x0800,
/// <summary>
/// Application type mask
/// </summary>
NEAPPTYP = 0x0700,
/// <summary>
/// Not compatible with P.M. Windowing
/// </summary>
NENOTWINCOMPAT = 0x0100,
/// <summary>
/// Compatible with P.M. Windowing
/// </summary>
NEWINCOMPAT = 0x0200,
/// <summary>
/// Uses P.M. Windowing API
/// </summary>
NEWINAPI = 0x0300,
/// <summary>
/// Floating-point instructions
/// </summary>
NEFLTP = 0x0080,
/// <summary>
/// 386 instructions
/// </summary>
NEI386 = 0x0040,
/// <summary>
/// 286 instructions
/// </summary>
NEI286 = 0x0020,
/// <summary>
/// 8086 instructions
/// </summary>
NEI086 = 0x0010,
/// <summary>
/// Runs in protected mode only
/// </summary>
NEPROT = 0x0008,
/// <summary>
/// Per-Process Library Initialization
/// </summary>
NEPPLI = 0x0004,
/// <summary>
/// Instance data
/// </summary>
NEINST = 0x0002,
/// <summary>
/// Solo data
/// </summary>
NESOLO = 0x0001,
}
/// <summary>
/// Format of NR_FLAGS(x):
///
/// xxxxx Unused
/// a Additive fixup
/// rr Reference type
/// </summary>
[Flags]
internal enum NrFlags : byte
{
/// <summary>
/// Additive fixup
/// </summary>
NRADD = 0x04,
/// <summary>
/// Reference type mask
/// </summary>
NRRTYP = 0x03,
/// <summary>
/// Internal reference
/// </summary>
NRRINT = 0x00,
/// <summary>
/// Import by ordinal
/// </summary>
NRRORD = 0x01,
/// <summary>
/// Import by name
/// </summary>
NRRNAM = 0x02,
/// <summary>
/// Operating system fixup
/// </summary>
NRROSF = 0x03,
}
/// <summary>
/// Format of NR_STYPE(x):
///
/// xxxxx Unused
/// sss Source type
////
/// </summary>
[Flags]
internal enum NrStype : byte
{
/// <summary>
/// Source type mask
/// </summary>
NRSTYP = 0x0f,
/// <summary>
/// lo byte
/// </summary>
NRSBYT = 0x00,
/// <summary>
/// 16-bit segment
/// </summary>
NRSSEG = 0x02,
/// <summary>
/// 32-bit pointer
/// </summary>
NRSPTR = 0x03,
/// <summary>
/// 16-bit offset
/// </summary>
NRSOFF = 0x05,
/// <summary>
/// 48-bit pointer
/// </summary>
NRSPTR48 = 0x0B,
/// <summary>
/// 32-bit offset
/// </summary>
NRSOFF32 = 0x0D,
}
/// <summary>
/// Format of NS_FLAGS(x)
///
/// x Unused
/// h Huge segment
/// c 32-bit code segment
/// d Discardable segment
/// DD I/O privilege level (286 DPL bits)
/// c Conforming segment
/// r Segment has relocations
/// e Execute/read only
/// p Preload segment
/// P Pure segment
/// m Movable segment
/// i Iterated segment
/// ttt Segment type
/// </summary>
[Flags]
internal enum NsFlags : ushort
{
/// <summary>
/// Segment type mask
/// </summary>
NSTYPE = 0x0007,
/// <summary>
/// Code segment
/// </summary>
NSCODE = 0x0000,
/// <summary>
/// Data segment
/// </summary>
NSDATA = 0x0001,
/// <summary>
/// Iterated segment flag
/// </summary>
NSITER = 0x0008,
/// <summary>
/// Movable segment flag
/// </summary>
NSMOVE = 0x0010,
/// <summary>
/// Shared segment flag
/// </summary>
NSSHARED = 0x0020,
/// <summary>
/// For compatibility
/// </summary>
NSPURE = 0x0020,
/// <summary>
/// Preload segment flag
/// </summary>
NSPRELOAD = 0x0040,
/// <summary>
/// Execute-only (code segment), or read-only (data segment)
/// </summary>
NSEXRD = 0x0080,
/// <summary>
/// Segment has relocations
/// </summary>
NSRELOC = 0x0100,
/// <summary>
/// Conforming segment
/// </summary>
NSCONFORM = 0x0200,
/// <summary>
/// I/O privilege level (286 DPL bits)
/// </summary>
NSDPL = 0x0C00,
/// <summary>
/// Left shift count for SEGDPL field
/// </summary>
SHIFTDPL = 10,
/// <summary>
/// Segment is discardable
/// </summary>
NSDISCARD = 0x1000,
/// <summary>
/// 32-bit code segment
/// </summary>
NS32BIT = 0x2000,
/// <summary>
/// Huge memory segment, length of segment and minimum allocation size are in segment sector units
/// </summary>
NSHUGE = 0x4000,
}
/// <summary>
/// Predefined Resource Types
/// </summary>
internal enum ResourceTypes : ushort
{
RT_CURSOR = 1,
RT_BITMAP = 2,
RT_ICON = 3,
RT_MENU = 4,
RT_DIALOG = 5,
RT_STRING = 6,
RT_FONTDIR = 7,
RT_FONT = 8,
RT_ACCELERATOR = 9,
RT_RCDATA = 10,
RT_MESSAGELIST = 11, // RT_MESSAGETABLE
RT_GROUP_CURSOR = 12,
RT_RESERVED_1 = 13, // Undefined
RT_GROUP_ICON = 14,
RT_RESERVED_2 = 15, // Undefined
RT_VERSION = 16,
RT_DLGINCLUDE = 17,
RT_PLUGPLAY = 19,
RT_VXD = 20,
RT_ANICURSOR = 21,
RT_NEWRESOURCE = 0x2000,
RT_NEWBITMAP = (RT_BITMAP |RT_NEWRESOURCE),
RT_NEWMENU = (RT_MENU |RT_NEWRESOURCE),
RT_NEWDIALOG = (RT_DIALOG |RT_NEWRESOURCE),
RT_ERROR = 0x7fff,
}
[Flags]
internal enum SectionCharacteristics : uint
{
CodeSection = 0x00000020,
InitializedDataSection = 0x00000040,
UninitializedDataSection = 0x00000080,
SectionCannotBeCached = 0x04000000,
SectionIsNotPageable = 0x08000000,
SectionIsShared = 0x10000000,
ExecutableSection = 0x20000000,
ReadableSection = 0x40000000,
WritableSection = 0x80000000,
}
[Flags]
internal enum TargetOperatingSystems : byte
{
/// <summary>
/// Unknown (any "new-format" OS)
/// </summary>
NE_UNKNOWN = 0x0,
/// <summary>
/// Microsoft/IBM OS/2 (default)
/// </summary>
NE_OS2 = 0x1,
/// <summary>
/// Microsoft Windows
/// </summary>
NE_WINDOWS = 0x2,
/// <summary>
/// Microsoft MS-DOS 4.x
/// </summary>
NE_DOS4 = 0x3,
/// <summary>
/// Windows 386
/// </summary>
NE_WIN386 = 0x4,
}
}

View File

@@ -1,12 +1,32 @@
using System.Runtime.InteropServices;
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_DATA_DIRECTORY
internal class IMAGE_DATA_DIRECTORY
{
public uint VirtualAddress;
public uint Size;
public uint VirtualAddress { get; private set; }
public uint Size { get; private set; }
public static IMAGE_DATA_DIRECTORY Deserialize(Stream stream)
{
IMAGE_DATA_DIRECTORY idd = new IMAGE_DATA_DIRECTORY();
idd.VirtualAddress = stream.ReadUInt32();
idd.Size = stream.ReadUInt32();
return idd;
}
}
}
}

View File

@@ -1,30 +1,77 @@
using System.Runtime.InteropServices;
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_DOS_HEADER
/// <summary>
/// DOS 1, 2, 3 .EXE header
/// </summary>
internal class IMAGE_DOS_HEADER
{
public ushort e_magic; /* 00: MZ Header signature */
public ushort e_cblp; /* 02: Bytes on last page of file */
public ushort e_cp; /* 04: Pages in file */
public ushort e_crlc; /* 06: Relocations */
public ushort e_cparhdr; /* 08: Size of header in paragraphs */
public ushort e_minalloc; /* 0a: Minimum extra paragraphs needed */
public ushort e_maxalloc; /* 0c: Maximum extra paragraphs needed */
public ushort e_ss; /* 0e: Initial (relative) SS value */
public ushort e_sp; /* 10: Initial SP value */
public ushort e_csum; /* 12: Checksum */
public ushort e_ip; /* 14: Initial IP value */
public ushort e_cs; /* 16: Initial (relative) CS value */
public ushort e_lfarlc; /* 18: File address of relocation table */
public ushort e_ovno; /* 1a: Overlay number */
public ushort[] e_res; /* 1c: Reserved words [4] */
public ushort e_oemid; /* 24: OEM identifier (for e_oeminfo) */
public ushort e_oeminfo; /* 26: OEM information; e_oemid specific */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public ushort[] e_res2; /* 28: Reserved words [10] */
public uint e_lfanew; /* 3c: Offset to extended header */
public ushort Magic { get; private set; } // 00 Magic number
public ushort LastPageBytes { get; private set; } // 02 Bytes on last page of file
public ushort Pages { get; private set; } // 04 Pages in file
public ushort Relocations { get; private set; } // 06 Relocations
public ushort HeaderParagraphSize { get; private set; } // 08 Size of header in paragraphs
public ushort MinimumExtraParagraphs { get; private set; } // 0A Minimum extra paragraphs needed
public ushort MaximumExtraParagraphs { get; private set; } // 0C Maximum extra paragraphs needed
public ushort InitialSSValue { get; private set; } // 0E Initial (relative) SS value
public ushort InitialSPValue { get; private set; } // 10 Initial SP value
public ushort Checksum { get; private set; } // 12 Checksum
public ushort InitialIPValue { get; private set; } // 14 Initial IP value
public ushort InitialCSValue { get; private set; } // 16 Initial (relative) CS value
public ushort RelocationTableAddr { get; private set; } // 18 File address of relocation table
public ushort OverlayNumber { get; private set; } // 1A Overlay number
public ushort[] Reserved1 { get; private set; } // 1C Reserved words
public ushort OEMIdentifier { get; private set; } // 24 OEM identifier (for e_oeminfo)
public ushort OEMInformation { get; private set; } // 26 OEM information; e_oemid specific
public ushort[] Reserved2 { get; private set; } // 28 Reserved words
public int NewExeHeaderAddr { get; private set; } // 3C File address of new exe header
public static IMAGE_DOS_HEADER Deserialize(Stream stream)
{
IMAGE_DOS_HEADER idh = new IMAGE_DOS_HEADER();
idh.Magic = stream.ReadUInt16();
idh.LastPageBytes = stream.ReadUInt16();
idh.Pages = stream.ReadUInt16();
idh.Relocations = stream.ReadUInt16();
idh.HeaderParagraphSize = stream.ReadUInt16();
idh.MinimumExtraParagraphs = stream.ReadUInt16();
idh.MaximumExtraParagraphs = stream.ReadUInt16();
idh.InitialSSValue = stream.ReadUInt16();
idh.InitialSPValue = stream.ReadUInt16();
idh.Checksum = stream.ReadUInt16();
idh.InitialIPValue = stream.ReadUInt16();
idh.InitialCSValue = stream.ReadUInt16();
idh.RelocationTableAddr = stream.ReadUInt16();
idh.OverlayNumber = stream.ReadUInt16();
idh.Reserved1 = new ushort[Constants.ERES1WDS];
for (int i = 0; i < Constants.ERES1WDS; i++)
{
idh.Reserved1[i] = stream.ReadUInt16();
}
idh.OEMIdentifier = stream.ReadUInt16();
idh.OEMInformation = stream.ReadUInt16();
idh.Reserved2 = new ushort[Constants.ERES2WDS];
for (int i = 0; i < Constants.ERES2WDS; i++)
{
idh.Reserved2[i] = stream.ReadUInt16();
}
idh.NewExeHeaderAddr = stream.ReadInt32();
return idh;
}
}
}

View File

@@ -1,17 +1,42 @@
using System.Runtime.InteropServices;
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_FILE_HEADER
internal class IMAGE_FILE_HEADER
{
public ushort Machine;
public ushort NumberOfSections;
public uint TimeDateStamp;
public uint PointerToSymbolTable;
public uint NumberOfSymbols;
public ushort SizeOfOptionalHeader;
public FileCharacteristics Characteristics;
public ushort Machine { get; private set; }
public ushort NumberOfSections { get; private set; }
public uint TimeDateStamp { get; private set; }
public uint PointerToSymbolTable { get; private set; }
public uint NumberOfSymbols { get; private set; }
public ushort SizeOfOptionalHeader { get; private set; }
public ushort Characteristics { get; private set; }
public static IMAGE_FILE_HEADER Deserialize(Stream stream)
{
IMAGE_FILE_HEADER ifh = new IMAGE_FILE_HEADER();
ifh.Machine = stream.ReadUInt16();
ifh.NumberOfSections = stream.ReadUInt16();
ifh.TimeDateStamp = stream.ReadUInt32();
ifh.PointerToSymbolTable = stream.ReadUInt32();
ifh.NumberOfSymbols = stream.ReadUInt32();
ifh.SizeOfOptionalHeader = stream.ReadUInt16();
ifh.Characteristics = stream.ReadUInt16();
return ifh;
}
}
}
}

View File

@@ -1,13 +0,0 @@
using System.Runtime.InteropServices;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_NT_HEADERS32
{
public uint Signature; /* "PE"\0\0 */ /* 0x00 */
public IMAGE_FILE_HEADER FileHeader; /* 0x04 */
public IMAGE_OPTIONAL_HEADER32 OptionalHeader; /* 0x18 */
}
}

View File

@@ -1,13 +0,0 @@
using System.Runtime.InteropServices;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_NT_HEADERS64
{
public uint Signature;
public IMAGE_FILE_HEADER FileHeader;
public IMAGE_OPTIONAL_HEADER64 OptionalHeader;
}
}

View File

@@ -0,0 +1,100 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal class IMAGE_OPTIONAL_HEADER
{
// Standard fields
public ushort Magic { get; private set; }
public byte MajorLinkerVersion { get; private set; }
public byte MinorLinkerVersion { get; private set; }
public uint SizeOfCode { get; private set; }
public uint SizeOfInitializedData { get; private set; }
public uint SizeOfUninitializedData { get; private set; }
public uint AddressOfEntryPoint { get; private set; }
public uint BaseOfCode { get; private set; }
public uint BaseOfData { get; private set; }
// NT additional fields.
public uint ImageBase { get; private set; }
public uint SectionAlignment { get; private set; }
public uint FileAlignment { get; private set; }
public ushort MajorOperatingSystemVersion { get; private set; }
public ushort MinorOperatingSystemVersion { get; private set; }
public ushort MajorImageVersion { get; private set; }
public ushort MinorImageVersion { get; private set; }
public ushort MajorSubsystemVersion { get; private set; }
public ushort MinorSubsystemVersion { get; private set; }
public uint Reserved1 { get; private set; }
public uint SizeOfImage { get; private set; }
public uint SizeOfHeaders { get; private set; }
public uint CheckSum { get; private set; }
public ushort Subsystem { get; private set; }
public ushort DllCharacteristics { get; private set; }
public uint SizeOfStackReserve { get; private set; }
public uint SizeOfStackCommit { get; private set; }
public uint SizeOfHeapReserve { get; private set; }
public uint SizeOfHeapCommit { get; private set; }
public uint LoaderFlags { get; private set; }
public uint NumberOfRvaAndSizes { get; private set; }
public IMAGE_DATA_DIRECTORY[] DataDirectory { get; private set; }
public static IMAGE_OPTIONAL_HEADER Deserialize(Stream stream)
{
IMAGE_OPTIONAL_HEADER ioh = new IMAGE_OPTIONAL_HEADER();
ioh.Magic = stream.ReadUInt16();
ioh.MajorLinkerVersion = stream.ReadByteValue();
ioh.MinorLinkerVersion = stream.ReadByteValue();
ioh.SizeOfCode = stream.ReadUInt32();
ioh.SizeOfInitializedData = stream.ReadUInt32();
ioh.SizeOfUninitializedData = stream.ReadUInt32();
ioh.AddressOfEntryPoint = stream.ReadUInt32();
ioh.BaseOfCode = stream.ReadUInt32();
ioh.BaseOfData = stream.ReadUInt32();
ioh.ImageBase = stream.ReadUInt32();
ioh.SectionAlignment = stream.ReadUInt32();
ioh.FileAlignment = stream.ReadUInt32();
ioh.MajorOperatingSystemVersion = stream.ReadUInt16();
ioh.MinorOperatingSystemVersion = stream.ReadUInt16();
ioh.MajorImageVersion = stream.ReadUInt16();
ioh.MinorImageVersion = stream.ReadUInt16();
ioh.MajorSubsystemVersion = stream.ReadUInt16();
ioh.MinorSubsystemVersion = stream.ReadUInt16();
ioh.Reserved1 = stream.ReadUInt32();
ioh.SizeOfImage = stream.ReadUInt32();
ioh.SizeOfHeaders = stream.ReadUInt32();
ioh.CheckSum = stream.ReadUInt32();
ioh.Subsystem = stream.ReadUInt16();
ioh.DllCharacteristics = stream.ReadUInt16();
ioh.SizeOfStackReserve = stream.ReadUInt32();
ioh.SizeOfStackCommit = stream.ReadUInt32();
ioh.SizeOfHeapReserve = stream.ReadUInt32();
ioh.SizeOfHeapCommit = stream.ReadUInt32();
ioh.LoaderFlags = stream.ReadUInt32();
ioh.NumberOfRvaAndSizes = stream.ReadUInt32();
ioh.DataDirectory = new IMAGE_DATA_DIRECTORY[Constants.IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
for (int i = 0; i < Constants.IMAGE_NUMBEROF_DIRECTORY_ENTRIES; i++)
{
ioh.DataDirectory[i] = IMAGE_DATA_DIRECTORY.Deserialize(stream);
}
return ioh;
}
}
}

View File

@@ -1,48 +0,0 @@
using System.Runtime.InteropServices;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_OPTIONAL_HEADER32
{
/* Standard fields */
public ushort Magic; /* 0x10b or 0x107 */ /* 0x00 */
public byte MajorLinkerVersion;
public byte MinorLinkerVersion;
public uint SizeOfCode;
public uint SizeOfInitializedData;
public uint SizeOfUninitializedData;
public uint AddressOfEntryPoint; /* 0x10 */
public uint BaseOfCode;
public uint BaseOfData;
/* NT additional fields */
public uint ImageBase;
public uint SectionAlignment; /* 0x20 */
public uint FileAlignment;
public ushort MajorOperatingSystemVersion;
public ushort MinorOperatingSystemVersion;
public ushort MajorImageVersion;
public ushort MinorImageVersion;
public ushort MajorSubsystemVersion; /* 0x30 */
public ushort MinorSubsystemVersion;
public uint Win32VersionValue;
public uint SizeOfImage;
public uint SizeOfHeaders;
public uint CheckSum; /* 0x40 */
public ushort Subsystem;
public DllCharacteristics DllCharacteristics;
public uint SizeOfStackReserve;
public uint SizeOfStackCommit;
public uint SizeOfHeapReserve; /* 0x50 */
public uint SizeOfHeapCommit;
public uint LoaderFlags;
public uint NumberOfRvaAndSizes;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.IMAGE_NUMBEROF_DIRECTORY_ENTRIES)]
public IMAGE_DATA_DIRECTORY[] DataDirectory; /* 0x60, [IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */
/* 0xE0 */
}
}

View File

@@ -1,41 +0,0 @@
using System.Runtime.InteropServices;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_OPTIONAL_HEADER64
{
public ushort Magic; /* 0x20b */
public byte MajorLinkerVersion;
public byte MinorLinkerVersion;
public uint SizeOfCode;
public uint SizeOfInitializedData;
public uint SizeOfUninitializedData;
public uint AddressOfEntryPoint;
public uint BaseOfCode;
public ulong ImageBase;
public uint SectionAlignment;
public uint FileAlignment;
public ushort MajorOperatingSystemVersion;
public ushort MinorOperatingSystemVersion;
public ushort MajorImageVersion;
public ushort MinorImageVersion;
public ushort MajorSubsystemVersion;
public ushort MinorSubsystemVersion;
public uint Win32VersionValue;
public uint SizeOfImage;
public uint SizeOfHeaders;
public uint CheckSum;
public ushort Subsystem;
public DllCharacteristics DllCharacteristics;
public ulong SizeOfStackReserve;
public ulong SizeOfStackCommit;
public ulong SizeOfHeapReserve;
public ulong SizeOfHeapCommit;
public uint LoaderFlags;
public uint NumberOfRvaAndSizes;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.IMAGE_NUMBEROF_DIRECTORY_ENTRIES)]
public IMAGE_DATA_DIRECTORY[] DataDirectory; // [IMAGE_NUMBEROF_DIRECTORY_ENTRIES]
}
}

View File

@@ -1,40 +1,93 @@
using System.Runtime.InteropServices;
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_OS2_HEADER
/// <summary>
/// New .EXE header
/// </summary>
internal class IMAGE_OS2_HEADER
{
public ushort ne_magic; /* 00 NE signature 'NE' */
public byte ne_ver; /* 02 Linker version number */
public byte ne_rev; /* 03 Linker revision number */
public ushort ne_enttab; /* 04 Offset to entry table relative to NE */
public ushort ne_cbenttab; /* 06 Length of entry table in bytes */
public uint ne_crc; /* 08 Checksum */
public ushort ne_flags; /* 0c Flags about segments in this file */
public ushort ne_autodata; /* 0e Automatic data segment number */
public ushort ne_heap; /* 10 Initial size of local heap */
public ushort ne_stack; /* 12 Initial size of stack */
public uint ne_csip; /* 14 Initial CS:IP */
public uint ne_sssp; /* 18 Initial SS:SP */
public ushort ne_cseg; /* 1c # of entries in segment table */
public ushort ne_cmod; /* 1e # of entries in module reference tab. */
public ushort ne_cbnrestab; /* 20 Length of nonresident-name table */
public ushort ne_segtab; /* 22 Offset to segment table */
public ushort ne_rsrctab; /* 24 Offset to resource table */
public ushort ne_restab; /* 26 Offset to resident-name table */
public ushort ne_modtab; /* 28 Offset to module reference table */
public ushort ne_imptab; /* 2a Offset to imported name table */
public uint ne_nrestab; /* 2c Offset to nonresident-name table */
public ushort ne_cmovent; /* 30 # of movable entry points */
public ushort ne_align; /* 32 Logical sector alignment shift count */
public ushort ne_cres; /* 34 # of resource segments */
public byte ne_exetyp; /* 36 Flags indicating target OS */
public byte ne_flagsothers; /* 37 Additional information flags */
public ushort ne_pretthunks; /* 38 Offset to return thunks */
public ushort ne_psegrefbytes; /* 3a Offset to segment ref. bytes */
public ushort ne_swaparea; /* 3c Reserved by Microsoft */
public ushort ne_expver; /* 3e Expected Windows version number */
public ushort Magic { get; private set; } // 00 Magic number NE_MAGIC
public byte LinkerVersion { get; private set; } // 02 Linker Version number
public byte LinkerRevision { get; private set; } // 03 Linker Revision number
public ushort EntryTableOffset { get; private set; } // 04 Offset of Entry Table
public ushort EntryTableSize { get; private set; } // 06 Number of bytes in Entry Table
public uint CrcChecksum { get; private set; } // 08 Checksum of whole file
public ushort Flags { get; private set; } // 0C Flag word
public ushort Autodata { get; private set; } // 0E Automatic data segment number
public ushort InitialHeapAlloc { get; private set; } // 10 Initial heap allocation
public ushort InitialStackAlloc { get; private set; } // 12 Initial stack allocation
public uint InitialCSIPSetting { get; private set; } // 14 Initial CS:IP setting
public uint InitialSSSPSetting { get; private set; } // 18 Initial SS:SP setting
public ushort FileSegmentCount { get; private set; } // 1C Count of file segments
public ushort ModuleReferenceTableSize { get; private set; } // 1E Entries in Module Reference Table
public ushort NonResidentNameTableSize { get; private set; } // 20 Size of non-resident name table
public ushort SegmentTableOffset { get; private set; } // 22 Offset of Segment Table
public ushort ResourceTableOffset { get; private set; } // 24 Offset of Resource Table
public ushort ResidentNameTableOffset { get; private set; } // 26 Offset of resident name table
public ushort ModuleReferenceTableOffset { get; private set; } // 28 Offset of Module Reference Table
public ushort ImportedNamesTableOffset { get; private set; } // 2A Offset of Imported Names Table
public uint NonResidentNamesTableOffset { get; private set; } // 2C Offset of Non-resident Names Table
public ushort MovableEntriesCount { get; private set; } // 30 Count of movable entries
public ushort SegmentAlignmentShiftCount { get; private set; } // 32 Segment alignment shift count
public ushort ResourceEntriesCount { get; private set; } // 34 Count of resource entries
public byte TargetOperatingSystem { get; private set; } // 36 Target operating system
public byte AdditionalFlags { get; private set; } // 37 Additional flags
public ushort[] Reserved { get; private set; } // 38 3 reserved words
public byte WindowsSDKRevision { get; private set; } // 3E Windows SDK revison number
public byte WindowsSDKVersion { get; private set; } // 3F Windows SDK version number
public static IMAGE_OS2_HEADER Deserialize(Stream stream)
{
IMAGE_OS2_HEADER ioh = new IMAGE_OS2_HEADER();
ioh.Magic = stream.ReadUInt16();
ioh.LinkerVersion = stream.ReadByteValue();
ioh.LinkerRevision = stream.ReadByteValue();
ioh.EntryTableOffset = stream.ReadUInt16();
ioh.EntryTableSize = stream.ReadUInt16();
ioh.CrcChecksum = stream.ReadUInt32();
ioh.Flags = stream.ReadUInt16();
ioh.Autodata = stream.ReadUInt16();
ioh.InitialHeapAlloc = stream.ReadUInt16();
ioh.InitialStackAlloc = stream.ReadUInt16();
ioh.InitialCSIPSetting = stream.ReadUInt32();
ioh.InitialSSSPSetting = stream.ReadUInt32();
ioh.FileSegmentCount = stream.ReadUInt16();
ioh.ModuleReferenceTableSize = stream.ReadUInt16();
ioh.NonResidentNameTableSize = stream.ReadUInt16();
ioh.SegmentTableOffset = stream.ReadUInt16();
ioh.ResourceTableOffset = stream.ReadUInt16();
ioh.ResidentNameTableOffset = stream.ReadUInt16();
ioh.ModuleReferenceTableOffset = stream.ReadUInt16();
ioh.ImportedNamesTableOffset = stream.ReadUInt16();
ioh.NonResidentNamesTableOffset = stream.ReadUInt32();
ioh.MovableEntriesCount = stream.ReadUInt16();
ioh.SegmentAlignmentShiftCount = stream.ReadUInt16();
ioh.ResourceEntriesCount = stream.ReadUInt16();
ioh.TargetOperatingSystem = stream.ReadByteValue();
ioh.AdditionalFlags = stream.ReadByteValue();
ioh.Reserved = new ushort[Constants.NERESWORDS];
for (int i = 0; i < Constants.NERESWORDS; i++)
{
ioh.Reserved[i] = stream.ReadUInt16();
}
ioh.WindowsSDKRevision = stream.ReadByteValue();
ioh.WindowsSDKVersion = stream.ReadByteValue();
return ioh;
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal class IMAGE_RESOURCE_DATA_ENTRY
{
public uint OffsetToData { get; private set; }
public uint Size { get; private set; }
public uint CodePage { get; private set; }
public uint Reserved { get; private set; }
public static IMAGE_RESOURCE_DATA_ENTRY Deserialize(Stream stream)
{
IMAGE_RESOURCE_DATA_ENTRY irde = new IMAGE_RESOURCE_DATA_ENTRY();
irde.OffsetToData = stream.ReadUInt32();
irde.Size = stream.ReadUInt32();
irde.CodePage = stream.ReadUInt32();
irde.Reserved = stream.ReadUInt32();
return irde;
}
}
}

View File

@@ -0,0 +1,40 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal class IMAGE_RESOURCE_DIRECTORY
{
public uint Characteristics { get; private set; }
public uint TimeDateStamp { get; private set; }
public ushort MajorVersion { get; private set; }
public ushort MinorVersion { get; private set; }
public ushort NumberOfNamedEntries { get; private set; }
public ushort NumberOfIdEntries { get; private set; }
public static IMAGE_RESOURCE_DIRECTORY Deserialize(Stream stream)
{
IMAGE_RESOURCE_DIRECTORY ird = new IMAGE_RESOURCE_DIRECTORY();
ird.Characteristics = stream.ReadUInt32();
ird.TimeDateStamp = stream.ReadUInt32();
ird.MajorVersion = stream.ReadUInt16();
ird.MinorVersion = stream.ReadUInt16();
ird.NumberOfNamedEntries = stream.ReadUInt16();
ird.NumberOfIdEntries = stream.ReadUInt16();
return ird;
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal class IMAGE_RESOURCE_DIRECTORY_ENTRY
{
public uint Name { get; private set; }
public uint OffsetToData { get; private set; }
public static IMAGE_RESOURCE_DIRECTORY_ENTRY Deserialize(Stream stream)
{
IMAGE_RESOURCE_DIRECTORY_ENTRY irde = new IMAGE_RESOURCE_DIRECTORY_ENTRY();
irde.Name = stream.ReadUInt32();
irde.OffsetToData = stream.ReadUInt32();
return irde;
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal class IMAGE_RESOURCE_DIR_STRING_U
{
public ushort Length { get; private set; }
public char[] NameString { get; private set; }
public static IMAGE_RESOURCE_DIR_STRING_U Deserialize(Stream stream)
{
IMAGE_RESOURCE_DIR_STRING_U irdsu = new IMAGE_RESOURCE_DIR_STRING_U();
irdsu.Length = stream.ReadUInt16();
irdsu.NameString = stream.ReadChars(irdsu.Length);
return irdsu;
}
}
}

View File

@@ -1,21 +1,56 @@
using System.Runtime.InteropServices;
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_SECTION_HEADER
internal class IMAGE_SECTION_HEADER
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.IMAGE_SIZEOF_SHORT_NAME)]
public byte[] Name; // [IMAGE_SIZEOF_SHORT_NAME];
public uint PhysicalAddressOrVirtualSize; // Misc
public uint VirtualAddress;
public uint SizeOfRawData;
public uint PointerToRawData;
public uint PointerToRelocations;
public uint PointerToLinenumbers;
public ushort NumberOfRelocations;
public ushort NumberOfLinenumbers;
public SectionCharacteristics Characteristics;
public byte[] Name { get; private set; }
// Misc
public uint PhysicalAddress { get; private set; }
public uint VirtualSize { get; private set; }
public uint VirtualAddress { get; private set; }
public uint SizeOfRawData { get; private set; }
public uint PointerToRawData { get; private set; }
public uint PointerToRelocations { get; private set; }
public uint PointerToLinenumbers { get; private set; }
public ushort NumberOfRelocations { get; private set; }
public ushort NumberOfLinenumbers { get; private set; }
public SectionCharacteristics Characteristics { get; private set; }
public static IMAGE_SECTION_HEADER Deserialize(Stream stream)
{
IMAGE_SECTION_HEADER ish = new IMAGE_SECTION_HEADER();
ish.Name = stream.ReadBytes(Constants.IMAGE_SIZEOF_SHORT_NAME);
// Misc
ish.PhysicalAddress = stream.ReadUInt32();
ish.VirtualSize = ish.PhysicalAddress;
ish.VirtualAddress = stream.ReadUInt32();
ish.SizeOfRawData = stream.ReadUInt32();
ish.PointerToRawData = stream.ReadUInt32();
ish.PointerToRelocations = stream.ReadUInt32();
ish.PointerToLinenumbers = stream.ReadUInt32();
ish.NumberOfRelocations = stream.ReadUInt16();
ish.NumberOfLinenumbers = stream.ReadUInt16();
ish.Characteristics = (SectionCharacteristics)stream.ReadUInt32();
return ish;
}
}
}
}

View File

@@ -1,62 +0,0 @@
using System.Runtime.InteropServices;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGE_VXD_HEADER
{
public ushort e32_magic;
public byte e32_border;
public byte e32_worder;
public uint e32_level;
public ushort e32_cpu;
public ushort e32_os;
public uint e32_ver;
public uint e32_mflags;
public uint e32_mpages;
public uint e32_startobj;
public uint e32_eip;
public uint e32_stackobj;
public uint e32_esp;
public uint e32_pagesize;
public uint e32_lastpagesize;
public uint e32_fixupsize;
public uint e32_fixupsum;
public uint e32_ldrsize;
public uint e32_ldrsum;
public uint e32_objtab;
public uint e32_objcnt;
public uint e32_objmap;
public uint e32_itermap;
public uint e32_rsrctab;
public uint e32_rsrccnt;
public uint e32_restab;
public uint e32_enttab;
public uint e32_dirtab;
public uint e32_dircnt;
public uint e32_fpagetab;
public uint e32_frectab;
public uint e32_impmod;
public uint e32_impmodcnt;
public uint e32_impproc;
public uint e32_pagesum;
public uint e32_datapage;
public uint e32_preload;
public uint e32_nrestab;
public uint e32_cbnrestab;
public uint e32_nressum;
public uint e32_autodata;
public uint e32_debuginfo;
public uint e32_debuglen;
public uint e32_instpreload;
public uint e32_instdemand;
public uint e32_heapsize;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public byte[] e32_res3; // [12]
public uint e32_winresoff;
public uint e32_winreslen;
public ushort e32_devid;
public ushort e32_ddkver;
}
}

View File

@@ -0,0 +1,40 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal class NAMEINFO
{
public ushort Offset { get; private set; }
public ushort Length { get; private set; }
public ushort Flags { get; private set; }
public ushort ID { get; private set; }
public ushort Handle { get; private set; }
public ushort Usage { get; private set; }
public static NAMEINFO Deserialize(Stream stream)
{
NAMEINFO ni = new NAMEINFO();
ni.Offset = stream.ReadUInt16();
ni.Length = stream.ReadUInt16();
ni.Flags = stream.ReadUInt16();
ni.ID = stream.ReadUInt16();
ni.Handle = stream.ReadUInt16();
ni.Usage = stream.ReadUInt16();
return ni;
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System;
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Relocation item
/// </summary>
internal class NewRlc
{
public char SourceType { get; private set; } // Source type
public char Flags { get; private set; } // Flag byte
public ushort SourceOffset { get; private set; } // Source offset
// nr_intref - Internal Reference
public char TargetSegmentNumber { get; private set; } // Target segment number
public char Reserved1 { get; private set; } // Reserved
public ushort TargetEntryTableOffset { get; private set; } // Target Entry Table offset
// nr_import - Import
public ushort ModuleReferenceTableIndex { get; private set; } // Index into Module Reference Table
public ushort ProcedureOffset { get; private set; } // Procedure ordinal or name offset
// nr_osfix - Operating system fixup
public ushort OperatingSystemFixupType { get; private set; } // OSFIXUP type
public ushort Reserved2 { get; private set; } // Reserved
public static NewRlc Deserialize(Stream stream)
{
NewRlc nr = new NewRlc();
nr.SourceType = stream.ReadChar();
nr.Flags = stream.ReadChar();
nr.SourceOffset = stream.ReadUInt16();
// nr_intref
nr.TargetSegmentNumber = stream.ReadChar();
nr.Reserved1 = stream.ReadChar();
nr.TargetEntryTableOffset = stream.ReadUInt16();
// nr_import
nr.ModuleReferenceTableIndex = BitConverter.ToUInt16(new byte[] { (byte)nr.SourceType, (byte)nr.Flags }, 0);
nr.ProcedureOffset = nr.TargetEntryTableOffset;
// nr_osfix
nr.OperatingSystemFixupType = nr.ModuleReferenceTableIndex;
nr.Reserved2 = nr.ProcedureOffset;
return nr;
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Relocation info
/// </summary>
internal class NewRlcInfo
{
/// <summary>
/// Number of relocation items that follow
/// </summary>
public ushort RelocationItemCount { get; private set; }
public static NewRlcInfo Deserialize(Stream stream)
{
NewRlcInfo nri = new NewRlcInfo();
nri.RelocationItemCount = stream.ReadUInt16();
return nri;
}
}
}

View File

@@ -0,0 +1,38 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Resource table
/// </summary>
internal class NewRsrc
{
/// <summary>
/// Alignment shift count for resources
/// </summary>
public ushort AlignmentShiftCount { get; private set; }
public RsrcTypeInfo TypeInfo { get; private set; }
public static NewRsrc Deserialize(Stream stream)
{
NewRsrc nr = new NewRsrc();
nr.AlignmentShiftCount = stream.ReadUInt16();
nr.TypeInfo = RsrcTypeInfo.Deserialize(stream);
return nr;
}
}
}

View File

@@ -0,0 +1,54 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// New .EXE segment table entry
/// </summary>
internal class NewSeg
{
/// <summary>
/// File sector of start of segment
/// </summary>
public ushort StartFileSector { get; private set; }
/// <summary>
/// Number of bytes in file
/// </summary>
public ushort BytesInFile { get; private set; }
/// <summary>
/// Attribute flags
/// </summary>
public ushort Flags { get; private set; }
/// <summary>
/// Minimum allocation in bytes
/// </summary>
public ushort MinimumAllocation { get; private set; }
public static NewSeg Deserialize(Stream stream)
{
NewSeg ns = new NewSeg();
ns.StartFileSector = stream.ReadUInt16();
ns.BytesInFile = stream.ReadUInt16();
ns.Flags = stream.ReadUInt16();
ns.MinimumAllocation = stream.ReadUInt16();
return ns;
}
}
}

View File

@@ -0,0 +1,63 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System;
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Segment data
/// </summary>
internal class NewSegdata
{
#region ns_iter
/// <summary>
/// Number of iterations
/// </summary>
public ushort Iterations { get; private set; }
/// <summary>
/// Number of bytes
/// </summary>
public ushort TotalBytes { get; private set; }
/// <summary>
/// Iterated data bytes
/// </summary>
public char IteratedDataBytes { get; private set; }
#endregion
#region ns_noiter
/// <summary>
/// Data bytes
/// </summary>
public char DataBytes { get; private set; }
#endregion
public static NewSegdata Deserialize(Stream stream)
{
NewSegdata nsd = new NewSegdata();
nsd.Iterations = stream.ReadUInt16();
nsd.TotalBytes = stream.ReadUInt16();
nsd.IteratedDataBytes = stream.ReadChar();
nsd.DataBytes = (char)BitConverter.GetBytes(nsd.Iterations)[0];
return nsd;
}
}
}

View File

@@ -0,0 +1,38 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal class ResourceTable
{
public ushort rscAlignShift { get; private set; }
public TYPEINFO TypeInfo { get; private set; }
public ushort rscEndTypes { get; private set; }
public sbyte[][] rscResourceNames { get; private set; }
public byte rscEndNames { get; private set; }
public static ResourceTable Deserialize(Stream stream)
{
ResourceTable rt = new ResourceTable();
rt.rscAlignShift = stream.ReadUInt16();
rt.TypeInfo = TYPEINFO.Deserialize(stream);
rt.rscEndTypes = stream.ReadUInt16();
rt.rscResourceNames = null; // TODO: Figure out size
rt.rscEndNames = stream.ReadByteValue();
return rt;
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Resource name information block
/// </summary>
internal class RsrcNameInfo
{
/*
* The following two fields must be shifted left by the value of
* the rs_align field to compute their actual value. This allows
* resources to be larger than 64k, but they do not need to be
* aligned on 512 byte boundaries, the way segments are.
*/
/// <summary>
/// File offset to resource data
/// </summary>
public ushort Offset { get; private set; }
/// <summary>
/// Length of resource data
/// </summary>
public ushort Length { get; private set; }
/// <summary>
/// Resource flags
/// </summary>
public ushort Flags { get; private set; }
/// <summary>
/// Resource name id
/// </summary>
public ushort NameID { get; private set; }
/// <summary>
/// If loaded, then global handle
/// </summary>
public ushort Handle { get; private set; }
/// <summary>
/// Initially zero. Number of times the handle for this resource has been given out
/// </summary>
public ushort UsageCount { get; private set; }
public static RsrcNameInfo Deserialize(Stream stream)
{
RsrcNameInfo rni = new RsrcNameInfo();
rni.Offset = stream.ReadUInt16();
rni.Length = stream.ReadUInt16();
rni.Flags = stream.ReadUInt16();
rni.NameID = stream.ReadUInt16();
rni.Handle = stream.ReadUInt16();
rni.UsageCount = stream.ReadUInt16();
return rni;
}
}
}

View File

@@ -0,0 +1,42 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Resource type or name string
/// </summary>
internal class RsrcString
{
/// <summary>
/// Number of bytes in string
/// </summary>
public byte Length { get; private set; }
/// <summary>
/// Next of string
/// </summary>
public char[] Text { get; private set; }
public static RsrcString Deserialize(Stream stream)
{
RsrcString rs = new RsrcString();
rs.Length = stream.ReadByteValue();
rs.Text = stream.ReadChars(rs.Length);
return rs;
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
/// <summary>
/// Resource type information block
/// </summary>
internal class RsrcTypeInfo
{
public ushort ID { get; private set; }
public ushort rt_nres { get; private set; }
public uint rt_proc { get; private set; }
public static RsrcTypeInfo Deserialize(Stream stream)
{
RsrcTypeInfo rti = new RsrcTypeInfo();
rti.ID = stream.ReadUInt16();
rti.rt_nres = stream.ReadUInt16();
rti.rt_proc = stream.ReadUInt32();
return rti;
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* NEWEXE.H (C) Copyright Microsoft Corp 1984-1987
*
* Data structure definitions for the OS/2 & Windows
* executable file format.
*
* Modified by IVS on 24-Jan-1991 for Resource DeCompiler
* (C) Copyright IVS 1991
*
* http://csn.ul.ie/~caolan/pub/winresdump/winresdump/newexe.h
*/
using System.IO;
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal class TYPEINFO
{
public ushort TypeID { get; private set; }
public ushort ResourceCount { get; private set; }
public uint Reserved { get; private set; }
public NAMEINFO NameInfo { get; private set; }
public static TYPEINFO Deserialize(Stream stream)
{
TYPEINFO ti = new TYPEINFO();
ti.TypeID = stream.ReadUInt16();
ti.ResourceCount = stream.ReadUInt16();
ti.Reserved = stream.ReadUInt32();
ti.NameInfo = NAMEINFO.Deserialize(stream);
return ti;
}
}
}

View File

@@ -1,203 +0,0 @@
using System;
// Converted from https://github.com/wine-mirror/wine/blob/master/include/winnt.h
namespace BurnOutSharp.ExecutableType.Microsoft
{
internal enum DirectoryEntries
{
IMAGE_DIRECTORY_ENTRY_EXPORT = 0,
IMAGE_DIRECTORY_ENTRY_IMPORT = 1,
IMAGE_DIRECTORY_ENTRY_RESOURCE = 2,
IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3,
IMAGE_DIRECTORY_ENTRY_SECURIT = 4,
IMAGE_DIRECTORY_ENTRY_BASERELOC = 5,
IMAGE_DIRECTORY_ENTRY_DEBUG = 6,
IMAGE_DIRECTORY_ENTRY_COPYRIGHT = 7,
IMAGE_DIRECTORY_ENTRY_GLOBALPTR = 8, // (MIPS GP)
IMAGE_DIRECTORY_ENTRY_TLS = 9,
IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG = 10,
IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT = 11,
IMAGE_DIRECTORY_ENTRY_IAT = 12, // Import Address Table
IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT = 13,
IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14,
}
[Flags]
internal enum DllCharacteristics : ushort
{
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE = 0x0040,
IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY = 0x0080,
IMAGE_DLLCHARACTERISTICS_NX_COMPAT = 0x0100,
IMAGE_DLLCHARACTERISTICS_NO_ISOLATION = 0x0200,
IMAGE_DLLCHARACTERISTICS_NO_SEH = 0x0400,
IMAGE_DLLCHARACTERISTICS_NO_BIND = 0x0800,
IMAGE_DLLCHARACTERISTICS_WDM_DRIVER = 0x2000,
IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000,
}
[Flags]
internal enum FileCharacteristics : ushort
{
IMAGE_FILE_RELOCS_STRIPPED = 0x0001, /* No relocation info */
IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002,
IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004,
IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008,
IMAGE_FILE_AGGRESIVE_WS_TRIM = 0x0010,
IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020,
IMAGE_FILE_16BIT_MACHINE = 0x0040,
IMAGE_FILE_BYTES_REVERSED_LO = 0x0080,
IMAGE_FILE_32BIT_MACHINE = 0x0100,
IMAGE_FILE_DEBUG_STRIPPED = 0x0200,
IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400,
IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800,
IMAGE_FILE_SYSTEM = 0x1000,
IMAGE_FILE_DLL = 0x2000,
IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000,
IMAGE_FILE_BYTES_REVERSED_HI = 0x8000,
}
internal enum MachineSettings : ushort
{
IMAGE_FILE_MACHINE_UNKNOWN = 0,
IMAGE_FILE_MACHINE_TARGET_HOST = 0x0001,
IMAGE_FILE_MACHINE_I860 = 0x014d,
IMAGE_FILE_MACHINE_I386 = 0x014c,
IMAGE_FILE_MACHINE_R3000 = 0x0162,
IMAGE_FILE_MACHINE_R4000 = 0x0166,
IMAGE_FILE_MACHINE_R10000 = 0x0168,
IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x0169,
IMAGE_FILE_MACHINE_ALPHA = 0x0184,
IMAGE_FILE_MACHINE_SH3 = 0x01a2,
IMAGE_FILE_MACHINE_SH3DSP = 0x01a3,
IMAGE_FILE_MACHINE_SH3E = 0x01a4,
IMAGE_FILE_MACHINE_SH4 = 0x01a6,
IMAGE_FILE_MACHINE_SH5 = 0x01a8,
IMAGE_FILE_MACHINE_ARM = 0x01c0,
IMAGE_FILE_MACHINE_THUMB = 0x01c2,
IMAGE_FILE_MACHINE_ARMNT = 0x01c4,
IMAGE_FILE_MACHINE_ARM64 = 0xaa64,
IMAGE_FILE_MACHINE_AM33 = 0x01d3,
IMAGE_FILE_MACHINE_POWERPC = 0x01f0,
IMAGE_FILE_MACHINE_POWERPCFP = 0x01f1,
IMAGE_FILE_MACHINE_IA64 = 0x0200,
IMAGE_FILE_MACHINE_MIPS16 = 0x0266,
IMAGE_FILE_MACHINE_ALPHA64 = 0x0284,
IMAGE_FILE_MACHINE_MIPSFPU = 0x0366,
IMAGE_FILE_MACHINE_MIPSFPU16 = 0x0466,
IMAGE_FILE_MACHINE_AXP64 = 0x0284,
IMAGE_FILE_MACHINE_TRICORE = 0x0520,
IMAGE_FILE_MACHINE_CEF = 0x0cef,
IMAGE_FILE_MACHINE_EBC = 0x0ebc,
IMAGE_FILE_MACHINE_AMD64 = 0x8664,
IMAGE_FILE_MACHINE_M32R = 0x9041,
IMAGE_FILE_MACHINE_CEE = 0xc0ee,
}
[Flags]
internal enum SectionCharacteristics : uint
{
IMAGE_SCN_TYPE_REG = 0x00000000, // Reserved
IMAGE_SCN_TYPE_DSECT = 0x00000001, // Reserved
IMAGE_SCN_TYPE_NOLOAD = 0x00000002, // Reserved
IMAGE_SCN_TYPE_GROUP = 0x00000004, // Reserved
IMAGE_SCN_TYPE_NO_PAD = 0x00000008, // Reserved
IMAGE_SCN_TYPE_COPY = 0x00000010, // Reserved
IMAGE_SCN_CNT_CODE = 0x00000020,
IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040,
IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080,
IMAGE_SCN_LNK_OTHER = 0x00000100,
IMAGE_SCN_LNK_INFO = 0x00000200,
IMAGE_SCN_TYPE_OVER = 0x00000400, // Reserved
IMAGE_SCN_LNK_REMOVE = 0x00000800,
IMAGE_SCN_LNK_COMDAT = 0x00001000,
/* 0x00002000 - Reserved */
IMAGE_SCN_MEM_PROTECTED = 0x00004000, // Obsolete
IMAGE_SCN_MEM_FARDATA = 0x00008000,
IMAGE_SCN_MEM_SYSHEAP = 0x00010000, // Obsolete
IMAGE_SCN_MEM_PURGEABLE = 0x00020000,
IMAGE_SCN_MEM_16BIT = 0x00020000,
IMAGE_SCN_MEM_LOCKED = 0x00040000,
IMAGE_SCN_MEM_PRELOAD = 0x00080000,
IMAGE_SCN_ALIGN_1BYTES = 0x00100000,
IMAGE_SCN_ALIGN_2BYTES = 0x00200000,
IMAGE_SCN_ALIGN_4BYTES = 0x00300000,
IMAGE_SCN_ALIGN_8BYTES = 0x00400000,
IMAGE_SCN_ALIGN_16BYTES = 0x00500000, // Default
IMAGE_SCN_ALIGN_32BYTES = 0x00600000,
IMAGE_SCN_ALIGN_64BYTES = 0x00700000,
IMAGE_SCN_ALIGN_128BYTES = 0x00800000,
IMAGE_SCN_ALIGN_256BYTES = 0x00900000,
IMAGE_SCN_ALIGN_512BYTES = 0x00A00000,
IMAGE_SCN_ALIGN_1024BYTES = 0x00B00000,
IMAGE_SCN_ALIGN_2048BYTES = 0x00C00000,
IMAGE_SCN_ALIGN_4096BYTES = 0x00D00000,
IMAGE_SCN_ALIGN_8192BYTES = 0x00E00000,
/* 0x00F00000 - Unused */
IMAGE_SCN_ALIGN_MASK = 0x00F00000,
IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000,
IMAGE_SCN_MEM_DISCARDABLE = 0x02000000,
IMAGE_SCN_MEM_NOT_CACHED = 0x04000000,
IMAGE_SCN_MEM_NOT_PAGED = 0x08000000,
IMAGE_SCN_MEM_SHARED = 0x10000000,
IMAGE_SCN_MEM_EXECUTE = 0x20000000,
IMAGE_SCN_MEM_READ = 0x40000000,
IMAGE_SCN_MEM_WRITE = 0x80000000,
}
internal enum Subsystem : ushort
{
IMAGE_SUBSYSTEM_UNKNOWN = 0,
IMAGE_SUBSYSTEM_NATIVE = 1,
IMAGE_SUBSYSTEM_WINDOWS_GUI = 2, // Windows GUI subsystem
IMAGE_SUBSYSTEM_WINDOWS_CUI = 3, // Windows character subsystem
IMAGE_SUBSYSTEM_OS2_CUI = 5,
IMAGE_SUBSYSTEM_POSIX_CUI = 7,
IMAGE_SUBSYSTEM_NATIVE_WINDOWS = 8, // native Win9x driver
IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9, // Windows CE subsystem
IMAGE_SUBSYSTEM_EFI_APPLICATION = 10,
IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11,
IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = 12,
IMAGE_SUBSYSTEM_EFI_ROM = 13,
IMAGE_SUBSYSTEM_XBOX = 14,
IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION = 16,
}
internal static class Constants
{
public const ushort IMAGE_DOS_SIGNATURE = 0x5A4D; /* MZ */
public const ushort IMAGE_OS2_SIGNATURE = 0x454E; /* NE */
public const ushort IMAGE_OS2_SIGNATURE_LE = 0x454C; /* LE */
public const ushort IMAGE_OS2_SIGNATURE_LX = 0x584C; /* LX */
public const ushort IMAGE_VXD_SIGNATURE = 0x454C; /* LE */
public const uint IMAGE_NT_SIGNATURE = 0x00004550; /* PE00 */
public const int IMAGE_SIZEOF_FILE_HEADER = 20;
public const int IMAGE_SIZEOF_ROM_OPTIONAL_HEADER = 56;
public const int IMAGE_SIZEOF_STD_OPTIONAL_HEADER = 28;
public const int IMAGE_SIZEOF_NT_OPTIONAL32_HEADER = 224;
public const int IMAGE_SIZEOF_NT_OPTIONAL64_HEADER = 240;
public const int IMAGE_SIZEOF_SHORT_NAME = 8;
public const int IMAGE_SIZEOF_SECTION_HEADER = 40;
public const int IMAGE_SIZEOF_SYMBOL = 18;
public const int IMAGE_SIZEOF_AUX_SYMBOL = 18;
public const int IMAGE_SIZEOF_RELOCATION = 10;
public const int IMAGE_SIZEOF_BASE_RELOCATION = 8;
public const int IMAGE_SIZEOF_LINENUMBER = 6;
public const int IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR = 60;
// Possible Magic values
public const ushort IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b;
public const ushort IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b;
public const ushort IMAGE_ROM_OPTIONAL_HDR_MAGIC = 0x107;
public const int IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16;
}
}