From 28d4c27558b7247d47167c8ee6f8987533a4d82a Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 6 Dec 2021 12:14:05 +0800 Subject: [PATCH] Add realpath to Library --- src/lib.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5fe3bf0..d1ae839 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,10 +25,19 @@ use ld_so_conf::parse_ldsoconf; pub struct Library { /// The path to the library. pub path: PathBuf, + /// The normalized real path to the library. + pub realpath: Option, /// The dependencies of this library. pub needed: Vec, } +impl Library { + /// Is this library found in filesystem. + pub fn found(&self) -> bool { + self.realpath.is_some() + } +} + /// Library dependency tree #[derive(Debug, Clone)] pub struct DependencyTree { @@ -78,11 +87,15 @@ impl DependencyAnalyzer { for dyn_ in &dynamic.dyns { if dyn_.d_tag == DT_RUNPATH { if let Some(runpath) = dynstrtab.get_at(dyn_.d_val as usize) { - runpaths = parse_ld_paths(runpath, path)?; + if let Ok(ld_paths) = parse_ld_paths(runpath, path) { + runpaths = ld_paths; + } } } else if dyn_.d_tag == DT_RPATH { if let Some(rpath) = dynstrtab.get_at(dyn_.d_val as usize) { - rpaths = parse_ld_paths(rpath, path)?; + if let Ok(ld_paths) = parse_ld_paths(rpath, path) { + rpaths = ld_paths; + } } } } @@ -117,6 +130,7 @@ impl DependencyAnalyzer { interp.to_string(), Library { path: PathBuf::from(interp), + realpath: PathBuf::from(interp).canonicalize().ok(), needed: Vec::new(), }, ); @@ -192,13 +206,18 @@ impl DependencyAnalyzer { if compatible_elfs(elf, &lib_elf) { let needed = lib_elf.libraries.iter().map(ToString::to_string).collect(); return Ok(Some(Library { - path: lib_path.canonicalize()?, + path: lib_path.to_path_buf(), + realpath: lib_path.canonicalize().ok(), needed, })); } } } - Ok(None) + Ok(Some(Library { + path: PathBuf::from(lib), + realpath: None, + needed: Vec::new(), + })) } }