class ElfLib
Defined at line 26 of file ../../src/lib/elflib/elflib.h
Public Methods
const Elf64_Ehdr * GetEhdr ()
Returns the ELF header.
Defined at line 49 of file ../../src/lib/elflib/elflib.h
void ~ElfLib ()
Defined at line 161 of file ../../src/lib/elflib/elflib.cc
std::vector<std::string> GetAndClearWarnings ()
ElfLib may notice inconsistencies as it parses the ELF file or address
space, but may be able to continue. In such cases it will log a warning
message internally. This method will retrieve those messages and clear
them from the internal list.
Defined at line 163 of file ../../src/lib/elflib/elflib.h
bool SetDebugData (std::unique_ptr<ElfLib> debug)
Attach a second ElfLib to this one which contains debug info. This second
object will be treated as authoritative on section headers.
Returns true on success. Returns false if either this or the given debug
data already have debug data associated, or if this has sections
associated already.
Defined at line 367 of file ../../src/lib/elflib/elflib.cc
MemoryRegion GetSectionData (const std::string & name)
Get the contents of a section by its name. Return nullptr if there is no
section by that name.
Defined at line 723 of file ../../src/lib/elflib/elflib.cc
MemoryRegion GetSectionData (size_t section)
Get the contents of a section by its index. Return nullptr if the index is
invalid.
Defined at line 657 of file ../../src/lib/elflib/elflib.cc
MemoryRegion GetSectionData (const Elf64_Shdr * header)
Get the contents of the given section header. |header| may be null, in which case an empty
MemoryRegion will be returned, otherwise is assumed to be correct and correspond to the ELF
file passed to |Create|.
Defined at line 678 of file ../../src/lib/elflib/elflib.cc
const std::vector<Elf64_Shdr> & GetSectionHeaders ()
Get a list of all section headers.
Defined at line 525 of file ../../src/lib/elflib/elflib.cc
const std::vector<Elf64_Phdr> & GetSegmentHeaders ()
Get a list of all segement headers.
Defined at line 530 of file ../../src/lib/elflib/elflib.cc
MemoryRegion GetSegmentData (size_t segment)
Get the contents of a segment by its index. Return nullptr if the index is
invalid.
Defined at line 535 of file ../../src/lib/elflib/elflib.cc
std::optional<std::vector<uint8_t>> GetNote (const std::string & name, uint64_t type)
Get a note from the notes section.
Defined at line 571 of file ../../src/lib/elflib/elflib.cc
std::string GetGNUBuildID ()
Get the NT_GNU_BUILD_ID note as a hex string. Return empty string if we
don't have that note.
Defined at line 631 of file ../../src/lib/elflib/elflib.cc
std::optional<std::string> GetSoname ()
Get the DT_SONAME.
Defined at line 648 of file ../../src/lib/elflib/elflib.cc
std::optional<Elf64_Sym> GetSymbol (const std::string & name)
Get a symbol from the symbol table. Return nullptr if there is no such
symbol. Pointer should live as long as the memory accessor.
Defined at line 1176 of file ../../src/lib/elflib/elflib.cc
std::optional<std::map<std::string, Elf64_Sym>> GetAllSymbols ()
Get a map of the symbols in the ".symtab" section and their string names. Returns nullopt if
the symbols could not be loaded. This section may be missing or very small for stripped
binaries, see also GetAllDynamicSymbols().
Defined at line 1186 of file ../../src/lib/elflib/elflib.cc
std::optional<Elf64_Sym> GetDynamicSymbol (const std::string & name)
Get a symbol from the symbol table. Return nullptr if there is no such
symbol. Pointer should live as long as the memory accessor.
Defined at line 1181 of file ../../src/lib/elflib/elflib.cc
std::optional<std::map<std::string, Elf64_Sym>> GetAllDynamicSymbols ()
Get a map of all dynamic symbols and their string names. Returns nullopt if the symbols could
not be loaded.
The ".dynsym" table is normally described as containing a subset of the information (just the
global symbols) in the ".symtab" section. But in a stripped binary, there might be only a
".dynsym" section.
Defined at line 1190 of file ../../src/lib/elflib/elflib.cc
std::optional<std::vector<std::string>> GetSharedObjectDependencies ()
Defined at line 1200 of file ../../src/lib/elflib/elflib.cc
bool ProbeHasDebugInfo ()
Attempt to discern whether this file has debug symbols (otherwise it is
presumably stripped).
There are different types of debug information and a file could contain an
arbitrary subset of it. This function specifically probes for a
".debug_info" section which contains the main DWARF symbol information. But
a file could lack this but still contain certain names or unwind
information. If you need to tell if a file has this other information, a
different probe function should be added for the specific thing you need.
Defined at line 1234 of file ../../src/lib/elflib/elflib.cc
bool ProbeHasProgramBits ()
Attempt to discern whether this file has the actual program contents. It
may not if it is a split debug info file.
Defined at line 1251 of file ../../src/lib/elflib/elflib.cc
std::unique_ptr<ElfLib> Create (FILE * fp, Ownership owned)
Create a new ElfLib object for reading a file. If take_ownership is set to
true, the given handle will be closed when the ElfLib object is destroyed.
Defined at line 258 of file ../../src/lib/elflib/elflib.cc
std::unique_ptr<ElfLib> Create (const std::string & path)
Create a new ElfLib object for reading a file. ElfLib will attempt to open
the file and retain a handle to it until the object is destroyed.
Defined at line 363 of file ../../src/lib/elflib/elflib.cc
std::unique_ptr<ElfLib> Create (const uint8_t * mem, size_t size)
Create a new ElfLib object for accessing an ELF file mapped into memory.
This is expected to be a file, not an address space, and will be addressed
accordingly.
Defined at line 306 of file ../../src/lib/elflib/elflib.cc
std::unique_ptr<ElfLib> Create (std::function<bool (uint64_t, std::vector<uint8_t> *)> fetch, uint64_t load_address, AddressMode address_mode)
Create an ElfLib object for reading ELF structures via a read callback.
The offsets will assume either an ELF file or an ELF mapped address space
depending on the value of the address_mode argument.
Defined at line 333 of file ../../src/lib/elflib/elflib.cc
std::map<std::string, uint64_t> GetPLTOffsets ()
Returns a map from symbol names to the locations of their PLT entries.
Returns an empty map if the data is inaccessible.
Getting this information is architecture-specific and involves reading and
decoding the actual jump table instructions in the .plt section. Once
we've done that decoding we can quickly get relocation indices and then
symbol table mappings.
Defined at line 1012 of file ../../src/lib/elflib/elflib.cc
Enumerations
enum AddressMode
| Name | Value |
|---|---|
| kFile | 0 |
| kProcess | 1 |
How do we expect the ELF structures to be mapped? Are they packed in a
file or mapped as they would be in a running process?
Defined at line 40 of file ../../src/lib/elflib/elflib.h
enum Ownership
| Name | Value |
|---|---|
| kTakeOwnership | 0 |
| kDontTakeOwnership | 1 |
Whether we should take ownership of the FILE handle given to our Create
method.
Defined at line 44 of file ../../src/lib/elflib/elflib.h
Records
Friends
class PltEntryBufferArm
class PltEntryBufferX86