Sha256: 6478d9c432a52d3a1397f6d067879b2f2932935590ebc0f7abeded1089fbe6db

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

#!/usr/bin/env ruby
# Author Eric Monti (emonti at matasano)
#
# Reverses a hexdump back to raw data. Designed to work with hexdumps created 
# by Unix utilities like 'xxd' as well as 'hexdump -C'.

require 'rbkb'
require 'rbkb/command_line'

include RBkB::CommandLine

#------------------------------------------------------------------------------
# Init options and arg parsing
OPTS = {:len => 16}
arg = bkb_stdargs(nil, OPTS)

arg.banner += " <input-file | blank for stdin>"

#------------------------------------------------------------------------------
# Add local options

arg.on("-l", "--length LEN", Numeric, 
  "Bytes per line in hexdump (default: #{OPTS[:len]})") do |l|
    bail("Length must be greater than zero") unless (OPTS[:len] = l) > 0
end

#------------------------------------------------------------------------------
# Parse arguments
arg.parse!(ARGV) rescue bail "Error: #{$!}\nUse -h|--help for more info."

if OPTS[:indat].nil? and a=ARGV.shift
  OPTS[:indat] = File.open(a, "rb") rescue "Error: Can't open file '#{a}'"
end

# catchall
if ARGV.length != 0 
    bail "Error: bad arguments - #{ARGV.join(' ')}\n-h|--help for more info."
end

# Default to standard input
OPTS[:indat] ||= STDIN.read() 

#------------------------------------------------------------------------------
# Do stuff

exit 1 unless((OPTS[:len] ||= OPTS[:indat].length) > 0)

OPTS[:indat].dehexdump(
  :len => OPTS[:len], 
  :out => STDOUT
) rescue bail "Error: #{$!}"


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
emonti-rbkb-0.6.1.1 bin/dedump
emonti-rbkb-0.6.1.2 bin/dedump
emonti-rbkb-0.6.1.3 bin/dedump