azathoth_core/os/linux/
structs.rs

1
2/// Represents the ELF64 file header.
3///
4/// Contains metadata about the ELF executable, including entry point, 
5/// program header table, and section header table offsets.
6#[repr(C)]
7#[derive(Debug)]
8pub struct Elf64Ehdr {
9    /// Identification bytes (magic number, class, data encoding, etc.).
10    pub e_ident: [u8; 16],
11    /// Object file type (e.g., ET_EXEC, ET_DYN).
12    pub e_type: u16,
13    /// Target machine architecture (e.g., EM_X86_64).
14    pub e_machine: u16,
15    /// ELF version.
16    pub e_version: u32,
17    /// Entry point virtual address.
18    pub e_entry: u64,
19    /// File offset of the program header table.
20    pub e_phoff: u64,
21    /// File offset of the section header table.
22    pub e_shoff: u64,
23    /// Processor-specific flags.
24    pub e_flags: u32,
25    /// ELF header size in bytes.
26    pub e_ehsize: u16,
27    /// Size of each program header entry.
28    pub e_phentsize: u16,
29    /// Number of entries in the program header table.
30    pub e_phnum: u16,
31    /// Size of each section header entry.
32    pub e_shentsize: u16,
33    /// Number of entries in the section header table.
34    pub e_shnum: u16,
35    /// Section name string table index.
36    pub e_shstrndx: u16,
37}
38
39/// Represents an ELF64 dynamic table entry.
40///
41/// Used in shared objects and executables to describe dynamic linking information.
42#[repr(C)]
43#[derive(Debug)]
44pub struct Elf64Dyn {
45    /// Dynamic entry type (e.g., DT_NEEDED, DT_SYMTAB).
46    pub d_tag: i64,
47    /// Value associated with the tag (address or integer).
48    pub d_val: u64,
49}
50
51/// Represents an ELF64 relocation entry with addend.
52///
53/// Describes how a symbol or address should be relocated at runtime.
54#[repr(C)]
55#[derive(Debug)]
56pub struct Elf64Rela {
57    /// Location to apply the relocation.
58    pub r_offset: u64,
59    /// Addend constant used in the relocation calculation.
60    pub r_addend: i64,
61    /// Relocation type and symbol index, packed.
62    pub r_info: u64,
63}
64
65/// Represents an ELF64 symbol table entry.
66///
67/// Used to store symbol information such as function and variable names and addresses.
68#[repr(C)]
69#[derive(Debug)]
70pub struct Elf64Sym {
71    /// Index into the string table for the symbol's name.
72    pub st_name: u32,
73    /// Symbol's type and binding attributes.
74    pub st_info: u8,
75    /// Symbol's visibility.
76    pub st_other: u8,
77    /// Section index where the symbol is defined.
78    pub st_shndx: u16,
79    /// Symbol's value or address.
80    pub st_value: u64,
81    /// Size of the symbol in bytes.
82    pub st_size: u64,
83}
84
85/// Represents an ELF64 program header table entry.
86///
87/// Describes a segment of the program to be loaded into memory.
88#[repr(C)]
89#[derive(Debug, Clone)]
90pub struct Elf64Phdr {
91    /// Segment type (e.g., PT_LOAD, PT_DYNAMIC).
92    pub p_type: u32,
93    /// Segment flags (e.g., executable, writable).
94    pub p_flags: u32,
95    /// File offset of the segment.
96    pub p_offset: u64,
97    /// Virtual address where the segment is loaded.
98    pub p_vaddr: u64,
99    /// Physical address (usually ignored on modern systems).
100    pub p_paddr: u64,
101    /// Size of the segment in the file.
102    pub p_filesz: u64,
103    /// Size of the segment in memory.
104    pub p_memsz: u64,
105    /// Alignment constraints for this segment.
106    pub p_align: u64,
107}
108
109/// Represents an ELF64 section header table entry.
110///
111/// Describes individual sections within the ELF file.
112#[repr(C)]
113#[derive(Debug, Clone)]
114pub struct Elf64Shdr {
115    /// Index into the section name string table.
116    pub sh_name: usize,
117    /// Section type (e.g., SHT_PROGBITS, SHT_SYMTAB).
118    pub sh_type: u32,
119    /// Section flags (e.g., SHF_ALLOC, SHF_EXECINSTR).
120    pub sh_flags: u64,
121    /// Virtual address of the section in memory.
122    pub sh_addr: u64,
123    /// File offset of the section.
124    pub sh_offset: u64,
125    /// Size of the section in bytes.
126    pub sh_size: u64,
127    /// Section header table link index.
128    pub sh_link: u32,
129    /// Additional section-specific information.
130    pub sh_info: u32,
131    /// Section alignment constraints.
132    pub sh_addralign: u64,
133    /// Size of entries in the section (if it holds a table).
134    pub sh_entsize: u64,
135}