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.



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

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

Instance Method Details

#go(*args) ⇒ Object



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

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 StandardError
    bail "Error: #{$!}"
  end

  self.exit(0)
end

#make_parser ⇒ Object



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

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
  arg
end

#parse(*args) ⇒ Object



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

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