// SPDX-License-Identifier: MIT #pragma once #include #include #include #include #include "Linux/Utils/ELFContainer.h" #include #include #include namespace ELFLoader { class ELFSymbolDatabase final { public: ELFSymbolDatabase(::ELFLoader::ELFContainer *file); ~ELFSymbolDatabase(); uint64_t GetElfBase() const; void MapMemoryRegions(std::function Mapper); void WriteLoadableSections(::ELFLoader::ELFContainer::MemoryWriter Writer); uint64_t DefaultRIP() const; using RangeType = std::pair; ::ELFLoader::ELFSymbol const *GetSymbolInRange(RangeType Address); ::ELFLoader::ELFSymbol const *GetGlobalSymbolInRange(RangeType Address); ::ELFLoader::ELFSymbol const *GetNoWeakSymbolInRange(RangeType Address); void GetInitLocations(fextl::vector *Locations); private: ::ELFLoader::ELFContainer *File; struct ELFInfo { fextl::string Name; ::ELFLoader::ELFContainer* Container; ::ELFLoader::ELFContainer::MemoryLayout CustomLayout; void *ELFBase; uint64_t GuestBase; }; ELFInfo LocalInfo; fextl::vector DynamicELFInfo; fextl::vector InitializationOrder; uint64_t ELFMemorySize{}; bool FixedNoReplace {true}; void *ELFBase{}; fextl::unordered_map NameToELF; fextl::vector LibrarySearchPaths; // Symbols fextl::vector Symbols; using SymbolTableType = fextl::unordered_map; SymbolTableType SymbolMap; SymbolTableType SymbolMapGlobalOnly; SymbolTableType SymbolMapNoWeak; SymbolTableType SymbolMapNoMain; SymbolTableType SymbolMapNoMainNoWeak; fextl::map SymbolMapByAddress; bool FindLibraryFile(fextl::string *Result, const char *Library); void FillLibrarySearchPaths(); void FillMemoryLayouts(uint64_t DefinedBase); void FillInitializationOrder(); void FillSymbols(); void HandleRelocations(); ::ELFLoader::ELFSymbol const *GetSymbolFromTable(RangeType Address, fextl::unordered_map &Table); }; }