コード例 #1
0
ファイル: CLRMetaDataHeader.cs プロジェクト: Workshell/pe
        internal CLRMetaDataHeader(CLRMetaData metaData)
        {
            LocationCalculator calc = metaData.CLR.DataDirectory.Directories.Image.GetCalculator();
            Stream stream = metaData.CLR.DataDirectory.Directories.Image.GetStream();
            ulong image_base = metaData.CLR.DataDirectory.Directories.Image.NTHeaders.OptionalHeader.ImageBase;
            uint rva = metaData.Location.RelativeVirtualAddress;
            ulong va = metaData.Location.VirtualAddress;
            ulong offset = metaData.Location.FileOffset;
            uint size = 0;
            Section section = metaData.Location.Section;

            stream.Seek(offset.ToInt64(), SeekOrigin.Begin);

            MetaData = metaData;
            Signature = Utils.ReadUInt32(stream);

            if (Signature != CLR_METADATA_SIGNATURE)
                throw new ExecutableImageException("Incorrect signature found in CLR meta-data header.");

            MajorVersion = Utils.ReadUInt16(stream);
            MinorVersion = Utils.ReadUInt16(stream);
            Reserved = Utils.ReadUInt32(stream);
            VersionLength = Utils.ReadUInt32(stream);
            Version = Utils.ReadString(stream, VersionLength);
            Flags = Utils.ReadUInt16(stream);
            Streams = Utils.ReadUInt16(stream);

            size = sizeof(uint) + sizeof(ushort) + sizeof(ushort) + sizeof(uint) + sizeof(uint) + VersionLength + sizeof(ushort) + sizeof(ushort);

            Location = new Location(offset, rva, va, size, size, section);
        }
コード例 #2
0
ファイル: CLRMetaData.cs プロジェクト: Workshell/pe
        public static CLRMetaData Get(CLRHeader header)
        {
            LocationCalculator calc = header.CLR.DataDirectory.Directories.Image.GetCalculator();
            ulong image_base = header.CLR.DataDirectory.Directories.Image.NTHeaders.OptionalHeader.ImageBase;
            uint rva = header.MetaDataAddress;
            ulong va = image_base + rva;
            ulong offset = calc.RVAToOffset(rva);
            uint size = header.MetaDataSize;
            Section section = calc.RVAToSection(rva);
            Location location = new Location(offset, rva, va, size, size, section);
            CLRMetaData meta_data = new CLRMetaData(header.CLR, location, header);

            return meta_data;
        }