pub struct LdCache {
pub old_format: Option<OldCache>,
pub new_format: Option<NewCache>,
pub string_table: Vec<u8>,
pub string_table_offset: usize,
}Expand description
The main cache structure representing a parsed ld.so.cache file.
This structure can contain either the old format, new format, or both. When both formats are present, the new format takes precedence for library lookups.
§Fields
old_format- Legacy cache format data (ld.so-1.7.0)new_format- Modern glibc cache format with hardware capabilitiesstring_table- Raw bytes containing null-terminated library names and pathsstring_table_offset- Absolute file offset where the string table begins (for new format)
§Examples
use ld_so_cache::parsers::parse_ld_cache;
let data = fs::read("/etc/ld.so.cache")?;
let cache = parse_ld_cache(&data)?;
// Check which formats are present
if cache.old_format.is_some() {
println!("Old format present");
}
if cache.new_format.is_some() {
println!("New format present");
}Fields§
§old_format: Option<OldCache>§new_format: Option<NewCache>§string_table: Vec<u8>§string_table_offset: usizeImplementations§
Source§impl LdCache
impl LdCache
Sourcepub fn get_entries(&self) -> Result<Vec<CacheEntry>, CacheError>
pub fn get_entries(&self) -> Result<Vec<CacheEntry>, CacheError>
Extracts all library entries from the cache.
This method processes both old and new format entries, converting raw
cache data into user-friendly CacheEntry structures. If both formats
are present, only the new format entries are returned as they include
hardware capability information.
§Returns
A vector of CacheEntry structures containing library names, paths,
flags, and hardware capabilities (when available).
§Errors
CacheError::InvalidStringOffset- String offset points outside the string tableCacheError::ParseError- String contains invalid UTF-8 characters
Invalid entries are silently skipped rather than causing the entire operation to fail.
§Example
let entries = cache.get_entries()?;
for entry in entries {
println!("{} -> {}", entry.library_name, entry.library_path);
if entry.flags & 1 != 0 {
println!(" ELF library");
}
if let Some(hwcap) = entry.hwcap {
println!(" Hardware capabilities: 0x{:016x}", hwcap);
}
}Trait Implementations§
impl StructuralPartialEq for LdCache
Auto Trait Implementations§
impl Freeze for LdCache
impl RefUnwindSafe for LdCache
impl Send for LdCache
impl Sync for LdCache
impl Unpin for LdCache
impl UnwindSafe for LdCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more