Exemplo n.º 1
0
        public override List <ElfSection> LoadSectionHeaders()
        {
            // Create the sections.
            var inames   = new List <uint>();
            var links    = new List <uint>();
            var infos    = new List <uint>();
            var sections = new List <ElfSection>();
            var rdr      = CreateReader(Header64.e_shoff);

            for (uint i = 0; i < Header64.e_shnum; ++i)
            {
                var shdr    = Elf64_SHdr.Load(rdr);
                var section = new ElfSection
                {
                    Number  = i,
                    Type    = shdr.sh_type,
                    Flags   = shdr.sh_flags,
                    Address = shdr.sh_addr != 0
                        ? platform !.MakeAddressFromLinear(shdr.sh_addr, false)
                        : null !,
                    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(sections, inames[i]);

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

                case SectionHeaderType.SHT_DYNAMIC:
                case SectionHeaderType.SHT_HASH:
                case SectionHeaderType.SHT_SYMTAB:
                case SectionHeaderType.SHT_DYNSYM:
                    linkSection = GetSectionByIndex(sections, links[i]);
                    break;
                }
                section.LinkedSection    = linkSection;
                section.RelocatedSection = relSection;
            }
            return(sections);
        }
Exemplo n.º 2
0
 public string GetStrPtr64(Elf64_SHdr sect, uint offset)
 {
     if (sect == null)
     {
         // Most commonly, this will be an null, because a call to GetSectionByName() failed
         throw new ArgumentException("GetStrPtr passed null section.");
     }
     // Get a pointer to the start of the string table and add the offset
     return ReadAsciiString(RawImage, sect.sh_offset + offset);
 }
Exemplo n.º 3
0
 private ImageMapSegmentRenderer CreateRenderer64(Elf64_SHdr shdr)
 {
     switch (shdr.sh_type)
     {
     case SectionHeaderType.SHT_DYNAMIC:
         return new DynamicSectionRenderer64(this, shdr);
     case SectionHeaderType.SHT_RELA:
         return new RelaSegmentRenderer64(this, shdr);
     case SectionHeaderType.SHT_SYMTAB:
     case SectionHeaderType.SHT_DYNSYM:
         return new SymtabSegmentRenderer64(this, shdr);
     default: return null;
     }
 }
Exemplo n.º 4
0
 public SymtabSegmentRenderer64(ElfImageLoader loader, Elf64_SHdr shdr)
 {
     this.loader = loader;
     this.shdr = shdr;
 }
Exemplo n.º 5
0
 private ImageMapSegmentRenderer CreateRenderer64(Elf64_SHdr shdr)
 {
     return null;        //$NYI
 }
Exemplo n.º 6
0
 public DynamicSectionRenderer64(ElfImageLoader loader, Elf64_SHdr shdr)
 {
     this.loader = loader;
     this.shdr = shdr;
 }
Exemplo n.º 7
0
 public SymtabSegmentRenderer64(ElfImageLoader loader, Elf64_SHdr shdr)
 {
     this.loader = loader;
     this.shdr   = shdr;
 }
Exemplo n.º 8
0
 public DynamicSectionRenderer64(ElfImageLoader loader, Elf64_SHdr shdr)
 {
     this.loader = loader;
     this.shdr   = shdr;
 }