use bytemuck::{Pod, Zeroable};
use crate::{
elf::constants::STV_MASK,
endian::{I64, U16, U32, U64},
};
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Ehdr64 {
pub e_ident: [u8; 16],
pub e_type: U16,
pub e_machine: U16,
pub e_version: U32,
pub e_entry: U64,
pub e_phoff: U64,
pub e_shoff: U64,
pub e_flags: U32,
pub e_ehsize: U16,
pub e_phentsize: U16,
pub e_phnum: U16,
pub e_shentsize: U16,
pub e_shnum: U16,
pub e_shstrndx: U16,
}
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Shdr64 {
pub sh_name: U32,
pub sh_type: U32,
pub sh_flags: U64,
pub sh_addr: U64,
pub sh_offset: U64,
pub sh_size: U64,
pub sh_link: U32,
pub sh_info: U32,
pub sh_addralign: U64,
pub sh_entsize: U64,
}
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Phdr64 {
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,
}
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Sym64 {
pub st_name: U32,
pub st_info: u8,
pub st_other: u8,
pub st_shndx: U16,
pub st_value: U64,
pub st_size: U64,
}
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Rela64 {
pub r_offset: U64,
pub r_info: U64,
pub r_addend: I64,
}
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Dyn64 {
pub d_tag: I64,
pub d_un: U64,
}
impl Rela64 {
#[allow(clippy::cast_possible_truncation)]
pub const fn sym(&self) -> u32 {
(self.r_info.get() >> 32) as u32
}
#[allow(clippy::cast_possible_truncation)]
pub const fn r_type(&self) -> u32 {
(self.r_info.get() & 0xffff_ffff) as u32
}
}
impl Sym64 {
pub const fn bind(&self) -> u8 {
self.st_info >> 4
}
pub const fn type_(&self) -> u8 {
self.st_info & 0x0f
}
pub const fn visibility(&self) -> u8 {
self.st_other & STV_MASK
}
}
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Verneed64 {
pub vn_version: U16,
pub vn_cnt: U16,
pub vn_file: U32,
pub vn_aux: U32,
pub vn_next: U32,
}
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Vernaux64 {
pub vna_hash: U32,
pub vna_flags: U16,
pub vna_other: U16,
pub vna_name: U32,
pub vna_next: U32,
}
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Verdef64 {
pub vd_version: U16,
pub vd_flags: U16,
pub vd_ndx: U16,
pub vd_cnt: U16,
pub vd_hash: U32,
pub vd_aux: U32,
pub vd_next: U32,
}
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Verdaux64 {
pub vda_name: U32,
pub vda_next: U32,
}