Package ghidra.app.util.bin.format.elf
Class ElfSectionHeader
java.lang.Object
ghidra.app.util.bin.format.elf.ElfSectionHeader
- All Implemented Interfaces:
MemoryLoadable,StructConverter
A class to represent the Elf32_Shdr data structure.
typedef int32_t Elf32_Sword;
typedef uint32_t Elf32_Word;
typedef uint32_t Elf32_Addr;
typedef struct {
Elf32_Word sh_name; //Section name (string tbl index)
Elf32_Word sh_type; //Section type
Elf32_Word sh_flags; //Section flags
Elf32_Addr sh_addr; //Section virtual addr at execution
Elf32_Off sh_offset; //Section file offset
Elf32_Word sh_size; //Section size in bytes
Elf32_Word sh_link; //Link to another section
Elf32_Word sh_info; //Additional section information
Elf32_Word sh_addralign; //Section alignment
Elf32_Word sh_entsize; //Entry size if section holds table *
} Elf32_Shdr;
typedef uint32_t Elf64_Word;
typedef uint64_t Elf64_Xword;
typedef uint64_t Elf64_Addr;
typedef uint64_t Elf64_Off;
typedef struct {
Elf64_Word sh_name; //Section name (string tbl index)
Elf64_Word sh_type; //Section type
Elf64_Xword sh_flags; //Section flags
Elf64_Addr sh_addr; //Section virtual addr at execution
Elf64_Off sh_offset; //Section file offset
Elf64_Xword sh_size; //Section size in bytes
Elf64_Word sh_link; //Link to another section
Elf64_Word sh_info; //Additional section information
Elf64_Xword sh_addralign; //Section alignment
Elf64_Xword sh_entsize; //Entry size if section holds table *
} Elf64_Shdr;
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionElfSectionHeader(BinaryReader reader, ElfHeader header) ConstructElfSectionHeader -
Method Summary
Modifier and TypeMethodDescriptionbooleanlongIf the section will appear in the memory image of a process, this member gives the address at which the section's first byte should reside.longSome sections have address alignment constraints.Return ElfHeader associated with this sectionlongSome sections hold a table of fixed-size entries, such as a symbol table.getFilteredLoadInputStream(ElfLoadHelper elfLoadHelper, Address start, long dataLength, BiConsumer<String, Throwable> errorConsumer) Return filtered InputStream for loading a memory block (includes non-loaded OTHER blocks).longgetFlags()Sections support 1-bit flags that describe miscellaneous attributes.intgetInfo()This member holds extra information, whose interpretation depends on the section type.intgetLink()This member holds extra information, whose interpretation depends on the section type.longReturns the logical size of this section, possibly affected by compression.intgetName()An index into the section header string table section, giving the location of a null-terminated string which is the name of this section.Returns the actual string name for this section.longThe byte offset from the beginning of the file to the first byte in the section.Returns raw data input stream associated with this loadable object..Returns the binary reader.longgetSize()This member gives the section's size in bytes.intgetType()This member categorizes the section's contents and semantics.Get header type as string.booleanhasFilteredLoadInputStream(ElfLoadHelper elfLoadHelper, Address start) Determine if the use of input stream decompression or filtering via an extension is neccessary.inthashCode()booleanisAlloc()Returns true if this section is allocated (e.g., SHF_ALLOC is set)booleanReturns true if this section is compressed in a supported manner.booleanReturns true if this section is executable.booleanReturns true if this section header's offset is invalid.booleanReturns true if this section is writable.voidsetAddress(long addr) Sets the start address of this section.Returns a structure datatype representing the contents of the implementor of this interface.toString()
-
Constructor Details
-
ElfSectionHeader
ConstructElfSectionHeader- Parameters:
reader- dedicated reader instance positioned to the start of the program header data. (the reader supplied will be retained and altered).header- ELF header- Throws:
IOException- if an IO error occurs during parse
-
-
Method Details
-
getElfHeader
Return ElfHeader associated with this section- Returns:
- ElfHeader
-
getAddress
public long getAddress()If the section will appear in the memory image of a process, this member gives the address at which the section's first byte should reside. Otherwise, the member contains 0.- Returns:
- the address of the section in memory
-
getAddressAlignment
public long getAddressAlignment()Some sections have address alignment constraints. For example, if a section holds a doubleword, the system must ensure doubleword alignment for the entire section. That is, the value of sh_addr must be congruent to 0, modulo the value of sh_addralign. Currently, only 0 and positive integral powers of two are allowed. Values 0 and 1 mean the section has no alignment constraints.- Returns:
- the section address alignment constraints
-
getEntrySize
public long getEntrySize()Some sections hold a table of fixed-size entries, such as a symbol table. For such a section, this member gives the size in bytes of each entry. The member contains 0 if the section does not hold a table of fixed-size entries.- Returns:
- the section entry size
-
getFlags
public long getFlags()Sections support 1-bit flags that describe miscellaneous attributes. Flag definitions appear aove.- Returns:
- the section flags
-
isWritable
public boolean isWritable()Returns true if this section is writable.- Returns:
- true if this section is writable.
-
isExecutable
public boolean isExecutable()Returns true if this section is executable.- Returns:
- true if this section is executable.
-
isAlloc
public boolean isAlloc()Returns true if this section is allocated (e.g., SHF_ALLOC is set)- Returns:
- true if this section is allocated.
-
isCompressed
public boolean isCompressed()Returns true if this section is compressed in a supported manner. This does NOT include sections that carry compressed data, such as ".zdebuginfo" type sections.- Returns:
- true if the section was compressed and needs to be decompressed, false if normal section
-
getInfo
public int getInfo()This member holds extra information, whose interpretation depends on the section type. If sh_type is SHT_REL or SHT_RELA, then sh_info holds the section header index of the section to which the relocation applies. If sh_type is SHT_SYMTAB or SHT_DYNSYM, then sh_info holds one greater than the symbol table index of the last local symbol (binding STB_LOCAL).- Returns:
- the section header info
-
getLink
public int getLink()This member holds extra information, whose interpretation depends on the section type. If sh_type is SHT_SYMTAB, SHT_DYNSYM, or SHT_DYNAMIC, then sh_link holds the section header table index of its associated string table. If sh_type is SHT_REL, SHT_RELA, or SHT_HASH sh_link holds the section header index of the associated symbol table.- Returns:
- the section header link
-
getName
public int getName()An index into the section header string table section, giving the location of a null-terminated string which is the name of this section.- Returns:
- the index of the section name
-
getNameAsString
Returns the actual string name for this section. The section only stores an byte index into the string table where the name string is located.- Returns:
- the actual string name for this section
-
toString
-
getOffset
public long getOffset()The byte offset from the beginning of the file to the first byte in the section. One section type, SHT_NOBITS described below, occupies no space in the file, and its sh_offset member locates the conceptual placement in the file.- Returns:
- byte offset from the beginning of the file to the first byte in the section
-
isInvalidOffset
public boolean isInvalidOffset()Returns true if this section header's offset is invalid.- Returns:
- true if this section header's offset is invalid
-
getSize
public long getSize()This member gives the section's size in bytes. Unless the section type is SHT_NOBITS, the section occupies sh_size bytes in the file. A section of type SHT_NOBITS may have a non-zero size, but it occupies no space in the file.- Returns:
- the section's size in bytes
-
getLogicalSize
public long getLogicalSize()Returns the logical size of this section, possibly affected by compression.- Returns:
- logical size of this section, see
getSize()
-
hasFilteredLoadInputStream
Description copied from interface:MemoryLoadableDetermine if the use of input stream decompression or filtering via an extension is neccessary. If this method returns true and afiltered streamis required and will prevent the use of a direct mapping to file bytes for affected memory regions.- Specified by:
hasFilteredLoadInputStreamin interfaceMemoryLoadable- Parameters:
elfLoadHelper- ELF load helperstart- memory load address- Returns:
- true if the use of a filtered input stream is required
-
getFilteredLoadInputStream
public InputStream getFilteredLoadInputStream(ElfLoadHelper elfLoadHelper, Address start, long dataLength, BiConsumer<String, Throwable> errorConsumer) throws IOExceptionDescription copied from interface:MemoryLoadableReturn filtered InputStream for loading a memory block (includes non-loaded OTHER blocks). SeeMemoryLoadable.hasFilteredLoadInputStream(ElfLoadHelper, Address).- Specified by:
getFilteredLoadInputStreamin interfaceMemoryLoadable- Parameters:
elfLoadHelper- ELF load helperstart- memory load addressdataLength- the in-memory data length in bytes (actual bytes read from dataInput may be more)errorConsumer- consumer that will accept errors which may occur during stream decompression, if null Msg.error() will be used.- Returns:
- filtered input stream or original input stream
- Throws:
IOException- if error initializing filtered input stream
-
getRawInputStream
Description copied from interface:MemoryLoadableReturns raw data input stream associated with this loadable object..- Specified by:
getRawInputStreamin interfaceMemoryLoadable- Returns:
- raw data input stream associated with this loadable object.
- Throws:
IOException- if error initializing input stream
-
getType
public int getType()This member categorizes the section's contents and semantics.- Returns:
- the section's contents and semantics
-
getTypeAsString
Get header type as string. ElfSectionHeaderType name will be returned if know, otherwise a numeric name of the form "SHT_0x12345678" will be returned.- Returns:
- header type as string
-
getReader
Returns the binary reader.- Returns:
- the binary reader
-
setAddress
public void setAddress(long addr) Sets the start address of this section.- Parameters:
addr- the new start address of this section
-
toDataType
Description copied from interface:StructConverterReturns 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:
toDataTypein interfaceStructConverter- Returns:
- returns a structure datatype representing the implementor of this interface
- See Also:
-
hashCode
public int hashCode() -
equals
-