Example #1
0
        public override void LoadSectionHeaders()
        {
            // Create the sections.
            var inames = new List <uint>();
            var links  = new List <uint>();
            var infos  = new List <uint>();
            var rdr    = imgLoader.CreateReader(Header.e_shoff);

            for (uint i = 0; i < Header.e_shnum; ++i)
            {
                var shdr = Elf32_SHdr.Load(rdr);
                if (shdr == null)
                {
                    break;
                }
                var section = new ElfSection
                {
                    Number     = i,
                    Type       = shdr.sh_type,
                    Flags      = shdr.sh_flags,
                    Address    = Address.Ptr32(shdr.sh_addr),
                    FileOffset = shdr.sh_offset,
                    Size       = shdr.sh_size,
                    Alignment  = shdr.sh_addralign,
                    EntrySize  = shdr.sh_entsize,
                };
                Sections.Add(section);
                inames.Add(shdr.sh_name);
                links.Add(shdr.sh_link);
                infos.Add(shdr.sh_info);
            }

            // Get section names and crosslink sections.

            for (int i = 0; i < Sections.Count; ++i)
            {
                var section = Sections[i];
                section.Name = ReadSectionName(inames[i]);

                ElfSection linkSection = null;
                ElfSection relSection  = null;
                switch (section.Type)
                {
                case SectionHeaderType.SHT_REL:
                case SectionHeaderType.SHT_RELA:
                    linkSection = GetSectionByIndex(links[i]);
                    relSection  = GetSectionByIndex(infos[i]);
                    break;

                case SectionHeaderType.SHT_DYNAMIC:
                case SectionHeaderType.SHT_HASH:
                case SectionHeaderType.SHT_SYMTAB:
                case SectionHeaderType.SHT_DYNSYM:
                    linkSection = GetSectionByIndex(links[i]);
                    break;
                }
                section.LinkedSection    = linkSection;
                section.RelocatedSection = relSection;
            }
        }