use std::ffi::c_void;
use lief_ffi as ffi;
use crate::common::{FromFFI, into_optional};
use crate::macho::Binary;
use crate::runtime;
pub struct Module {
ptr: cxx::UniquePtr<ffi::runtime_osx_Module>,
}
impl FromFFI<ffi::runtime_osx_Module> for Module {
fn from_ffi(ptr: cxx::UniquePtr<ffi::runtime_osx_Module>) -> Self {
Self { ptr }
}
}
impl Module {
pub fn from_handle(handle: *const c_void) -> Option<Module> {
into_optional(ffi::runtime_osx_Module::from_handle(handle as u64))
}
pub fn handle(&self) -> *const c_void {
self.ptr.handle() as *const c_void
}
pub fn dlsym(&self, name: String) -> *const c_void {
cxx::let_cxx_string!(s = name);
self.ptr.dlsym(&s) as *const c_void
}
pub fn parse_from_path(&self) -> Option<Binary> {
into_optional(self.ptr.parse_from_path())
}
pub fn parse_from_memory(&self) -> Option<Binary> {
into_optional(self.ptr.parse_from_memory())
}
}
impl runtime::Module for Module {
#[doc(hidden)]
fn as_generic(&self) -> &ffi::runtime_Module {
self.ptr.as_ref().unwrap().as_ref()
}
}
pub fn dlopen(name: &str) -> Option<Module> {
cxx::let_cxx_string!(s = name);
into_optional(ffi::runtime_osx_dlopen(&s))
}