diff --git a/tree/.local/nu/readelf.nu b/tree/.local/nu/readelf.nu index d638906..b4933b2 100755 --- a/tree/.local/nu/readelf.nu +++ b/tree/.local/nu/readelf.nu @@ -1,36 +1,13 @@ #!/bin/env nu -def elf-sections [ +# Inpect ELF-files +def elf [ elf: string # ELF-file to inspect + get?: cell-path ] { - LANG=C readelf --wide --sections $elf | - parse -r " +\\[ *\\S+\\] +(?\\.\\S+) +(?\\S+) +0*(?\\S+) +0*(?\\S+) +0*(?\\S+).*" | - into int -r 16 "addr" "off" "size" - -} - -def elf-symbols [ - elf: string # ELF-file to inspect - --section (-s): string -] { - - let symbols = ( - LANG=C readelf --wide --syms --demangle=rust $elf | - tail -n +5 | - parse -r " *(?\\d+): (?\\S+) +(?\\S+) +(?\\S+) +(?\\S+) +(?\\S+) +(?\\S+) (?.*)" | - into int "size" | - into int "num" | - into int -r 16 "addr" - ) - - - if $section == null { - $symbols + if $get == null { + ^elf $elf | from json } else { - let section = (elf-sections $elf | where name == $section | first) - let section_start = ($section | get addr) - let section_end = ($section_start + ($section | get size)) - - $symbols | where addr >= $section_start and addr < $section_end + ^elf $elf | from json | get $get } }