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)


48
49
50
51
52
53
54
55
56
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 48

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'
  elsif encoder_class < Encoders::XMLEncoder        then 'xml'
  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:



110
111
112
113
114
115
116
117
118
119
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 110

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:



67
68
69
70
71
72
73
74
75
76
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 67

def load_encoder(name)
  Payloads::Encoders.load_class(name)
rescue Payloads::Encoders::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:



87
88
89
90
91
92
93
94
95
96
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 87

def load_encoder_from(file)
  Payloads::Encoders.load_class_from_file(file)
rescue Payloads::Encoders::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.



133
134
135
136
137
138
139
140
141
142
# File 'lib/ronin/payloads/cli/encoder_methods.rb', line 133

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