class Rbkb::Cli::Dedump

Copyright 2009 emonti at matasano.com See README.rdoc for license information

Reverses a hexdump back to raw data. Designed to work with hexdumps created by Unix utilities like ‘xxd’ as well as ‘hexdump -C’.

Public Class Methods

new(*args) { |this| ... } click to toggle source
Calls superclass method Rbkb::Cli::Executable::new
# File lib/rbkb/cli/dedump.rb, line 10
def initialize(*args)
  super(*args) {|this|
    this.opts[:len] ||= 16
    yield this if block_given?
  }
end

Public Instance Methods

go(*args) click to toggle source
Calls superclass method Rbkb::Cli::Executable#go
# File lib/rbkb/cli/dedump.rb, line 34
def go(*args)
  super(*args)

  # Default to standard input
  @opts[:indat] ||= @stdin.read() 

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

  begin
    @opts[:indat].dehexdump( :len => @opts[:len], :out => @stdout)
  rescue
    bail "Error: #{$!}"
  end

  self.exit(0)
end
make_parser() click to toggle source
Calls superclass method Rbkb::Cli::Executable#make_parser
# File lib/rbkb/cli/dedump.rb, line 17
def make_parser()
  arg = super()
  arg.banner += " <input-file | blank for stdin>"

  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
  return arg
end
parse(*args) click to toggle source
Calls superclass method Rbkb::Cli::Executable#parse
# File lib/rbkb/cli/dedump.rb, line 28
def parse(*args)
  super(*args)
  parse_file_argument(:indat)
  parse_catchall()
end