pub struct Segment<'data> {
pub delete: bool,
pub p_type: u32,
pub p_flags: u32,
pub p_offset: u64,
pub p_vaddr: u64,
pub p_paddr: u64,
pub p_filesz: u64,
pub p_memsz: u64,
pub p_align: u64,
pub sections: Vec<SectionId>,
/* private fields */
}Expand description
A segment in Segments.
This corresponds to elf::ProgramHeader32 or elf::ProgramHeader64.
Fields§
§delete: boolIgnore this segment when writing the ELF file.
p_type: u32The p_type field in the ELF program header.
One of the PT_* constants.
p_flags: u32The p_flags field in the ELF program header.
A combination of the PF_* constants.
p_offset: u64The p_offset field in the ELF program header.
This is the file offset of the data in the segment. This should correspond to the file offset of the sections that are placed in this segment. Currently there is no support for section data that is not contained in sections.
p_vaddr: u64The p_vaddr field in the ELF program header.
p_paddr: u64The p_paddr field in the ELF program header.
p_filesz: u64The p_filesz field in the ELF program header.
p_memsz: u64The p_memsz field in the ELF program header.
p_align: u64The p_align field in the ELF program header.
sections: Vec<SectionId>The sections contained in this segment.
Implementations§
Source§impl<'data> Segment<'data>
impl<'data> Segment<'data>
Sourcepub fn contains_offset(&self, offset: u64) -> bool
pub fn contains_offset(&self, offset: u64) -> bool
Returns true if the segment contains the given file offset.
Sourcepub fn address_from_offset(&self, offset: u64) -> u64
pub fn address_from_offset(&self, offset: u64) -> u64
Return the address corresponding to the given file offset.
This will return a meaningless value if contains_offset is false.
Sourcepub fn contains_address(&self, address: u64) -> bool
pub fn contains_address(&self, address: u64) -> bool
Returns true if the segment contains the given address.
Sourcepub fn remove_sections(&mut self)
pub fn remove_sections(&mut self)
Remove all sections from the segment, and set its size to zero.
Sourcepub fn append_section(&mut self, section: &mut Section<'_>)
pub fn append_section(&mut self, section: &mut Section<'_>)
Add a section to the segment.
If this is a elf::PT_LOAD segment, then the file offset and address of the
section is changed to be at the end of the segment.
The segment’s file and address ranges are extended to include the section.
This uses the sh_size field of the section, not the size of the section data.
The section’s id is added to the segment’s list of sections.
Sourcepub fn append_section_range(&mut self, section: &Section<'_>)
pub fn append_section_range(&mut self, section: &Section<'_>)
Extend this segment’s file and address ranges to include the given section.
If the segment’s p_memsz is zero, then this signifies that the segment
has no file or address range yet. In this case, the segment’s file and address
ranges are set equal to the section. Otherwise, the segment’s file and address
ranges are extended to include the section.
This uses the sh_size field of the section, not the size of the section data.
Sourcepub fn recalculate_ranges(&mut self, sections: &Sections<'data>)
pub fn recalculate_ranges(&mut self, sections: &Sections<'data>)
Recalculate the file and address ranges of the segment.
Resets the segment’s file and address ranges to zero, and then
calls append_section_range for each section in the segment.