Class: Rbkb::Cli::Dedump

Inherits:
Executable show all
Defined in:
lib/rbkb/cli/dedump.rb

Overview

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’.

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, run

Constructor Details

#initialize(*args) ⇒ Dedump

Returns a new instance of Dedump.



9
10
11
12
13
14
# File 'lib/rbkb/cli/dedump.rb', line 9

def initialize(*args)
  super(*args) {|this|
    this.opts[:len] ||= 16
    yield this if block_given?
  }
end

Instance Method Details

#go(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rbkb/cli/dedump.rb', line 33

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_parserObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/rbkb/cli/dedump.rb', line 16

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) ⇒ Object



27
28
29
30
31
# File 'lib/rbkb/cli/dedump.rb', line 27

def parse(*args)
  super(*args)
  parse_file_argument(:indat)
  parse_catchall()
end