From 9c9eb8ca7bf98755bfd20b51e0bc628df914b0cf Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 30 Dec 2022 14:00:10 -0800 Subject: [PATCH] Align to correct boundary, look for executables --- BurnOutSharp.Builders/PortableExecutable.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/BurnOutSharp.Builders/PortableExecutable.cs b/BurnOutSharp.Builders/PortableExecutable.cs index fdc830a6..7b54f94a 100644 --- a/BurnOutSharp.Builders/PortableExecutable.cs +++ b/BurnOutSharp.Builders/PortableExecutable.cs @@ -1299,9 +1299,19 @@ namespace BurnOutSharp.Builders // Get the section size int size = (int)sections.First(s => s.PointerToRawData == initialOffset).SizeOfRawData; - // Align to the 1024-byte boundary - while (data.Position - initialOffset < size && data.Position % 1024 != 0) - _ = data.ReadByteValue(); + // Align to the 512-byte boundary or we find the start of an MS-DOS header + while (data.Position - initialOffset < size && data.Position % 0x200 != 0) + { + // If we find the start of an MS-DOS header + if (data.ReadUInt16() == Models.MSDOS.Constants.SignatureUInt16) + { + data.Seek(-2, origin: SeekOrigin.Current); + break; + } + + // Otherwise + data.Seek(-1, origin: SeekOrigin.Current); + } // If we have not used up the full size, parse the remaining chunk as a single resource if (data.Position - initialOffset < size)