Sha256: 7bd445007b73505e637e32bd311f25aeaa1fadc86975a59fc4ebd772e3513576

Contents?: true

Size: 1.15 KB

Versions: 11

Compression:

Stored size: 1.15 KB

Contents

require 'rbkb/cli'

# 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).
class Rbkb::Cli::Unhexify < Rbkb::Cli::Executable
  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

  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

  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
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
emonti-rbkb-0.6.6 lib/rbkb/cli/unhexify.rb
emonti-rbkb-0.6.7 lib/rbkb/cli/unhexify.rb
emonti-rbkb-0.6.8 lib/rbkb/cli/unhexify.rb
emonti-rbkb-0.6.9.1 lib/rbkb/cli/unhexify.rb
emonti-rbkb-0.6.9 lib/rbkb/cli/unhexify.rb
rbkb-0.7.2 lib/rbkb/cli/unhexify.rb
rbkb-0.7.1 lib/rbkb/cli/unhexify.rb
rbkb-0.7.0 lib/rbkb/cli/unhexify.rb
rbkb-0.6.12 lib/rbkb/cli/unhexify.rb
rbkb-0.6.11 lib/rbkb/cli/unhexify.rb
rbkb-0.6.10 lib/rbkb/cli/unhexify.rb