From 9b98215fc9cbc30c12aa0d8676f94f5f8b0d0cb8 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 15 Mar 2022 11:18:53 -0700 Subject: [PATCH] Make SourceArray private in NE --- .../ExecutableType/Microsoft/NE/NewExecutable.cs | 10 +++++----- BurnOutSharp/PackerType/InnoSetup.cs | 1 + BurnOutSharp/PackerType/WiseInstaller.cs | 7 ++++++- BurnOutSharp/ProtectionType/CDDVDCops.cs | 7 ++++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/BurnOutSharp/ExecutableType/Microsoft/NE/NewExecutable.cs b/BurnOutSharp/ExecutableType/Microsoft/NE/NewExecutable.cs index 03d27828..cf77e17c 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/NE/NewExecutable.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/NE/NewExecutable.cs @@ -20,7 +20,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.NE /// /// Source array that the executable was parsed from /// - public byte[] SourceArray { get; } = null; + private readonly byte[] _sourceArray = null; /// /// Source stream that the executable was parsed from @@ -83,7 +83,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.NE return; this.Initialized = Deserialize(fileContent, offset); - this.SourceArray = fileContent; + this._sourceArray = fileContent; } /// @@ -169,7 +169,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.NE return ReadArbitraryRangeFromSourceStream(rangeStart, length); // If we have a source array, use that - if (this.SourceArray != null) + if (this._sourceArray != null) return ReadArbitraryRangeFromSourceArray(rangeStart, length); // Otherwise, return null @@ -206,11 +206,11 @@ namespace BurnOutSharp.ExecutableType.Microsoft.NE private byte[] ReadArbitraryRangeFromSourceArray(int rangeStart, int length) { int startingIndex = (int)Math.Max(rangeStart, 0); - int readLength = (int)Math.Min(length == -1 ? length = Int32.MaxValue : length, 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/PackerType/InnoSetup.cs b/BurnOutSharp/PackerType/InnoSetup.cs index 8ee4f404..543d9db9 100644 --- a/BurnOutSharp/PackerType/InnoSetup.cs +++ b/BurnOutSharp/PackerType/InnoSetup.cs @@ -113,6 +113,7 @@ namespace BurnOutSharp.PackerType private static string GetOldVersion(string file, NewExecutable nex) { + // TODO: Don't read entire file // TODO: Only 64 bytes at the end of the file is needed var data = nex.ReadArbitraryRange(); if (data != null) diff --git a/BurnOutSharp/PackerType/WiseInstaller.cs b/BurnOutSharp/PackerType/WiseInstaller.cs index bd27bd61..4bd0250d 100644 --- a/BurnOutSharp/PackerType/WiseInstaller.cs +++ b/BurnOutSharp/PackerType/WiseInstaller.cs @@ -23,6 +23,11 @@ namespace BurnOutSharp.PackerType if (stub == null) return null; + // TODO: Don't read entire file + var data = nex.ReadArbitraryRange(); + if (data == null) + return null; + // TODO: Keep this around until it can be confirmed with NE checks as well // TODO: This _may_ actually over-match. See msvbvm50.exe for an example var neMatchSets = new List @@ -31,7 +36,7 @@ namespace BurnOutSharp.PackerType new ContentMatchSet(new byte?[] { 0x57, 0x69, 0x73, 0x65, 0x4D, 0x61, 0x69, 0x6E }, "Wise Installation Wizard Module"), }; - return MatchUtil.GetFirstMatch(file, nex.SourceArray, neMatchSets, includeDebug); + return MatchUtil.GetFirstMatch(file, data, neMatchSets, includeDebug); } /// diff --git a/BurnOutSharp/ProtectionType/CDDVDCops.cs b/BurnOutSharp/ProtectionType/CDDVDCops.cs index a5f8369f..595b071b 100644 --- a/BurnOutSharp/ProtectionType/CDDVDCops.cs +++ b/BurnOutSharp/ProtectionType/CDDVDCops.cs @@ -48,6 +48,11 @@ namespace BurnOutSharp.ProtectionType if (stub == null) return null; + // TODO: Don't read entire file + var data = nex.ReadArbitraryRange(); + if (data == null) + return null; + // TODO: Do something with these strings in the NE header(?) // - CDCOPS // - CDcops assembly-language DLL @@ -63,7 +68,7 @@ namespace BurnOutSharp.ProtectionType }, GetVersion, "CD-Cops"), }; - return MatchUtil.GetFirstMatch(file, nex.SourceArray, neMatchSets, includeDebug); + return MatchUtil.GetFirstMatch(file, data, neMatchSets, includeDebug); } ///