use crate::common::AsFFI;
use lief_ffi as ffi;
use std::path::Path;
pub mod binary;
pub mod builder;
pub mod dynamic;
pub mod hash;
pub mod header;
pub mod note;
pub mod parser_config;
pub mod relocation;
pub mod section;
pub mod segment;
pub mod symbol;
pub mod symbol_versioning;
#[doc(inline)]
pub use binary::Binary;
#[doc(inline)]
pub use header::Header;
#[doc(inline)]
pub use section::Section;
#[doc(inline)]
pub use segment::Segment;
#[doc(inline)]
pub use symbol::Symbol;
#[doc(inline)]
pub use hash::Sysv as SysvHash;
#[doc(inline)]
pub use hash::Gnu as GnuHash;
#[doc(inline)]
pub use note::Notes;
#[doc(inline)]
pub use dynamic::Entries as DynamicEntries;
#[doc(inline)]
pub use relocation::Relocation;
#[doc(inline)]
pub use symbol_versioning::{
SymbolVersion, SymbolVersionAux, SymbolVersionAuxRequirement, SymbolVersionDefinition,
SymbolVersionRequirement,
};
#[doc(inline)]
pub use parser_config::Config as ParserConfig;
#[allow(non_camel_case_types)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum PhdrReloc {
AUTO,
PIE_SHIFT,
BSS_END,
BINARY_END,
SEGMENT_GAP,
UNKNOWN(u32),
}
impl From<u32> for PhdrReloc {
fn from(value: u32) -> Self {
match value {
0 => PhdrReloc::AUTO,
1 => PhdrReloc::PIE_SHIFT,
2 => PhdrReloc::BSS_END,
3 => PhdrReloc::BINARY_END,
4 => PhdrReloc::SEGMENT_GAP,
_ => PhdrReloc::UNKNOWN(value),
}
}
}
impl From<PhdrReloc> for u32 {
fn from(value: PhdrReloc) -> u32 {
match value {
PhdrReloc::AUTO => 0,
PhdrReloc::PIE_SHIFT => 1,
PhdrReloc::BSS_END => 2,
PhdrReloc::BINARY_END => 3,
PhdrReloc::SEGMENT_GAP => 4,
PhdrReloc::UNKNOWN(v) => v,
}
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum SecInsertPos {
AUTO,
POST_SEGMENT,
POST_SECTION,
UNKNOWN(u32),
}
impl From<u32> for SecInsertPos {
fn from(value: u32) -> Self {
match value {
0 => SecInsertPos::AUTO,
1 => SecInsertPos::POST_SEGMENT,
2 => SecInsertPos::POST_SECTION,
_ => SecInsertPos::UNKNOWN(value),
}
}
}
impl From<SecInsertPos> for u32 {
fn from(value: SecInsertPos) -> u32 {
match value {
SecInsertPos::AUTO => 0,
SecInsertPos::POST_SEGMENT => 1,
SecInsertPos::POST_SECTION => 2,
SecInsertPos::UNKNOWN(v) => v,
}
}
}
pub fn parse<P: AsRef<Path>>(path: P) -> Option<Binary> {
Binary::parse(path)
}
pub fn parse_with_config<P: AsRef<Path>>(path: P, config: &ParserConfig) -> Option<Binary> {
Binary::parse_with_config(path, config)
}
pub fn parse_from_dump<P: AsRef<Path>>(path: P, addr: u64) -> Option<Binary> {
Binary::parse_from_dump(path, addr)
}
pub fn parse_from_dump_with_config<P: AsRef<Path>>(
path: P,
addr: u64,
config: &ParserConfig,
) -> Option<Binary> {
Binary::parse_from_dump_with_config(path, addr, config)
}
pub fn check_layout(binary: &Binary) -> Result<(), String> {
cxx::let_cxx_string!(error = "");
unsafe {
if ffi::ELF_Utils::check_layout(binary.as_ffi(), error.as_mut().get_unchecked_mut()) {
return Ok(());
}
}
Err(error.to_string())
}