Skip to content

Commit

Permalink
elf: Allow parsing SectionHeader from raw bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Lissy committed Jan 25, 2024
1 parent 1b30473 commit 8e53202
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/elf/section_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,19 @@ if_alloc! {
self.sh_addr as usize..(self.sh_addr as usize).saturating_add(self.sh_size as usize)
}
/// Parse `count` section headers from `bytes` at `offset`, using the given `ctx`
/// Assuming this is read from the whole file, it will check offset.
#[cfg(feature = "endian_fd")]
pub fn parse(bytes: &[u8], mut offset: usize, mut count: usize, ctx: Ctx) -> error::Result<Vec<SectionHeader>> {
use scroll::Pread;
// Zero offset means no section headers, not even the null section header.
if offset == 0 {
return Ok(Vec::new());
}
Self::parse_raw(bytes, offset, count, ctx)
}
/// Parse `count` section headers from `bytes` at `offset`, using the given `ctx`
#[cfg(feature = "endian_fd")]
pub fn parse_raw(bytes: &[u8], mut offset: usize, mut count: usize, ctx: Ctx) -> error::Result<Vec<SectionHeader>> {
use scroll::Pread;
let empty_sh = bytes.gread_with::<SectionHeader>(&mut offset, ctx)?;
if count == 0 as usize {
// Zero count means either no section headers if offset is also zero (checked
Expand Down

0 comments on commit 8e53202

Please sign in to comment.