diff --git a/BurnOutSharp/ExecutableType/Microsoft/PE/PortableExecutable.cs b/BurnOutSharp/ExecutableType/Microsoft/PE/PortableExecutable.cs
index 23642ecb..deb7a628 100644
--- a/BurnOutSharp/ExecutableType/Microsoft/PE/PortableExecutable.cs
+++ b/BurnOutSharp/ExecutableType/Microsoft/PE/PortableExecutable.cs
@@ -23,13 +23,12 @@ namespace BurnOutSharp.ExecutableType.Microsoft.PE
///
/// Source array that the executable was parsed from
///
- /// TODO: Find every place this is used and try to remove usage
- public byte[] SourceArray { get; } = null;
+ private readonly byte[] _sourceArray = null;
///
/// Source stream that the executable was parsed from
///
- public Stream SourceStream { get; } = null;
+ private readonly Stream _sourceStream = null;
#region Headers
@@ -195,7 +194,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.PE
if (stream == null || !stream.CanRead || !stream.CanSeek)
return;
- this.SourceStream = stream;
+ this._sourceStream = stream;
this.Initialized = Deserialize(stream);
}
@@ -209,7 +208,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.PE
if (fileContent == null || fileContent.Length == 0 || offset < 0)
return;
- this.SourceArray = fileContent;
+ this._sourceArray = fileContent;
this.Initialized = Deserialize(fileContent, offset);
}
@@ -551,17 +550,17 @@ namespace BurnOutSharp.ExecutableType.Microsoft.PE
/// Read an arbitrary range from the source
///
/// The start of where to read data from, -1 means start of source
- /// The end of where to read data from (exclusive), -1 means end of source
+ /// How many bytes to read, -1 means read until end
///
- public byte[] ReadArbitraryRange(int rangeStart = -1, int rangeEnd = -1)
+ public byte[] ReadArbitraryRange(int rangeStart = -1, int length = -1)
{
// If we have a source stream, use that
- if (this.SourceStream != null)
- return ReadArbitraryRangeFromSourceStream(rangeStart, rangeEnd);
+ if (this._sourceStream != null)
+ return ReadArbitraryRangeFromSourceStream(rangeStart, length);
// If we have a source array, use that
- if (this.SourceArray != null)
- return ReadArbitraryRangeFromSourceArray(rangeStart, rangeEnd);
+ if (this._sourceArray != null)
+ return ReadArbitraryRangeFromSourceArray(rangeStart, length);
// Otherwise, return null
return null;
@@ -571,19 +570,19 @@ namespace BurnOutSharp.ExecutableType.Microsoft.PE
/// Read an arbitrary range from the stream source, if possible
///
/// The start of where to read data from, -1 means start of source
- /// The end of where to read data from (exclusive), -1 means end of source
+ /// How many bytes to read, -1 means read until end
///
- private byte[] ReadArbitraryRangeFromSourceStream(int rangeStart, int rangeEnd)
+ private byte[] ReadArbitraryRangeFromSourceStream(int rangeStart, int length)
{
- lock (this.SourceStream)
+ lock (this._sourceStream)
{
int startingIndex = (int)Math.Max(rangeStart, 0);
- int readLength = (int)Math.Min(rangeEnd, this.SourceStream.Length);
+ int readLength = (int)Math.Min(length == -1 ? length = Int32.MaxValue : length, this._sourceStream.Length);
- long originalPosition = this.SourceStream.Position;
- this.SourceStream.Seek(startingIndex, SeekOrigin.Begin);
- byte[] sectionData = this.SourceStream.ReadBytes(readLength);
- this.SourceStream.Seek(originalPosition, SeekOrigin.Begin);
+ long originalPosition = this._sourceStream.Position;
+ this._sourceStream.Seek(startingIndex, SeekOrigin.Begin);
+ byte[] sectionData = this._sourceStream.ReadBytes(readLength);
+ this._sourceStream.Seek(originalPosition, SeekOrigin.Begin);
return sectionData;
}
}
@@ -592,16 +591,16 @@ namespace BurnOutSharp.ExecutableType.Microsoft.PE
/// Read an arbitrary range from the array source, if possible
///
/// The start of where to read data from, -1 means start of source
- /// The end of where to read data from (exclusive), -1 means end of source
+ /// How many bytes to read, -1 means read until end
///
- private byte[] ReadArbitraryRangeFromSourceArray(int rangeStart, int rangeEnd)
+ private byte[] ReadArbitraryRangeFromSourceArray(int rangeStart, int length)
{
int startingIndex = (int)Math.Max(rangeStart, 0);
- int readLength = (int)Math.Min(rangeEnd, this.SourceArray.Length);
+ int readLength = (int)Math.Min(length == -1 ? length = Int32.MaxValue : length, this._sourceArray.Length);
try
{
- return this.SourceArray.ReadBytes(ref startingIndex, readLength);
+ return this._sourceArray.ReadBytes(ref startingIndex, readLength);
}
catch
{
diff --git a/BurnOutSharp/ProtectionType/SecuROM.cs b/BurnOutSharp/ProtectionType/SecuROM.cs
index caab02a5..8c3b0d81 100644
--- a/BurnOutSharp/ProtectionType/SecuROM.cs
+++ b/BurnOutSharp/ProtectionType/SecuROM.cs
@@ -34,17 +34,20 @@ namespace BurnOutSharp.ProtectionType
{
int sectionAddr = (int)lastSection.PointerToRawData;
int sectionEnd = sectionAddr + (int)lastSection.VirtualSize;
- var matchers = new List
- {
- // AddD + (char)0x03 + (char)0x00 + (char)0x00 + (char)0x00)
- new ContentMatchSet(
- new ContentMatch(new byte?[] { 0x41, 0x64, 0x64, 0x44, 0x03, 0x00, 0x00, 0x00 }, start: sectionEnd),
- GetV4Version, "SecuROM"),
- };
- string match = MatchUtil.GetFirstMatch(file, pex.SourceArray, matchers, includeDebug);
- if (!string.IsNullOrWhiteSpace(match))
- return match;
+ var postLastSectionData = pex.ReadArbitraryRange(rangeStart: sectionEnd);
+ if (postLastSectionData != null)
+ {
+ var matchers = new List
+ {
+ // AddD + (char)0x03 + (char)0x00 + (char)0x00 + (char)0x00)
+ new ContentMatchSet(new byte?[] { 0x41, 0x64, 0x64, 0x44, 0x03, 0x00, 0x00, 0x00 }, GetV4Version, "SecuROM"),
+ };
+
+ string match = MatchUtil.GetFirstMatch(file, postLastSectionData, matchers, includeDebug);
+ if (!string.IsNullOrWhiteSpace(match))
+ return match;
+ }
}
// Get the sections 5+, if they exist (example names: .fmqyrx, .vcltz, .iywiak)