Package ghidra.app.util.bin.format.elf
Class ElfSymbol
java.lang.Object
ghidra.app.util.bin.format.elf.ElfSymbol
A class to represent the ELF 32bit and 64bit Symbol data structures.
typedef struct { Elf32_Word st_name; //Symbol name (string tbl index) Elf32_Addr st_value; //Symbol value Elf32_Word st_size; //Symbol size unsigned char st_info; //Symbol type and binding unsigned char st_other; //Symbol visibility Elf32_Section st_shndx; //Section index } Elf32_Sym; typedef struct { Elf64_Word st_name; //Symbol name (string tbl index) unsigned char st_info; //Symbol type and binding unsigned char st_other; //Symbol visibility Elf64_Section st_shndx; //Section index Elf64_Addr st_value; //Symbol value Elf64_Xword st_size; //Symbol size } Elf64_Sym;
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final byte
Global symbols are visible to all object files being combined.static final byte
Symbol is unique in namespace.static final byte
Local symbols are not visible outside the object file containing their definition.static final byte
Weak symbols resemble global symbols, but their definitions have lower precedence.static final byte
An uninitialized common blockstatic final byte
The symbol's name gives the name of the source file associated with the object file.static final byte
The symbol is associated with a function or other executable code.static final byte
The symbol's type is not specified.static final byte
The symbol is associated with a data object, such as a variable, an array, etc.static final byte
Symbol is in support of complex relocation.static final byte
The symbol is associated with a section.static final byte
Symbol is in support of complex relocation (signed value).static final byte
In object files: st_value contains offset from the beginning of the section In DSOs: st_value contains offset in the TLS initialization image (inside of .tdata)static final byte
Default symbol visibility rulesstatic final byte
Sym unavailable in other modulesstatic final byte
Processor specific hidden classstatic final byte
Not preemptible, not exported -
Constructor Summary
ConstructorDescriptionConstruct a new special null symbol which corresponds to symbol index 0.ElfSymbol
(BinaryReader reader, int symbolIndex, ElfSymbolTable symbolTable, ElfHeader header) Construct a normal ElfSymbol. -
Method Summary
Modifier and TypeMethodDescriptionboolean
byte
getBind()
Returns the symbol's binding.int
Get the extended symbol section index value whenst_shndx
(getSectionHeaderIndex()
) has a value of SHN_XINDEX.Returns the formatted string name for this symbol.byte
getInfo()
This member specifies the symbol's type and binding attributes.int
getName()
This member holds an index into the object file's symbol string table, which holds the character representations of the symbol names.Returns the actual string name for this symbol.byte
getOther()
This member currently holds 0 and has no defined meaning.short
Get the raw section index value (st_shndx
) for this symbol.long
getSize()
Many symbols have associated sizes.Get the symbol table containing this symbolint
Get the index of this symbol within the corresponding symbol table.byte
getType()
Returns the symbol's binding.long
getValue()
This member gives the value of the associated symbol.byte
Returns the symbol's visibility.int
hashCode()
boolean
Determine if st_shndx is within the reserved processor-specific index rangevoid
initSymbolName
(BinaryReader reader, ElfStringTable stringTable) Initialize the string name of the symbol.boolean
Returns true if the symbol has an absolute value that will not change because of relocation.boolean
isCommon()
The symbol labels a common block that has not yet been allocated.boolean
Returns true if this is an external symbol.boolean
isFile()
Returns true if this symbol defines a file.boolean
Returns true if this symbol defines a function.boolean
isGlobal()
Returns true if this symbol is global.boolean
isLocal()
Returns true if this symbol is local.boolean
isNoType()
Returns true if this symbol's type is not specified.boolean
isObject()
Returns true if this symbol defines an object.boolean
Returns true if this symbol defines a section.boolean
isTLS()
Returns true if this symbol defines a thread-local symbol.boolean
isWeak()
Returns true if this symbol is weak.toString()
-
Field Details
-
FORMATTED_NO_NAME
- See Also:
-
STB_LOCAL
public static final byte STB_LOCALLocal symbols are not visible outside the object file containing their definition.- See Also:
-
STB_GLOBAL
public static final byte STB_GLOBALGlobal symbols are visible to all object files being combined.- See Also:
-
STB_WEAK
public static final byte STB_WEAKWeak symbols resemble global symbols, but their definitions have lower precedence.- See Also:
-
STB_GNU_UNIQUE
public static final byte STB_GNU_UNIQUESymbol is unique in namespace.- See Also:
-
STT_NOTYPE
public static final byte STT_NOTYPEThe symbol's type is not specified.- See Also:
-
STT_OBJECT
public static final byte STT_OBJECTThe symbol is associated with a data object, such as a variable, an array, etc.- See Also:
-
STT_FUNC
public static final byte STT_FUNCThe symbol is associated with a function or other executable code.- See Also:
-
STT_SECTION
public static final byte STT_SECTIONThe symbol is associated with a section. (Used for relocation and normally have STB_LOCAL binding.)- See Also:
-
STT_FILE
public static final byte STT_FILEThe symbol's name gives the name of the source file associated with the object file.- See Also:
-
STT_COMMON
public static final byte STT_COMMONAn uninitialized common block- See Also:
-
STT_TLS
public static final byte STT_TLSIn object files: st_value contains offset from the beginning of the section In DSOs: st_value contains offset in the TLS initialization image (inside of .tdata)- See Also:
-
STT_RELC
public static final byte STT_RELCSymbol is in support of complex relocation.- See Also:
-
STT_SRELC
public static final byte STT_SRELCSymbol is in support of complex relocation (signed value).- See Also:
-
STV_DEFAULT
public static final byte STV_DEFAULTDefault symbol visibility rules- See Also:
-
STV_INTERNAL
public static final byte STV_INTERNALProcessor specific hidden class- See Also:
-
STV_HIDDEN
public static final byte STV_HIDDENSym unavailable in other modules- See Also:
-
STV_PROTECTED
public static final byte STV_PROTECTEDNot preemptible, not exported- See Also:
-
-
Constructor Details
-
ElfSymbol
public ElfSymbol()Construct a new special null symbol which corresponds to symbol index 0. -
ElfSymbol
public ElfSymbol(BinaryReader reader, int symbolIndex, ElfSymbolTable symbolTable, ElfHeader header) throws IOException Construct a normal ElfSymbol. Warning! the routine initSymbolName() must be called on the symbol later to initialize the string name. This is a performance enhancement.- Parameters:
reader
- to read symbol entry at current position (reader is not retained, position is altered)symbolIndex
- index of the symbol to readsymbolTable
- symbol table to associate the symbol toheader
- ELF header- Throws:
IOException
- if an IO error occurs during parse
-
-
Method Details
-
initSymbolName
Initialize the string name of the symbol. NOTE: This routine MUST be called for each ELFSymbol after the elf symbols have been created. This is done separately from the initial symbol entry read because the string names are in a separate location. If they are read at the same time the reading buffer will jump around and significantly degrade reading performance.- Parameters:
reader
- to read from (position remains unchanged)stringTable
- stringTable to initialize symbol name
-
getSymbolTable
Get the symbol table containing this symbol- Returns:
- symbol table
-
getSymbolTableIndex
public int getSymbolTableIndex()Get the index of this symbol within the corresponding symbol table.- Returns:
- index of this symbol within the corresponding symbol table
-
isNoType
public boolean isNoType()Returns true if this symbol's type is not specified.- Returns:
- true if this symbol's type is not specified
-
hashCode
public int hashCode() -
equals
-
isLocal
public boolean isLocal()Returns true if this symbol is local. Local symbols are not visible outside the object file containing their definition. Local symbols of the same name may exist in multiple files without colliding.- Returns:
- true if this symbol is local
-
isGlobal
public boolean isGlobal()Returns true if this symbol is global. Global symbols are visible to all object files being combined. One object file's definition of a global symbol will satisfy another file's undefined reference to the same global symbol.- Returns:
- true if this symbol is global
-
isWeak
public boolean isWeak()Returns true if this symbol is weak. Weak symbols resemble global symbols, but their definitions have lower precedence.- Returns:
- true if this symbol is weak
-
isExternal
public boolean isExternal()Returns true if this is an external symbol. A symbol is considered external if it's binding is global and it's size is zero.- Returns:
- true if this is an external symbol
-
isSection
public boolean isSection()Returns true if this symbol defines a section.- Returns:
- true if this symbol defines a section
-
isFunction
public boolean isFunction()Returns true if this symbol defines a function.- Returns:
- true if this symbol defines a function
-
isObject
public boolean isObject()Returns true if this symbol defines an object.- Returns:
- true if this symbol defines an object
-
isFile
public boolean isFile()Returns true if this symbol defines a file.- Returns:
- true if this symbol defines a file
-
isTLS
public boolean isTLS()Returns true if this symbol defines a thread-local symbol.- Returns:
- true if this symbol defines a thread-local symbol
-
isAbsolute
public boolean isAbsolute()Returns true if the symbol has an absolute value that will not change because of relocation.- Returns:
- true if the symbol value will not change due to relocation
-
isCommon
public boolean isCommon()The symbol labels a common block that has not yet been allocated. The symbol's value gives alignment constraints, similar to a section's sh_addralign member. That is, the link editor will allocate the storage for the symbol at an address that is a multiple of st_value. The symbol's size tells how many bytes are required.- Returns:
- true if this is a common symbol
-
getInfo
public byte getInfo()This member specifies the symbol's type and binding attributes.- Returns:
- the symbol's type and binding attributes
-
getVisibility
public byte getVisibility()Returns the symbol's visibility. For example, default.- Returns:
- the symbol's visibility
-
getBind
public byte getBind()Returns the symbol's binding. For example, global.- Returns:
- the symbol's binding
-
getType
public byte getType()Returns the symbol's binding. For example, section.- Returns:
- the symbol's binding
-
getName
public int getName()This member holds an index into the object file's symbol string table, which holds the character representations of the symbol names. If the value is non-zero, it represents a string table index that gives the symbol name. Otherwise, the symbol table entry has no name.- Returns:
- the index to the symbol's name
-
getNameAsString
Returns the actual string name for this symbol. The symbol only stores an byte index into the string table where the name string is located.- Returns:
- the actual string name for this symbol (may be null or empty string)
-
getFormattedName
Returns the formatted string name for this symbol. If the name is blank or can not be resolved due to a missing string table the literal string <no name> will be returned. the name string is located.- Returns:
- the actual string name for this symbol or the literal string <no name>
-
getOther
public byte getOther()This member currently holds 0 and has no defined meaning.- Returns:
- no defined meaning
-
getSectionHeaderIndex
public short getSectionHeaderIndex()Get the raw section index value (st_shndx
) for this symbol. Special values (SHN_LORESERVE and higher) must be treated properly. The value SHN_XINDEX indicates that the extended value must be used to obtained the actual section index (seegetExtendedSectionHeaderIndex()
).- Returns:
- the
st_shndx
section index value
-
getExtendedSectionHeaderIndex
public int getExtendedSectionHeaderIndex()Get the extended symbol section index value whenst_shndx
(getSectionHeaderIndex()
) has a value of SHN_XINDEX. This requires a lookup into a table defined by an associated SHT_SYMTAB_SHNDX section.- Returns:
- extended symbol section index value
-
hasProcessorSpecificSymbolSectionIndex
public boolean hasProcessorSpecificSymbolSectionIndex()Determine if st_shndx is within the reserved processor-specific index range- Returns:
- true if specified symbol section index corresponds to a processor specific value in the range SHN_LOPROC..SHN_HIPROC, else false
-
getSize
public long getSize()Many symbols have associated sizes. For example, a data object's size is the number of bytes contained in the object. This member holds 0 if the symbol has no size or an unknown size.- Returns:
- the symbol's size
-
getValue
public long getValue()This member gives the value of the associated symbol. Depending on the context, this may be an absolute value, an address, etc.- Returns:
- the symbol's value
-
toString
-