hex2bin.sh 626 B

1234567891011121314151617
  1. #!/bin/bash
  2. # Convert the .hex files from tests/dumps to binary files so that they can be fed into the fuzzer as corpus
  3. # Read either the first argument or from stdin (http://stackoverflow.com/questions/6980090/bash-read-from-file-or-stdin)
  4. cat "${1:-/dev/stdin}" | \
  5. # Strip out comments starting with #
  6. sed -E 's/#.*$//' | \
  7. # Strip out comments starting with //
  8. sed -E 's/\/\/.*$//' | \
  9. # Strip out multi-line comments /* ... */
  10. perl -0777 -pe 's{/\*.*?\*/}{}gs' | \
  11. # Strip out all non hexadecimal characters
  12. sed -E 's/[^0-9a-fA-F]*//g' | \
  13. # Convert hex to binary using xxd's reverser in plain hexdump style
  14. xxd -r -ps