pub struct SectionHeader { /* private fields */ }
Expand description
Represents a section in the section table.
Implementations§
Source§impl Header
impl Header
Sourcepub const SIZE_IN_BYTES: u16 = 40u16
pub const SIZE_IN_BYTES: u16 = 40u16
Size of a section header entry
Sourcepub const SHT_PROGBITS: u32 = 1u32
pub const SHT_PROGBITS: u32 = 1u32
Program data
Sourcepub const SHT_SYMTAB: u32 = 2u32
pub const SHT_SYMTAB: u32 = 2u32
Symbol table
Sourcepub const SHT_STRTAB: u32 = 3u32
pub const SHT_STRTAB: u32 = 3u32
String table
Sourcepub const SHT_DYNAMIC: u32 = 6u32
pub const SHT_DYNAMIC: u32 = 6u32
Dynamic linking information
Sourcepub const SHT_NOBITS: u32 = 8u32
pub const SHT_NOBITS: u32 = 8u32
Program space with no data (bss)
Sourcepub const SHT_DYNSYM: u32 = 11u32
pub const SHT_DYNSYM: u32 = 11u32
Dynamic linker symbol table
Sourcepub const SHT_INIT_ARRAY: u32 = 14u32
pub const SHT_INIT_ARRAY: u32 = 14u32
Array of constructors
Sourcepub const SHT_FINI_ARRAY: u32 = 15u32
pub const SHT_FINI_ARRAY: u32 = 15u32
Array of destructors
Sourcepub const SHT_PREINIT_ARRAY: u32 = 16u32
pub const SHT_PREINIT_ARRAY: u32 = 16u32
Array of pre-constructors
Sourcepub const SHT_SYMTAB_SHNDX: u32 = 18u32
pub const SHT_SYMTAB_SHNDX: u32 = 18u32
Extended section indicies
Sourcepub fn new<DS>(loader: &Loader<DS>, idx: u16) -> Result<Self, Error<DS::Error>>where
DS: Source,
pub fn new<DS>(loader: &Loader<DS>, idx: u16) -> Result<Self, Error<DS::Error>>where
DS: Source,
Create a new section header.
Sourcepub fn sh_name_offset(&self) -> u32
pub fn sh_name_offset(&self) -> u32
Return the sh_name_offset
field
Sourcepub fn sh_name<'a, DS: Source>(
&self,
loader: &Loader<DS>,
buffer: &'a mut [u8],
) -> Result<&'a str, Error<DS::Error>>
pub fn sh_name<'a, DS: Source>( &self, loader: &Loader<DS>, buffer: &'a mut [u8], ) -> Result<&'a str, Error<DS::Error>>
Get the string name for this section.
Examples found in repository?
examples/load.rs (line 91)
24fn main() -> Result<(), Error> {
25 let mut args = std::env::args_os();
26 let _example_name = args.next();
27 let filename = args.next().ok_or(Error::MissingArgument)?;
28 let data = std::fs::read(&filename)?;
29 let loader = ldr::Loader::new(&data[..])?;
30
31 println!("Loaded ELF {}", filename.to_string_lossy());
32 println!("Entry Point: 0x{:08x}", loader.e_entry());
33
34 let segment_start_addr = loader.segment_start_offset();
35 let mut total_ram_used = 0;
36 for (idx, ph) in loader.iter_program_headers().enumerate() {
37 let ph = ph.expect("PH loaded OK");
38 let p_type = match ph.p_type() {
39 ldr::ProgramHeader::PT_NULL => "PT_NULL",
40 ldr::ProgramHeader::PT_LOAD => "PT_LOAD",
41 ldr::ProgramHeader::PT_DYNAMIC => "PT_DYNAMIC",
42 ldr::ProgramHeader::PT_INTERP => "PT_INTERP",
43 ldr::ProgramHeader::PT_NOTE => "PT_NOTE",
44 ldr::ProgramHeader::PT_SHLIB => "PT_SHLIB",
45 ldr::ProgramHeader::PT_PHDR => "PT_PHDR",
46 ldr::ProgramHeader::PT_TLS => "PT_TLS",
47 ldr::ProgramHeader::PT_GNU_STACK => "PT_GNU_STACK",
48 _ => "PT_???",
49 };
50
51 let ignored = if ph.p_offset() >= segment_start_addr {
52 "OK"
53 } else {
54 "Ignored"
55 };
56
57 let data_bytes = ph.p_filesz();
58 let zero_bytes = ph.p_memsz() - data_bytes;
59 let load_addr = ph.p_paddr();
60
61 total_ram_used += ph.p_memsz();
62
63 println!("PH {idx:02}: p_type = {p_type:12}, data_bytes=0x{data_bytes:04x}, zero_bytes=0x{zero_bytes:04x}, load_addr=0x{load_addr:08x} ({ignored})");
64 }
65
66 println!("Total RAM used: {total_ram_used} bytes");
67
68 for (idx, sh) in loader.iter_section_headers().enumerate() {
69 let sh = sh.expect("SH loaded OK");
70 let sh_type = match sh.sh_type() {
71 ldr::SectionHeader::SHT_NULL => "SHT_NULL",
72 ldr::SectionHeader::SHT_PROGBITS => "SHT_PROGBITS",
73 ldr::SectionHeader::SHT_SYMTAB => "SHT_SYMTAB",
74 ldr::SectionHeader::SHT_STRTAB => "SHT_STRTAB",
75 ldr::SectionHeader::SHT_RELA => "SHT_RELA",
76 ldr::SectionHeader::SHT_HASH => "SHT_HASH",
77 ldr::SectionHeader::SHT_DYNAMIC => "SHT_DYNAMIC",
78 ldr::SectionHeader::SHT_NOTE => "SHT_NOTE",
79 ldr::SectionHeader::SHT_NOBITS => "SHT_NOBITS",
80 ldr::SectionHeader::SHT_REL => "SHT_REL",
81 ldr::SectionHeader::SHT_DYNSYM => "SHT_DYNSYM",
82 ldr::SectionHeader::SHT_INIT_ARRAY => "SHT_INIT_ARRAY",
83 ldr::SectionHeader::SHT_FINI_ARRAY => "SHT_FINI_ARRAY",
84 ldr::SectionHeader::SHT_PREINIT_ARRAY => "SHT_PREINIT_ARRAY",
85 ldr::SectionHeader::SHT_GROUP => "SHT_GROUP",
86 ldr::SectionHeader::SHT_SYMTAB_SHNDX => "SHT_SYMTAB_SHNDX",
87 _ => "???",
88 };
89
90 let mut buffer = [0u8; 64];
91 let name = sh.sh_name(&loader, &mut buffer).unwrap_or("E_TOO_LONG");
92 println!("SH {idx:02}: {sh:08x?} ({sh_type}, {name:?})");
93 }
94
95 Ok(())
96}
Sourcepub fn sh_type(&self) -> u32
pub fn sh_type(&self) -> u32
Return the sh_type
field
Examples found in repository?
examples/load.rs (line 70)
24fn main() -> Result<(), Error> {
25 let mut args = std::env::args_os();
26 let _example_name = args.next();
27 let filename = args.next().ok_or(Error::MissingArgument)?;
28 let data = std::fs::read(&filename)?;
29 let loader = ldr::Loader::new(&data[..])?;
30
31 println!("Loaded ELF {}", filename.to_string_lossy());
32 println!("Entry Point: 0x{:08x}", loader.e_entry());
33
34 let segment_start_addr = loader.segment_start_offset();
35 let mut total_ram_used = 0;
36 for (idx, ph) in loader.iter_program_headers().enumerate() {
37 let ph = ph.expect("PH loaded OK");
38 let p_type = match ph.p_type() {
39 ldr::ProgramHeader::PT_NULL => "PT_NULL",
40 ldr::ProgramHeader::PT_LOAD => "PT_LOAD",
41 ldr::ProgramHeader::PT_DYNAMIC => "PT_DYNAMIC",
42 ldr::ProgramHeader::PT_INTERP => "PT_INTERP",
43 ldr::ProgramHeader::PT_NOTE => "PT_NOTE",
44 ldr::ProgramHeader::PT_SHLIB => "PT_SHLIB",
45 ldr::ProgramHeader::PT_PHDR => "PT_PHDR",
46 ldr::ProgramHeader::PT_TLS => "PT_TLS",
47 ldr::ProgramHeader::PT_GNU_STACK => "PT_GNU_STACK",
48 _ => "PT_???",
49 };
50
51 let ignored = if ph.p_offset() >= segment_start_addr {
52 "OK"
53 } else {
54 "Ignored"
55 };
56
57 let data_bytes = ph.p_filesz();
58 let zero_bytes = ph.p_memsz() - data_bytes;
59 let load_addr = ph.p_paddr();
60
61 total_ram_used += ph.p_memsz();
62
63 println!("PH {idx:02}: p_type = {p_type:12}, data_bytes=0x{data_bytes:04x}, zero_bytes=0x{zero_bytes:04x}, load_addr=0x{load_addr:08x} ({ignored})");
64 }
65
66 println!("Total RAM used: {total_ram_used} bytes");
67
68 for (idx, sh) in loader.iter_section_headers().enumerate() {
69 let sh = sh.expect("SH loaded OK");
70 let sh_type = match sh.sh_type() {
71 ldr::SectionHeader::SHT_NULL => "SHT_NULL",
72 ldr::SectionHeader::SHT_PROGBITS => "SHT_PROGBITS",
73 ldr::SectionHeader::SHT_SYMTAB => "SHT_SYMTAB",
74 ldr::SectionHeader::SHT_STRTAB => "SHT_STRTAB",
75 ldr::SectionHeader::SHT_RELA => "SHT_RELA",
76 ldr::SectionHeader::SHT_HASH => "SHT_HASH",
77 ldr::SectionHeader::SHT_DYNAMIC => "SHT_DYNAMIC",
78 ldr::SectionHeader::SHT_NOTE => "SHT_NOTE",
79 ldr::SectionHeader::SHT_NOBITS => "SHT_NOBITS",
80 ldr::SectionHeader::SHT_REL => "SHT_REL",
81 ldr::SectionHeader::SHT_DYNSYM => "SHT_DYNSYM",
82 ldr::SectionHeader::SHT_INIT_ARRAY => "SHT_INIT_ARRAY",
83 ldr::SectionHeader::SHT_FINI_ARRAY => "SHT_FINI_ARRAY",
84 ldr::SectionHeader::SHT_PREINIT_ARRAY => "SHT_PREINIT_ARRAY",
85 ldr::SectionHeader::SHT_GROUP => "SHT_GROUP",
86 ldr::SectionHeader::SHT_SYMTAB_SHNDX => "SHT_SYMTAB_SHNDX",
87 _ => "???",
88 };
89
90 let mut buffer = [0u8; 64];
91 let name = sh.sh_name(&loader, &mut buffer).unwrap_or("E_TOO_LONG");
92 println!("SH {idx:02}: {sh:08x?} ({sh_type}, {name:?})");
93 }
94
95 Ok(())
96}
Sourcepub fn sh_addralign(&self) -> u32
pub fn sh_addralign(&self) -> u32
Return the sh_addralign
field
Sourcepub fn sh_entsize(&self) -> u32
pub fn sh_entsize(&self) -> u32
Return the sh_entsize
field
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnwindSafe for Header
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more