Class: Ronin::Payloads::Encoders::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/payloads/encoders/pipeline.rb

Overview

Represents a pipeline of payload encoders.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoders = []) ⇒ Pipeline

Initializes the encoder pipeline.

Parameters:

  • encoders (Array<Encoder>) (defaults to: [])

    Optional encoders to pre-populate the encoder pipeline with.

Since:

  • 1.0.0



47
48
49
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 47

def initialize(encoders=[])
  @encoders = encoders
end

Instance Attribute Details

#encodersArray<Encoder> (readonly)

The encoders in the pipeline.

Returns:

Since:

  • 1.0.0



39
40
41
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 39

def encoders
  @encoders
end

Instance Method Details

#<<(new_encoder) ⇒ self

Adds a new encoder to the encoder pipeline.

Parameters:

  • new_encoder (Encoder)

    The new encoder to add.

Returns:

  • (self)

Since:

  • 1.0.0



59
60
61
62
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 59

def <<(new_encoder)
  @encoders << new_encoder
  return self
end

#[](id_or_index) ⇒ Encoder?

Fetches an encoder at the given index or by the encoder's id.

Parameters:

  • id_or_index (Integer, String)

    The index or the encoder's id to look up.

Returns:

  • (Encoder, nil)

    The encoder at the given index or with the matching id.

Since:

  • 1.0.0



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 111

def [](id_or_index)
  case id_or_index
  when String
    id = id_or_index

    @encoders.find { |encoder| encoder.class_id == id }
  else
    index = id_or_index

    @encoders[index]
  end
end

#each {|encoder| ... } ⇒ Enumerator

Enumerates over each encoder in the pipeline.

Yields:

  • (encoder)

    If a block is given, it will be passed each encoder in the pipeline.

Yield Parameters:

  • encoder (Encoder)

    An encoder in the pipeline.

Returns:

  • (Enumerator)

    If a block is not given, then an Enumerator will be returned.

Since:

  • 1.0.0



85
86
87
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 85

def each(&block)
  @encoders.each(&block)
end

#empty?Boolean

Determines whether the pipeline is empty and has no encoders in it.

Returns:

  • (Boolean)

Since:

  • 1.0.0



69
70
71
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 69

def empty?
  @encoders.empty?
end

#encode(payload) ⇒ String

Encodes the payload using the encoder pipeline.

Parameters:

  • payload (String)

    The unencoded payload.

Returns:

  • (String)

    The fully encoded payload.

Raises:

  • (BadEncoder)

    One of the encoders in the pipeline did not return a value.

Since:

  • 1.0.0



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 136

def encode(payload)
  encoded_payload = payload

  @encoders.each do |encoder|
    unless (encoded_payload = encoder.encode(encoded_payload))
      raise(BadEncoder,"no result was returned by the encoder: #{encoder.inspect}")
    end
  end

  return encoded_payload
end

#validateObject

Validates all encoders in the pipeline.

Raises:

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

    One of the required params was not set.

  • (ValidationError)

    Another encoder validation error occurred.

Since:

  • 1.0.0



98
99
100
# File 'lib/ronin/payloads/encoders/pipeline.rb', line 98

def validate
  each(&:validate)
end