pelf 0.1.5

A library for parsing/generating/analyzing ELF
Documentation
use crate::{Elf64Addr, Elf64Off, Elf64Word, Elf64Xword};

use super::SectionHeaderType;

/// The elf64 section header.
#[derive(Clone, Default, Debug)]
pub struct Elf64SectionHeader {
    /// section name (string table index)
    pub name: Elf64Word,
    /// section type
    pub section_type: SectionHeaderType,
    /// section flags
    pub flags: Elf64Xword,
    /// section virtual addr at execution
    pub addr: Elf64Addr,
    /// section file offset
    pub offset: Elf64Off,
    /// section size in byte
    pub size: Elf64Xword,
    /// link to another section
    pub link: Elf64Word,
    /// additional section information
    pub info: Elf64Word,
    /// section alignment
    pub addralign: Elf64Xword,
    /// entry size if section holds table
    pub entsize: Elf64Xword,
}

impl From<RawElf64SectionHeader> for Elf64SectionHeader {
    fn from(value: RawElf64SectionHeader) -> Self {
        Self {
            name: value.sh_name,
            section_type: SectionHeaderType::from(value.sh_type),
            flags: value.sh_flags,
            addr: value.sh_addr,
            offset: value.sh_offset,
            size: value.sh_size,
            link: value.sh_link,
            info: value.sh_info,
            addralign: value.sh_addralign,
            entsize: value.sh_entsize,
        }
    }
}

/// The raw representation of elf64 section header.
#[derive(Clone, Default, Debug)]
pub struct RawElf64SectionHeader {
    /// section name (string table index)
    pub sh_name: Elf64Word,
    /// section type
    pub sh_type: Elf64Word,
    /// section flags
    pub sh_flags: Elf64Xword,
    /// section virtual addr at execution
    pub sh_addr: Elf64Addr,
    /// section file offset
    pub sh_offset: Elf64Off,
    /// section size in byte
    pub sh_size: Elf64Xword,
    /// link to another section
    pub sh_link: Elf64Word,
    /// additional section information
    pub sh_info: Elf64Word,
    /// section alignment
    pub sh_addralign: Elf64Xword,
    /// entry size if section holds table
    pub sh_entsize: Elf64Xword,
}