Make ReadArbitraryRange safer to handle

This commit is contained in:
Matt Nadareski
2025-09-03 10:41:53 -04:00
parent 6904674785
commit b1600ad7d2
4 changed files with 48 additions and 13 deletions

View File

@@ -59,19 +59,27 @@ namespace BinaryObjectScanner.Packer
// 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)
byte[]? data;
try
{
var matchers = new List<ContentMatchSet>
data = nex.ReadArbitraryRange();
if (data == null)
return "Unknown 1.X";
}
catch
{
// Ignore errors reading ranges
return "Unknown 1.X";
}
var matchers = new List<ContentMatchSet>
{
// "rDlPtS02" + (char)0x87 + "eVx"
new(new byte?[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x32, 0x87, 0x65, 0x56, 0x78 }, "1.2.16 or earlier"),
};
return MatchUtil.GetFirstMatch(file, data, matchers, false) ?? "Unknown 1.X";
}
return "Unknown 1.X";
return MatchUtil.GetFirstMatch(file, data, matchers, false) ?? "Unknown 1.X";
}
}
}

View File

@@ -73,9 +73,18 @@ namespace BinaryObjectScanner.Protection
public string? CheckExecutable(string file, NewExecutable nex, bool includeDebug)
{
// TODO: Don't read entire file
var data = nex.ReadArbitraryRange();
if (data == null)
byte[]? data;
try
{
data = nex.ReadArbitraryRange();
if (data == null)
return null;
}
catch
{
// Ignore errors reading ranges
return null;
}
// TODO: Figure out what NE section this lives in
var neMatchSets = new List<ContentMatchSet>

View File

@@ -52,9 +52,18 @@ namespace BinaryObjectScanner.Protection
}
// TODO: Don't read entire file
var data = nex.ReadArbitraryRange();
if (data == null)
byte[]? data;
try
{
data = nex.ReadArbitraryRange();
if (data == null)
return null;
}
catch
{
// Ignore errors reading ranges
return null;
}
var neMatchSets = new List<ContentMatchSet>
{

View File

@@ -41,9 +41,18 @@ namespace BinaryObjectScanner.Protection
public string? CheckExecutable(string file, NewExecutable nex, bool includeDebug)
{
// TODO: Don't read entire file
var data = nex.ReadArbitraryRange();
if (data == null)
byte[]? data;
try
{
data = nex.ReadArbitraryRange();
if (data == null)
return null;
}
catch
{
// Ignore errors reading ranges
return null;
}
// TODO: Figure out what NE section this lives in
var neMatchSets = new List<ContentMatchSet>