use crate::formats::pe::PeFile;
use crate::inspect::uki::SectionInfo;
use anyhow::Result;
mod sealed {
pub trait Sealed {}
impl Sealed for crate::formats::pe::PeFile {}
}
pub(crate) trait SectionLookupExt: sealed::Sealed {
fn section_bytes_and_location(&self, name: &str) -> Result<(&[u8], (usize, usize))>;
fn section_info_and_bytes(&self, name: &str) -> Result<(SectionInfo, &[u8])>;
}
impl SectionLookupExt for PeFile {
fn section_bytes_and_location(&self, name: &str) -> Result<(&[u8], (usize, usize))> {
let bytes = self
.section_bytes(name)?
.ok_or_else(|| anyhow::anyhow!("no {name} section found in the UKI"))?;
let (offset, size) = self
.section_info(name)?
.ok_or_else(|| anyhow::anyhow!("Couldn't get {name} offset and size in the UKI"))?;
Ok((bytes, (offset, size)))
}
fn section_info_and_bytes(&self, name: &str) -> Result<(SectionInfo, &[u8])> {
let (bytes, (offset, size)) = self.section_bytes_and_location(name)?;
let sha256 = String::new(); Ok((
SectionInfo {
offset,
size,
sha256,
},
bytes,
))
}
}