Crates.io | arm-attr |
lib.rs | arm-attr |
version | 0.1.1 |
source | src |
created_at | 2024-06-10 19:36:46.297054 |
updated_at | 2024-06-15 08:45:24.556267 |
description | Reads ARM build attributes of an ELF file |
homepage | |
repository | https://github.com/AetiasHax/arm-attr |
max_upload_size | |
id | 1267509 |
size | 122,890 |
Parses ARM build attributes from ELF files according to the 2023Q3 ARM ABI.
The two examples below show two different methods to read build attributes: iterator (lazy and fast) and struct (eager and slow but correct).
This first example reads the tags directly. It's faster, but:
use arm_attr::{read::Endian, tag::Tag, BuildAttrs};
let data = [/* byte contents of .ARM.attributes */];
let build_attrs = BuildAttrs::new(&data, Endian::Little).unwrap();
for subsection in build_attrs.subsections() {
let subsection = subsection.unwrap();
if subsection.is_aeabi() {
for (_, tag) in subsection.into_public_tag_iter().unwrap() {
match tag {
Tag::CpuName(name) => println!("CPU name: {name}"),
_ => {}
}
}
}
}
This second example collects all tags using into_public_attributes
. It's slower but doesn't suffer from the flaws mentioned
in the first example.
let data = [/* byte contents of .ARM.attributes */];
let build_attrs = BuildAttrs::new(&data, Endian::Little).unwrap();
for subsection in build_attrs.subsections() {
let subsection = subsection.unwrap();
if subsection.is_aeabi() {
let file = subsection.into_public_attributes().unwrap();
if let Some(name) = file.attributes.cpu_name {
println!("CPU name: {name}");
}
for (sections, section) in file.sections {
if let Some(name) = section.attributes.cpu_name {
println!("CPU name in sections {sections:?}: {name}");
}
for (symbols, symbol) in section.symbols {
if let Some(name) = symbol.attributes.cpu_name {
println!("CPU name in symbols {symbols:?} of sections {sections:?}: {name}");
}
}
}
}
}