Class: Rbkb::Cli::Unhexify
- Inherits:
-
Executable
- Object
- Executable
- Rbkb::Cli::Unhexify
- Defined in:
- lib/rbkb/cli/unhexify.rb
Overview
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).
Instance Attribute Summary
Attributes inherited from Executable
#argv, #exit_status, #oparse, #opts, #stderr, #stdin, #stdout
Instance Method Summary collapse
Methods inherited from Executable
#bail, #bail_args, #exit, #initialize, run
Constructor Details
This class inherits a constructor from Rbkb::Cli::Executable
Instance Method Details
#go(*args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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 ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rbkb/cli/unhexify.rb', line 9 def make_parser super() add_std_file_opt(:indat) arg = @oparse #---------------------------------------------------------------------- # Add local options arg. += " <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) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# 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 |