@@ -72,6 +72,8 @@ def getSymbolNameInSection
7272 | .ok ste => RawELFFile.symbolNameByLinkAndOffset
7373 elffile (SectionHeaderTableEntry.sh_link shte) (SymbolTableEntry.st_name ste)
7474
75+ --TODO find? might be more appropriate than filter here.
76+
7577def printSymbolsForSectionType (elffile: RawELFFile) (ent_type : Nat) :=
7678 let ofType := elffile.getRawSectionHeaderTableEntries.filter $ λ⟨shte, _⟩↦
7779 SectionHeaderTableEntry.sh_type shte == ent_type
@@ -88,6 +90,18 @@ def printHexForSectionIdx (elffile : RawELFFile) (idx : Nat) :=
8890 | .none => IO.println s! "There doesn't appear to be a section header { idx} "
8991 | .some ⟨_, sec⟩ => dumpBytesAsHex sec.section_body
9092
93+ def printHexForSectionName (elffile : RawELFFile) (name : String) :=
94+ match elffile.getSectionHeaderStringTable? with
95+ | .error err => IO.println err
96+ | .ok (_,shstrtab_sec) =>
97+ let shstrtab : ELFStringTable := ⟨shstrtab_sec.section_body⟩
98+ let offset := shstrtab.stringToOffset name
99+ let findPred : RawSectionHeaderTableEntry × InterpretedSection → Bool := (λent => SectionHeaderTableEntry.sh_name ent.fst == offset)
100+ let msec := elffile.getRawSectionHeaderTableEntries.find? findPred
101+ match msec with
102+ | .none => IO.println s! "There doesn't appear to be a section header named { name} "
103+ | .some ⟨_, sec⟩ => dumpBytesAsHex sec.section_body
104+
91105def printHexForSymbolIdx (elffile : RawELFFile) (idx : Nat) :=
92106 match do
93107 let ⟨symshte, symsec⟩ ← elffile.getSymbolTable?
@@ -239,8 +253,10 @@ def runReadCmd (p : Cli.Parsed): IO UInt32 := do
239253 | none => IO.println "couldn't parse section number provided for string dump"
240254 | some idx => printStringsForSectionIdx elffile idx
241255 | "hex-dump" => match flag.as? Nat with
242- | none => IO.println "couldn't parse section number provided for hex dump"
243256 | some idx => printHexForSectionIdx elffile idx
257+ | none => match flag.as? String with
258+ | some name => printHexForSectionName elffile name
259+ | none => IO.println "couldn't parse section provided for hex dump"
244260 | "sym-dump" => match flag.as? Nat with
245261 | none => IO.println "couldn't parse symbol number provided for hex dump"
246262 | some idx => printHexForSymbolIdx elffile idx
0 commit comments