Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use crate::common::{FromFFI, into_optional};
4 : use std::marker::PhantomData;
5 : use crate::dsc::UUID;
6 : use super::DyldSharedCache;
7 :
8 : /// This class represents a subcache in the case of large/split dyld shared
9 : /// cache.
10 : ///
11 : /// It mirror (and abstracts) the original `dyld_subcache_entry` / `dyld_subcache_entry_v1`
12 : pub struct SubCache<'a> {
13 : ptr: cxx::UniquePtr<ffi::dsc_SubCache>,
14 : _owner: PhantomData<&'a ()>,
15 : }
16 :
17 : impl FromFFI<ffi::dsc_SubCache> for SubCache<'_> {
18 0 : fn from_ffi(ptr: cxx::UniquePtr<ffi::dsc_SubCache>) -> Self {
19 0 : Self {
20 0 : ptr,
21 0 : _owner: PhantomData,
22 0 : }
23 0 : }
24 : }
25 :
26 : impl SubCache<'_> {
27 : /// The uuid of the subcache file
28 0 : pub fn uuid(&self) -> UUID {
29 0 : let vec = Vec::from(self.ptr.uuid().as_slice());
30 0 : assert!(vec.len() == 16);
31 0 : let mut uuid: UUID = [0; 16];
32 0 : for i in 0..16 {
33 0 : uuid[i] = vec[i] as u8;
34 0 : }
35 0 : uuid
36 0 : }
37 :
38 : /// The offset of this subcache from the main cache base address
39 0 : pub fn vm_offset(&self) -> u64 {
40 0 : self.ptr.vm_offset()
41 0 : }
42 :
43 : /// The file name suffix of the subCache file (e.g. `.25.data`, `.03.development`)
44 0 : pub fn suffix(&self) -> String {
45 0 : self.ptr.suffix().to_string()
46 0 : }
47 :
48 : /// The associated DyldSharedCache object for this subcache
49 0 : pub fn cache(&self) -> Option<DyldSharedCache> {
50 0 : into_optional(self.ptr.cache())
51 0 : }
52 : }
53 :
54 : impl std::fmt::Debug for SubCache<'_> {
55 0 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 0 : f.debug_struct("SubCache")
57 0 : .field("uuid", &self.uuid())
58 0 : .field("vm_offset", &self.vm_offset())
59 0 : .field("suffix", &self.suffix())
60 0 : .finish()
61 0 :
62 0 : }
63 : }
|