Class: Rex::Post::HWBridge::Extensions::CustomMethods::CustomMethods

Inherits:
Rex::Post::HWBridge::Extension show all
Defined in:
lib/rex/post/hwbridge/extensions/custom_methods/custom_methods.rb

Overview

Custom Methods extension - set of commands provided by the HW itself

Instance Attribute Summary

Attributes inherited from Rex::Post::HWBridge::Extension

#client, #name

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ CustomMethods

Returns a new instance of CustomMethods.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rex/post/hwbridge/extensions/custom_methods/custom_methods.rb', line 17

def initialize(client)
  super(client, 'automotive')

  # Alias the following things on the client object so that they
  # can be directly referenced
  client.register_extension_aliases(
    [
      {
        'name' => 'custom_methods',
        'ext'  => self
      }
    ])
end

Instance Method Details

#send_request(cmd, args, methods) ⇒ Object

Converts a cmd and args to a request to the hardware device cmd is the cmd without a path args are all KEY=value pairs. All checks are assumed to have already been done methods is a hash of all methods and their formatting returns a formatted response



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rex/post/hwbridge/extensions/custom_methods/custom_methods.rb', line 38

def send_request(cmd, args, methods)
  arguments = ""
  if args.size > 0
    arguments = "?"
    first = true
    args.each do |arg|
      arguments += "&" if not first
      arguments += arg
      first = false
    end
  end
  resp = { "success" => false }
  methods.each do |meth|
    if meth["method_name"] =~ /#{cmd}$/
      resp = client.send_request("#{meth["method_name"]}#{arguments}")
      if resp.has_key? "value" and meth.has_key? "return"
        case meth["return"]
        when "nil"
          print_warning("A return was given when none was expected")
        when "int"
          resp["value"] = resp["value"].to_i
        when "hex"
          resp["value"] = "0x" + resp["value"].to_s(16)
        when "boolean"
          resp["value"] = resp["value"] == "true" ? true : false
        when "float"
          resp["value"] = resp["value"].to_f
        end
      end
    end
  end
  resp
end