Class: Msf::RPC::JSON::RpcCommand
- Inherits:
-
Object
- Object
- Msf::RPC::JSON::RpcCommand
- Defined in:
- lib/msf/core/rpc/json/rpc_command.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#execute_timeout ⇒ Object
Returns the value of attribute execute_timeout.
-
#framework ⇒ Object
readonly
Returns the value of attribute framework.
Instance Method Summary collapse
-
#execute(method, params) ⇒ Object
Invokes the method on the receiver object with the specified params, returning the method’s return value.
-
#initialize(framework, execute_timeout: 7200) ⇒ RpcCommand
constructor
Instantiate an RpcCommand.
-
#register_method(method, name: nil) ⇒ Method
Add a method to the RPC Command.
Constructor Details
#initialize(framework, execute_timeout: 7200) ⇒ RpcCommand
Instantiate an RpcCommand.
9 10 11 12 13 |
# File 'lib/msf/core/rpc/json/rpc_command.rb', line 9 def initialize(framework, execute_timeout: 7200) @framework = framework @execute_timeout = execute_timeout @methods = {} end |
Instance Attribute Details
#execute_timeout ⇒ Object
Returns the value of attribute execute_timeout.
4 5 6 |
# File 'lib/msf/core/rpc/json/rpc_command.rb', line 4 def execute_timeout @execute_timeout end |
#framework ⇒ Object (readonly)
Returns the value of attribute framework.
3 4 5 |
# File 'lib/msf/core/rpc/json/rpc_command.rb', line 3 def framework @framework end |
Instance Method Details
#execute(method, params) ⇒ Object
Invokes the method on the receiver object with the specified params, returning the method’s return value.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/msf/core/rpc/json/rpc_command.rb', line 37 def execute(method, params) unless @methods.key?(method) raise MethodNotFound.new(method) end ::Timeout.timeout(@execute_timeout) do if params.nil? return @methods[method].call() elsif params.is_a?(Array) return @methods[method].call(*params) else return @methods[method].call(**params) end end end |
#register_method(method, name: nil) ⇒ Method
Add a method to the RPC Command
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/msf/core/rpc/json/rpc_command.rb', line 19 def register_method(method, name: nil) if name.nil? if method.is_a?(Method) name = method.name.to_s else name = method.to_s end end @methods[name] = method end |