Skip to content

Commit

Permalink
Adds Elf64Phdr::file_range().
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Oct 21, 2024
1 parent a8d03ed commit b1b2eda
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/elf_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ pub enum ElfParserError {
}

impl Elf64Phdr {
/// Returns the byte range the section spans in the file.
pub fn file_range(&self) -> Option<Range<usize>> {
(self.p_type == PT_LOAD).then(|| {
let offset = self.p_offset as usize;
offset..offset.saturating_add(self.p_filesz as usize)
})
}

/// Returns the segment virtual address range.
pub fn vm_range(&self) -> Range<Elf64Addr> {
let addr = self.p_vaddr;
Expand Down

0 comments on commit b1b2eda

Please sign in to comment.