Package ghidra.app.util.bin.format.elf
Class ElfSymbol
- java.lang.Object
-
- ghidra.app.util.bin.format.elf.ElfSymbol
-
- All Implemented Interfaces:
ByteArrayConverter
public class ElfSymbol extends java.lang.Object implements ByteArrayConverter
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
Fields Modifier and Type Field Description static byte
STB_GLOBAL
Global symbols are visible to all object files being combined.static byte
STB_GNU_UNIQUE
Symbol is unique in namespace.static byte
STB_LOCAL
Local symbols are not visible outside the object file containing their definition.static byte
STB_WEAK
Weak symbols resemble global symbols, but their definitions have lower precedence.static byte
STT_COMMON
An uninitialized common blockstatic byte
STT_FILE
The symbol's name gives the name of the source file associated with the object file.static byte
STT_FUNC
The symbol is associated with a function or other executable code.static byte
STT_NOTYPE
The symbol's type is not specified.static byte
STT_OBJECT
The symbol is associated with a data object, such as a variable, an array, etc.static byte
STT_RELC
Symbol is in support of complex relocation.static byte
STT_SECTION
The symbol is associated with a section.static byte
STT_SRELC
Symbol is in support of complex relocation (signed value).static byte
STT_TLS
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 byte
STV_DEFAULT
Default symbol visibility rulesstatic byte
STV_HIDDEN
Sym unavailable in other modulesstatic byte
STV_INTERNAL
Processor specific hidden classstatic byte
STV_PROTECTED
Not preemptible, not exported
-
Constructor Summary
Constructors Constructor Description ElfSymbol()
DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ElfSymbol
createElfSymbol(FactoryBundledWithBinaryReader reader, int symbolIndex, ElfSymbolTable symbolTable, ElfStringTable stringTable, ElfHeader header)
static ElfSymbol
createGlobalFunctionSymbol(ElfHeader header, int name, java.lang.String nameAsString, long addr, int symbolIndex, ElfSymbolTable symbolTable)
Creates a new global function symbol.static ElfSymbol
createSectionSymbol32(ElfHeader header, long sectionAddress, short sectionHeaderIndex, java.lang.String name, int symbolIndex, ElfSymbolTable symbolTable)
Creates a new section symbol.boolean
equals(java.lang.Object obj)
byte
getBind()
Returns the symbol's binding.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.java.lang.String
getNameAsString()
Returns the actual string name for this symbol.byte
getOther()
This member currently holds 0 and has no defined meaning.short
getSectionHeaderIndex()
Every symbol table entry is "defined" in relation to some section; this member holds the relevant section header table index.long
getSize()
Many symbols have associated sizes.ElfSymbolTable
getSymbolTable()
Get the symbol table containing this symbolint
getSymbolTableIndex()
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
getVisibility()
Returns the symbol's visibility.int
hashCode()
boolean
isAbsolute()
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
isExternal()
Returns true if this is an external symbol.boolean
isFile()
Returns true if this symbol defines a file.boolean
isFunction()
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
isSection()
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.void
setValue(long value)
Sets the value of this symbol.byte[]
toBytes(DataConverter dc)
Returns a byte array representing this implementor of this interface.java.lang.String
toString()
-
-
-
Field Detail
-
STB_LOCAL
public static final byte STB_LOCAL
Local symbols are not visible outside the object file containing their definition.- See Also:
- Constant Field Values
-
STB_GLOBAL
public static final byte STB_GLOBAL
Global symbols are visible to all object files being combined.- See Also:
- Constant Field Values
-
STB_WEAK
public static final byte STB_WEAK
Weak symbols resemble global symbols, but their definitions have lower precedence.- See Also:
- Constant Field Values
-
STB_GNU_UNIQUE
public static final byte STB_GNU_UNIQUE
Symbol is unique in namespace.- See Also:
- Constant Field Values
-
STT_NOTYPE
public static final byte STT_NOTYPE
The symbol's type is not specified.- See Also:
- Constant Field Values
-
STT_OBJECT
public static final byte STT_OBJECT
The symbol is associated with a data object, such as a variable, an array, etc.- See Also:
- Constant Field Values
-
STT_FUNC
public static final byte STT_FUNC
The symbol is associated with a function or other executable code.- See Also:
- Constant Field Values
-
STT_SECTION
public static final byte STT_SECTION
The symbol is associated with a section. (Used for relocation and normally have STB_LOCAL binding.)- See Also:
- Constant Field Values
-
STT_FILE
public static final byte STT_FILE
The symbol's name gives the name of the source file associated with the object file.- See Also:
- Constant Field Values
-
STT_COMMON
public static final byte STT_COMMON
An uninitialized common block- See Also:
- Constant Field Values
-
STT_TLS
public static final byte STT_TLS
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)- See Also:
- Constant Field Values
-
STT_RELC
public static final byte STT_RELC
Symbol is in support of complex relocation.- See Also:
- Constant Field Values
-
STT_SRELC
public static final byte STT_SRELC
Symbol is in support of complex relocation (signed value).- See Also:
- Constant Field Values
-
STV_DEFAULT
public static final byte STV_DEFAULT
Default symbol visibility rules- See Also:
- Constant Field Values
-
STV_INTERNAL
public static final byte STV_INTERNAL
Processor specific hidden class- See Also:
- Constant Field Values
-
STV_HIDDEN
public static final byte STV_HIDDEN
Sym unavailable in other modules- See Also:
- Constant Field Values
-
STV_PROTECTED
public static final byte STV_PROTECTED
Not preemptible, not exported- See Also:
- Constant Field Values
-
-
Method Detail
-
createElfSymbol
public static ElfSymbol createElfSymbol(FactoryBundledWithBinaryReader reader, int symbolIndex, ElfSymbolTable symbolTable, ElfStringTable stringTable, ElfHeader header) throws java.io.IOException
- Throws:
java.io.IOException
-
createSectionSymbol32
public static ElfSymbol createSectionSymbol32(ElfHeader header, long sectionAddress, short sectionHeaderIndex, java.lang.String name, int symbolIndex, ElfSymbolTable symbolTable)
Creates a new section symbol.- Parameters:
header
- the corresponding ELF headersectionAddress
- the start address of the sectionsectionHeaderIndex
- the index of the section in the section header tablename
- the string name of the sectionsymbolIndex
- index of symbol within corresponding symbol tablesymbolTable
- symbol table- Returns:
- the new section symbol
-
createGlobalFunctionSymbol
public static ElfSymbol createGlobalFunctionSymbol(ElfHeader header, int name, java.lang.String nameAsString, long addr, int symbolIndex, ElfSymbolTable symbolTable)
Creates a new global function symbol.- Parameters:
header
- the corresponding ELF headername
- the byte index of the namenameAsString
- the string name of the sectionaddr
- the address of the functionsymbolIndex
- index of symbol within corresponding symbol tablesymbolTable
- symbol table- Returns:
- the new global function symbol
-
getSymbolTable
public ElfSymbolTable 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()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
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
public java.lang.String 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
-
getOther
public byte getOther()
This member currently holds 0 and has no defined meaning.- Returns:
- no defined meaning
-
getSectionHeaderIndex
public short getSectionHeaderIndex()
Every symbol table entry is "defined" in relation to some section; this member holds the relevant section header table index.- Returns:
- the relevant section header table index
-
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- See Also:
Object.toString()
-
toBytes
public byte[] toBytes(DataConverter dc)
Description copied from interface:ByteArrayConverter
Returns a byte array representing this implementor of this interface.- Specified by:
toBytes
in interfaceByteArrayConverter
- Parameters:
dc
- the data converter to use- Returns:
- a byte array representing this object
- See Also:
ByteArrayConverter.toBytes(ghidra.util.DataConverter)
-
setValue
public void setValue(long value)
Sets the value of this symbol. The value is generally an address.- Parameters:
value
- the new value of the symbol
-
-