logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

strings.sh (2798B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. WD="$(dirname "$0")"
  5. target="${WD}/../cmd/strings"
  6. plans=26
  7. . "$(dirname "$0")/tap.sh"
  8. usage="strings: [-az] [-t format] [-n number] [file...]
  9. "
  10. t --exit=1 usage "-t aa $WD/inputs/all_bytes" "${usage}"
  11. t devnull /dev/null ''
  12. t_file all_bytes "$WD/outputs/strings/all_bytes" "$WD/inputs/all_bytes"
  13. t default "${WD}/inputs/strings/length" '___4
  14. ____5
  15. _____6
  16. ______7
  17. _______8
  18. ________9
  19. '
  20. t n8 "-n 8 ${WD}/inputs/strings/length" '_______8
  21. ________9
  22. '
  23. t z8 "-z -n 8 ${WD}/inputs/strings/length" "$(printf '_______8\0________9\0')"
  24. #atf_test_case noperm cleanup
  25. #noperm_body() {
  26. # touch inputs/chmod_000 || atf_fail "touching chmod_000"
  27. # chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
  28. # # shellcheck disable=SC1112
  29. # atf_check -s exit:1 -e 'inline:strings: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/strings inputs/chmod_000
  30. #}
  31. #noperm_cleanup() {
  32. # chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000"
  33. # rm inputs/chmod_000 || atf_fail "rm chmod_000"
  34. #}
  35. t octal:devnull '-to /dev/null' ''
  36. t_file octal:all_bytes "$WD/outputs/strings/all_bytes_to" -to "$WD/inputs/all_bytes"
  37. t_file octal:lengthelf "$WD/outputs/strings/length_to" -to "$WD/inputs/strings/length"
  38. t_file octal:length8elf "$WD/outputs/strings/length_8_to" -to -n 8 "$WD/inputs/strings/length"
  39. t hex:devnull '-tx /dev/null' ''
  40. t_file hex:all_bytes "$WD/outputs/strings/all_bytes_tx" -tx "$WD/inputs/all_bytes"
  41. t_file hex:lengthelf "$WD/outputs/strings/length_tx" -tx "$WD/inputs/strings/length"
  42. t_file hex:length8elf "$WD/outputs/strings/length_8_tx" -tx -n 8 "$WD/inputs/strings/length"
  43. t dec:devnull '-td /dev/null' ''
  44. t_file dec:all_bytes "$WD/outputs/strings/all_bytes_td" -td "$WD/inputs/all_bytes"
  45. t_file dec:lengthelf "$WD/outputs/strings/length_td" -td "$WD/inputs/strings/length"
  46. t_file dec:length8elf "$WD/outputs/strings/length_8_td" -td -n 8 "$WD/inputs/strings/length"
  47. fmt_t="strings: error: Unknown format: t
  48. ${usage}"
  49. t --exit=1 fmt_t:devnull '-tt /dev/null' "${fmt_t}"
  50. t --exit=1 fmt_t:all_bytes "-tt $WD/inputs/all_bytes" "${fmt_t}"
  51. t --exit=1 fmt_t:lengthelf "-tt $WD/inputs/strings/length" "${fmt_t}"
  52. t --exit=1 fmt_t:length8elf "-tt -n 8 $WD/inputs/strings/length" "${fmt_t}"
  53. t --exit=1 erange_n:0 "-n 0 $WD/inputs/all_bytes" "strings: error: Option \`-n 0\` is too small
  54. ${usage}"
  55. t --exit=1 erange_n:4097 "-n 4097 $WD/inputs/all_bytes" "strings: error: Option \`-n 4097\` is too large
  56. ${usage}"
  57. t --exit=1 erange_n:f "-n f $WD/inputs/all_bytes" "strings: error: Option \`-n f\`: Invalid argument
  58. ${usage}"
  59. t --exit=1 erange_n:42f "-n 42f $WD/inputs/all_bytes" "strings: error: Option \`-n 42f\`: Invalid argument
  60. ${usage}"