Sha256: caa0bf2e7b83cd0c5720264c2f95d8925987ec0198f78cda6955b56721a6a4f7

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

#!/usr/bin/env ruby
# Author Eric Monti (emonti at matasano)
#
# 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).
# 
# Usage: unhexify [options] <data | blank for stdin>
#     -h, --help                       Show this message
#     -v, --version                    Show version and exit
#     -f, --file FILENAME              Input from FILENAME
#     -d, --delim DELIMITER            DELIMITER regex between hex chunks
# 

require 'rbkb'
require 'rbkb/command_line'

include RBkB::CommandLine

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

arg.banner += " <data | blank for stdin>"

arg = bkb_inputargs(arg, OPTS)

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

arg.on("-d", "--delim DELIMITER", 
  "DELIMITER regex between hex chunks") do |d|
    OPTS[:delim] = Regexp.new(d.gsub('\\\\', '\\'))
end

#------------------------------------------------------------------------------
# Parse arguments
arg.parse!(ARGV) rescue bail "Error: #{$!}\n#{arg}"

# default string arg
if OPTS[:indat].nil? and a=ARGV.shift
	OPTS[:indat] = a.dup 
end

# catchall
if ARGV.length != 0 
    bail "Error: bad arguments - #{ARGV.join(' ')}\n#{arg}"
end

OPTS[:indat] ||= STDIN.read()

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

OPTS[:indat].delete!("\r\n")
OPTS[:indat]

OPTS[:delim] ||= /\s*/

unless out = OPTS[:indat].unhexify(OPTS[:delim])
    bail "Error: Failed parsing as hex"
end

STDOUT.write(out)

Version data entries

3 entries across 3 versions & 1 rubygems

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