public override void Render(ImageSegment segment, Program program, Formatter formatter) { var entries = shdr.EntryCount(); var symtab = shdr.LinkedSection; var rdr = loader.CreateReader(shdr.FileOffset); for (ulong i = 0; i < entries; ++i) { ulong offset; if (!rdr.TryReadUInt64(out offset)) { return; } ulong info; if (!rdr.TryReadUInt64(out info)) { return; } ulong addend; if (!rdr.TryReadUInt64(out addend)) { return; } ulong sym = info >> 32; string symStr = loader.GetSymbol64(symtab, sym); formatter.Write("{0:X8} {1,3} {2:X8} {3:X16} {4} ({5})", offset, info & 0xFFFFFFFF, sym, addend, symStr, sym); formatter.WriteLine(); } }
public override void Render(ImageSegment segment, Program program, Formatter formatter) { var entries = shdr.EntryCount(); var symtab = shdr.LinkedSection; var rdr = loader.CreateReader(shdr.FileOffset); for (var i = 0; i < entries; ++i) { uint iName; if (!rdr.TryReadUInt32(out iName)) return; byte info; if (!rdr.TryReadByte(out info)) return; byte other; if (!rdr.TryReadByte(out other)) return; ushort shIndex; if (!rdr.TryReadUInt16(out shIndex)) return; ulong value; if (!rdr.TryReadUInt64(out value)) return; ulong size; if (!rdr.TryReadUInt64(out size)) return; string symStr = loader.GetStrPtr(symtab, iName); string segName = loader.GetSectionName(shIndex); formatter.Write("{0,4} {1,-40} {2:X8} {3:X8} {4:X2} {5}", i, symStr, value, size, info & 0xFF, segName); formatter.WriteLine(); } }
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); } } }
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)); } } }
/// <remarks> /// According to the ELF x86_64 documentation, the .rela.plt and .plt tables /// should contain the same number of entries, even if the individual entry /// sizes are distinct. The entries in .real.plt refer to symbols while the /// entries in .plt are (writeable) pointers. Any caller that jumps to one /// of pointers in the .plt table is a "trampoline", and should be replaced /// in the decompiled code with just a call to the symbol obtained from the /// .real.plt section. /// </remarks> public override void Relocate(Program program) { base.Relocate(program); this.importReferences = program.ImportReferences; 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)); } }
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)); } } }