Skip to main content

elf/
elf.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! Calculate ELF32 and ELF64 header layouts without reading or writing a file.
6
7mod support;
8
9use binlayout::LayoutError;
10use support::{ElfClass, elf_header};
11
12fn main() -> Result<(), LayoutError> {
13    for class in [ElfClass::Elf32, ElfClass::Elf64] {
14        let header = elf_header(class)?;
15        println!(
16            "{class:?}: size={}, align={}",
17            header.size(),
18            header.align()
19        );
20        for field in header.fields() {
21            println!(
22                "  {:<12} offset={:>2}, size={}",
23                field.name(),
24                field.offset(),
25                field.layout().size()
26            );
27        }
28    }
29    Ok(())
30}