Module: VmScanItemRegistry

Defined in:
lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb

Instance Method Summary collapse

Instance Method Details

#base_reg_path(scanHash) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb', line 33

def base_reg_path(scanHash)
  path = File.join(scanHash["hive"], scanHash["key"])
  path.tr!("/", "\\")
  # If we are not processing the value the base path is the hive + key, minus the last path element
  path = path.split("\\")[0..-2].join("\\") unless include_value?(scanHash)
  path
end

#build_reg_path(scanHash) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb', line 24

def build_reg_path(scanHash)
  path = get_long_hive_name(scanHash["hive"]) + "\\" + scanHash["key"]

  # Include the value as part of the search if we have a valid value
  path += "\\" + scanHash["value"] if include_value?(scanHash)

  path
end

#get_long_hive_name(hive) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb', line 52

def get_long_hive_name(hive)
  case hive
  when "HKLM"
    "HKEY_LOCAL_MACHINE"
  when "HKCU"
    "HKEY_CURRENT_USER"
  when "HKCR"
    "HKEY_CLASSES_ROOT"
  else
    hive
  end
end

#include_value?(scanHash) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
# File 'lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb', line 41

def include_value?(scanHash)
  # Include the value as part of the search if we have a valid value
  value = scanHash["value"].to_s.strip
  value = "" if value.length == 1 && value[0, 1] == "*"
  if !value.blank?
    return true
  else
    return false
  end
end

#parse_data(_vm, data) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb', line 16

def parse_data(_vm, data)
  if data
    scan_definition["content"].each do |d|
      d[:data] = MIQRexml.findRegElement(build_reg_path(d), data.root) if d[:data].nil?
    end
  end
end

#to_xmlObject



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb', line 2

def to_xml
  xml = @xml_class.newNode("scan_item")
  xml.add_attributes("guid" => @params["guid"], "name" => @params["name"], "item_type" => @params["item_type"])

  scan_definition["content"].each do |d|
    if d[:data]
      xml_partial = xml.root.add_element("registry")
      xml_partial.add_attributes("base_path" => base_reg_path(d), "id" => build_reg_path(d))
      xml_partial << d[:data]
    end
  end
  xml
end