pub mod cli;
pub mod model;
pub mod plugin;
pub mod render;
use plugin::{DecoderRegistry, PartitionMeta};
use render::Report;
fn partition_bytes(data: &[u8], entry: &pcf::PartitionEntry, in_bounds: bool) -> Vec<u8> {
if in_bounds && entry.used_bytes > 0 {
let start = entry.start_offset as usize;
let end = (entry.start_offset + entry.used_bytes) as usize;
data[start..end].to_vec()
} else {
Vec::new()
}
}
pub fn build_report(data: &[u8], verify: bool, registry: &DecoderRegistry) -> Report {
let walk = model::walk(data, verify);
let layout = model::build(&walk);
let mut decoded = Vec::new();
for b in &layout.blocks {
for ev in &b.entries {
let e = &ev.entry;
let bytes = partition_bytes(data, e, ev.data_in_bounds);
let label = e.label_string().unwrap_or_default();
let meta = PartitionMeta {
partition_type: e.partition_type,
uid: &e.uid,
label: &label,
};
decoded.push((e.uid, registry.decode(&meta, &bytes)));
}
}
Report { layout, decoded }
}