Beispiel #1
0
        private static void CopyRelocationsX86_64(DwarfRelocatableSection dwarfRelocSection, DwarfElfContext elfContext, ElfRelocationTable relocTable)
        {
            relocTable.Entries.Clear();
            foreach (var reloc in dwarfRelocSection.Relocations)
            {
                var relocType = reloc.Size == DwarfAddressSize.Bit64 ? ElfRelocationType.R_X86_64_64 : ElfRelocationType.R_X86_64_32;
                switch (reloc.Target)
                {
                case DwarfRelocationTarget.Code:
                    relocTable.Entries.Add(new ElfRelocation(reloc.Offset, relocType, (uint)elfContext.CodeSectionSymbolIndex, (long)reloc.Addend));
                    break;

                case DwarfRelocationTarget.DebugString:
                    relocTable.Entries.Add(new ElfRelocation(reloc.Offset, relocType, (uint)elfContext.StringTableSymbolIndex, (long)reloc.Addend));
                    break;

                case DwarfRelocationTarget.DebugAbbrev:
                    relocTable.Entries.Add(new ElfRelocation(reloc.Offset, relocType, (uint)elfContext.AbbreviationTableSymbolIndex, (long)reloc.Addend));
                    break;

                case DwarfRelocationTarget.DebugInfo:
                    relocTable.Entries.Add(new ElfRelocation(reloc.Offset, relocType, (uint)elfContext.InfoSectionSymbolIndex, (long)reloc.Addend));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Beispiel #2
0
        public static void CopyRelocationsTo(this DwarfRelocatableSection dwarfRelocSection, DwarfElfContext elfContext, ElfRelocationTable relocTable)
        {
            if (elfContext == null)
            {
                throw new ArgumentNullException(nameof(elfContext));
            }
            if (relocTable == null)
            {
                throw new ArgumentNullException(nameof(relocTable));
            }

            switch (elfContext.Elf.Arch.Value)
            {
            case ElfArch.X86_64:
                CopyRelocationsX86_64(dwarfRelocSection, elfContext, relocTable);
                break;

            default:
                throw new NotImplementedException($"The relocation for architecture {relocTable.Parent.Arch} is not supported/implemented.");
            }
        }
Beispiel #3
0
        public static void PrintRelocations(this DwarfRelocatableSection relocSection, TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer.WriteLine();
            if (relocSection.Relocations.Count == 0)
            {
                writer.WriteLine("  There are no relocations in this section.");
                return;
            }

            writer.WriteLine($"  Relocations of this section contains {(relocSection.Relocations.Count > 1 ? $"{relocSection.Relocations.Count} entries" : "1 entry")}:");
            writer.WriteLine();
            writer.WriteLine("    Offset             Target               Size   Addend");
            foreach (var reloc in relocSection.Relocations)
            {
                writer.WriteLine($"{reloc.Offset:x16}   {reloc.Target,-24} {(uint)reloc.Size,-6} {reloc.Addend:x}");
            }
        }