Package ghidra.app.util.bin.format.elf

# Class ElfSymbolTable

java.lang.Object
ghidra.app.util.bin.format.elf.ElfSymbolTable

All Implemented Interfaces:
  `ElfFileSection`, `StructConverter`

public class ElfSymbolTable extends Object implements ElfFileSection
A container class to hold ELF symbols.

- ## Field Summary

  ### Fields inherited from interface ghidra.app.util.bin.StructConverter

  `ASCII, BYTE, DWORD, IBO32, IBO64, POINTER, QWORD, SLEB128, STRING, ULEB128, UTF16, UTF8, VOID, WORD`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ElfSymbolTable(BinaryReader reader, ElfHeader header, ElfSectionHeader symbolTableSection, long fileOffset, long addrOffset, long length, long entrySize, ElfStringTable stringTable, int[] symbolSectionIndexTable, boolean isDynamic)`
  Construct and parse an Elf symbol table

- ## Method Summary

  Modifier and Type
  Method
  Description
  `long`
  `getAddressOffset()`
  Preferred memory address offset where data should be loaded.
  `int`
  `getEntrySize()`
  Size of each structured entry in bytes
  `int`
  `getExtendedSectionIndex(ElfSymbol sym)`
  Get the extended symbol section index value for the specified ELF symbol which originated from this symbol table.
  `long`
  `getFileOffset()`
  Offset within file where section bytes are specified
  `final String`
  `getFormattedSymbolName(int symbolIndex)`
  Get the formatted ELF symbol name which corresponds to the specified index.
  `ElfSymbol[]`
  `getGlobalSymbols()`
  Returns all of the global symbols.
  `long`
  `getLength()`
  Length of file section in bytes
  `String[]`
  `getSourceFiles()`
  Returns all of the sources file names.
  `ElfStringTable`
  `getStringTable()`
  Returns the associated string table section.
  `final ElfSymbol`
  `getSymbol(int symbolIndex)`
  Get the Elf symbol which corresponds to the specified index.
  `ElfSymbol`
  `getSymbolAt(long addr)`
  Returns the symbol at the specified address.
  `int`
  `getSymbolCount()`
  `int`
  `getSymbolIndex(ElfSymbol symbol)`
  Returns the index of the specified symbol in this symbol table.
  `final String`
  `getSymbolName(int symbolIndex)`
  Get the ELF symbol name which corresponds to the specified index.
  `ElfSymbol[]`
  `getSymbols()`
  Returns all of the symbols defined in this symbol table.
  `ElfSectionHeader`
  `getTableSectionHeader()`
  Get the section header which corresponds to this table, or null if only associated with a dynamic table entry
  `boolean`
  `isDynamic()`
  Returns true if this is the dynamic symbol table
  `DataType`
  `toDataType()`
  Returns a structure datatype representing the contents of the implementor of this interface.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ElfSymbolTable

    public ElfSymbolTable(BinaryReader reader, ElfHeader header, ElfSectionHeader symbolTableSection, long fileOffset, long addrOffset, long length, long entrySize, ElfStringTable stringTable, int[] symbolSectionIndexTable, boolean isDynamic) throws IOException
    Construct and parse an Elf symbol table
    Parameters:
      `reader` - byte reader (reader is not retained and position is unaffected)
      `header` - elf header
      `symbolTableSection` - string table section header or null if associated with a dynamic table entry
      `fileOffset` - symbol table file offset
      `addrOffset` - memory address of symbol table (should already be adjusted for prelink)
      `length` - length of symbol table in bytes of -1 if unknown
      `entrySize` - size of each symbol entry in bytes
      `stringTable` - associated string table
      `symbolSectionIndexTable` - extended symbol section index table (may be null, used when symbol `st_shndx == SHN_XINDEX`). See `ElfSymbol.getExtendedSectionHeaderIndex()`).
      `isDynamic` - true if symbol table is the dynamic symbol table
    Throws:
      `IOException` - if an IO or parse error occurs

- ## Method Details

  - ### isDynamic

    public boolean isDynamic()
    Returns true if this is the dynamic symbol table
    Returns:
      true if this is the dynamic symbol table

  - ### getStringTable

    public ElfStringTable getStringTable()
    Returns the associated string table section.
    Returns:
      the associated string table section

  - ### getSymbolCount

    public int getSymbolCount()
    Returns:
      number of symbols

  - ### getSymbols

    public ElfSymbol[] getSymbols()
    Returns all of the symbols defined in this symbol table.
    Returns:
      all of the symbols defined in this symbol table

  - ### getExtendedSectionIndex

    public int getExtendedSectionIndex(ElfSymbol sym)
    Get the extended symbol section index value for the specified ELF symbol which originated from this symbol table. This section index is provided by an associated SHT_SYMTAB_SHNDX section when the symbols st_shndx == SHN_XINDEX.
    Parameters:
      `sym` - ELF symbol from this symbol table
    Returns:
      associated extended section index value or 0 if not defined.

  - ### getSymbolIndex

    public int getSymbolIndex(ElfSymbol symbol)
    Returns the index of the specified symbol in this symbol table.
    Parameters:
      `symbol` - the symbol
    Returns:
      the index of the specified symbol

  - ### getSymbolAt

    public ElfSymbol getSymbolAt(long addr)
    Returns the symbol at the specified address.
    Parameters:
      `addr` - the symbol address
    Returns:
      the symbol at the specified address

  - ### getSymbol

    public final ElfSymbol getSymbol(int symbolIndex)
    Get the Elf symbol which corresponds to the specified index. Each relocation table may correspond to a specific symbol table to which the specified symbolIndex will be applied.
    Parameters:
      `symbolIndex` - symbol index
    Returns:
      Elf symbol which corresponds to symbol index or null if out of range

  - ### getSymbolName

    public final String getSymbolName(int symbolIndex)
    Get the ELF symbol name which corresponds to the specified index.
    Parameters:
      `symbolIndex` - symbol index
    Returns:
      symbol name which corresponds to symbol index or null if out of range

  - ### getFormattedSymbolName

    public final String getFormattedSymbolName(int symbolIndex)
    Get the formatted ELF symbol name which corresponds to the specified index. If the name is blank or can not be resolved due to a missing string table the literal string <no name> will be returned.
    Parameters:
      `symbolIndex` - symbol index
    Returns:
      formatted symbol name which corresponds to symbol index or the literal string <no name>

  - ### getGlobalSymbols

    public ElfSymbol[] getGlobalSymbols()
    Returns all of the global symbols.
    Returns:
      all of the global symbols

  - ### getSourceFiles

    public String[] getSourceFiles()
    Returns all of the sources file names.
    Returns:
      all of the sources file names

  - ### getLength

    public long getLength()
    Description copied from interface: `ElfFileSection`
    Length of file section in bytes
    Specified by:
      `getLength` in interface `ElfFileSection`
    Returns:
      length of file section in bytes

  - ### getAddressOffset

    public long getAddressOffset()
    Description copied from interface: `ElfFileSection`
    Preferred memory address offset where data should be loaded. The returned offset will already have the prelink adjustment applied, although will not reflect any change in the image base.
    Specified by:
      `getAddressOffset` in interface `ElfFileSection`
    Returns:
      default memory address offset where data should be loaded

  - ### getTableSectionHeader

    public ElfSectionHeader getTableSectionHeader()
    Get the section header which corresponds to this table, or null if only associated with a dynamic table entry
    Returns:
      symbol table section header or null

  - ### getFileOffset

    public long getFileOffset()
    Description copied from interface: `ElfFileSection`
    Offset within file where section bytes are specified
    Specified by:
      `getFileOffset` in interface `ElfFileSection`
    Returns:
      offset within file where section bytes are specified

  - ### getEntrySize

    public int getEntrySize()
    Description copied from interface: `ElfFileSection`
    Size of each structured entry in bytes
    Specified by:
      `getEntrySize` in interface `ElfFileSection`
    Returns:
      entry size or -1 if variable

  - ### toDataType

    public DataType toDataType() throws DuplicateNameException
    Description copied from interface: `StructConverter`
    Returns a structure datatype representing the contents of the implementor of this interface.

    For example, given:

         class A {
             int foo;
             double bar;
         }

    The return value should be a structure data type with two data type components; an INT and a DOUBLE. The structure should contain field names and, if possible, field comments.

    Specified by:
      `toDataType` in interface `StructConverter`
    Returns:
      returns a structure datatype representing the implementor of this interface
    Throws:
      `DuplicateNameException` - when a datatype of the same name already exists
    See Also:
      - `StructureDataType`