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)); } } }
private void LoadImportReferencesFromRelaPlt() { var rela_plt = loader.GetSectionInfoByName(".rela.plt"); var plt = loader.GetSectionInfoByName(".plt"); var relaRdr = loader.CreateReader(rela_plt.FileOffset); for (ulong i = 0; i < rela_plt.EntryCount(); ++i) { // Read the .rela.plt entry ulong offset; if (!relaRdr.TryReadUInt64(out offset)) { return; } ulong info; if (!relaRdr.TryReadUInt64(out info)) { return; } long addend; if (!relaRdr.TryReadInt64(out addend)) { return; } ulong sym = info >> 32; string symStr = loader.GetSymbol64(rela_plt.LinkedSection, sym); var addr = plt.Address + (uint)(i + 1) * plt.EntrySize; importReferences.Add( addr, new NamedImportReference(addr, null, symStr)); } }
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); } } }
public override void Relocate(Program program) { DumpRela64(loader); var syms = RelocateDynamicSymbols(program); if (syms != null) { return; } foreach (var relSection in loader.Sections.Where(s => s.Type == SectionHeaderType.SHT_RELA)) { var symbols = loader.Symbols[relSection.LinkedSection.FileOffset]; var referringSection = relSection.RelocatedSection; var rdr = loader.CreateReader(relSection.FileOffset); for (uint i = 0; i < relSection.EntryCount(); ++i) { var rela = loader.LoadRelaEntry(rdr); var sym = symbols[rela.SymbolIndex]; RelocateEntry(program, sym, referringSection, rela); } } }
protected void DumpRela64(ElfLoader64 loader) { foreach (var section in loader.Sections.Where(s => s.Type == SectionHeaderType.SHT_RELA)) { 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]; 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)); } } }