コード例 #1
0
ファイル: MetadataHeader.cs プロジェクト: 0xe9/Snile
 public MetadataHeader(Reader reader)
 {
     this.memStream = reader.memStream;
     this.binaryParser = reader.binaryParser;
     uint metaDataRVA = reader.GetCLRHeader().GetMetaDataRVA();
     this.metaDataHeaderAddress = (long)reader.RVAtoOffset(metaDataRVA);
     this.versionLength = (int)(binaryParser.ParseUInt32(metaDataHeaderAddress + 0xC));
 }
コード例 #2
0
ファイル: StreamParser.cs プロジェクト: 0xe9/Snile
        public StreamParser(Reader reader)
        {
            this.reader = reader;
            this.memStream = reader.memStream;
            this.binaryParser = reader.binaryParser;

            uint metaDataRVA = reader.GetCLRHeader().GetMetaDataRVA();
            long metaDataHeaderAddress = (long)reader.RVAtoOffset(metaDataRVA);
            this.streamHeaderAddress = (long)(metaDataHeaderAddress + 0x20);

            this.streamCount = (int)reader.GetMetadataHeader().GetNumberOfStreams();

            binaryParser.BaseStream.Position = streamHeaderAddress;

            streams = new MetadataStream[this.streamCount];

            int count = 0;

            for (int i = 0; i < this.streamCount; i++)
            {
                string name;
                long start = streamHeaderAddress + count;
                long streamStart = start + (i * 4);

                binaryParser.BaseStream.Position = streamStart;
                uint offset = binaryParser.ReadUInt32();
                uint size = binaryParser.ReadUInt32();

                List<char> buff = new List<char>();
                char next;
                do
                {
                    next = this.binaryParser.ReadChar();
                    buff.Add(next);
                } while (this.binaryParser.BaseStream.Position % 4 != 0 || next != '\0');

                name = new string(buff.TakeWhile(sName => !sName.Equals('\0')).ToArray());

                //gets tableheap offset
                if (i == this.streamCount -1)
                {
                    tableHeapOffset = binaryParser.BaseStream.Position;
                }

                if (name.Length >= 8)
                {
                    count += 16;
                }
                else if (name.Length >= 4)
                {
                    count += 12;
                }
                else
                {
                    count += 8;
                }

                this.streams[i] = new MetadataStream(name, offset, size);
            }
            InitStreams();
        }
コード例 #3
0
ファイル: Streams.cs プロジェクト: 0xe9/Snile
        public Streams(Reader reader)
        {
            this.memStream = reader.memStream;
            this.binaryParser = reader.binaryParser;
            uint metaDataRVA = reader.GetCLRHeader().GetMetaDataRVA();
            long metaDataHeaderAddress = (long)reader.RVAtoOffset(metaDataRVA);
            this.streamHeaderAddress = (long)(metaDataHeaderAddress + 0x20);
            this.streamCount = (int)reader.GetMetadataHeader().GetNumberOfStreams();

            binaryParser.BaseStream.Position = streamHeaderAddress;

            streams = new Stream[this.streamCount];

            int count = 0;

            for (int i = 0; i < this.streamCount; i++)
            {
                string name;
                long start = streamHeaderAddress + count;
                long streamStart = start + (i * 4);

                binaryParser.BaseStream.Position = streamStart;
                uint offset = binaryParser.ReadUInt32();
                uint size = binaryParser.ReadUInt32();

                List<char> buff = new List<char>();
                char next;
                do
                {
                    next = this.binaryParser.ReadChar();
                    buff.Add(next);
                } while (this.binaryParser.BaseStream.Position % 4 != 0 || next != '\0');

                name = new string(buff.TakeWhile(sName => !sName.Equals('\0')).ToArray());

                if (name.Length >= 8)
                {
                    count += 16;
                }
                else if (name.Length >= 4)
                {
                    count += 12;
                }
                else
                {
                    count += 8;
                }

                if(((name.Equals("#-")) || ((name.Equals("#~")))))
                {
                    this.tableHeap = new TableHeap(reader, name, offset, size);
                }

                if (name.Equals("#Strings"))
                {
                    this.stringsHeap = new StringsHeap(reader, name, offset, size);
                }

                if (name.Equals("#US"))
                {
                    this.userStringsHeap = new UserStringsHeap(reader, name, offset, size);
                }

                if (name.Equals("#GUID"))
                {
                    this.guidHeap = new GUIDHeap(reader, name, offset, size);
                }

                if (name.Equals("#Blob"))
                {
                    this.blobHeap = new BlobHeap(reader, name, offset, size);
                }
                this.streams[i] = new Stream(name, offset, size);
            }
        }