diff --git a/tree/.config/nushell/config.nu b/tree/.config/nushell/config.nu index a871568..a38bfa7 100644 --- a/tree/.config/nushell/config.nu +++ b/tree/.config/nushell/config.nu @@ -545,4 +545,8 @@ alias gpu = git push -u origin alias gsta = git stash push alias gstp = git stash pop +# random scripts +source ~/.local/nu/readelf.nu + +# init starship prompt source ~/.cache/starship/init.nu diff --git a/tree/.local/nu/readelf.nu b/tree/.local/nu/readelf.nu new file mode 100755 index 0000000..585e17f --- /dev/null +++ b/tree/.local/nu/readelf.nu @@ -0,0 +1,36 @@ +#!/bin/env nu + +def elf-sections [ + elf: string # ELF-file to inspect +] { + 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 + } 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 && addr < $section_end + } +}