Exemplo n.º 1
0
        public CLIFile(string pReferenceName, byte[] pData)
            : base(pData)
        {
            ReferenceName = pReferenceName;

            DataDirectory headerDataDirectory = OptionalHeader.DataDirectories[14];
            SectionHeader headerSectionHeader = GetSection(headerDataDirectory.VirtualAddress);

            Cursor = headerSectionHeader.PointerToRawData + (headerDataDirectory.VirtualAddress - headerSectionHeader.VirtualAddress);
            CLIHeader.Read(this);
            SectionHeader metadataSectionHeader = GetSection(CLIHeader.Metadata.VirtualAddress);

            CLIMetadataHeaderOffset = metadataSectionHeader.PointerToRawData + (CLIHeader.Metadata.VirtualAddress - metadataSectionHeader.VirtualAddress);
            Cursor = CLIMetadataHeaderOffset;
            CLIMetadataHeader.Read(this);
            Cursor = CLIMetadataHeaderOffset;
            foreach (CLIMetadataStreamHeader streamHeader in CLIMetadataHeader.Streams)
            {
                switch (streamHeader.Name)
                {
                case "#~": TablesStream = streamHeader; break;

                case "#Strings": StringsStream = streamHeader; break;

                case "#US": USStream = streamHeader; break;

                case "#GUID": GUIDStream = streamHeader; break;

                case "#Blob": BlobStream = streamHeader; break;

                default: throw new BadImageFormatException("Invalid CLIMetadataHeader Stream");
                }
            }
            Cursor = CLIMetadataHeaderOffset + TablesStream.Offset;
            CLIMetadataTablesHeader.Read(this);

            Array.ForEach(sMetadataLoaders, l => l.Initializer(this));
            Array.ForEach(sMetadataLoaders, l => l.Loader(this));
            Array.ForEach(sMetadataLoaders, l => l.Linker(this));
            Array.ForEach(MethodDefTable, m => { if (m.Body != null)
                                                 {
                                                     m.Body.LinkData(m);
                                                 }
                          });
        }
Exemplo n.º 2
0
        public bool Read(PEFile pFile)
        {
            Signature = pFile.ReadUInt32();
            MajorVersion = pFile.ReadUInt16();
            MinorVersion = pFile.ReadUInt16();
            Reserved = pFile.ReadUInt32();
            VersionLength = pFile.ReadUInt32();
            Version = pFile.ReadBytes(VersionLength);
            Flags = pFile.ReadUInt16();
            StreamCount = pFile.ReadUInt16();

            Streams = new CLIMetadataStreamHeader[StreamCount];
            for (int index = 0; index < Streams.Length; ++index)
            {
                Streams[index] = new CLIMetadataStreamHeader();
                Streams[index].Read(pFile);
            }
            return true;
        }
Exemplo n.º 3
0
        public bool Read(PEFile pFile)
        {
            Signature     = pFile.ReadUInt32();
            MajorVersion  = pFile.ReadUInt16();
            MinorVersion  = pFile.ReadUInt16();
            Reserved      = pFile.ReadUInt32();
            VersionLength = pFile.ReadUInt32();
            Version       = pFile.ReadBytes(VersionLength);
            Flags         = pFile.ReadUInt16();
            StreamCount   = pFile.ReadUInt16();

            Streams = new CLIMetadataStreamHeader[StreamCount];
            for (int index = 0; index < Streams.Length; ++index)
            {
                Streams[index] = new CLIMetadataStreamHeader();
                Streams[index].Read(pFile);
            }
            return(true);
        }
Exemplo n.º 4
0
        public CLIFile(string pReferenceName, byte[] pData)
            : base(pData)
        {
            ReferenceName = pReferenceName;

            DataDirectory headerDataDirectory = OptionalHeader.DataDirectories[14];
            SectionHeader headerSectionHeader = GetSection(headerDataDirectory.VirtualAddress);
            Cursor = headerSectionHeader.PointerToRawData + (headerDataDirectory.VirtualAddress - headerSectionHeader.VirtualAddress);
            CLIHeader.Read(this);
            SectionHeader metadataSectionHeader = GetSection(CLIHeader.Metadata.VirtualAddress);
            CLIMetadataHeaderOffset = metadataSectionHeader.PointerToRawData + (CLIHeader.Metadata.VirtualAddress - metadataSectionHeader.VirtualAddress);
            Cursor = CLIMetadataHeaderOffset;
            CLIMetadataHeader.Read(this);
            Cursor = CLIMetadataHeaderOffset;
            foreach (CLIMetadataStreamHeader streamHeader in CLIMetadataHeader.Streams)
            {
                switch (streamHeader.Name)
                {
                    case "#~": TablesStream = streamHeader; break;
                    case "#Strings": StringsStream = streamHeader; break;
                    case "#US": USStream = streamHeader; break;
                    case "#GUID": GUIDStream = streamHeader; break;
                    case "#Blob": BlobStream = streamHeader; break;
                    default: throw new BadImageFormatException("Invalid CLIMetadataHeader Stream");
                }
            }
            Cursor = CLIMetadataHeaderOffset + TablesStream.Offset;
            CLIMetadataTablesHeader.Read(this);

            Array.ForEach(sMetadataLoaders, l => l.Initializer(this));
            Array.ForEach(sMetadataLoaders, l => l.Loader(this));
            Array.ForEach(sMetadataLoaders, l => l.Linker(this));
            Array.ForEach(MethodDefTable, m => { if (m.Body != null) m.Body.LinkData(m); });
        }