using System; using System.IO; namespace BurnOutSharp.Wrappers { public class MSDOS : WrapperBase { #region Pass-Through Properties #region Header /// public byte[] Magic => _executable.Header.Magic; /// public ushort LastPageBytes => _executable.Header.LastPageBytes; /// public ushort Pages => _executable.Header.Pages; /// public ushort RelocationItems => _executable.Header.RelocationItems; /// public ushort HeaderParagraphSize => _executable.Header.HeaderParagraphSize; /// public ushort MinimumExtraParagraphs => _executable.Header.MinimumExtraParagraphs; /// public ushort MaximumExtraParagraphs => _executable.Header.MaximumExtraParagraphs; /// public ushort InitialSSValue => _executable.Header.InitialSSValue; /// public ushort InitialSPValue => _executable.Header.InitialSPValue; /// public ushort Checksum => _executable.Header.Checksum; /// public ushort InitialIPValue => _executable.Header.InitialIPValue; /// public ushort InitialCSValue => _executable.Header.InitialCSValue; /// public ushort RelocationTableAddr => _executable.Header.RelocationTableAddr; /// public ushort OverlayNumber => _executable.Header.OverlayNumber; #endregion #region PE Extensions /// public ushort[] Reserved1 => _executable.Header.Reserved1; /// public ushort OEMIdentifier => _executable.Header.OEMIdentifier; /// public ushort OEMInformation => _executable.Header.OEMInformation; /// public ushort[] Reserved2 => _executable.Header.Reserved2; /// public uint NewExeHeaderAddr => _executable.Header.NewExeHeaderAddr; #endregion #region Relocation Table /// public Models.MSDOS.RelocationEntry[] RelocationTable => _executable.RelocationTable; #endregion #endregion #region Instance Variables /// /// Internal representation of the executable /// private Models.MSDOS.Executable _executable; #endregion #region Constructors /// /// Private constructor /// private MSDOS() { } /// /// Create an MS-DOS executable from a byte array and offset /// /// Byte array representing the executable /// Offset within the array to parse /// An MS-DOS executable wrapper on success, null on failure public static MSDOS Create(byte[] data, int offset) { var executable = Builder.MSDOS.ParseExecutable(data, offset); if (executable == null) return null; var wrapper = new MSDOS { _executable = executable, _dataSource = DataSource.ByteArray, _byteArrayData = data, _byteArrayOffset = offset, }; return wrapper; } /// /// Create an MS-DOS executable from a Stream /// /// Stream representing the executable /// An MS-DOS executable wrapper on success, null on failure public static MSDOS Create(Stream data) { var executable = Builder.MSDOS.ParseExecutable(data); if (executable == null) return null; var wrapper = new MSDOS { _executable = executable, _dataSource = DataSource.Stream, _streamData = data, }; return wrapper; } #endregion #region Printing /// public override void Print() { Console.WriteLine("MS-DOS Executable Information:"); Console.WriteLine("-------------------------"); Console.WriteLine(); PrintHeader(); PrintRelocationTable(); } /// /// Print header information /// private void PrintHeader() { Console.WriteLine(" Header Information:"); Console.WriteLine(" -------------------------"); Console.WriteLine($" Magic number: {BitConverter.ToString(Magic).Replace("-", string.Empty)}"); Console.WriteLine($" Last page bytes: {LastPageBytes}"); Console.WriteLine($" Pages: {Pages}"); Console.WriteLine($" Relocation items: {RelocationItems}"); Console.WriteLine($" Header paragraph size: {HeaderParagraphSize}"); Console.WriteLine($" Minimum extra paragraphs: {MinimumExtraParagraphs}"); Console.WriteLine($" Maximum extra paragraphs: {MaximumExtraParagraphs}"); Console.WriteLine($" Initial SS value: {InitialSSValue}"); Console.WriteLine($" Initial SP value: {InitialSPValue}"); Console.WriteLine($" Checksum: {Checksum}"); Console.WriteLine($" Initial IP value: {InitialIPValue}"); Console.WriteLine($" Initial CS value: {InitialCSValue}"); Console.WriteLine($" Relocation table address: {RelocationTableAddr}"); Console.WriteLine($" Overlay number: {OverlayNumber}"); } /// /// Print relocation table information /// private void PrintRelocationTable() { Console.WriteLine(" Relocation Table Information:"); Console.WriteLine(" -------------------------"); if (RelocationItems == 0 || RelocationTable.Length == 0) { Console.WriteLine(" No relocation table items"); } else { for (int i = 0; i < RelocationTable.Length; i++) { var entry = RelocationTable[i]; Console.WriteLine($" Relocation Table Entry {i}"); Console.WriteLine($" Offset = {entry.Offset}"); Console.WriteLine($" Segment = {entry.Segment}"); } } Console.WriteLine(); } #endregion } }