// dnlib: See LICENSE.txt for more info using System; using dnlib.IO; using dnlib.PE; namespace dnlib.DotNet.Writer { /// /// A chunk /// public class DataReaderChunk : IChunk { FileOffset offset; RVA rva; DataReader data; readonly uint virtualSize; bool setOffsetCalled; /// public FileOffset FileOffset => offset; /// public RVA RVA => rva; /// /// Constructor /// /// The data public DataReaderChunk(DataReader data) : this(ref data) { } /// /// Constructor /// /// The data /// Virtual size of public DataReaderChunk(DataReader data, uint virtualSize) : this(ref data, virtualSize) { } /// /// Constructor /// /// The data internal DataReaderChunk(ref DataReader data) : this(ref data, (uint)data.Length) { } /// /// Constructor /// /// The data /// Virtual size of internal DataReaderChunk(ref DataReader data, uint virtualSize) { this.data = data; this.virtualSize = virtualSize; } /// /// Gets the data reader /// public DataReader CreateReader() => data; /// /// Replaces the old data with new data. The new data must be the same size as the old data if /// has been called. That method gets called after /// event /// /// public void SetData(DataReader newData) { if (setOffsetCalled && newData.Length != data.Length) throw new InvalidOperationException("New data must be the same size as the old data after SetOffset() has been called"); data = newData; } /// public void SetOffset(FileOffset offset, RVA rva) { this.offset = offset; this.rva = rva; setOffsetCalled = true; } /// public uint GetFileLength() => (uint)data.Length; /// public uint GetVirtualSize() => virtualSize; /// public uint CalculateAlignment() => 0; /// public void WriteTo(DataWriter writer) { data.Position = 0; data.CopyTo(writer); } } }