From 5d8493cf7e2d725fbd2aeca1644f56ebdafd4cf9 Mon Sep 17 00:00:00 2001 From: tzlil Date: Tue, 21 Mar 2023 15:44:11 +0200 Subject: finished section headers printing --- src/structs.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'src/structs.rs') diff --git a/src/structs.rs b/src/structs.rs index 69ec14e..4757f2a 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -319,6 +319,24 @@ pub struct ElfSectionHeader { pub entsize: u64, } +impl std::fmt::Display for ElfSectionHeader { + fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_fmt(format_args!( + "{: <16} {:0>16x} {:0>8x}\n {:0>16x} {:0>16x} {: ^10} {: <5} {: <5} {}", + self.r#type, + self.addr, + self.offset, + self.size, + self.entsize, + self.flags, + self.link, + self.info, + self.addralign + ))?; + Ok(()) + } +} + #[derive(Debug, Copy, Clone)] #[repr(u32)] pub enum ElfSectionType { @@ -389,11 +407,43 @@ pub enum ElfSectionType { GnuHash = 0x6FFFFFF6, } +impl std::fmt::Display for ElfSectionType { + fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + ElfSectionType::Null => "NULL".fmt(formatter), + ElfSectionType::ProgBits => "PROGBITS".fmt(formatter), + ElfSectionType::SymTab => "SYMTAB".fmt(formatter), + ElfSectionType::StrTab => "STRTAB".fmt(formatter), + ElfSectionType::Rela => "RELA".fmt(formatter), + ElfSectionType::Hash => "HASH".fmt(formatter), + ElfSectionType::Dynamic => "Dynamic".fmt(formatter), + ElfSectionType::Note => "NOTE".fmt(formatter), + ElfSectionType::NoBits => "NOBITS".fmt(formatter), + ElfSectionType::Rel => "REL".fmt(formatter), + ElfSectionType::ShLib => "SHLIB".fmt(formatter), + ElfSectionType::DynSym => "DYNSYM".fmt(formatter), + ElfSectionType::GnuHash => "GNU_HASH".fmt(formatter), + } + } +} + bitflags! { - #[derive(Debug, Copy, Clone)] - pub struct ElfSectionFlags: u64 { + #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + pub struct ElfSectionFlags: u64 { const WRITE = 0x1; const ALLOC = 0x2; const EXEC = 0x4; } } + +// PAIN IN THE ASS!!!!!!! +// https://github.com/aixoss/binutils/blob/master/binutils/readelf.c#L4966 +// https://github.com/llvm-mirror/llvm/blob/2c4ca6832fa6b306ee6a7010bfb80a3f2596f824/tools/llvm-readobj/ELFDumper.cpp#L1176 +impl std::fmt::Display for ElfSectionFlags { + fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + // if *self == ElfSectionFlags::WRITE { + " A".fmt(formatter); + // } + Ok(()) + } +} -- cgit 1.4.1