private void LoadELF <T>(ELF <T> elf, bool useVirtualAddress) where T : struct { if (!elf.TryGetSection(".symtab", out var symtabSection)) { return; } var thumb = elf.Machine == ELFSharp.ELF.Machine.ARM; var symtab = (SymbolTable <T>)symtabSection; var elfSymbols = symtab.Entries.Where(x => !armSpecificSymbolNames.Contains(x.Name)).Where(x => !excludedSymbolTypes.Contains(x.Type)) .Where(x => x.PointedSectionIndex != (uint)SpecialSectionIndex.Undefined).Select(x => new Symbol(x, thumb)); InsertSymbols(elfSymbols); EntryPoint = elf.GetEntryPoint(); FirstNotNullSectionAddress = elf.Sections .Where(x => x.Type != SectionType.Null && x.Flags.HasFlag(SectionFlags.Allocatable)) .Select(x => x.GetSectionPhysicalAddress()) .Cast <ulong?>() .Min(); var segments = elf.Segments.Where(x => x.Type == ELFSharp.ELF.Segments.SegmentType.Load).OfType <ELFSharp.ELF.Segments.Segment <T> >(); foreach (var segment in segments) { var loadAddress = useVirtualAddress ? segment.GetSegmentAddress() : segment.GetSegmentPhysicalAddress(); maxLoadAddress = SymbolAddress.Max(maxLoadAddress, loadAddress + segment.GetSegmentSize()); } }
/// <summary> /// Inserts one symbol into the lookup structure. /// </summary> /// <param name="symbol">Symbol.</param> public void InsertSymbol(Symbol symbol) { var symbolToAdd = GetUnique(symbol); symbols.Add(symbolToAdd); symbolsByName.Add(symbol.Name, symbol); maxLoadAddress = SymbolAddress.Max(maxLoadAddress, symbol.End); }
/// <summary> /// Inserts a batch of symbols. /// </summary> /// <param name="symbols">Symbols.</param> public void InsertSymbols(IEnumerable <Symbol> symbols) { var symbolsToAdd = new List <Symbol>(); // deduplicate symbols foreach (var symbol in symbols) { symbolsToAdd.Add(GetUnique(symbol)); } // Add symbols to name map foreach (var symbolToAdd in symbolsToAdd) { AddSymbolToNameLookup(symbolToAdd); maxLoadAddress = SymbolAddress.Max(maxLoadAddress, symbolToAdd.End); } // Add symbols to interval set this.symbols.Add(symbolsToAdd); }