internal bool ReadEntry() { var tailLength = this.tailLength; if (tailLength + 1 >= this.Size) { return(false); } byte compressedIntBytes = 0; byte[] currentData = null; int currentDataCount = 0; currentDataCount = CliMetadataFixedRoot.ReadCompressedUnsignedInt(reader, out compressedIntBytes); if (tailLength + compressedIntBytes >= this.Size) { reader.BaseStream.Seek(-(tailLength + compressedIntBytes - this.Size), SeekOrigin.Current); return(false); } else { tailLength += compressedIntBytes; } if (currentDataCount == 0) { /* * * Reached the end of the heap which is padded * with zeroes until the next 4-byte boundry. * */ return(false); } if (tailLength + currentDataCount > this.Size) { throw new BadImageFormatException(string.Format("The data within the {0} heap entry is longer than expected.", this.Name)); } currentData = new byte[currentDataCount]; for (int i = 0; i < currentDataCount && tailLength < this.Size; i++, tailLength++) { currentData[i] = reader.ReadByte(); } this.AddData(this.GetData(currentData), compressedIntBytes); if (tailLength >= this.Size) { return(false); } return(true); }
internal void Read(EndianAwareBinaryReader reader) { this.syncObject = this.metadataRoot.SourceImage.SyncObject; lock (this.syncObject) { byte[] blobSectionData = new byte[this.Size]; reader.Read(blobSectionData, 0, blobSectionData.Length); MemoryStream blobStream = new MemoryStream(blobSectionData); this.reader = new EndianAwareBinaryReader(blobStream, Endianness.LittleEndian, false); this.blobStream = blobStream; //this.reader = new EndianAwareBinaryReader(reader.BaseStream, Endianness.LittleEndian, false); byte firstNull = (byte)(this.reader.PeekByte() & 0xFF); if (firstNull != 0) { throw new BadImageFormatException(string.Format("The first item of a {0} heap must be null.", this.Name)); } this.smallEntries.Add(0, new SmallBlobEntry(1) { BlobData = new byte[this.reader.ReadByte()] }); byte currentItemLengthWidth; long currentPosition = 1; while (currentPosition < this.Size) { int currentLength = CliMetadataFixedRoot.ReadCompressedUnsignedInt(this.reader, out currentItemLengthWidth); if (currentItemLengthWidth == 1) { this.smallEntries.Add((uint)currentPosition, new SmallBlobEntry((sbyte)currentLength)); } else if (currentItemLengthWidth == 2) { this.mediumEntries.Add((uint)currentPosition, new MediumBlobEntry((short)currentLength)); } else { this.largEntries.Add((uint)currentPosition, new LargeBlobEntry(currentLength)); } if (currentPosition + currentItemLengthWidth + currentLength > this.Size) { break; } currentPosition += currentItemLengthWidth + currentLength; this.reader.BaseStream.Seek(currentLength, SeekOrigin.Current); } } }
public CliMetadataBlobHeaderAndHeap(CliMetadataStreamHeader originalHeader, CliMetadataFixedRoot metadataRoot) : base(originalHeader) { this.metadataRoot = metadataRoot; }