diff --git a/BurnOutSharp.Builders/MSDOS.cs b/BurnOutSharp.Builders/MSDOS.cs index dd0362f7..16399606 100644 --- a/BurnOutSharp.Builders/MSDOS.cs +++ b/BurnOutSharp.Builders/MSDOS.cs @@ -1,6 +1,8 @@ using System.IO; +using System.Text; using BurnOutSharp.Models.MSDOS; using BurnOutSharp.Utilities; +using static BurnOutSharp.Models.MSDOS.Constants; namespace BurnOutSharp.Builders { @@ -100,12 +102,9 @@ namespace BurnOutSharp.Builders #region Standard Fields - header.Magic = new byte[2]; - for (int i = 0; i < header.Magic.Length; i++) - { - header.Magic[i] = data.ReadByteValue(); - } - if (header.Magic[0] != 'M' || header.Magic[1] != 'Z') + byte[] magic = data.ReadBytes(2); + header.Magic = Encoding.ASCII.GetString(magic); + if (header.Magic != SignatureString) return null; header.LastPageBytes = data.ReadUInt16(); diff --git a/BurnOutSharp.Models/MSDOS/Constants.cs b/BurnOutSharp.Models/MSDOS/Constants.cs new file mode 100644 index 00000000..ebba5f9f --- /dev/null +++ b/BurnOutSharp.Models/MSDOS/Constants.cs @@ -0,0 +1,11 @@ +namespace BurnOutSharp.Models.MSDOS +{ + public static class Constants + { + public static readonly byte[] SignatureBytes = new byte[] { 0x4d, 0x5a }; + + public const string SignatureString = "MZ"; + + public const ushort SignatureUInt16 = 0x5a4d; + } +} \ No newline at end of file diff --git a/BurnOutSharp.Models/MSDOS/ExecutableHeader.cs b/BurnOutSharp.Models/MSDOS/ExecutableHeader.cs index 73758d73..f553e27f 100644 --- a/BurnOutSharp.Models/MSDOS/ExecutableHeader.cs +++ b/BurnOutSharp.Models/MSDOS/ExecutableHeader.cs @@ -17,7 +17,7 @@ namespace BurnOutSharp.Models.MSDOS /// 0x5A4D (ASCII for 'M' and 'Z') /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] - public byte[] Magic; + public string Magic; /// /// Number of bytes in the last page. diff --git a/BurnOutSharp.Wrappers/LinearExecutable.cs b/BurnOutSharp.Wrappers/LinearExecutable.cs index d53d4d86..ca6a866d 100644 --- a/BurnOutSharp.Wrappers/LinearExecutable.cs +++ b/BurnOutSharp.Wrappers/LinearExecutable.cs @@ -11,7 +11,7 @@ namespace BurnOutSharp.Wrappers #region Standard Fields /// - public byte[] Stub_Magic => _executable.Stub.Header.Magic; + public string Stub_Magic => _executable.Stub.Header.Magic; /// public ushort Stub_LastPageBytes => _executable.Stub.Header.LastPageBytes; diff --git a/BurnOutSharp.Wrappers/MSDOS.cs b/BurnOutSharp.Wrappers/MSDOS.cs index 8f42f45d..2e64ba17 100644 --- a/BurnOutSharp.Wrappers/MSDOS.cs +++ b/BurnOutSharp.Wrappers/MSDOS.cs @@ -10,7 +10,7 @@ namespace BurnOutSharp.Wrappers #region Header /// - public byte[] Magic => _executable.Header.Magic; + public string Magic => _executable.Header.Magic; /// public ushort LastPageBytes => _executable.Header.LastPageBytes; @@ -164,7 +164,7 @@ namespace BurnOutSharp.Wrappers { Console.WriteLine(" Header Information:"); Console.WriteLine(" -------------------------"); - Console.WriteLine($" Magic number: {BitConverter.ToString(Magic).Replace("-", string.Empty)}"); + Console.WriteLine($" Magic number: {Magic}"); Console.WriteLine($" Last page bytes: {LastPageBytes}"); Console.WriteLine($" Pages: {Pages}"); Console.WriteLine($" Relocation items: {RelocationItems}"); diff --git a/BurnOutSharp.Wrappers/NewExecutable.cs b/BurnOutSharp.Wrappers/NewExecutable.cs index a8ff5790..58d59a71 100644 --- a/BurnOutSharp.Wrappers/NewExecutable.cs +++ b/BurnOutSharp.Wrappers/NewExecutable.cs @@ -15,7 +15,7 @@ namespace BurnOutSharp.Wrappers #region Standard Fields /// - public byte[] Stub_Magic => _executable.Stub.Header.Magic; + public string Stub_Magic => _executable.Stub.Header.Magic; /// public ushort Stub_LastPageBytes => _executable.Stub.Header.LastPageBytes; @@ -305,7 +305,7 @@ namespace BurnOutSharp.Wrappers { Console.WriteLine(" MS-DOS Stub Header Information:"); Console.WriteLine(" -------------------------"); - Console.WriteLine($" Magic number: {BitConverter.ToString(Stub_Magic).Replace("-", string.Empty)}"); + Console.WriteLine($" Magic number: {Stub_Magic}"); Console.WriteLine($" Last page bytes: {Stub_LastPageBytes}"); Console.WriteLine($" Pages: {Stub_Pages}"); Console.WriteLine($" Relocation items: {Stub_RelocationItems}"); diff --git a/BurnOutSharp.Wrappers/PortableExecutable.cs b/BurnOutSharp.Wrappers/PortableExecutable.cs index 66abdd99..c826b6af 100644 --- a/BurnOutSharp.Wrappers/PortableExecutable.cs +++ b/BurnOutSharp.Wrappers/PortableExecutable.cs @@ -19,7 +19,7 @@ namespace BurnOutSharp.Wrappers #region Standard Fields /// - public byte[] Stub_Magic => _executable.Stub.Header.Magic; + public string Stub_Magic => _executable.Stub.Header.Magic; /// public ushort Stub_LastPageBytes => _executable.Stub.Header.LastPageBytes; @@ -1059,7 +1059,7 @@ namespace BurnOutSharp.Wrappers { Console.WriteLine(" MS-DOS Stub Header Information:"); Console.WriteLine(" -------------------------"); - Console.WriteLine($" Magic number: {BitConverter.ToString(Stub_Magic).Replace("-", string.Empty)}"); + Console.WriteLine($" Magic number: {Stub_Magic}"); Console.WriteLine($" Last page bytes: {Stub_LastPageBytes}"); Console.WriteLine($" Pages: {Stub_Pages}"); Console.WriteLine($" Relocation items: {Stub_RelocationItems}");