Ejemplo n.º 1
0
        void init()
        {
            seek(0);
            if (reader.ReadUInt16() != 0x5A4D)
            {
                throw new BadImageFormatException("Not a PE file");
            }
            skip(29 * 2);
            seek(reader.ReadUInt32());

            if (reader.ReadUInt32() != 0x4550)
            {
                throw new BadImageFormatException("Not a PE file");
            }
            fileHeader     = new FileHeader(reader);
            optionalHeader = new OptionalHeader(reader);

            sectionHeaders = new SectionHeader[fileHeader.numberOfSections];
            for (int i = 0; i < sectionHeaders.Length; i++)
            {
                sectionHeaders[i] = new SectionHeader(reader);
            }

            uint netRva = optionalHeader.dataDirectories[14].virtualAddress;

            if (netRva != 0)
            {
                seekRva(netRva);
                cor20Header   = new Cor20Header(reader);
                dotNetSection = getSectionHeaderRva(netRva);
                seekRva(cor20Header.metadataDirectory.virtualAddress);
                cor20Header.initMetadataTable();
            }

            uint resourceRva    = optionalHeader.dataDirectories[2].virtualAddress;
            uint resourceOffset = 0;

            if (resourceRva != 0)
            {
                resourceOffset = rvaToOffset(resourceRva);
            }
            resources = new Resources(reader, resourceOffset, optionalHeader.dataDirectories[2].size);
        }
Ejemplo n.º 2
0
        void init()
        {
            seek(0);
            if (reader.ReadUInt16() != 0x5A4D)
                throw new BadImageFormatException("Not a PE file");
            skip(29 * 2);
            seek(reader.ReadUInt32());

            if (reader.ReadUInt32() != 0x4550)
                throw new BadImageFormatException("Not a PE file");
            fileHeader = new FileHeader(reader);
            optionalHeader = new OptionalHeader(reader);

            sectionHeaders = new SectionHeader[fileHeader.numberOfSections];
            for (int i = 0; i < sectionHeaders.Length; i++)
                sectionHeaders[i] = new SectionHeader(reader);

            uint netOffset = optionalHeader.dataDirectories[14].virtualAddress;
            if (netOffset != 0) {
                seekRva(netOffset);
                cor20Header = new Cor20Header(reader);
                dotNetSection = getSectionHeader(netOffset);
                seekRva(cor20Header.metadataDirectory.virtualAddress);
                cor20Header.initMetadataTable();
            }
        }