2个版本 (1个稳定版)

1.0.0 2021年9月21日
0.1.0 2021年8月31日

#525 in 嵌入式开发

Download history 139/week @ 2024-03-11 65/week @ 2024-03-18 88/week @ 2024-03-25 160/week @ 2024-04-01 66/week @ 2024-04-08 74/week @ 2024-04-15 45/week @ 2024-04-22 58/week @ 2024-04-29 11/week @ 2024-05-06 206/week @ 2024-05-13 63/week @ 2024-05-20 9/week @ 2024-05-27 13/week @ 2024-06-03 18/week @ 2024-06-17 75/week @ 2024-06-24

每月107次下载
2 crate 中使用

Apache-2.0

9KB
55

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

noted

此crate实现了一个宏,用于定义ELF注释,以便与处理ELF注释的工具进行信息通信。

请务必查看ELF规范中的注释部分

示例

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());
}

许可证:Apache-2.0

无运行时依赖