@@ -85,20 +85,28 @@ def printStringsForSectionIdx (elffile : RawELFFile) (idx : Nat) :=
85
85
| .some ⟨_, sec⟩ => for byte in sec.section_body do
86
86
if byte == 0 then IO.print '\n ' else IO.print (Char.ofNat byte.toNat)
87
87
88
- def printHexForSectionIdx (elffile : RawELFFile) (idx : Nat) :=
89
- match elffile.getRawSectionHeaderTableEntries[idx]? with
90
- | .none => IO.println s! "There doesn't appear to be a section header { idx} "
91
- | .some ⟨_, sec⟩ => dumpBytesAsHex sec.section_body
92
-
93
- def printHexForSectionName (elffile : RawELFFile) (name : String) :=
88
+ def msecByName (elffile : RawELFFile) (name : String) : IO (Option (RawSectionHeaderTableEntry × InterpretedSection)) :=
94
89
match elffile.getSectionHeaderStringTable? with
95
- | .error err => IO.println err
90
+ | .error err => IO.println err *> return none
96
91
| .ok (_,shstrtab_sec) =>
97
92
let shstrtab : ELFStringTable := ⟨shstrtab_sec.section_body⟩
98
93
let offset := shstrtab.stringToOffset name
99
94
let findPred : RawSectionHeaderTableEntry × InterpretedSection → Bool := (λent => SectionHeaderTableEntry.sh_name ent.fst == offset)
100
- let msec := elffile.getRawSectionHeaderTableEntries.find? findPred
101
- match msec with
95
+ return (elffile.getRawSectionHeaderTableEntries.find? findPred)
96
+
97
+ def printStringsForSectionName (elffile : RawELFFile) (name : String) := do
98
+ match (← msecByName elffile name) with
99
+ | .none => IO.println s! "There doesn't appear to be a section header named { name} "
100
+ | .some ⟨_, sec⟩ => for byte in sec.section_body do
101
+ if byte == 0 then IO.print '\n ' else IO.print (Char.ofNat byte.toNat)
102
+
103
+ def printHexForSectionIdx (elffile : RawELFFile) (idx : Nat) :=
104
+ match elffile.getRawSectionHeaderTableEntries[idx]? with
105
+ | .none => IO.println s! "There doesn't appear to be a section header { idx} "
106
+ | .some ⟨_, sec⟩ => dumpBytesAsHex sec.section_body
107
+
108
+ def printHexForSectionName (elffile : RawELFFile) (name : String) := do
109
+ match (← msecByName elffile name) with
102
110
| .none => IO.println s! "There doesn't appear to be a section header named { name} "
103
111
| .some ⟨_, sec⟩ => dumpBytesAsHex sec.section_body
104
112
@@ -250,8 +258,10 @@ def runReadCmd (p : Cli.Parsed): IO UInt32 := do
250
258
printSymbolsForSectionType elffile symtab
251
259
--TODO fallback to DYNSYM when SYMTAB isn't present
252
260
| "string-dump" => match flag.as? Nat with
253
- | none => IO.println "couldn't parse section number provided for string dump"
254
261
| some idx => printStringsForSectionIdx elffile idx
262
+ | none => match flag.as? String with
263
+ | some name => printStringsForSectionName elffile name
264
+ | none => IO.println "couldn't parse section number provided for string dump"
255
265
| "hex-dump" => match flag.as? Nat with
256
266
| some idx => printHexForSectionIdx elffile idx
257
267
| none => match flag.as? String with
0 commit comments