#elf #note #notes

no-std noted

Library for creating ELF notes

2 releases (1 stable)

1.0.0 Sep 21, 2021
0.1.0 Aug 31, 2021

#808 in Embedded development

Download history 1977/week @ 2022-11-27 1747/week @ 2022-12-04 3502/week @ 2022-12-11 5561/week @ 2022-12-18 806/week @ 2022-12-25 1575/week @ 2023-01-01 4931/week @ 2023-01-08 2893/week @ 2023-01-15 3721/week @ 2023-01-22 1745/week @ 2023-01-29 1421/week @ 2023-02-05 837/week @ 2023-02-12 1134/week @ 2023-02-19 1713/week @ 2023-02-26 1122/week @ 2023-03-05 1019/week @ 2023-03-12

5,052 downloads per month
Used in 2 crates

Apache-2.0

8KB
55 lines

Workflow Status Average time to resolve an issue Percentage of issues still open Maintenance

noted

This crate implements a macro that defines ELF notes for communicating information to the tooling that processes ELF notes.

Be sure to check out the note section in the ELF specification.

Example

use noted::noted;
use goblin::Object;

noted! {
    section = ".note.noted";

    static FOO<"xxxxxxxx", 1>: [u8; 4] = [1, 2, 3, 4];
    static BAR<"yyyyy", 2>: u64 = 7;
    static BAZ<"zzz", 3>: u32 = 8;
}

fn main() {
    // Load this binary
    let path = std::env::current_exe().unwrap();
    let buffer = std::fs::read(path).unwrap();
    let elf = match Object::parse(&buffer).unwrap() {
        Object::Elf(elf) => elf,
        _ => panic!("unsupported type"),
    };

    // Parse and sort the notes in the specified section
    let mut notes: Vec<_> = elf
        .iter_note_sections(&buffer, Some(".note.noted"))
        .unwrap()
        .map(|x| x.unwrap())
        .collect();
    notes.sort_unstable_by_key(|x| x.n_type);

    eprintln!("{:?}", notes);

    // Validate all the notes
    assert_eq!(3, notes.len());

    assert_eq!(notes[0].n_type, 1);
    assert_eq!(notes[1].n_type, 2);
    assert_eq!(notes[2].n_type, 3);

    assert_eq!(notes[0].name, "xxxxxxxx");
    assert_eq!(notes[1].name, "yyyyy");
    assert_eq!(notes[2].name, "zzz");

    assert_eq!(notes[0].desc, &[1, 2, 3, 4]);
    assert_eq!(notes[1].desc, &7u64.to_ne_bytes());
    assert_eq!(notes[2].desc, &8u32.to_ne_bytes());
}

License: Apache-2.0

No runtime deps