Class: Ronin::Payloads::CLI::Commands::Encode Private
- Inherits:
-
Ronin::Payloads::CLI::Command
- Object
- Core::CLI::Command
- Ronin::Payloads::CLI::Command
- Ronin::Payloads::CLI::Commands::Encode
- Includes:
- EncoderMethods, FormatOption
- Defined in:
- lib/ronin/payloads/cli/commands/encode.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Encodes data using the encoder(s).
Usage
ronin-payloads encode [options] {--string STRING | FILE}
Options
-F hex|c|shell|powershell|xml|html|js|ruby,
--format Formats the outputed data
-E, --encoder ENCODER The encoder name to load
-p, --param ENCODER.NAME=VALUE Sets a param on an encoder
-s, --string STRING The string to encode
-h, --help Print help information
Arguments
[FILE] The optional file to read and encode
Constant Summary
Constants included from FormatOption
Instance Attribute Summary collapse
-
#encoders ⇒ Array<String>
readonly
private
The encoder names to load.
-
#params ⇒ Hash{String => Hash{String => String}}
readonly
private
The params for the encoders.
-
#pipeline ⇒ Encoders::Pipeline?
readonly
private
The encoder pipeline.
Attributes included from FormatOption
Instance Method Summary collapse
-
#build_pipeline ⇒ Object
private
Builds the encoder pipeline.
-
#encode_data(data) ⇒ String
private
Encodes the data.
-
#initialize(**kwargs) ⇒ Encode
constructor
private
Initializes the
ronin-payloads encode
command. -
#load_data(file = nil) ⇒ String
private
Loads the data to encode.
-
#run(file = nil) ⇒ Object
private
Runs the
ronin-payloads encode
command. -
#validate_encoder(encoder) ⇒ Object
private
Validates the loaded encoders.
Methods included from EncoderMethods
#encoder_type, #initialize_encoder, #load_encoder, #load_encoder_from
Methods included from FormatOption
#format_data, included, #print_data
Constructor Details
#initialize(**kwargs) ⇒ Encode
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 the ronin-payloads encode
command.
114 115 116 117 118 119 |
# File 'lib/ronin/payloads/cli/commands/encode.rb', line 114 def initialize(**kwargs) super(**kwargs) @encoders = [] @params = Hash.new { |hash,key| hash[key] = {} } end |
Instance Attribute Details
#encoders ⇒ Array<String> (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 encoder names to load.
96 97 98 |
# File 'lib/ronin/payloads/cli/commands/encode.rb', line 96 def encoders @encoders end |
#params ⇒ Hash{String => Hash{String => String}} (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 params for the encoders.
101 102 103 |
# File 'lib/ronin/payloads/cli/commands/encode.rb', line 101 def params @params end |
#pipeline ⇒ Encoders::Pipeline? (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 encoder pipeline.
106 107 108 |
# File 'lib/ronin/payloads/cli/commands/encode.rb', line 106 def pipeline @pipeline end |
Instance Method Details
#build_pipeline ⇒ 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.
Builds the encoder pipeline.
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ronin/payloads/cli/commands/encode.rb', line 136 def build_pipeline @pipeline = Encoders::Pipeline.new @encoders.each do |encoder_id| encoder_class = load_encoder(encoder_id) params = @params[encoder_id] encoder = initialize_encoder(encoder_class, params: params) validate_encoder(encoder) @pipeline << encoder end end |
#encode_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.
Encodes the data.
197 198 199 200 201 202 203 |
# File 'lib/ronin/payloads/cli/commands/encode.rb', line 197 def encode_data(data) @pipeline.encode(data) rescue => error print_error "unhandled exception occurred while encoding data" print_exception(error) exit(1) end |
#load_data(file = nil) ⇒ 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.
Loads the data to encode.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/ronin/payloads/cli/commands/encode.rb', line 175 def load_data(file=nil) if file unless File.file?(file) print_error "No such file or directory: #{file}" exit(-1) end File.binread(file) elsif [:string] [:string] else stdin.read end end |
#run(file = nil) ⇒ 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.
Runs the ronin-payloads encode
command.
127 128 129 130 131 |
# File 'lib/ronin/payloads/cli/commands/encode.rb', line 127 def run(file=nil) build_pipeline print_data(encode_data(load_data(file))) 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 encoders.
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ronin/payloads/cli/commands/encode.rb', line 159 def validate_encoder(encoder) encoder.validate rescue Core::Params::ParamError, ValidationError => error print_error "failed to validate the encoder #{encoder.class_id}: #{error.}" exit(1) rescue => error print_error "an unhandled exception occurred while validating the encoder #{encoder.class_id}" print_exception(error) exit(-1) end |