Exemple #1
0
        internal CLRMetaData(PortableExecutableImage image, Location location, CLRMetaDataHeader header, CLRMetaDataStreamTable streamTable,
                             CLRMetaDataStreams streams)
        {
            _image = image;

            Location    = location;
            Header      = header;
            StreamTable = streamTable;
            Streams     = streams;
        }
Exemple #2
0
        internal static async Task <CLRMetaData> GetAsync(PortableExecutableImage image, CLRHeader header)
        {
            var calc           = image.GetCalculator();
            var imageBase      = image.NTHeaders.OptionalHeader.ImageBase;
            var rva            = header.MetaDataAddress;
            var va             = imageBase + rva;
            var offset         = calc.RVAToOffset(rva);
            var size           = header.MetaDataSize;
            var section        = calc.RVAToSection(rva);
            var location       = new Location(image, offset, rva, va, size, size, section);
            var metaDataHeader = await CLRMetaDataHeader.LoadAsync(image, location).ConfigureAwait(false);

            var metaDataStreamTable = await CLRMetaDataStreamTable.LoadAsync(image, metaDataHeader).ConfigureAwait(false);

            var metaDataStreams = await CLRMetaDataStreams.LoadAsync(image, location, metaDataStreamTable).ConfigureAwait(false);

            var metaData = new CLRMetaData(image, location, metaDataHeader, metaDataStreamTable, metaDataStreams);

            return(metaData);
        }
Exemple #3
0
        internal static Task <CLRMetaDataStreams> LoadAsync(PortableExecutableImage image, Location mdLocation, CLRMetaDataStreamTable streamTable)
        {
            try
            {
                var imageBase = image.NTHeaders.OptionalHeader.ImageBase;
                var streams   = new CLRMetaDataStream[streamTable.Count];

                for (var i = 0; i < streams.Length; i++)
                {
                    var entry  = streamTable[i];
                    var stream = new CLRMetaDataStream(image, mdLocation, imageBase, entry);

                    streams[i] = stream;
                }

                uint  rva    = 0;
                ulong va     = 0;
                ulong offset = 0;
                ulong size   = 0;

                if (streams.Length > 0)
                {
                    var stream = streams.MinBy(s => s.Location.FileOffset);

                    rva    = stream.Location.RelativeVirtualAddress;
                    va     = stream.Location.VirtualAddress;
                    offset = stream.Location.FileOffset;
                }

                foreach (var stream in streams)
                {
                    size += stream.Location.FileSize;
                }

                var location = new Location(image, offset, rva, va, size, size);
                var result   = new CLRMetaDataStreams(image, location, streams);

                return(Task.FromResult(result));
            }
            catch (Exception ex)
            {
                throw new PortableExecutableImageException(image, "Could not load CLR meta-data streams from stream.", ex);
            }
        }