Git Product home page Git Product logo

ld_cache_rs's Introduction

ld_cache_rs

A simple parser for ld.so.cache in rust without any c bindings

Library to parse ld.so.cache according to the numerous format define in glibc This library doesn't use any c bindings or doesn't try to create a structure to match it over the data, it uses plain parsing and thus allow the definition of endianness. As parsing ld.so.cache is useful to get access to the symbol, the parsing is done stringently as well as fastly. If you want to make a dirt cheap parser for ld.so.cache a simple call to strings /etc/ld.so.cache will do.

Usage

You usually want to load the default cache (/etc/ld.so.cache) with Cache::new(), however if you need to load a file and not the default one, we do support that with Cache::parse(buf: &[u8], endianness: TargetEndian) where the endianness is one of the 3 values, Big, Little and Native.

use ldcache_rs::{Cache, CacheError, Entry};
use std::collections::hash_map::Iter;
fn main(){
    /// parse /etc/ld.so.cache with Native Endianness
    let cache:Result<Cache,CacheError>=Cache::new();
    let cache=cache.unwrap();
    /// Utility function, does the contains check on the entries with the full lib name
    let ok:bool=cache.contains("key");
    /// Utility function, get the entry based on the full lib name
    let entry:Option<&Entry>=cache.get("key");
    /// Utility function, get the paths of the lib based on the full lib name
    let paths:Option<Vec<&str>>=cache.get_paths("key");
    /// Utility function, get the first path of the lib based on the full lib name
    let path:Option<&str>=cache.get_path("key");
    /// Utility function, create an iterator over the entries
    let iter:Iter<'_, String, Entry>=cache.iter();
    /// 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
    let ok_partial:bool=cache.contains_partial("key");
    /// Utility function, return the first element that contains the key inside the full lib
    /// name (partial match)
    let entry_partial:Option<&Entry>=cache.get_partial("key");
    /// Utility function, return the first lib paths for which the full lib
    /// name contains the key (partial match)
    let paths_partial:Option<Vec<&str>>=cache.get_paths_partial("key");
    /// Utility function, return the first lib path for which the full lib
    /// name contains the key (partial match)
    let path_partial:Option<&str>=cache.get_path_partial("key");
}

ld_cache_rs's People

Contributors

ektehtris avatar

Stargazers

 avatar LongYinan avatar messense avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.