Module: Ronin::Payloads::CLI::EncoderMethods Private

Included in:
Commands::Build, Commands::Encode, Commands::Encoder
Defined in:
lib/ronin/payloads/cli/encoder_methods.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.

Common methods for handling encoders.

Instance Method Summary collapse

Instance Method Details

#encoder_type(encoder_class) ⇒ 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.

Returns the encoder type for the encoder class.

Parameters:

Returns:

  • (String, nil)


46
47
48
49
50
51
52
53
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 46

def encoder_type(encoder_class)
  if    encoder_class < Encoders::HTMLEncoder       then 'html'
  elsif encoder_class < Encoders::JavaScriptEncoder then 'javascript'
  elsif encoder_class < Encoders::ShellEncoder      then 'shell'
  elsif encoder_class < Encoders::PowerShellEncoder then 'powershell'
  elsif encoder_class < Encoders::SQLEncoder        then 'sql'
  end
end

#initialize_encoder(encoder_class, **kwargs) ⇒ Encoders::Encoder

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.

Initializes an encoder.

Parameters:

  • encoder_class (Class<Encoders::Encoder>)

    The encoder class.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Encoders::Encoder#initialize.

Returns:



107
108
109
110
111
112
113
114
115
116
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 107

def initialize_encoder(encoder_class,**kwargs)
  encoder_class.new(**kwargs)
rescue Core::Params::ParamError => error
  print_error(error.message)
  exit(1)
rescue => error
  print_exception(error)
  print_error("an unhandled exception occurred while initializing encoder #{encoder_class.id}")
  exit(-1)
end

#load_encoder(name) ⇒ Class<Encoders::Encoder>

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.

Loads a encoder class.

Parameters:

  • name (String)

    The encoder name to load.

Returns:



64
65
66
67
68
69
70
71
72
73
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 64

def load_encoder(name)
  Payloads::Encoders.load_class(name)
rescue Payloads::ClassNotFound => error
  print_error(error.message)
  exit(1)
rescue => error
  print_exception(error)
  print_error("an unhandled exception occurred while loading encoder #{name}")
  exit(-1)
end

#load_encoder_from(file) ⇒ Class<Encoders::Encoder>

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.

Loads the encoder from a given file.

Parameters:

  • file (String)

    The file to load the encoder class from.

Returns:



84
85
86
87
88
89
90
91
92
93
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 84

def load_encoder_from(file)
  Payloads::Encoders.load_class_from_file(file)
rescue Payloads::ClassNotFound => error
  print_error(error.message)
  exit(1)
rescue => error
  print_exception(error)
  print_error("an unhandled exception occurred while loading encoder from file #{file}")
  exit(-1)
end

#validate_encoder(encoder) ⇒ 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.

Validates the loaded encoder.

Parameters:

Raises:

  • (Ronin::Core::Params::RequiredParam)

    One of the required params was not set.

  • (ValidationError)

    Another encoder validation error occurred.



130
131
132
133
134
135
136
137
138
139
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 130

def validate_encoder(encoder)
  encoder.validate
rescue Core::Params::ParamError, Encoders::ValidationError => error
  print_error("failed to validate the encoder #{encoder.class_id}: #{error.message}")
  exit(1)
rescue => error
  print_exception(error)
  print_error("an unhandled exception occurred while validating the encoder #{encoder.class_id}")
  exit(-1)
end