Make SourceArray private in NE

This commit is contained in:
Matt Nadareski
2022-03-15 11:18:53 -07:00
parent 40e037fb2a
commit 9b98215fc9
4 changed files with 18 additions and 7 deletions

View File

@@ -20,7 +20,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.NE
/// <summary>
/// Source array that the executable was parsed from
/// </summary>
public byte[] SourceArray { get; } = null;
private readonly byte[] _sourceArray = null;
/// <summary>
/// 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;
}
/// <summary>
@@ -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
{

View File

@@ -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)

View File

@@ -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<ContentMatchSet>
@@ -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);
}
/// <inheritdoc/>

View File

@@ -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);
}
/// <inheritdoc/>