Class: Ronin::UI::CLI::Commands::Encoder

Inherits:
ScriptCommand
  • Object
show all
Defined in:
lib/ronin/ui/cli/commands/encoder.rb

Overview

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#executeObject

Runs the input data through the encoder.

Since:

  • 1.0.0


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ronin/ui/cli/commands/encoder.rb', line 68

def execute
  unless (@encoder = load_script)
    print_error "Could not find the specified encoder"
    exit -1
  end

  open_input do |input|
    encoded = begin
                @encoder.encode(input)
              rescue Behaviors::Exception => e
                print_exception(e)
                exit -1
              end

    open_output do |output|
      if options.raw?
        output.write(encoded)
      else
        output.puts(encoded.inspect)
      end
    end
  end
end

#open_input {|data| ... } ⇒ Object (protected)

Opens the input stream and reads the data.

Yields:

  • (data)

    The input data will be passed to the block.

  • (String)

    data The data read from the input stream.

Since:

  • 1.0.0


103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ronin/ui/cli/commands/encoder.rb', line 103

def open_input
  if @input
    yield @input
  elsif @input_file
    File.open(@input_file,'rb') do |file|
      yield file.read
    end
  else
    yield STDIN.read
  end
end

#open_output {|output| ... } ⇒ Object (protected)

Opens the output stream.

Yields:

  • (output)

    The block will be passed the opened output stream.

  • (IO)

    output The output stream.

Since:

  • 1.0.0


124
125
126
127
128
129
130
# File 'lib/ronin/ui/cli/commands/encoder.rb', line 124

def open_output(&block)
  if @output
    File.open(@output,'wb',&block)
  else
    yield STDOUT
  end
end

#setupObject

Sets up the Encoder command.

Since:

  • 1.0.0


58
59
60
61
62
63
# File 'lib/ronin/ui/cli/commands/encoder.rb', line 58

def setup
  super

  # silence all output, if we are to print the raw data
  UI::Output.silent! if raw?
end