Class SerializedBlobStream
- Namespace
- AsmResolver.PE.DotNet.Metadata
- Assembly
- AsmResolver.PE.dll
Provides an implementation of a blob stream that obtains blobs from a readable segment in a file.
public class SerializedBlobStream : BlobStream, IMetadataStream, ISegment, IOffsetProvider, IWritable
- Inheritance
-
SerializedBlobStream
- Implements
- Inherited Members
Constructors
SerializedBlobStream(byte[])
Creates a new blob stream with the provided byte array as the raw contents of the stream.
public SerializedBlobStream(byte[] rawData)
Parameters
rawData
byte[]The raw contents of the stream.
SerializedBlobStream(string, in BinaryStreamReader)
Creates a new blob stream with the provided segment in a file as the raw contents of the stream.
public SerializedBlobStream(string name, in BinaryStreamReader reader)
Parameters
name
stringThe name of the stream.
reader
BinaryStreamReaderThe raw contents of the stream.
SerializedBlobStream(string, byte[])
Creates a new blob stream with the provided byte array as the raw contents of the stream.
public SerializedBlobStream(string name, byte[] rawData)
Parameters
Properties
CanRead
Gets a value indicating whether the raw contents of the stream can be read using a binary stream reader.
public override bool CanRead { get; }
Property Value
Methods
CreateReader()
Creates a binary reader that reads the raw contents of the metadata stream.
public override BinaryStreamReader CreateReader()
Returns
- BinaryStreamReader
The reader.
Exceptions
- InvalidOperationException
Occurs when CanRead is
false
.
EnumerateBlobs()
Performs a linear sweep on the stream and yields all blobs that are stored.
public override IEnumerable<(uint Index, byte[] Blob)> EnumerateBlobs()
Returns
- IEnumerable<(uint Index, byte[] Blob)>
The blob enumerator.
Remarks
As blobs can be referenced at any offset within the heap, the heap is technically allowed to contain garbage data in between blob entries. As such, this linear sweep enumerator may not be an accurate depiction of all blobs that are used by the module.
GetBlobByIndex(uint)
Gets a blob by its blob index.
public override byte[]? GetBlobByIndex(uint index)
Parameters
index
uintThe offset into the heap to start reading.
Returns
- byte[]
The blob, excluding the bytes encoding the length of the blob, or
null
if the index was invalid.
GetPhysicalSize()
Computes the number of bytes that the structure contains.
public override uint GetPhysicalSize()
Returns
- uint
The number of bytes.
TryFindBlobIndex(byte[]?, out uint)
Searches the stream for the provided blob.
public override bool TryFindBlobIndex(byte[]? blob, out uint index)
Parameters
blob
byte[]The blob to search for.
index
uintWhen the function returns
true
, contains the index at which the blob was found.
Returns
- bool
true
if the blob index was found,false
otherwise.
TryGetBlobReaderByIndex(uint, out BinaryStreamReader)
Gets a blob binary reader by its blob index.
public override bool TryGetBlobReaderByIndex(uint index, out BinaryStreamReader reader)
Parameters
index
uintThe offset into the heap to start reading.
reader
BinaryStreamReaderWhen this method returns
true
, this parameter contains the created binary reader.
Returns
- bool
true
if a blob reader could be created at the provided index,false
otherwise.
Write(BinaryStreamWriter)
Serializes the structure to an output stream.
public override void Write(BinaryStreamWriter writer)
Parameters
writer
BinaryStreamWriterThe output stream to write the data to.