Ejemplo n.º 1
0
        private void Load()
        {
            _image.Load(_reader);

            uint mdbOffset = (uint)_reader.Position;

            _reader.Position = mdbOffset;

            // Metadata Header
            // Signature
            if (_reader.ReadUInt32() != 0x424A5342)
            {
                throw new BadMetadataException("Invalid metadata header.");
            }

            // MajorVersion			2
            // MinorVersion			2
            // Reserved				4
            _reader.Advance(8);

            var runtimeVersion = _reader.ReadZeroTerminatedString(_reader.ReadInt32());

            // align for dword boundary
            _reader.Align4();

            // Flags		2
            _reader.Advance(2);

            LoadHeaps(mdbOffset);
        }
Ejemplo n.º 2
0
        private static List <SEHBlock> ReadSehBlocks(BufferedBinaryReader reader)
        {
            const int FatSize  = 24;
            const int TinySize = 12;
            var       blocks   = new List <SEHBlock>();
            bool      next     = true;

            while (next)
            {
                // Goto 4 byte boundary (each section has to start at 4 byte boundary)
                reader.Align4();

                uint header = reader.ReadUInt32();
                var  sf     = (SectionFlags)(header & 0xFF);
                int  size   = (int)(header >> 8); //in bytes
                if ((sf & SectionFlags.OptILTable) != 0)
                {
                }
                else if ((sf & SectionFlags.FatFormat) == 0)
                {
                    // tiny header
                    size &= 0xFF; // 1 byte size (filter out the padding)
                    int n = size / TinySize;
                    for (int i = 0; i < n; ++i)
                    {
                        var block = new SEHBlock(reader, false);
                        blocks.Add(block);
                    }
                }
                else
                {
                    //make sure this is an exception block , otherwise skip
                    if ((sf & SectionFlags.EHTable) != 0)
                    {
                        int n = size / FatSize;
                        for (int i = 0; i < n; ++i)
                        {
                            var block = new SEHBlock(reader, true);
                            blocks.Add(block);
                        }
                    }
                    else
                    {
                        reader.Position += size;
                    }
                }

                next = (sf & SectionFlags.MoreSects) != 0;
            }

            return(blocks);
        }