using System.IO; using System.Text; namespace BinaryObjectScanner.Wrappers { public class MSDOS : WrapperBase { #region Descriptive Properties /// public override string DescriptionString => "MS-DOS Executable"; #endregion #region Constructors /// #if NET48 public MSDOS(SabreTools.Models.MSDOS.Executable model, byte[] data, int offset) #else public MSDOS(SabreTools.Models.MSDOS.Executable? model, byte[]? data, int offset) #endif : base(model, data, offset) { // All logic is handled by the base class } /// #if NET48 public MSDOS(SabreTools.Models.MSDOS.Executable model, Stream data) #else public MSDOS(SabreTools.Models.MSDOS.Executable? model, Stream? data) #endif : base(model, data) { // All logic is handled by the base class }/// /// 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 #if NET48 public static MSDOS Create(byte[] data, int offset) #else public static MSDOS? Create(byte[]? data, int offset) #endif { // If the data is invalid if (data == null) return null; // If the offset is out of bounds if (offset < 0 || offset >= data.Length) return null; // Create a memory stream and use that MemoryStream dataStream = new MemoryStream(data, offset, data.Length - offset); return Create(dataStream); } /// /// Create an MS-DOS executable from a Stream /// /// Stream representing the executable /// An MS-DOS executable wrapper on success, null on failure #if NET48 public static MSDOS Create(Stream data) #else public static MSDOS? Create(Stream? data) #endif { // If the data is invalid if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead) return null; var executable = new SabreTools.Serialization.Streams.MSDOS().Deserialize(data); if (executable == null) return null; try { return new MSDOS(executable, data); } catch { return null; } } #endregion #region Printing /// public override StringBuilder PrettyPrint() { StringBuilder builder = new StringBuilder(); Printing.MSDOS.Print(builder, this.Model); return builder; } #endregion } }