use crate::common::into_optional;
use lief_ffi as ffi;
use std::ffi::{CString, c_char};
use std::path::Path;
pub mod dyld_shared_cache;
pub mod dylib;
pub mod mapping_info;
pub mod subcache;
pub mod uuid;
mod caching;
#[doc(inline)]
pub use dyld_shared_cache::DyldSharedCache;
#[doc(inline)]
pub use dylib::Dylib;
#[doc(inline)]
pub use subcache::SubCache;
#[doc(inline)]
pub use mapping_info::MappingInfo;
#[doc(inline)]
pub use uuid::UUID;
#[doc(inline)]
pub use caching::enable_cache;
#[doc(inline)]
pub use caching::enable_cache_from_dir;
pub fn load_from_path<P: AsRef<Path>>(path: P, arch: &str) -> Option<DyldSharedCache> {
cxx::let_cxx_string!(__cxx_path = path.as_ref().to_str().unwrap());
cxx::let_cxx_string!(__cxx_arch = arch);
into_optional(ffi::dsc_DyldSharedCache::from_path(
&__cxx_path,
&__cxx_arch,
))
}
pub fn load_from_files<P: AsRef<Path>>(files: &[P]) -> Option<DyldSharedCache> {
let mut c_strings = Vec::new();
let mut c_ptrs = Vec::new();
for file in files.iter() {
let c_str = CString::new(file.as_ref().to_str().unwrap()).unwrap();
c_strings.push(c_str);
let c_ptr = c_strings.last().unwrap().as_ptr() as *const c_char;
c_ptrs.push(c_ptr);
}
let files_ptr: *const *const c_char = c_ptrs.as_ptr();
unsafe {
into_optional(ffi::dsc_DyldSharedCache::from_files(
files_ptr as *const c_char,
c_ptrs.len(),
))
}
}
pub fn is_shared_cache<P: AsRef<Path>>(path: P) -> bool {
cxx::let_cxx_string!(__cxx_s = path.as_ref().to_str().unwrap());
ffi::dsc_Utils::is_shared_cache(&__cxx_s)
}