示例#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)
            {
                if (Elf64_Sym.TryLoad(rdr, out var sym))
                {
                    //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 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);
            }
            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,
            });
        }
示例#3
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);
        }