pub mod binary;
pub mod binding_info;
pub mod builder;
pub mod commands;
pub mod export_info;
pub mod fat_binary;
pub mod header;
pub mod parser_config;
pub mod relocation;
pub mod section;
pub mod stub;
pub mod symbol;
pub mod thread_local_variables;
use lief_ffi as ffi;
use std::path::Path;
#[doc(inline)]
pub use binary::Binary;
#[doc(inline)]
pub use binding_info::BindingInfo;
#[doc(inline)]
pub use commands::Commands;
#[doc(inline)]
pub use export_info::ExportInfo;
#[doc(inline)]
pub use fat_binary::FatBinary;
#[doc(inline)]
pub use header::Header;
#[doc(inline)]
pub use relocation::Relocation;
#[doc(inline)]
pub use section::Generic;
#[doc(inline)]
pub use section::MachOSection;
#[doc(inline)]
pub use section::Section;
#[doc(inline)]
pub use stub::Stub;
#[doc(inline)]
pub use symbol::Symbol;
#[doc(inline)]
pub use thread_local_variables::ThreadLocalVariables;
use crate::common::AsFFI;
#[doc(inline)]
pub use parser_config::Config as ParserConfig;
pub fn parse<P: AsRef<Path>>(path: P) -> Option<FatBinary> {
FatBinary::parse(path)
}
pub fn parse_with_config<P: AsRef<Path>>(path: P, config: &ParserConfig) -> Option<FatBinary> {
FatBinary::parse_with_config(path, config)
}
pub fn parse_from_dump<P: AsRef<Path>>(path: P, addr: u64) -> Option<FatBinary> {
FatBinary::parse_from_dump(path, addr)
}
pub fn parse_from_dump_with_config<P: AsRef<Path>>(
path: P,
addr: u64,
config: &ParserConfig,
) -> Option<FatBinary> {
FatBinary::parse_from_dump_with_config(path, addr, config)
}
pub fn check_layout(binary: &Binary) -> Result<(), String> {
cxx::let_cxx_string!(error = "");
unsafe {
if ffi::MachO_Utils::check_layout(binary.as_ffi(), error.as_mut().get_unchecked_mut()) {
return Ok(());
}
}
Err(error.to_string())
}
pub fn check_fat_layout(fat: &FatBinary) -> Result<(), String> {
cxx::let_cxx_string!(error = "");
unsafe {
if ffi::MachO_Utils::check_layout_fat(fat.as_ffi(), error.as_mut().get_unchecked_mut()) {
return Ok(());
}
}
Err(error.to_string())
}
pub fn is_fat<P: AsRef<Path>>(path: P) -> bool {
cxx::let_cxx_string!(__cxx_s = path.as_ref().to_str().unwrap().to_string());
ffi::MachO_Utils::is_fat(&__cxx_s)
}
pub fn is_64<P: AsRef<Path>>(path: P) -> bool {
cxx::let_cxx_string!(__cxx_s = path.as_ref().to_str().unwrap().to_string());
ffi::MachO_Utils::is_64(&__cxx_s)
}
#[allow(non_camel_case_types)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MachOType {
MAGIC,
CIGAM,
MAGIC_64,
CIGAM_64,
MAGIC_FAT,
CIGAM_FAT,
NEURAL_MODEL,
UNKNOWN(u32),
}
impl From<u32> for MachOType {
fn from(value: u32) -> Self {
match value {
0xFEEDFACE => MachOType::MAGIC,
0xCEFAEDFE => MachOType::CIGAM,
0xFEEDFACF => MachOType::MAGIC_64,
0xCFFAEDFE => MachOType::CIGAM_64,
0xCAFEBABE => MachOType::MAGIC_FAT,
0xBEBAFECA => MachOType::CIGAM_FAT,
0xBEEFFACE => MachOType::NEURAL_MODEL,
_ => MachOType::UNKNOWN(value),
}
}
}
impl From<MachOType> for u32 {
fn from(value: MachOType) -> u32 {
match value {
MachOType::MAGIC => 0xFEEDFACE,
MachOType::CIGAM => 0xCEFAEDFE,
MachOType::MAGIC_64 => 0xFEEDFACF,
MachOType::CIGAM_64 => 0xCFFAEDFE,
MachOType::MAGIC_FAT => 0xCAFEBABE,
MachOType::CIGAM_FAT => 0xBEBAFECA,
MachOType::NEURAL_MODEL => 0xBEEFFACE,
MachOType::UNKNOWN(v) => v,
}
}
}