Esempio n. 1
0
 public override void TerminateMetadataRoot(MetadataRoot root)
 {
     m_mdSize          = (uint)(m_binaryWriter.BaseStream.Position - m_mdStart);
     m_imporTableStart = (uint)m_binaryWriter.BaseStream.Position;
     m_binaryWriter.Write(new byte [0x60]);              // imports
     m_imgWriter.Initialize();
     PatchHeader();
     root.GetImage().Accept(m_imgWriter);
 }
Esempio n. 2
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);
        }