Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dynamic): sort the shared library list #37

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -45,7 +45,7 @@ pub struct Analyzer<'a> {
/// System calls.
pub system_calls: Vec<Line<'a>>,
/// Library dependencies.
pub dependencies: DependencyTree,
pub dependencies: Vec<(String, String)>,
}

impl Debug for Analyzer<'_> {
Expand All @@ -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,
Expand All @@ -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<Vec<(String, String)>> {
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::<Vec<(String, String)>>();
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<Event>) {
let config = BytesConfig::new(self.file.bytes.to_vec()).with_min_length(self.strings_len);
Expand Down
11 changes: 1 addition & 10 deletions src/tui/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
Expand Down
Loading