use crate::Arch;
use crate::BinaryFormat;
#[derive(Clone)]
pub struct Blob {
pub load_address: u64,
pub data: Vec<u8>,
}
impl Blob {
pub fn new(load_address: u64, data: Vec<u8>) -> Self {
Self { load_address, data }
}
pub fn from_slice(load_address: u64, bytes: &[u8]) -> Self {
Self {
load_address,
data: bytes.to_vec(),
}
}
}
impl BinaryFormat for Blob {
fn load_address(&self) -> u64 {
self.load_address
}
fn architecture(&self) -> Arch {
Arch::X86_64
}
fn entry_points(&self) -> Vec<u64> {
vec![self.load_address]
}
fn byte_at(&self, addr: u64) -> Option<u8> {
let offset = addr.checked_sub(self.load_address)? as usize;
self.data.get(offset).copied()
}
fn bytes_at(&self, addr: u64) -> Option<&[u8]> {
let offset = addr.checked_sub(self.load_address)? as usize;
self.data.get(offset..)
}
fn segment_bounds(&self, addr: u64) -> Option<(u64, u64)> {
self.contains(addr).then(|| {
(
self.load_address,
self.load_address + self.data.len() as u64,
)
})
}
fn mapped_regions(&self) -> Vec<(u64, Vec<u8>, bool, bool)> {
vec![(self.load_address, self.data.clone(), true, false)]
}
}