Package ghidra.app.util.bin.format.elf
Class ElfProgramHeader
java.lang.Object
ghidra.app.util.bin.format.elf.ElfProgramHeader
- All Implemented Interfaces:
MemoryLoadable
,StructConverter
,Comparable<ElfProgramHeader>
public class ElfProgramHeader
extends Object
implements StructConverter, Comparable<ElfProgramHeader>, MemoryLoadable
An executable or shared object file's program header table is an
array of structures, each describing a segment
or other information the system needs to prepare the program for execution.
An object file segment contains one or more sections.
Program headers are meaningful only for executable
and shared object files. A file specifies its
own program header size with the ELF
header's e_phentsize and e_phnum members.
Some entries describe process segments; others give supplementary information and do not contribute to
the process image. Segment entries may appear in any order. Except for PT_LOAD segment
entries which must appear in ascending order, sorted on the p_vaddr member.
typedef struct { Elf32_Word p_type; Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align; } Elf32_Phdr; typedef struct { Elf64_Word p_type; //Segment type Elf64_Word p_flags; //Segment flags Elf64_Off p_offset; //Segment file offset Elf64_Addr p_vaddr; //Segment virtual address Elf64_Addr p_paddr; //Segment physical address Elf64_Xword p_filesz; //Segment size in file Elf64_Xword p_memsz; //Segment size in memory Elf64_Xword p_align; //Segment alignment } Elf64_Phdr;
-
Field Summary
-
Constructor Summary
ConstructorDescriptionElfProgramHeader
(BinaryReader reader, ElfHeader header) ConstructElfProgramHeader
-
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(ElfProgramHeader that) boolean
long
Get the adjusted file load size (i.e., filtered load size) to be loaded into memory block which relates to this program header; it may be zero if no block should be created.long
Get the adjusted memory size in bytes of the memory block which relates to this program header; it may be zero if no block should be created.long
getAlign()
As ''Program Loading'' later in this part describes, loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page size.Get descriptive comment which includes type and descriptionGet header descriptionReturn ElfHeader associated with this program headerlong
This member gives the number of bytes in the file image of the segment; it may be zero.getFilteredLoadInputStream
(ElfLoadHelper elfLoadHelper, Address start, long dataLength, BiConsumer<String, Throwable> errorConsumer) Return filtered InputStream for loading a memory block (includes non-loaded OTHER blocks).int
getFlags()
This member gives flags relevant to the segment.long
Get the unadjusted memory size in bytes specified by this program header; it may be zero.long
This member gives the offset from the beginning of the file at which the first byte of the segment resides.long
getOffset
(long virtualAddress) Compute the file offset associated with the specified loaded virtual address defined by this PT_LOAD program header.long
On systems for which physical addressing is relevant, this member is reserved for the segment's physical address.Returns raw data input stream associated with this loadable object..Returns the binary reader.int
getType()
This member tells what kind of segment this array element describes or how to interpret the array element's information.Get header type as string.long
This member gives the virtual address at which the first byte of the segment resides in memory.boolean
hasFilteredLoadInputStream
(ElfLoadHelper elfLoadHelper, Address start) Determine if the use of input stream decompression or filtering via an extension is neccessary.int
hashCode()
boolean
Returns true if this segment is executable when loadedboolean
Return true if this program header's offset is invalid.boolean
isRead()
Returns true if this segment is readable when loadedboolean
isWrite()
Returns true if this segment is writable when loadedReturns a structure datatype representing the contents of the implementor of this interface.toString()
-
Field Details
-
header
-
-
Constructor Details
-
ElfProgramHeader
ConstructElfProgramHeader
- 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 program header- Returns:
- ElfHeader
-
getTypeAsString
Get header type as string. ElfProgramHeaderType name will be returned if know, otherwise a numeric name of the form "PT_0x12345678" will be returned.- Returns:
- header type as string
-
toString
-
getDescription
Get header description- Returns:
- header description
-
getComment
Get descriptive comment which includes type and description- Returns:
- descriptive comment
-
getAlign
public long getAlign()As ''Program Loading'' later in this part describes, loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page size. This member gives the value to which the segments are aligned in memory and in the file. Values 0 and 1 mean no alignment is required. Otherwise, p_align should be a positive, integral power of 2, and p_vaddr should equal p_offset, modulo p_align.- Returns:
- the segment alignment value
-
getFileSize
public long getFileSize()This member gives the number of bytes in the file image of the segment; it may be zero.- Returns:
- the number of bytes in the file image
-
getFlags
public int getFlags()This member gives flags relevant to the segment. Defined flag values appear below.- Returns:
- the segment flags
-
isRead
public boolean isRead()Returns true if this segment is readable when loaded- Returns:
- true if this segment is readable when loaded
-
isWrite
public boolean isWrite()Returns true if this segment is writable when loaded- Returns:
- true if this segment is writable when loaded
-
isExecute
public boolean isExecute()Returns true if this segment is executable when loaded- Returns:
- true if this segment is executable when loaded
-
getMemorySize
public long getMemorySize()Get the unadjusted memory size in bytes specified by this program header; it may be zero.- Returns:
- the unadjusted memory size in bytes specified by this program header
-
getAdjustedMemorySize
public long getAdjustedMemorySize()Get the adjusted memory size in bytes of the memory block which relates to this program header; it may be zero if no block should be created. The returned value reflects any adjustment the ElfExtension may require based upon the specific processor/language implementation which may require filtering of file bytes as loaded into memory.- Returns:
- the number of bytes in the resulting memory block
-
getAdjustedLoadSize
public long getAdjustedLoadSize()Get the adjusted file load size (i.e., filtered load size) to be loaded into memory block which relates to this program header; it may be zero if no block should be created. The returned value reflects any adjustment the ElfExtension may require based upon the specific processor/language implementation which may require filtering of file bytes as loaded into memory.- Returns:
- the number of bytes to be loaded into the resulting memory block
-
hasFilteredLoadInputStream
Description copied from interface:MemoryLoadable
Determine if the use of input stream decompression or filtering via an extension is neccessary. If this method returns true and afiltered stream
is required and will prevent the use of a direct mapping to file bytes for affected memory regions.- Specified by:
hasFilteredLoadInputStream
in 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:MemoryLoadable
Return filtered InputStream for loading a memory block (includes non-loaded OTHER blocks). SeeMemoryLoadable.hasFilteredLoadInputStream(ElfLoadHelper, Address)
.- Specified by:
getFilteredLoadInputStream
in 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:MemoryLoadable
Returns raw data input stream associated with this loadable object..- Specified by:
getRawInputStream
in interfaceMemoryLoadable
- Returns:
- raw data input stream associated with this loadable object.
- Throws:
IOException
- if error initializing input stream
-
getReader
Returns the binary reader.- Returns:
- the binary reader
-
getOffset
public long getOffset()This member gives the offset from the beginning of the file at which the first byte of the segment resides.- Returns:
- the offset from the beginning of the file
-
isInvalidOffset
public boolean isInvalidOffset()Return true if this program header's offset is invalid.- Returns:
- true if this program header's offset is invalid
-
getOffset
public long getOffset(long virtualAddress) Compute the file offset associated with the specified loaded virtual address defined by this PT_LOAD program header. This can be useful when attempting to locate addresses defined by the PT_DYNAMIC section.- Parameters:
virtualAddress
- a memory address which has already had the PRElink adjustment applied- Returns:
- computed file offset or -1 if virtual address not contained within this header
- See Also:
-
getPhysicalAddress
public long getPhysicalAddress()On systems for which physical addressing is relevant, this member is reserved for the segment's physical address. Because System V ignores physical addressing for application programs, this member has unspecified contents for executable files and shared objects.- Returns:
- the segment's physical address
-
getType
public int getType()This member tells what kind of segment this array element describes or how to interpret the array element's information. Type values and their meanings appear below.- Returns:
- the program header type
-
getVirtualAddress
public long getVirtualAddress()This member gives the virtual address at which the first byte of the segment resides in memory.- Returns:
- the virtual address
-
toDataType
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 interfaceStructConverter
- Returns:
- returns a structure datatype representing the implementor of this interface
- See Also:
-
compareTo
- Specified by:
compareTo
in interfaceComparable<ElfProgramHeader>
-
hashCode
public int hashCode() -
equals
-