Example #1
0
        void PatchStreamHeaderOffset(MetadataHeap heap)
        {
            long pos = m_binaryWriter.BaseStream.Position;

            m_binaryWriter.BaseStream.Position = heap.GetStream().Header.Offset;
            m_binaryWriter.Write((uint)(pos - m_mdStart));
            m_binaryWriter.BaseStream.Position = pos;
        }
Example #2
0
        void CreateStream(string name)
        {
            MetadataStream stream = new MetadataStream();

            stream.Header.Name = name;
            stream.Heap        = MetadataHeap.HeapFactory(stream);
            m_root.Streams.Add(stream);
        }
Example #3
0
        void SetHeapIndexSize(MetadataHeap heap, byte flag)
        {
            if (heap == null)
            {
                return;
            }
            TablesHeap th = m_root.Streams.TablesHeap;

            heap.IndexSize = ((th.HeapSizes & flag) > 0) ? 4 : 2;
        }
        public override void VisitMetadataStreamCollection(MetadataStreamCollection coll)
        {
            MetadataStream tables = new MetadataStream();

            tables.Header.Name = MetadataStream.Tables;
            tables.Heap        = MetadataHeap.HeapFactory(tables);
            TablesHeap th = tables.Heap as TablesHeap;

            th.Tables = new TableCollection(th);
            m_root.Streams.Add(tables);
        }
Example #5
0
 void SetHeapSize(MetadataHeap heap, MemoryBinaryWriter data, byte flag)
 {
     if (data.BaseStream.Length > 65536)
     {
         m_root.Streams.TablesHeap.HeapSizes |= flag;
         heap.IndexSize = 4;
     }
     else
     {
         heap.IndexSize = 2;
     }
 }
Example #6
0
        void VisitHeap(MetadataHeap heap)
        {
            long cursor = m_binaryReader.BaseStream.Position;

            m_binaryReader.BaseStream.Position = m_root.GetImage().ResolveVirtualAddress(
                m_root.GetImage().CLIHeader.Metadata.VirtualAddress)
                                                 + heap.GetStream().Header.Offset;

            heap.Data = m_binaryReader.ReadBytes((int)heap.GetStream().Header.Size);

            m_binaryReader.BaseStream.Position = cursor;
        }
Example #7
0
        public override void VisitMetadataStreamHeader(MetadataStream.MetadataStreamHeader header)
        {
            header.Offset = m_binaryReader.ReadUInt32();
            header.Size   = m_binaryReader.ReadUInt32();

            StringBuilder buffer = new StringBuilder();

            while (true)
            {
                char cur = (char)m_binaryReader.ReadSByte();
                if (cur == '\0')
                {
                    break;
                }
                buffer.Append(cur);
            }
            header.Name = buffer.ToString();
            if (header.Name.Length == 0)
            {
                throw new MetadataFormatException("Invalid stream name");
            }

            long rootpos = m_root.GetImage().ResolveVirtualAddress(
                m_root.GetImage().CLIHeader.Metadata.VirtualAddress);

            long curpos = m_binaryReader.BaseStream.Position;

            if (header.Size != 0)
            {
                curpos -= rootpos;
            }

            curpos += 3;
            curpos &= ~3;

            if (header.Size != 0)
            {
                curpos += rootpos;
            }

            m_binaryReader.BaseStream.Position = curpos;

            header.Stream.Heap = MetadataHeap.HeapFactory(header.Stream);
        }