class Rbkb::Cli::Unhexify

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

unhexify converts a string of hex bytes back to raw data. Input can be supplied via stdin, a hex-string argument, or a file containing hex (use -f).

Public Instance Methods

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

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

  @opts[:indat].delete!("\r\n")
  @opts[:delim] ||= Regexp.new('\s*')

  @stdout << @opts[:indat].unhexify(@opts[:delim])

  self.exit(0)
end
make_parser() click to toggle source
Calls superclass method Rbkb::Cli::Executable#make_parser
# File lib/rbkb/cli/unhexify.rb, line 9
def make_parser
  super()
  add_std_file_opt(:indat)
  arg = @oparse

  #----------------------------------------------------------------------
  # Add local options
  arg.banner += " <data | blank for stdin>"

  arg.on("-d", "--delim DELIMITER", 
         "DELIMITER regex between hex chunks") do |d|
      @opts[:delim] = Regexp.new(d.gsub('\\\\', '\\'))
  end
end
parse(*args) click to toggle source
Calls superclass method Rbkb::Cli::Executable#parse
# File lib/rbkb/cli/unhexify.rb, line 24
def parse(*args)
  super(*args)

  # default string arg
  if @opts[:indat].nil? and a=@argv.shift
    @opts[:indat] = a.dup 
  end

  # catchall
  bail_args @argv.join(' ') if ARGV.length != 0 
end