Skip to content

Commit

Permalink
Add realpath to Library
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Dec 6, 2021
1 parent 0a66513 commit 28d4c27
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// The dependencies of this library.
pub needed: Vec<String>,
}

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 {
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -117,6 +130,7 @@ impl DependencyAnalyzer {
interp.to_string(),
Library {
path: PathBuf::from(interp),
realpath: PathBuf::from(interp).canonicalize().ok(),
needed: Vec::new(),
},
);
Expand Down Expand Up @@ -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(),
}))
}
}

Expand Down

0 comments on commit 28d4c27

Please sign in to comment.