// dnlib: See LICENSE.txt for more info using System; namespace dnlib.IO { /// /// Creates s that read native memory /// public sealed unsafe class NativeMemoryDataReaderFactory : DataReaderFactory { /// /// The filename or null if the data is not from a file /// public override string Filename => filename; /// /// Gets the total length of the data /// public override uint Length => length; DataStream stream; string filename; uint length; NativeMemoryDataReaderFactory(byte* data, uint length, string filename) { this.filename = filename; this.length = length; stream = DataStreamFactory.Create(data); } internal void SetLength(uint length) => this.length = length; /// /// Creates a instance /// /// Pointer to data /// Length of data /// The filename or null if the data is not from a file /// public static NativeMemoryDataReaderFactory Create(byte* data, uint length, string filename) { if (data is null) throw new ArgumentNullException(nameof(data)); return new NativeMemoryDataReaderFactory(data, length, filename); } /// /// Creates a data reader /// /// Offset of data /// Length of data /// public override DataReader CreateReader(uint offset, uint length) => CreateReader(stream, offset, length); /// /// This method doesn't need to be called since this instance doesn't own the native memory /// public override void Dispose() { stream = EmptyDataStream.Instance; length = 0; filename = null; } } }