-
Notifications
You must be signed in to change notification settings - Fork 20
/
interface.py
78 lines (58 loc) · 2.15 KB
/
interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""Windows Registry key and value collector."""
class WindowsRegistryKeyCollector(object):
"""Windows Registry key and value collector."""
def __init__(self, debug=False):
"""Initializes a Windows Registry key and value collector.
Args:
debug (Optional[bool]): True if debug information should be printed.
"""
super(WindowsRegistryKeyCollector, self).__init__()
self._debug = debug
def _GetStringValueFromKey(
self, registry_key, value_name, default_value=None):
"""Retrieves a string value from a Registry value.
Args:
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
value_name (str): name of the value.
default_value (Optional[str]): default value.
Returns:
str: value or the default value if not available.
"""
if not registry_key:
return default_value
registry_value = registry_key.GetValueByName(value_name)
if not registry_value:
return default_value
if not registry_value.DataIsString():
return default_value
return registry_value.GetDataAsObject()
def _GetValueDataFromKey(self, registry_key, value_name):
"""Retrieves the value data from a Registry value.
Args:
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
value_name (str): name of the value.
Returns:
bytes: value data or None if not available.
"""
if not registry_key:
return None
registry_value = registry_key.GetValueByName(value_name)
if not registry_value:
return None
return registry_value.data
def _GetValueFromKey(self, registry_key, value_name, default_value=None):
"""Retrieves a value from a Registry value.
Args:
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
value_name (str): name of the value.
default_value (Optional[str]): default value.
Returns:
str: value or the default value if not available.
"""
if not registry_key:
return default_value
registry_value = registry_key.GetValueByName(value_name)
if not registry_value:
return default_value
return registry_value.GetDataAsObject()