more things

This commit is contained in:
nora 2023-02-13 20:42:50 +01:00
parent f861e0511d
commit d6daaea999
7 changed files with 114 additions and 24 deletions

View file

@ -125,7 +125,7 @@ pub const EI_PAD: usize = 9; /* Byte index of padding bytes */
pub const EI_NIDENT: usize = 16;
const_group_with_fmt! {
pub struct Type(u16): "type"
pub struct Type(u16): "ET"
pub const ET_NONE = 0;
pub const ET_REL = 1;
@ -135,7 +135,7 @@ const_group_with_fmt! {
}
const_group_with_fmt! {
pub struct Machine(u16): "machine"
pub struct Machine(u16): "EM"
pub const EM_NONE = 0; /* No machine */
pub const EM_X86_64 = 62; /* AMD x86-64 architecture */
@ -207,6 +207,37 @@ pub const SHT_LOSUNW: u32 = 0x6ffffffa; /* Sun-specific low bound. */
pub const SHT_HISUNW: u32 = 0x6fffffff; /* Sun-specific high bound. */
pub const SHT_HIOS: u32 = 0x6fffffff; /* End OS-specific type */
// ------------------
// Program headers
// ------------------
const_group_with_fmt! {
pub struct PhType(u32): "PT"
pub const PT_NULL = 0; /* Program header table entry unused */
pub const PT_LOAD = 1; /* Loadable program segment */
pub const PT_DYNAMIC = 2; /* Dynamic linking information */
pub const PT_INTERP = 3; /* Program interpreter */
pub const PT_NOTE = 4; /* Auxiliary information */
pub const PT_SHLIB = 5; /* Reserved */
pub const PT_PHDR = 6; /* Entry for header table itself */
pub const PT_TLS = 7; /* Thread-local storage segment */
pub const PT_NUM = 8; /* Number of defined types */
pub const PT_GNU_EH_FRAME = 0x6474e550; /* GCC .eh_frame_hdr segment */
pub const PT_GNU_STACK = 0x6474e551; /* Indicates stack executability */
pub const PT_GNU_RELRO = 0x6474e552; /* Read-only after relocation */
pub const PT_GNU_PROPERTY = 0x6474e553; /* GNU property */
pub const PT_SUNWBSS = 0x6ffffffa; /* Sun Specific segment */
pub const PT_SUNWSTACK = 0x6ffffffb; /* Stack segment */
pub const PT_HISUNW = 0x6fffffff;
}
pub const PT_LOOS: u32 = 0x60000000; /* Start of OS-specific */
pub const PT_LOSUNW: u32 = 0x6ffffffa;
pub const PT_HIOS: u32 = 0x6fffffff; /* End of OS-specific */
pub const PT_LOPROC: u32 = 0x70000000; /* Start of processor-specific */
pub const PT_HIPROC: u32 = 0x7fffffff; /* End of processor-specific */
// ------------------
// Symbols
// ------------------

View file

@ -134,7 +134,7 @@ const _: [u8; c::EI_NIDENT] = [0; mem::size_of::<ElfIdent>()];
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
#[repr(C)]
pub struct Phdr {
pub r#type: u32,
pub r#type: c::PhType,
pub flags: u32,
pub offset: Offset,
pub vaddr: Addr,

View file

@ -17,7 +17,7 @@ pub type Result<T> = std::result::Result<T, WriteElfError>;
#[derive(Debug, Clone)]
pub struct ElfWriter {
header: read::ElfHeader,
entry: Entry,
entry: SectionRelativeAbsoluteAddr,
sections_headers: Vec<Section>,
programs_headers: Vec<ProgramHeader>,
}
@ -30,7 +30,7 @@ pub struct Header {
}
#[derive(Debug, Clone)]
pub struct Entry {
pub struct SectionRelativeAbsoluteAddr {
pub section: SectionIdx,
pub rel_offset: Offset,
}
@ -45,9 +45,7 @@ pub struct Section {
}
#[derive(Debug, Clone)]
pub struct ProgramHeader {
pub content: Vec<u8>,
}
pub struct ProgramHeader {}
const SH_STRTAB: usize = 1;
@ -58,15 +56,15 @@ impl ElfWriter {
r#type: header.r#type,
machine: header.machine,
version: 1,
entry: Addr(u64::MAX),
entry: Addr(0x3333333333333333),
phoff: Offset(0),
shoff: Offset(0),
flags: u32::MAX,
ehsize: size_of::<read::ElfHeader> as u16,
ehsize: size_of::<read::ElfHeader>() as u16,
phentsize: size_of::<read::Phdr>() as u16,
phnum: u16::MAX,
phnum: 0x3333,
shentsize: size_of::<read::Shdr>() as u16,
shnum: u16::MAX,
shnum: 0x3333,
// Set below.
shstrndex: SectionIdx(SH_STRTAB as u16),
};
@ -92,7 +90,7 @@ impl ElfWriter {
Self {
header,
entry: Entry {
entry: SectionRelativeAbsoluteAddr {
section: SectionIdx(0),
rel_offset: Offset(0),
},
@ -101,7 +99,7 @@ impl ElfWriter {
}
}
pub fn set_entry(&mut self, entry: Entry) {
pub fn set_entry(&mut self, entry: SectionRelativeAbsoluteAddr) {
self.entry = entry;
}