Пример #1
0
        public override Dictionary <int, ElfSymbol> LoadSymbolsSection(ElfSection symSection)
        {
            //Debug.Print("Symbols");
            var stringtableSection = symSection.LinkedSection;
            var rdr     = CreateReader(symSection.FileOffset);
            var symbols = new Dictionary <int, ElfSymbol>();

            for (ulong i = 0; i < symSection.Size / symSection.EntrySize; ++i)
            {
                var sym = Elf64_Sym.Load(rdr);
                //Debug.Print("  {0,3} {1,-25} {2,-12} {3,6} {4,-15} {5:X8} {6,9}",
                //    i,
                //    RemoveGlibcSuffix(ReadAsciiString(stringtableSection.FileOffset + sym.st_name)),
                //    (ElfSymbolType)(sym.st_info & 0xF),
                //    sym.st_shndx,
                //    GetSectionName(sym.st_shndx),
                //    sym.st_value,
                //    sym.st_size);
                symbols.Add(
                    (int)i,
                    new ElfSymbol
                {
                    Name         = RemoveModuleSuffix(ReadAsciiString(stringtableSection.FileOffset + sym.st_name)),
                    Type         = (ElfSymbolType)(sym.st_info & 0xF),
                    SectionIndex = sym.st_shndx,
                    Value        = sym.st_value,
                    Size         = sym.st_size,
                });
            }
            return(symbols);
        }
Пример #2
0
 public static Elf64_Sym Load(ImageReader rdr)
 {
     var sym = new Elf64_Sym();
     sym.st_name = rdr.ReadUInt32();
     sym.st_info = rdr.ReadByte();
     sym.st_other = rdr.ReadByte();
     sym.st_shndx = rdr.ReadUInt16();
     sym.st_value = rdr.ReadUInt64();
     sym.st_size = rdr.ReadUInt64();
     return sym;
 }
Пример #3
0
        public static Elf64_Sym Load(ImageReader rdr)
        {
            var sym = new Elf64_Sym();

            sym.st_name  = rdr.ReadUInt32();
            sym.st_info  = rdr.ReadByte();
            sym.st_other = rdr.ReadByte();
            sym.st_shndx = rdr.ReadUInt16();
            sym.st_value = rdr.ReadUInt64();
            sym.st_size  = rdr.ReadUInt64();
            return(sym);
        }
Пример #4
0
        public override ElfSymbol LoadSymbol(ulong offsetSymtab, ulong symbolIndex, ulong entrySize, ulong offsetStringTable)
        {
            var rdr = CreateReader(offsetSymtab + entrySize * symbolIndex);
            var sym = Elf64_Sym.Load(rdr);

            return(new ElfSymbol
            {
                Name = RemoveModuleSuffix(ReadAsciiString(offsetStringTable + sym.st_name)),
                Type = (ElfSymbolType)(sym.st_info & 0xF),
                Bind = sym.st_info >> 4,
                SectionIndex = sym.st_shndx,
                Value = sym.st_value,
                Size = sym.st_size,
            });
        }
Пример #5
0
        public override ElfSymbol?LoadSymbol(ulong offsetSymtab, ulong symbolIndex, ulong entrySize, ulong offsetStringTable)
        {
            var rdr = CreateReader(offsetSymtab + entrySize * symbolIndex);

            if (!Elf64_Sym.TryLoad(rdr, out var sym))
            {
                return(null);
            }
            var name = RemoveModuleSuffix(ReadAsciiString(offsetStringTable + sym.st_name));

            return(new ElfSymbol(name)
            {
                Type = (ElfSymbolType)(sym.st_info & 0xF),
                Bind = (ElfSymbolBinding)(sym.st_info >> 4),
                SectionIndex = sym.st_shndx,
                Value = sym.st_value,
                Size = sym.st_size,
            });
        }
Пример #6
0
 public static bool TryLoad(EndianImageReader rdr, out Elf64_Sym sym)
 {
     sym = new Elf64_Sym();
     if (
         rdr.TryReadUInt32(out sym.st_name) &&
         rdr.TryReadByte(out sym.st_info) &&
         rdr.TryReadByte(out sym.st_other) &&
         rdr.TryReadUInt16(out sym.st_shndx) &&
         rdr.TryReadUInt64(out sym.st_value) &&
         rdr.TryReadUInt64(out sym.st_size))
     {
         return(true);
     }
     else
     {
         sym = null !;
         return(false);
     }
 }
Пример #7
0
        public override Dictionary <int, ElfSymbol> LoadSymbolsSection(ElfSection symSection)
        {
            ElfImageLoader.trace.Inform("== Symbols from {0} ==", symSection.Name);
            var symbols            = new Dictionary <int, ElfSymbol>();
            var stringtableSection = symSection.LinkedSection !;
            var rdr = CreateReader(symSection.FileOffset);

            for (ulong i = 0; i < symSection.Size / symSection.EntrySize; ++i)
            {
                if (!Elf64_Sym.TryLoad(rdr, out var sym))
                {
                    ElfImageLoader.trace.Warn("Unable to load symbol entry {0} from {1}", i, symSection.Name);
                    continue;
                }
                var name = RemoveModuleSuffix(ReadAsciiString(stringtableSection.FileOffset + sym.st_name));
                ElfImageLoader.trace.Verbose("  {0,3} {1,-25} {2,-12} {3,6} {4} {5,-15} {6:X16} {7,9}",
                                             i,
                                             string.IsNullOrWhiteSpace(name) ? "<empty>" : name,
                                             (ElfSymbolType)(sym.st_info & 0xF),
                                             sym.st_shndx,
                                             GetBindingName((ElfSymbolBinding)(sym.st_info >> 4)),
                                             GetSectionName(sym.st_shndx),
                                             sym.st_value,
                                             sym.st_size);

                var esym = new ElfSymbol(name)
                {
                    Type         = (ElfSymbolType)(sym.st_info & 0xF),
                    Bind         = (ElfSymbolBinding)(sym.st_info >> 4),
                    SectionIndex = sym.st_shndx,
                    Value        = sym.st_value,
                    Size         = sym.st_size,
                };
                symbols.Add((int)i, esym);
            }
            return(symbols);
        }