Class: Msf::Modules::External::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/modules/external/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(m) ⇒ Message

Returns a new instance of Message.



24
25
26
27
28
# File 'lib/msf/core/modules/external/message.rb', line 24

def initialize(m)
  self.method = m
  self.params = {}
  self.id = Base64.strict_encode64(SecureRandom.random_bytes(16))
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/msf/core/modules/external/message.rb', line 9

def id
  @id
end

#methodObject

Returns the value of attribute method.



8
9
10
# File 'lib/msf/core/modules/external/message.rb', line 8

def method
  @method
end

#paramsObject

Returns the value of attribute params.



9
10
11
# File 'lib/msf/core/modules/external/message.rb', line 9

def params
  @params
end

Class Method Details

.from_module(j) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/msf/core/modules/external/message.rb', line 11

def self.from_module(j)
  if j['method']
    m = self.new(j['method'].to_sym)
    m.params = j['params']
    m
  elsif j['result']
    m = self.new(:reply)
    m.params = j['result']
    m.id = j['id']
    m
  end
end

Instance Method Details

#to_jsonObject



30
31
32
33
34
35
36
37
38
# File 'lib/msf/core/modules/external/message.rb', line 30

def to_json
  params =
    if self.params.respond_to? :to_external_message_h
      self.params.to_external_message_h
    else
      self.params.to_h
    end
  JSON.generate({jsonrpc: '2.0', id: self.id, method: self.method, params: params})
end