-
Notifications
You must be signed in to change notification settings - Fork 20
/
delegatefolders.py
68 lines (53 loc) · 1.83 KB
/
delegatefolders.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
# -*- coding: utf-8 -*-
"""Windows delegate folders collector."""
from winregrc import interface
class DelegateFolder(object):
"""Delegate folder.
Attributes:
identifier (str): identifier.
name (str): name.
namespace (str): namespace.
"""
def __init__(self, identifier, name, namespace):
"""Initializes a delegate folder.
Args:
identifier (str): identifier.
name (str): name.
namespace (str): namespace.
"""
super(DelegateFolder, self).__init__()
self.identifier = identifier
self.name = name
self.namespace = namespace
class DelegateFoldersCollector(interface.WindowsRegistryKeyCollector):
"""Windows delegate folders collector."""
_EXPLORER_KEY_PATH = (
'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\'
'Explorer')
def _CollectDelegateFolders(self, delegate_folders_key, namespace):
"""Collects Windows delegate folders.
Args:
delegate_folders_key (dfwinreg.WinRegistryKey): delegate folders Windows
Registry key.
namespace (str): namespace.
Yields:
DelegateFolder: a delegate folder.
"""
for subkey in delegate_folders_key.GetSubkeys():
name = self._GetValueFromKey(subkey, '')
yield DelegateFolder(subkey.name, name, namespace)
def Collect(self, registry):
"""Collects Windows delegate folders.
Args:
registry (dfwinreg.WinRegistry): Windows Registry.
Yields:
DelegateFolder: a delegate folder.
"""
explorer_key = registry.GetKeyByPath(self._EXPLORER_KEY_PATH)
if explorer_key:
for subkey in explorer_key.GetSubkeys():
delegate_folders_key = subkey.GetSubkeyByPath(
'NameSpace\\DelegateFolders')
if delegate_folders_key:
yield from self._CollectDelegateFolders(
delegate_folders_key, subkey.name)