Bash snippet - Extract part of a file (hex offsets allowed) and save in another.


SUBMITTED BY: DanielK

DATE: Aug. 13, 2016, 2:45 p.m.

FORMAT: Bash

SIZE: 332 Bytes

HITS: 728

  1. function hextract()
  2. {
  3. if [ $# -gt 3 ]; then
  4. HEX2DEC_START=$((16#${2}))
  5. HEX2DEC_END=$((16#${3}))
  6. dd if="${1}" of="${4}" bs=4096 count=$((${HEX2DEC_END}-${HEX2DEC_START})) skip=${HEX2DEC_START} iflag=count_bytes,skip_bytes
  7. else
  8. echo "${FUNCNAME} <infile> <startoffset 0x> <endoffset 0x> <outfile>"
  9. fi
  10. }

comments powered by Disqus