diff --git a/src/app.rs b/src/app.rs index 75ed838..61e7688 100644 --- a/src/app.rs +++ b/src/app.rs @@ -7,7 +7,7 @@ use crate::{ use elf::{endian::AnyEndian, ElfBytes}; use heh::app::Application as Heh; use heh::decoder::Encoding; -use lddtree::{DependencyAnalyzer, DependencyTree}; +use lddtree::DependencyAnalyzer; use ratatui::text::Line; use rust_strings::BytesConfig; use std::{ @@ -45,7 +45,7 @@ pub struct Analyzer<'a> { /// System calls. pub system_calls: Vec>, /// Library dependencies. - pub dependencies: DependencyTree, + pub dependencies: Vec<(String, String)>, } impl Debug for Analyzer<'_> { @@ -67,8 +67,8 @@ impl<'a> Analyzer<'a> { let elf = Elf::try_from(elf_bytes)?; let heh = Heh::new(file_info.open_file()?, Encoding::Ascii, 0) .map_err(|e| Error::HexdumpError(e.to_string()))?; - let dependencies = DependencyAnalyzer::default().analyze(file_info.path)?; Ok(Self { + dependencies: Self::extract_libs(&file_info)?, files, file: file_info, elf, @@ -77,10 +77,38 @@ impl<'a> Analyzer<'a> { heh, tracer: TraceData::default(), system_calls: Vec::new(), - dependencies, }) } + /// Extracts the library dependencies. + pub fn extract_libs(file_info: &FileInfo<'a>) -> Result> { + let mut dependencies = DependencyAnalyzer::default() + .analyze(file_info.path)? + .libraries + .clone() + .into_iter() + .map(|(name, lib)| { + ( + name.to_string(), + lib.realpath + .unwrap_or(lib.path) + .to_string_lossy() + .to_string(), + ) + }) + .collect::>(); + dependencies.sort_by(|a, b| { + let lib_condition1 = a.0.starts_with("lib"); + let lib_condition2 = b.0.starts_with("lib"); + match (lib_condition1, lib_condition2) { + (true, false) => std::cmp::Ordering::Less, + (false, true) => std::cmp::Ordering::Greater, + _ => a.0.cmp(&b.0), + } + }); + Ok(dependencies) + } + /// Returns the sequences of printable characters. pub fn extract_strings(&mut self, event_sender: mpsc::Sender) { let config = BytesConfig::new(self.file.bytes.to_vec()).with_min_length(self.strings_len); diff --git a/src/tui/state.rs b/src/tui/state.rs index 6a79902..308802d 100644 --- a/src/tui/state.rs +++ b/src/tui/state.rs @@ -351,18 +351,9 @@ impl<'a> State<'a> { self.list = SelectableList::with_items( self.analyzer .dependencies - .libraries .clone() .into_iter() - .map(|(name, lib)| { - vec![ - name.to_string(), - lib.realpath - .unwrap_or(lib.path) - .to_string_lossy() - .to_string(), - ] - }) + .map(|(name, lib)| vec![name, lib]) .collect(), ); }