Module: Ronin::Payloads::CLI::FormatOption Private

Included in:
Commands::Build, Commands::Encode
Defined in:
lib/ronin/payloads/cli/format_option.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Adds a -F,--format hex|c|shell|powershell|xml|html|js|ruby option.

Constant Summary collapse

FORMATS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Available formats.

{
  hex: -> {
    require 'ronin/support/encoding/hex'
    Support::Encoding::Hex.method(:escape)
  },

  c: -> {
    require 'ronin/support/encoding/c'
    Support::Encoding::C.method(:quote)
  },

  shell: -> {
    require 'ronin/support/encoding/shell'
    Support::Encoding::Shell.method(:quote)
  },

  powershell: -> {
    require 'ronin/support/encoding/powershell'
    Support::Encoding::PowerShell.method(:quote)
  },

  xml: -> {
    require 'ronin/support/encoding/xml'
    Support::Encoding::XML.method(:encode)
  },

  html: -> {
    require 'ronin/support/encoding/html'
    Support::Encoding::HTML.method(:encode)
  },

  js: -> {
    require 'ronin/support/encoding/js'
    Support::Encoding::JS.method(:quote)
  },

  ruby: -> {
    require 'ronin/support/encoding/ruby'
    Support::Encoding::Ruby.method(:quote)
  }
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formatMethod? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The format to encode data with.

Returns:

  • (Method, nil)


89
90
91
# File 'lib/ronin/payloads/cli/format_option.rb', line 89

def format
  @format
end

Class Method Details

.included(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds the -F,--format hex|c|shell|powershell|xml|html|js|ruby option.

Parameters:



78
79
80
81
82
83
84
# File 'lib/ronin/payloads/cli/format_option.rb', line 78

def self.included(command)
  command.option :format, short: '-F',
                          value: {type: FORMATS.keys},
                          desc: 'Formats the outputed data' do |format|
                            @format = FORMATS.fetch(format).call
                          end
end

Instance Method Details

#format_data(data) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Formats the given data based on the -F,--format option.

Parameters:

  • data (String)

    The data to format.

Returns:

  • (String)

    The formatted data.



100
101
102
103
104
# File 'lib/ronin/payloads/cli/format_option.rb', line 100

def format_data(data)
  if @format then @format.call(data)
  else            data
  end
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Formats and prints the given data.

Parameters:

  • data (String)

    The raw data to format and print.



112
113
114
115
116
117
118
# File 'lib/ronin/payloads/cli/format_option.rb', line 112

def print_data(data)
  formatted_data = format_data(data)

  if stdout.tty? then puts formatted_data
  else                stdout.write(formatted_data)
  end
end