mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-04-28 17:37:20 +00:00
Stream safety and better streams
This commit is contained in:
@@ -871,8 +871,16 @@ namespace BurnOutSharp.Wrappers
|
||||
/// <returns>A PE executable wrapper on success, null on failure</returns>
|
||||
public static PortableExecutable Create(byte[] data, int offset)
|
||||
{
|
||||
MemoryStream dataStream = new MemoryStream(data);
|
||||
dataStream.Position = offset;
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and use that
|
||||
MemoryStream dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Create(dataStream);
|
||||
}
|
||||
|
||||
@@ -883,6 +891,10 @@ namespace BurnOutSharp.Wrappers
|
||||
/// <returns>A PE executable wrapper on success, null on failure</returns>
|
||||
public static PortableExecutable Create(Stream data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
return null;
|
||||
|
||||
var executable = Builder.PortableExecutable.ParseExecutable(data);
|
||||
if (executable == null)
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user