From aeaeff28d39ecf82e189950063b1e4ff34beb2f2 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 7 Dec 2022 23:56:08 -0800 Subject: [PATCH] Better alignment in PE resources --- BurnOutSharp.Builder/Extensions.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/BurnOutSharp.Builder/Extensions.cs b/BurnOutSharp.Builder/Extensions.cs index b7ec50ef..c6a918a6 100644 --- a/BurnOutSharp.Builder/Extensions.cs +++ b/BurnOutSharp.Builder/Extensions.cs @@ -609,9 +609,12 @@ namespace BurnOutSharp.Builder dialogTemplateExtended.Typeface = entry.Data.ReadString(ref offset, Encoding.Unicode); } - // Align to the DWORD boundary - while ((offset % 4) != 0) - _ = entry.Data.ReadByte(ref offset); + // Align to the DWORD boundary if we're not at the end + if (offset != entry.Data.Length) + { + while ((offset % 4) != 0) + _ = entry.Data.ReadByte(ref offset); + } #endregion @@ -832,9 +835,12 @@ namespace BurnOutSharp.Builder dialogTemplate.Typeface = entry.Data.ReadString(ref offset, Encoding.Unicode); } - // Align to the DWORD boundary - while ((offset % 4) != 0) - _ = entry.Data.ReadByte(ref offset); + // Align to the DWORD boundary if we're not at the end + if (offset != entry.Data.Length) + { + while ((offset % 4) != 0) + _ = entry.Data.ReadByte(ref offset); + } #endregion