Skip to content

Commit 09137d2

Browse files
feat(static): add human readable option for Static/Section headers/ Size (#96)
1 parent 419feae commit 09137d2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/elf/header.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ pub struct SectionHeaders {
169169
inner: Vec<SectionHeader>,
170170
/// Section names.
171171
names: Vec<String>,
172+
/// Human readable format
173+
human_readable: bool,
174+
}
175+
176+
impl SectionHeaders {
177+
/// Toggles the value for human readable format.
178+
pub fn toggle_readability(&mut self) {
179+
self.human_readable = !self.human_readable;
180+
}
172181
}
173182

174183
impl<'a>
@@ -209,6 +218,7 @@ impl<'a>
209218
.unwrap_or_else(|_| String::from("unknown"))
210219
})
211220
.collect(),
221+
human_readable: true,
212222
})
213223
}
214224
}
@@ -226,7 +236,11 @@ impl<'a> Property<'a> for SectionHeaders {
226236
.to_string(),
227237
format!("{:#x}", header.sh_addr),
228238
format!("{:#x}", header.sh_offset),
229-
format!("{:#x}", header.sh_size),
239+
if self.human_readable {
240+
format!("{}", ByteSize(header.sh_size))
241+
} else {
242+
format!("{:#x}", header.sh_size)
243+
},
230244
header.sh_entsize.to_string(),
231245
format!("{:#x}", header.sh_flags),
232246
header.sh_link.to_string(),

src/tui/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ impl<'a> State<'a> {
350350
Command::HumanReadable => {
351351
if self.tab == Tab::StaticAnalysis {
352352
self.analyzer.elf.program_headers.toggle_readability();
353+
self.analyzer.elf.section_headers.toggle_readability();
353354
self.handle_tab()?;
354355
}
355356
}

0 commit comments

Comments
 (0)