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.


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

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


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

def id
  @id
end

#methodObject

Returns the value of attribute method


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

def method
  @method
end

#paramsObject

Returns the value of attribute params


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

def params
  @params
end

Class Method Details

.from_module(j) ⇒ Object


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

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


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

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