From 09137d28f0d32beda55576042966c444b698b686 Mon Sep 17 00:00:00 2001 From: Dacian <144836817+dacianpascu06@users.noreply.github.com> Date: Tue, 29 Oct 2024 08:42:31 +0200 Subject: [PATCH] feat(static): add human readable option for Static/Section headers/ Size (#96) --- src/elf/header.rs | 16 +++++++++++++++- src/tui/state.rs | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/elf/header.rs b/src/elf/header.rs index 789236b..5fb2531 100644 --- a/src/elf/header.rs +++ b/src/elf/header.rs @@ -169,6 +169,15 @@ pub struct SectionHeaders { inner: Vec, /// Section names. names: Vec, + /// Human readable format + human_readable: bool, +} + +impl SectionHeaders { + /// Toggles the value for human readable format. + pub fn toggle_readability(&mut self) { + self.human_readable = !self.human_readable; + } } impl<'a> @@ -209,6 +218,7 @@ impl<'a> .unwrap_or_else(|_| String::from("unknown")) }) .collect(), + human_readable: true, }) } } @@ -226,7 +236,11 @@ impl<'a> Property<'a> for SectionHeaders { .to_string(), format!("{:#x}", header.sh_addr), format!("{:#x}", header.sh_offset), - format!("{:#x}", header.sh_size), + if self.human_readable { + format!("{}", ByteSize(header.sh_size)) + } else { + format!("{:#x}", header.sh_size) + }, header.sh_entsize.to_string(), format!("{:#x}", header.sh_flags), header.sh_link.to_string(), diff --git a/src/tui/state.rs b/src/tui/state.rs index c78638f..81707ce 100644 --- a/src/tui/state.rs +++ b/src/tui/state.rs @@ -350,6 +350,7 @@ impl<'a> State<'a> { Command::HumanReadable => { if self.tab == Tab::StaticAnalysis { self.analyzer.elf.program_headers.toggle_readability(); + self.analyzer.elf.section_headers.toggle_readability(); self.handle_tab()?; } }