Example #1
0
        private void LoadImportReferencesFromRelaPlt()
        {
            var rela_plt = loader.GetSectionInfoByName(".rela.plt");
            var plt      = loader.GetSectionInfoByName(".plt");

            if (rela_plt == null || plt == null)
            {
                return;
            }
            var relaRdr = loader.CreateReader(rela_plt.FileOffset);

            for (ulong i = 0; i < rela_plt.EntryCount(); ++i)
            {
                // Read the .rela.plt entry
                var rela = Elf64_Rela.Read(relaRdr);

                ulong sym     = rela.r_info >> 32;
                var   fileOff = rela_plt.LinkedSection !.FileOffset;
                if (fileOff == 0)
                {
                    continue;
                }
                var symStr = loader.Symbols[fileOff][(int)sym];

                var addr = plt.Address !+(uint)(i + 1) * plt.EntrySize;
                var st   = ElfLoader.GetSymbolType(symStr);
                if (st.HasValue)
                {
                    importReferences ![addr] = new NamedImportReference(addr, null, symStr.Name, st.Value);
Example #2
0
        protected void DumpRela64(ElfLoader64 loader)
        {
            foreach (var section in loader.Sections.Where(s =>
                                                          s.Type == SectionHeaderType.SHT_RELA &&
                                                          s.LinkedSection != null &&
                                                          s.LinkedSection.FileOffset != 0))
            {
                Debug.Print("RELA: offset {0:X} symbol section {1}, relocating in section {2}",
                            section.FileOffset,
                            section.LinkedSection.Name,
                            section.RelocatedSection.Name);

                var symbols = loader.Symbols[section.LinkedSection.FileOffset];
                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,
                                RelocationTypeToString((uint)rela.r_info),
                                symbols[(int)(rela.r_info >> 32)].Name,
                                rela.r_addend,
                                (int)(rela.r_info >> 32));
                }
            }
        }
Example #3
0
        private void LoadImportReferencesFromRelaPlt()
        {
            var rela_plt = loader.GetSectionInfoByName(".rela.plt");
            var plt      = loader.GetSectionInfoByName(".plt");

            if (rela_plt == null || plt == null)
            {
                return;
            }
            var relaRdr = loader.CreateReader(rela_plt.FileOffset);

            for (ulong i = 0; i < rela_plt.EntryCount(); ++i)
            {
                // Read the .rela.plt entry
                var rela = Elf64_Rela.Read(relaRdr);

                ulong sym    = rela.r_info >> 32;
                var   symStr = loader.Symbols[rela_plt.LinkedSection][(int)sym];

                var addr = plt.Address + (uint)(i + 1) * plt.EntrySize;
                importReferences.Add(
                    addr,
                    new NamedImportReference(addr, null, symStr.Name));
            }
        }
Example #4
0
        public override void RelocateEntry(Program program, ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela)
        {
            var rt = (RiscV64Rt)(rela.r_info & 0xFF);

            switch (rt)
            {
            case RiscV64Rt.R_RISCV_COPY:
                break;
            }
        }
Example #5
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);
     }
 }
Example #6
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);
         }
     }
 }
Example #7
0
        public override void RelocateEntry(Program program, ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela)
        {
            var rt = (RiscV64Rt)(rela.r_info & 0xFF);

            switch (rt)
            {
            case RiscV64Rt.R_RISCV_COPY:
                break;
            }
        }
Example #8
0
 public override void RelocateEntry(Program program, ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela)
 {
     throw new NotImplementedException();
 }
Example #9
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;
            EndianImageReader 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);
            }
        }
Example #10
0
 public abstract void RelocateEntry(Program program, ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela);
Example #11
0
 public abstract void RelocateEntry(Program program, ElfSymbol symbol, ElfSection referringSection, Elf64_Rela rela);