Пример #1
0
        public override ElfRelocation LoadRelaEntry(EndianImageReader rdr)
        {
            var rela = Elf64_Rela.Read(rdr);

            return(new ElfRelocation
            {
                Offset = rela.r_offset,
                Info = rela.r_info,
                Addend = rela.r_addend,
                SymbolIndex = (int)(rela.r_info >> 32),
            });
        }
Пример #2
0
 public override void RelocateEntry(Program program, ElfSymbol sym, ElfSection referringSection, Elf64_Rela rela)
 {
     if (loader.Sections.Count <= sym.SectionIndex)
         return;
     if (sym.SectionIndex == 0)
         return;
     var symSection = loader.Sections[(int)sym.SectionIndex];
     ulong S = (ulong)sym.Value + symSection.Address.ToLinear();
     long A = 0;
     int sh = 0;
     uint mask = ~0u;
     Address addr;
     ulong P;
     ImageReader relR;
     ImageWriter relW;
     if (referringSection.Address != null)
     {
         addr = referringSection.Address + rela.r_offset;
         P = addr.ToLinear();
         relR = program.CreateImageReader(addr);
         relW = program.CreateImageWriter(addr);
     }
     else
     {
         addr = null;
         P = 0;
         relR = null;
         relW = null;
     }
     ulong PP = P;
     var rt = (x86_64Rt)(rela.r_info & 0xFF);
     switch (rt)
     {
     case x86_64Rt.R_X86_64_NONE: //  just ignore (common)
         break;
     case x86_64Rt.R_X86_64_COPY:
         break;
     default:
         Debug.Print("x86_64 ELF relocation type {0} not implemented yet.",
             rt);
         break;
         //throw new NotImplementedException(string.Format(
         //    "x86_64 ELF relocation type {0} not implemented yet.",
         //    rt));
     }
     if (relR != null)
     {
         var w = relR.ReadUInt64();
         w += ((ulong)(S + (ulong)A + P) >> sh) & mask;
         relW.WriteUInt64(w);
     }
 }
Пример #3
0
 public override void Relocate(Program program)
 {
     DumpRela64(loader);
     foreach (var relSection in loader.Sections.Where(s => s.Type == SectionHeaderType.SHT_RELA))
     {
         var symbols          = loader.Symbols[relSection.LinkedSection];
         var referringSection = relSection.RelocatedSection;
         var rdr = loader.CreateReader(relSection.FileOffset);
         for (uint i = 0; i < relSection.EntryCount(); ++i)
         {
             var rela = Elf64_Rela.Read(rdr);
             var sym  = symbols[(int)(rela.r_info >> 32)];
             RelocateEntry(program, sym, referringSection, rela);
         }
     }
 }
Пример #4
0
        protected void DumpRela64(ElfLoader64 loader)
        {
            foreach (var section in loader.Sections.Where(s => s.Type == SectionHeaderType.SHT_RELA))
            {
                Debug.Print("RELA: offset {0:X} link section {1}",
                            section.FileOffset,
                            section.LinkedSection.Name);

                var symbols = loader.Symbols[section.LinkedSection];
                var rdr     = loader.CreateReader(section.FileOffset);
                for (uint i = 0; i < section.EntryCount(); ++i)
                {
                    var rela = Elf64_Rela.Read(rdr);
                    Debug.Print("  off:{0:X16} type:{1,-16} add:{3,-20} {4,3} {2}",
                                rela.r_offset,
                                (SparcRt)(rela.r_info & 0xFF),
                                symbols[(int)(rela.r_info >> 8)].Name,
                                rela.r_addend,
                                (int)(rela.r_info >> 8));
                }
            }
        }
Пример #5
0
 public abstract void RelocateEntry(Program program, ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela);
Пример #6
0
        public override void RelocateEntry(Program program, ElfSymbol sym, ElfSection referringSection, Elf64_Rela rela)
        {
            if (loader.Sections.Count <= sym.SectionIndex)
            {
                return;
            }
            if (sym.SectionIndex == 0)
            {
                return;
            }
            var         symSection = loader.Sections[(int)sym.SectionIndex];
            ulong       S          = (ulong)sym.Value + symSection.Address.ToLinear();
            long        A          = 0;
            int         sh         = 0;
            uint        mask       = ~0u;
            Address     addr;
            ulong       P;
            ImageReader relR;
            ImageWriter relW;

            if (referringSection.Address != null)
            {
                addr = referringSection.Address + rela.r_offset;
                P    = addr.ToLinear();
                relR = program.CreateImageReader(addr);
                relW = program.CreateImageWriter(addr);
            }
            else
            {
                addr = null;
                P    = 0;
                relR = null;
                relW = null;
            }
            ulong PP = P;
            var   rt = (x86_64Rt)(rela.r_info & 0xFF);

            switch (rt)
            {
            case x86_64Rt.R_X86_64_NONE: //  just ignore (common)
                break;

            case x86_64Rt.R_X86_64_COPY:
                break;

            default:
                Debug.Print("x86_64 ELF relocation type {0} not implemented yet.",
                            rt);
                break;
                //throw new NotImplementedException(string.Format(
                //    "x86_64 ELF relocation type {0} not implemented yet.",
                //    rt));
            }
            if (relR != null)
            {
                var w = relR.ReadUInt64();
                w += ((ulong)(S + (ulong)A + P) >> sh) & mask;
                relW.WriteUInt64(w);
            }
        }
Пример #7
0
 public virtual void RelocateEntry(ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela)
 {
     throw new NotImplementedException();
 }
Пример #8
0
 public abstract void RelocateEntry(Program program, ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela);
Пример #9
0
 public override void RelocateEntry(Program program, ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela)
 {
     throw new NotImplementedException();
 }
Пример #10
0
 public override void RelocateEntry(Program program, ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela)
 {
     throw new NotImplementedException();
 }