Struct Cache

Source
pub struct Cache {
    pub version: String,
    pub count: u32,
    pub strlen: Option<u32>,
    pub flags: Option<u8>,
    pub extension_offset: Option<u32>,
    pub entries: HashMap<String, Entry>,
    /* private fields */
}

Fields§

§version: String

Cache version as parsed from ld.so.cache (usually 1.1 for the new one)

§count: u32

number of entries in the cache (parsed from the ld.so.cache)

§strlen: Option<u32>

string table length

§flags: Option<u8>

flags for endianness (as of 2.33) values are 0: Not Set 1: Invalid 2: Little 3: Big

§extension_offset: Option<u32>

File offset of the extension directory (as of 2.33)

§entries: HashMap<String, Entry>

list of entries, we use a hashmap as the use case is more to retrieve a path from a lib name

Implementations§

Source§

impl Cache

The cache have two possible interpretations

struct file_entry
{
  int flags;		/* This is 1 for an ELF library.  */
  unsigned int key, value; /* String table indices.  */
};

struct cache_file
{
  char magic[sizeof CACHEMAGIC - 1];
  unsigned int nlibs;
  struct file_entry libs[0];
};

#define CACHEMAGIC_NEW "glibc-ld.so.cache"
#define CACHE_VERSION "1.1"
#define CACHEMAGIC_VERSION_NEW CACHEMAGIC_NEW CACHE_VERSION


struct file_entry_new
{
  int32_t flags;		/* This is 1 for an ELF library.  */
  uint32_t key, value;		/* String table indices.  */
  uint32_t osversion;		/* Required OS version.	 */
  uint64_t hwcap;		/* Hwcap entry.	 */
};

struct cache_file_new
{
  char magic[sizeof CACHEMAGIC_NEW - 1];
  char version[sizeof CACHE_VERSION - 1];
  uint32_t nlibs;		/* Number of entries.  */
  uint32_t len_strings;		/* Size of string table. */
  uint32_t unused[5];		/* Leave space for future extensions and align to 8 byte boundary.  */
  struct file_entry_new libs[0]; /* Entries describing libraries.  */
  /* After this the string table of size len_strings is found.	*/
};

as of 2.33 we know use 2 of the unused

struct cache_file_new {
  char magic[sizeof CACHEMAGIC_NEW - 1];
  char version[sizeof CACHE_VERSION - 1];
  uint32_t nlibs;		/* Number of entries.  */
  uint32_t len_strings;		/* Size of string table. */

  /* flags & cache_file_new_flags_endian_mask is one of the values
     cache_file_new_flags_endian_unset, cache_file_new_flags_endian_invalid,
     cache_file_new_flags_endian_little, cache_file_new_flags_endian_big.

     The remaining bits are unused and should be generated as zero and
     ignored by readers.  */
  uint8_t flags;

  uint8_t padding_unsed[3];	/* Not used, for future extensions.  */

  /* File offset of the extension directory.  See struct
     cache_extension below.  Must be a multiple of four.  */
  uint32_t extension_offset;

  uint32_t unused[3];		/* Leave space for future extensions
				   and align to 8 byte boundary.  */
  struct file_entry_new libs[0]; /* Entries describing libraries.  */
  /* After this the string table of size len_strings is found.	*/
};

As a side note, 5 was chosen because you have len_strings which was added compared to the usual format so (5+1)4=24 bytes or 38 bytes.

Source

pub fn new() -> Result<Cache, CacheError>

Source

pub fn parse(buf: &[u8], endianness: TargetEndian) -> Result<Cache, CacheError>

Source

pub fn str_from_u8_nul_utf8(utf8_src: &[u8]) -> Result<&str, Utf8Error>

Source

pub fn contains(&self, key: &str) -> bool

Utility function, does the contains check on the entries with the full lib name

Source

pub fn get(&self, key: &str) -> Option<&Entry>

Utility function, get the entry based on the full lib name

Source

pub fn get_paths(&self, key: &str) -> Option<Vec<&str>>

Utility function, get the paths of the lib based on the full lib name

Source

pub fn get_path(&self, key: &str) -> Option<&str>

Utility function, get the first path of the lib based on the full lib name

Source

pub fn iter(&self) -> Iter<'_, String, Entry>

Utility function, create an iterator over the entries

Source

pub fn contains_partial(&self, key: &str) -> bool

Utility function, return a boolean indicating if there is a partial match As this utility will iterate over all elements, if you need the element please use get_partial or get_path_partial

Source

pub fn get_partial(&self, key: &str) -> Option<&Entry>

Utility function, return the first element that contains the key inside the full lib name (partial match)

Source

pub fn get_paths_partial(&self, key: &str) -> Option<Vec<&str>>

Utility function, return the first lib paths for which the full lib name contains the key (partial match)

Source

pub fn get_path_partial(&self, key: &str) -> Option<&str>

Utility function, return the first lib path for which the full lib name contains the key (partial match)

Trait Implementations§

Source§

impl Clone for Cache

Source§

fn clone(&self) -> Cache

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Cache

Source§

fn default() -> Cache

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Cache

§

impl RefUnwindSafe for Cache

§

impl Send for Cache

§

impl Sync for Cache

§

impl Unpin for Cache

§

impl UnwindSafe for Cache

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.