1use crate::Arch;
2
3use crate::BinaryFormat;
4
5#[derive(Clone)]
13pub struct Blob {
14 pub load_address: u64,
15 pub data: Vec<u8>,
16}
17
18impl Blob {
19 pub fn new(load_address: u64, data: Vec<u8>) -> Self {
20 Self { load_address, data }
21 }
22
23 pub fn from_slice(load_address: u64, bytes: &[u8]) -> Self {
25 Self {
26 load_address,
27 data: bytes.to_vec(),
28 }
29 }
30}
31
32impl BinaryFormat for Blob {
33 fn load_address(&self) -> u64 {
34 self.load_address
35 }
36
37 fn architecture(&self) -> Arch {
38 Arch::X86_64
40 }
41
42 fn entry_points(&self) -> Vec<u64> {
44 vec![self.load_address]
45 }
46
47 fn byte_at(&self, addr: u64) -> Option<u8> {
48 let offset = addr.checked_sub(self.load_address)? as usize;
49 self.data.get(offset).copied()
50 }
51
52 fn bytes_at(&self, addr: u64) -> Option<&[u8]> {
53 let offset = addr.checked_sub(self.load_address)? as usize;
54 self.data.get(offset..)
55 }
56
57 fn segment_bounds(&self, addr: u64) -> Option<(u64, u64)> {
58 self.contains(addr).then(|| {
59 (
60 self.load_address,
61 self.load_address + self.data.len() as u64,
62 )
63 })
64 }
65
66 fn mapped_regions(&self) -> Vec<(u64, Vec<u8>, bool, bool)> {
69 vec![(self.load_address, self.data.clone(), true, false)]
70 }
71}