From 1f40c2e05276ccb5d7c0fda79c98f77e9891a1e9 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 14 Dec 2022 21:30:53 -0800 Subject: [PATCH] Fix locking exception --- BurnOutSharp.Builder/Extensions.cs | 14 ++++--- BurnOutSharp.Wrappers/PortableExecutable.cs | 44 ++++++++++----------- BurnOutSharp/Tools/Extensions.cs | 17 +++++--- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/BurnOutSharp.Builder/Extensions.cs b/BurnOutSharp.Builder/Extensions.cs index 8359ef43..d156b4e6 100644 --- a/BurnOutSharp.Builder/Extensions.cs +++ b/BurnOutSharp.Builder/Extensions.cs @@ -137,13 +137,17 @@ namespace BurnOutSharp.Builder int charWidth = nullTerminator.Length; List keyChars = new List(); - while (offset < content.Length && BitConverter.ToUInt16(content, offset) != 0x0000) + while (offset < content.Length) { - keyChars.Add(encoding.GetChars(content, offset, charWidth)[0]); offset += charWidth; - } - offset += 2; + char c = encoding.GetChars(content, offset, charWidth)[0]; + keyChars.Add(c); + offset += charWidth; - return new string(keyChars.ToArray()); + if (c == '\0') + break; + } + + return new string(keyChars.ToArray()).TrimEnd('\0'); } #endregion diff --git a/BurnOutSharp.Wrappers/PortableExecutable.cs b/BurnOutSharp.Wrappers/PortableExecutable.cs index 9eaf93b3..b7263559 100644 --- a/BurnOutSharp.Wrappers/PortableExecutable.cs +++ b/BurnOutSharp.Wrappers/PortableExecutable.cs @@ -583,21 +583,18 @@ namespace BurnOutSharp.Wrappers { get { - lock (_sourceDataLock) - { - // Use the cached data if possible - if (_debugData != null && _debugData.Count != 0) - return _debugData; - - // If we have no resource table, just return - if (DebugTable?.DebugDirectoryTable == null - || DebugTable.DebugDirectoryTable.Length == 0) - return null; - - // Otherwise, build and return the cached dictionary - ParseDebugTable(); + // Use the cached data if possible + if (_debugData != null && _debugData.Count != 0) return _debugData; - } + + // If we have no resource table, just return + if (DebugTable?.DebugDirectoryTable == null + || DebugTable.DebugDirectoryTable.Length == 0) + return null; + + // Otherwise, build and return the cached dictionary + ParseDebugTable(); + return _debugData; } } @@ -2815,16 +2812,19 @@ namespace BurnOutSharp.Wrappers if (DebugData == null) return Enumerable.Empty(); - return DebugData.Select(r => r.Value) + var nb10Found = DebugData.Select(r => r.Value) .Select(r => r as Models.PortableExecutable.NB10ProgramDatabase) .Where(n => n != null) - .Where(n => n.PdbFileName.Contains("path")) - .Select(n => (object)n) - .Concat(DebugData.Select(r => r.Value) - .Select(r => r as Models.PortableExecutable.RSDSProgramDatabase) - .Where(r => r != null) - .Where(r => r.PathAndFileName.Contains("path")) - .Select(r => (object)r)); + .Where(n => n.PdbFileName.Contains(path)) + .Select(n => (object)n); + + var rsdsFound = DebugData.Select(r => r.Value) + .Select(r => r as Models.PortableExecutable.RSDSProgramDatabase) + .Where(r => r != null) + .Where(r => r.PathAndFileName.Contains(path)) + .Select(r => (object)r); + + return nb10Found.Concat(rsdsFound); } /// diff --git a/BurnOutSharp/Tools/Extensions.cs b/BurnOutSharp/Tools/Extensions.cs index c5261c56..3cf34b53 100644 --- a/BurnOutSharp/Tools/Extensions.cs +++ b/BurnOutSharp/Tools/Extensions.cs @@ -126,17 +126,24 @@ namespace BurnOutSharp.Tools /// public static string ReadString(this byte[] content, ref int offset, Encoding encoding) { + if (offset >= content.Length) + return null; + byte[] nullTerminator = encoding.GetBytes(new char[] { '\0' }); int charWidth = nullTerminator.Length; List keyChars = new List(); - while (BitConverter.ToUInt16(content, offset) != 0x0000) + while (offset < content.Length) { - keyChars.Add(encoding.GetChars(content, offset, charWidth)[0]); offset += charWidth; - } - offset += 2; + char c = encoding.GetChars(content, offset, charWidth)[0]; + keyChars.Add(c); + offset += charWidth; - return new string(keyChars.ToArray()); + if (c == '\0') + break; + } + + return new string(keyChars.ToArray()).TrimEnd('\0'); } ///